List of usage examples for javax.swing JOptionPane getValue
public Object getValue()
From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java
private static boolean showDialog(String message, final long timeout) { try {/* w ww.j a v a 2 s. c om*/ int dialog = JOptionPane.YES_NO_OPTION; JOptionPane optionPane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); final JDialog dlg = optionPane.createDialog("Error"); new Thread(new Runnable() { @Override public void run() { { ThreadUtils.sleep(timeout); dlg.dispose(); } } }).start(); dlg.setVisible(true); int value = ((Integer) optionPane.getValue()).intValue(); if (value == JOptionPane.YES_OPTION) { return true; } else { return false; } } catch (RuntimeException e) { return true; } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public void openPDF(boolean isInternalR, File pdf, Component comp) throws FileNotFoundException { if (isInternalR) { try {//www . ja v a2 s . com Desktop.getDesktop().open(pdf); } catch (Exception ex) { log.info(ex.getMessage()); String msg = "Unable to open PDF format through java. Would you like to save " + pdf.getAbsoluteFile() + " in a new location?"; JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, null, JOptionPane.YES_OPTION); JDialog dialog = pane.createDialog(comp, "Report PDF"); dialog.setVisible(true); Object choice = pane.getValue(); if (choice.equals(JOptionPane.YES_OPTION)) { jfcFiles = new JFileChooser(); jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int state = jfcFiles.showSaveDialog(comp); if (state == JFileChooser.APPROVE_OPTION) { File file = checkFileExtension(".pdf"); log.info("Opening: " + file.getName() + "."); if (file != null) pdf.renameTo(file); } else { log.info("Open command cancelled by user."); } } } } }
From source file:com.gs.obevo.util.inputreader.DialogInputReader.java
@Override public String readPassword(String promptMessage) { final JPasswordField jpf = new JPasswordField(); JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = jop.createDialog(promptMessage); dialog.addComponentListener(new ComponentAdapter() { @Override/* www. j av a2s . c o m*/ public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jpf.requestFocusInWindow(); } }); } }); dialog.setVisible(true); int result = (Integer) jop.getValue(); dialog.dispose(); String password = null; if (result == JOptionPane.OK_OPTION) { password = new String(jpf.getPassword()); } if (StringUtils.isEmpty(password)) { return null; } else { return password; } }
From source file:com.gs.obevo.util.inputreader.DialogInputReader.java
@Override public String readLine(String promptMessage) { final JTextField juf = new JTextField(); JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog userDialog = juop.createDialog(promptMessage); userDialog.addComponentListener(new ComponentAdapter() { @Override//from www . j av a 2 s .com public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { juf.requestFocusInWindow(); } }); } }); userDialog.setVisible(true); int uresult = (Integer) juop.getValue(); userDialog.dispose(); String userName = null; if (uresult == JOptionPane.OK_OPTION) { userName = new String(juf.getText()); } if (StringUtils.isEmpty(userName)) { return null; } else { return userName; } }
From source file:com.ga.forms.DailyLogAddUI.java
private void checkInOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInOutButtonActionPerformed DailyLogRecord log = new DailyLogRecord(); if (DailyLogAddUI.checkIn && !DailyLogAddUI.breakDone) { args = new HashMap(); DailyLogAddUI.breakDone = true;//w ww .j a v a 2 s .co m args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); if (yesRdButton.isSelected() == true) { this.timeOnBreak = "00:30"; } else if (customRdButton.isSelected() == true) { this.timeOnBreak = customBreakTimeTextField.getText(); } else { this.timeOnBreak = "00:00"; } log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), "", this.timeOnBreak, "", "", "", args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); args.clear(); args.put("date", dateDisplayLbl.getText()); log.updateRecord(doc, args); } else if (DailyLogAddUI.checkIn && DailyLogAddUI.breakDone && !DailyLogAddUI.checkOut) { args = new HashMap(); DailyLogAddUI.checkOut = true; args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); DailyLogDuration durationAgent = new DailyLogDuration(); durationAgent.calculateCurrentDuration(checkInTimeCombo.getSelectedItem().toString(), this.timeOnBreak, checkOutTimeCombo.getSelectedItem().toString()); this.duration = durationAgent.getCurrentDuration(); JFrame parent = new JFrame(); JOptionPane optionPane = new JOptionPane("Duration: " + this.duration + "\n\nDo you want to Check Out?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); JDialog msgDialog = optionPane.createDialog(parent, "DLM"); msgDialog.setVisible(true); if (optionPane.getValue().equals(0)) { int hours = Integer.parseInt(this.duration.split(":")[0]); int minutes = Integer.parseInt(this.duration.split(":")[1]); if (hours < 9) { durationAgent.calculateUnderTime(this.duration); this.underTime = durationAgent.getUnderTime(); this.overTime = "00:00"; } else if (hours >= 9 && minutes > 0 && minutes < 60) { this.underTime = "00:00"; durationAgent.calculateOverTime(this.duration); this.overTime = durationAgent.getOverTime(); } else { this.underTime = "00:00"; this.overTime = "00:00"; } log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), checkOutTimeCombo.getSelectedItem().toString(), this.timeOnBreak, this.duration, this.underTime, this.overTime, args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); args.clear(); args.put("date", dateDisplayLbl.getText()); log.updateRecord(doc, args); } else { msgDialog.dispose(); } } else { args = new HashMap(); DailyLogAddUI.checkIn = true; args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn)); args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone)); args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut)); log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(), checkInTimeCombo.getSelectedItem().toString(), "", "", "", "", "", args); doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString()); log.insertRecord(doc); } }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void export() { Document doc = getDocumentManager().getSelection(); if (!(doc instanceof Transferable)) return;/*from w w w. j av a 2 s .c o m*/ Transferable transferable = (Transferable) doc; String title = doc.getTitle(); if (title == null) title = "Export"; else title = "Export '" + title + "'"; JComboBox src = new JComboBox(transferable.getTransferDataFlavors()); src.setRenderer(new DefaultListCellRenderer() { /** * */ private static final long serialVersionUID = -4553255745845039428L; public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String text; if (value instanceof DataFlavor) { DataFlavor flavor = (DataFlavor) value; String mimeType = flavor.getMimeType(); String humanRep = flavor.getHumanPresentableName(); String charset = flavor.getParameter("charset"); if (mimeType == null) text = "?"; else { text = mimeType; int ix = text.indexOf(';'); if (ix >= 0) text = text.substring(0, ix).trim(); } if (charset != null) text += "; charset=" + charset; if (humanRep != null) text += " (" + humanRep + ")"; } else { text = String.valueOf(value); } return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus); } }); JComboBox dst = new JComboBox(new Object[] { "File", "Clipboard" }); Object[] msg = { "Source:", doc.getTitle(), "Export as:", src, "Export to:", dst }; Object[] options = { "Ok", "Cancel" }; JOptionPane op = new JOptionPane(msg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options); JDialog dialog = op.createDialog(getWindow(), title); dialog.setModal(true); dialog.setVisible(true); boolean ok = "Ok".equals(op.getValue()); DataFlavor flavor = (DataFlavor) src.getSelectedItem(); dialog.dispose(); if (!ok) return; if (flavor == null) return; if ("Clipboard".equals(dst.getSelectedItem())) { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(new SelectedTransfer(flavor, transferable), null); } else { export(transferable, flavor); } }
From source file:com._17od.upm.gui.DatabaseActions.java
/** * Prompt the user to enter a password/*from w ww .ja va2 s . co m*/ * @return The password entered by the user or null of this hit escape/cancel */ private char[] askUserForPassword(String message) { char[] password = null; final JPasswordField masterPassword = new JPasswordField(""); JOptionPane pane = new JOptionPane(new Object[] { message, masterPassword }, 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() != null && pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) { password = masterPassword.getPassword(); } return password; }
From source file:com.floreantpos.config.ui.TerminalConfigurationView.java
public void restartPOS() { JOptionPane optionPane = new JOptionPane(Messages.getString("TerminalConfigurationView.26"), //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, Application.getApplicationIcon(), new String[] { /*Messages.getString("TerminalConfigurationView.28"),*/Messages .getString("TerminalConfigurationView.30") }); //$NON-NLS-1$ //$NON-NLS-2$ Object[] optionValues = optionPane.getComponents(); for (Object object : optionValues) { if (object instanceof JPanel) { JPanel panel = (JPanel) object; Component[] components = panel.getComponents(); for (Component component : components) { if (component instanceof JButton) { component.setPreferredSize(new Dimension(100, 80)); JButton button = (JButton) component; button.setPreferredSize(PosUIManager.getSize(100, 50)); }//from ww w . ja v a2 s . co m } } } JDialog dialog = optionPane.createDialog(Application.getPosWindow(), Messages.getString("TerminalConfigurationView.31")); //$NON-NLS-1$ dialog.setIconImage(Application.getApplicationIcon().getImage()); dialog.setLocationRelativeTo(Application.getPosWindow()); dialog.setVisible(true); Object selectedValue = (String) optionPane.getValue(); if (selectedValue != null) { if (selectedValue.equals(Messages.getString("TerminalConfigurationView.28"))) { //$NON-NLS-1$ try { Main.restart(); } catch (IOException | InterruptedException | URISyntaxException e) { } } else { } } }
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 w w . ja v a2 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(); } } }
From source file:com._17od.upm.gui.DatabaseActions.java
public void changeMasterPassword() throws IOException, ProblemReadingDatabaseFile, CryptoException, PasswordDatabaseException, TransportException { if (getLatestVersionOfDatabase()) { //The first task is to get the current master password boolean passwordCorrect = false; boolean okClicked = true; do {//from w ww .j a va 2 s . co m char[] password = askUserForPassword(Translator.translate("enterDatabasePassword")); if (password == null) { okClicked = false; } else { try { dbPers.load(database.getDatabaseFile(), password); passwordCorrect = true; } catch (InvalidPasswordException e) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword")); } } } while (!passwordCorrect && okClicked); //If the master password was entered correctly then the next step is to get the new master password if (passwordCorrect == true) { final JPasswordField masterPassword = new JPasswordField(""); boolean passwordsMatch = false; Object buttonClicked; //Ask the user for the new master password //This loop will continue until the two passwords entered match or until the user hits the cancel button do { JPasswordField confirmedMasterPassword = new JPasswordField(""); JOptionPane pane = new JOptionPane( new Object[] { Translator.translate("enterNewMasterPassword"), masterPassword, Translator.translate("confirmation"), confirmedMasterPassword }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = pane.createDialog(mainWindow, Translator.translate("changeMasterPassword")); dialog.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { masterPassword.requestFocusInWindow(); } }); dialog.show(); buttonClicked = pane.getValue(); if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION))) { if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch")); } else { passwordsMatch = true; } } } while (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && !passwordsMatch); //If the user clicked OK and the passwords match then change the database password if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && passwordsMatch) { this.dbPers.getEncryptionService().initCipher(masterPassword.getPassword()); saveDatabase(); } } } }