List of usage examples for javax.swing SwingUtilities getWindowAncestor
public static Window getWindowAncestor(Component c)
Window
ancestor of c
, or null if c
is not contained inside a Window
. From source file:eu.ggnet.dwoss.redtape.document.DocumentUpdateView.java
private void addNonUnitPosition(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNonUnitPosition PositionType type;//ww w . j av a2s .c o m if (((JButton) evt.getSource()) == addProductBatchButton) { type = PositionType.PRODUCT_BATCH; } else if (((JButton) evt.getSource()) == addServiceButton) { type = PositionType.SERVICE; } else if (((JButton) evt.getSource()) == addCommentButton) { type = PositionType.COMMENT; } else { type = PositionType.SHIPPING_COST; } try { controller.addPosition(document.getDossier().getId(), type, null, false); Platform.runLater(() -> { positions.clear(); positions.addAll(document.getPositions().values()); }); } catch (UserInfoException ex) { DwOssCore.show(SwingUtilities.getWindowAncestor(this), ex); } }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearnerFeedbackChartPane() { JXTaskPane feedbackChartPane = new JXTaskPane(); feedbackChartPane.setScrollOnExpand(true); feedbackChartPane.setTitle("Learner Feedback"); FeedbackChartMaker maker = new FeedbackChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouselistener, listening for a double click on a bar of the stacked bar chartPanel.addChartMouseListener(new ChartMouseListener() { @Override//from ww w. j a v a 2 s . com public void chartMouseClicked(ChartMouseEvent cme) { //Get the mouse event MouseEvent trigger = cme.getTrigger(); //Test if the mouse event is a left-button if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) { //Create a pop up dialog containing that the tlalineitems FeedbackPopupDialog popup = new FeedbackPopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, module.getTLALineItems()); //Set the title of the popup popup.setTitle("All Activities"); //Centre the popup at the location of the mouse click Point location = trigger.getLocationOnScreen(); int w = popup.getWidth(); int h = popup.getHeight(); popup.setLocation(location.x - w / 2, location.y - h / 2); popup.setVisible(true); int returnStatus = popup.getReturnStatus(); if (returnStatus == LearningTypePopupDialog.RET_OK) { modifyTLALineItem(popup.getSelectedTLALineItem(), 1); } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof CategoryItemEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(150, 200)); feedbackChartPane.add(chartPanel); return feedbackChartPane; }
From source file:com.googlecode.vfsjfilechooser2.VFSJFileChooser.java
/** * Creates and returns a new <code>JDialog</code> wrapping * <code>this</code> centered on the <code>parent</code> * in the <code>parent</code>'s frame. * This method can be overriden to further manipulate the dialog, * to disable resizing, set the location, etc. Example: * <pre>/*from ww w.j a v a 2 s . c o m*/ * class MyFileChooser extends VFSJFileChooser { * protected JDialog createDialog(Component parent) throws HeadlessException { * JDialog dialog = super.createDialog(parent); * dialog.setLocation(300, 200); * dialog.setResizable(false); * return dialog; * } * } * </pre> * * @param parent the parent component of the dialog; * can be <code>null</code> * @return a new <code>JDialog</code> containing this instance * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true. * @see java.awt.GraphicsEnvironment#isHeadless * @since 1.4 */ protected JDialog createDialog(Component parent) throws HeadlessException { String title = getUI().getDialogTitle(this); putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, title); Window window = null; try { window = SwingUtilities.getWindowAncestor(parent); } catch (Exception ex) { } if (window == null) { if (parent instanceof Window) { window = (Window) parent; } else { window = SHARED_FRAME; } dialog = new JDialog((Frame) window, title, true); } else if (window instanceof Frame) { dialog = new JDialog((Frame) window, title, true); } else { dialog = new JDialog((Dialog) window, title, true); } dialog.setComponentOrientation(this.getComponentOrientation()); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG); } } dialog.pack(); dialog.setLocationRelativeTo(parent); return dialog; }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected ComponentConfigurationEditorAPI createComponentEditorAPI(final String componentId, final Option option, final InstructionConfig instruction) { return new ComponentConfigurationEditorImpl() { @Override/*from w w w . j a v a 2s . com*/ public void onIODataChanged() { // repaint everything so they will check for errors, auto-corrects etc ScriptEditor.this.repaint(); } @Override public ODLApi getApi() { return api; } @Override public ODLDatastore<? extends ODLTableDefinition> getAvailableInputDatastore() { if (instruction != null && !Strings.isEmpty(instruction.getDatastore())) { if (Strings.equalsStd(ScriptConstants.EXTERNAL_DS_NAME, instruction.getDatastore())) { return runner.getDatastoreDefinition(); } AdapterConfig adapterConfig = ScriptUtils.getAdapterById(script, instruction.getDatastore(), true); if (adapterConfig != null) { return adapterConfig.createOutputDefinition(); } } return null; } @Override public Preferences getComponentPreferences() { return PreferencesManager.getSingleton().node(Strings.std(componentId)); } @Override public JFrame getAncestorFrame() { return (JFrame) SwingUtilities.getWindowAncestor(ScriptEditor.this); } @Override public boolean isInstruction() { return instruction != null; } @Override public void executeInPlace(String title, int mode) { ScriptEditor.this.executeInPlace(title, componentId, option, instruction, mode); } }; }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return/*w w w . java 2 s . c o m*/ */ private JPanel createSchemeComboBoxPanel() { JPanel schemeListPanel = new JPanel(new GridBagLayout()); // create categories configuration panel { GridBagConstraints itemConstraint = new GridBagConstraints(); // Add active scheme label JLabel actviceSchemeLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.active_scheme"); { itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.insets = new Insets(0, 5, 5, 5); itemConstraint.weightx = 1.0; actviceSchemeLabel.setBackground(Color.red); schemeListPanel.add(actviceSchemeLabel, itemConstraint); } // add button panel { JPanel buttonPanel = new JPanel(new GridBagLayout()); // rename scheme button { renameSchemeButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.rename_scheme_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String newName = createNameDialog(currentActiveColorSchemeName); if (newName != null && !newName.equals(currentActiveColorSchemeName)) { renameColorSchemeAction(newName); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(renameSchemeButton, itemConstraint); } // remove scheme button { removeSchemeButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.remove_scheme_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { ConfirmDialog dialog = new ConfirmDialog( SwingUtilities.getWindowAncestor((Component) e.getSource()), "plotter.configuration_dialog.confirm_color_scheme_delete", ConfirmDialog.YES_NO_OPTION, false); dialog.setLocationRelativeTo((Component) e.getSource()); dialog.setVisible(true); if (dialog.getReturnOption() == ConfirmDialog.YES_OPTION) { removeColorSchemeAction((ColorScheme) colorSchemeComboBox.getSelectedItem()); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(removeSchemeButton, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.insets = new Insets(0, 5, 5, 5); schemeListPanel.add(buttonPanel, itemConstraint); } { colorSchemeComboBox = new JComboBox(colorSchemeComboBoxModel); actviceSchemeLabel.setLabelFor(colorSchemeComboBox); colorSchemeComboBox.setRenderer(new ColorSchemeComboBoxRenderer()); colorSchemeComboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { return; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { Object selectedValue = colorSchemeComboBox.getSelectedItem(); if (selectedValue instanceof ColorScheme) { ColorScheme selection = (ColorScheme) selectedValue; if (selection != null) { if (!currentActiveColorSchemeName.equals(selection.getName())) { currentActiveColorSchemeName = selection.getName(); adaptModels(); } } } else { String newName = I18N.getGUILabel("plotter.new_color_scheme_name.label"); String suffix = ""; int counter = 1; while (currentColorSchemes.get(newName + suffix) != null) { suffix = "_" + counter; counter++; } newName += suffix; String userSelectedName = createNameDialog(newName); if (userSelectedName == null) { colorSchemeComboBox.setSelectedItem(getCurrentActiveColorScheme()); return; } addNewColorSchemeAction(userSelectedName); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { return; } }); itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 0.0; itemConstraint.weighty = 0.0; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; schemeListPanel.add(colorSchemeComboBox, itemConstraint); } } return schemeListPanel; }
From source file:com.digitalgeneralists.assurance.ui.components.ComparisonResultPanel.java
private void displayAttributesDialog(FileReference file) { ClassPathXmlApplicationContext springContext = null; try {/*from w ww . jav a 2 s. co m*/ if (this.getParent() != null) { JFrame parent = (JFrame) SwingUtilities.getWindowAncestor(this.getParent()); springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IDialogFactory dialogFactory = (IDialogFactory) springContext.getBean("DialogFactory"); JDialog scanDefinitionDialog = dialogFactory.createFileAttributesDialogInstance(parent, ModalityType.APPLICATION_MODAL, file); scanDefinitionDialog.setPreferredSize(new Dimension(400, 600)); scanDefinitionDialog.setVisible(true); dialogFactory = null; } } finally { if (springContext != null) { springContext.close(); springContext = null; } } }
From source file:de.tbuchloh.kiskis.gui.MainFramePanel.java
private ICryptoContext selectFile(final boolean isSaveDialog) { final FileDialog dlg = new FileDialog((JFrame) SwingUtilities.getWindowAncestor(this)); dlg.setSelectedFile(new File(Settings.getLastFile())); dlg.setSaveDialog(isSaveDialog);/*from w w w . ja v a 2 s.c om*/ dlg.setVisible(true); final File selectedFile = dlg.getSelectedFile(); if (selectedFile == null) { return null; } return new PasswordCryptoContext(dlg.getSelectedAlgo(), _pwdBuffer, selectedFile); }
From source file:ca.osmcanada.osvuploadr.JPMain.java
private void jbRemoveDupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRemoveDupActionPerformed JFMain topframe = (JFMain) SwingUtilities.getWindowAncestor(this); topframe.ShowInfoBox();// w ww. j a v a2 s .c o m topframe.SetInfoBoxText("test"); for (String item : listDir.getItems()) { Thread t = new Thread() { public void run() { FolderCleaner fc = new FolderCleaner(item); fc.setLocale(l); fc.setInfoBox(topframe); fc.RemoveDuplicates(); } }; t.start(); } }
From source file:com.hexidec.ekit.EkitCore.java
/** * Convenience method for obtaining the application as a Window */ public Window getWindow() { return SwingUtilities.getWindowAncestor(this); }
From source file:nick.gaImageRecognitionGui.panel.JPanelTraining.java
private void jButtonTrainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainActionPerformed IApiTrainer trainer = initTrainer(); saveSettings();//from w w w . j ava 2 s . c o m JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this); final JDialog frame = new JDialog(topFrame, false); JPanelTrainingInProgress trainingPanel = new JPanelTrainingInProgress(trainer); frame.getContentPane().add(trainingPanel); frame.pack(); Util.centreWindow(frame); frame.setVisible(true); }