Java Code Examples for javax.swing.JOptionPane#showInternalConfirmDialog()

The following examples show how to use javax.swing.JOptionPane#showInternalConfirmDialog() . 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: 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 2
Source File: ProjectCloseModule.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters,
    @Nonnull Collection<Task> tasks) {

  int selectedValue = JOptionPane.showInternalConfirmDialog(
      MZmineCore.getDesktop().getMainWindow().getContentPane(),
      "Are you sure you want to close the current project?", "Close project",
      JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

  if (selectedValue != JOptionPane.YES_OPTION)
    return ExitCode.CANCEL;

  // Close all windows related to previous project
  GUIUtils.closeAllWindows();

  // Create a new, empty project
  MZmineProject newProject = new MZmineProjectImpl();

  // Replace the current project with the new one
  ProjectManager projectManager = MZmineCore.getProjectManager();
  projectManager.setCurrentProject(newProject);

  // Ask the garbage collector to free the previously used memory
  System.gc();

  logger.info("Project closed.");
  return ExitCode.OK;
}
 
Example 3
Source File: MainWindow.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public @Nonnull ExitCode exitMZmine() {

  int selectedValue = JOptionPane.showInternalConfirmDialog(this.getContentPane(),
      "Are you sure you want to exit?", "Exiting...", JOptionPane.YES_NO_OPTION,
      JOptionPane.WARNING_MESSAGE);

  if (selectedValue != JOptionPane.YES_OPTION)
    return ExitCode.CANCEL;

  this.dispose();

  logger.info("Exiting MZmine");

  System.exit(0);

  return ExitCode.OK;
}