List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:eu.ggnet.dwoss.redtape.action.StateTransitionAction.java
@Override public void actionPerformed(ActionEvent e) { //TODO: All the extra checks for hints don't feel like the optimum //Invoice//from w w w. java2s .com if (((RedTapeStateTransition) transition).getHints() .contains(RedTapeStateTransition.Hint.CREATES_INVOICE)) { int confirmInvoice = JOptionPane.showOptionDialog(parent, "Eine Rechnung wird unwiederruflich erstellt. Mchten Sie fortfahren?", "Rechnungserstellung", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); if (confirmInvoice == JOptionPane.CANCEL_OPTION) return; } //Cancel if (((RedTapeStateTransition) transition).equals(RedTapeStateTransitions.CANCEL)) { int confirmInvoice = JOptionPane.showOptionDialog(parent, "Der Vorgang wird storniert.\nMchten Sie fortfahren?", "Abbrechen des Vorganges", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); if (confirmInvoice == JOptionPane.NO_OPTION) return; } if (((RedTapeStateTransition) transition).getHints() .contains(RedTapeStateTransition.Hint.ADDS_SETTLEMENT)) { SettlementViewCask view = new SettlementViewCask(); OkCancelDialog<SettlementViewCask> dialog = new OkCancelDialog<>(parent, "Zahlung hinterlegen", view); dialog.setVisible(true); if (dialog.getCloseType() == CloseType.OK) { for (Document.Settlement settlement : view.getSettlements()) { cdoc.getDocument().add(settlement); } } else { return; } } if (((RedTapeStateTransition) transition).getHints() .contains(RedTapeStateTransition.Hint.UNIT_LEAVES_STOCK)) { for (Position p : cdoc.getDocument().getPositions(PositionType.PRODUCT_BATCH).values()) { //TODO not the best but fastest solution for now, this must be changed later if (StringUtils.isBlank(p.getRefurbishedId())) { if (JOptionPane.showConfirmDialog(parent, "Der Vorgang enthlt Neuware, wurden alle Seriennummern erfasst?", "Bitte verifizieren", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) return; } } } Dossier d = lookup(RedTapeWorker.class).stateChange(cdoc, transition, lookup(Guardian.class).getUsername()) .getDossier(); controller.reloadSelectionOnStateChange(d); }
From source file:javaapplication3.SolidscapeDialog.java
public void SolidscapeDialogStart() { instance = new InstanceCall(); setTitle("Add Information about" + new File(BPath.getText()).getName()); hideErrorFields();// www. j a v a 2 s .co m Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); this.dateRunTxt.setText(sdf.format(date)); this.setLocationRelativeTo(null); //search database for buildName //File BPathfile = new File(BPath.getText().replace("\\", "\\\\")); setVisible(true); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { String ObjButtons[] = { "Yes", "No" }; int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]); if (PromptResult == JOptionPane.YES_OPTION) { gatherScrapThenExit(); PrinterBuild.selectAllFiles("Solidscape"); dispose(); } else { ResultSet r = SolidscapeMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName()); try { while (r.next()) { SolidscapeMain.dba.updatePendingJobsBuildName(r.getString("buildName"), r.getString("fileName")); } } catch (SQLException ex) { Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex); } ResultSet s = SolidscapeMain.dba .searchSolidscapeByBuildName(new File(BPath.getText()).getName()); try { while (s.next()) { SolidscapeMain.dba.deleteByBuildName(s.getString("buildName"), "solidscape"); } } catch (SQLException ex) { Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex); } dispose(); } } }); }
From source file:net.sf.jabref.gui.exporter.ExportToClipboardAction.java
@Override public void run() { BasePanel panel = frame.getCurrentBasePanel(); if (panel == null) { return;//from w w w .j a v a 2 s . c om } if (panel.getSelectedEntries().isEmpty()) { message = Localization.lang("This operation requires one or more entries to be selected."); getCallBack().update(); return; } List<IExportFormat> exportFormats = new LinkedList<>(ExportFormats.getExportFormats().values()); Collections.sort(exportFormats, (e1, e2) -> e1.getDisplayName().compareTo(e2.getDisplayName())); String[] exportFormatDisplayNames = new String[exportFormats.size()]; for (int i = 0; i < exportFormats.size(); i++) { IExportFormat exportFormat = exportFormats.get(i); exportFormatDisplayNames[i] = exportFormat.getDisplayName(); } JList<String> list = new JList<>(exportFormatDisplayNames); list.setBorder(BorderFactory.createEtchedBorder()); list.setSelectionInterval(0, 0); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { Localization.lang("Export with selected format"), Localization.lang("Return to JabRef") }, Localization.lang("Export with selected format")); if (answer == JOptionPane.NO_OPTION) { return; } IExportFormat format = exportFormats.get(list.getSelectedIndex()); // Set the global variable for this database's file directory before exporting, // so formatters can resolve linked files correctly. // (This is an ugly hack!) Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory(); File tmp = null; try { // To simplify the exporter API we simply do a normal export to a temporary // file, and read the contents afterwards: tmp = File.createTempFile("jabrefCb", ".tmp"); tmp.deleteOnExit(); List<BibEntry> entries = panel.getSelectedEntries(); // Write to file: format.performExport(panel.getBibDatabaseContext(), tmp.getPath(), panel.getBibDatabaseContext().getMetaData().getEncoding(), entries); // Read the file and put the contents on the clipboard: StringBuilder sb = new StringBuilder(); try (Reader reader = new InputStreamReader(new FileInputStream(tmp), panel.getBibDatabaseContext().getMetaData().getEncoding())) { int s; while ((s = reader.read()) != -1) { sb.append((char) s); } } ClipboardOwner owner = (clipboard, content) -> { // Do nothing }; RtfSelection rs = new RtfSelection(sb.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner); message = Localization.lang("Entries exported to clipboard") + ": " + entries.size(); } catch (Exception e) { LOGGER.error("Error exporting to clipboard", e); //To change body of catch statement use File | Settings | File Templates. message = Localization.lang("Error exporting to clipboard"); } finally { // Clean up: if ((tmp != null) && !tmp.delete()) { LOGGER.info("Cannot delete temporary clipboard file"); } } }
From source file:SaveDialog.java
boolean okToQuit() { String[] choices = { "Yes, Save and Quit", "No, Quit without saving", "CANCEL" }; int result = JOptionPane.showOptionDialog(this, "You have unsaved changes. Save before quitting?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, choices, choices[0]);/* w ww .jav a 2 s . c o m*/ // Use of "null" as the Icon argument is contentious... the // document says you can pass null, but it does seem to // generate a lot of blather if you do, something about // a NullPointerException :-) ... if (result >= 0) System.out.println("You clicked " + choices[result]); switch (result) { case -1: System.out.println("You killed my die-alog - it died"); return false; case 0: // save and quit System.out.println("Saving..."); // mainApp.doSave(); return true; case 1: // just quit return true; case 2: // cancel return false; default: throw new IllegalArgumentException("Unexpected return " + result); } }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private String askUser() { //Create Options for option dialog String path = ""; // Set cross-platform Java L&F (also called "Metal") try {// ww w.jav a 2 s . c om UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); final ImageIcon icon = new ImageIcon(local_path + "/" + ICON_PATH); //Ask the user to ask for scratch Object[] options = { "Import existing JSON option file", "Configure the bot from scratch" }; int n = JOptionPane.showOptionDialog(new JFrame(), "Chose one of the following options:", "NuBot UI Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon, //do not use a custom Icon options, //the titles of buttons options[0]); //default button title if (n == JOptionPane.YES_OPTION) { //Prompt user to chose a file. JFileChooser fileChooser = createFileChoser(); int result = fileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); path = selectedFile.getAbsolutePath(); LOG.info("Option file selected : " + path); } else { LOG.info("Closing Launch UI utility."); System.exit(0); } } } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException e) { LOG.error(e.toString()); } return path; }
From source file:com.cmsoftware.keyron.vista.Login.java
/** * Operaciones de verificacin de actualizacin de acuerdo a la * configuracin.//from w w w.j a v a 2 s.co m */ private void verificarActualizacion() { new Thread(() -> { if (new AplicacionFunciones().verificarActualizacion()) { String mensaje = "Hay una nueva versin del programa. Qu desea hacer?"; String[] opciones = { "Descargar e instalar", "Ms informacin" }; int respuesta = JOptionPane.showOptionDialog(null, mensaje, "Confirmar Operacin - Keyron", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opciones, 0); if (respuesta == 0) { new EsperarDescarga(null, true, "Iniciando descarga...").setVisible(true); } else if (respuesta == 1) { new InformacionNuevaVersion(null, true).setVisible(true); } } }).start(); }
From source file:Framework.java
private boolean quitConfirmed(JFrame frame) { String s1 = "Quit"; String s2 = "Cancel"; Object[] options = { s1, s2 }; int n = JOptionPane.showOptionDialog(frame, "Windows are still open.\nDo you really want to quit?", "Quit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, s1); if (n == JOptionPane.YES_OPTION) { return true; } else {//from w w w. jav a2 s. c o m return false; } }
From source file:gov.nih.nci.nbia.StandaloneDMV2.java
void checkCompatibility() { if (serverUrl.endsWith("DownloadServlet")) { this.serverUrl = serverUrl.concat("V2"); }/*from w w w . j av a 2s .co m*/ if (!serverUrl.endsWith("DownloadServletV2")) { Object[] options = { "OK" }; int n = JOptionPane.showOptionDialog(frame, serverVersionMsg, "Incompatible Server Notification", JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); System.exit(n); } }
From source file:javaapplication3.ObjetDialog.java
public void ObjetDialogStart() { instance = new InstanceCall(); setTitle("Add Information about" + new File(BPath.getText()).getName()); hideErrorFields();//from w ww .j av a2 s. co m Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); this.dateRunTxt.setText(sdf.format(date)); this.setLocationRelativeTo(null); //search database for buildName //File BPathfile = new File(BPath.getText().replace("\\", "\\\\")); setVisible(true); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { String ObjButtons[] = { "Yes", "No" }; int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]); if (PromptResult == JOptionPane.YES_OPTION) { gatherScrapThenExit(); PrinterBuild.selectAllFiles("Objet"); dispose(); } else { ResultSet r = ObjetMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName()); try { while (r.next()) { ObjetMain.dba.updatePendingJobsBuildName(r.getString("buildName"), r.getString("fileName")); } } catch (SQLException ex) { Logger.getLogger(ObjetDialog.class.getName()).log(Level.SEVERE, null, ex); } ResultSet s = ObjetMain.dba.searchObjetByBuildName(new File(BPath.getText()).getName()); try { while (s.next()) { ObjetMain.dba.deleteByBuildName(s.getString("buildName"), "objet"); } } catch (SQLException ex) { Logger.getLogger(ObjetDialog.class.getName()).log(Level.SEVERE, null, ex); } dispose(); } } }); }
From source file:javaapplication3.ZCorpDialog.java
public void ZCorpDialogStart() { instance = new InstanceCall(); setTitle("Add Information about" + new File(BPath.getText()).getName()); hideErrorFields();/*from ww w . j av a 2s .c o m*/ Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); this.dateRunTxt.setText(sdf.format(date)); this.setLocationRelativeTo(null); //search database for buildName //File BPathfile = new File(BPath.getText().replace("\\", "\\\\")); setVisible(true); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { String ObjButtons[] = { "Yes", "No" }; int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]); if (PromptResult == JOptionPane.YES_OPTION) { gatherScrapThenExit(); PrinterBuild.selectAllFiles("ZCorp"); dispose(); } else { ResultSet r = ZCorpMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName()); try { while (r.next()) { ZCorpMain.dba.updatePendingJobsBuildName(r.getString("buildName"), r.getString("fileName")); } } catch (SQLException ex) { Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex); } ResultSet s = ZCorpMain.dba.searchZCorpByBuildName(new File(BPath.getText()).getName()); try { while (s.next()) { ZCorpMain.dba.deleteByBuildName(s.getString("buildName"), "zcorp"); } } catch (SQLException ex) { Logger.getLogger(ZCorpDialog.class.getName()).log(Level.SEVERE, null, ex); } dispose(); } } }); }