List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException
optionType
parameter, where the messageType
parameter determines the icon to display. From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void reinitializeGroovyClipboardFormatters() { String dialogTitle = "Reinitialize example groovy clipboard formatters?"; String message = "This overwrites all example groovy clipboard formatters. Other clipboard formatters are not changed!\nReinitialize example groovy clipboard formatters right now?"; int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows if (JOptionPane.OK_OPTION != result) { return;/*from w w w .jav a2s .c om*/ } applicationPreferences.installExampleClipboardFormatters(); }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
public void disposeWithSavePrompt() { String currentXML = getXML(); if (currentXML.equals(lastOutputXML) == false) { if (JOptionPane.showConfirmDialog(ScriptEditor.this, "Script has been modified but not saved, changes will be lost. Really close?", "Really Closing?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { ScriptEditor.this.dispose(); }/* w w w. j ava 2s. com*/ } else { ScriptEditor.this.dispose(); } }
From source file:gdt.jgui.entity.edge.JBondsPanel.java
/** * Get the context menu.//from w ww. j av a2s . c o m * @return the context menu. */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); int cnt = menu.getItemCount(); mia = new JMenuItem[cnt]; for (int i = 0; i < cnt; i++) mia[i] = menu.getItem(i); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { //System.out.println("WeblinkPanel:getConextMenu:menu selected"); menu.removeAll(); if (mia != null) { for (JMenuItem mi : mia) menu.add(mi); menu.addSeparator(); } if (hasSelectedItems()) { JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { String[] sa = JBondsPanel.this.listSelectedItems(); if (sa == null) return; for (String s : sa) { // System.out.println("JBondsPanel:delete:s="+s); if (isGraphEntity()) removeBondEntry(s); else if (isEdgeEntity()) removeBond(console, s); else if (isDetailEntity()) { System.out.println("JBondsPanel:delete detail:"); Entigrator entigrator = console.getEntigrator(entihome$); BondDetailHandler.deleteDetail(entigrator, s); } } close(); JBondsPanel bp = new JBondsPanel(); String bpLocator$ = bp.getLocator(); bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$); bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, bpLocator$); } } }); menu.add(deleteItem); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String[] sa = JBondsPanel.this.listSelectedItems(); if (sa == null) return; for (String s : sa) { console.clipboard.putString(s); } } }); menu.add(copyItem); menu.addSeparator(); } if (isEdgeEntity()) { JMenuItem newItem = new JMenuItem("New"); newItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //System.out.println("JBondsPanel:new:"+locator$); Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); if (!entity.existsElement("bond")) entity.createElement("bond"); String bondKey$ = Identity.key(); entity.putElementItem("bond", new Core(null, bondKey$, null)); // String icon$=Support.readHandlerIcon(JEntitiesPanel.class, "globe.png"); entigrator.save(entity); // JBondsPanel.this.getPanel().removeAll(); close(); JBondsPanel bp = new JBondsPanel(); String bpLocator$ = bp.getLocator(); bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$); bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$); //bpLocator$=Locator.append(bpLocator$, BaseHandler.HANDLER_METHOD,"instantiate"); JConsoleHandler.execute(console, bpLocator$); } }); menu.add(newItem); } if (isGraphEntity()) { JMenuItem showItem = new JMenuItem("Show"); showItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { JGraphRenderer gr = new JGraphRenderer(); String grLocator$ = gr.getLocator(); grLocator$ = Locator.append(grLocator$, Entigrator.ENTIHOME, entihome$); grLocator$ = Locator.append(grLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, grLocator$); } catch (Exception ee) { Logger.getLogger(JGraphRenderer.class.getName()).info(ee.toString()); } } }); menu.add(showItem); if (hasBondsToPaste()) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pasteBonds(); JBondsPanel bp = new JBondsPanel(); String bpLocator$ = bp.getLocator(); bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$); bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, bpLocator$); } }); menu.add(pasteItem); } } JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { Logger.getLogger(JBondsPanel.class.getName()).severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); menu.addSeparator(); JMenuItem sortInNode = new JMenuItem("Sort in node"); sortInNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { selectMode$ = SELECT_MODE_IN; JItemPanel[] ipa = getItems(); Entigrator entigrator = console.getEntigrator(entihome$); InNodeComparator inc = new InNodeComparator(); inc.entigrator = entigrator; ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa)); Collections.sort(ipl, inc); panel.removeAll(); // System.out.println("JBondsPanel:sort in node:ipl="+ipl.size()); if (ipa != null) for (JItemPanel ip : ipl) { panel.add(ip); } revalidate(); repaint(); Sack entity = entigrator.getEntityAtKey(entityKey$); if (!entity.existsElement("parameter")) entity.createElement("parameter"); entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$)); entigrator.save(entity); } catch (Exception ee) { } } }); menu.add(sortInNode); JMenuItem sortOutNode = new JMenuItem("Sort out node"); sortOutNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { selectMode$ = SELECT_MODE_OUT; JItemPanel[] ipa = getItems(); ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa)); Collections.sort(ipl, new ItemPanelComparator()); panel.removeAll(); System.out.println("JBondsPanel:sort out node:ipl=" + ipl.size()); if (ipa != null) for (JItemPanel ip : ipl) { panel.add(ip); } revalidate(); repaint(); Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); if (!entity.existsElement("parameter")) entity.createElement("parameter"); entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$)); entigrator.save(entity); } catch (Exception ee) { } } }); menu.add(sortOutNode); } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:net.sf.jabref.gui.fieldeditors.FileListEditor.java
/** * Run a file download operation.//from w w w .j a va 2 s . c o m */ private void downloadFile() { String bibtexKey = entryEditor.getEntry().getCiteKey(); if (bibtexKey == null) { int answer = JOptionPane.showConfirmDialog(frame, Localization.lang("This entry has no BibTeX key. Generate key now?"), Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.OK_OPTION) { ActionListener l = entryEditor.getGenerateKeyAction(); l.actionPerformed(null); bibtexKey = entryEditor.getEntry().getCiteKey(); } } DownloadExternalFile def = new DownloadExternalFile(frame, frame.getCurrentBasePanel().getBibDatabaseContext(), bibtexKey); try { def.download(this); } catch (IOException ex) { LOGGER.warn("Cannot download.", ex); } }
From source file:de.fhg.igd.mapviewer.server.file.FileTiler.java
/** * Ask the user for an image file for that a tiled map shall be created *//*from w ww . j av a 2s .c o m*/ public void run() { JFileChooser fileChooser = new JFileChooser(); // load current dir fileChooser.setCurrentDirectory( new File(pref.get(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()))); // open int returnVal = fileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { // save current dir pref.put(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()); // get file File imageFile = fileChooser.getSelectedFile(); // get image dimension Dimension size = getSize(imageFile); log.info("Image size: " + size); // ask for min tile size int minTileSize = 0; while (minTileSize <= 0) { try { minTileSize = Integer.parseInt( JOptionPane.showInputDialog("Minimal tile size", String.valueOf(DEF_MIN_TILE_SIZE))); } catch (Exception e) { minTileSize = 0; } } // determine min map width int width = size.width; while (width / 2 > minTileSize && width % 2 == 0) { width = width / 2; } int minMapWidth = width; // min map width log.info("Minimal map width: " + minMapWidth); // determine min map height int height = size.height; while (height / 2 > minTileSize && height % 2 == 0) { height = height / 2; // min map height } int minMapHeight = height; log.info("Minimal map height: " + minMapHeight); // ask for min map size int minMapSize = 0; while (minMapSize <= 0) { try { minMapSize = Integer.parseInt( JOptionPane.showInputDialog("Minimal map size", String.valueOf(DEF_MIN_MAP_SIZE))); } catch (Exception e) { minMapSize = 0; } } // determine zoom levels int zoomLevels = 1; width = size.width; height = size.height; while (width % 2 == 0 && height % 2 == 0 && width / 2 >= Math.max(minMapWidth, minMapSize) && height / 2 >= Math.max(minMapHeight, minMapSize)) { zoomLevels++; width = width / 2; height = height / 2; } log.info("Number of zoom levels: " + zoomLevels); // determine tile width width = minMapWidth; int tileWidth = minMapWidth; for (int i = 3; i < Math.sqrt(minMapWidth) && width > minTileSize;) { tileWidth = width; if (width % i == 0) { width = width / i; } else i++; } // determine tile height height = minMapHeight; int tileHeight = minMapHeight; for (int i = 3; i < Math.sqrt(minMapHeight) && height > minTileSize;) { tileHeight = height; if (height % i == 0) { height = height / i; } else i++; } // create tiles for each zoom level if (JOptionPane.showConfirmDialog(null, "Create tiles (" + tileWidth + "x" + tileHeight + ") for " + zoomLevels + " zoom levels?", "Create tiles", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { int currentWidth = size.width; int currentHeight = size.height; File currentImage = imageFile; Properties properties = new Properties(); properties.setProperty(PROP_TILE_WIDTH, String.valueOf(tileWidth)); properties.setProperty(PROP_TILE_HEIGHT, String.valueOf(tileHeight)); properties.setProperty(PROP_ZOOM_LEVELS, String.valueOf(zoomLevels)); List<File> files = new ArrayList<File>(); for (int i = 0; i < zoomLevels; i++) { int mapWidth = currentWidth / tileWidth; int mapHeight = currentHeight / tileHeight; log.info("Creating tiles for zoom level " + i); log.info("Map width: " + currentWidth + " pixels, " + mapWidth + " tiles"); log.info("Map height: " + currentHeight + " pixels, " + mapHeight + " tiles"); // create tiles tile(currentImage, TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + "%d", TILE_FILE_EXTENSION, tileWidth, tileHeight); // add files to list for (int num = 0; num < mapWidth * mapHeight; num++) { files.add(new File(imageFile.getParentFile().getAbsolutePath() + File.separator + TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + num + TILE_FILE_EXTENSION)); } // store map width and height at current zoom properties.setProperty(PROP_MAP_WIDTH + i, String.valueOf(mapWidth)); properties.setProperty(PROP_MAP_HEIGHT + i, String.valueOf(mapHeight)); // create image for next zoom level currentWidth /= 2; currentHeight /= 2; // create temp image file name File nextImage = suffixFile(imageFile, i + 1); // resize image convert(currentImage, nextImage, currentWidth, currentHeight, 100); // delete previous temp file if (!currentImage.equals(imageFile)) { if (!currentImage.delete()) { log.warn("Error deleting " + imageFile.getAbsolutePath()); } } currentImage = nextImage; } // delete previous temp file if (!currentImage.equals(imageFile)) { if (!currentImage.delete()) { log.warn("Error deleting " + imageFile.getAbsolutePath()); } } // write properties file File propertiesFile = new File( imageFile.getParentFile().getAbsolutePath() + File.separator + MAP_PROPERTIES_FILE); try { FileWriter propertiesWriter = new FileWriter(propertiesFile); try { properties.store(propertiesWriter, "Map generated from " + imageFile.getName()); // add properties file to list files.add(propertiesFile); } finally { propertiesWriter.close(); } } catch (IOException e) { log.error("Error writing map properties file", e); } // add a converter properties file String convProperties = askForPath(fileChooser, new ExactFileFilter(CONVERTER_PROPERTIES_FILE), "Select a converter properties file"); File convFile = null; if (convProperties != null) { convFile = new File(convProperties); files.add(convFile); } // create jar file log.info("Creating jar archive..."); if (createJarArchive(replaceExtension(imageFile, MAP_ARCHIVE_EXTENSION), files)) { log.info("Archive successfully created, deleting tiles..."); // don't delete converter properties if (convFile != null) files.remove(files.size() - 1); // delete files for (File file : files) { if (!file.delete()) { log.warn("Error deleting " + file.getAbsolutePath()); } } } log.info("Fin."); } } }
From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void deleteAllLogs() { String dialogTitle = "Delete all log files?"; String message = "This deletes *all* log files, even the Lilith logs and the global logs!\nDelete all log files right now?"; int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows if (JOptionPane.OK_OPTION != result) { return;// w w w . j av a2s . c o m } mainFrame.deleteAllLogs(); }
From source file:org.datacleaner.bootstrap.Bootstrap.java
private FileObject[] downloadFiles(String[] urls, FileObject targetDirectory, String[] targetFilenames, WindowContext windowContext, MonitorHttpClient httpClient, MonitorConnection monitorConnection) { final DownloadFilesActionListener downloadAction = new DownloadFilesActionListener(urls, targetDirectory, targetFilenames, null, windowContext, httpClient); try {/* www . j a v a2 s . co m*/ downloadAction.actionPerformed(null); FileObject[] files = downloadAction.getFiles(); if (logger.isInfoEnabled()) { logger.info("Succesfully downloaded urls: {}", Arrays.toString(urls)); } return files; } catch (SSLPeerUnverifiedException e) { downloadAction.cancelDownload(true); if (monitorConnection == null || monitorConnection.isAcceptUnverifiedSslPeers()) { throw new IllegalStateException("Failed to verify SSL peer", e); } if (logger.isInfoEnabled()) { logger.info("SSL peer not verified. Asking user for confirmation to accept urls: {}", Arrays.toString(urls)); } int confirmation = JOptionPane.showConfirmDialog(null, "Unverified SSL peer.\n\n" + "The certificate presented by the server could not be verified.\n\n" + "Do you want to continue, accepting the unverified certificate?", "Unverified SSL peer", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); if (confirmation != JOptionPane.YES_OPTION) { throw new IllegalStateException(e); } monitorConnection.setAcceptUnverifiedSslPeers(true); httpClient = monitorConnection.getHttpClient(); return downloadFiles(urls, targetDirectory, targetFilenames, windowContext, httpClient, monitorConnection); } }
From source file:ffx.ui.KeywordPanel.java
/** * Give the user a File Dialog Box so they can select a key file. *///from w w w . j a v a2 s .c o m public void keyOpen() { if (fileOpen && KeywordComponent.isKeywordModified()) { int option = JOptionPane.showConfirmDialog(this, "Save Changes First", "Opening New File", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (option == JOptionPane.CANCEL_OPTION) { return; } else if (option == JOptionPane.YES_OPTION) { keySave(currentKeyFile); } keyClear(); } JFileChooser d = MainPanel.resetFileChooser(); if (currentSystem != null) { File cwd = currentSystem.getFile(); if (cwd != null && cwd.getParentFile() != null) { d.setCurrentDirectory(cwd.getParentFile()); } } d.setAcceptAllFileFilterUsed(false); d.setFileFilter(MainPanel.keyFileFilter); d.setDialogTitle("Open KEY File"); int result = d.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File newKeyFile = d.getSelectedFile(); if (newKeyFile != null && newKeyFile.exists() && newKeyFile.canRead()) { keyOpen(newKeyFile); } } }
From source file:de.juwimm.cms.gui.admin.PanUnitGroupPerUser.java
public boolean exitPerformed(ExitEvent e) { try {// ww w.ja v a 2 s . com if (unitPickData.isModified() || groupPickData.isModified()) { int i = JOptionPane.showConfirmDialog(this, rb.getString("dialog.wantToSave"), rb.getString("dialog.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (i == JOptionPane.YES_OPTION) { saveChanges(currentSelected); } else if (i == JOptionPane.CANCEL_OPTION) { return false; } } } catch (Exception ex) { } return true; }
From source file:ca.canuckcoding.wosqi.FeedViewer.java
private void install() { int tab = jTabbedPane2.getSelectedIndex(); ArrayList<PackageEntry> pkgList = getInstallList(selected[tab]); String msg = "<html><body width=\"300px\">" + MessageFormat .format(bundle.getString("DEPENDANCY_INSTALL_WARNING"), new Object[] { selected[tab].name }) + "\n"; ArrayList installList = new ArrayList(); for (int i = 0; i < pkgList.size(); i++) { PackageEntry curr = pkgList.get(i); if (!pkgMgr.isInstalled(curr)) { if (!curr.id.equals(selected[tab].id)) { msg += "\n" + curr.name; }//w w w. j a v a 2 s. c o m installList.add(curr.getDownloadUrl()); } } if (installList.size() > 1) { if (JOptionPane.showConfirmDialog(rootPane, msg, bundle.getString("WARNING"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { doInstall(tab, installList); } } else { doInstall(tab, installList); } }