List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:de.freese.base.swing.mac_os_x.MyApp.java
/** * General quit handler; fed to the OSXAdapter as the method to call when a * system quit event<br>//w ww .j av a 2 s . c om * occurs. A quit event is triggered by Cmd-Q, selecting Quit from the * application or<br> * Dock menu, or logging out. * <p/> * @return boolean */ public boolean quit() { int option = JOptionPane.showConfirmDialog(this, "Are you sure you want to quit?", "Quit?", JOptionPane.YES_NO_OPTION); return (option == JOptionPane.YES_OPTION); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRResultsController.java
@Override protected void tryToCreateFile(File pdfFile) { try {//from ww w . j a va 2 s . co m boolean success = pdfFile.createNewFile(); if (success) { doseResponseController.showMessage("Pdf Report successfully created!", "Report created", JOptionPane.INFORMATION_MESSAGE); } else { Object[] options = { "Yes", "No", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "File already exists. Do you want to replace it?", "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]); // if YES, user wants to delete existing file and replace it if (showOptionDialog == 0) { boolean delete = pdfFile.delete(); if (!delete) { return; } // if NO, returns already existing file } else if (showOptionDialog == 1) { return; } } } catch (IOException ex) { doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error", JOptionPane.ERROR_MESSAGE); return; } try (FileOutputStream fileOutputStream = new FileOutputStream(pdfFile)) { // actually create PDF file createPdfFile(fileOutputStream); } catch (IOException ex) { doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error", JOptionPane.ERROR_MESSAGE); } }
From source file:net.sf.profiler4j.console.ClassListPanel.java
/** * This method initializes addAsRuleButton * //from www . j a v a2s. c o m * @return javax.swing.JButton */ private JButton getAddAsRuleButton() { if (addAsRuleButton == null) { addAsRuleButton = new JButton(); addAsRuleButton .setIcon(new ImageIcon(getClass().getResource("/net/sf/profiler4j/console/images/wand.png"))); addAsRuleButton.setToolTipText("Create rules from classes"); addAsRuleButton.setEnabled(false); addAsRuleButton.setPreferredSize(new java.awt.Dimension(28, 28)); addAsRuleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { int ret = JOptionPane.showConfirmDialog(ClassListPanel.this, "Create rules from selected classes?", "Question", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.OK_OPTION) { int i = 0; for (int r : classesTable.getSelectedRows()) { String n = (String) classListTableModel.getRow(r).info.getName(); Rule rule = new Rule(n + ".*(*)", Rule.Action.ACCEPT); app.getProject().getRules().add(i++, rule); } ProjectDialog d = new ProjectDialog(app.getMainFrame(), app); d.edit(app.getProject()); } } }); } return addAsRuleButton; }
From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java
public static boolean checkFavouritesChanges() { boolean isChanged = false; Map favourites = (TreeMap) VOHelper.getVOGroup(FAVOURITES); Map egis = (TreeMap) VOHelper.getVOGroup(EGI); Map others = (TreeMap) VOHelper.getVOGroup(OTHERS); Iterator<Map.Entry<String, List>> entries = favourites.entrySet().iterator(); while (entries.hasNext()) { Entry<String, List> favourite = entries.next(); String favVOName = favourite.getKey(); List voDetails = favourite.getValue(); for (int i = 0; i < voDetails.size(); i++) { TreeMap favInfo = (TreeMap) voDetails.get(i); boolean isSame = false; String group = ""; if (egis.containsKey(favVOName)) { List egiVODetails = (List) egis.get(favVOName); isSame = compareTreeMapInList(favVOName, favInfo, egiVODetails); group = EGI;/*from www. j a v a 2 s. c o m*/ } else if (others.containsKey(favVOName)) { List othersVODetails = (List) others.get(favVOName); isSame = compareTreeMapInList(favVOName, favInfo, othersVODetails); group = OTHERS; } if (!isSame && !group.equals("")) { int reply = JOptionPane.showConfirmDialog(null, "VO '" + favVOName + "' setup has been modified in " + group + " setup. Your " + FAVOURITES + " configuration might not work.\n Do you want to update Favourites with the updated configurations?", "Update " + FAVOURITES + " configuration", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ResourceIcon(VOHelper.class, ConfigHelper.ICON)); if (reply == JOptionPane.OK_OPTION) { if (group.equals(EGI)) { favourites.put(favVOName, egis.get(favVOName)); isChanged = true; } else if (group.equals(OTHERS)) { favourites.put(favVOName, others.get(favVOName)); isChanged = true; } break; } } } } if (isChanged) { String newContent = createStringFromTreeMap((TreeMap) favourites); try { writeToFile(favouritesFile, newContent); } catch (IOException e) { isChanged = false; JOptionPane.showMessageDialog(null, "Failed to remove VO from Favourites. Cannot write to file '" + favouritesFile + "'", "Error: Remove VO", JOptionPane.ERROR_MESSAGE); } } return isChanged; }
From source file:marytts.tools.voiceimport.DatabaseImportMain.java
protected void askIfSave() throws IOException { if (bnl.hasChanged()) { int answer = JOptionPane.showOptionDialog(this, "Do you want to save the list of basenames?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (answer == JOptionPane.YES_OPTION) { JFileChooser fc = new JFileChooser(); fc.setSelectedFile(new File(db.getProp(db.BASENAMEFILE))); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { bnl.write(fc.getSelectedFile()); }/*from w ww . j av a 2 s. c om*/ } } else { System.exit(0); } }
From source file:com.sshtools.j2ssh.authentication.UserGridCredential.java
private static GSSCredential chooseCert(int proxyType, int lifetimeHours, SshConnectionProperties props) throws IOException, IllegalArgumentException, IllegalStateException { String dProfile = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_PROFILE, null); String dDN = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_DN, null); if (props instanceof SshToolsConnectionProfile) { SshToolsConnectionProfile profile = (SshToolsConnectionProfile) props; dProfile = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_PROFILE, dProfile); dDN = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_DN, dDN); }//from w w w.j av a 2 s . c o m String profile = Browser.getCurrentBrowser(); if (profile == null) { String profiles[] = Browser.getBrowserList(); if (profiles == null) return null; if (profiles.length == 0) { JOptionPane.showMessageDialog(props.getWindow(), "No browsers found", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); return null; } if (profiles.length == 1) { Browser.setBrowser(profiles[0]); //user chooses profile. } else { boolean chosen = false; if (dProfile != null) { for (String p : profiles) { if (p.equals(dProfile)) { chosen = true; Browser.setBrowser(p); } } } if (!chosen) { JComboBox combo = new JComboBox(profiles); int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose browser to use:", "Grid Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { combo, "OK" }, null); if (ret == JOptionPane.CLOSED_OPTION) new IOException("Canceled by user."); Browser.setBrowser(profiles[combo.getSelectedIndex()]); //user chooses profile. } } profile = Browser.getCurrentBrowser(); } String dnlist[] = null; try { dnlist = Browser.getDNlist(new PasswordPrompt(props)); } catch (IOException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } catch (KeyStoreException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } catch (CertificateException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } catch (javax.security.auth.login.FailedLoginException e) { JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "Incorrect Password", JOptionPane.ERROR_MESSAGE); return null; } catch (GeneralSecurityException e) { if (e.getMessage().indexOf("version>=1.5") >= 0) { JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); } else { e.printStackTrace(); errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e); log.debug("Could not access keystore in profile: " + profile + " : " + e); } } if (dnlist == null) return null; int index = -1; if (dnlist.length == 0) { JOptionPane.showMessageDialog(props.getWindow(), "No Certificates found", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); return null; } if (dnlist.length == 1) { index = 0; } else { if (dDN != null) { for (int i = 0; i < dnlist.length; i++) { if (dnlist[i].equals(dDN)) { index = i; } } } if (index == -1) { JComboBox dnCombo = new JComboBox(dnlist); int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose certificate to use:", "GSI-SSHTerm Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { dnCombo, "OK" }, null); if (ret == JOptionPane.CLOSED_OPTION) new IOException("Canceled by user."); index = dnCombo.getSelectedIndex(); } } try { GSSCredential gssproxy = Browser.getGridProxy(dnlist[index], proxyType, lifetimeHours); if (SAVE_BROWSER_PROXY) { GlobusCredential proxy = ((GlobusGSSCredentialImpl) gssproxy).getGlobusCredential(); ProxyHelper.saveProxy(proxy, props); } return gssproxy; } catch (GeneralSecurityException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e); log.debug("Could not load certificate from browser: " + e); } catch (GlobusCredentialException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e); log.debug("Could not load certificate from browser: " + e); } catch (GSSException e) { e.printStackTrace(); errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e); log.debug("Could not load certificate from browser: " + e); } return null; }
From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/* w w w.j a v a2 s . co m*/ final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
From source file:edu.virginia.speclab.juxta.author.view.export.WebServiceExportDialog.java
private void onExportClicked() { File jxt = null;// w ww . java 2 s . c o m boolean errorHandled = false; try { // make sure all data has been specified String setName = this.nameEdit.getText(); if (setName.length() == 0) { JOptionPane.showMessageDialog(this.juxtaFrame, "Please enter an export name for this session", "Missing Data", JOptionPane.ERROR_MESSAGE); return; } // dump the session to a temporary jxt file // and send this to the web service. Note that the // false param on the save marks this as a temporary one // that does not alter the session itself jxt = File.createTempFile("export", ".jxt"); this.juxtaFrame.getSession().saveSessionForExport(jxt); final String desc = this.descriptionEdit.getText(); try { // do the export showStatusUI(); authenticateUser(); this.exportTaskId = this.wsClient.beginExport(jxt, setName, desc); } catch (Exception e) { // catch naming conflict errors and prompt to overwrite if (e.getMessage().contains("Conflict")) { int resp = JOptionPane.showConfirmDialog(this.juxtaFrame, "A comparison set with this name already exists. Overwrite it?", "Overwrite", JOptionPane.YES_NO_OPTION); if (resp == JOptionPane.YES_OPTION) { this.statusLabel.setText("Re-Exporting JXT"); this.exportTaskId = this.wsClient.beginExport(jxt, setName, desc, true); } else { errorHandled = true; showSetupUI(); return; } } else { RequestStatus status = new RequestStatus(Status.FAILED, e.getMessage()); displayStatus(status); return; } } // kick off a thread that will do the // status check requests. this.statusTask = this.scheduler.scheduleAtFixedRate(new Runnable() { public void run() { final WebServiceClient client = WebServiceExportDialog.this.wsClient; final String id = WebServiceExportDialog.this.exportTaskId; try { RequestStatus status = client.getExportStatus(id); displayStatus(status); if (status.isTerminated()) { WebServiceExportDialog.this.statusTask.cancel(false); } } catch (IOException e) { RequestStatus status = new RequestStatus(Status.FAILED, e.getMessage()); displayStatus(status); WebServiceExportDialog.this.statusTask.cancel(false); } } }, 2, 2, TimeUnit.SECONDS); } catch (Exception e) { if (errorHandled == false) { JOptionPane.showMessageDialog(this.juxtaFrame, "Unable to export session:\n " + e.getMessage(), "Failure", JOptionPane.ERROR_MESSAGE); showSetupUI(); } } finally { if (jxt != null) { jxt.delete(); } } }
From source file:com.sec.ose.osi.ui.frm.main.JMenuMain.java
private JMenuItem getJMenuItemSyncToServer() { if (jMenuItemSyncToServer == null) { jMenuItemSyncToServer = new JMenuItem(); jMenuItemSyncToServer.setText("Sync to Server (flush identify queue)"); jMenuItemSyncToServer.setEnabled(true); jMenuItemSyncToServer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("Sync to Server clicked"); String title = "Sync to server - " + IdentifyMediator.getInstance().getSelectedProjectName(); String message = "OSI will flush all items in identify queue without UI update.\n" + "You are strongly suggested to click \"Sync From Server\" after completing this task.\n" + "Do you want to progress it now?"; int yesNo = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION); if (yesNo == JOptionPane.NO_OPTION) return; mEventHandler.handle(EventHandler.MAN_TOOL_SYNC_TO_SERVER); }/*from w w w . j a va2s.com*/ }); } return jMenuItemSyncToServer; }
From source file:net.landora.video.manager.ManagerFrame.java
public void exit() { int reply = JOptionPane.showConfirmDialog(this, "Are you sure you wish to quit?", "Exit", JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION) { System.exit(0);/*from w w w . ja va 2 s. co m*/ } }