List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION
int OK_CANCEL_OPTION
To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:evm.RegisterFingerPrint.java
@Override public void OnCaptureCompleted(boolean bln, int i, String string, FingerData fd) { if (bln) {/*from ww w .j a va2s. com*/ fingerData = fd; int ch = JOptionPane.showConfirmDialog(this, "Confirm", "Confirm scan", JOptionPane.OK_CANCEL_OPTION); switch (ch) { case 0: fdarr[finger_count++] = fd; //count.setText(c+""); System.out.println(finger_count); break; case 1: System.out.println("2"); } if (finger_count >= 10) okButton.setEnabled(true); else startCapture(); } else { JOptionPane.showMessageDialog(this, "Could not capture. ERR " + i + "\n" + string); dispose(); } }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
private JButton getCancelBtn(final JFrame d) { JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel")); cancelar.addActionListener(new ActionListener() { @Override/* w ww .j ava2 s . co m*/ public void actionPerformed(ActionEvent e) { if (cambios) { int res = JOptionPane.showConfirmDialog(d, "Existen cambios sin guardar. Seguro que desea cerrar la ventana?", "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION); if (res != JOptionPane.CANCEL_OPTION) { d.dispose(); } } else { d.dispose(); } } }); return cancelar; }
From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void reinitializeGroovyConditions() { String dialogTitle = "Reinitialize example groovy conditions?"; String message = "This overwrites all example groovy conditions. Other conditions are not changed!\nReinitialize example groovy conditions right now?"; int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows if (JOptionPane.OK_OPTION != result) { return;/* ww w . java2s . co m*/ } applicationPreferences.installExampleConditions(); }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * // ww w. j a v a 2s .c om * @return */ public Action getSelectTankAction() { Action ret = actionMap.get(ACTION_SELECT_TANK); if (ret == null) { ret = new AbstractAction(ACTION_SELECT_TANK) { private static final long serialVersionUID = 1L; final JComboBox cb = getComboBox(); @Override public void actionPerformed(ActionEvent event) { try { int selected = JOptionPane.showConfirmDialog(debuggerFrame, cb, "Enter the base URL to Tank:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (selected == JOptionPane.OK_OPTION) { String url = (String) cb.getSelectedItem(); if (url != null) { int startInd = url.indexOf('('); int endInd = url.indexOf(')'); if (startInd != -1 && endInd != -1) { url = url.substring(startInd + 1, endInd); } url = StringUtils.removeEndIgnoreCase(url, "/"); if (!url.startsWith("http")) { url = "http://" + url; } try { new ScriptServiceClient(url).ping(); setServiceUrl(url); } catch (Exception e) { showError("Cannot connect to Tank at the url " + url + ". \nExample: http://tank.mysite.com/"); } } } } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Enter a Tank URL."); actionMap.put(ACTION_SELECT_TANK, ret); } return ret; }
From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java
/** * Show an error message with toggable detail * * @param parent/* www . j a va2s . c o m*/ * @param mesg * @param title * @param exception */ public static void showErrorMessage(Component parent, String mesg, String title, Throwable exception) { boolean details = false; while (true) { String[] opts = new String[] { details ? "Hide Details" : "Details", "Ok" }; StringBuffer buf = new StringBuffer(); if (mesg != null) { buf.append(mesg); } appendException(exception, 0, buf, details); //MultilineLabel message = new MultilineLabel(buf.toString()); javax.swing.JTextArea message = new javax.swing.JTextArea(buf.toString()); message.setEditable(false); message.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); javax.swing.JLabel jl = new javax.swing.JLabel(); message.setFont(jl.getFont()); message.setBackground(jl.getBackground()); int opt = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, opts, opts[1]); if (opt == 0) { details = !details; } else { break; } } }
From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java
public boolean isConfirmed() { Object[] options = { "Yes", "No" }; int option = JOptionPane.showOptionDialog(panelMain, "Are you sure you want to generate '" + model.getFileName() + "' ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, new ImageIcon(getClass().getResource(ICON_CONFIRM)), options, options[0]); return option == JOptionPane.OK_OPTION; }
From source file:io.github.jeddict.jpa.modeler.properties.PropertiesHandler.java
public static ComboBoxPropertySupport getCollectionTypeProperty( AttributeWidget<? extends Attribute> attributeWidget, final CollectionTypeHandler colSpec) { JPAModelerScene modelerScene = attributeWidget.getModelerScene(); EntityMappings em = modelerScene.getBaseElementSpec(); ModelerFile modelerFile = modelerScene.getModelerFile(); ComboBoxListener<String> comboBoxListener = new ComboBoxListener<String>() { private final Set<String> value = new HashSet<>(); @Override// ww w . j a v a2 s . c om public void setItem(ComboBoxValue<String> value) { String prevType = colSpec.getCollectionType(); String newType = value.getValue(); setCollectionType(value); manageMapType(prevType, newType); attributeWidget.setAttributeTooltip(); attributeWidget.visualizeDataType(); } void setCollectionType(ComboBoxValue<String> value) { String collectionType = value.getValue(); boolean valid = validateCollectionType(collectionType, colSpec.getCollectionImplType(), true); boolean nextValidation = valid; if (!nextValidation) { try { if (StringUtils.isNotBlank(collectionType)) { if (java.util.Collection.class.isAssignableFrom(Class.forName(collectionType.trim())) || java.util.Map.class.isAssignableFrom(Class.forName(collectionType.trim()))) { nextValidation = true; } } } catch (ClassNotFoundException ex) { //skip allow = false; } } if (!nextValidation) { collectionType = java.util.Collection.class.getName(); } colSpec.setCollectionType(collectionType); em.getCache().addCollectionClass(collectionType); if (!valid) { attributeWidget.refreshProperties(); } } void manageMapType(String prevType, String newType) { Class prevClass = null; try { prevClass = Class.forName(prevType); } catch (ClassNotFoundException ex) { } Class newClass = null; try { newClass = Class.forName(newType); } catch (ClassNotFoundException ex) { } if ((prevClass != null && newClass != null && prevClass != newClass && (Map.class.isAssignableFrom(prevClass) || Map.class.isAssignableFrom(newClass))) || (prevClass == null && newClass != null && Map.class.isAssignableFrom(newClass)) || (prevClass != null && newClass == null && Map.class.isAssignableFrom(prevClass))) { if (newClass == null || !Map.class.isAssignableFrom(newClass)) { ((MapKeyHandler) attributeWidget.getBaseElementSpec()).resetMapAttribute(); } attributeWidget.refreshProperties(); } } @Override public ComboBoxValue<String> getItem() { if (!value.contains(colSpec.getCollectionType())) { value.add(colSpec.getCollectionType()); em.getCache().addCollectionClass(colSpec.getCollectionType()); } return new ComboBoxValue(colSpec.getCollectionType(), colSpec.getCollectionType().substring(colSpec.getCollectionType().lastIndexOf('.') + 1)); } @Override public List<ComboBoxValue<String>> getItemList() { List<ComboBoxValue<String>> comboBoxValues = new ArrayList<>(); value.addAll(em.getCache().getCollectionClasses()); em.getCache().getCollectionClasses().stream().filter(StringUtils::isNotEmpty) .forEach((collection) -> { Class _class; try { _class = Class.forName(collection); comboBoxValues.add(new ComboBoxValue(_class.getName(), _class.getSimpleName())); } catch (ClassNotFoundException ex) { comboBoxValues.add(new ComboBoxValue(collection, collection + "(Not Exist)")); } }); return comboBoxValues; } @Override public String getDefaultText() { return EMPTY; } @Override public ActionHandler getActionHandler() { return ActionHandler.getInstance(() -> { String collectionType = NBModelerUtil.browseClass(modelerFile); try { if (Collection.class.isAssignableFrom(Class.forName(collectionType)) || Map.class.isAssignableFrom(Class.forName(collectionType))) { return new ComboBoxValue<>(collectionType, collectionType.substring(collectionType.lastIndexOf('.') + 1)); } } catch (ClassNotFoundException ex) { } throw new IllegalStateException("Invalid Collection/Map type"); }).afterCreation(e -> em.getCache().addCollectionClass(e.getValue())) .afterDeletion(e -> em.getCache().getCollectionClasses().remove(e.getValue())) .beforeDeletion( () -> JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), "Are you sue you want to delete this collection class ?", "Delete Collection Class", JOptionPane.OK_CANCEL_OPTION)); } }; return new ComboBoxPropertySupport(modelerScene.getModelerFile(), "collectionType", "Collection Type", "", comboBoxListener); }
From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a username and password./* w w w. j av a 2s . c om*/ * @param topframe the parent frame * @return the list of user[index 1] and password[index 2], or 'null' if cancel was pressed */ public static ArrayList<String> askForUserAndPassword(final Frame topframe) { ArrayList<String> userAndPass = new ArrayList<String>(); //get remote prefs AppPreferences remotePrefs = AppPreferences.getRemote(); //get remote password String remoteUsername = remotePrefs.get("settings.email.username", null); //$NON-NLS-1$ PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel plabel = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JLabel ulabel = createI18NFormLabel("EMailHelper.USERNAME"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JTextField userField = createTextField(remoteUsername, 25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(ulabel, cc.xy(1, 1)); builder.add(userField, cc.xy(3, 1)); builder.add(plabel, cc.xy(1, 3)); builder.add(passField, cc.xy(3, 3)); builder.add(savePassword, cc.xy(3, 5)); Integer option = JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), JOptionPane.OK_CANCEL_OPTION, //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); String userText = new String(userField.getText()); if (savePassword.isSelected()) { if (StringUtils.isNotEmpty(passwordText)) { remotePrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } if (option == JOptionPane.CANCEL_OPTION) { return null; } //else userAndPass.add(0, userText); userAndPass.add(1, passwordText); return userAndPass; }
From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void reinitializeGroovyClipboardFormatters() { String dialogTitle = "Reinitialize example groovy clipboard formatters?"; String message = "This overwrites all example groovy clipboard formatters. Other clipboard formatters are not changed!\nReinitialize example groovy clipboard formatters right now?"; int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows if (JOptionPane.OK_OPTION != result) { return;/* ww w . j a v a2 s . c om*/ } applicationPreferences.installExampleClipboardFormatters(); }
From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java
private void install(String downloadUrl) { Double vNum = 0.0;//from w ww . ja v a 2 s. c o m if (appVersion != null) { vNum = Double.parseDouble(appVersion); } String installerPath = getInstallerName(downloadUrl); if (os.contains("windows")) { try { Runtime.getRuntime().exec("msiexec /i \"" + installerPath + "\""); } catch (Exception e) { e.printStackTrace(); } } else if (os.startsWith("mac")) { try { Runtime.getRuntime().exec(new String[] { "/usr/bin/open", installerPath }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { JLabel pwLabel = new JLabel("Sudo Password"); JTextField password = new JPasswordField(); Object[] objs = { pwLabel, password }; int result = JOptionPane.showConfirmDialog(null, objs, "Please enter a sudo password", JOptionPane.OK_CANCEL_OPTION); String pas = null; if (result == JOptionPane.OK_OPTION) { pas = password.getText(); } if (pas != null) { if (os.equals("CentOS")) { // sudo yum install TCIADownloader-1.0-1.x86_64.rpm try { String upgradCmd = "/usr/bin/sudo -S yum -q -y remove TCIADownloader.x86_64;/usr/bin/sudo -S yum -y -q install "; if (vNum >= 3.2) upgradCmd = "/usr/bin/sudo -S yum -q -y remove NBIADataRetriever.x86_64;/usr/bin/sudo -S yum -y -q install "; String[] cmd = { "/bin/bash", "-c", upgradCmd + installerPath }; Process pb = Runtime.getRuntime().exec(cmd); BufferedWriter writer = null; writer = new BufferedWriter(new OutputStreamWriter(pb.getOutputStream())); writer.write(pas); writer.write('\n'); writer.flush(); String status = null; if (pb.waitFor() == 0) { status = "successfully"; } else { status = "unsuccessfully"; } JOptionPane.showMessageDialog(null, "Installation of new version of NBIA Data Retriever is completed " + status + "."); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (os.equals("Ubuntu")) { // sudo dpkg -i tciadownloader_1.0-2_amd64.deb String upgradCmd = "/usr/bin/sudo -S dpkg -i "; if (vNum >= 3.2) upgradCmd = "/usr/bin/sudo -S dpkg -i nbia-data-retriever; /usr/bin/sudo -S dpkg -i "; try { String[] cmd = { "/bin/bash", "-c", upgradCmd + installerPath }; Process pb = Runtime.getRuntime().exec(cmd); BufferedWriter writer = null; writer = new BufferedWriter(new OutputStreamWriter(pb.getOutputStream())); writer.write(pas); writer.write('\n'); writer.flush(); String status = null; if (pb.waitFor() == 0) { status = "successfully"; } else { status = "unsuccessfully"; } JOptionPane.showMessageDialog(null, "Installation of new version of NBIA Data Retriever is completed " + status + "."); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }