Java Code Examples for javax.swing.JOptionPane#OK_CANCEL_OPTION

The following examples show how to use javax.swing.JOptionPane#OK_CANCEL_OPTION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Messages.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public static Messages getMessages(HashMap<String, Object> options, String bundle) {
  Messages msg = (Messages) options.get(MESSAGES);
  if (msg == null) {
    String language = (String) options.get(LANGUAGE);
    if (language == null) {
      JOptionPane pane = new JOptionPane("Please select your language:", JOptionPane.QUESTION_MESSAGE,
          JOptionPane.OK_CANCEL_OPTION);
      pane.setSelectionValues(getDescriptiveLanguageCodes(null));
      pane.setWantsInput(true);
      String initialSelection = getDescriptiveLanguageCode(Locale.getDefault().getLanguage());
      pane.setInitialSelectionValue(initialSelection);
      showDlg((Component) options.get(Options.MAIN_PARENT_COMPONENT), pane, "Language selecion");
      String sel = (String) pane.getInputValue();
      if (sel == null) {
        sel = initialSelection;
      }
      options.put(LANGUAGE, getLanguageFromDescriptive(sel));
    }
    msg = new Messages(bundle, options);
    options.put(MESSAGES, msg);
    Locale.setDefault(msg.getLocale());
  } else if (bundle != null) {
    msg.setLocale(options);
    msg.addBundle(bundle);
  }
  return msg;
}
 
Example 2
Source File: MultiSizeIssue.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static void chooseBandsWithSameSize() {
    String title = Dialogs.getDialogTitle("Choose bands with same size.");
    int optionType = JOptionPane.OK_CANCEL_OPTION;
    int messageType = JOptionPane.INFORMATION_MESSAGE;

    final StringBuilder msgTextBuilder = new StringBuilder("The functionality you have chosen is not supported for bands of different sizes.<br/>");

    JPanel panel = new JPanel(new BorderLayout(4, 4));
    final JEditorPane textPane = new JEditorPane("text/html", msgTextBuilder.toString());
    setFont(textPane);
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (IOException | URISyntaxException e1) {
                Dialogs.showWarning("Could not open URL: " + e.getDescription());
            }
        }
    });
    panel.add(textPane, BorderLayout.CENTER);
    final JComboBox<Object> resamplerBox = new JComboBox<>();

    NotifyDescriptor d = new NotifyDescriptor(panel, title, optionType, messageType, null, null);
    DialogDisplayer.getDefault().notify(d);
}
 
Example 3
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean showDialog(Window parent) {
  JOptionPane optionPane = new JOptionPane(mainPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
  JDialog dialog = optionPane.createDialog(parent, "Select plugin versions");
  dialog.setResizable(true);
  dialog.setVisible(true);
  return (((Integer)optionPane.getValue()).intValue() == JOptionPane.OK_OPTION);
}
 
Example 4
Source File: DialogInputReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public String readPassword(String promptMessage) {
    final JPasswordField jpf = new JPasswordField();
    JOptionPane jop = new JOptionPane(jpf,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = jop.createDialog(promptMessage);
    dialog.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jpf.requestFocusInWindow();
                }
            });
        }
    });
    dialog.setVisible(true);
    int result = (Integer) jop.getValue();
    dialog.dispose();
    String password = null;
    if (result == JOptionPane.OK_OPTION) {
        password = new String(jpf.getPassword());
    }
    if (StringUtils.isEmpty(password)) {
        return null;
    } else {
        return password;
    }
}
 
Example 5
Source File: DialogCallbackHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 6
Source File: DialogCallbackHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 7
Source File: DialogCallbackHandler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 8
Source File: ScoreActions.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Prompts the user for interactive confirmation or modification of
 * score/page parameters
 *
 * @param sheet the current sheet, or null
 * @return true if parameters are applied, false otherwise
 */
