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:Forms.CreateGearForm.java
private void showLintErrorDialog(GearSpecLintResult result) { Object[] options = { "OK" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel), result.getResponseMessage(), "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);/*from w ww.j a v a2 s .com*/ }
From source file:net.sf.jabref.exporter.SaveDatabaseAction.java
/** * Check whether or not the external database has been modified. If so need to alert the user to accept external updates prior to * saving the database. This is necessary to avoid overwriting other users work when using a multiuser database file. * * @return true if the external database file has been modified and the user must choose to accept the changes and false if no modifications * were found or there is no requested protection for the database file. *//* w w w . ja v a 2 s.c o m*/ private boolean checkExternalModification() { // Check for external modifications: if (panel.isUpdatedExternally() || Globals.fileUpdateMonitor.hasBeenModified(panel.getFileMonitorHandle())) { String[] opts = new String[] { Localization.lang("Review changes"), Localization.lang("Save"), Localization.lang("Cancel") }; int answer = JOptionPane.showOptionDialog(panel.frame(), Localization.lang("File has been updated externally. " + "What do you want to do?"), Localization.lang("File updated externally"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]); if (answer == JOptionPane.CANCEL_OPTION) { canceled = true; return true; } else if (answer == JOptionPane.YES_OPTION) { canceled = true; JabRefExecutorService.INSTANCE.execute((Runnable) () -> { if (!FileBasedLock.waitForFileLock(panel.getBibDatabaseContext().getDatabaseFile(), 10)) { // TODO: GUI handling of the situation when the externally modified file keeps being locked. LOGGER.error("File locked, this will be trouble."); } ChangeScanner scanner = new ChangeScanner(panel.frame(), panel, panel.getBibDatabaseContext().getDatabaseFile()); JabRefExecutorService.INSTANCE.executeWithLowPriorityInOwnThreadAndWait(scanner); if (scanner.changesFound()) { scanner.displayResult((ChangeScanner.DisplayResultCallback) resolved -> { if (resolved) { panel.setUpdatedExternally(false); SwingUtilities.invokeLater( (Runnable) () -> panel.getSidePaneManager().hide("fileUpdate")); } else { canceled = true; } }); } }); return true; } else { // User indicated to store anyway. if (panel.getBibDatabaseContext().getMetaData().isProtected()) { JOptionPane.showMessageDialog(frame, Localization .lang("Database is protected. Cannot save until external changes have been reviewed."), Localization.lang("Protected database"), JOptionPane.ERROR_MESSAGE); canceled = true; } else { panel.setUpdatedExternally(false); panel.getSidePaneManager().hide("fileUpdate"); } } } // Return false as either no external database file modifications have been found or overwrite is requested any way return false; }
From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java
private User createUserFromPrompter() { JTextField nameField = new JTextField(15); JTextField passField = new JPasswordField(15); JTextField confirmField = new JPasswordField(15); JPanel namePanel = new JPanel(new BorderLayout()); namePanel.add(new JLabel("User Name"), BorderLayout.WEST); namePanel.add(nameField, BorderLayout.EAST); JPanel passPanel = new JPanel(new BorderLayout()); passPanel.add(new JLabel("Password"), BorderLayout.WEST); passPanel.add(passField, BorderLayout.EAST); JPanel confirmPanel = new JPanel(new BorderLayout()); confirmPanel.add(new JLabel("Confirm Password"), BorderLayout.WEST); confirmPanel.add(confirmField, BorderLayout.EAST); Object[] messages = new Object[] { "Specify the User's Name and Password.", namePanel, passPanel, confirmPanel };/*w w w.j av a2 s .co m*/ String[] options = { "OK", "Cancel", }; int option = JOptionPane.showOptionDialog(getPanel(), messages, "Specify the User's Name and Password", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (nameField.getText().equals("") || nameField.getText() == null || passField.getText().equals("") || passField.getText() == null) { return null; } if (!passField.getText().equals(confirmField.getText())) { JOptionPane.showMessageDialog(getPanel(), "The passwords you entered do not match.", "Error", JOptionPane.ERROR_MESSAGE); return null; } User user = null; if (option == 0) { String password; try { password = new String(Hex.encodeHex(digester.digest(passField.getText().getBytes("UTF-8")))); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unable to encode password", e); } user = new User(nameField.getText(), password); } return user; }
From source file:net.chaosserver.timelord.swingui.CommonTaskPanel.java
/** * Shows a dialog the gives the user the option to hide a task * that has not been written to for a long time. * * @param taskName the name of the task to prompt the user to hide * @param lastInputDate the last date the user added time to the task * * @return Either (0) for hiding the task or (1) for continuing to show *//*from ww w . j a va2s .co m*/ protected int showHideTaskDialog(String taskName, Date lastInputDate) { int result; String hideTask = "Hide Task"; String ignore = "Ignore"; Object[] options = { hideTask, ignore }; result = JOptionPane.showOptionDialog(null, "No time has been tracked to the task [" + taskName + "] since [" + DateUtil.BASIC_DATE_FORMAT.format(lastInputDate) + "]. Do you wish to hide it?", "Hide Very Old Task", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, hideTask); return result; }
From source file:Forms.CreateGearForm.java
private void showSaveErrorDialog() { Object[] options = { "OK" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel), "There was a problem saving your Gear Spec. Please try again.", "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); }
From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java
public boolean isConfirmed() { Object[] options = { "Yes", "No" }; int option = JOptionPane.showOptionDialog(panelMain, "Are you sure you want to generate '" + model.getFileName() + "' ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, new ImageIcon(getClass().getResource(ICON_CONFIRM)), options, options[0]); return option == JOptionPane.OK_OPTION; }
From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java
/** * Show an error message with toggable detail * * @param parent/*w w w .ja v a 2 s . c o m*/ * @param mesg * @param title * @param exception */ public static void showErrorMessage(Component parent, String mesg, String title, Throwable exception) { boolean details = false; while (true) { String[] opts = new String[] { details ? "Hide Details" : "Details", "Ok" }; StringBuffer buf = new StringBuffer(); if (mesg != null) { buf.append(mesg); } appendException(exception, 0, buf, details); //MultilineLabel message = new MultilineLabel(buf.toString()); javax.swing.JTextArea message = new javax.swing.JTextArea(buf.toString()); message.setEditable(false); message.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); javax.swing.JLabel jl = new javax.swing.JLabel(); message.setFont(jl.getFont()); message.setBackground(jl.getBackground()); int opt = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, opts, opts[1]); if (opt == 0) { details = !details; } else { break; } } }
From source file:net.sf.jabref.gui.exporter.SaveDatabaseAction.java
/** * Check whether or not the external database has been modified. If so need to alert the user to accept external updates prior to * saving the database. This is necessary to avoid overwriting other users work when using a multiuser database file. * * @return true if the external database file has been modified and the user must choose to accept the changes and false if no modifications * were found or there is no requested protection for the database file. *//* w w w . ja v a 2s . co m*/ private boolean checkExternalModification() { // Check for external modifications: if (panel.isUpdatedExternally() || Globals.getFileUpdateMonitor().hasBeenModified(panel.getFileMonitorHandle())) { String[] opts = new String[] { Localization.lang("Review changes"), Localization.lang("Save"), Localization.lang("Cancel") }; int answer = JOptionPane.showOptionDialog(panel.frame(), Localization.lang("File has been updated externally. " + "What do you want to do?"), Localization.lang("File updated externally"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]); if (answer == JOptionPane.CANCEL_OPTION) { canceled = true; return true; } else if (answer == JOptionPane.YES_OPTION) { canceled = true; JabRefExecutorService.INSTANCE.execute(() -> { if (!FileBasedLock.waitForFileLock(panel.getBibDatabaseContext().getDatabaseFile().toPath(), 10)) { // TODO: GUI handling of the situation when the externally modified file keeps being locked. LOGGER.error("File locked, this will be trouble."); } ChangeScanner scanner = new ChangeScanner(panel.frame(), panel, panel.getBibDatabaseContext().getDatabaseFile()); JabRefExecutorService.INSTANCE.executeWithLowPriorityInOwnThreadAndWait(scanner); if (scanner.changesFound()) { scanner.displayResult(resolved -> { if (resolved) { panel.setUpdatedExternally(false); SwingUtilities.invokeLater(() -> panel.getSidePaneManager().hide("fileUpdate")); } else { canceled = true; } }); } }); return true; } else { // User indicated to store anyway. if (panel.getBibDatabaseContext().getMetaData().isProtected()) { JOptionPane.showMessageDialog(frame, Localization .lang("Database is protected. Cannot save until external changes have been reviewed."), Localization.lang("Protected database"), JOptionPane.ERROR_MESSAGE); canceled = true; } else { panel.setUpdatedExternally(false); panel.getSidePaneManager().hide("fileUpdate"); } } } // Return false as either no external database file modifications have been found or overwrite is requested any way return false; }
From source file:com.atlauncher.data.Settings.java
public void loadEverything() { setupServers(); // Setup the servers available to use in the Launcher findActiveServers(); // Find active servers loadServerProperty(false); // Get users Server preference if (hasUpdatedFiles()) { downloadUpdatedFiles(); // Downloads updated files on the server }//from w w w .j a va 2 s . co m checkForLauncherUpdate(); downloadExternalLibraries(); if (!Utils.checkAuthLibLoaded()) { LogManager.error("AuthLib was not loaded into the classpath!"); } loadNews(); // Load the news this.languageLoaded = true; // Languages are now loaded loadMinecraftVersions(); // Load info about the different Minecraft versions loadPacks(); // Load the Packs available in the Launcher loadUsers(); // Load the Testers and Allowed Players for the packs loadInstances(); // Load the users installed Instances loadAccounts(); // Load the saved Accounts loadCheckingServers(); // Load the saved servers we're checking with the tool loadProperties(); // Load the users Properties if (this.isUsingCustomJavaPath()) { checkForValidJavaPath(true); // Checks for a valid Java path } console.setupLanguage(); // Setup language on the console clearOldLogs(); // Clear all the old logs out checkResources(); // Check for new format of resources checkAccountUUIDs(); // Check for accounts UUID's and add them if necessary LogManager.debug("Checking for access to master server"); OUTER: for (Pack pack : this.packs) { if (pack.isTester()) { for (Server server : this.servers) { if (server.getName().equals("Master Server (Testing Only)")) { server.setUserSelectable(true); LogManager.debug("Access to master server granted"); break OUTER; // Don't need to check anymore so break the outer loop } } } } LogManager.debug("Finished checking for access to master server"); loadServerProperty(true); // Get users Server preference if (Utils.isWindows() && this.javaPath.contains("x86")) { LogManager.warn("You're using 32 bit Java on a 64 bit Windows install!"); String[] options = { Language.INSTANCE.localize("common.yes"), Language.INSTANCE.localize("common.no") }; int ret = JOptionPane.showOptionDialog(App.settings.getParent(), HTMLUtils.centerParagraph( Language.INSTANCE.localizeWithReplace("settings.running32bit", "<br/><br/>")), Language.INSTANCE.localize("settings.running32bittitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (ret == 0) { Utils.openBrowser("http://www.atlauncher.com/help/32bit/"); System.exit(0); } } if (!Utils.isJava7OrAbove(true) && !this.hideOldJavaWarning) { LogManager.warn("You're using an old unsupported version of Java (Java 6 or older)!"); String[] options = { Language.INSTANCE.localize("common.download"), Language.INSTANCE.localize("common" + ".ok"), Language.INSTANCE.localize("instance" + "" + ".dontremindmeagain") }; int ret = JOptionPane.showOptionDialog(App.settings.getParent(), HTMLUtils.centerParagraph( Language.INSTANCE.localizeWithReplace("settings.unsupportedjava", "<br/><br/>")), Language.INSTANCE.localize("settings.unsupportedjavatitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (ret == 0) { Utils.openBrowser("http://atl.pw/java7download"); System.exit(0); } else if (ret == 2) { this.hideOldJavaWarning = true; this.saveProperties(); } } if (this.advancedBackup) { dropbox = new DropboxSync(); } if (!this.hadPasswordDialog) { checkAccounts(); // Check accounts with stored passwords } if (this.enableServerChecker) { this.startCheckingServers(); } }
From source file:Forms.CreateGearForm.java
private void showLoadErrorDialog() { Object[] options = { "OK" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel), "There was a problem loading your Gear Spec. Please try again.", "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); }