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:Forms.CreateGearForm.java
private void showSaveErrorDialog() { Object[] options = { "OK" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel), "There was a problem saving your Gear Spec. Please try again.", "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); }
From source file:Forms.CreateGearForm.java
private void showLoadErrorDialog() { Object[] options = { "OK" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel), "There was a problem loading your Gear Spec. Please try again.", "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); }
From source file:net.pms.newgui.GeneralTab.java
public void addPlugins() { FormLayout layout = new FormLayout("fill:10:grow", "p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); int i = 1;//from w w w . j a va2 s.com for (final ExternalListener listener : ExternalFactory.getExternalListeners()) { if (i > 30) { logger.warn("Plugin limit of 30 has been reached"); break; } JButton bPlugin = new JButton(listener.name()); // listener to show option screen bPlugin.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showOptionDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), listener.config(), Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); } }); builder.add(bPlugin, cc.xy(1, i++)); } pPlugins.add(builder.getPanel()); }
From source file:io.github.jeddict.reveng.klass.RevEngWizardDescriptor.java
private EntityMappings generateJPAModel(final ProgressReporter reporter, EntityMappings entityMappings, final FileObject sourcePackage, final Set<String> entities, final FileObject targetFilePath, final String targetFileName, final boolean includeReference, final boolean softWrite, final boolean autoOpen) throws IOException, ProcessInterruptedException { int progressIndex = 0; String progressMsg = getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N; reporter.progress(progressMsg, progressIndex++); List<String> missingEntities = new ArrayList<>(); SourceExplorer source = new SourceExplorer(sourcePackage, entityMappings, entities, includeReference); for (String entityClassFQN : entities) { try {//from w ww .j av a2s. c om source.createClass(entityClassFQN); } catch (FileNotFoundException ex) { ex.printStackTrace(); missingEntities.add(entityClassFQN); } } progressIndex = loadJavaClasses(reporter, progressIndex, source.getClasses(), entityMappings); List<ClassExplorer> classes = checkReferencedClasses(source, missingEntities, includeReference); while (!classes.isEmpty()) { progressIndex = loadJavaClasses(reporter, progressIndex, classes, entityMappings); classes = checkReferencedClasses(source, missingEntities, includeReference); } 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 (isEmpty(entityMappings.getPackage())) { _package = "<default_root_package>"; } else { _package = entityMappings.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(e -> { Window window = SwingUtilities.getWindowAncestor(cancel); if (nonNull(window)) { window.setVisible(false); } manageEntityMapping(entityMappings); if (nonNull(targetFilePath) && nonNull(targetFileName)) { JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName, 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 { manageEntityMapping(entityMappings); if (nonNull(targetFilePath) && nonNull(targetFileName)) { JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName, softWrite, autoOpen); } return entityMappings; } throw new ProcessInterruptedException(); }
From source file:org.esa.snap.rcp.spectrum.SpectrumTopComponent.java
private void selectSpectralBands() { final RasterDataNode currentRaster = currentView.getRaster(); final DisplayableSpectrum[] allSpectra = rasterToSpectraMap.get(currentRaster); final SpectrumChooser spectrumChooser = new SpectrumChooser(SwingUtilities.getWindowAncestor(this), allSpectra);/*www. jav a 2 s. co m*/ if (spectrumChooser.show() == ModalDialog.ID_OK) { final DisplayableSpectrum[] spectra = spectrumChooser.getSpectra(); rasterToSpectraMap.put(currentRaster, spectra); } }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected void executeAdapterResultViewer(final AdaptedTableConfig table, final boolean isMap, final AdapterConfig... includeAdapters) { RunMe<Void> runMe = new RunMe<Void>() { @Override/*from w w w .ja v a 2 s . c o m*/ public Void runMe(ExecutionReport report) { // get the id of the adapter containing the table String dsid = ScriptUtils.getAdapterId(script, table); if (dsid == null) { throw new RuntimeException(); } // Take copy of the script and set all unsynced options. // This will avoid problems if part of the script is set to sync incorrectly... Script copy = ScriptIO.instance().deepCopy(script); ScriptUtils.setAllUnsynced(copy); // Remove other instructions from the option which are unneeded (otherwise table may appear twice etc...) // Assume that any instructions in the option containing the target adapter table are unneeded. // This should cover all but some very unusual circumstances... String optionid = ScriptUtils.getOptionIdByAdapterId(copy, dsid); Option option = ScriptUtils.getOption(copy, optionid); option.getInstructions().clear(); // Get adapter ids String[] adapterIds = new String[includeAdapters.length]; for (int i = 0; i < adapterIds.length; i++) { adapterIds[i] = includeAdapters[i].getId(); } // Get the collapsed subset of the script TableId tableId = new TableId(dsid, table.getName()); Script subscript = OptionsSubpath.getSubpathScript(copy, new TableId[] { tableId }, adapterIds, report); if (report.isFailed()) { return null; } if (subscript.getOptions().size() > 0) { // script should now be collapsed... throw new RuntimeException(); } // remove all other tables in the adapter containing the target table as they are definitely not needed AdapterConfig adapterConfig = ScriptUtils.getAdapterById(subscript, dsid, true); Iterator<AdaptedTableConfig> itTable = adapterConfig.getTables().iterator(); while (itTable.hasNext()) { if (Strings.equalsStd(itTable.next().getName(), table.getName()) == false) { itTable.remove(); } } // if we're showing a map then rename all remaining tables (could be multiple for a union) to drawables if (isMap) { for (AdaptedTableConfig tableConfig : adapterConfig.getTables()) { tableConfig.setName(api.standardComponents().map().getDrawableTableDefinition().getName()); } } // treat like a standard adapter, not a VLS adapterConfig.setAdapterType(ScriptAdapterType.NORMAL); // // create a single dummy adapter which just copies the table contents, excluding any sort columns // ScriptOptionImpl builder = new ScriptOptionImpl(api,null, subscript,null); // ScriptAdapter adapter= builder.addDataAdapter("DummyAdapter"); // final String adptId =adapter.getAdapterId(); // ScriptAdapterTable dummyTable = adapter.addEmptyTable(table.getName()); // dummyTable.setSourceTable(dsid, table.getName()); // for(int i =0;i<table.getColumnCount(); i++){ // if(table.getColumn(i).getSortField() == SortField.NO){ // dummyTable.addColumn(table.getColumnName(i), table.getColumnType(i), false, table.getColumnName(i)); // } // } // if(isMap){ // // set table to have "drawables" name // dummyTable.setTableName(api.standardComponents().map().getDrawableTableDefinition().getName()); // } // // add instruction to the end of the script ScriptOptionImpl builder = new ScriptOptionImpl(api, null, subscript, null); builder.addInstruction(adapterConfig.getId(), isMap ? api.standardComponents().map().getId() : api.standardComponents().tableViewer().getId(), ODLComponent.MODE_DEFAULT); // give script a unique id String name = isMap ? "Map data" : "Table result"; UUID uuid = UUID.nameUUIDFromBytes((script.getUuid().toString() + "-" + name).getBytes()); subscript.setUuid(uuid); // finally run the temporary script runner.executeScript(subscript, null, "Result of data adapter table"); return null; } }; // run the runnable! RunProcessWithExecReport.runProcess((JFrame) SwingUtilities.getWindowAncestor(this), runMe); }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningTypeChartPane() { JXTaskPane typeChartPane = new JXTaskPane(); typeChartPane.setTitle("Learning Types"); typeChartPane.setScrollOnExpand(true); final LearningTypeChartMaker maker = new LearningTypeChartMaker(module); final ChartPanel chartPanel = maker.getChartPanel(); //Add a mouse listener to the chart chartPanel.addChartMouseListener(new ChartMouseListener() { @Override//w ww . j a va 2 s .c om 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) { //Check that the mouse click is on a segment of the pie if (cme.getEntity() instanceof PieSectionEntity) { //Get the selected segment of the pie PieSectionEntity pieSection = (PieSectionEntity) cme.getEntity(); //Get the key that corresponds to that segment--this is a learning type String key = pieSection.getSectionKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningTypeMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningTypePopupDialog popup = new LearningTypePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs, key); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //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(), 0); } } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { //Set the cursor shape according to the location of the cursor if (cme.getEntity() instanceof PieSectionEntity) { chartPanel.setCursor(HAND); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } } }); chartPanel.setPreferredSize(new Dimension(150, 200)); typeChartPane.add(chartPanel); return typeChartPane; }
From source file:net.pms.PMS.java
public static void main(String args[]) throws IOException, ConfigurationException { boolean displayProfileChooser = false; // FIXME (breaking change): use a standard argument // format (and a standard argument processor) e.g. // --console, --scrollbars &c. if (args.length > 0) { for (int a = 0; a < args.length; a++) { if (args[a].equals(CONSOLE)) { System.setProperty(CONSOLE, Boolean.toString(true)); } else if (args[a].equals(NATIVELOOK)) { System.setProperty(NATIVELOOK, Boolean.toString(true)); } else if (args[a].equals(SCROLLBARS)) { System.setProperty(SCROLLBARS, Boolean.toString(true)); } else if (args[a].equals(NOCONSOLE)) { System.setProperty(NOCONSOLE, Boolean.toString(true)); } else if (args[a].equals(PROFILES)) { displayProfileChooser = true; }// w w w .ja va 2 s .c o m } } try { Toolkit.getDefaultToolkit(); if (isHeadless()) { if (System.getProperty(NOCONSOLE) == null) { System.setProperty(CONSOLE, Boolean.toString(true)); } } } catch (Throwable t) { System.err.println("Toolkit error: " + t.getClass().getName() + ": " + t.getMessage()); if (System.getProperty(NOCONSOLE) == null) { System.setProperty(CONSOLE, Boolean.toString(true)); } } if (!isHeadless() && displayProfileChooser) { ProfileChooser.display(); } try { setConfiguration(new PmsConfiguration()); assert getConfiguration() != null; // Load the (optional) logback config file. // This has to be called after 'new PmsConfiguration' // as the logging starts immediately and some filters // need the PmsConfiguration. // XXX not sure this is (still) true: the only filter // we use is ch.qos.logback.classic.filter.ThresholdFilter LoggingConfigFileLoader.load(); // create the PMS instance returned by get() createInstance(); // calls new() then init() } catch (Throwable t) { String errorMessage = String.format("Configuration error: %s: %s", t.getClass().getName(), t.getMessage()); System.err.println(errorMessage); t.printStackTrace(); if (!isHeadless() && instance != null) { JOptionPane.showMessageDialog( ((JFrame) (SwingUtilities.getWindowAncestor((Component) instance.getFrame()))), errorMessage, Messages.getString("PMS.42"), JOptionPane.ERROR_MESSAGE); } } }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private JXTaskPane createLearningExperienceChartPane() { JXTaskPane experienceChartPane = new JXTaskPane(); experienceChartPane.setScrollOnExpand(true); experienceChartPane.setTitle("Learning Experiences"); final LearningExperienceChartMaker maker = new LearningExperienceChartMaker(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 w ww. j a v a 2 s. c o m 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) { //Get the selected segment of the pie CategoryItemEntity bar = (CategoryItemEntity) cme.getEntity(); //Get the row key that corresponds to that segment--this is a learning experience String key = bar.getRowKey().toString(); //Get the set of tlalineitems whose activity contains that learning type Set<TLALineItem> relevantTLAs = maker.getLearningExperienceMap().get(key); //Create a pop up dialog containing that set of tlalineitems LearningExperiencePopupDialog popup = new LearningExperiencePopupDialog( (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, relevantTLAs); //Set the title of the popup to indicate which learning type was selected popup.setTitle("Activities with \'" + key + "\'"); //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(), 0); } } } @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(125, 75)); chartPanel.setMinimumDrawHeight(75); experienceChartPane.add(chartPanel); return experienceChartPane; }
From source file:eu.ggnet.dwoss.redtape.document.DocumentUpdateView.java
private void addUnitAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUnitAction if (unitInputField.getText().isEmpty()) return;/*w w w . jav a2s . co m*/ if (document.isClosed()) { JOptionPane.showMessageDialog(this, "Hinzufgen von Sopo Ware nicht erlaubt.", "Abgeschlossenes Dokument", JOptionPane.INFORMATION_MESSAGE); return; } for (String sopo : unitInputField.getText().trim().split("(\\s*,\\s*|\\s+)")) { if (StringUtils.isBlank(sopo)) continue; try { controller.addPosition(document.getDossier().getId(), PositionType.UNIT, sopo, false); } catch (Exception ex) { DwOssCore.show(SwingUtilities.getWindowAncestor(this), ex); } } Platform.runLater(new Runnable() { @Override public void run() { positions.clear(); positions.addAll(document.getPositions().values()); } }); unitInputField.setText(""); }