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:kevin.gvmsgarch.App.java
private static boolean areYouSure(Worker.ArchiveMode mode, Worker.ListLocation location, ContactFilter filter) { String message = "Are you sure you want to " + mode.toPrettyString() + " your messages from " + location.toString() + "\nfiltered by " + filter.toString() + "?"; String warning;/*from w w w .j a v a2 s . c o m*/ if ((warning = mode.getWarning()) != null) { message += "\n\n" + warning; } return JOptionPane.showConfirmDialog(null, message, "Really really sure?", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION; }
From source file:MyFormApp.java
private void RemovebuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RemovebuttonMouseClicked // TODO add your handling code here:JDialog.setDefaultLookAndFeelDecorated(true); //?? ? ?/*from ww w. j a v a 2 s .com*/ int index = jList2.getSelectedIndex(); //?? int response = JOptionPane.showConfirmDialog(null, "Do you want to delete " + model.getElementAt(index) + " ?", "Confirm", //? JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) {//?? if (model.getSize() > 0) System.out.println(PATH + model.getElementAt(index));//? deleteDir(new File(PATH + model.getElementAt(index)));// pdf deleteDir(new File(PATH + model.getElementAt(index).getIconName() + ".png"));// model.removeElementAt(index);// LIST } }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createImportButton() { JButton b = new JButton(new AbstractAction(null, UIAgent.getInstance().getIcon(UIAgent.ICON_IMPORT_24)) { private static final long serialVersionUID = 985413615438877711L; @Override// w ww. jav a2 s .co m public void actionPerformed(ActionEvent e) { JFileChooser ch = new JFileChooser(); ch.setFileFilter(new ExtensionFilter("xls", "Excel File")); int i = ch.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { DiveProfileExcelParser p = new DiveProfileExcelParser(); try { File f = ch.getSelectedFile(); DiveProfile dp = p.read(f); I18nResourceManager i18n = I18nResourceManager.sharedInstance(); int yes = JOptionPane.showConfirmDialog(DiveProfileGraphicDetailPanel.this, i18n.getString("overwritte.diveprofile.confirm"), i18n.getString("confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (yes == JOptionPane.YES_OPTION) { currentDive.setDiveProfile(dp); setDiveProfile(dp, currentDive); logBookManagerFacade.setDiveChanged(currentDive); } } catch (IOException e1) { ExceptionDialog.showDialog(e1, DiveProfileGraphicDetailPanel.this); LOGGER.error(e1.getMessage()); } } } }); b.setToolTipText("Import"); return b; }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * Handles an action event./*from w w w . j av a2 s . com*/ * * @param evt * the event. */ public void actionPerformed(ActionEvent evt) { try { String acmd = evt.getActionCommand(); if (acmd.equals(ACTION_CHART_ZOOM_BOX)) { setPanMode(false); } else if (acmd.equals(ACTION_CHART_PAN)) { setPanMode(true); } else if (acmd.equals(ACTION_CHART_ZOOM_IN)) { ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), ZOOM_FACTOR); } else if (acmd.equals(ACTION_CHART_ZOOM_OUT)) { ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), 1 / ZOOM_FACTOR); } else if (acmd.equals(ACTION_CHART_ZOOM_TO_FIT)) { // X-axis (has no fixed borders) chartPanel.autoRangeHorizontal(); Plot plot = chartPanel.getChart().getPlot(); if (plot instanceof ValueAxisPlot) { XYPlot vvPlot = (XYPlot) plot; ValueAxis axis = vvPlot.getRangeAxis(); if (axis != null) { axis.setLowerBound(yMin); axis.setUpperBound(yMax); } } } else if (acmd.equals(ACTION_CHART_EXPORT)) { try { chartPanel.doSaveAs(); } catch (IOException i) { MsgBox.error(i.getMessage()); } } else if (acmd.equals(ACTION_CHART_PRINT)) { chartPanel.createChartPrintJob(); } else if (acmd.equals(ACTION_CHART_PROPERTIES)) { ChartPropertyEditPanel panel = new ChartPropertyEditPanel(jFreeChart); int result = JOptionPane.showConfirmDialog(this, panel, localizationResources.getString("Chart_Properties"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { panel.updateChartProperties(jFreeChart); } } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:com.sshtools.tunnel.PortForwardingPane.java
protected void editPortForward() { ForwardingConfiguration config = model.getForwardingConfigurationAt(table.getSelectedRow()); if (config.getName().equals("x11")) { JOptionPane.showMessageDialog(this, "You cannot edit X11 forwarding.", "Error", JOptionPane.ERROR_MESSAGE); return;/*from w w w.j ava2s .c o m*/ } PortForwardEditorPane editor = new PortForwardEditorPane(config); int option = JOptionPane.showConfirmDialog(this, editor, "Edit Tunnel", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (option != JOptionPane.CANCEL_OPTION && option != JOptionPane.CLOSED_OPTION) { try { ForwardingClient forwardingClient = client; String id = editor.getForwardName(); if (id.equals("x11")) { throw new Exception("The id of x11 is reserved."); } if (editor.getHost().equals("")) { throw new Exception("Please specify a destination host."); } int i = model.getRowCount(); if (editor.isLocal()) { forwardingClient.removeLocalForwarding(config.getName()); forwardingClient.addLocalForwarding(id, editor.getBindAddress(), editor.getLocalPort(), editor.getHost(), editor.getRemotePort()); forwardingClient.startLocalForwarding(id); } else { forwardingClient.removeRemoteForwarding(config.getName()); forwardingClient.addRemoteForwarding(id, editor.getBindAddress(), editor.getLocalPort(), editor.getHost(), editor.getRemotePort()); forwardingClient.startRemoteForwarding(id); } if (i < model.getRowCount()) { table.getSelectionModel().addSelectionInterval(i, i); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } finally { model.refresh(); sessionPanel.setAvailableActions(); } } }
From source file:model.settings.ReadSettings.java
/** * checks whether program information on current workspace exist. * @return if workspace is now set.//from w w w .j a v a 2 s . c om */ public static String install() { boolean installed = false; String wsLocation = ""; /* * does program root directory exist? */ if (new File(PROGRAM_LOCATION).exists()) { //try to read try { wsLocation = readFromFile(PROGRAM_SETTINGS_LOCATION); installed = new File(wsLocation).exists(); if (!installed) { wsLocation = ""; } } catch (FileNotFoundException e) { System.out.println("file not found " + e); showErrorMessage(); } catch (IOException e) { System.out.println("io" + e); showErrorMessage(); } } //if settings not found. if (!installed) { new File(PROGRAM_LOCATION).mkdir(); try { //create new file chooser JFileChooser jc = new JFileChooser(); //sets the text and language of all the components in JFileChooser UIManager.put("FileChooser.openDialogTitleText", "Open"); UIManager.put("FileChooser.lookInLabelText", "LookIn"); UIManager.put("FileChooser.openButtonText", "Open"); UIManager.put("FileChooser.cancelButtonText", "Cancel"); UIManager.put("FileChooser.fileNameLabelText", "FileName"); UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles"); UIManager.put("FileChooser.openButtonToolTipText", "OpenSelectedFile"); UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel"); UIManager.put("FileChooser.fileNameHeaderText", "FileName"); UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel"); UIManager.put("FileChooser.homeFolderToolTipText", "Desktop"); UIManager.put("FileChooser.newFolderToolTipText", "CreateNewFolder"); UIManager.put("FileChooser.listViewButtonToolTipText", "List"); UIManager.put("FileChooser.newFolderButtonText", "CreateNewFolder"); UIManager.put("FileChooser.renameFileButtonText", "RenameFile"); UIManager.put("FileChooser.deleteFileButtonText", "DeleteFile"); UIManager.put("FileChooser.filterLabelText", "TypeFiles"); UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details"); UIManager.put("FileChooser.fileSizeHeaderText", "Size"); UIManager.put("FileChooser.fileDateHeaderText", "DateModified"); SwingUtilities.updateComponentTreeUI(jc); jc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jc.setMultiSelectionEnabled(false); final String informationMsg = "Please select the workspace folder. \n" + "By default, the new files are saved in there. \n\n" + "Is changed simply by using the Save-As option.\n" + "If no folder is specified, the default worspace folder \n" + "is the home directory of the current user."; final int response = JOptionPane.showConfirmDialog(jc, informationMsg, "Select workspace folder", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); final String defaultSaveLocation = System.getProperty("user.home") + System.getProperty("file.separator"); File f; if (response != JOptionPane.NO_OPTION) { //fetch selected file f = jc.getSelectedFile(); jc.showDialog(null, "select"); } else { f = new File(defaultSaveLocation); } printInformation(); if (f == null) { f = new File(defaultSaveLocation); } //if file selected if (f != null) { //if the file exists if (f.exists()) { writeToFile(PROGRAM_SETTINGS_LOCATION, ID_PROGRAM_LOCATION + "\n" + f.getAbsolutePath()); } else { //open message dialog JOptionPane.showConfirmDialog(null, "Folder does " + "not exist", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } //recall install return install(); } } catch (IOException e) { System.out.println(e); JOptionPane.showConfirmDialog(null, "An exception occured." + " Try again later.", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } } if (System.getProperty("os.name").equals("Mac OS X")) { installOSX(); } else if (System.getProperty("os.name").equals("Linux")) { installLinux(); } else if (System.getProperty("os.name").equals("Windows")) { installWindows(); } return wsLocation; }
From source file:net.sf.jabref.external.DroppedFileHandler.java
private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCompound edits) { if (!"pdf".equals(fileType.getExtension())) { return false; }/*from ww w . j a va 2 s . com*/ List<BibEntry> xmpEntriesInFile; try { xmpEntriesInFile = XMPUtil.readXMP(fileName, Globals.prefs); } catch (IOException e) { LOGGER.warn("Problem reading XMP", e); return false; } if ((xmpEntriesInFile == null) || xmpEntriesInFile.isEmpty()) { return false; } JLabel confirmationMessage = new JLabel(Localization.lang("The PDF contains one or several BibTeX-records.") + "\n" + Localization.lang("Do you want to import these as new entries into the current database?")); int reply = JOptionPane.showConfirmDialog(frame, confirmationMessage, Localization.lang("XMP-metadata found in PDF: %0", fileName), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (reply == JOptionPane.CANCEL_OPTION) { return true; // The user canceled thus that we are done. } if (reply == JOptionPane.NO_OPTION) { return false; } // reply == JOptionPane.YES_OPTION) /* * TODO Extract Import functionality from ImportMenuItem then we could * do: * * ImportMenuItem importer = new ImportMenuItem(frame, (mainTable == * null), new PdfXmpImporter()); * * importer.automatedImport(new String[] { fileName }); */ boolean isSingle = xmpEntriesInFile.size() == 1; BibEntry single = isSingle ? xmpEntriesInFile.get(0) : null; boolean success = true; String destFilename; if (linkInPlace.isSelected()) { destFilename = FileUtil .shortenFileName(new File(fileName), panel.getBibDatabaseContext().getFileDirectory()) .toString(); } else { if (renameCheckBox.isSelected()) { destFilename = fileName; } else { destFilename = single.getCiteKey() + "." + fileType.getExtension(); } if (copyRadioButton.isSelected()) { success = doCopy(fileName, destFilename, edits); } else if (moveRadioButton.isSelected()) { success = doMove(fileName, destFilename, edits); } } if (success) { for (BibEntry aXmpEntriesInFile : xmpEntriesInFile) { aXmpEntriesInFile.setId(IdGenerator.next()); edits.addEdit(new UndoableInsertEntry(panel.getDatabase(), aXmpEntriesInFile, panel)); panel.getDatabase().insertEntry(aXmpEntriesInFile); doLink(aXmpEntriesInFile, fileType, destFilename, true, edits); } panel.markBaseChanged(); panel.updateEntryEditorIfShowing(); } return true; }
From source file:emailplugin.MailCreator.java
/** * Shows a Warning if the Plugin was not configured correctly. * * @param parent Parent-Dialog/*from w w w.java 2s . c om*/ */ private void showNotConfiguredCorrectly(Frame parent) { int ret = JOptionPane.showConfirmDialog(parent, mLocalizer.msg("NotConfiguredCorrectly", "Not configured correctly"), Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); if (ret == JOptionPane.YES_OPTION) { Plugin.getPluginManager().showSettings(mPlugin); } }
From source file:gdt.jgui.entity.JEntitiesPanel.java
/** * Get context menu.//from ww w. j av a 2 s .c o m * @return the context menu. * */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); mia = null; int cnt = menu.getItemCount(); if (cnt > 0) { 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) { menu.removeAll(); if (mia != null) for (JMenuItem mi : mia) try { if (mi != null) menu.add(mi); } catch (Exception ee) { System.out.println("JEntitiesPanel:getConextMenu:" + ee.toString()); } Properties locator = Locator.toProperties(locator$); if (locator.getProperty(EntityHandler.ENTITY_CONTAINER) != null) { if (JEntityPrimaryMenu.hasToPaste(console, locator$)) { pasteItem = new JMenuItem("Paste components"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pasteComponents(); } }); menu.add(pasteItem); } if (hasSelectedItems()) { if (containerKey$ != null) { removeComponentsItem = new JMenuItem("Remove components"); removeComponentsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeComponents(); } }); menu.add(removeComponentsItem); } } } if (locator.getProperty(EntityHandler.ENTITY_COMPONENT) != null) { if (componentKey$ != null) { removeContainersItem = new JMenuItem("Remove containers"); removeContainersItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeContainers(); } }); menu.add(removeContainersItem); } } if (hasSelectedItems()) { menu.addSeparator(); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); ArrayList<String> sl = new ArrayList<String>(); for (JItemPanel ip : ipa) if (ip.isChecked()) sl.add(ip.getLocator()); String[] sa = sl.toArray(new String[0]); console.clipboard.clear(); for (String aSa : sa) console.clipboard.putString(aSa); } }); menu.add(copyItem); reindexItem = new JMenuItem("Reindex"); reindexItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); for (JItemPanel ip : ipa) if (ip.isChecked()) { JEntityPrimaryMenu.reindexEntity(console, ip.getLocator()); } } }); menu.add(reindexItem); archiveItem = new JMenuItem("Archive"); archiveItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); Entigrator entigrator = console.getEntigrator(entihome$); Properties locator; ArrayList<String> sl = new ArrayList<String>(); String entityKey$; for (JItemPanel ip : ipa) { if (ip.isChecked()) { locator = Locator.toProperties(ip.getLocator()); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); sl.add(entityKey$); } } String[] sa = sl.toArray(new String[0]); System.out.println("JEntitiesPanel:archive:1"); String[] ea = JReferenceEntry.getCoalition(console, entigrator, sa); if (ea == null) System.out.println("JEntitiesPanel:archive:ea null"); else System.out.println("JEntitiesPanel:archive:ea=" + ea.length); JArchivePanel archivePanel = new JArchivePanel(); String apLocator$ = archivePanel.getLocator(); //locator$=getLocator(); apLocator$ = Locator.append(apLocator$, Entigrator.ENTIHOME, entihome$); apLocator$ = Locator.append(apLocator$, EntityHandler.ENTITY_LIST, Locator.toString(ea)); String icon$ = Support.readHandlerIcon(null, JEntityPrimaryMenu.class, "archive.png"); apLocator$ = Locator.append(apLocator$, Locator.LOCATOR_ICON, icon$); JConsoleHandler.execute(console, apLocator$); } }); menu.add(archiveItem); menu.addSeparator(); 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) { JItemPanel[] ipa = JEntitiesPanel.this.getItems(); Entigrator entigrator = console.getEntigrator(entihome$); String iLocator$; Properties iLocator; String iEntityKey$; String iEntityLabel$; Sack iEntity; ArrayList<String> sl = new ArrayList<String>(); for (JItemPanel ip : ipa) { iLocator$ = ip.getLocator(); iLocator = Locator.toProperties(iLocator$); iEntityLabel$ = iLocator.getProperty(EntityHandler.ENTITY_LABEL); if (ip.isChecked()) { iEntityKey$ = iLocator.getProperty(EntityHandler.ENTITY_KEY); iEntity = entigrator.getEntityAtKey(iEntityKey$); if (iEntity != null) entigrator.deleteEntity(iEntity); } else { sl.add(iEntityLabel$); } } String[] sa = sl.toArray(new String[0]); if (sa != null && sa.length > 0) { String sa$ = Locator.toString(sa); locator$ = Locator.append(locator$, EntityHandler.ENTITY_LIST, sa$); } JConsoleHandler.execute(console, locator$); } } }); menu.add(deleteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); menu.addSeparator(); 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.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); return menu; }
From source file:at.becast.youploader.gui.FrmMain.java
/** * Creates new form frmMain//from www .j a v a 2s .c o m */ public FrmMain() { self = this; this.tos = false; this.setMinimumSize(new Dimension(900, 580)); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { LOG.info(Main.APP_NAME + " " + Main.VERSION + " closing.", FrmMain.class); Main.s.put("left", String.valueOf(getX())); Main.s.put("top", String.valueOf(getY())); Main.s.put("width", String.valueOf(getWidth())); Main.s.put("height", String.valueOf(getHeight())); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.stop(); e.getWindow().dispose(); } }); UploadMgr = UploadManager.getInstance(); TemplateMgr = TemplateManager.getInstance(); UploadMgr.setParent(this); String sspeed = Main.s.setting.get("speed"); if (sspeed != null) { speed = Integer.parseInt(sspeed); } else { speed = 0; } initComponents(); initMenuBar(); loadAccounts(); this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/yp.png"))); try { loadQueue(); } catch (SQLException | IOException e) { LOG.error("Error: ", e); } this.setVisible(true); if (Main.firstlaunch) { int n = JOptionPane.showConfirmDialog(null, LANG.getString("frmMain.initialAccount.Message"), LANG.getString("frmMain.initialAccount.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (n == JOptionPane.YES_OPTION) { mntmAddAccountActionPerformed(); } } else { PlaylistUpdater pu = new PlaylistUpdater(this); Thread updater = new Thread(pu); updater.start(); AccountUpdater au = new AccountUpdater(this); Thread aupdater = new Thread(au); aupdater.start(); } EditPanel edit = (EditPanel) ss1.contentPane; if (edit.getCmbTemplate().getModel().getSize() > 0) { edit.getCmbTemplate().setSelectedIndex(0); } tray = new TrayManager(this); addWindowStateListener(new WindowStateListener() { public void windowStateChanged(WindowEvent e) { if (e.getNewState() == ICONIFIED) { tray.add(); setVisible(false); } if (e.getNewState() == 7) { tray.add(); setVisible(false); } if (e.getNewState() == MAXIMIZED_BOTH) { tray.remove(); setVisible(true); } if (e.getNewState() == NORMAL) { tray.remove(); setVisible(true); } } }); }