List of usage examples for javax.swing JOptionPane putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:eu.delving.sip.base.VisualFeedback.java
public static boolean askOption(JDesktopPane desktop, Object message, String title, int optionType, int messageType) { JOptionPane pane = new JOptionPane(message, messageType, optionType, null, null, null); pane.putClientProperty(new Object(), Boolean.TRUE); JDialog frame = pane.createDialog(desktop, title); pane.selectInitialValue();/*from w w w . j a v a 2s. c o m*/ frame.setVisible(true); acquireFocus(); Object selectedValue = pane.getValue(); return selectedValue != null && selectedValue instanceof Integer && (Integer) selectedValue == YES_OPTION; }
From source file:eu.delving.sip.base.VisualFeedback.java
public static String askQuestion(JDesktopPane desktop, String question, Object initialSelectionValue) { final JOptionPane pane = new JOptionPane(question, QUESTION_MESSAGE, OK_CANCEL_OPTION, null, null, null); pane.putClientProperty(new Object(), Boolean.TRUE); pane.setWantsInput(true);//from w w w. j a v a 2 s . c om pane.setInitialSelectionValue(initialSelectionValue); JDialog frame = pane.createDialog(desktop, "Question"); pane.selectInitialValue(); frame.setVisible(true); acquireFocus(); Object value = pane.getInputValue(); return value == UNINITIALIZED_VALUE ? null : (String) value; }
From source file:processing.app.Editor.java
/** * Check if the sketch is modified and ask user to save changes. * @return false if canceling the close/quit operation *///from w w w .ja va 2 s . co m protected boolean checkModified() { if (!sketch.isModified()) return true; // As of Processing 1.0.10, this always happens immediately. // http://dev.processing.org/bugs/show_bug.cgi?id=1456 toFront(); String prompt = I18n.format(_("Save changes to \"{0}\"? "), sketch.getName()); if (!OSUtils.isMacOS()) { int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.YES_OPTION: return handleSave(true); case JOptionPane.NO_OPTION: return true; // ok to continue case JOptionPane.CANCEL_OPTION: case JOptionPane.CLOSED_OPTION: // Escape key pressed return false; default: throw new IllegalStateException(); } } else { // This code is disabled unless Java 1.5 is being used on Mac OS X // because of a Java bug that prevents the initial value of the // dialog from being set properly (at least on my MacBook Pro). // The bug causes the "Don't Save" option to be the highlighted, // blinking, default. This sucks. But I'll tell you what doesn't // suck--workarounds for the Mac and Apple's snobby attitude about it! // I think it's nifty that they treat their developers like dirt. // Pane formatting adapted from the quaqua guide // http://www.randelshofer.ch/quaqua/guide/joptionpane.html JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }" + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>" + " before closing?</b>" + "<p>If you don't save, your changes will be lost."), JOptionPane.QUESTION_MESSAGE); String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") }; pane.setOptions(options); // highlight the safest option ala apple hig pane.setInitialValue(options[0]); // on macosx, setting the destructive property places this option // away from the others at the lefthand side pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2)); JDialog dialog = pane.createDialog(this, null); dialog.setVisible(true); Object result = pane.getValue(); if (result == options[0]) { // save (and close/quit) return handleSave(true); } else if (result == options[2]) { // don't save (still close/quit) return true; } else { // cancel? return false; } } }