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:org.forester.archaeopteryx.TreePanel.java
final private void addEmptyNode(final PhylogenyNode node) { if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) { errorMessageNoCutCopyPasteInUnrootedDisplay(); return;/* www . j a v a 2 s.c om*/ } final String label = getASimpleTextRepresentationOfANode(node); String msg = ""; if (ForesterUtil.isEmpty(label)) { msg = "How to add the new, empty node?"; } else { msg = "How to add the new, empty node to node" + label + "?"; } final Object[] options = { "As sibling", "As descendant", "Cancel" }; final int r = JOptionPane.showOptionDialog(this, msg, "Addition of Empty New Node", JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); boolean add_as_sibling = true; if (r == 1) { add_as_sibling = false; } else if (r != 0) { return; } final Phylogeny phy = new Phylogeny(); phy.setRoot(new PhylogenyNode()); phy.setRooted(true); if (add_as_sibling) { if (node.isRoot()) { JOptionPane.showMessageDialog(this, "Cannot add sibling to root", "Attempt to add sibling to root", JOptionPane.ERROR_MESSAGE); return; } phy.addAsSibling(node); } else { phy.addAsChild(node); } _phylogeny.externalNodesHaveChanged(); _phylogeny.hashIDs(); _phylogeny.recalculateNumberOfExternalDescendants(true); resetNodeIdToDistToLeafMap(); setEdited(true); repaint(); }
From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java
private boolean promptForDelete(SPObject obj) { String typeString = ""; if (obj instanceof User) { typeString = "User"; }/*from w ww . ja v a 2 s. c o m*/ if (obj instanceof Group) { typeString = "Group"; } Object[] options = { "Yes", "No" }; int option = JOptionPane.showOptionDialog(null, new Object[] { "Are you sure you want to delete the " + typeString + " \"" + obj.getName() + "\"?" }, "", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (option == 0) { return true; } return false; }
From source file:net.pms.newgui.GeneralTab.java
public void addPlugins() { FormLayout layout = new FormLayout("fill:10:grow", "p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); int i = 1;/*from w ww .j a v a 2 s. c o m*/ for (final ExternalListener listener : ExternalFactory.getExternalListeners()) { if (i > 30) { logger.warn("Plugin limit of 30 has been reached"); break; } JButton bPlugin = new JButton(listener.name()); // listener to show option screen bPlugin.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showOptionDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), listener.config(), Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); } }); builder.add(bPlugin, cc.xy(1, i++)); } pPlugins.add(builder.getPanel()); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java
/** * // w w w .java2s .co m */ protected void checkForChanges() { if (fieldHasChanged) { Object[] options = { getResourceString("SAVE"), //$NON-NLS-1$ getResourceString("DISCARD") }; //$NON-NLS-1$ int retVal = JOptionPane.showOptionDialog(null, getResourceString("FFE_SAVE_CHG"), //$NON-NLS-1$ getResourceString("SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION, //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (retVal == JOptionPane.YES_OPTION) { fieldsPanel.getEditBtn().doClick(); } } }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
protected boolean checkForOrdersConflictingWithExistingData(MarketLogFile logFile, final PriceInfo.Type priceType) { // get date of latest price currently known MarketFilter filter = new MarketFilterBuilder(priceType, logFile.getRegion()).end(); final List<PriceInfo> history = fetchPriceInfo(filter, logFile.getInventoryType()); if (history.isEmpty() || logFile.isEmpty()) { return true; }/* w w w . j a v a 2 s . c o m*/ EveDate latestHistoryDate = null; for (PriceInfo info : history) { if (latestHistoryDate == null || info.getTimestamp().compareTo(latestHistoryDate) >= 0) { latestHistoryDate = info.getTimestamp(); } } // get earliest price timestamp from market log final EveDate[] earliestFileDate = new EveDate[1]; logFile.visit(new IMarketLogVisitor() { @Override public void visit(MarketLogEntry entry) { if (!priceType.matches(entry.getType())) { return; } if (earliestFileDate[0] == null || entry.getIssueDate().compareTo(earliestFileDate[0]) < 0) { earliestFileDate[0] = entry.getIssueDate(); } } }); if (earliestFileDate[0] == null) { return true; } // check for overlapping of price data from file // with already known prices if (earliestFileDate[0].compareTo(latestHistoryDate) <= 0) { String typeLabel; switch (priceType) { case BUY: typeLabel = "buy"; break; case SELL: typeLabel = "sell"; break; default: throw new RuntimeException("Unhandled switch/case"); } final String label = "<HTML><BODY>" + "<BR><BR>" + "WARNING: This market logfile contains " + typeLabel + " orders that conflict <BR> with " + "data already present in the application's database.<BR><BR>"; final String[] options = { "Ignore conflicting " + typeLabel + " orders", "Cancel" }; final int userChoice = JOptionPane.showOptionDialog(null, label, "Orders from market log conflict with existing data", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (userChoice == 0) { final int size = logFile.size(); final int removedCount = logFile.removeEntriesOlderThan(latestHistoryDate, priceType); JOptionPane.showMessageDialog(null, "Removed " + removedCount + " of " + size + " " + typeLabel + " orders total ( left: " + logFile.size() + " )"); } else { return false; } } return true; }
From source file:com.atlauncher.data.Settings.java
public void checkAccounts() { boolean matches = false; if (this.accounts != null || this.accounts.size() >= 1) { for (Account account : this.accounts) { if (account.isRemembered()) { matches = true;//from ww w . j a v a 2 s. com } } } if (matches) { String[] options = { Language.INSTANCE.localize("common.ok"), Language.INSTANCE.localize("account" + "" + ".removepasswords") }; int ret = JOptionPane.showOptionDialog(App.settings.getParent(), HTMLUtils.centerParagraph( Language.INSTANCE.localizeWithReplace("account.securitywarning", "<br/>")), Language.INSTANCE.localize("account.securitywarningtitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (ret == 1) { for (Account account : this.accounts) { if (account.isRemembered()) { account.setRemember(false); } } this.saveAccounts(); } } this.saveProperties(); }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Starts up the timelord application and displays the frame. *///from ww w .j a va 2 s. c om public void start() { applicationFrame = new JFrame("Timelord"); // Get the pretty application icon URL iconUrl = this.getClass().getResource("/net/chaosserver/timelord/TimelordIcon.gif"); if (log.isTraceEnabled()) { log.trace("iconUrl is [" + iconUrl + "]"); } if (iconUrl != null) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image applicationImage = toolkit.getImage(iconUrl); applicationIcon = new ImageIcon(applicationImage); applicationFrame.setIconImage(applicationImage); } else { if (log.isWarnEnabled()) { log.warn("Cound not find icon url"); } } if (!isAlreadyRunning() && !isUpgradeRequested()) { TimelordMenu menu = new TimelordMenu(this); applicationFrame.setJMenuBar(menu); applicationFrame.addWindowListener(new WindowCloser()); if (OsUtil.isMac()) { try { Class<?> macSwingerClass = Class .forName("net.chaosserver.timelord." + "swingui.macos.MacSwinger"); Constructor<?> macSwingerConstructor = macSwingerClass .getConstructor(new Class[] { Timelord.class }); macSwingerConstructor.newInstance(new Object[] { this }); } catch (Exception e) { // Shouldn't happen, but not a big deal if (log.isWarnEnabled()) { log.warn("Failed to create the MacSwinger", e); } } } TimelordDataReaderWriter timelordDataRW = new XmlDataReaderWriter(); try { TimelordData inputTimelordData = timelordDataRW.readTimelordData(); inputTimelordData.cleanse(); inputTimelordData.resetTaskListeners(); setTimelordData(inputTimelordData); menu.setTimelordData(getTimelordData()); applicationFrame.setSize(loadLastFrameSize()); timelordTabbedPane = new TimelordTabbedPane(getTimelordData()); applicationFrame.getContentPane().add(timelordTabbedPane); applicationFrame.setLocation(loadLastFrameLocation()); applicationFrame.setVisible(true); // If there is no data for Today, let the user set the // start time. TimelordDayView timelordDayView = new TimelordDayView(inputTimelordData, DateUtil.trunc(new Date())); if (timelordDayView.getTotalTimeToday(true) == 0) { menu.timelord.changeStartTime(true); } bringToFrontThread = new BringToFrontThread(applicationFrame, this); bringToFrontThread.start(); autoSaveThread = new AutoSaveThread(getTimelordData()); autoSaveThread.start(); } catch (TimelordDataException e) { String shutdown = "Shutdown"; Object[] options = { shutdown }; JOptionPane.showOptionDialog(null, "There was an unrecoverable error trying to load " + "the file.\nTimelord was probably shutdown " + "in the middle of the last write.\nThere " + "should be a lot of backup files inside the " + "defaut location.\nCopy one of the backups " + "over the most recent, restart, and keep your " + "fingers crossed.\n" + e, "Timelord Data File Corrupted", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, shutdown); stop(); } } else { stop(); } }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
/** * Override the default removal so we can actually stop sharing * and delete the file./* www. j a v a2 s . c o m*/ * Deletes the selected rows in the table. * CAUTION: THIS WILL DELETE THE FILE FROM THE DISK. */ public void removeSelection() { int[] rows = TABLE.getSelectedRows(); if (rows.length == 0) return; if (TABLE.isEditing()) { TableCellEditor editor = TABLE.getCellEditor(); editor.cancelCellEditing(); } List<File> files = new ArrayList<File>(rows.length); // sort row indices and go backwards so list indices don't change when // removing the files from the model list Arrays.sort(rows); for (int i = rows.length - 1; i >= 0; i--) { File file = DATA_MODEL.getFile(rows[i]); files.add(file); } CheckBoxListPanel<File> listPanel = new CheckBoxListPanel<File>(files, new FileTextProvider(), true); listPanel.getList().setVisibleRowCount(4); // display list of files that should be deleted Object[] message = new Object[] { new MultiLineLabel(I18n.tr( "Are you sure you want to delete the selected file(s), thus removing it from your computer?"), 400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP), listPanel, Box.createVerticalStrut(ButtonRow.BUTTON_SEP) }; // get platform dependent options which are displayed as buttons in the dialog Object[] removeOptions = createRemoveOptions(); int option = JOptionPane.showOptionDialog(MessageService.getParentComponent(), message, I18n.tr("Message"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, removeOptions, removeOptions[0] /* default option */); if (option == removeOptions.length - 1 /* "cancel" option index */ || option == JOptionPane.CLOSED_OPTION) { return; } // remove still selected files List<File> selected = listPanel.getSelectedElements(); List<String> undeletedFileNames = new ArrayList<String>(); for (File file : selected) { // stop seeding if seeding BittorrentDownload dm = null; if ((dm = TorrentUtil.getDownloadManager(file)) != null) { dm.setDeleteDataWhenRemove(false); dm.setDeleteTorrentWhenRemove(false); BTDownloadMediator.instance().remove(dm); } // close media player if still playing if (MediaPlayer.instance().isThisBeingPlayed(file)) { MediaPlayer.instance().stop(); MPlayerMediator.instance().showPlayerWindow(false); } // removeOptions > 2 => OS offers trash options boolean removed = FileUtils.delete(file, removeOptions.length > 2 && option == 0 /* "move to trash" option index */); if (removed) { DATA_MODEL.remove(DATA_MODEL.getRow(file)); } else { undeletedFileNames.add(getCompleteFileName(file)); } } clearSelection(); if (undeletedFileNames.isEmpty()) { return; } // display list of files that could not be deleted message = new Object[] { new MultiLineLabel(I18n.tr( "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."), 400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP), new JScrollPane(createFileList(undeletedFileNames)) }; JOptionPane.showMessageDialog(MessageService.getParentComponent(), message, I18n.tr("Error"), JOptionPane.ERROR_MESSAGE); super.removeSelection(); }
From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java
/** * @return Return true if there is a small number of labels or whether the user wishes to continue. *///from w w w. jav a2s . c o m protected boolean checkForALotOfLabels(final RecordSetIFace recordSet) { // if (recordSet.getNumItems() > 200) // XXX Pref { Object[] options = { getResourceString("Create_New_Report"), getResourceString("CANCEL") }; int n = JOptionPane.showOptionDialog(UIRegistry.get(UIRegistry.FRAME), String.format(getResourceString("LotsOfLabels"), new Object[] { (recordSet.getNumItems()) }), getResourceString("LotsOfLabelsTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //don't use a custom Icon options, //the titles of buttons options[0]); //default button title if (n == 1) { return false; } } return true; }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveHex(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUHexFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hex Files", "hex"); fc.setFileFilter(filter);//from www . j a v a2 s.c o m fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".hex")) { fileToBeSaved = new File(fc.getSelectedFile() + ".hex"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame1 = new JFrame(); n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { String filePath; try { filePath = fileToBeSaved.getPath(); fileToBeSaved.delete(); } finally { } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].isHexFile) { fileSaveHex(i, bank.patch[i].hexFile, filePath); } else { fileSaveHex(i, bank.patch[i].patchModel.getRenderBlock().generateHex(), filePath); } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } saveMRUHexFolder(filePath); } }