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:net.sf.jabref.EntryEditor.java
public boolean storeSource(boolean showError) { // Store edited bibtex code. BibtexParser bp = new BibtexParser(new StringReader(source.getText())); try {//from www. jav a 2s. c om BibtexDatabase db = bp.parse().getDatabase(); if (db.getEntryCount() > 1) { throw new RuntimeException("More than one entry found."); } if (db.getEntryCount() < 1) { throw new RuntimeException("No entries found."); } BibtexEntry newEntry = db.getEntryById(db.getKeySet().iterator().next()); int id = entry.getId(); String newKey = newEntry.getCiteKey(); boolean hasChangesBetweenCurrentAndNew = false; boolean changedType = false; boolean duplicateWarning = false; boolean emptyWarning = StringUtils.isEmpty(newKey); if (panel.database.setCiteKeyForEntry(id, newKey)) { duplicateWarning = true; } NamedCompound compound = new NamedCompound(Globals.lang("source edit")); // First, remove fields that the user have removed (and add undo information to revert it if necessary) for (String fieldName : entry.getAllFields()) { String oldValue = entry.getField(fieldName); String newValue = newEntry.getField(fieldName); if (newValue == null) { compound.addEdit(new UndoableFieldChange(entry, fieldName, oldValue, null)); entry.clearField(fieldName); hasChangesBetweenCurrentAndNew = true; } } // Then set all fields that have been set by the user. for (String fieldName : newEntry.getAllFields()) { String oldValue = entry.getField(fieldName); String newValue = newEntry.getField(fieldName); if (newValue != null && !newValue.equals(oldValue)) { LatexFieldFormatter lff = new LatexFieldFormatter(); lff.format(newValue, fieldName); compound.addEdit(new UndoableFieldChange(entry, fieldName, oldValue, newValue)); entry.setField(fieldName, newValue); hasChangesBetweenCurrentAndNew = true; } } // See if the user has changed the entry type: if (newEntry.getType() != entry.getType()) { compound.addEdit(new UndoableChangeType(entry, entry.getType(), newEntry.getType())); entry.setType(newEntry.getType()); hasChangesBetweenCurrentAndNew = true; changedType = true; } compound.end(); if (!hasChangesBetweenCurrentAndNew) { return true; } panel.undoManager.addEdit(compound); if (duplicateWarning) { warnDuplicateBibtexkey(); } else if (emptyWarning && showError) { warnEmptyBibtexkey(); } else { panel.output(Globals.lang("Stored entry") + "."); } lastAcceptedSourceString = source.getText(); if (!changedType) { updateAllFields(); lastSourceAccepted = true; shouldUpdateSourcePanel = true; } else { panel.updateEntryEditorIfShowing(); // We will throw away the current EntryEditor, so we do not have to update it } // TODO: does updating work properly after source stored? // panel.tableModel.remap(); // panel.entryTable.repaint(); // panel.refreshTable(); panel.markBaseChanged(); SwingUtilities.invokeLater(new Runnable() { public void run() { final int row = panel.mainTable.findEntry(entry); if (row >= 0) { //if (panel.mainTable.getSelectedRowCount() == 0) // panel.mainTable.setRowSelectionInterval(row, row); //scrollTo(row); panel.mainTable.ensureVisible(row); } } }); return true; } catch (Throwable ex) { ex.printStackTrace(); // The source couldn't be parsed, so the user is given an // error message, and the choice to keep or revert the contents // of the source text field. shouldUpdateSourcePanel = false; lastSourceAccepted = false; tabbed.setSelectedComponent(srcPanel); if (showError) { Object[] options = { Globals.lang("Edit"), Globals.lang("Revert to original source") }; int answer = JOptionPane.showOptionDialog(frame, Globals.lang("Error") + ": " + ex.getMessage(), Globals.lang("Problem with parsing entry"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (answer != 0) { shouldUpdateSourcePanel = true; updateSource(); } } return false; } }
From source file:com.sec.ose.osi.ui.frm.main.identification.patternmatch.JPanPatternMatchMain.java
public UEPatternMatch exportUIEntity(String projectName) { String currentComponentName = ""; String newComponentName = ""; String newLicenseName = getSelectedLicenseName(); SelectedFilePathInfo selectedPaths = IdentifyMediator.getInstance().getSelectedFilePathInfo(); boolean bFile = selectedPaths.isFile(); String selectedPath = selectedPaths.getSelectedPath(); if (bFile) {//from ww w .j av a2s . c o m currentComponentName = IdentificationDBManager.getComponentNameForPatternMatchFile(projectName, selectedPath); } else { currentComponentName = IdentificationDBManager.getComponentNameForPatternMatchResetFolder(projectName, selectedPath); } int status = IdentificationDBManager.getStatusForPatternMatch(projectName, selectedPath); if (rdbtnItsLibraryWhich.isSelected()) { newComponentName = "DECLARED_PROPRIETARY_LIBRARY"; } else if (rdbtnThird.isSelected()) { newComponentName = "DECLARED_THIRDPARTY_LIBRARY"; } else if (rdbtnIKnowThe.isSelected()) { if (status == AbstractMatchInfo.STATUS_PENDING && getJComboBoxLicenseForOpt3().getSelectedItem() == null) { JOptionPane.showOptionDialog(null, "\"License\" Field must be non-empty.", "Pending identification", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK"); return null; } if (status == AbstractMatchInfo.STATUS_PENDING && LicenseAPIWrapper.getLicenseID(newLicenseName) == null) { JOptionPane.showOptionDialog(null, "The license name (" + newLicenseName + ") does not exist in Protex Server. " + "\nPlease correct the license name.", "Pending identification", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK"); return null; } if ((getSelectedComponentName()).length() > 0) { newComponentName = getSelectedComponentName(); } else { newComponentName = (String) cbPmBindType.getSelectedItem() + "_" + IdentifyMediator.getInstance().getSelectedLicenseName(); } } if (currentComponentName == null) currentComponentName = ""; if (newLicenseName == null) newLicenseName = ""; UEPatternMatch xUEPatternMatch = new UEPatternMatch(currentComponentName, newComponentName, newLicenseName); return xUEPatternMatch; }
From source file:com.pironet.tda.TDA.java
private void saveSession() { initSessionFc();//from ww w . j a v a2s . c o m int returnVal = sessionFc.showSaveDialog(this.getRootPane()); sessionFc.setPreferredSize(sessionFc.getSize()); PrefManager.get().setPreferredSizeFileChooser(sessionFc.getSize()); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = sessionFc.getSelectedFile(); // check if file has a suffix if (!file.getName().contains(".")) { file = new File(file.getAbsolutePath() + ".tsf"); } int selectValue = 0; if (file.exists()) { Object[] options = { "Overwrite", "Cancel" }; selectValue = JOptionPane.showOptionDialog(null, "<html><body>File exists<br><b>" + file + "</b></body></html>", "Confirm overwrite", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } if (selectValue == 0) { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(file))); oos.writeObject(dumpFile); oos.writeObject(topNodes); oos.writeObject(dumpStore); } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(oos); } PrefManager.get().addToRecentSessions(file.getAbsolutePath()); } } }
From source file:com.paniclauncher.data.Settings.java
public void rotateLogFiles() { File logFile1 = new File(getBaseDir(), "PanicLauncher-Log-1.txt"); File logFile2 = new File(getBaseDir(), "PanicLauncher-Log-2.txt"); File logFile3 = new File(getBaseDir(), "PanicLauncher-Log-3.txt"); if (logFile3.exists()) { Utils.delete(logFile3);/*from ww w . j a v a2 s. c om*/ } if (logFile2.exists()) { logFile2.renameTo(logFile3); } if (logFile1.exists()) { logFile1.renameTo(logFile2); } try { logFile1.createNewFile(); } catch (IOException e) { String[] options = { "OK" }; JOptionPane.showOptionDialog(null, "<html><center>Cannot create the log file.<br/><br/>Make sure" + " you are running the Launcher from somewhere with<br/>write" + " permissions for your user account such as your Home/Users folder" + " or desktop.</center></html>", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); System.exit(0); } }
From source file:Citas.FrameCita.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == agregarB) { try {/*ww w . j av a 2 s . c o m*/ //Cita JSONObject cita = new JSONObject(); cita.put("fecha", fechaJ.getText()); cita.put("hora", horaJ.getText()); cita.put("paciente", 3); cita.put("medicos", "1"); cita.put("tratamiento", "tratamiento"); cita.put("diagnostico", "diagnostico"); cita.put("motivo", motivosTA.getText()); System.out.print(cita); //Paciente JSONObject paciente = new JSONObject(); paciente.put("cedula", cedulaJ.getText()); paciente.put("nombre", nombreJ.getText()); paciente.put("apellido", apellidoJ.getText()); paciente.put("direccion", direccionJ.getText()); paciente.put("correo", correoJ.getText()); paciente.put("tlfncasa", telefonoCasaJ.getText()); paciente.put("tlfncelular", telefonoCelularJ.getText()); System.out.print(paciente); //rutasAdd.add("http://localhost/API_Citas/public/Pacientes/insertarPaciente", paciente); rutasAdd.add("http://localhost/API_Citas/public/Citas/insertarCita", cita); setCitas(); } catch (IOException ex) { Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex); } catch (java.text.ParseException ex) { Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex); } return; } if (e.getSource() == modificarB) { return; } if (e.getSource() == eliminarB) { return; } if (e.getSource() == atrasB) { } if (e.getSource() == buscarB) { String[] opciones = { "Aceptar" }; int opcion = JOptionPane.showOptionDialog(null //componente , "Cedula no pertenece a ningun paciente registrado" // Mensaje , "Paciente no encontrado" // Titulo en la barra del cuadro , JOptionPane.DEFAULT_OPTION // Tipo de opciones , JOptionPane.WARNING_MESSAGE // Tipo de mensaje (icono) , null // Icono (ninguno) , opciones // Opciones personalizadas , null // Opcion por defecto ); } }
From source file:org.fhaes.jsea.JSEAFrame.java
private void launchLagMap() { Object[] options = { "Yes", "No", "Cancel" }; int n = JOptionPane.showOptionDialog(this, "LagMap is an interactive web application written by Wendy Gross and run within your web browser.\nWould you like to continue?", "Lauch LagMap", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);/*from ww w . j a v a 2s . c om*/ if (n == JOptionPane.YES_OPTION) Platform.browseWebpage(RemoteHelp.LAUNCH_LAG_MAP, this); }
From source file:DragDropTreeExample.java
protected void transferFile(int action, File srcFile, File targetDirectory, FileTree.FileTreeNode targetNode) { DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " file " + srcFile.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath()); // Create a File entry for the target String name = srcFile.getName(); File newFile = new File(targetDirectory, name); if (newFile.exists()) { // Already exists - is it the same file? if (newFile.equals(srcFile)) { // Exactly the same file - ignore return; }//from www. ja v a 2 s . com // File of this name exists in this directory if (copyOverExistingFiles == false) { int res = JOptionPane.showOptionDialog(tree, "A file called\n " + name + "\nalready exists in the directory\n " + targetDirectory.getAbsolutePath() + "\nOverwrite it?", "File Exists", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Yes", "Yes to All", "No", "Cancel" }, "No"); switch (res) { case 1: // Yes to all copyOverExistingFiles = true; case 0: // Yes break; case 2: // No return; default: // Cancel throw new IllegalStateException("Cancelled"); } } } else { // New file - create it try { newFile.createNewFile(); } catch (IOException e) { JOptionPane.showMessageDialog(tree, "Failed to create new file\n " + newFile.getAbsolutePath(), "File Creation Failed", JOptionPane.ERROR_MESSAGE); return; } } // Copy the data and close file. BufferedInputStream is = null; BufferedOutputStream os = null; try { is = new BufferedInputStream(new FileInputStream(srcFile)); os = new BufferedOutputStream(new FileOutputStream(newFile)); int size = 4096; byte[] buffer = new byte[size]; int len; while ((len = is.read(buffer, 0, size)) > 0) { os.write(buffer, 0, len); } } catch (IOException e) { JOptionPane.showMessageDialog(tree, "Failed to copy file\n " + name + "\nto directory\n " + targetDirectory.getAbsolutePath(), "File Copy Failed", JOptionPane.ERROR_MESSAGE); return; } finally { try { if (is != null) { is.close(); } if (os != null) { os.close(); } } catch (IOException e) { } } // Remove the source if this is a move operation. if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) { srcFile.delete(); } // Update the tree display if (targetNode != null) { tree.addNode(targetNode, name); } }
From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java
/** * @param appResName//w ww .ja v a 2s. co m * @param tableid * @return AppResource with the provided name. * * If a resource named appResName exists it will be returned, else a new resource is created. */ private static AppResAndProps getAppRes(final String appResName, final Integer tableid, final boolean confirmOverwrite) { AppResourceIFace resApp = AppContextMgr.getInstance().getResource(appResName); if (resApp != null) { if (!confirmOverwrite) { return new AppResAndProps(resApp, null); } //else int option = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), String.format(UIRegistry.getResourceString("REP_CONFIRM_IMP_OVERWRITE"), resApp.getName()), UIRegistry.getResourceString("REP_CONFIRM_IMP_OVERWRITE_TITLE"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); if (option == JOptionPane.YES_OPTION) { return new AppResAndProps(resApp, null); } //else return null; } //else return createAppResAndProps(appResName, tableid, null); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
public void unlinkSelectedServers() { final Collection<Server> selectedServers = serverList.getSelectedServers(); final String unlinkString = "Unlink " + selectedServers.size() + " servers"; final int result = JOptionPane.showOptionDialog(this, "You are about to unlink " + selectedServers.size() + " server(s).\n" + "Unlinked servers are not terminated and will keep running.", unlinkString, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, Arrays.asList(unlinkString, "Cancel").toArray(), "Cancel"); if (result != JOptionPane.OK_OPTION) { return;//w w w .j a v a 2 s . co m } for (final Server server : selectedServers) { server.unlink(); } }
From source file:course_generator.param.frmEditCurve.java
/** * Delete the selected curve// ww w.j a va 2 s . co m */ protected void DeleteCurve() { if (!bEditMode) { int index = ListCurves.getSelectedIndex(); if (index >= 0) { String s = Paramfile = (String) model.getElementAt(index); if (s.toUpperCase() != "DEFAULT") { Object[] options = { " " + bundle.getString("frmEditCurve.DeleteYes") + " ", " " + bundle.getString("frmEditCurve.DeleteNo") + " " }; int ret = JOptionPane.showOptionDialog(this, bundle.getString("frmEditCurve.DeleteCurveMessage"), bundle.getString("frmEditCurve.DeleteCurveTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (ret == JOptionPane.YES_OPTION) { File f = new File(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + s + ".par"); f.delete(); LoadCurve(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/default.par"); Paramfile = "Default"; RefreshView(); RefreshCurveList(); } } } } }