Java Code Examples for javax.swing.JOptionPane#OK_OPTION

The following examples show how to use javax.swing.JOptionPane#OK_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: AlertFiltersMultipleOptionsPanel.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public boolean showRemoveDialogue(AlertFilter e) {
    JCheckBox removeWithoutConfirmationCheckBox = new JCheckBox(REMOVE_DIALOG_CHECKBOX_LABEL);
    Object[] messages = {REMOVE_DIALOG_TEXT, " ", removeWithoutConfirmationCheckBox};
    int option =
            JOptionPane.showOptionDialog(
                    View.getSingleton().getMainFrame(),
                    messages,
                    REMOVE_DIALOG_TITLE,
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    new String[] {
                        REMOVE_DIALOG_CONFIRM_BUTTON_LABEL, REMOVE_DIALOG_CANCEL_BUTTON_LABEL
                    },
                    null);

    if (option == JOptionPane.OK_OPTION) {
        setRemoveWithoutConfirmation(removeWithoutConfirmationCheckBox.isSelected());
        return true;
    }

    return false;
}
 
Example 2
Source File: ScaleBuilder.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * An abnormal situation has been found, as detailed in provided msg,
 * now how should we proceed, depending on batch mode or user answer.
 *
 * @param msg the problem description
 * @throws StepException thrown when processing must stop
 */
private void makeDecision (String msg)
        throws StepException
{
    logger.warn(msg.replaceAll(LINE_SEPARATOR, " "));

    Score score = sheet.getScore();

    if (Main.getGui() != null) {
        // Make sheet visible to the user
        SheetsController.getInstance().showAssembly(sheet);
    }

    if ((Main.getGui() == null)
        || (Main.getGui().displayModelessConfirm(
            msg + LINE_SEPARATOR + "OK for discarding this sheet?") == JOptionPane.OK_OPTION)) {
        if (score.isMultiPage()) {
            sheet.remove(false);
            throw new StepException("Sheet removed");
        } else {
            throw new StepException("Sheet ignored");
        }
    }
}
 
Example 3
Source File: GlobalSettingsDialog.java    From swingsane with Apache License 2.0 6 votes vote down vote up
private void addLoginActionPerformed(ActionEvent e) {
  LoginDialog loginDialog = new LoginDialog(this);
  Login login = new Login();
  loginDialog.setUsername(login.getUsername());
  loginDialog.setPassword(login.getPassword());
  loginDialog.setModal(true);
  loginDialog.setVisible(true);
  if (loginDialog.getDialogResult() == JOptionPane.OK_OPTION) {
    login.setUsername(loginDialog.getUsername().trim());
    login.setPassword(loginDialog.getPassword().trim());
    String resource = loginDialog.getResource().trim();
    if (!(logins.containsKey(resource))) {
      logins.put(resource, login);
      loginListModel.addElement(resource);
    }
    loginList.revalidate();
  }
}
 
Example 4
Source File: InputOutputAnnotationSetsDialog.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Show the dialog. If the dialog is closed with the OK button, the
 * contents of the two lists (input and output annotation set names)
 * are persisted back to the relevant Controller features.
 * 
 * @return true if the dialog was closed with the OK button, false
 *         otherwise.
 */
