Java Code Examples for javax.swing.JOptionPane#QUESTION_MESSAGE

The following examples show how to use javax.swing.JOptionPane#QUESTION_MESSAGE . 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: AutoUpgrade.java    From netbeans with Apache License 2.0 8 votes vote down vote up
private static boolean showUpgradeDialog (final File source, String note) {
       Util.setDefaultLookAndFeel();

JPanel panel = new JPanel(new BorderLayout());
panel.add(new AutoUpgradePanel (source.getAbsolutePath (), note), BorderLayout.CENTER);
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
panel.add(progressBar, BorderLayout.SOUTH);
progressBar.setVisible(false);

JButton bYES = new JButton("Yes");
bYES.setMnemonic(KeyEvent.VK_Y);
JButton bNO = new JButton("No");
bNO.setMnemonic(KeyEvent.VK_N);
JButton[] options = new JButton[] {bYES, bNO};
       JOptionPane p = new JOptionPane (panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, bYES);
       JDialog d = Util.createJOptionProgressDialog(p, NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), source, progressBar);
       d.setVisible (true);

       return new Integer (JOptionPane.YES_OPTION).equals (p.getValue ());
   }
 
Example 2
Source File: TestViewer.java    From sis with Apache License 2.0 7 votes vote down vote up
/**
 * Saves the image of the currently selected frame.
 */
private void savePNG() {
    final RenderedImage image = getSelectedImage();
    if (image != null) {
        final File file = new File(System.getProperty("user.home"), "ImageTest.png");
        final String title, message;
        final int type;
        if (file.exists()) {
            type    = JOptionPane.WARNING_MESSAGE;
            title   = "Confirm overwrite";
            message = "File " + file + " exists. Overwrite?";
        } else {
            type    = JOptionPane.QUESTION_MESSAGE;
            title   = "Confirm write";
            message = "Save in " + file + '?';
        }
        if (JOptionPane.showInternalConfirmDialog(desktop, message, title,
                JOptionPane.YES_NO_OPTION, type) == JOptionPane.OK_OPTION)
        {
            try {
                ImageTestCase.savePNG(image, file);
            } catch (IOException e) {
                JOptionPane.showInternalMessageDialog(desktop, e.toString(),
                        "Error", JOptionPane.WARNING_MESSAGE);
            }
        }
    }
}
 
Example 3
Source File: Messages.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public int confirmOverwriteFile(Component parent, File f, String buttons) {
  int result = YES;
  if (f.exists()) {
    boolean dir = f.isDirectory();
    List<Object> v = new ArrayList<Object>();
    v.add(get(dir ? "FILE_DIR_BEG" : "FILE_BEG"));
    v.add(quote(f.getAbsolutePath()));
    boolean readOnly = !f.canWrite();
    if (readOnly) {
      v.add(get("FILE_READONLY"));
    } else {
      v.add(get("FILE_EXISTS"));
      v.add(get(dir ? "FILE_OVERWRITE_DIR_PROMPT" : "FILE_OVERWRITE_PROMPT"));
    }
    if (readOnly) {
      showErrorWarning(parent, ERROR, v, null, null);
      result = CANCEL;
    } else {
      NarrowOptionPane pane = new NarrowOptionPane(60, v.toArray(), JOptionPane.QUESTION_MESSAGE,
          JOptionPane.DEFAULT_OPTION, null, parseButtons(buttons));
      result = getFeedback(parent, pane, get("CONFIRM"));
    }
  }
  return result;
}
 
Example 4
Source File: ConfirmTabCloseDialog.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
private void initLayout() {
	Object[] messages = new Object[1];
	{
		JPanel srp = new JPanel();
		srp.setLayout(new BorderLayout());
		JLabel jl = new JLabel("Are you sure you want to close this tab?");
		srp.add(jl, BorderLayout.NORTH);
		messages[0] = srp;
	}

	pane = new JOptionPane(messages, // the dialog message array
			JOptionPane.QUESTION_MESSAGE, // message type
			JOptionPane.DEFAULT_OPTION, // option type
			null, // optional icon, use null to use the default icon
			OPTIONS, // options string array, will be made into buttons
			OPTIONS[0]);

	dialog = pane.createDialog(parent,  LangTool.getString("sa.confirmTabClose"));

}
 