private static boolean applyUserSettings (final Sheet sheet)
{
    try {
        final WrappedBoolean apply = new WrappedBoolean(false);
        final ScoreParameters scoreParams = new ScoreParameters(sheet);
        final JOptionPane optionPane = new JOptionPane(
                scoreParams.getComponent(),
                JOptionPane.QUESTION_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION);
        final String frameTitle = (sheet != null)
                ? (sheet.getScore()
                .getRadix()
                   + " parameters")
                : "General parameters";
        final JDialog dialog = new JDialog(
                Main.getGui().getFrame(),
                frameTitle,
                true); // Modal flag
        dialog.setContentPane(optionPane);
        dialog.setName("scoreParams");

        optionPane.addPropertyChangeListener(
                new PropertyChangeListener()
        {
            @Override
            public void propertyChange (PropertyChangeEvent e)
            {
                String prop = e.getPropertyName();

                if (dialog.isVisible()
                    && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                    Object obj = optionPane.getValue();
                    int value = ((Integer) obj).intValue();
                    apply.set(value == JOptionPane.OK_OPTION);

                    // Exit only if user gives up or enters correct data
                    if (!apply.isSet()
                        || scoreParams.commit(sheet)) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    } else {
                        // Incorrect data, so don't exit yet
                        try {
                            // TODO: Is there a more civilized way?
                            optionPane.setValue(
                                    JOptionPane.UNINITIALIZED_VALUE);
                        } catch (Exception ignored) {
                        }
                    }
                }
            }
        });

        dialog.pack();
        MainGui.getInstance()
                .show(dialog);

        return apply.value;
    } catch (Exception ex) {
        logger.warn("Error in ScoreParameters", ex);

        return false;
    }
}
 
Example 9
Source File: VCardEditor.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
    * Displays a users profile.
    * 
    * @param jid
    *            the jid of the user.
    * @param vcard
    *            the users vcard.
    * @param parent
    *            the parent component, used for location handling.
    */
   public void displayProfile(final BareJid jid, VCard vcard, JComponent parent) {
VCardViewer viewer = new VCardViewer(jid);

final JFrame dlg = new JFrame(Res.getString("title.view.profile.for",
	jid));

avatarLabel = new JLabel();
avatarLabel.setHorizontalAlignment(JButton.RIGHT);
avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white,
	Color.lightGray));

// The user should only be able to close this dialog.
Object[] options = { Res.getString("button.view.profile"),
	Res.getString("close") };
final JOptionPane pane = new JOptionPane(viewer,
	JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
	options, options[0]);

// mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
// GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5,
// 5, 5), 0, 0));

dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16)
	.getImage());

dlg.pack();
dlg.setSize(350, 250);
dlg.setResizable(true);
dlg.setContentPane(pane);
dlg.setLocationRelativeTo(parent);

PropertyChangeListener changeListener = new PropertyChangeListener() {
    @Override
	public void propertyChange(PropertyChangeEvent e) {
	if (pane.getValue() instanceof Integer) {
	    pane.removePropertyChangeListener(this);
	    dlg.dispose();
	    return;
	}
	String value = (String) pane.getValue();
	if (Res.getString("close").equals(value)) {
	    pane.removePropertyChangeListener(this);
	    dlg.dispose();
	} else if (Res.getString("button.view.profile").equals(value)) {
	    pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
	    SparkManager.getVCardManager().viewFullProfile(jid, pane);
	}
    }
};

pane.addPropertyChangeListener(changeListener);

dlg.addKeyListener(new KeyAdapter() {
    @Override
	public void keyPressed(KeyEvent keyEvent) {
	if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
	    dlg.dispose();
	}
    }
});

dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
   }
 
Example 10
Source File: StandaloneShutdownDialog.java    From webanno with Apache License 2.0 4 votes vote down vote up
@EventListener
public void onApplicationEvent(ApplicationReadyEvent aEvt)
{
    log.info("Console: " + ((System.console() != null) ? "available" : "not available"));
    log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no"));
    
    // Show this only when run from the standalone JAR via a double-click
    if (port != -1 && System.console() == null && !GraphicsEnvironment.isHeadless()
            && runningFromCommandline) {
        log.info("If you are running " + applicationName
                + " in a server environment, please use '-Djava.awt.headless=true'");
        eventPublisher.publishEvent(
                new ShutdownDialogAvailableEvent(StandaloneShutdownDialog.this));

        final int style;
        final String[] options;
        if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
            style = JOptionPane.OK_CANCEL_OPTION;
            options = new String[] { ACTION_SHUTDOWN, ACTION_OPEN_BROWSER };
        }
        else {
            style = JOptionPane.OK_OPTION;
            options = new String[] { ACTION_SHUTDOWN };
        }
        
        EventQueue.invokeLater(() -> {
            final JOptionPane optionPane = new JOptionPane(
                    new JLabel("<HTML>" + applicationName + " is running now and can be "
                            + "accessed via <b>http://localhost:8080</b>.<br>"
                            + applicationName
                            + " works best with the browsers Google Chrome or Safari.<br>"
                            + "Use this dialog to shut " + applicationName + " down.</HTML>"),
                    JOptionPane.INFORMATION_MESSAGE, style, null, options);

            final JDialog dialog = new JDialog((JFrame) null, applicationName, false);
            dialog.setContentPane(optionPane);
            dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
            dialog.addWindowListener(new WindowAdapter()
            {
                @Override
                public void windowClosing(WindowEvent we)
                {
                    // Avoid closing window by other means than button
                }
            });
            optionPane.addPropertyChangeListener(this::handleCloseEvent);
            dialog.pack();
            dialog.setVisible(true);
        });
    }
    else {
        log.info("Running in server environment or from command line: disabling interactive shutdown dialog.");
    }
}
 
