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:hr.fer.zemris.vhdllab.platform.gui.dialog.AbstractOptionPaneDialogManager.java
@SuppressWarnings("unchecked") @Override//w w w . j a v a 2 s. c om public <T> T showDialog(Object... args) { String title = getTitle(args); String text = getText(args); int optionType = getOptionType(); int messageType = getMessageType(); Frame owner = getFrame(); Object[] options = getOptionsForType(optionType); int option = JOptionPane.showOptionDialog(owner, text, title, optionType, messageType, null, options, options[0]); return (T) evaluateOption(option); }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static DialogResult showConfirmationDialog(Component parent, String title, String message) { final Object[] options = { "Yes", "No", "Cancel" }; final int outcome = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); switch (outcome) { case 0:/* w ww . ja v a2 s . c o m*/ return DialogResult.YES; case 1: return DialogResult.NO; case 2: case JOptionPane.CLOSED_OPTION: return DialogResult.CANCEL; default: throw new RuntimeException("Internal error, unexpected outcome " + outcome); } }
From source file:com.moneydance.modules.features.importlist.io.DeleteOneOperation.java
@Override public void showWarningAndExecute(final List<File> files) { final File file = files.iterator().next(); final String message = this.localizable.getConfirmationMessageDeleteOneFile(file.getName()); final Object confirmationLabel = new JLabel(message); final Image image = Helper.INSTANCE.getSettings().getIconImage(); Icon icon = null;/*from w w w . java 2 s . co m*/ if (image != null) { icon = new ImageIcon(image); } final Object[] options = { this.localizable.getOptionDeleteFile(), this.localizable.getOptionCancel() }; final int choice = JOptionPane.showOptionDialog(null, // no parent component confirmationLabel, null, // no title JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, icon, options, options[1]); if (choice == 0) { this.execute(files); } else { LOG.info(String.format("Canceled deleting file %s", file.getAbsoluteFile())); } }
From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java
private char[] getPin() { Box mainPanel = Box.createVerticalBox(); Box passwordPanel = Box.createHorizontalBox(); JLabel promptLabel = new JLabel("eID PIN:"); passwordPanel.add(promptLabel);//from w w w. ja va 2 s .c om passwordPanel.add(Box.createHorizontalStrut(5)); JPasswordField passwordField = new JPasswordField(8); passwordPanel.add(passwordField); mainPanel.add(passwordPanel); Component parentComponent = null; int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { char[] pin = passwordField.getPassword(); return pin; } throw new RuntimeException("operation canceled."); }
From source file:com.pdk.DisassembleElfAction.java
@Override public void actionPerformed(ActionEvent e) { try {//w w w.ja va2s . c o m Lookup context = Utilities.actionsGlobalContext(); DataObject file = context.lookup(DataObject.class); if (file == null) { showList(); } else { File fileObj = new File(file.getPrimaryFile().getPath()); if (!fileObj.getName().endsWith(".o")) { showList(); } else { File dir = new File(file.getFolder().getPrimaryFile().getPath()); Object[] options = { "Disasm", "Sections", "Cancel" }; int n = JOptionPane.showOptionDialog(null, "Please select", "Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == 2) { return; } String command2 = null; if (n == 0) { command2 = "i586-peter-elf-objdump -S"; } else if (n == 1) { command2 = "i586-peter-elf-readelf -S"; } if (command2 == null) { return; } final String command = "/toolchain/bin/" + command2 + " " + fileObj.getName(); process = Runtime.getRuntime().exec(command, null, dir); InputStreamReader isr = new InputStreamReader(process.getInputStream()); final BufferedReader br = new BufferedReader(isr, 1024 * 1024 * 50); final JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "i586-peter-elf-objdump -S " + fileObj.getName(), true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.progressBar.setString("Updating"); d.addCancelEventListener(this); Thread longRunningThread = new Thread() { public void run() { try { lines = new StringBuilder(); String line; stop = false; while (!stop && (line = br.readLine()) != null) { d.progressBar.setString(line); lines.append(line).append("\n"); } DisassembleDialog disassembleDialog = new DisassembleDialog(); disassembleDialog.setTitle(command); if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox .getModel()).getIndexOf("Monospaced") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox.setSelectedItem("Monospaced"); } if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox .getModel()).getIndexOf("Monospaced.plain") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox .setSelectedItem("Monospaced.plain"); } disassembleDialog.enhancedTextArea1.setText(lines.toString()); disassembleDialog.setVisible(true); } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } } }; d.thread = longRunningThread; d.setVisible(true); } } } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } }
From source file:net.sf.firemox.ui.MdbListener.java
/** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) *//*from w w w .j a va2 s . co m*/ public void actionPerformed(ActionEvent e) { if ("menu_options_tbs_more".equals(e.getActionCommand())) { // goto "more TBS" page try { WebBrowser.launchBrowser("http://sourceforge.net/project/showfiles.php?group_id=" + IdConst.PROJECT_ID + "&package_id=107882"); } catch (Exception e1) { JOptionPane.showOptionDialog(MagicUIComponents.magicForm, LanguageManager.getString("error") + " : " + e1.getMessage(), LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, UIHelper.getIcon("wiz_update_error.gif"), null, null); } return; } if ("menu_options_tbs_update".equals(e.getActionCommand())) { // update the current TBS XmlConfiguration.main(new String[] { "-g", MToolKit.tbsName }); return; } if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) { /* * rebuild completely the current TBS */ XmlConfiguration.main(new String[] { "-f", "-g", MToolKit.tbsName }); return; } // We change the TBS // Wait for confirmation if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(MagicUIComponents.magicForm, LanguageManager.getString("warn-disconnect"), LanguageManager.getString("disconnect"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, UIHelper.getIcon("wiz_update.gif"), null, null)) { // Save the current settings before changing TBS Magic.saveSettings(); // Copy this settings file to the profile directory of this TBS final File propertyFile = MToolKit.getFile(IdConst.FILE_SETTINGS); try { FileUtils.copyFile(propertyFile, MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false)); // Delete the current settings file of old TBS propertyFile.delete(); // Load the one of the new TBS abstractMainForm.setMdb(e.getActionCommand()); Configuration.loadTemplateFile( MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false).getAbsolutePath()); // Copy the saved configuration of new TBS FileUtils.copyFile(MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false), propertyFile); Log.info("Successful TBS swith to " + MToolKit.tbsName); // Restart the game System.exit(IdConst.EXIT_CODE_RESTART); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:gov.nih.nci.nbia.StandaloneDMV1.java
void checkCompatibility() { if (!serverUrl.endsWith("Servlet")) { 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);/*www. j a va 2 s . c o m*/ } }
From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java
synchronized public void exit() { log.debug("exit() - identifyQueueSize: " + IdentifyQueue.getInstance().size()); ComponentAPIWrapper.save();//w w w . ja v a2 s . c om if (IdentifyQueue.getInstance().size() <= 0) { CacheableMgr.getInstance().saveToCache(); UserRequestHandler.getInstance().handle(UserRequestHandler.DELETE_IDENTIFICATION_TABLE, null, true, // progress false // result ); log.debug("OSIT EXIT..."); System.exit(0); } log.debug("show message dialog to confirm exit or not"); String[] buttonList = { "Yes", "No" }; int choice = JOptionPane.showOptionDialog(null, "Identification Queue is not empty.(size : " + IdentifyQueue.getInstance().size() + ")\n" + "If you close this application with non-empty queue.\n" + "identification process for this queue will start again.\n" + "But it's not recommended. (Data loss problem)\n" + "Do you really want to exit now?\n", "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttonList, "Yes"); if (choice == JOptionPane.NO_OPTION) { return; // will not exit. } log.debug("user select yes option and create thread"); JDlgExitMessage dlgExitMessage = new JDlgExitMessage(); String message = "OSI try to sync with Protex Server.\n" + "It takes several minutes to finish."; DialogDisplayerThread aDialogDiaplayerThread = new DialogDisplayerThread(message, dlgExitMessage); CompleteSendingThread aCompleteSendingThread = new CompleteSendingThread(aDialogDiaplayerThread); log.debug("Thread start"); aDialogDiaplayerThread.execute(); aCompleteSendingThread.start(); dlgExitMessage.setVisible(true); // block CacheableMgr.getInstance().saveToCache(); log.debug("OSIT EXIT..."); System.exit(0); }
From source file:br.com.colmeiatecnologia.EmailMarketing.model.ThreadEnviaEmail.java
@Override public void run() { int contadorEnvios = 0; while (contadorEnvios <= remetente.getMaximoEnvio()) { while (!remetente.getDestinatarios().isEmpty()) { if (contadorEnvios >= remetente.getMaximoEnvio()) break; EmailModel remetenteAtual = (EmailModel) remetente.getDestinatarios().toArray()[0]; try { enviaEmail(remetenteAtual); this.sucessos++; } catch (Exception e) { this.falhas++; this.emailsNaoEnviados = emailsNaoEnviados + remetenteAtual.getEmail() + "\n"; }//w w w .j a v a 2s . c o m //Apaga destinatario atual da lista de destinatrios remetente.getDestinatarios().remove(remetente.getDestinatarios().toArray()[0]); estatisticas.atualizaTela(this.sucessos, this.falhas, this.emailsNaoEnviados); contadorEnvios++; } contadorEnvios++; } if (remetente.getDestinatarios().isEmpty()) { this.cancel(); JOptionPane.showMessageDialog(estatisticas, "O envio do email marketing foi finalizado", "Finalizado", JOptionPane.INFORMATION_MESSAGE); if (falhas > 0) { Object[] options = { "No", "Sim" }; int n = JOptionPane.showOptionDialog(null, "Deseja reenviar os emails que nao foram enviados?", "Falha ao enviar alguns emails", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); //Enviar novamente if (n == 1) { janelaPrincipal.reenvia(this.remetente, this.mensagem, this.emailsNaoEnviados); } } estatisticas.dispose(); } }
From source file:net.sf.jabref.exporter.ExportToClipboardAction.java
@Override public void run() { BasePanel panel = frame.getCurrentBasePanel(); if (panel == null) { return;/* w w w.ja 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.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.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"); } } }