Example 5
Source File: MessageDialogs.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
/** Show a question with two options and cancel.
    @return 0 for the destructive option; 1 for the non-destructive
    option; 2 for cancel */
public int showYesNoCancelQuestion(String disableKey, Component parent,
                                   String mainMessage,
                                   String optionalMessage,
                                   String destructiveOption,
                                   String nonDestructiveOption)
{
    if (checkDisabled(disableKey))
        return 0;
    Object[] options = new Object[3];
    int destructiveIndex;
    if (Platform.isMac())
    {
        options[0] = nonDestructiveOption;
        options[1] = i18n("LB_CANCEL");
        options[2] = destructiveOption;
        destructiveIndex = 2;
    }
    else
    {
        options[0] = nonDestructiveOption;
        options[1] = destructiveOption;
        options[2] = i18n("LB_CANCEL");
        destructiveIndex = -1;
    }
    Object defaultOption = options[0];
    int type = JOptionPane.QUESTION_MESSAGE;
    Object value = show(disableKey, parent, "", mainMessage,
                        optionalMessage, type,
                        JOptionPane.YES_NO_CANCEL_OPTION, options,
                        defaultOption, destructiveIndex);
    int result;
    if (value == destructiveOption)
        result = 0;
    else if (value == nonDestructiveOption)
        result = 1;
    else
        result = 2;
    return result;
}
 
Example 6
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 7
Source File: StartupDialog.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static int styleFromMessageType(int messageType) {
    switch (messageType) {
    case JOptionPane.ERROR_MESSAGE:
        return JRootPane.ERROR_DIALOG;
    case JOptionPane.QUESTION_MESSAGE:
        return JRootPane.QUESTION_DIALOG;
    case JOptionPane.WARNING_MESSAGE:
        return JRootPane.WARNING_DIALOG;
    case JOptionPane.INFORMATION_MESSAGE:
        return JRootPane.INFORMATION_DIALOG;
    case JOptionPane.PLAIN_MESSAGE:
    default:
        return JRootPane.PLAIN_DIALOG;
    }
}
 
Example 8
Source File: OptionDialog.java    From Astrosoft with GNU General Public License v2.0 5 votes vote down vote up
public static int showDialog(String message, int messageType){

		int optionType = JOptionPane.DEFAULT_OPTION;
		String title = null;
		
		if (messageType == JOptionPane.ERROR_MESSAGE){
			title = "Error ";
			optionType = JOptionPane.DEFAULT_OPTION;
		}else if (messageType == JOptionPane.QUESTION_MESSAGE){
			title = "Confirm ";
			optionType = JOptionPane.YES_NO_OPTION;
		}
		else if (messageType == JOptionPane.INFORMATION_MESSAGE){
			title = "Information ";
			optionType = JOptionPane.DEFAULT_OPTION;
		}
		
		JOptionPane pane = new JOptionPane(message, messageType, optionType);
		
		JDialog dialog = pane.createDialog(pane, title);
		
		UIUtil.applyOptionPaneBackground(pane,UIConsts.OPTIONPANE_BACKGROUND);
		
		dialog.setVisible(true);
		
		Object selectedValue = pane.getValue();
	    if(selectedValue instanceof Integer) {
	    	return ((Integer)selectedValue).intValue();
		}
	    return JOptionPane.CLOSED_OPTION;
	}
 