Example 11
Source File: BookActions.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Prompts the user for interactive confirmation or modification of
 * book/page parameters
 *
 * @param stub the current sheet stub, or null
 * @return true if parameters are applied, false otherwise
 */
private static boolean applyUserSettings (final SheetStub stub)
{
    try {
        final WrappedBoolean apply = new WrappedBoolean(false);
        final ScoreParameters scoreParams = new ScoreParameters(stub);
        final JOptionPane optionPane = new JOptionPane(
                scoreParams.getComponent(),
                JOptionPane.QUESTION_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION);
        final String frameTitle = (stub != null) ? (stub.getBook().getRadix() + " parameters")
                : "General parameters";
        final JDialog dialog = new JDialog(OMR.gui.getFrame(), frameTitle, true); // Modal flag
        dialog.setContentPane(optionPane);
        dialog.setName("scoreParams");

        optionPane.addPropertyChangeListener(new PropertyChangeListener()
        {
            @Override
            public void propertyChange (PropertyChangeEvent e)
            {
                String prop = e.getPropertyName();

                if (dialog.isVisible() && (e.getSource() == optionPane)
                            && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                    Object obj = optionPane.getValue();
                    int value = (Integer) obj;
                    apply.set(value == JOptionPane.OK_OPTION);

                    // Exit only if user gives up or enters correct data
                    if (!apply.isSet() || scoreParams.commit(stub)) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    } else {
                        // Incorrect data, so don't exit yet
                        try {
                            // TODO: Is there a more civilized way?
                            optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                        } catch (Exception ignored) {
                        }
                    }
                }
            }
        });

        dialog.pack();
        OmrGui.getApplication().show(dialog);

        return apply.value;
    } catch (Exception ex) {
        logger.warn("Error in ScoreParameters", ex);

        return false;
    }
}
 
Example 12
Source File: UploadPropertiesDialog.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
public void openProperties(final UploadActionListener uploader){		
	JPanel message = new JPanel(new GridBagLayout());
	
	serverUrl = labelTextField(Constant.messages.getString("codedx.settings.serverurl") + " ", message,
			CodeDxProperties.getInstance().getServerUrl(), 30);
	apiKey = labelTextField(Constant.messages.getString("codedx.settings.apikey") + " ", message,
			CodeDxProperties.getInstance().getApiKey(), 30);
	projectBox = createProjectComboBox(message);
	timeout = labelTextField(Constant.messages.getString("codedx.setting.timeout") + " ", message,
			CodeDxProperties.getInstance().getTimeout(), 5);
	
	final JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
			DIALOG_BUTTONS, null);
	dialog = pane.createDialog(Constant.messages.getString("codedx.settings.title"));
	
	Thread popupThread = new Thread(){
		@Override
		public void run(){								
			dialog.setVisible(true);
			if (DIALOG_BUTTONS[0].equals(pane.getValue())) {
				String timeoutValue = timeout.getText();
				if (!isStringNumber(timeoutValue)) {
					timeoutValue = CodeDxProperties.DEFAULT_TIMEOUT_STRING;
					error(Constant.messages.getString("codedx.error.timeout"));
				}
				CodeDxProperties.getInstance().setProperties(serverUrl.getText(), apiKey.getText(), getProject().getValue(), timeoutValue);
				uploader.generateAndUploadReport();
			}
		}
	};
	Thread updateThread = new Thread(){
		@Override
		public void run(){
			if(!"".equals(serverUrl.getText()) && !"".equals(apiKey.getText())){
				updateProjects(true);
				String previousId = CodeDxProperties.getInstance().getSelectedId();
				for(NameValuePair p: projectArr){
					if(previousId.equals(p.getValue()))
						projectBox.setSelectedItem(p);
				}
			}
		}
	};
	popupThread.start();
	updateThread.start();
}
 