public boolean showDialog(Component parent) {
  int selectedOption = JOptionPane.showConfirmDialog(parent, panel,
          "Select input and output annotation sets",
          JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
  if(selectedOption == JOptionPane.OK_OPTION) {
    inputSetNames.clear();
    for(int i = 0; i < inputList.listModel.size(); i++) {
      inputSetNames.add(inputList.listModel.get(i));
    }

    outputSetNames.clear();
    for(int i = 0; i < outputList.listModel.size(); i++) {
      outputSetNames.add(outputList.listModel.get(i));
    }

    return true;
  }
  else {
    return false;
  }
}
 
Example 5
Source File: DefaultTitleEditor.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Presents a font selection dialog to the user.
 */
public void attemptFontSelection() {

    FontChooserPanel panel = new FontChooserPanel(this.titleFont);
    int result =
        JOptionPane.showConfirmDialog(
            this, panel, localizationResources.getString("Font_Selection"),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE
        );

    if (result == JOptionPane.OK_OPTION) {
        this.titleFont = panel.getSelectedFont();
        this.fontfield.setText(
            this.titleFont.getFontName() + " " + this.titleFont.getSize()
        );
    }
}
 
Example 6
Source File: SLDEditorDlg.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean load(JFrame frame) {
    Object[] options = {
        Localisation.getString(SLDEditor.class, "common.discard"),
        Localisation.getString(SLDEditor.class, "common.cancel")
    };

    int result =
            JOptionPane.showOptionDialog(
                    frame,
                    Localisation.getString(SLDEditor.class, "SLDEditor.unsavedChanges"),
                    Localisation.getString(SLDEditor.class, "SLDEditor.unsavedChangesTitle"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    options,
                    options[1]);

    // If discard option selected then allow the new symbol to be loaded
    return (result == JOptionPane.OK_OPTION);
}
 
Example 7
Source File: FilterLoader.java    From GIFKR with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean CopyFilterFiles(List<File> files, Component parent) {

		int response = JOptionPane.showConfirmDialog(parent, "<html><body><p style='width: 200px;'>"+FilterLoader.getFilterWarning()+"</p></body></html>", "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

		if(response != JOptionPane.OK_OPTION)
			return false;

		for(File f : files) {
			try {
				Files.copy(f.toPath(), new File(filterPath+"/"+f.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}	

//		GIFKR.restartApplication();

		return true;
	}
 
Example 8
Source File: Launcher.java    From open-ig with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Uninstall the game.
 */
void doUninstall() {
	if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(this, 
			label("Do you want to uninstall the game (removes all game files except save)?"),
			label("Uninstall"), JOptionPane.YES_NO_OPTION)) {
		File[] files = currentDir.listFiles(new FilenameFilter() {
			@Override
			public boolean accept(File dir, String name) {
				return name.startsWith("open-ig-");
			}
		});
		if (files != null) {
			for (File f : files) {
				if (!f.delete()) {
					System.out.printf("Could not delete file: %s%n", f);
				}
			}
		}
	}
}
 
Example 9
Source File: Program.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Used by macOsxCode() - should not be changed
 */
public void exit() {
	if (getStatusPanel().updateInProgress() > 0) {
		int value = JOptionPane.showConfirmDialog(getMainWindow().getFrame(),  GuiFrame.get().exitMsg(getStatusPanel().updateInProgress()), GuiFrame.get().exitTitle(getStatusPanel().updateInProgress()), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
		if (value != JOptionPane.OK_OPTION) {
			return;
		}
	}
	getStatusPanel().cancelUpdates();
	saveExit();
	LOG.info("Running shutdown hook(s) and exiting...");
	System.exit(0);
}
 
Example 10
Source File: Print.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
public static void doPrint(Project proj) {
	CircuitJList list = new CircuitJList(proj, true);
	Frame frame = proj.getFrame();
	if (list.getModel().getSize() == 0) {
		JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("printEmptyCircuitsMessage"),
				Strings.get("printEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
		return;
	}
	ParmsPanel parmsPanel = new ParmsPanel(list);
	int action = JOptionPane.showConfirmDialog(frame, parmsPanel, Strings.get("printParmsTitle"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
	if (action != JOptionPane.OK_OPTION)
		return;
	List<Circuit> circuits = list.getSelectedCircuits();
	if (circuits.isEmpty())
		return;

	PageFormat format = new PageFormat();
	Printable print = new MyPrintable(proj, circuits, parmsPanel.getHeader(), parmsPanel.getRotateToFit(),
			parmsPanel.getPrinterView());

	PrinterJob job = PrinterJob.getPrinterJob();
	job.setPrintable(print, format);
	if (job.printDialog() == false)
		return;
	try {
		job.print();
	} catch (PrinterException e) {
		JOptionPane.showMessageDialog(proj.getFrame(), StringUtil.format(Strings.get("printError"), e.toString()),
				Strings.get("printErrorTitle"), JOptionPane.ERROR_MESSAGE);
	}
}
 
Example 11
Source File: KnoxLoginDialog.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void collect() throws CredentialCollectionException {
  JLabel jl = new JLabel("Enter Your username: ");
  JTextField juf = new JTextField(24);
  JLabel jl2 = new JLabel("Enter Your password:  ");
  JPasswordField jpf = new JPasswordField(24);
  Box box1 = Box.createHorizontalBox();
  box1.add(jl);
  box1.add(juf);
  Box box2 = Box.createHorizontalBox();
  box2.add(jl2);
  box2.add(jpf);
  Box box = Box.createVerticalBox();
  box.add(box1);
  box.add(box2);

  // JDK-5018574 : Unable to set focus to another component in JOptionPane
  SwingUtils.workAroundFocusIssue(juf);

  int x = JOptionPane.showConfirmDialog(null, box,
      "KnoxShell Login", JOptionPane.OK_CANCEL_OPTION);

  if (x == JOptionPane.OK_OPTION) {
    ok = true;
    username = juf.getText();
    pass = jpf.getPassword();
  }
}
 
Example 12
Source File: ProgramPanel.java    From mpcmaid with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void assignSounds(Pad pad, List files) {
	if (files.size() < 2) {
		doAssignSamples(pad, files, false);
		return;
	}

	final String[] choices = ASSIGN_CHOICES2;
	int response = JOptionPane.showOptionDialog(this,
			"Each dropped file will be assigned to a pad or sample layer. ", "Assign samples to locations",
			JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, choices, "Pad");
	switch (response) {
	case 0: {
		return;
	}
	case 1: {
		doAssignSamples(pad, files, false);
		break;
	}
	case 2: {
		doAssignSamples(pad, files, true);
		break;
	}
	case 3: {
		if (!samples.isEmpty()) {
			int confirm = JOptionPane.showConfirmDialog(this,
					"This will overwrite existing samples, are you sure?", "Confirm overwrite",
					JOptionPane.OK_CANCEL_OPTION);
			if (confirm != JOptionPane.OK_OPTION) {
				return;
			}
		}
		doMultisample(files);
		break;
	}
	}
}
 
Example 13
Source File: L10nEditor.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void editHTMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editHTMLActionPerformed
    int row = bundleTable.getSelectedRow();
    int column = bundleTable.getSelectedColumn();
    HTMLEditor h = new HTMLEditor(res, (String)bundleTable.getValueAt(row, column));
    h.setPreferredSize(new Dimension(600, 400));
    int r = JOptionPane.showConfirmDialog(this, h, "Edit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if(r == JOptionPane.OK_OPTION) {
        bundleTable.setValueAt(h.getResult(), row, column);
    }

}
 
Example 14
Source File: ProcessorsMessageLocationDialog.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public boolean showRemoveDialogue(PayloadProcessorTableEntry processorTableEntry) {
    JCheckBox removeWithoutConfirmationCheckBox =
            new JCheckBox(REMOVE_DIALOG_CHECKBOX_LABEL);
    Object[] messages = {REMOVE_DIALOG_TEXT, " ", removeWithoutConfirmationCheckBox};
    int option =
            JOptionPane.showOptionDialog(
                    ProcessorsMessageLocationDialog.this,
                    messages,
                    REMOVE_DIALOG_TITLE,
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    new String[] {
                        REMOVE_DIALOG_CONFIRM_BUTTON_LABEL,
                        REMOVE_DIALOG_CANCEL_BUTTON_LABEL
                    },
                    null);

    if (option == JOptionPane.OK_OPTION) {
        getRemoveWithoutConfirmationCheckBox()
                .setSelected(removeWithoutConfirmationCheckBox.isSelected());
        return true;
    }

    return false;
}
 
Example 15
Source File: NewAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private Item promptForEngine(Item[] items) {
    final JList<Item> list = new JList<>(items);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);

    final JButton infoButton = new JButton();
    infoButton.setToolTipText("Show script engine details");
    infoButton.setIcon(TangoIcons.apps_help_browser(TangoIcons.Res.R16));
    infoButton.addActionListener(e -> {
        final Item item = list.getSelectedValue();
        showEngineDetails(list, item.scriptEngineFactory);
    });
    final JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.add(infoButton);

    JPanel titlePanel = new JPanel(new BorderLayout(16, 0));
    titlePanel.add(new JLabel("Language:"), BorderLayout.WEST);
    titlePanel.add(toolBar, BorderLayout.EAST);

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(titlePanel, BorderLayout.NORTH);
    contentPanel.add(new JScrollPane(list), BorderLayout.CENTER);

    final int i = JOptionPane.showOptionDialog(getScriptConsoleTopComponent(),
                                               contentPanel,
                                               "Select Scripting Language",
                                               JOptionPane.OK_CANCEL_OPTION,
                                               JOptionPane.PLAIN_MESSAGE,
                                               null, null, null);
    if (i == JOptionPane.OK_OPTION) {
        return list.getSelectedValue();
    }
    return null;
}
 
Example 16
Source File: SamplesRunner.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stopProcess(Process p, String name) {
    int res = JOptionPane.showConfirmDialog(view, "Stop process "+name+"?");
    if (res == JOptionPane.OK_OPTION) {
        try {
            p.destroy();
            JOptionPane.showMessageDialog(view, "Process has been stopped");
            view.removeProcess(p);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 17
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 18
Source File: DatabaseInit.java    From development with Apache License 2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {

        String dbFileName = DATABASE_INIT_XML;
        if (DatabaseInit.class.getResource(".") != null) {
            dbFileName = DatabaseInit.class.getResource(".").getFile()
                    + ROOT_PATH + DATABASE_INIT_XML;
        }

        String dbDriver = null;
        String dbURL = null;
        String dbUser = null;
        String dbPwd = null;

        boolean silent = false;
        for (int i = 0; i < args.length; i++) {
            if ("-s".equals(args[i])) {
                silent = true;
            }
            if ("-f".equals(args[i])) {
                dbFileName = args[i + 1];
            }
            if ("-dbDriver".equals(args[i])) {
                dbDriver = args[i + 1];
            }
            if ("-dbURL".equals(args[i])) {
                dbURL = args[i + 1];
            }
            if ("-dbUser".equals(args[i])) {
                dbUser = args[i + 1];
            }
            if ("-dbPwd".equals(args[i])) {
                dbPwd = args[i + 1];
            }
        }

        if (dbDriver == null) {
            System.out.println("Missing setting 'dbDriver'");
        }
        if (dbURL == null) {
            System.out.println("Missing setting 'dbURL'");
        }
        if (dbUser == null) {
            System.out.println("Missing setting 'dbUser'");
        }
        if (dbPwd == null) {
            System.out.println("Missing setting 'dbPwd'");
        }

        if (silent
                || JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null,
                        "Do you really want to initialize the database:\n"
                                + dbURL + "\nAll existing data will be LOST!",
                        "Confirmation", JOptionPane.OK_CANCEL_OPTION)) {

            DatabaseTaskHandler.init(dbDriver, dbURL, dbUser, dbPwd);

            // load
            DatabaseTaskHandler.insertData(dbFileName);

            System.out.println("File " + dbFileName
                    + " inserted into Database '" + dbURL + "'.");
        }
    }
 
Example 19
Source File: GuiUtils.java    From IrScrutinizer with GNU General Public License v3.0 4 votes vote down vote up
private static boolean confirm(Window frame, String message, int optionType) {
    return JOptionPane.showConfirmDialog(frame, message, "Confirmation requested", optionType) == JOptionPane.OK_OPTION;
}
 
Example 20
Source File: MainFrame.java    From zxpoly with GNU General Public License v3.0 4 votes vote down vote up
private void menuEditCopyBaseToPlansActionPerformed(java.awt.event.ActionEvent evt) {
  if (showConfirmDialog(this, "Do you really want to copy base data to all ZX-Poly planes?",
      "Confirmation", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
    this.mainEditor.copyPlansFromBase();
  }
}