List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException
optionType
parameter. From source file:com.tiempometa.muestradatos.JReadTags.java
private void deleteAllButtonActionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(this, "Se borrarn todos los tags de la base de datos.\nEsta operacin no se puede deshacer.\nContinuar?", "Borrar todos los tags", JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.YES_OPTION) { try {//w w w.j a va 2 s . c o m rfidDao.deleteAll(); tagTableModel.setData(new ArrayList<Rfid>()); tagTableModel.fireTableDataChanged(); } catch (SQLException e1) { JOptionPane.showMessageDialog(this, "No se pudieron borrar todos los tags. " + e1.getMessage(), "Error borrando tags", JOptionPane.ERROR_MESSAGE); } } }
From source file:jpad.MainEditor.java
public boolean quitApp() { if (hasChanges) { int dialogResult = JOptionPane.showConfirmDialog(this, "You have unsaved changes, would you like to save these first?", "Question", JOptionPane.YES_NO_CANCEL_OPTION); switch (dialogResult) { case 0:/*from ww w.j a v a 2 s . com*/ if (hasSavedToFile) saveFile(curFile); else saveAs(); return true; case 1: return true; case 2: return false; } } return true; }
From source file:com.sun.jersey.client.apache.config.DefaultCredentialsProvider.java
public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (scheme == null) { return null; }/*from w ww . j a v a2 s .c om*/ try { JTextField userField = new JTextField(); JPasswordField passwordField = new JPasswordField(); int response; if (scheme instanceof NTLMScheme) { JTextField domainField = new JTextField(); Object[] msg = { host + ":" + port + " requires Windows authentication", "Domain", domainField, "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host, domainField.getText()); } else if (scheme instanceof RFC2617Scheme) { Object[] msg = { host + ":" + port + " requires authentication with the realm '" + scheme.getRealm() + "'", "User Name", userField, "Password", passwordField }; response = JOptionPane.showConfirmDialog(null, msg, "Authenticate", JOptionPane.OK_CANCEL_OPTION); if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) { throw new CredentialsNotAvailableException("User cancled windows authentication."); } return new UsernamePasswordCredentials(userField.getText(), new String(passwordField.getPassword())); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + scheme.getSchemeName()); } } catch (IOException ioe) { throw new CredentialsNotAvailableException(ioe.getMessage(), ioe); } }
From source file:hudson.lifecycle.WindowsSlaveInstaller.java
/** * Called when the install menu is selected *//*from w w w. j a v a 2s . c o m*/ public void actionPerformed(ActionEvent e) { int r = JOptionPane.showConfirmDialog(dialog, "This will install a slave agent as a Windows service,\n" + "so that this slave will connect to Hudson as soon as the machine boots.\n" + "Do you want to proceed with installation?", Messages.WindowsInstallerLink_DisplayName(), JOptionPane.OK_CANCEL_OPTION); if (r != JOptionPane.OK_OPTION) return; if (!DotNet.isInstalled(2, 0)) { JOptionPane.showMessageDialog(dialog, ".NET Framework 2.0 or later is required for this feature", Messages.WindowsInstallerLink_DisplayName(), JOptionPane.ERROR_MESSAGE); return; } final File dir = new File(rootDir); try { final File slaveExe = new File(dir, "hudson-slave.exe"); FileUtils.copyURLToFile(getClass().getResource("/windows-service/hudson.exe"), slaveExe); // write out the descriptor URL jnlp = new URL(engine.getHudsonUrl(), "computer/" + engine.slaveName + "/slave-agent.jnlp"); String xml = generateSlaveXml(System.getProperty("java.home") + "\\bin\\java.exe", "-jnlpUrl " + jnlp.toExternalForm()); FileUtils.writeStringToFile(new File(dir, "hudson-slave.xml"), xml, "UTF-8"); // copy slave.jar URL slaveJar = new URL(engine.getHudsonUrl(), "jnlpJars/remoting.jar"); File dstSlaveJar = new File(dir, "slave.jar").getCanonicalFile(); if (!dstSlaveJar.exists()) // perhaps slave.jar is already there? FileUtils.copyURLToFile(slaveJar, dstSlaveJar); // install as a service ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); r = new LocalLauncher(task).launch().cmds(slaveExe, "install").stdout(task).pwd(dir).join(); if (r != 0) { JOptionPane.showMessageDialog(dialog, baos.toString(), "Error", JOptionPane.ERROR_MESSAGE); return; } r = JOptionPane.showConfirmDialog(dialog, "Installation was successful. Would you like to\n" + "Stop this slave agent and start the newly installed service?", Messages.WindowsInstallerLink_DisplayName(), JOptionPane.OK_CANCEL_OPTION); if (r != JOptionPane.OK_OPTION) return; // let the service start after we close our connection, to avoid conflicts Runtime.getRuntime().addShutdownHook(new Thread("service starter") { public void run() { try { StreamTaskListener task = new StreamTaskListener(System.out); int r = new LocalLauncher(task).launch().cmds(slaveExe, "start").stdout(task).pwd(dir) .join(); task.getLogger() .println(r == 0 ? "Successfully started" : "start service failed. Exit code=" + r); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); System.exit(0); } catch (Exception t) { StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); JOptionPane.showMessageDialog(dialog, sw.toString(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java
@Override public boolean getUserConfirmation(final String title, final String message) throws QTasteException { final MutableBoolean confirmed = new MutableBoolean(); try {//from w ww . j av a 2 s . c o m SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION); confirmed.setValue(result == JOptionPane.YES_OPTION); } }); } catch (Exception e) { throw new QTasteException("Error while showing user confirmation dialog", e); } return confirmed.booleanValue(); }
From source file:com.igormaznitsa.zxpspritecorrector.files.AbstractFilePlugin.java
protected boolean saveDataToFile(final File file, final byte[] data) throws IOException { if (file.isFile()) { switch (JOptionPane.showConfirmDialog(this.mainFrame, "Overwrite file '" + file.getAbsolutePath() + "'?", "Overwrite file", JOptionPane.YES_NO_CANCEL_OPTION)) { case JOptionPane.NO_OPTION: return true; case JOptionPane.CANCEL_OPTION: return false; }//from www . j a va2s. c om } FileUtils.writeByteArrayToFile(file, data); return true; }
From source file:latexstudio.editor.DbxFileActions.java
/** * Shows a .tex files list from user's dropbox and opens the selected one * * @return List, that contatins user's .tex files from his dropbox; can be * empty/*from w w w.j a v a 2s . c o m*/ */ public void openFromDropbox(DropboxRevisionsTopComponent drtc, RevisionDisplayTopComponent revtc) { List<DbxEntryDto> dbxEntries = getDbxTexEntries(DbxUtil.getDbxClient()); if (!dbxEntries.isEmpty()) { JList<DbxEntryDto> list = new JList(dbxEntries.toArray()); list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); int option = JOptionPane.showConfirmDialog(null, list, "Open file from Dropbox", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION && !list.isSelectionEmpty()) { DbxEntryDto entry = list.getSelectedValue(); String localPath = ApplicationUtils.getAppDirectory() + File.separator + entry.getName(); File outputFile = DbxUtil.downloadRemoteFile(entry, localPath); revtc.close(); drtc.updateRevisionsList(entry.getPath()); drtc.open(); drtc.requestActive(); String content = FileService.readFromFile(outputFile.getAbsolutePath()); etc.setEditorContent(content); etc.setCurrentFile(outputFile); etc.setDbxState(new DbxState(entry.getPath(), entry.getRevision())); etc.setModified(false); etc.setPreviewDisplayed(false); } } else { JOptionPane.showMessageDialog(etc, "No .tex files found!", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:org.jtheque.ui.impl.UIUtilsImpl.java
@Override public boolean askUserForConfirmation(final String text, final String title) { boolean yes = false; Window parent = null;/* ww w . j a v a 2 s. c o m*/ if (SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class) != null) { parent = SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class); } final Window p = parent; final int[] response = new int[1]; if (SwingUtilities.isEventDispatchThread()) { response[0] = JOptionPane.showConfirmDialog(parent, text, title, JOptionPane.YES_NO_OPTION); } else { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { response[0] = JOptionPane.showConfirmDialog(p, text, title, JOptionPane.YES_NO_OPTION); } }); } catch (InterruptedException e) { LoggerFactory.getLogger(getClass()).error(e.getMessage(), e); } catch (InvocationTargetException e) { LoggerFactory.getLogger(getClass()).error(e.getMessage(), e); } } if (response[0] == JOptionPane.YES_OPTION) { yes = true; } return yes; }
From source file:de.bley.word.menu.GuiMenu.java
private void addListener() { button.addActionListener(new ActionListener() { @Override/*from www.j ava 2 s . c o m*/ public void actionPerformed(ActionEvent e) { saveData(); refreshList(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (!textfield.getText().equals("") && !textfield.getText().equals(PropertieManager.getInstance() .getZuordnung().getReader().readFile(zuordnung.getPath().getFilepath()))) { int confirmed = JOptionPane.showConfirmDialog(null, "Daten speichern?", "Beenden", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { saveData(); } } } }); }
From source file:GUI.MainJF.java
public void LlenarTabla() { String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" }; Object[][] data = null;//ww w .j ava 2s. co m DefaultTableModel model = new DefaultTableModel(data, columnNames); HttpResponse response; response = JSON.request(Config.URL + "usuarios/listar.json"); JSONObject jObject = JSON.JSON(response); try { JSONArray jsonArr = jObject.getJSONArray("data"); for (int i = 0; i < jsonArr.length(); i++) { JSONObject data_json = jsonArr.getJSONObject(i); model.addRow( new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(), data_json.get("email").toString(), data_json.get("edad").toString(), data_json.get("descripcion").toString(), "Editar", "Eliminar" }); } } catch (Exception e) { e.printStackTrace(); } tb_usuarios.setModel(model); Action editar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2); String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3); String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4); FormUsuarios U = new FormUsuarios(); U.setID(id); U.setNombre(nombre); U.setEmail(email); U.setEdad(edad); U.setTipo(tipo); U.setLocationRelativeTo(null); U.setVisible(true); } }; ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5); botonEditar.setMnemonic(KeyEvent.VK_D); Action eliminar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); int rs = JOptionPane.showConfirmDialog(null, "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar", JOptionPane.YES_NO_OPTION); if (rs == JOptionPane.YES_OPTION) { List<NameValuePair> parametros = new ArrayList<NameValuePair>(); parametros.add(new BasicNameValuePair("idUsuario", id)); HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros); JSONObject jObject = JSON.JSON(response); int code = Integer.parseInt(jObject.get("code").toString()); /*if(code == 201){ JOptionPane.showMessageDialog(null, "Usuario eliminado"); //((DefaultTableModel)table.getModel()).removeRow(modelRow); }else{ JOptionPane.showMessageDialog(null, "Error eliminar Usuario"); }*/ } } }; ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6); botonEliminar.setMnemonic(KeyEvent.VK_D); model.fireTableDataChanged(); }