Example 13
Source File: DialogCallbackHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 14
Source File: IdeOptions.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
public void showOptions0() {
	IdeOptions o = this; // new IdeOptions(IdeOptions.theCurrentOptions);

	JPanel p1 = new JPanel(new GridLayout(1, 1));
	p1.add(new JScrollPane(general()));
	JPanel p2 = new JPanel(new GridLayout(1, 1));
	p2.add(new JScrollPane(onlyColors()));
	JPanel p3 = new JPanel(new GridLayout(1, 1));
	p3.add(new JScrollPane(outline()));
	JTabbedPane jtb = new JTabbedPane();
	jtb.add("General", p1);
	jtb.add("Colors", p2);
	jtb.add("Outline", p3);
	CodeTextPanel cc = new CodeTextPanel("", AqlOptions.getMsg());
	jtb.addTab("CQL", cc);

	jtb.setSelectedIndex(selected_tab);
	JPanel oo = new JPanel(new GridLayout(1, 1));
	oo.add(jtb);
	// oo.setPreferredSize(theD);

	// outline at top otherwise weird sizing collapse on screen
	JOptionPane pane = new JOptionPane(oo, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
			new String[] { "OK", "Cancel", "Reset", "Save", "Load", "Delete" }, "OK");
	// pane.setPreferredSize(theD);
	JDialog dialog = pane.createDialog(null, "Options");
	dialog.setModal(false);
	dialog.setResizable(true);
	dialog.addWindowListener(new WindowAdapter() {

		@Override
		public void windowDeactivated(WindowEvent e) {
			Object ret = pane.getValue();

			selected_tab = jtb.getSelectedIndex();

			if (ret == "OK") {
				theCurrentOptions = o;
				notifyListenersOfChange();
			} else if (ret == "Reset") {
				new IdeOptions().showOptions0();
			} else if (ret == "Save") { // save
				save(o);
				o.showOptions0();
			} else if (ret == "Load") { // load
				load().showOptions0();
			} else if (ret == "Delete") {
				delete();
				o.showOptions0();
			}
		}

	});
	dialog.setPreferredSize(theD);
	dialog.pack();
	dialog.setLocationRelativeTo(null);
	dialog.setVisible(true);
}
 
Example 15
Source File: InputTextAreaDialog.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
  * Prompt and return input.
  *
  * @param title       the title of the dialog.
  * @param description the dialog description.
  * @param icon        the icon to use.
  * @param parent      the parent to use.
  * @return the user input.
  */
 public String getInput(String title, String description, Icon icon, Component parent) {
     textArea = new JTextArea();
     textArea.setLineWrap(true);

     TitlePanel titlePanel = new TitlePanel(title, description, icon, true);

     // Construct main panel w/ layout.
     final JPanel mainPanel = new JPanel();
     mainPanel.setLayout(new BorderLayout());
     mainPanel.add(titlePanel, BorderLayout.NORTH);

     // The user should only be able to close this dialog.
     final Object[] options = {Res.getString("ok"), Res.getString("cancel")};
     optionPane = new JOptionPane(new JScrollPane(textArea), JOptionPane.PLAIN_MESSAGE,
             JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);

     mainPanel.add(optionPane, BorderLayout.CENTER);

     // Let's make sure that the dialog is modal. Cannot risk people
     // losing this dialog.
     JOptionPane p = new JOptionPane();
     dialog = p.createDialog(parent, title);
     dialog.setModal(true);
     dialog.pack();
     dialog.setSize(width, height);
     dialog.setContentPane(mainPanel);
     dialog.setLocationRelativeTo(parent);
     optionPane.addPropertyChangeListener(this);

     // Add Key Listener to Send Field
     textArea.addKeyListener(new KeyAdapter() {
         @Override
public void keyPressed(KeyEvent e) {
             if (e.getKeyChar() == KeyEvent.VK_TAB) {
                 optionPane.requestFocus();
             }
             else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                 dialog.dispose();
             }
         }
     });

     textArea.requestFocus();


     dialog.setVisible(true);
     return stringValue;
 }
 
