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:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
@SuppressWarnings("unchecked") @Override//from www . ja v a 2 s .com protected void createGeneralMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv) { JMenuItem mi; // creating a node mi = new JMenuItem("Create node"); final int layer = vv.getLayer().getLayer(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // adding an resource/demand boolean addConstraint = true; V node = vertexFactory.create(); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point); node.setCoordinateX(p2.getX()); node.setCoordinateY(p2.getY()); while (addConstraint) { new AddConstraintDialog(node, layer, GUI.getInstance(), new Dimension(300, 150)); // if a resource/demand has been added if (node.get().size() > 0) { addConstraint = false; @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).addVertex((SubstrateNode) node)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).addVertex((VirtualNode) node))) { vv.updateUI(); } else { throw new AssertionError("Adding Node failed."); } } else { String cons = (layer == 0 ? "Resource" : "Demand"); int option = JOptionPane.showConfirmDialog(GUI.getInstance(), "A " + cons + " must be added for the node to be created!", "Create Node", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { addConstraint = false; } } } } }); popup.add(mi); popup.addSeparator(); @SuppressWarnings("rawtypes") final MyGraphPanel pnl = GUI.getInstance().getGraphPanel(); if (pnl.getMaximized() == null) { mi = new JMenuItem("Maximize"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(vv); } }); } else { mi = new JMenuItem("Restore"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(null); } }); } popup.add(mi); if (pnl.getMaximized() != null) { mi = new JMenuItem("Hide"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { vv.getParent().setVisible(false); } }); popup.add(mi); } popup.addSeparator(); // Copied from MuLaNEO mi = new JMenuItem("Export layer to SVG"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int layer = vv.getLayer().getLayer(); MyFileChooser fc = new MyFileChooser("Export layer " + layer + " to SVG", MyFileChooserType.MISC, false); fc.addChoosableFileFilter(FileFilters.svgFilter); fc.setSelectedFile(new File("export-layer-" + layer + ".svg")); if (fc.showSaveDialog(GUI.getInstance()) == JFileChooser.APPROVE_OPTION) new SVGExporter().export(vv, fc.getSelectedFile()); } }); popup.add(mi); }
From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
@Override protected void createVertexMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv, final List<V> nodes) { JMenuItem mi;//from w w w . ja v a2 s .co m final int layer = vv.getLayer().getLayer(); if (nodes.size() == 1) { final V node = nodes.get(0); // create the add/edit/remove resource/demand menu items createAddConstraintMenuItem(node, layer); createEditConstraintMenuItem(node, layer); createRemoveConstraintMenuItem(node, layer); popup.addSeparator(); // delete the selected node mi = new JMenuItem("Delete node"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(GUI.getInstance(), "Delete node \"" + node.toString() + "\"?", "Delete node", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).removeVertex((SubstrateNode) node)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).removeVertex((VirtualNode) node))) { vv.updateUI(); } else { throw new AssertionError("Deleting node failed."); } } } }); popup.add(mi); } else if (nodes.size() == 2) { // add a link from v1 to v2 or v2 to v1 if two nodes are selected final V v1 = nodes.get(0); final V v2 = nodes.get(1); // v1 to v2 mi = new JMenuItem("Add link " + v1.toString() + " -> " + v2.toString()); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addLink(layer, v1, v2); } }); popup.add(mi); // v2 to v1 mi = new JMenuItem("Add link " + v2.toString() + " > " + v1.toString()); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addLink(layer, v2, v1); } }); popup.add(mi); } }
From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
private void addLink(int layer, V src, V dest) { boolean addConstraint = true; E edge = edgeFactory.create();//from w w w . j av a 2 s . com while (addConstraint) { new AddConstraintDialog(edge, layer, GUI.getInstance(), new Dimension(300, 150)); // if a resource/demand has been added if (edge.get().size() > 0) { addConstraint = false; @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).addEdge((SubstrateLink) edge, (SubstrateNode) src, (SubstrateNode) dest)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).addEdge((VirtualLink) edge, (VirtualNode) src, (VirtualNode) dest))) { vv.updateUI(); } else { throw new AssertionError("Adding link failed."); } } else { int option = JOptionPane.showConfirmDialog(GUI.getInstance(), "A " + (layer == 0 ? "Resource" : "Demand") + " must be added for the link to be created!", "Create Node", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { addConstraint = false; } } } }
From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java
/** * The DefaultUpload accepts all file types: we just return an instance of * FileData, without any test.//w ww . ja v a 2 s .co m * * @exception JUploadExceptionStopAddingFiles * If the users choosed to stop adding. This occurs when the * {@link #fileFilterAccept(File)} method returns false, and * the user then choose to stop adding files. * @see UploadPolicy#createFileData(File, File) */ public FileData createFileData(File file, File root) throws JUploadExceptionStopAddingFiles { if (!fileFilterAccept(file)) { String msg = file.getName() + " : " + getLocalizedString("errForbiddenExtension"); displayWarn(msg); if (confirmDialogStr(msg, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { // The user want to stop to add files to the list. For instance, // when he/she added a whole directory, and it contains a lot of // files that don't match the allowed file extension. throw new JUploadExceptionStopAddingFiles("Stopped by the user"); } return null; } else if (!file.canRead()) { displayInfo("Can't read file " + file.getName() + ". No DefaultFileData creation."); return null; } else { return new DefaultFileData(file, root, this); } }
From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java
/** * If debug is off, the log window may not be visible. We switch the debug * to on, to be sure that some information will be displayed to the user. <BR> * If debug is -1, the log window remains hidden. * /*from w w w.ja v a2 s . c om*/ * @see wjhk.jupload2.policies.UploadPolicy#displayErr(java.lang.String, * java.lang.Exception, int) */ public int displayErr(String errorText, Exception exception, int optionTypes) { // Then, we display it to the user. String alertMsg = errorText; // Then, the message body can be completed by the exception message. if (exception != null && (errorText == null || errorText.equals(""))) { // Ok, we have an exception. if (exception.getCause() != null) { alertMsg = exception.getCause().getMessage(); } else { alertMsg = exception.getMessage(); } } // The message displayed depend on the debug level: if (getDebugLevel() >= 30 && exception != null) { alertMsg = exception.getClass().getName() + ": " + alertMsg; } // Display the message to the user. The kind of alert box depends on the // given options: int buttonClicked = 0; switch (optionTypes) { case -1: // Standard message box. alertStr(alertMsg); buttonClicked = JOptionPane.OK_OPTION; break; case JOptionPane.OK_CANCEL_OPTION: case JOptionPane.YES_NO_CANCEL_OPTION: case JOptionPane.YES_NO_OPTION: buttonClicked = confirmDialogStr(alertMsg, optionTypes); break; default: // This is a problem. Let's display it to the user as a standard // alert box. alertStr(alertMsg); buttonClicked = JOptionPane.OK_OPTION; // Then, we log this new problem. String msg = "Unknown optionType in displayErr(String, Exception, int)"; alertStr(msg); logErr(msg, null); } // First, we log the error. logErr(errorText, exception); return buttonClicked; }
From source file:xtrememp.update.SoftwareUpdate.java
public static void checkForUpdates(final boolean showDialogs) { checkForUpdatesWorker = new SwingWorker<Version, Void>() { @Override// www .j a va 2 s .c o m protected Version doInBackground() throws Exception { logger.debug("checkForUpdates: started..."); long startTime = System.currentTimeMillis(); Version version = getLastVersion(new URL(updatesURL)); if (showDialogs) { // Simulate (if needed) a delay of 2 sec max to let the user cancel the task. long delayTime = System.currentTimeMillis() - startTime - 2000; if (delayTime > 0) { Thread.sleep(delayTime); } } return version; } @Override protected void done() { logger.debug("checkForUpdates: done"); if (checkForUpdatesDialog != null && checkForUpdatesDialog.isVisible()) { checkForUpdatesDialog.dispose(); } if (!isCancelled()) { try { newerVersion = get(); if (newerVersion != null && newerVersion.compareTo(currentVersion) == 1) { logger.debug("checkForUpdates: currentVersion = {}", currentVersion); logger.debug("checkForUpdates: newerVersion = {}", newerVersion); logger.debug("SoftwareUpdate::checkForUpdates: updates found"); Object[] options = { tr("Button.Cancel") }; Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { options = new Object[] { tr("Button.Download"), tr("Button.Cancel") }; } } JPanel panel = new JPanel(new BorderLayout(0, 10)); panel.add(new JLabel("<html>" + tr("Dialog.SoftwareUpdate.UpdatesFound") + " (" + newerVersion + ")</html>"), BorderLayout.CENTER); JCheckBox hideCheckBox = null; if (Settings.isAutomaticUpdatesEnabled()) { hideCheckBox = new JCheckBox( tr("Dialog.SoftwareUpdate.DisableAutomaticCheckForUpdates")); panel.add(hideCheckBox, BorderLayout.SOUTH); } int option = JOptionPane.showOptionDialog(XtremeMP.getInstance().getMainFrame(), panel, tr("Dialog.SoftwareUpdate"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (hideCheckBox != null) { Settings.setAutomaticUpdatesEnabled(!hideCheckBox.isSelected()); } if ((options.length == 2) && (option == JOptionPane.OK_OPTION)) { try { URL url = new URL(newerVersion.getDownloadURL()); desktop.browse(url.toURI()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } } else { logger.debug("checkForUpdates: no updates found"); if (showDialogs) { JOptionPane.showMessageDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate.NoUpdatesFound"), tr("Dialog.SoftwareUpdate"), JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { logger.error(ex.getMessage(), ex); if (showDialogs) { JOptionPane.showMessageDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate.ConnectionFailure"), tr("Dialog.SoftwareUpdate"), JOptionPane.INFORMATION_MESSAGE); } } } } }; checkForUpdatesWorker.execute(); }
From source file:xtrememp.XtremeMP.java
@Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == openMenuItem) { playlistManager.addFilesDialog(true); } else if (source == openURLMenuItem) { String url = JOptionPane.showInputDialog(mainFrame, tr("Dialog.OpenURL.Message"), tr("Dialog.OpenURL"), JOptionPane.INFORMATION_MESSAGE); if (url != null && Utilities.startWithProtocol(url)) { boolean isPlaylistFile = false; for (String ext : PlaylistFileFilter.PlaylistFileExt) { if (url.endsWith(ext)) { isPlaylistFile = true; }/*w w w . ja va 2 s . c o m*/ } if (isPlaylistFile) { playlistManager.clearPlaylist(); playlistManager.loadPlaylist(url); playlist.begin(); } else { PlaylistItem newPli = new PlaylistItem(url, url, -1, false); playlistManager.add(newPli); playlist.setCursor(newPli); } acOpenAndPlay(); } } else if (source == openPlaylistMenuItem) { playlistManager.openPlaylistDialog(); } else if (source == savePlaylistMenuItem) { playlistManager.savePlaylistDialog(); } else if (source == preferencesMenuItem) { PreferencesDialog preferencesDialog = new PreferencesDialog(audioPlayer, this); preferencesDialog.setVisible(true); } else if (source == exitMenuItem) { exit(); } else if (source == playPauseMenuItem || source == playPauseButton) { acPlayPause(); } else if (source == previousMenuItem || source == previousButton) { acPrevious(); } else if (source == nextMenuItem || source == nextButton) { acNext(); } else if (source == randomizePlaylistMenuItem) { playlistManager.randomizePlaylist(); } else if (source == stopMenuItem || source == stopButton) { acStop(); } else if (source == playlistManagerMenuItem) { if (visualizationManager.isVisible()) { visualizationManager.setDssEnabled(false); CardLayout cardLayout = (CardLayout) (mainPanel.getLayout()); cardLayout.show(mainPanel, Utilities.PLAYLIST_MANAGER); playlistManagerMenuItem.setSelected(true); Settings.setLastView(Utilities.PLAYLIST_MANAGER); } } else if (source == visualizationMenuItem) { if (playlistManager.isVisible()) { visualizationManager.setDssEnabled(true); CardLayout cardLayout = (CardLayout) (mainPanel.getLayout()); cardLayout.show(mainPanel, Utilities.VISUALIZATION_PANEL); visualizationMenuItem.setSelected(true); Settings.setLastView(Utilities.VISUALIZATION_PANEL); } } else if (source == updateMenuItem) { SoftwareUpdate.checkForUpdates(true); SoftwareUpdate.showCheckForUpdatesDialog(); } else if (source == aboutMenuItem) { Object[] options = { tr("Button.Close") }; Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { options = new Object[] { tr("Button.Close"), tr("Button.Website") }; } } StringBuffer message = new StringBuffer(); message.append("<html><b><font color='red' size='5'>").append(tr("Application.title")); message.append("</font></b><br>").append(tr("Application.description")); message.append("<br>Copyright 2005-2014 The Xtreme Media Player Project"); message.append("<br><br><b>").append(tr("Dialog.About.Authors")).append(": </b>") .append(tr("Application.authors")); message.append("<br><b>").append(tr("Dialog.About.Version")).append(": </b>").append(currentVersion); message.append("<br><b>").append(tr("Dialog.About.Codename")).append(": </b>") .append(currentVersion.getCodename()); message.append("<br><b>").append(tr("Dialog.About.ReleaseDate")).append(": </b>") .append(currentVersion.getReleaseDate()); message.append("<br><b>").append(tr("Dialog.About.Homepage")).append(": </b>") .append(tr("Application.homepage")); message.append("<br><br><b>").append(tr("Dialog.About.JavaVersion")).append(": </b>") .append(System.getProperty("java.version")); message.append("<br><b>").append(tr("Dialog.About.JavaVendor")).append(": </b>") .append(System.getProperty("java.vendor")); message.append("<br><b>").append(tr("Dialog.About.JavaHome")).append(": </b>") .append(System.getProperty("java.home")); message.append("<br><b>").append(tr("Dialog.About.OSName")).append(": </b>") .append(System.getProperty("os.name")); message.append("<br><b>").append(tr("Dialog.About.OSArch")).append(": </b>") .append(System.getProperty("os.arch")); message.append("<br><b>").append(tr("Dialog.About.UserName")).append(": </b>") .append(System.getProperty("user.name")); message.append("<br><b>").append(tr("Dialog.About.UserHome")).append(": </b>") .append(System.getProperty("user.home")); message.append("<br><b>").append(tr("Dialog.About.UserDir")).append(": </b>") .append(System.getProperty("user.dir")); message.append("</html>"); int n = JOptionPane.showOptionDialog(mainFrame, message, tr("Dialog.About"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, Utilities.APP_256_ICON, options, options[0]); if (n == 1 && desktop != null) { try { URL url = new URL(tr("Application.homepage")); desktop.browse(url.toURI()); } catch (IOException | URISyntaxException ex) { logger.error(ex.getMessage(), ex); } } } else if (source.equals(playModeRepeatNoneMenuItem)) { playlist.setPlayMode(Playlist.PlayMode.REPEAT_NONE); } else if (source.equals(playModeRepeatOneMenuItem)) { playlist.setPlayMode(Playlist.PlayMode.REPEAT_ONE); } else if (source.equals(playModeRepeatAllMenuItem)) { playlist.setPlayMode(Playlist.PlayMode.REPEAT_ALL); } else if (source.equals(playModeShuffleMenuItem)) { playlist.setPlayMode(Playlist.PlayMode.SHUFFLE); } }