List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:model.settings.ReadSettings.java
private static boolean checkForUpdate(final View _view, final boolean _showNoUpdateMSG) { try {/*from w ww. j a v a2 s. co m*/ // Create a URL for the desired page URL url = new URL("http://juliushuelsmann.github.io/paint/currentRelease"); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String version = in.readLine(); in.close(); final String[] result = Version.getMilestonePercentageDone(version); if (result == null) { // error return false; } final String MS = result[0]; final String perc = result[1]; try { // parse information to integer. int new_milestone = Integer.parseInt(MS); int new_percentage = Integer.parseInt(perc); int crrnt_milestone = Integer.parseInt(Version.MILESTONE); int crrnt_percentage = Integer.parseInt(Version.PERCENTAGE_DONE); if (new_milestone > crrnt_milestone || (new_percentage > crrnt_percentage && new_milestone == crrnt_milestone)) { int d = JOptionPane.showConfirmDialog(_view, "A new version of paint has been found:\n" + "Used Version:\t" + "" + crrnt_milestone + "." + "" + crrnt_percentage + "\n" + "New Version:\t" + "" + new_milestone + "." + "" + new_percentage + "\n\n" + "Do you want to download it right now? \n" + "This operation will close paint and restart \n" + "the new version in about one minute.", "Update", JOptionPane.YES_NO_OPTION); return d == JOptionPane.YES_OPTION; } else { if (_showNoUpdateMSG) { JOptionPane.showMessageDialog(_view, "No updates found.", "Update", JOptionPane.INFORMATION_MESSAGE); } return false; } } catch (NumberFormatException _nex) { // received version number corrupted. final String err_msg = "Failed to check for updates, \n" + "the fetched version number is currupted.\n" + "This error is server-related and will be \n" + "fixed after it has been noticed by the \n" + "programmer ;)."; // report error via logger. model.settings.State.getLogger().severe(err_msg); // notify the user if this the message call isn't silent. if (_showNoUpdateMSG) { JOptionPane.showMessageDialog(_view, err_msg, "Update", JOptionPane.INFORMATION_MESSAGE); } return false; } } catch (Exception e) { // update page not found, probably due to network problems. final String err_msg = "Connection to update page failed. \n" + "Either you are not corrected to the internet or \n" + "the update page has been removed accidently. \n" + "If you are able to connect to any other web-page,\n" + "the error is server-related and will be \n" + "fixed after being noticed by the \n" + "programmer ;)."; // report error via logger. State.getLogger().warning(err_msg); // notify the user if this the message call isn't silent. if (_showNoUpdateMSG) { JOptionPane.showMessageDialog(_view, err_msg, "Update", JOptionPane.INFORMATION_MESSAGE); } return false; } }
From source file:DialogDemo.java
/** Creates the reusable dialog. */ public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) { super(aFrame, true); dd = parent;/* w w w. j av a2 s .c om*/ magicWord = aWord.toUpperCase(); setTitle("Quiz"); textField = new JTextField(10); // Create an array of the text and components to be displayed. String msgString1 = "What was Dr. SEUSS's real last name?"; String msgString2 = "(The answer is \"" + magicWord + "\".)"; Object[] array = { msgString1, msgString2, textField }; // Create an array specifying the number of dialog buttons // and their text. Object[] options = { btnString1, btnString2 }; // Create the JOptionPane. optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]); // Make this dialog display it. setContentPane(optionPane); // Handle window closing correctly. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { /* * Instead of directly closing the window, we're going to change the * JOptionPane's value property. */ optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } }); // Ensure the text field always gets the first focus. addComponentListener(new ComponentAdapter() { public void componentShown(ComponentEvent ce) { textField.requestFocusInWindow(); } }); // Register an event handler that puts the text into the option pane. textField.addActionListener(this); // Register an event handler that reacts to option pane state changes. optionPane.addPropertyChangeListener(this); }
From source file:serial.ChartFromSerial.java
public void createSerialThread(SerialPort desiredPort) { //Create Serial Scanning Thread serialThread = new Thread() { @Override/*from ww w . j ava 2s .c o m*/ public void run() { try (Scanner serialScanner = new Scanner(desiredPort.getInputStream())) { int numIn; while (serialScanner.hasNextLine()) { String textIn = serialScanner.nextLine(); try { numIn = Integer.parseInt(textIn); defaultSeries.add(samples, numIn); text.append(samples++ + ": " + numIn + "\n"); if (autoScrollEnabled) { text.setCaretPosition(text.getDocument().getLength()); } } catch (NumberFormatException e) { System.out.println("Unexpected value at " + desiredPort.getSystemPortName() + ": \"" + textIn + "\""); } } } catch (Exception e) { System.out.println(e); samples = 0; if (JOptionPane.showConfirmDialog(rootPane, "The serial connection has fialed.\n Would you like to refresh?", "Serial connection failed.", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) { hardRefresh(); defaultSeries.clear(); text.setText(""); } else { buttonsOff(); } } } }; serialThread.start(); }
From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java
private void topngjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topngjButtonActionPerformed // Save chart as a PNG image JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Save chart"); KeelFileFilter fileFilter = new KeelFileFilter(); fileFilter.addExtension("png"); fileFilter.setFilterName("PNG images (.png)"); chooser.setFileFilter(fileFilter);// ww w . java2 s . c o m chooser.setCurrentDirectory(Path.getFilePath()); int opcion = chooser.showSaveDialog(this); Path.setFilePath(chooser.getCurrentDirectory()); if (opcion == JFileChooser.APPROVE_OPTION) { String nombre = chooser.getSelectedFile().getAbsolutePath(); if (!nombre.toLowerCase().endsWith(".png")) { // Add correct extension nombre += ".png"; } File tmp = new File(nombre); if (!tmp.exists() || JOptionPane.showConfirmDialog(this, "File " + nombre + " already exists. Do you want to replace it?", "Confirm", JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) { try { chart2.setBackgroundPaint(Color.white); ChartUtilities.saveChartAsPNG(new File(nombre), chart2, 1024, 768); } catch (Exception exc) { } } } }
From source file:com.proyecto.vista.MantenimientoEmpleado.java
private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed // TODO add your handling code here: List<Integer> array = new ArrayList(); array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.telefonoField, "telefono")); array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoMField, "apellido materno")); array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoPField, "apellido paterno")); array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.nombreField, "nombre")); array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.idField, "DNI")); FormularioUtil.validar2(array);// w w w .ja va2 s . c om if (FormularioUtil.error) { JOptionPane.showMessageDialog(null, FormularioUtil.mensaje, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); FormularioUtil.mensaje = ""; FormularioUtil.error = false; } else { String palabra = ""; String palabra2 = ""; if (accion == 1) { palabra = "registrar"; palabra2 = "registrado"; if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase()); empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase()); empleadoControlador.getSeleccionado() .setApellidoPaterno(apellidoPField.getText().toUpperCase()); empleadoControlador.getSeleccionado() .setApellidoMaterno(apellidoMField.getText().toUpperCase()); empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase()); empleadoControlador.accion(accion); lista.add(empleadoControlador.getSeleccionado()); if (accion == 1) { JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); FormularioUtil.limpiarComponente(panelDatos); } else { JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { FormularioUtil.limpiarComponente(panelDatos); JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else if (accion == 2) { palabra = "modificar"; palabra2 = "modificado"; if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { if (accion == 2) { JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); lista.clear(); empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase()); empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase()); empleadoControlador.getSeleccionado() .setApellidoPaterno(apellidoPField.getText().toUpperCase()); empleadoControlador.getSeleccionado() .setApellidoMaterno(apellidoMField.getText().toUpperCase()); empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase()); empleadoControlador.accion(accion); listar(); FormularioUtil.limpiarComponente(panelDatos); } else { JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { FormularioUtil.limpiarComponente(panelDatos); JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } FormularioUtil.limpiarComponente(panelDatos); FormularioUtil.activarComponente(panelOpciones, true); FormularioUtil.activarComponente(panelGuardar, false); FormularioUtil.activarComponente(panelDatos, false); } }
From source file:jeplus.JEPlusFrameMain.java
/** * Start batch operation// ww w . jav a2s .c om */ public void startBatchRunAll() { // Update display if (OutputPanel == null) { OutputPanel = new EPlusTextPanelOld("Output", EPlusTextPanel.VIEWER_MODE); int tabn = TpnEditors.getTabCount(); this.TpnEditors.insertTab("Executing batch ...", null, OutputPanel, "This is the execution log.", tabn); TpnEditors.setSelectedIndex(tabn); } else { TpnEditors.setSelectedComponent(OutputPanel); } // Check batch size and exec agent's capacity if (BatchManager.getBatchInfo().getTotalNumberOfJobs() > BatchManager.getAgent().getQueueCapacity()) { // Project is too large StringBuilder buf = new StringBuilder("<html><p>The estimated batch size ("); buf.append(LargeIntFormatter.format(BatchManager.getBatchInfo().getTotalNumberOfJobs())); buf.append(") exceeds the capacity of ").append(BatchManager.getAgent().getAgentID()).append(" ("); buf.append(LargeIntFormatter.format(BatchManager.getAgent().getQueueCapacity())); buf.append( "). </p><p>A large batch may cause jEPlus to crash. Please choose a different agent, or use random sampling or optimisation.</p>"); buf.append( "<p>However, the estimation did not take into account of manually fixed parameter values.</p><p>Please choose Yes if you want to go ahead with the simulation. </p>"); int res = JOptionPane.showConfirmDialog(this, buf.toString(), "Batch is too large", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { OutputPanel.appendContent("Batch cancelled.\n"); return; } } // Build jobs OutputPanel.appendContent("Building jobs ... "); ActingManager = BatchManager; // Start job ActingManager.runAll(); OutputPanel.appendContent("" + ActingManager.getJobQueue().size() + " jobs created.\n"); OutputPanel.appendContent("Starting simulation ...\n"); }
From source file:com.brainflow.application.toplevel.Brainflow.java
private void register(IImageDataSource limg) { DataSourceManager manager = DataSourceManager.getInstance(); boolean alreadyRegistered = manager.isRegistered(limg); if (alreadyRegistered) { StringBuffer sb = new StringBuffer(); sb.append("Image " + limg.getDataFile().getName().getBaseName()); sb.append(" has already been loaded, would you like to reload from disk?"); Integer ret = JOptionPane.showConfirmDialog(brainFrame, sb.toString(), "Image Already Loaded", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); log.info("return value is: " + ret); if (ret == JOptionPane.YES_OPTION) { limg.releaseData();/* w w w. j a va2 s . c om*/ } } else { manager.register(limg); } }
From source file:jeplus.gui.JPanel_TrnsysProjectFiles.java
private void cmdEditTemplateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEditTemplateActionPerformed // Test if the template file is present String fn = (String) cboTemplateFile.getSelectedItem(); String templfn = RelativeDirUtil.checkAbsolutePath(txtDCKDir.getText() + fn, Project.getBaseDir()); File ftmpl = new File(templfn); if (!ftmpl.exists()) { int n = JOptionPane.showConfirmDialog(this, "<html><p><center>The template file " + templfn + " does not exist." + "Do you want to select one?</center></p><p> Select 'NO' to create this file. </p>", "Template file not available", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { this.cmdSelectTemplateFileActionPerformed(null); templfn = txtDCKDir.getText() + (String) cboTemplateFile.getSelectedItem(); }//from ww w .j a v a 2 s . c o m } int idx = MainGUI.getTpnEditors().indexOfTab(fn); if (idx >= 0) { MainGUI.getTpnEditors().setSelectedIndex(idx); } else { EPlusTextPanel TemplFilePanel = new EPlusTextPanel(MainGUI.getTpnEditors(), fn, EPlusTextPanel.EDITOR_MODE, TRNSYSConfig.getFileFilter(TRNSYSConfig.TRNINPUT), templfn, Project); int ti = MainGUI.getTpnEditors().getTabCount(); TemplFilePanel.setTabId(ti); MainGUI.getTpnEditors().addTab(fn, TemplFilePanel); MainGUI.getTpnEditors().setSelectedIndex(ti); MainGUI.getTpnEditors().setTabComponentAt(ti, new ButtonTabComponent(MainGUI.getTpnEditors(), TemplFilePanel)); MainGUI.getTpnEditors().setToolTipTextAt(ti, templfn); } }
From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java
/** * DOCUMENT ME!/* w w w . j a va 2 s.c om*/ * * @param evt DOCUMENT ME! */ private void btnRemoveImgActionPerformed(final ActionEvent evt) { //GEN-FIRST:event_btnRemoveImgActionPerformed final Object[] selection = lstFotos.getSelectedValues(); if ((selection != null) && (selection.length > 0)) { final int answer = JOptionPane.showConfirmDialog(StaticSwingTools.getParentFrame(this), "Sollen die Fotos wirklich gelscht werden?", "Fotos entfernen", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { try { listListenerEnabled = false; final List<Object> removeList = Arrays.asList(selection); final List<CidsBean> fotos = cidsBean.getBeanCollectionProperty(beanCollProp); if (fotos != null) { fotos.removeAll(removeList); } // TODO set the laufende_nr for (int i = 0; i < lstFotos.getModel().getSize(); i++) { final CidsBean foto = (CidsBean) lstFotos.getModel().getElementAt(i); foto.setProperty("laufende_nummer", i + 1); } for (final Object toDeleteObj : removeList) { if (toDeleteObj instanceof CidsBean) { final CidsBean fotoToDelete = (CidsBean) toDeleteObj; final String file = String.valueOf(fotoToDelete.getProperty("url.object_name")); IMAGE_CACHE.remove(file); removedFotoBeans.add(fotoToDelete); } } } catch (final Exception ex) { LOG.error(ex, ex); showExceptionToUser(ex, this); } finally { // TODO check the laufende_nummer attribute listListenerEnabled = true; final int modelSize = lstFotos.getModel().getSize(); if (modelSize > 0) { lstFotos.setSelectedIndex(0); } else { image = null; lblPicture.setIcon(FOLDER_ICON); } } } } }
From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java
/** * @param appResName/*from w w w . j a v a 2 s . c o 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); }