Example 16
Source File: BookmarkEditor.java    From FancyBing with GNU General Public License v3.0 4 votes vote down vote up
public Bookmark editItem(Component parent, String title,
                         Bookmark bookmark, boolean selectName,
                         MessageDialogs messageDialogs)
{
    JPanel panel = new JPanel(new BorderLayout(GuiUtil.SMALL_PAD, 0));
    m_panelLeft = new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    panel.add(m_panelLeft, BorderLayout.WEST);
    m_panelRight =
        new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    panel.add(m_panelRight, BorderLayout.CENTER);
    m_name = createEntry("LB_BOOKMARKEDITOR_NAME", 25, bookmark.m_name);
    String file = "";
    if (bookmark.m_file != null)
        file = bookmark.m_file.toString();
    m_file = createEntry("LB_BOOKMARKEDITOR_FILE", 25, file);
    String move = "";
    if (bookmark.m_move > 0)
        move = Integer.toString(bookmark.m_move);
    m_move = createEntry("LB_BOOKMARKEDITOR_MOVE", 10, move);
    m_variation = createEntry("LB_BOOKMARKEDITOR_VARIATION", 10,
                              bookmark.m_variation);
    JOptionPane optionPane = new JOptionPane(panel,
                                             JOptionPane.PLAIN_MESSAGE,
                                             JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = optionPane.createDialog(parent, title);
    boolean done = false;
    while (! done)
    {
        if (selectName)
            m_name.selectAll();
        dialog.addWindowListener(new WindowAdapter() {
                public void windowActivated(WindowEvent e) {
                    m_name.requestFocusInWindow();
                }
            });
        dialog.setVisible(true);
        Object value = optionPane.getValue();
        if (! (value instanceof Integer)
            || ((Integer)value).intValue() != JOptionPane.OK_OPTION)
            return null;
        done = validate(parent, messageDialogs);
    }
    String newName = m_name.getText().trim();
    File newFile = new File(m_file.getText());
    int newMove = getMove();
    String newVariation = m_variation.getText().trim();
    Bookmark newBookmark =
        new Bookmark(newName, newFile, newMove, newVariation);
    dialog.dispose();
    return newBookmark;
}
 
Example 17
Source File: UsernamePassword.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Ask using a GUI for the username and password.
 */
private void readFromGUI() {
   // Create fields for user name.
   final JTextField usernameField = new JTextField(20);
   usernameField.setText(this.username);
   final JLabel usernameLabel = new JLabel("Username: ");
   usernameLabel.setLabelFor(usernameField);
   final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   usernamePane.add(usernameLabel);
   usernamePane.add(usernameField);

   // Create fields for password.
   final JPasswordField passwordField = new JPasswordField(20);
   passwordField.setText(this.password);
   final JLabel passwordLabel = new JLabel("Password: ");
   passwordLabel.setLabelFor(passwordField);
   final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   passwordPane.add(passwordLabel);
   passwordPane.add(passwordField);

   // Create panel
   final JPanel main = new JPanel();
   main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
   main.add(usernamePane);
   main.add(passwordPane);

   // Create and handle dialog
   final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog = jop.createDialog("User name and password");
   dialog.addComponentListener(new ComponentAdapter() {
      
      public void componentShown(ComponentEvent e) {
         SwingUtilities.invokeLater(new Runnable() {
            
            public void run() {
               if (usernameField.getText().isEmpty())
               {
                  usernameField.requestFocusInWindow();
               }
               else
               {
                  passwordField.requestFocusInWindow();
               }
            }
         });
      }
   });
   dialog.setVisible(true);
   final Integer result = (Integer) jop.getValue();
   dialog.dispose();
   if (result.intValue() == JOptionPane.OK_OPTION) {
      this.username = usernameField.getText();

      final char[] pwd = passwordField.getPassword();
      this.password = new String(pwd);
   }
}
 
Example 18
Source File: DialogCallbackHandler.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 19
Source File: DialogCallbackHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 20
Source File: DialogCallbackHandler.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}