List of usage examples for javax.swing JOptionPane YES_OPTION
int YES_OPTION
To view the source code for javax.swing JOptionPane YES_OPTION.
Click Source Link
From source file:org.fhaes.FHRecorder.FireHistoryRecorder.java
/** * Closes the dialog but only after running necessary checks * to ensure user doesn't inadvertently loose data * /*from w ww . j av a 2 s. co m*/ */ private void closeAfterRunningChecks() { if (Controller.isModified()) { Object[] options = { "Save", "Close without saving", "Cancel" }; int n = JOptionPane.showOptionDialog(Controller.thePrimaryWindow, "Save changes to file before closing?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { Controller.save(); setVisible(false); } else if (n == JOptionPane.NO_OPTION) { Controller.setIsModified(false); Controller.setIsChangedSinceOpened(false); setVisible(false); } else if (n == JOptionPane.CANCEL_OPTION) { return; } } setVisible(false); }
From source file:gdt.jgui.entity.procedure.JProcedurePanel.java
/** * Get the context menu./* w w w. j a va 2 s . c om*/ * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { menu.removeAll(); JMenuItem runItem = new JMenuItem("Run"); runItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { run(); } }); menu.add(runItem); Entigrator entigrator = console.getEntigrator(entihome$); Sack procedure = entigrator.getEntityAtKey(entityKey$); if (procedure.getElementItem("parameter", "noreset") == null) { JMenuItem resetItem = new JMenuItem("Reset"); resetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Reset source to default ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) reset(); } }); menu.add(resetItem); } JMenuItem folderItem = new JMenuItem("Open folder"); folderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { File file = new File(entihome$ + "/" + entityKey$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); menu.add(folderItem); try { //Entigrator entigrator=console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); String template$ = entity.getAttributeAt("template"); if (template$ != null) { JMenuItem adaptClone = new JMenuItem("Adapt clone"); adaptClone.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { adaptClone(console, getLocator()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); menu.add(adaptClone); } } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:edu.ku.brc.specify.tools.FormDisplayer.java
/** * //ww w. ja v a2 s .co m */ public void generateFormImages() { if (setup()) { createFormImagesIndexFile(); } int userChoice = JOptionPane.showConfirmDialog(getTopWindow(), getResourceString("FormDisplayer.CHOOSE_VIEWLIST"), //$NON-NLS-1$ getResourceString("FormDisplayer.CHOOSE_VIEWLIST_TITLE"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION); doAll = userChoice == JOptionPane.YES_OPTION ? true : false; if (setup()) { SpecifyAppContextMgr appContext = (SpecifyAppContextMgr) AppContextMgr.getInstance(); viewList = doAll ? appContext.getEntirelyAllViews() : appContext.getAllViews(); SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { showView(); } }); } JButton stopBtn = UIHelper.createButton("Stop Generating Images"); PanelBuilder pb = new PanelBuilder(new FormLayout("p", "p")); pb.add(stopBtn, (new CellConstraints()).xy(1, 1)); pb.setDefaultDialogBorder(); cancelDlg = new CustomDialog((Frame) null, "Stop Image Generation", false, CustomDialog.OK_BTN, pb.getPanel()); cancelDlg.setOkLabel(getResourceString("CLOSE")); cancelDlg.setAlwaysOnTop(true); cancelDlg.setVisible(true); //Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(cancelDlg.getGraphicsConfiguration());; Rectangle screenRect = cancelDlg.getGraphicsConfiguration().getBounds(); int y = screenRect.height - (cancelDlg.getSize().height * 2); cancelDlg.setLocation(screenRect.x, y); stopBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { synchronized (okToProc) { okToProc.set(false); viewInx = viewList.size(); } } }); } }); }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Asks if data should be saved before it terminates the application. *//* w w w.ja v a 2 s . c om*/ private void exitApplication() { boolean exit = true; //Only show dialog for saving before exiting if any data has been // changed if (FoodItemManager.instance().hasChanged()) { final String question = LocalisationManager.INSTANCE.getText("gui.mainFrame.saveModificationsQuestion"); final int option = JOptionPane.showConfirmDialog(view, question); //If user choses yes try to save. If that fails do not exit. if (option == JOptionPane.YES_OPTION) { try { PersistenceController.instance().saveDomainData(); } catch (IOException e) { exit = false; showSavingErrorDialog(); e.printStackTrace(); } } else if (option == JOptionPane.CANCEL_OPTION) { exit = false; } } if (exit) { System.exit(0); } }
From source file:com.mirth.connect.client.ui.SettingsPanelMap.java
public void doExportMap() { if (isSaveEnabled()) { int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?"); if (option == JOptionPane.YES_OPTION) { if (!doSave()) { return; }//from w w w. jav a2 s . c om } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { return; } } final String workingId = getFrame().startWorking("Exporting " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private Map<String, ConfigurationProperty> configurationMap; public Void doInBackground() { try { File file = getFrame().createFileForExport(null, "PROPERTIES"); if (file != null) { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.setDelimiterParsingDisabled(true); properties.setListDelimiter((char) 0); properties.clear(); PropertiesConfigurationLayout layout = properties.getLayout(); configurationMap = getFrame().mirthClient.getConfigurationMap(); Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>( String.CASE_INSENSITIVE_ORDER); sortedMap.putAll(configurationMap); for (Entry<String, ConfigurationProperty> entry : sortedMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue().getValue(); String comment = entry.getValue().getComment(); if (StringUtils.isNotBlank(key)) { properties.setProperty(key, value); layout.setComment(key, StringUtils.isBlank(comment) ? null : comment); } } properties.save(file); } } catch (Exception e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { getFrame().stopWorking(workingId); } }; worker.execute(); }
From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java
/** * Constructor./*from w w w . ja v a2 s .c o m*/ */ private TrashJPanel() { treeNodeToResourceUriMap = new HashMap(); rootNode = new DefaultMutableTreeNode(Messages.getString("TrashJPanel.notebookArchive")); treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new MyTreeModelListener()); tree = new JTree(treeModel); tree.setEditable(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeExpansionListener(this); tree.addTreeWillExpandListener(this); tree.setShowsRootHandles(true); tree.putClientProperty("JTree.lineStyle", "Angled"); // tree rendered // TODO implement own renderer in order to tooltips tree.setCellRenderer(new TrashTreeCellRenderer(IconsRegistry.getImageIcon("trashFull.png"), IconsRegistry.getImageIcon("explorerNotebookIcon.png"))); setLayout(new BorderLayout()); // control panel JToolBar tp = new JToolBar(); tp.setLayout(new GridLayout(1, 6)); undoButton = new JButton("", IconsRegistry.getImageIcon("trashUndo.png")); undoButton.setEnabled(false); undoButton.setToolTipText("Restore Outline"); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } new RestoreNotebookJDialog((String) treeNodeToResourceUriMap.get(node), "Restore Outline", "Restore", true); } }); tp.add(undoButton); deleteButton = new JButton("", IconsRegistry.getImageIcon("explorerDeleteSmall.png")); deleteButton.setToolTipText("Delete Outline"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to DELETE this Outline?", "Delete Outline", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { MindRaider.labelCustodian.deleteOutline((String) treeNodeToResourceUriMap.get(node)); refresh(); ExplorerJPanel.getInstance().refresh(); } } }); tp.add(deleteButton); emptyButton = new JButton("", IconsRegistry.getImageIcon("trashEmpty.png")); emptyButton.setToolTipText(Messages.getString("TrashJPanel.emptyArchive")); emptyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to DELETE all discarded Outlines?", "Empty Trash", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { final SwingWorker worker = new SwingWorker() { public Object construct() { ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame("Empty Trash", "<html><br> <b>Deleting:</b> </html>"); try { ResourceDescriptor[] resourceDescriptors = MindRaider.labelCustodian .getDiscardedOutlineDescriptors(); if (resourceDescriptors != null) { for (int i = 0; i < resourceDescriptors.length; i++) { MindRaider.labelCustodian.deleteOutline(resourceDescriptors[i].getUri()); } refresh(); } } finally { if (progressDialogJFrame != null) { progressDialogJFrame.dispose(); } } return null; } }; worker.start(); } } }); tp.add(emptyButton); add(tp, BorderLayout.NORTH); // add the tree JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); // build the whole tree buildTree(); // click handler tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } logger.debug("Tree selection path: " + node.getPath()[node.getLevel()]); enableDisableToolbarButtons(node.getLevel()); } }); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java
static public Set<Integer> getExcludedTraitIds(Component comp, String msgTitle, KdxploreDatabase kdxdb, SampleGroup sg) {//ww w .jav a 2 s. com Set<Integer> excludeTheseTraitIds = new HashSet<>(); try { Set<Integer> traitIds = collectTraitIdsFromSamples(kdxdb, sg); List<Trait> undecidableTraits = new ArrayList<>(); Set<Integer> missingTraitIds = new TreeSet<>(); Map<Integer, Trait> traitMap = kdxdb.getKDXploreKSmartDatabase().getTraitMap(); for (Integer traitId : traitIds) { Trait t = traitMap.get(traitId); if (t == null) { missingTraitIds.add(traitId); } else if (TraitLevel.UNDECIDABLE == t.getTraitLevel()) { undecidableTraits.add(t); } } if (!missingTraitIds.isEmpty()) { String msg = missingTraitIds.stream().map(i -> Integer.toString(i)) .collect(Collectors.joining(",")); MsgBox.error(comp, msg, "Missing Trait IDs"); return null; } if (!undecidableTraits.isEmpty()) { String msg = undecidableTraits.stream().map(Trait::getTraitName) .collect(Collectors.joining("\n", "Traits that are neither Plot nor Sub-Plot:\n", "\nDo you want to continue and Exclude samples for those Traits?")); if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(comp, msg, msgTitle, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE)) { return null; } Set<Integer> tmp = undecidableTraits.stream().map(Trait::getTraitId).collect(Collectors.toSet()); excludeTheseTraitIds.addAll(tmp); } } catch (IOException e) { MsgBox.error(comp, "Unable to read samples from database\n" + e.getMessage(), msgTitle); return null; } return excludeTheseTraitIds; }
From source file:components.DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;//w w w .ja v a 2s . c om final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); //yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } //yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } //yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }
From source file:com.emr.schemas.ButtonColumn.java
public void mouseClicked(MouseEvent e) { int row = table.getSelectedRow(); int col = table.getSelectedColumn(); if (col == 7) { //Ask user if they want to delete.. int deleteProcess = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this process?", "Delete Process", JOptionPane.YES_NO_OPTION); if (deleteProcess == JOptionPane.YES_OPTION) { name = (String) table.getModel().getValueAt(row, 0); desc = (String) table.getModel().getValueAt(row, 1); new DeleteProcess().execute(); }//from w ww .j av a 2s . c o m } }
From source file:com._17od.upm.gui.DatabaseActions.java
/** * This method asks the user for the name of a new database and then creates * it. If the file already exists then the user is asked if they'd like to * overwrite it./* w ww . j a va 2 s. c o m*/ * @throws CryptoException * @throws IOException */ public void newDatabase() throws IOException, CryptoException { File newDatabaseFile = getSaveAsFile(Translator.translate("newPasswordDatabase")); if (newDatabaseFile == null) { return; } final JPasswordField masterPassword = new JPasswordField(""); boolean passwordsMatch = false; do { //Get a new master password for this database from the user JPasswordField confirmedMasterPassword = new JPasswordField(""); JOptionPane pane = new JOptionPane( new Object[] { Translator.translate("enterMasterPassword"), masterPassword, Translator.translate("confirmation"), confirmedMasterPassword }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword")); dialog.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { masterPassword.requestFocusInWindow(); } }); dialog.show(); if (pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) { if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch")); } else { passwordsMatch = true; } } else { return; } } while (passwordsMatch == false); if (newDatabaseFile.exists()) { newDatabaseFile.delete(); } database = new PasswordDatabase(newDatabaseFile); dbPers = new PasswordDatabasePersistence(masterPassword.getPassword()); saveDatabase(); accountNames = new ArrayList(); doOpenDatabaseActions(); // If a "Database to Load on Startup" hasn't been set yet then ask the // user if they'd like to open this database on startup. if (Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP) == null || Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP).equals("")) { int option = JOptionPane.showConfirmDialog(mainWindow, Translator.translate("setNewLoadOnStartupDatabase"), Translator.translate("newPasswordDatabase"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { Preferences.set(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP, newDatabaseFile.getAbsolutePath()); Preferences.save(); } } }