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:nick.gaImageRecognitionGui.panel.JPanelTraining.java
private void jButtonSetTrainingRulesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetTrainingRulesActionPerformed JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this); final JDialog frame = new JDialog(topFrame, true); JPanelSetTrainingRules setTrainingrules = new JPanelSetTrainingRules(trainingRules); frame.getContentPane().add(setTrainingrules); frame.pack();/* ww w . j a va 2 s . c o m*/ Util.centreWindow(frame); frame.setVisible(true); }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showNativeDialog(Component target, boolean open) { Window window = target == null ? null : (Frame) SwingUtilities.getWindowAncestor(target); FileDialog dialog;/* w w w . ja v a 2 s. com*/ if (window instanceof Frame) { dialog = new FileDialog((Frame) window); } else if (window instanceof Dialog) { dialog = new FileDialog((Dialog) window); } else { throw new IllegalStateException("Unknown window type"); } dialog.setDirectory(previousDirectory.getAbsolutePath()); dialog.setMode(open ? FileDialog.LOAD : FileDialog.SAVE); dialog.setVisible(true); if (rememberPreviousLocation) { previousDirectory = new File(dialog.getDirectory()); } if (dialog.getFile() == null) { return Result.CANCEL; } selected = new File(dialog.getFile()); return Result.APPROVE; }
From source file:oct.analysis.application.dat.OCTAnalysisManager.java
/** * This method will take care of interacting with the user in determining * where the fovea is within the OCT. It first lets the user inspect the * automatically identified locations where the fovea may be and then choose * the selection that is at the fovea. If none of the automated findings are * at the fovea the user has the option to manual specify it's location. * Finally, the chosen X coordinate (within the OCT) of the fovea is set in * the manager and can be obtained via the getFoveaCenterXPosition getter. * * @param fullAutoMode find the fovea automatically without user input when * true, otherwise find the fovea in semi-automatic mode involving user * interaction//from w w w .j a va 2 s. c o m */ public void findCenterOfFovea(boolean fullAutoMode) throws InterruptedException, ExecutionException { //disable clicking other components while processing by enabling glass pane JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(imgPanel); Component glassPane = topFrame.getGlassPane(); glassPane.setVisible(true); //monitor progress of finding the fovea ProgressMonitor pm = new ProgressMonitor(imgPanel, "Analyzing OCT for fovea...", "", 0, 100); pm.setMillisToDecideToPopup(0); pm.setMillisToPopup(100); pm.setProgress(0); FoveaFindingTask fvtask = new FoveaFindingTask(!fullAutoMode, glassPane); fvtask.addPropertyChangeListener((PropertyChangeEvent evt) -> { if ("progress".equals(evt.getPropertyName())) { int progress1 = (Integer) evt.getNewValue(); pm.setProgress(progress1); } }); fvtask.execute(); }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * Searchs for the component in the AUT with the given * <code>componentIdentifier</code>. * @param componentIdentifier the identifier created in object mapping mode * @throws IllegalArgumentException if the given identifer is null or <br>the hierarchy is not valid: empty or containing null elements * @throws InvalidDataException if the hierarchy in the componentIdentifier does not consist of strings * @throws ComponentNotManagedException if no component could be found for the identifier * @return the instance of the component of the AUT *///w w w. ja v a 2 s .c o m public Component findComponent(IComponentIdentifier componentIdentifier) throws IllegalArgumentException, ComponentNotManagedException, InvalidDataException { Component comp = (Component) findBP.findComponent(componentIdentifier, ComponentHandler.getAutHierarchy()); if (comp != null && comp.isShowing()) { Window window = SwingUtilities.getWindowAncestor(comp); if (window != null && window.isShowing() && !window.isActive()) { window.toFront(); } return comp; } throw new ComponentNotManagedException("unmanaged component with identifier: '" //$NON-NLS-1$ + componentIdentifier.toString() + "'.", //$NON-NLS-1$ MessageIDs.E_COMPONENT_NOT_MANAGED); }
From source file:org.esa.snap.smart.configurator.ui.PerformancePanel.java
private void editVMParametersButtonActionPerformed(ActionEvent e) { Object source = e.getSource(); Window window = null;/*from w w w. j a v a 2 s . c om*/ if (source instanceof Component) { Component component = (Component) source; window = SwingUtilities.getWindowAncestor(component); } String vmParametersAsBlankSeparatedString = vmParametersTextField.getText(); LineSplitTextEditDialog vmParamsEditDialog = new LineSplitTextEditDialog(window, vmParametersAsBlankSeparatedString, " ", "VM Parameters", VMParameters.canSave()); vmParamsEditDialog.show(); vmParametersTextField.setText(vmParamsEditDialog.getTextWithSeparators()); controller.changed(); }
From source file:org.intermine.common.swing.WindowUtils.java
/** * Show a standard exception dialog.//from ww w . ja v a2 s .com * * @param comp The Component launching the exception. * @param error The exception. * @param titleMessageKey Message key for the title of the window. * @param bodyMessageKey Message key for the body of the window. * @param logger The logger to write the error message to. */ public static void showExceptionDialog(Component comp, Throwable error, String titleMessageKey, String bodyMessageKey, Log logger) { if (comp instanceof Window) { showExceptionDialog((Window) comp, error, titleMessageKey, bodyMessageKey, logger); } else { showExceptionDialog(SwingUtilities.getWindowAncestor(comp), error, titleMessageKey, bodyMessageKey, logger); } }
From source file:org.netbeans.jpa.modeler.jcre.wizard.RevEngWizardDescriptor.java
public static EntityMappings generateJPAModel(ProgressReporter reporter, Set<String> entities, Project project, FileObject packageFileObject, String fileName, boolean includeReference, boolean softWrite, boolean autoOpen) throws IOException, ProcessInterruptedException { int progressIndex = 0; String progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N; reporter.progress(progressMsg, progressIndex++); String version = getModelerFileVersion(); final EntityMappings entityMappingsSpec = EntityMappings.getNewInstance(version); entityMappingsSpec.setGenerated();/*from ww w .j av a2 s .c o m*/ if (!entities.isEmpty()) { String entity = entities.iterator().next(); entityMappingsSpec.setPackage(JavaIdentifiers.getPackageName(entity)); } List<String> missingEntities = new ArrayList<>(); for (String entityClass : entities) { progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Class_Parsing", entityClass + ".java");//NOI18N reporter.progress(progressMsg, progressIndex++); JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass, packageFileObject, missingEntities); } if (includeReference) { List<ManagedClass> classes = new ArrayList<>(entityMappingsSpec.getEntity()); // manageSiblingAttribute for MappedSuperClass and Embeddable is not required for (DBRE) DB REV ENG CASE classes.addAll(entityMappingsSpec.getMappedSuperclass()); classes.addAll(entityMappingsSpec.getEmbeddable()); for (ManagedClass<IPersistenceAttributes> managedClass : classes) { for (RelationAttribute attribute : new ArrayList<>( managedClass.getAttributes().getRelationAttributes())) { String entityClass = StringUtils.isBlank(entityMappingsSpec.getPackage()) ? attribute.getTargetEntity() : entityMappingsSpec.getPackage() + '.' + attribute.getTargetEntity(); if (!entities.contains(entityClass)) { progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Class_Parsing", entityClass + ".java");//NOI18N reporter.progress(progressMsg, progressIndex++); JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass, packageFileObject, missingEntities); entities.add(entityClass); } } } } if (!missingEntities.isEmpty()) { final String title, _package; StringBuilder message = new StringBuilder(); if (missingEntities.size() == 1) { title = "Conflict detected - Entity not found"; message.append(JavaSourceParserUtil.simpleClassName(missingEntities.get(0))).append(" Entity is "); } else { title = "Conflict detected - Entities not found"; message.append("Entities ").append(missingEntities.stream() .map(e -> JavaSourceParserUtil.simpleClassName(e)).collect(toList())).append(" are "); } if (StringUtils.isEmpty(entityMappingsSpec.getPackage())) { _package = "<default_root_package>"; } else { _package = entityMappingsSpec.getPackage(); } message.append("missing in Project classpath[").append(_package) .append("]. \n Would like to cancel the process ?"); SwingUtilities.invokeLater(() -> { JButton cancel = new JButton("Cancel import process (Recommended)"); JButton procced = new JButton("Procced"); cancel.addActionListener((ActionEvent e) -> { Window w = SwingUtilities.getWindowAncestor(cancel); if (w != null) { w.setVisible(false); } StringBuilder sb = new StringBuilder(); sb.append('\n').append("You have following option to resolve conflict :").append('\n') .append('\n'); sb.append( "1- New File > Persistence > JPA Diagram from Reverse Engineering (Manually select entities)") .append('\n'); sb.append( "2- Recover missing entities manually > Reopen diagram file > Import entities again"); NotifyDescriptor nd = new NotifyDescriptor.Message(sb.toString(), NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); }); procced.addActionListener((ActionEvent e) -> { Window w = SwingUtilities.getWindowAncestor(cancel); if (w != null) { w.setVisible(false); } manageEntityMappingspec(entityMappingsSpec); JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, softWrite, autoOpen); }); JOptionPane.showOptionDialog(WindowManager.getDefault().getMainWindow(), message.toString(), title, OK_CANCEL_OPTION, ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"), new Object[] { cancel, procced }, cancel); }); } else { manageEntityMappingspec(entityMappingsSpec); JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, softWrite, autoOpen); return entityMappingsSpec; } throw new ProcessInterruptedException(); }
From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java
private boolean stopConfirm() { JOptionPane pane = new JOptionPane("Do you want to stop recording?", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION, null); JDialog dialog = pane.createDialog(SwingUtilities.getWindowAncestor(this), "Stop recording"); dialog.setVisible(true);/*from w w w .j a v a2 s. c om*/ Object selectedValue = pane.getValue(); if (selectedValue == null) { return false; } return JOptionPane.YES_OPTION == (Integer) selectedValue; }
From source file:org.nuclos.client.layout.wysiwyg.editor.ui.panels.WYSIWYGMetaInformationPicker.java
/** * This Method displays the Dialog//w w w . java2s .co m * @param wysiwygLayoutEditorPanel * @param values the List of valid Entitys * @param parent * @return the picked entity - is null if canceled */ public static String showPickDialog(WYSIWYGLayoutEditorPanel editorPanel, List<String> values, TableLayoutPanel parent) { WYSIWYGMetaInformationPicker picker; picker = new WYSIWYGMetaInformationPicker(SwingUtilities.getWindowAncestor(editorPanel), values, parent); picker.pack(); picker.setLocationRelativeTo(parent); picker.setVisible(true); return picker.getSelectedEntity(); }
From source file:org.omegat.gui.align.AlignPanelController.java
private void splitRow(int row, int col) { BeadTableModel model = (BeadTableModel) panel.table.getModel(); if (!model.isEditableColumn(col)) { throw new IllegalArgumentException(); }/*from w ww. jav a 2 s.co m*/ String text = panel.table.getValueAt(row, col).toString(); String reference = (String) panel.table.getValueAt(row, col == BeadTableModel.COL_SRC ? BeadTableModel.COL_TRG : BeadTableModel.COL_SRC); SplittingPanelController splitter = new SplittingPanelController(text, reference); String[] split = splitter.show(SwingUtilities.getWindowAncestor(panel.table)); if (split.length == 1) { return; } modified = true; Rectangle initialRect = panel.table.getVisibleRect(); panel.table.clearSelection(); int resultRows[] = model.splitRow(row, col, split); panel.table.changeSelection(resultRows[0], col, false, false); panel.table.changeSelection(resultRows[resultRows.length - 1], col, false, true); ensureSelectionVisible(initialRect); }