Example 9
Source File: SystemRequestDialog.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
private void initLayout() {
	JPanel srp = new JPanel();
	srp.setLayout(new BorderLayout());
	JLabel jl = new JLabel("Enter alternate job");
	text = new JTextField();
	srp.add(jl, BorderLayout.NORTH);
	srp.add(text, BorderLayout.CENTER);
	Object[] message = new Object[1];
	message[0] = srp;

	pane = new JOptionPane(message, // the dialog message array
			JOptionPane.QUESTION_MESSAGE, // message type
			JOptionPane.DEFAULT_OPTION, // option type
			null, // optional icon, use null to use the default icon
			OPTIONS, // options string array, will be made into buttons
			OPTIONS[0]);

	dialog = pane.createDialog(parent, "System Request");

	// add the listener that will set the focus to the desired option
	dialog.addWindowListener(new WindowAdapter() {
		public void windowOpened(WindowEvent e) {
			text.requestFocus();
		}
	});

}
 
Example 10
Source File: PollIntervalDialog.java    From sql-developer-keepalive with MIT License 4 votes vote down vote up
private void initDialog() {
    textField = new JTextField(20);
    PlainDocument doc = (PlainDocument) textField.getDocument();
    doc.setDocumentFilter(new NumberFilter());

    Object[] controls = { "Specify poll interval (in seconds):", textField };
    Object[] options = { OK_STRING, CANCEL_STRING };

    optionPane = new JOptionPane(controls, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);
    setContentPane(optionPane);

    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent e) {

            if (isVisible() && JOptionPane.VALUE_PROPERTY.equals(e.getPropertyName())) {

                Object value = optionPane.getValue();

                if (value == JOptionPane.UNINITIALIZED_VALUE) {
                    return;
                }

                switch (value.toString()) {
                case OK_STRING:
                    String v = textField.getText();
                    if (checkValue(v)) {
                        pollInterval = Integer.parseInt(v, 10);
                        setVisible(false);
                    } else {
                        //to let PropertyChangeEvent fire next time the user presses button
                        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                    }
                    break;

                case CANCEL_STRING:
                    pollInterval = null;
                    setVisible(false);
                    break;
                }
            }
        }

    });
}
 
Example 11
Source File: MultiSizeIssue.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public static Product maybeResample(Product product) {
    String title = Dialogs.getDialogTitle("Resampling Required");
    final List<Resampler> availableResamplers = getAvailableResamplers(product);
    int optionType;
    int messageType;
    final StringBuilder msgTextBuilder = new StringBuilder("The functionality you have chosen is not supported for products with bands of different sizes.<br/>");
    if (availableResamplers.isEmpty()) {
        optionType = JOptionPane.OK_CANCEL_OPTION;
        messageType = JOptionPane.INFORMATION_MESSAGE;
    } else if (availableResamplers.size() == 1) {
        msgTextBuilder.append("You can use the ").append(availableResamplers.get(0).getName()).
                append(" to resample this product so that all bands have the same size, <br/>" +
                               "which will enable you to use this feature.<br/>" +
                               "Do you want to resample the product now?");
        optionType = JOptionPane.YES_NO_OPTION;
        messageType = JOptionPane.QUESTION_MESSAGE;
    } else {
        msgTextBuilder.append("You can use one of these resamplers to resample this product so that all bands have the same size, <br/>" +
                                      "which will enable you to use this feature.<br/>" +
                                      "Do you want to resample the product now?");
        optionType = JOptionPane.YES_NO_OPTION;
        messageType = JOptionPane.QUESTION_MESSAGE;
    }
    msgTextBuilder.append("<br/>" +
                                  "<br/>" +
                                  "More info about this issue and its status can be found in the " +
                                  "<a href=\"https://senbox.atlassian.net/browse/SNAP-1\">SNAP Issue Tracker</a>."
    );
    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<>();
    if (availableResamplers.size() > 1) {
        String[] resamplerNames = new String[availableResamplers.size()];
        for (int i = 0; i < availableResamplers.size(); i++) {
            resamplerNames[i] = availableResamplers.get(i).getName();
            resamplerBox.addItem(resamplerNames[i]);
        }
        panel.add(resamplerBox, BorderLayout.SOUTH);
    }
    NotifyDescriptor d = new NotifyDescriptor(panel, title, optionType, messageType, null, null);
    DialogDisplayer.getDefault().notify(d);
    if (d.getValue() == NotifyDescriptor.YES_OPTION) {
        Resampler selectedResampler;
        if (availableResamplers.size() == 1) {
            selectedResampler = availableResamplers.get(0);
        } else {
            selectedResampler = availableResamplers.get(resamplerBox.getSelectedIndex());
        }
        return selectedResampler.resample(product);
    }
    return null;
}
 
