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:edu.harvard.mcz.imagecapture.DeterminationFrame.java
/** * This method initializes jTable // w w w .j a v a 2s . com * * @return javax.swing.JTable */ private JTable getJTable() { if (jTableDeterminations == null) { jTableDeterminations = new JTable(); DeterminationTableModel model = new DeterminationTableModel(); jTableDeterminations.setModel(model); if (determinations != null) { jTableDeterminations.setModel(determinations); } FilteringAgentJComboBox field = new FilteringAgentJComboBox(); jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_IDENTIFIEDBY) .setCellEditor(new ComboBoxCellEditor(field)); setTableColumnEditors(); jTableDeterminations.setRowHeight(jTableDeterminations.getRowHeight() + 4); jTableDeterminations.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupDets.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupDets.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupDets = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { log.debug(clickedOnDetsRow); if (clickedOnDetsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisFrame, "Delete the selected determination?", "Delete Determination", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting determination row " + clickedOnDetsRow); ((DeterminationTableModel) jTableDeterminations.getModel()) .deleteRow(clickedOnDetsRow); } else { log.debug("determination row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisFrame, "Unable to select row to delete."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisFrame, "Failed to delete a determination row. " + ex.getMessage()); } } }); jPopupDets.add(mntmDeleteRow); } return jTableDeterminations; }
From source file:net.sf.jabref.external.DownloadExternalFile.java
/** * Start a download.// w ww .ja va 2 s .c o m * * @param callback The object to which the filename should be reported when download * is complete. */ public void download(URL url, final DownloadCallback callback) throws IOException { String res = url.toString(); String mimeType; // First of all, start the download itself in the background to a temporary file: final File tmp = File.createTempFile("jabref_download", "tmp"); tmp.deleteOnExit(); URLDownload udl = MonitoredURLDownload.buildMonitoredDownload(frame, url); try { // TODO: what if this takes long time? // TODO: stop editor dialog if this results in an error: mimeType = udl.determineMimeType(); // Read MIME type } catch (IOException ex) { JOptionPane.showMessageDialog(frame, Localization.lang("Invalid URL") + ": " + ex.getMessage(), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Error while downloading " + "'" + res + "'", ex); return; } final URL urlF = url; final URLDownload udlF = udl; JabRefExecutorService.INSTANCE.execute(() -> { try { udlF.downloadToFile(tmp); } catch (IOException e2) { dontShowDialog = true; if ((editor != null) && editor.isVisible()) { editor.setVisible(false, false); } JOptionPane.showMessageDialog(frame, Localization.lang("Invalid URL") + ": " + e2.getMessage(), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Error while downloading " + "'" + urlF + "'", e2); return; } // Download finished: call the method that stops the progress bar etc.: SwingUtilities.invokeLater(DownloadExternalFile.this::downloadFinished); }); Optional<ExternalFileType> suggestedType = Optional.empty(); if (mimeType != null) { LOGGER.debug("MIME Type suggested: " + mimeType); suggestedType = ExternalFileTypes.getInstance().getExternalFileTypeByMimeType(mimeType); } // Then, while the download is proceeding, let the user choose the details of the file: String suffix; if (suggestedType.isPresent()) { suffix = suggestedType.get().getExtension(); } else { // If we didn't find a file type from the MIME type, try based on extension: suffix = getSuffix(res); if (suffix == null) { suffix = ""; } suggestedType = ExternalFileTypes.getInstance().getExternalFileTypeByExt(suffix); } String suggestedName = getSuggestedFileName(suffix); List<String> fDirectory = databaseContext.getFileDirectory(); String directory; if (fDirectory.isEmpty()) { directory = null; } else { directory = fDirectory.get(0); } final String suggestDir = directory == null ? System.getProperty("user.home") : directory; File file = new File(new File(suggestDir), suggestedName); FileListEntry entry = new FileListEntry("", file.getCanonicalPath(), suggestedType); editor = new FileListEntryEditor(frame, entry, true, false, databaseContext); editor.getProgressBar().setIndeterminate(true); editor.setOkEnabled(false); editor.setExternalConfirm(closeEntry -> { File f = directory == null ? new File(closeEntry.link) : expandFilename(directory, closeEntry.link); if (f.isDirectory()) { JOptionPane.showMessageDialog(frame, Localization.lang("Target file cannot be a directory."), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); return false; } if (f.exists()) { return JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", f.getName()), Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION; } else { return true; } }); if (dontShowDialog) { return; } else { editor.setVisible(true, false); } // Editor closed. Go on: if (editor.okPressed()) { File toFile = directory == null ? new File(entry.link) : expandFilename(directory, entry.link); String dirPrefix; if (directory == null) { dirPrefix = null; } else { if (directory.endsWith(System.getProperty("file.separator"))) { dirPrefix = directory; } else { dirPrefix = directory + System.getProperty("file.separator"); } } try { boolean success = FileUtil.copyFile(tmp, toFile, true); if (!success) { // OOps, the file exists! LOGGER.error("File already exists! DownloadExternalFile.download()"); } // If the local file is in or below the main file directory, change the // path to relative: if ((directory != null) && entry.link.startsWith(directory) && (entry.link.length() > dirPrefix.length())) { entry = new FileListEntry(entry.description, entry.link.substring(dirPrefix.length()), entry.type); } callback.downloadComplete(entry); } catch (IOException ex) { LOGGER.warn("Problem downloading file", ex); } if (!tmp.delete()) { LOGGER.info("Cannot delete temporary file"); } } else { // Canceled. Just delete the temp file: if (downloadFinished && !tmp.delete()) { LOGGER.info("Cannot delete temporary file"); } } }
From source file:eu.ggnet.dwoss.receipt.UiUnitSupport.java
private UniqueUnit optionalChangeStock(UniqueUnit uniqueUnit, StockUnit stockUnit, Stock localStock, Window parent, String account) { if (!stockUnit.isInStock()) return uniqueUnit; if (localStock.equals(stockUnit.getStock())) return uniqueUnit; if (stockUnit.isInTransaction()) { JOptionPane.showMessageDialog(parent, "Achtung, Gert ist nicht auf " + localStock.getName() + ",\n" + "aber Gert ist auch auf einer Transaktion.\n" + "Automatische Lagernderung nicht mglich !"); return uniqueUnit; }//w ww .ja v a2 s .c o m int option = JOptionPane.showConfirmDialog(parent, "Gert steht nicht auf " + localStock.getName() + ", welches als Standort angegeben ist. Gertestandort ndern ?", "Standortabweichung", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { ComboBoxDialog<Stock> dialog = new ComboBoxDialog<>(parent, lookup(StockAgent.class).findAll(Stock.class).toArray(new Stock[0]), new StockCellRenderer()); dialog.setSelection(localStock); dialog.setVisible(true); if (dialog.isOk()) return unitProcessor.transfer(uniqueUnit, dialog.getSelection().getId(), account); } return uniqueUnit; }
From source file:cz.moz.ctmanager.main.MainAppFrame.java
private void removeContactButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeContactButtonActionPerformed int selectedRow = contactTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(this, "Nothing Selected", "Error Message", JOptionPane.ERROR_MESSAGE); } else {/* ww w .ja va 2 s .c om*/ Object[] options = { "Are you Sure?" }; int choice = JOptionPane.showConfirmDialog(this, options, "Are you Sure", 2); if (choice == 0) { DefaultTableModel newTableModel = (DefaultTableModel) contactTable.getModel(); int selectedContactID = (int) contactTable.getValueAt(contactTable.getSelectedRow(), 0); newTableModel.removeRow(selectedRow); emailsDao.removeAll(selectedContactID); phonesDao.removeAll(selectedContactID); contactsDao.removeContact(selectedContactID); } } }
From source file:net.sf.profiler4j.console.Console.java
/** * @return <code>true</code> if a new project was created (the user could have been * cancelled)/*from w ww . j a va 2 s. co m*/ */ public boolean newProject() { if (client.isConnected()) { int ret = JOptionPane.showConfirmDialog(mainFrame, "Proceed and disconnect?", "New Profiling Project", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return false; } } if (checkUnsavedChanges()) { return false; } if (client.isConnected()) { disconnect(); if (client.isConnected()) { return false; } } Project p = new Project(); ProjectDialog d = new ProjectDialog(mainFrame, this); if (d.edit(p)) { this.project = p; return true; } return false; }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
public boolean canExit() { if (hasChanges) { /*//from w w w .ja v a 2 s.c om * Wenn es ungespeicherte Aenderungen gibt, dann Benutzer fragen */ int ret = JOptionPane.showConfirmDialog(getMainFrame(), "Save changes before exit?", "", JOptionPane.YES_NO_CANCEL_OPTION); switch (ret) { case JOptionPane.CANCEL_OPTION: return false; case JOptionPane.NO_OPTION: return true; case JOptionPane.YES_OPTION: /* * Speichern anstossen */ saveDatabase(); /* * Nur wenn Speichern erfolgreich war 'true' zurueckgeben */ return !hasChanges; default: return false; } } else { return true; } }
From source file:com.emental.mindraider.ui.outline.OutlineArchiveJPanel.java
public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to delete this Note?", "Delete Note", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { // determine selected concept parameters int selectedRow = table.getSelectedRow(); if (selectedRow >= 0) { // map the row to the model (column sorters may change it) selectedRow = table.convertRowIndexToModel(selectedRow); if (tableModel.getDiscardedConcepts() != null && tableModel.getDiscardedConcepts().length > selectedRow) { MindRaider.noteCustodian.deleteConcept(MindRaider.profile.getActiveOutlineUri().toString(), tableModel.getDiscardedConcepts()[selectedRow].getUri()); OutlineJPanel.getInstance().refresh(); }/* w w w .j a va 2 s.co m*/ return; } } }
From source file:net.pms.movieinfo.MovieInfo.java
@Override public JComponent config() { FormLayout layout = new FormLayout( "left:pref, 2dlu, p,2dlu, p,2dlu, p, 2dlu, p, 2dlu, p,2dlu, p,200dlu, pref:grow", //$NON-NLS-1$ "p, 5dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p,0:grow"); //$NON-NLS-1$ PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.EMPTY);//from w w w .j a v a 2 s .c o m builder.opaque(false); CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator("MOVIE INFO CONFIG", cc.xy(1, 1)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); pluginsField = new JTextField(); pluginsField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getPlugins() != null) pluginsField.setText(configuration.getPlugins()); pluginsField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setPlugins(pluginsField.getText()); } }); builder.addLabel("Plugins to use (in prioritized order):", cc.xy(1, 3)); builder.add(pluginsField, cc.xyw(3, 3, 12)); maxNumberOfActorsField = new JSpinner(new SpinnerNumberModel()); maxNumberOfActorsField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented maxNumberOfActorsField.setValue(configuration.getMaxNumberOfActors()); maxNumberOfActorsField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setMaxNumberOfActors((Integer) maxNumberOfActorsField.getValue()); } }); builder.addLabel("Maximum number of actors to display:", cc.xy(1, 5)); builder.add(maxNumberOfActorsField, cc.xy(3, 5)); downloadCoverField = new JCheckBox(); downloadCoverField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented downloadCoverField.setSelected(configuration.getDownloadCover()); downloadCoverField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setDownloadCover(downloadCoverField.isSelected()); } }); builder.addLabel("Download cover to movie folder:", cc.xy(5, 5)); builder.add(downloadCoverField, cc.xy(7, 5)); displayInfoField = new JTextField(); displayInfoField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getDisplayInfo() != null) { displayInfoField.setText(configuration.getDisplayInfoAsString()); } displayInfoField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //TODO: Needs verification logics configuration.setDisplayInfoFromString(displayInfoField.getText()); } }); builder.addLabel("DisplayInfo:", cc.xy(13, 5)); builder.add(displayInfoField, cc.xyw(14, 5, 2)); plotLineLengthField = new JSpinner(new SpinnerNumberModel()); plotLineLengthField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented plotLineLengthField.setValue(configuration.getPlotLineLength()); plotLineLengthField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setPlotLineLength((Integer) plotLineLengthField.getValue()); } }); builder.addLabel("Plot line length:", cc.xy(9, 5)); builder.add(plotLineLengthField, cc.xy(11, 5)); filterField = new JTextField(); filterField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getFilters() != null) { filterField.setText(configuration.getFiltersAsString()); } filterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //TODO: Needs verification logics configuration.setFiltersFromString(filterField.getText()); } }); ScanPath = new JTextField(); builder.addLabel("Filter:", cc.xy(1, 7)); builder.add(filterField, cc.xyw(3, 7, 12)); builder.addLabel("Scan path:", cc.xy(1, 9)); builder.add(ScanPath, cc.xyw(3, 9, 12)); ScanPath.setText((String) PMS.getConfiguration().getCustomProperty("movieinfo.scan_path")); JButton scan = new JButton("Scan files"); scan.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (mdb != null) { if (!mdb.isScanLibraryRunning()) { int option = JOptionPane.showConfirmDialog(LooksFrame.get(), Messages.getString("FoldTab.3") + Messages.getString("FoldTab.4"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { mdb.scanLibrary(ScanPath.getText()); } } else { int option = JOptionPane.showConfirmDialog(LooksFrame.get(), Messages.getString("FoldTab.10"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { mdb.stopScanLibrary(); } } } } }); builder.add(scan, cc.xy(1, 11)); return builder.getPanel(); }
From source file:com.mirth.connect.plugins.datapruner.DataPrunerPanel.java
public void doStart() { final MutableBoolean saveChanges = new MutableBoolean(false); if (isSaveEnabled()) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Settings changes must be saved first, would you like to save the settings and prune now?", "Select an Option", JOptionPane.OK_CANCEL_OPTION)) { if (!validateFields()) { return; }/*from www .j a v a 2 s . c o m*/ saveChanges.setValue(true); } else { return; } } setStartTaskVisible(false); final String workingId = parent.startWorking("Starting the data pruner..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() { if (saveChanges.getValue()) { try { plugin.setPropertiesToServer(getProperties()); } catch (Exception e) { getFrame().alertThrowable(getFrame(), e); return null; } } try { parent.mirthClient.getServlet(DataPrunerServletInterface.class).start(); } catch (Exception e) { parent.alertThrowable(parent, e, "An error occurred while attempting to start the data pruner."); return null; } return null; } @Override public void done() { if (saveChanges.getValue()) { setSaveEnabled(false); } parent.stopWorking(workingId); updateStatus(); } }; worker.execute(); }
From source file:com.floreantpos.config.ui.DatabaseConfigurationView.java
public void actionPerformed(ActionEvent e) { try {//w ww.j ava2 s. c om String command = e.getActionCommand(); Database selectedDb = (Database) databaseCombo.getSelectedItem(); String providerName = selectedDb.getProviderName(); String databaseURL = tfServerAddress.getText(); String databasePort = tfServerPort.getText(); String databaseName = tfDatabaseName.getText(); String user = tfUserName.getText(); String pass = new String(tfPassword.getPassword()); String connectionString = selectedDb.getConnectString(databaseURL, databasePort, databaseName); String hibernateDialect = selectedDb.getHibernateDialect(); String driverClass = selectedDb.getHibernateConnectionDriverClass(); if (TEST.equalsIgnoreCase(command)) { Application.getInstance().setSystemInitialized(false); saveConfig(selectedDb, providerName, databaseURL, databasePort, databaseName, user, pass, connectionString, hibernateDialect); try { DatabaseUtil.checkConnection(connectionString, hibernateDialect, driverClass, user, pass); } catch (DatabaseConnectionException e1) { JOptionPane.showMessageDialog(this, Messages.getString("DatabaseConfigurationDialog.32")); //$NON-NLS-1$ return; } JOptionPane.showMessageDialog(POSUtil.getBackOfficeWindow(), Messages.getString("DatabaseConfigurationDialog.31")); //$NON-NLS-1$ } else if (CONFIGURE_DB.equals(command)) { Application.getInstance().setSystemInitialized(false); int i = JOptionPane.showConfirmDialog(POSUtil.getBackOfficeWindow(), Messages.getString("DatabaseConfigurationDialog.33"), //$NON-NLS-1$ Messages.getString("DatabaseConfigurationDialog.34"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ if (i != JOptionPane.YES_OPTION) { return; } i = JOptionPane.showConfirmDialog(POSUtil.getBackOfficeWindow(), Messages.getString("DatabaseConfigurationView.3"), //$NON-NLS-1$ Messages.getString("DatabaseConfigurationView.4"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ boolean generateSampleData = false; if (i == JOptionPane.YES_OPTION) generateSampleData = true; saveConfig(selectedDb, providerName, databaseURL, databasePort, databaseName, user, pass, connectionString, hibernateDialect); String connectionString2 = selectedDb.getCreateDbConnectString(databaseURL, databasePort, databaseName); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); boolean createDatabase = DatabaseUtil.createDatabase(connectionString2, hibernateDialect, driverClass, user, pass, generateSampleData); this.setCursor(Cursor.getDefaultCursor()); if (createDatabase) { //JOptionPane.showMessageDialog(DatabaseConfigurationView.this, Messages.getString("DatabaseConfigurationDialog.35")); //$NON-NLS-1$ JOptionPane.showMessageDialog(POSUtil.getBackOfficeWindow(), "Database created. Default password is 1111.\n\nThe system will now restart."); //$NON-NLS-1$ Main.restart(); } else { JOptionPane.showMessageDialog(POSUtil.getBackOfficeWindow(), Messages.getString("DatabaseConfigurationDialog.36")); //$NON-NLS-1$ } } else if (SAVE.equalsIgnoreCase(command)) { Application.getInstance().setSystemInitialized(false); saveConfig(selectedDb, providerName, databaseURL, databasePort, databaseName, user, pass, connectionString, hibernateDialect); } else if (CANCEL.equalsIgnoreCase(command)) { } } catch (Exception e2) { POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getBackOfficeWindow(), e2.getMessage()); } }