List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION
int YES_NO_CANCEL_OPTION
To view the source code for javax.swing JOptionPane YES_NO_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java
/** * Called when the WorkbenchPaneSS for the uploaded dataset is shutting down, and when * the Upload UI 'Close' button is clicked. * // w w w. j a va2s .co m * @param shuttingDownSS - the dataset that is shutting down. * @return true if the Uploader can be closed, otherwise false. */ public boolean aboutToShutdown(final WorkbenchPaneSS shuttingDownSS) { if (shuttingDownSS != null && shuttingDownSS != wbSS) { return true; } if (currentTask != null || (shuttingDownSS != null && (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL)) && getUploadedObjects() > 0)) { JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), getResourceString("WB_UPLOAD_BUSY_CANNOT_CLOSE")); return false; } boolean result = true; if (uploadedObjectViewer != null) { uploadedObjectViewer.closeView(); } if (result && shuttingDownSS == null && (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL)) && getUploadedObjects() > 0 && !isUpdateUpload()) { result = false; String msg = String.format(getResourceString("WB_UPLOAD_CONFIRM_SAVE"), theWb.getName()); JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("WB_UPLOAD_FORM_TITLE"), JOptionPane.YES_NO_CANCEL_OPTION); if (rv == JOptionPane.YES_OPTION) { saveRecordSets(); result = true; wbSS.saveObject(); } else if (rv == JOptionPane.NO_OPTION) { undoUpload(shuttingDownSS == null, true, true); result = true; } //else rv equals JOptionPane.CANCEL_OPTION or CLOSED_OPTION if (result) { for (UploadTable ut : uploadTables) { try { ut.shutdown(); } catch (UploaderException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(Uploader.class, ex); throw new RuntimeException(ex); } } } } if (additionalLocksSet) { freeAdditionalLocks(); } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
@Override public boolean aboutToShutdown() { super.aboutToShutdown(); for (WorkBenchPluginIFace wbp : workBenchPlugins.values()) { wbp.shutdown();// w w w . j a v a 2 s . co m } // Tell it is about to be hidden. // this way it can end any editing if (formPane != null) { if (!checkCurrentEditState()) { SubPaneMgr.getInstance().showPane(this); // Need to reverify to get the error to display again. if (spreadSheet.getCellEditor() != null) { spreadSheet.getCellEditor().stopCellEditing(); } return false; } } if (datasetUploader != null && !datasetUploader.aboutToShutdown(this)) { return false; } if (datasetUploader != null) { if (datasetUploader.closing(this)) { datasetUploader = null; Uploader.unlockApp(); Uploader.unlockUpload(); } } boolean retStatus = true; if (hasChanged) { // turn off alwaysOnTop for Swing repaint reasons (prevents a lock up) if (imageFrame != null) { imageFrame.setAlwaysOnTop(false); } String msg = String.format(getResourceString("SaveChanges"), getTitle()); JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); final String wbName = workbench.getName(); int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION); if (rv == JOptionPane.YES_OPTION) { //GlassPane and Progress bar currently don't show up during shutdown SwingUtilities.invokeLater(new Runnable() { public void run() { UIRegistry.writeSimpleGlassPaneMsg( String.format(getResourceString("WB_SAVING"), new Object[] { workbench.getName() }), WorkbenchTask.GLASSPANE_FONT_SIZE); UIRegistry.getStatusBar().setIndeterminate(wbName, true); } }); SwingWorker saver = new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { Boolean result = null; try { saveObject(); result = new Boolean(true); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(WorkbenchPaneSS.class, ex); log.error(ex); } return result; } /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#finished() */ @Override public void finished() { UIRegistry.clearSimpleGlassPaneMsg(); UIRegistry.getStatusBar().setProgressDone(wbName); shutdownLock.decrementAndGet(); shutdown(); } }; shutdownLock.incrementAndGet(); saver.start(); //retStatus = saver.get() != null; } else if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { return false; } else if (rv == JOptionPane.NO_OPTION) { hasChanged = false; // we do this so we don't get asked a second time } } if (retStatus) { ((WorkbenchTask) ContextMgr.getTaskByClass(WorkbenchTask.class)).closing(this); ((SGRTask) ContextMgr.getTaskByClass(SGRTask.class)).closing(this); if (spreadSheet != null) { spreadSheet.getSelectionModel().removeListSelectionListener(workbenchRowChangeListener); } workbenchRowChangeListener = null; } return retStatus; }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
@Override public boolean aboutToShutdown() { boolean result = true; unlock();//from ww w .jav a 2 s .c o m if (isChanged()) { String msg = String.format(getResourceString("SaveChanges"), getTitle()); JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION); if (rv == JOptionPane.YES_OPTION) { saveQuery(false); } else if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { return false; } else if (rv == JOptionPane.NO_OPTION) { // nothing } } return result; }
From source file:interfaces.InterfazPrincipal.java
private void tablaUsuariosDelSistemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaUsuariosDelSistemaMouseClicked // TODO add your handling code here: String opcionHabilitar = "Habilitar"; String nombreUsuario = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 0)); String estado = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 2)); if (estado.equals("Habilitado")) { opcionHabilitar = "Deshabilitar"; }//from w w w.j av a 2 s.c om Object[] opciones = { "Cancelar", "Editar", opcionHabilitar }; final ControladorUsuarios controladorUsuarios = new ControladorUsuarios(); final Usuarios usuarioSelecionado = controladorUsuarios.obtenerUsuario(nombreUsuario); if (nombreUsuario.equals("admin") || nombreUsuario.equals(JTextFieldnombreDeUsuario.getText())) { JOptionPane.showMessageDialog(this, "No se puede editarse a si mismo o el usuario administrador del sistema", "Mensaje del sistema", JOptionPane.WARNING_MESSAGE); } else { int opcionElegida = JOptionPane.showOptionDialog(this, "Por favor elija una opcin", "Editar cliente", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null); switch (opcionElegida) { case 1: final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar usuario"); dialogoEditar.setSize(400, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(15, 10, 40, 0); c.ipadx = 0; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; JLabel editarNombreClienteDialogo = new JLabel("Login:"); panelDialogo.add(editarNombreClienteDialogo, c); final JTextField valorEditarNombreClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); valorEditarNombreClienteDialogo.setText(usuarioSelecionado.getLogin()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel editarPasswordClienteDialogo = new JLabel("Contrasea:"); panelDialogo.add(editarPasswordClienteDialogo, c); final JTextField valoreditarPasswordClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); panelDialogo.add(valoreditarPasswordClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel mensajeEditarPassword = new JLabel( "Si no desea editar la contrasea deje este espacio en blanco:"); panelDialogo.add(mensajeEditarPassword, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 15, 10, 15); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 4; c.gridwidth = 1; c.insets = new Insets(0, 15, 10, 15); c.ipadx = 0; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String nombreUsuario = valorEditarNombreClienteDialogo.getText(); usuarioSelecionado.setLogin(nombreUsuario); if (!valoreditarPasswordClienteDialogo.getText().equals("")) { usuarioSelecionado.setPassword(valoreditarPasswordClienteDialogo.getText()); } controladorUsuarios.modificarUsuario(usuarioSelecionado.getUser_id(), usuarioSelecionado.getLogin(), usuarioSelecionado.getPassword()); JOptionPane.showMessageDialog(dialogoEditar, "Se ha modificado el usuario con xito", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); dialogoEditar.dispose(); } }); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); break; case 2: if (estado.equals("Habilitado")) { usuarioSelecionado.setStatus('i'); } else { usuarioSelecionado.setStatus('e'); } controladorUsuarios.modificarEstadoUsuario(usuarioSelecionado); JOptionPane.showMessageDialog(this, "Se ha cambiado el estado del usuario", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); break; default: break; } } // TODO add your handling code here: }
From source file:lu.fisch.unimozer.Diagram.java
public boolean askToSave() { try {//from www. ja v a2 s . c om if (diagram.getClassCount() > 0 && isChanged() == true) { int answ = JOptionPane.showConfirmDialog(frame, "Do you want to save the current project?", "Save project?", JOptionPane.YES_NO_CANCEL_OPTION); if (answ == JOptionPane.YES_OPTION) { if (directoryName == null) return saveWithAskingLocation(); else return save(); } else if (answ == JOptionPane.NO_OPTION) { return true; } else return false; } return true; } catch (Exception e) { JOptionPane.showMessageDialog(frame, "A terrible error occured!\n" + e.getMessage() + "\n", "Error", JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR); return false; } }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Hygiene() { JPanel pnlContent = new JPanel(new VerticalLayout()); JPanel pnlPrevalence = new JPanel(new BorderLayout()); final JButton btnPrevalence = GUITools.createHyperlinkButton("opde.controlling.hygiene.prevalence", null, null);/* ww w.jav a 2 s .c o m*/ final JDateChooser jdc = new JDateChooser(new Date()); final JCheckBox cbAnonymous = new JCheckBox(SYSTools.xx("misc.msg.anon")); cbAnonymous.setSelected(true); jdc.setMaxSelectableDate(new Date()); btnPrevalence.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { MREPrevalenceSheets mre = new MREPrevalenceSheets(new LocalDate(), cbAnonymous.isSelected(), progressClosure); return mre.createSheet(); } @Override protected void done() { try { File source = (File) get(); Object[] options = { SYSTools.xx("prevalence.optiondialog.option1"), SYSTools.xx("prevalence.optiondialog.option2"), SYSTools.xx("opde.wizards.buttontext.cancel") }; int n = JOptionPane.showOptionDialog(OPDE.getMainframe(), SYSTools.xx("prevalence.optiondialog.question"), SYSTools.xx("prevalence.optiondialog.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); File copyTargetDirectory = null; if (n == 1) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("title"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(pnlPrevalence) == JFileChooser.APPROVE_OPTION) { copyTargetDirectory = chooser.getSelectedFile(); } } if (copyTargetDirectory != null) { FileUtils.copyFile(source, copyTargetDirectory); } else { if (n == 0) { SYSFilesTools.handleFile((File) get(), Desktop.Action.OPEN); } } } catch (Exception e) { OPDE.fatal(e); } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlPrevalence.add(btnPrevalence, BorderLayout.WEST); JPanel optionPanel = new JPanel(); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.LINE_AXIS)); optionPanel.add(cbAnonymous); optionPanel.add(jdc); pnlPrevalence.add(optionPanel, BorderLayout.EAST); pnlContent.add(pnlPrevalence); return pnlContent; }
From source file:org.docx4all.ui.main.WordMLEditor.java
private int showConfirmClosingInternalFrame(JInternalFrame iframe, String resourceKeyPrefix) { int answer = JOptionPane.CANCEL_OPTION; String filePath = (String) iframe.getClientProperty(WordMLDocument.FILE_PATH_PROPERTY); ResourceMap rm = getContext().getResourceMap(); String title = rm.getString(resourceKeyPrefix + ".dialog.title") + " " + filePath.substring(filePath.lastIndexOf(File.separator) + 1); String message = filePath + "\n" + rm.getString(resourceKeyPrefix + ".confirmMessage"); Object[] options = { rm.getString(resourceKeyPrefix + ".confirm.saveNow"), rm.getString(resourceKeyPrefix + ".confirm.dontSave"), rm.getString(resourceKeyPrefix + ".confirm.cancel") }; answer = showConfirmDialog(title, message, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, options, options[0]);//from w ww.j av a 2 s. c o m if (answer == JOptionPane.CANCEL_OPTION) { ; } else if (answer == JOptionPane.YES_OPTION) { boolean success = FileMenu.getInstance().save(iframe, null, FileMenu.SAVE_FILE_ACTION_NAME); if (success) { getToolbarStates().setDocumentDirty(iframe, false); getToolbarStates().setLocalEditsEnabled(iframe, false); } else { answer = JOptionPane.CANCEL_OPTION; } } else { //getToolbarStates().setDocumentDirty(iframe, false); } return answer; }
From source file:org.domainmath.gui.MainFrame.java
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed String dir = MainFrame.dirComboBox.getSelectedItem().toString(); int i = JOptionPane.showConfirmDialog(this, "Add this folder to Path List?-\n" + dir, "DomainMath IDE", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (i == JOptionPane.YES_OPTION) { MainFrame.octavePanel.evaluate("addpath(genpath(" + "'" + dir + "'));"); MainFrame.octavePanel.evaluate("savepath();"); }//from w w w. j a va 2s.c o m }
From source file:org.domainmath.gui.MainFrame.java
/** * It closes a file.// w w w . ja va2 s . c o m * @param selectedIndex */ public void askSave(int selectedIndex) { String s = fileTab.getTitleAt(selectedIndex); if (s.endsWith("*")) { //modified document. String f = s.substring(0, s.lastIndexOf("*")); // ask to save file. int i = JOptionPane.showConfirmDialog(this, "Do you want to save changes in " + f + " ?", "DomainMath IDE", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (i == JOptionPane.YES_OPTION) { //need to save file // add this file to recent menu list. File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex)); recentFileMenu.addEntry(selected_file.getAbsolutePath()); // save the file. save(selected_file, selectedIndex); // close the file. this.removeFileNameFromList(selectedIndex); fileTab.remove(selectedIndex); FILE_TAB_INDEX--; } else if (i == JOptionPane.NO_OPTION) { // I dont need to save the file. // add this file to recent menu list. File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex)); recentFileMenu.addEntry(selected_file.getAbsolutePath()); // close the file. this.removeFileNameFromList(selectedIndex); fileTab.remove(selectedIndex); FILE_TAB_INDEX--; } } else { //unmodified file. // add this file to recent menu list. File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex)); recentFileMenu.addEntry(selected_file.getAbsolutePath()); // close the file. removeFileNameFromList(selectedIndex); fileTab.remove(selectedIndex); FILE_TAB_INDEX--; } }
From source file:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * Asks the user if she wishes to save the file before exiting PUCK. *//*from w w w . j a va 2s. c o m*/ public void askSaveExitCancel() { int option = JOptionPane.showConfirmDialog(PuckFrame.this, UIMessages.getInstance().getMessage("confirm.saveonexit.text"), UIMessages.getInstance().getMessage("confirm.saveonexit.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (option == JOptionPane.YES_OPTION) { try { boolean done; if (editingFileName != null) { saveChangesInCurrentFile(); done = true; } else { done = saveAs(); } if (done) exit(); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } else if (option == JOptionPane.NO_OPTION) { exit(); } }