Example 12
Source File: SelectExportMethodDialog.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private static DialogDescriptor createDialog(Component parentComponent, String title, String text, String helpID, JCheckBox[] options) {
    final String copyToClipboardText = "Copy to Clipboard";  /*I18N*/
    final String writeToFileText = "Write to File"; /*I18N*/
    final String cancelText = "Cancel"; /*I18N*/

    final String iconDir = "/org/esa/snap/resources/images/icons/";
    final ImageIcon copyIcon = new ImageIcon(SelectExportMethodDialog.class.getResource(iconDir + "Copy16.gif"));
    final ImageIcon saveIcon = new ImageIcon(SelectExportMethodDialog.class.getResource(iconDir + "Save16.gif"));

    final JButton copyToClipboardButton = new JButton(copyToClipboardText);
    copyToClipboardButton.setMnemonic('b');
    copyToClipboardButton.setIcon(copyIcon);

    final JButton writeToFileButton = new JButton(writeToFileText);
    writeToFileButton.setMnemonic('W');
    writeToFileButton.setIcon(saveIcon);

    final JButton cancelButton = new JButton(cancelText);
    cancelButton.setMnemonic('C');
    cancelButton.setIcon(null);

    final JPanel panel = new JPanel(new GridBagLayout());
    final JPanel checkboxPanel = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.LINE_START;
    c.gridx = 0;
    c.gridy = GridBagConstraints.RELATIVE;
    for (JCheckBox option : options) {
        checkboxPanel.add(option, c);
    }
    c.gridx = 0;
    c.gridy = 0;
    panel.add(checkboxPanel, c);
    final JPanel buttonPanel = new JPanel(new FlowLayout());
    c.gridy = GridBagConstraints.RELATIVE;
    buttonPanel.add(copyToClipboardButton, c);
    buttonPanel.add(writeToFileButton, c);
    buttonPanel.add(cancelButton, c);
    c.gridx = 0;
    c.gridy = 1;
    panel.add(buttonPanel, c);

    final JOptionPane optionPane = new JOptionPane(text, /*I18N*/
                                                   JOptionPane.QUESTION_MESSAGE,
                                                   JOptionPane.DEFAULT_OPTION,
                                                   null,
                                                   new JPanel[]{panel},
                                                   copyToClipboardButton);
    final JDialog dialog = optionPane.createDialog(parentComponent, title);
    dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    if (helpID != null) {
        HelpCtx.setHelpIDString((JComponent) optionPane, helpID);
    }

    // Create action listener for all 3 buttons (as instance of an anonymous class)
    final ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            optionPane.setValue(e.getSource());
            dialog.setVisible(false);
            dialog.dispose();
        }
    };
    copyToClipboardButton.addActionListener(actionListener);
    writeToFileButton.addActionListener(actionListener);
    cancelButton.addActionListener(actionListener);

    return new DialogDescriptor(dialog, optionPane, copyToClipboardButton, writeToFileButton);
}
 
