List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION
int OK_CANCEL_OPTION
To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:se.trixon.jota.client.ui.MainFrame.java
void showEditor(long jobId, boolean openJob) { EditorPanel editorPanel = new EditorPanel(jobId, openJob); SwingHelper.makeWindowResizable(editorPanel); int retval = JOptionPane.showOptionDialog(this, editorPanel, mBundle.getString("jobEditor"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { editorPanel.save();/*w w w .ja va 2 s . c om*/ try { mManager.getServerCommander().saveJota(); } catch (RemoteException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void showOptions() { OptionsPanel optionsPanel = new OptionsPanel(); SwingHelper.makeWindowResizable(optionsPanel); int retval = JOptionPane.showOptionDialog(this, optionsPanel, Dict.OPTIONS.toString(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { optionsPanel.save();/*from w w w . j a v a 2 s .co m*/ } }
From source file:se.trixon.mapollage.ui.MainFrame.java
private void profileRemove() { if (!mProfiles.isEmpty()) { String message = String.format(Dict.Dialog.MESSAGE_PROFILE_REMOVE.toString(), getSelectedProfile().getName()); int retval = JOptionPane.showConfirmDialog(this, message, Dict.Dialog.TITLE_PROFILE_REMOVE.toString(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (retval == JOptionPane.OK_OPTION) { mProfiles.remove(getSelectedProfile()); populateProfiles(null, 0);/*from ww w . j av a2 s . c o m*/ } } }
From source file:se.trixon.mapollage.ui.MainFrame.java
private void profileRemoveAll() { if (!mProfiles.isEmpty()) { String message = String.format(Dict.Dialog.MESSAGE_PROFILE_REMOVE_ALL.toString(), getSelectedProfile().getName()); int retval = JOptionPane.showConfirmDialog(this, message, Dict.Dialog.TITLE_PROFILE_REMOVE_ALL.toString(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (retval == JOptionPane.OK_OPTION) { mProfiles.clear();/* www . j a v a 2 s . c o m*/ populateProfiles(null, 0); } } }
From source file:se.trixon.pacoma.ui.MainFrame.java
private void editCollage(Collage collage) { String title = Dict.Dialog.TITLE_EDIT_PROPERTIES.toString(); boolean existing = true; if (collage == null) { collage = new Collage(); collage.addPropertyChangeListener(mCollagePropertyChangeListener); title = mBundleUI.getString("create_new_collage"); existing = false;/*from w ww.jav a 2s .c o m*/ } PropertiesPanel propertiesPanel = new PropertiesPanel(collage); SwingHelper.makeWindowResizable(propertiesPanel); int result = JOptionPane.showOptionDialog(this, propertiesPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (result == JOptionPane.YES_OPTION) { propertiesPanel.store(); mCollage = collage; if (!existing) { mActionManager.setEnabledDocumentActions(true); mCollage.setName(String.format("%s %d", Dict.UNTITLED.toString(), ++sDocumentCounter)); } } }
From source file:ua.utility.fkindexgenerator.UIUtils.java
/** * * @param c/*from www . ja va2s . co m*/ * @param title * @param prompt * @return */ public static boolean promptForCancel(Component c, String title, String prompt) { return (JOptionPane.showConfirmDialog(c, prompt, title, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION); }
From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudLoginDialog.java
public PasswordAuthentication getPasswordAuthentication(final String prompt) { // Set the default background colour to white UIManager UI = new UIManager(); UI.put("OptionPane.background", Color.white); UI.put("Panel.background", Color.white); String defaultUserName = ""; if (giftCloudProperties.getLastUserName().isPresent()) { defaultUserName = giftCloudProperties.getLastUserName().get(); }//from w w w . j ava 2 s. c om // Create a panel for entering username and password final JPanel usernamePasswordPanel = new JPanel(new GridBagLayout()); final JLabel promptField = new JLabel(prompt, SwingConstants.CENTER); final JTextField usernameField = new JTextField(defaultUserName, 16); final JPasswordField passwordField = new JPasswordField(16); // Add a special listener to get the focus onto the username field when the component is created, or password if the username has already been populated from the default value if (StringUtils.isBlank(defaultUserName)) { usernameField.addAncestorListener(new RequestFocusListener()); } else { passwordField.addAncestorListener(new RequestFocusListener()); } usernamePasswordPanel.add(promptField, promptConstraint); usernamePasswordPanel.add(new JLabel("Username:"), labelConstraint); usernamePasswordPanel.add(usernameField, fieldConstraint); usernamePasswordPanel.add(new JLabel("Password:"), labelConstraint); usernamePasswordPanel.add(passwordField, fieldConstraint); // Show the login dialog final int returnValue = JOptionPane.showConfirmDialog(new JDialog(getFrame(parent)), usernamePasswordPanel, LOGIN_DIALOG_TITLE, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon); if (JOptionPane.OK_OPTION == returnValue) { giftCloudProperties.setLastUserName(usernameField.getText()); giftCloudProperties.setLastPassword(passwordField.getPassword()); giftCloudProperties.save(); return new PasswordAuthentication(usernameField.getText(), passwordField.getPassword()); } else { return null; } }
From source file:utils.ZTransform.java
@Override public void actionPerformed(ActionEvent e) { List<CMatrix> loadedCMatrices = CoolMapMaster.getLoadedCMatrices(); if (loadedCMatrices == null || loadedCMatrices.isEmpty()) { Messenger.showWarningMessage("No datasets were imported.", "No data"); return;//from w w w. j ava 2 s . c om } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTable table = new JTable(); DefaultTableModel defaultTableModel = Utils.getDefaultTableModel(); table.setModel(defaultTableModel); table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0)); table.getTableHeader().setReorderingAllowed(false); int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), new JScrollPane(table), "Select data", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { int[] selectedRows = table.getSelectedRows(); ArrayList<CMatrix> selectedMatrices = new ArrayList<CMatrix>(); for (int row : selectedRows) { int index = table.convertRowIndexToModel(row); try { String ID = table.getModel().getValueAt(index, 0).toString(); CMatrix mx = CoolMapMaster.getCMatrixByID(ID); if (mx != null) { selectedMatrices.add(mx); } } catch (Exception e) { } } //do createZTransform(selectedMatrices); } } }); }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
private JMenu createShortMenu() { JMenu shortMenu = new JMenu(); addDarkModeCallback(b -> {//from w w w. ja v a 2 s.co m shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter()); shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE); }); shortMenu.setBackground(OPENBST_BLUE.brighter()); shortMenu.setForeground(OPENBST_BLUE); shortMenu.setText(Lang.get("banner.title")); shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16))); JMenuItem label = new JMenuItem(Lang.get("menu.title")); label.setEnabled(false); shortMenu.add(label); shortMenu.addSeparator(); shortMenu.add( new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title"))); } })); shortMenu.addSeparator(); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { doNewEditor(); } })); JMenu additionalMenu = new JMenu(Lang.get("menu.advanced")); shortMenu.add(additionalMenu); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new PackageDialog(instance).setVisible(true); } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { final Map<String, String> languages = new Gson() .fromJson(new InputStreamReader( OpenBST.class.getResourceAsStream( "/utybo/branchingstorytree/swing/lang/langs.json"), StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() { }.getType()); languages.remove("en"); languages.remove("default"); JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet())); JPanel panel = new JPanel(); panel.add(new JLabel(Lang.get("langcheck.choose"))); panel.add(jcb); int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { Locale selected = new Locale((String) jcb.getSelectedItem()); if (!Lang.getMap().keySet().contains(selected)) { try { Lang.loadTranslationsFromFile(selected, OpenBST.class .getResourceAsStream("/utybo/branchingstorytree/swing/lang/" + languages.get(jcb.getSelectedItem().toString()))); } catch (UnrespectedModelException | IOException e1) { LOG.warn("Failed to load translation file", e1); } } ArrayList<String> list = new ArrayList<>(); Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> { if (!Lang.getLocaleMap(selected).containsKey(k)) { list.add(k + "\n"); } }); StringBuilder sb = new StringBuilder(); Collections.sort(list); list.forEach(s -> sb.append(s)); JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck")); dialog.getContentPane().setLayout(new MigLayout()); dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")), "pushx, growx, wrap"); JTextArea area = new JTextArea(); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText(sb.toString()); area.setEditable(false); area.setBorder(BorderFactory.createLoweredBevelBorder()); JScrollPane jsp = new JScrollPane(area); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy"); dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.this); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setVisible(true); } } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { DebugInfo.launch(OpenBSTGUI.this); } })); JMenu includedFiles = new JMenu("Included BST files"); for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) { JMenuItem jmi = new JMenuItem(entry.getKey()); jmi.addActionListener(ev -> { String path = "/bst/" + entry.getValue(); InputStream is = OpenBSTGUI.class.getResourceAsStream(path); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...", is); new Thread(() -> { try { File f = File.createTempFile("openbstinternal", ".bsp"); FileOutputStream fos = new FileOutputStream(f); IOUtils.copy(pmis, fos); openStory(f); } catch (final IOException e) { LOG.error("IOException caught", e); showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName()) .replace("$m", e.getMessage()), e); } }).start(); }); includedFiles.add(jmi); } additionalMenu.add(includedFiles); shortMenu.addSeparator(); JMenu themesMenu = new JMenu(Lang.get("menu.themes")); shortMenu.add(themesMenu); themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16))); ButtonGroup themesGroup = new ButtonGroup(); JRadioButtonMenuItem jrbmi; jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark")); if (0 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light")); if (1 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug")); if (2 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight")); int j = 3; for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalLightThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalLightThemesMenu); JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark")); for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalDarkThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalDarkThemesMenu); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) { /** * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new AboutDialog(instance).setVisible(true); } })); return shortMenu; }
From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
@Override protected void createEdgeMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv, List<E> links) {// w w w . ja va 2 s . c o m JMenuItem mi; if (links.size() == 1) { final E link = links.get(0); final int layer = vv.getLayer().getLayer(); // create the add/edit/remove resource/demand menu items createAddConstraintMenuItem(link, layer); createEditConstraintMenuItem(link, layer); createRemoveConstraintMenuItem(link, layer); popup.addSeparator(); // deleting the selected link mi = new JMenuItem("Delete link"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(GUI.getInstance(), "Delete link \"" + link.toString() + "\"?", "Delete link", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).removeEdge((SubstrateLink) link)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).removeEdge((VirtualLink) link))) { vv.updateUI(); } else { throw new AssertionError("Deleting link failed!"); } } } }); popup.add(mi); } }