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:pl.otros.logview.gui.actions.ConnectToSocketHubAppenderAction.java
private boolean chooseLogImporter() { DataConfiguration configuration = getOtrosApplication().getConfiguration(); List<Object> list1 = configuration.getList(ConfKeys.SOCKET_HUB_APPENDER_ADDRESSES); configuration.getInt(ConfKeys.SOCKET_HUB_APPENDER_ADDRESSES_MAX_COUNT, 20); Vector<String> recent = new Vector<String>(); for (Object o : list1) { recent.add(o.toString());// w w w .j a v a2 s .c o m } JXComboBox box = new JXComboBox(recent); box.setEditable(true); AutoCompleteDecorator.decorate(box); MigLayout migLayout = new MigLayout(); JPanel panel = new JPanel(migLayout); panel.add(new JLabel("Host name:port")); panel.add(box, "wrap, width 200:220:440"); while (true) { String[] options = { "Connect", "Cancel" }; int showConfirmDialog = JOptionPane.showOptionDialog(getOtrosApplication().getApplicationJFrame(), panel, "Enter host name and port", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (showConfirmDialog != JOptionPane.OK_OPTION) { return false; } try { String hostAndPortString = box.getSelectedItem().toString().trim(); socket = tryToConnectToSocket(configuration, hostAndPortString, SocketFactory.getDefault()); } catch (UnknownHostException e) { JOptionPane.showMessageDialog(panel, host + " is unknown host name", "Error", JOptionPane.ERROR_MESSAGE); continue; } catch (IOException e) { JOptionPane.showMessageDialog(panel, "Cannot connect to host " + host + ":" + port, "Error", JOptionPane.ERROR_MESSAGE); continue; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(panel, "Can't parse port number.", "Error", JOptionPane.ERROR_MESSAGE); continue; } return true; } }
From source file:pl.otros.vfs.browser.auth.AbstractUiUserAuthenticator.java
@Override public UserAuthenticationData requestAuthentication(Type[] types) { try {/*from w w w. ja v a 2 s . co m*/ Runnable doRun = new Runnable() { @Override public void run() { if (saveCredentialsCheckBox == null) { saveCredentialsCheckBox = new JCheckBox(Messages.getMessage("authenticator.savePassword"), true); } JPanel authOptionPanel = getOptionsPanel(); JPanel panel = new JPanel(new BorderLayout()); panel.add(authOptionPanel); panel.add(saveCredentialsCheckBox, BorderLayout.SOUTH); String[] options = { Messages.getMessage("general.okButtonText"), Messages.getMessage("general.cancelButtonText") }; int showConfirmDialog = JOptionPane.showOptionDialog(null, panel, Messages.getMessage("authenticator.enterCredentials"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (showConfirmDialog != JOptionPane.OK_OPTION) { throw new AuthorisationCancelledException("Authorization cancelled by user"); } data = new UserAuthenticationDataWrapper(); getAuthenticationData(data); } }; if (SwingUtilities.isEventDispatchThread()) { doRun.run(); } else { SwingUtilities.invokeAndWait(doRun); } } catch (Exception e) { if (Throwables.getRootCause(e) instanceof AuthorisationCancelledException) { throw (AuthorisationCancelledException) Throwables.getRootCause(e); } } return data; }
From source file:processing.app.Editor.java
/** * Second stage of open, occurs after having checked to see if the * modifications (if any) to the previous sketch need to be saved. *///from w ww . j a v a2s . c o m protected boolean handleOpenInternal(File sketchFile) { // check to make sure that this .pde file is // in a folder of the same name String fileName = sketchFile.getName(); File file = SketchData.checkSketchFile(sketchFile); if (file == null) { if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { Base.showWarning(_("Bad file selected"), _("Arduino can only open its own sketches\n" + "and other files ending in .ino or .pde"), null); return false; } else { String properParent = fileName.substring(0, fileName.length() - 4); Object[] options = { _("OK"), _("Cancel") }; String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" + "a sketch folder named \"{1}\".\n" + "Create this folder, move the file, and continue?"), fileName, properParent); int result = JOptionPane.showOptionDialog(this, prompt, _("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { // create properly named folder File properFolder = new File(sketchFile.getParent(), properParent); if (properFolder.exists()) { Base.showWarning(_("Error"), I18n.format(_("A folder named \"{0}\" already exists. " + "Can't open sketch."), properParent), null); return false; } if (!properFolder.mkdirs()) { //throw new IOException("Couldn't create sketch folder"); Base.showWarning(_("Error"), _("Could not create the sketch folder."), null); return false; } // copy the sketch inside File properPdeFile = new File(properFolder, sketchFile.getName()); try { Base.copyFile(sketchFile, properPdeFile); } catch (IOException e) { Base.showWarning(_("Error"), _("Could not copy to a proper location."), e); return false; } // remove the original file, so user doesn't get confused sketchFile.delete(); // update with the new path file = properPdeFile; } else if (result == JOptionPane.NO_OPTION) { return false; } } } try { sketch = new Sketch(this, file); } catch (IOException e) { Base.showWarning(_("Error"), _("Could not create the sketch."), e); return false; } header.rebuild(); setTitle(I18n.format(_("{0} | Arduino {1}"), sketch.getName(), BaseNoGui.VERSION_NAME_LONG)); // Disable untitled setting from previous document, if any untitled = false; // opening was successful return true; // } catch (Exception e) { // e.printStackTrace(); // statusError(e); // return false; // } }
From source file:processing.app.Editor.java
/** * Checks to see if the sketch has been modified, and if so, * asks the user to save the sketch or cancel the export. * This prevents issues where an incomplete version of the sketch * would be exported, and is a fix for//from w ww.java 2 s . c o m * <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=157">Bug 157</A> */ protected boolean handleExportCheckModified() { if (!sketch.isModified()) return true; Object[] options = { _("OK"), _("Cancel") }; int result = JOptionPane.showOptionDialog(this, _("Save changes before export?"), _("Save"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.OK_OPTION) { handleSave(true); } else { // why it's not CANCEL_OPTION is beyond me (at least on the mac) // but f-- it.. let's get this shite done.. //} else if (result == JOptionPane.CANCEL_OPTION) { statusNotice(_("Export canceled, changes must first be saved.")); //toolbar.clear(); return false; } return true; }
From source file:processing.app.Sketch.java
/** * Remove a piece of code from the sketch and from the disk. *//*from w ww . j av a 2s . c o m*/ public void handleDeleteCode() throws IOException { editor.status.clearState(); // make sure the user didn't hide the sketch folder ensureExistence(); // if read-only, give an error if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { // if the files are read-only, need to first do a "save as". Base.showMessage(tr("Sketch is Read-Only"), tr("Some files are marked \"read-only\", so you'll\n" + "need to re-save the sketch in another location,\n" + "and try again.")); return; } // confirm deletion with user, yes/no Object[] options = { tr("OK"), tr("Cancel") }; String prompt = (currentIndex == 0) ? tr("Are you sure you want to delete this sketch?") : I18n.format(tr("Are you sure you want to delete \"{0}\"?"), current.getCode().getFileNameWithExtensionIfNotIno()); int result = JOptionPane.showOptionDialog(editor, prompt, tr("Delete"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { if (currentIndex == 0) { // need to unset all the modified flags, otherwise tries // to do a save on the handleNew() // delete the entire sketch Base.removeDir(data.getFolder()); // get the changes into the sketchbook menu //sketchbook.rebuildMenus(); // make a new sketch, and i think this will rebuild the sketch menu //editor.handleNewUnchecked(); //editor.handleClose2(); editor.base.handleClose(editor); } else { // delete the file if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data))) { Base.showMessage(tr("Couldn't do it"), I18n.format(tr("Could not delete \"{0}\"."), current.getCode().getFileName())); return; } // remove code from the list data.removeCode(current.getCode()); // just set current tab to the main tab setCurrentCode(0); // update the tabs editor.header.repaint(); } } }
From source file:processing.app.Sketch.java
/** * Save all code in the current sketch./*w w w . j a va2 s .co m*/ */ public boolean save() throws IOException { // make sure the user didn't hide the sketch folder ensureExistence(); // first get the contents of the editor text area if (current.getCode().isModified()) { current.getCode().setProgram(editor.getText()); } // don't do anything if not actually modified //if (!modified) return false; if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { Base.showMessage(tr("Sketch is read-only"), tr("Some files are marked \"read-only\", so you'll\n" + "need to re-save this sketch to another location.")); return saveAs(); } // rename .pde files to .ino File mainFile = new File(getMainFilePath()); File mainFolder = mainFile.getParentFile(); File[] pdeFiles = mainFolder.listFiles((dir, name) -> { return name.toLowerCase().endsWith(".pde"); }); if (pdeFiles != null && pdeFiles.length > 0) { if (PreferencesData.get("editor.update_extension") == null) { Object[] options = { tr("OK"), tr("Cancel") }; int result = JOptionPane.showOptionDialog(editor, tr("In Arduino 1.0, the default file extension has changed\n" + "from .pde to .ino. New sketches (including those created\n" + "by \"Save-As\") will use the new extension. The extension\n" + "of existing sketches will be updated on save, but you can\n" + "disable this in the Preferences dialog.\n" + "\n" + "Save sketch and update its extension?"), tr(".pde -> .ino"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result != JOptionPane.OK_OPTION) return false; // save cancelled PreferencesData.setBoolean("editor.update_extension", true); } if (PreferencesData.getBoolean("editor.update_extension")) { // Do rename of all .pde files to new .ino extension for (File pdeFile : pdeFiles) renameCodeToInoExtension(pdeFile); } } data.save(); calcModified(); return true; }
From source file:processing.app.Sketch.java
/** * Add a file to the sketch./*from w w w . ja v a 2 s . co m*/ * <p/> * .pde or .java files will be added to the sketch folder. <br/> * .jar, .class, .dll, .jnilib, and .so files will all * be added to the "code" folder. <br/> * All other files will be added to the "data" folder. * <p/> * If they don't exist already, the "code" or "data" folder * will be created. * <p/> * @return true if successful. */ public boolean addFile(File sourceFile) { String filename = sourceFile.getName(); File destFile = null; String codeExtension = null; boolean replacement = false; // if the file appears to be code related, drop it // into the code folder, instead of the data folder if (filename.toLowerCase().endsWith(".o") || filename.toLowerCase().endsWith(".a") || filename.toLowerCase().endsWith(".so")) { //if (!codeFolder.exists()) codeFolder.mkdirs(); prepareCodeFolder(); destFile = new File(data.getCodeFolder(), filename); } else { for (String extension : SketchData.EXTENSIONS) { String lower = filename.toLowerCase(); if (lower.endsWith("." + extension)) { destFile = new File(data.getFolder(), filename); codeExtension = extension; } } if (codeExtension == null) { prepareDataFolder(); destFile = new File(data.getDataFolder(), filename); } } // check whether this file already exists if (destFile.exists()) { Object[] options = { tr("OK"), tr("Cancel") }; String prompt = I18n.format(tr("Replace the existing version of {0}?"), filename); int result = JOptionPane.showOptionDialog(editor, prompt, tr("Replace"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { replacement = true; } else { return false; } } // If it's a replacement, delete the old file first, // otherwise case changes will not be preserved. // http://dev.processing.org/bugs/show_bug.cgi?id=969 if (replacement) { boolean muchSuccess = destFile.delete(); if (!muchSuccess) { Base.showWarning(tr("Error adding file"), I18n.format(tr("Could not delete the existing ''{0}'' file."), filename), null); return false; } } // make sure they aren't the same file if ((codeExtension == null) && sourceFile.equals(destFile)) { Base.showWarning(tr("You can't fool me"), tr("This file has already been copied to the\n" + "location from which where you're trying to add it.\n" + "I ain't not doin nuthin'."), null); return false; } // in case the user is "adding" the code in an attempt // to update the sketch's tabs if (!sourceFile.equals(destFile)) { try { Base.copyFile(sourceFile, destFile); } catch (IOException e) { Base.showWarning(tr("Error adding file"), I18n.format(tr("Could not add ''{0}'' to the sketch."), filename), e); return false; } } if (codeExtension != null) { SketchCode newCode = (new SketchCodeDocument(this, destFile)).getCode(); if (replacement) { data.replaceCode(newCode); } else { ensureExistence(); data.addCode(newCode); data.sortCode(); } setCurrentCode(filename); editor.header.repaint(); if (editor.untitled) { // TODO probably not necessary? problematic? // Mark the new code as modified so that the sketch is saved current.getCode().setModified(true); } } else { if (editor.untitled) { // TODO probably not necessary? problematic? // If a file has been added, mark the main code as modified so // that the sketch is properly saved. data.getCode(0).setModified(true); } } return true; }
From source file:processing.app.UpdateCheck.java
public void run() { //System.out.println("checking for updates..."); // generate a random id in case none exists yet Random r = new Random(); long id = r.nextLong(); String idString = PreferencesData.get("update.id"); if (idString != null) { id = Long.parseLong(idString); } else {/* w w w . j a va2 s. co m*/ PreferencesData.set("update.id", String.valueOf(id)); } try { String info; info = URLEncoder.encode( id + "\t" + PApplet.nf(BaseNoGui.REVISION, 4) + "\t" + System.getProperty("java.version") + "\t" + System.getProperty("java.vendor") + "\t" + System.getProperty("os.name") + "\t" + System.getProperty("os.version") + "\t" + System.getProperty("os.arch"), "UTF-8"); int latest = readInt(downloadURL + "?" + info); String lastString = PreferencesData.get("update.last"); long now = System.currentTimeMillis(); if (lastString != null) { long when = Long.parseLong(lastString); if (now - when < ONE_DAY) { // don't annoy the shit outta people return; } } PreferencesData.set("update.last", String.valueOf(now)); String prompt = tr("A new version of Arduino is available,\n" + "would you like to visit the Arduino download page?"); if (base.activeEditor != null) { if (latest > BaseNoGui.REVISION) { Object[] options = { tr("Yes"), tr("No") }; int result = JOptionPane.showOptionDialog(base.activeEditor, prompt, tr("Update"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { Base.openURL(tr("http://www.arduino.cc/en/Main/Software")); } } } } catch (Exception e) { //e.printStackTrace(); //System.err.println("Error while trying to check for an update."); } }
From source file:project5.Panels.SearchPanel.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: Object[] options = { "OK" }; int n = JOptionPane.showOptionDialog(this, "A notification has been sent to lender for confirmation.", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options); jButton2.setText("Pending"); }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed File toDelete = new File("pluginClasses"); String[] deleteArray = toDelete.list(); if (deleteArray != null) { for (String fileName : deleteArray) { File f = new File("pluginClasses/" + fileName); f.delete();//from w w w . j ava2 s. c om } } if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) { Object[] opt = { "Save", "Discard", "Cancel" }; String message = "There are unsaved Server Settings.\nDo you want to save them?"; int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]); if (op == 0) { AdminRefs.getInstance().saveSettings(); } if (op == 2) { return; } } if (ClientOptions.getInstance().unsavedSettings()) { Object[] opt = { "Save", "Discard", "Cancel" }; String message = "There are unsaved Client Settings.\nDo you want to save them?"; int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]); if (op == 0) { ClientOptions.getInstance().saveSettings(); } if (op == 2) { return; } } QueryHistorySupport.getInstance().saveQueryHistory(); if (clientCore.isAdmin()) { AdminRefs.getInstance().shutdownServer(); } System.exit(0); }