Example 13
Source File: LicenseCompanion.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void doInstall ()
        throws Exception
{
    // When running without UI, we assume license is accepted
    if (!Installer.hasUI()) {
        return;
    }

    // User choice (must be an output, yet final)
    final boolean[] isOk = new boolean[1];

    final String yes = "Yes";
    final String no = "No";
    final String browse = "View License";
    final JOptionPane optionPane = new JOptionPane(
            "Do you agree to license " + LICENSE_NAME + "?",
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_CANCEL_OPTION,
            null,
            new Object[]{yes, no, browse},
            yes);
    final String frameTitle = "End User License Agreement";
    final JDialog dialog = new JDialog(
            Installer.getFrame(),
            frameTitle,
            true);
    dialog.setContentPane(optionPane);

    // Prevent dialog closing
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

    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 option = optionPane.getValue();
                logger.debug("option: {}", option);

                if (option == yes) {
                    isOk[0] = true;
                    dialog.setVisible(false);
                    dialog.dispose();
                } else if (option == no) {
                    isOk[0] = false;
                    dialog.setVisible(false);
                    dialog.dispose();
                } else if (option == browse) {
                    logger.info(
                            "Launching browser on {}",
                            LICENSE_URL);
                    showLicense();
                    optionPane.setValue(
                            JOptionPane.UNINITIALIZED_VALUE);
                } else {
                }
            }
        }
    });

    dialog.pack();
    dialog.setLocationRelativeTo(Installer.getFrame());
    dialog.setVisible(true);

    logger.debug("OK: {}", isOk[0]);

    if (!isOk[0]) {
        throw new LicenseDeclinedException();
    }
}
 
Example 14
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 15
Source File: Macronizer.java    From tn5250j with GNU General Public License v2.0 4 votes vote down vote up
public static void showRunScriptDialog(SessionPanel session) {

      JPanel rsp = new JPanel();
      rsp.setLayout(new BorderLayout());
      JLabel jl = new JLabel("Enter script to run");
      final JTextField rst = new JTextField();
      rsp.add(jl,BorderLayout.NORTH);
      rsp.add(rst,BorderLayout.CENTER);
      Object[]      message = new Object[1];
      message[0] = rsp;
      String[] options = {"Run","Cancel"};

      final JOptionPane pane = new JOptionPane(
             message,                           // the dialog message array
             JOptionPane.QUESTION_MESSAGE,      // message type
             JOptionPane.DEFAULT_OPTION,        // option type
             null,                              // optional icon, use null to use the default icon
             options,                           // options string array, will be made into buttons//
             options[0]);                       // option that should be made into a default button


      // create a dialog wrapping the pane
      final JDialog dialog = pane.createDialog(session, // parent frame
                        "Run Script"  // dialog title
                        );

      // add the listener that will set the focus to
      // the desired option
      dialog.addWindowListener( new WindowAdapter() {
         public void windowOpened( WindowEvent e) {
            super.windowOpened( e );

            // now we're setting the focus to the desired component
            // it's not the best solution as it depends on internals
            // of the OptionPane class, but you can use it temporarily
            // until the bug gets fixed
            // also you might want to iterate here thru the set of
            // the buttons and pick one to call requestFocus() for it

            rst.requestFocus();
         }
      });
      dialog.setVisible(true);

      // now we can process the value selected
      // now we can process the value selected
      // if its Integer, the user most likely hit escape
      Object myValue = pane.getValue();
      if (!(myValue instanceof Integer)) {
         String value = (String) myValue;

         if (value.equals(options[0])) {
             // send option along with system request
             if (rst.getText().length() > 0) {
                 invoke(rst.getText(), session);
             }
         }
      }


   }
 
Example 16
Source File: Messages.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public boolean showInputDlg(Component parent, String[] msgKeys, String[] shortPromptKeys, JComponent[] promptObjects,
    String titleKey) {

  ArrayList<Object> v = new ArrayList<Object>();

  if (msgKeys != null) {
    for (String msgKey : msgKeys) {
      v.add(get(msgKey));
    }
  }

  if (promptObjects != null) {
    if (shortPromptKeys == null) {
      for (JComponent jc : promptObjects) {
        v.add(jc);
      }
    } else {
      GridBagLayout gridBag = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.BOTH;
      c.insets = new java.awt.Insets(3, 3, 3, 3);

      JPanel panel = new JPanel(gridBag);
      for (int i = 0; i < promptObjects.length; i++) {
        if (shortPromptKeys.length > i) {
          JLabel lb = new JLabel(get(shortPromptKeys[i]));
          lb.setLabelFor(promptObjects[i]);
          lb.setHorizontalAlignment(SwingConstants.LEFT);
          c.gridwidth = GridBagConstraints.RELATIVE;
          gridBag.setConstraints(lb, c);
          panel.add(lb);
        }
        c.gridwidth = GridBagConstraints.REMAINDER;
        gridBag.setConstraints(promptObjects[i], c);
        panel.add(promptObjects[i]);
      }
      v.add(panel);
    }
  }
  String title = (titleKey != null ? get(titleKey) : "");

  NarrowOptionPane pane = new NarrowOptionPane(60, v.toArray(), JOptionPane.QUESTION_MESSAGE,
      JOptionPane.DEFAULT_OPTION, null, parseButtons("oc"));
  return getFeedback(parent, pane, title) == OK;
}
 
Example 17
Source File: SwingClientApplication.java    From chipster with MIT License 4 votes vote down vote up
@Override
public void setVisualisationMethod(VisualisationMethod method, List<Variable> variables, List<DataBean> datas, FrameType target) {
	
	if (method == null) {
		boolean datasetsSelected = (datas != null && !datas.isEmpty());
		boolean datasetsExist = !getDataManager().databeans().isEmpty();
		
		if (datasetsSelected) {
			method = VisualisationMethods.DATA_DETAILS;
		} else if (datasetsExist) {
			method = VisualisationMethods.SESSION_DETAILS;
		} else {				
			method = VisualisationMethods.EMPTY;
		}				
		
		super.setVisualisationMethod(method, variables, datas, target);
		return;
	}

	long estimate = method.estimateDuration(datas);

	if (estimate > SLOW_VISUALISATION_LIMIT) {
		int returnValue = JOptionPane.DEFAULT_OPTION;

		String message = "";
		int severity;
		// Check the running tasks
		if (estimate > VERY_SLOW_VISUALISATION_LIMIT) {

			message += "Visualising the selected large dataset with this method might stop Chipster from responding. \n" + "If you choose to continue, it's recommended to save the session before visualising.";
			severity = JOptionPane.WARNING_MESSAGE;
		} else {
			message += "Are you sure you want to visualise large dataset, which may " + "take several seconds?";
			severity = JOptionPane.QUESTION_MESSAGE;
		}
		Object[] options = { "Cancel", "Visualise" };

		returnValue = JOptionPane.showOptionDialog(this.getMainFrame(), message, "Cancel visualisation", JOptionPane.YES_NO_OPTION, severity, null, options, options[0]);

		if (returnValue == 1) {
			super.setVisualisationMethod(method, variables, datas, target);
		} else {
			return;
		}
	} else {
		super.setVisualisationMethod(method, variables, datas, target);
	}
}
 
Example 18
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 19
Source File: CustomDialog.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    // Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    // Create an array specifying the number of dialog buttons
    // and their text.
    Object[] options = { btnString1, btnString2 };

    // Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);

    // Make this dialog display it.
    setContentPane(optionPane);

    // Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window, we're going to change
             * the JOptionPane's value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    // Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    // Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    // Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}
 
Example 20
Source File: Messages.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public int showQuestionDlgObj(Component parent, Object msg, String titleKey, String buttons) {
  NarrowOptionPane pane = new NarrowOptionPane(60, msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION,
      null, parseButtons(buttons));
  String title = get(StrUtils.secureString(titleKey, "QUESTION"));
  return getFeedback(parent, pane, title);
}