List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
@Override protected void confirmDeleteAlternative(Alternative alternative) { if (!smaaModel.getCategories().contains(alternative)) { super.confirmDeleteAlternative(alternative); } else {// w ww .j a v a 2 s .c o m String typeName = "category"; int conf = JOptionPane.showConfirmDialog(parent, "Do you really want to delete " + typeName + " " + alternative + "?", "Confirm deletion", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_DELETE)); if (conf == JOptionPane.YES_OPTION) { smaaModel.deleteCategory(alternative); } } }
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 ww. j a va 2 s .co 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:ca.uviccscu.lp.persistence.ChooseFolderDialog.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed String path = jTextField3.getText(); File f = new File(path); l.trace("WFolder path entered: [" + path + "]"); int verification = SettingsManager.verifyWorkingFolder(path); l.trace("Initial WFolder verification: " + verification); if (verification != 0) { switch (verification) { case (1): { if (path == null || path.equals("")) { verification = 8;//from www . j a v a 2 s .c o m l.trace("WFolder verification ch: " + verification); JOptionPane.showMessageDialog(this, "Path field empty!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); } if (verification == 1) { try { Thread.sleep(100); } catch (InterruptedException ex) { java.util.logging.Logger.getLogger(ChooseFolderDialog.class.getName()).log(Level.SEVERE, null, ex); } int resp = JOptionPane.showConfirmDialog(this, "Directory doesn't exist! Create?", "WFolder creation warning", JOptionPane.YES_NO_OPTION); if (resp == JOptionPane.YES_OPTION) { verification = 0; l.trace("WFolder verification ch: " + verification); } else if (resp == JOptionPane.NO_OPTION) { verification = 7; l.trace("WFolder verification ch: " + verification); } } break; } case (2): { if (path == null || path.equals("")) { verification = 8; l.trace("WFolder verification ch: " + verification); JOptionPane.showMessageDialog(this, "Path field empty!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Path not absolute!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); } break; } case (3): { JOptionPane.showMessageDialog(this, "Can't read!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); break; } case (4): { JOptionPane.showMessageDialog(this, "Can't write!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); break; } case (5): { JOptionPane.showMessageDialog(this, "File error!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); break; } case (6): { //JOptionPane.showMessageDialog(this, "File error!", "WFolder creation error", JOptionPane.ERROR_MESSAGE); l.error("Directory not empty"); l.trace("WFolder verification ch: " + verification); //JDialog jd = new JDialog((JFrame) null, true); int resp = JOptionPane.showConfirmDialog(null, "Directory nonempty: " + f.getAbsolutePath() + ". Wipe and proceed?", "Confirm deletion", JOptionPane.YES_NO_OPTION); if (resp == JOptionPane.YES_OPTION) { try { FileUtils.deleteDirectory(f); verification = 0; } catch (IOException ex) { l.fatal("Can't wipe directory", ex); System.exit(1); } } break; } } } l.trace("Final WFolder verification: " + verification); if (verification == 0) { Shared.lastFolder_path = path; Shared.lastFolder_verification = verification; Shared.lastFolder_wasCancelled = false; this.setVisible(false); } }
From source file:com.dragoniade.deviantart.deviation.SearchStream.java
public List<Collection> getCollections() { List<Collection> collections = new ArrayList<Collection>(); if (search.getCollection() == null) { collections.add(null);//w ww . ja v a 2s. co m return collections; } String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/"; GetMethod method = new GetMethod(queryString); try { int sc = -1; do { sc = client.executeMethod(method); if (sc != 200) { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return null; } } } while (sc != 200); InputStream is = method.getResponseBodyAsStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = -1; while ((read = is.read(buffer)) > -1) { baos.write(buffer, 0, read); } String charsetName = method.getResponseCharSet(); String body = baos.toString(charsetName); String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(body); while (matcher.find()) { String id = matcher.group(1); String name = matcher.group(2); Collection c = new Collection(Long.parseLong(id), name); collections.add(c); } } catch (IOException e) { } finally { method.releaseConnection(); } collections.add(null); return collections; }
From source file:net.sf.jabref.importer.OpenDatabaseAction.java
/** * @param file the file, may be null or not existing *///from www. ja v a 2s.c om private void openTheFile(File file, boolean raisePanel) { if ((file != null) && file.exists()) { File fileToLoad = file; frame.output(Localization.lang("Opening") + ": '" + file.getPath() + "'"); boolean tryingAutosave = false; boolean autoSaveFound = AutoSaveManager.newerAutoSaveExists(file); if (autoSaveFound && !Globals.prefs.getBoolean(JabRefPreferences.PROMPT_BEFORE_USING_AUTOSAVE)) { // We have found a newer autosave, and the preferences say we should load // it without prompting, so we replace the fileToLoad: fileToLoad = AutoSaveManager.getAutoSaveFile(file); tryingAutosave = true; } else if (autoSaveFound) { // We have found a newer autosave, but we are not allowed to use it without // prompting. int answer = JOptionPane.showConfirmDialog(null, "<html>" + Localization.lang("An autosave file was found for this database. This could indicate " + "that JabRef didn't shut down cleanly last time the file was used.") + "<br>" + Localization.lang("Do you want to recover the database from the autosave file?") + "</html>", Localization.lang("Recover from autosave"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { fileToLoad = AutoSaveManager.getAutoSaveFile(file); tryingAutosave = true; } } boolean done = false; while (!done) { String fileName = file.getPath(); Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, file.getPath()); // Should this be done _after_ we know it was successfully opened? if (FileBasedLock.hasLockFile(file.toPath())) { Optional<FileTime> modificationTime = FileBasedLock.getLockFileTimeStamp(file.toPath()); if ((modificationTime.isPresent()) && ((System.currentTimeMillis() - modificationTime.get().toMillis()) > FileBasedLock.LOCKFILE_CRITICAL_AGE)) { // The lock file is fairly old, so we can offer to "steal" the file: int answer = JOptionPane.showConfirmDialog(null, "<html>" + Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance.") + "<p>" + Localization.lang("Do you want to override the file lock?"), Localization.lang("File locked"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { FileBasedLock.deleteLockFile(file.toPath()); } else { return; } } else if (!FileBasedLock.waitForFileLock(file.toPath(), 10)) { JOptionPane.showMessageDialog(null, Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); return; } } Charset encoding = Globals.prefs.getDefaultEncoding(); ParserResult result; String errorMessage = null; try { result = OpenDatabaseAction.loadDatabase(fileToLoad, encoding); } catch (IOException ex) { LOGGER.error("Error loading database " + fileToLoad, ex); result = ParserResult.getNullResult(); } if (result.isNullResult()) { JOptionPane.showMessageDialog(null, Localization.lang("Error opening file") + " '" + fileName + "'", Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); String message = "<html>" + errorMessage + "<p>" + (tryingAutosave ? Localization.lang( "Error opening autosave of '%0'. Trying to load '%0' instead.", file.getName()) : ""/*Globals.lang("Error opening file '%0'.", file.getName())*/) + "</html>"; JOptionPane.showMessageDialog(null, message, Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE); if (tryingAutosave) { tryingAutosave = false; fileToLoad = file; } else { done = true; } continue; } else { done = true; } final BasePanel panel = addNewDatabase(result, file, raisePanel); if (tryingAutosave) { panel.markNonUndoableBaseChanged(); } // After adding the database, go through our list and see if // any post open actions need to be done. For instance, checking // if we found new entry types that can be imported, or checking // if the database contents should be modified due to new features // in this version of JabRef: final ParserResult finalReferenceToResult = result; SwingUtilities.invokeLater( () -> OpenDatabaseAction.performPostOpenActions(panel, finalReferenceToResult, true)); } } }
From source file:com.alvermont.terraj.planet.ui.TerrainFrame.java
private void saveImageItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveImageItemActionPerformed {//GEN-HEADEREND:event_saveImageItemActionPerformed int choice = pngChooser.showSaveDialog(this); if (choice == JFileChooser.APPROVE_OPTION) { try {/*www . j a v a 2 s . c o m*/ if (!pngChooser.getFileContents().canRead() || (JOptionPane.showConfirmDialog(this, "This file already exists. Do you want to\n" + "overwrite it?", "Replace File?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) { final OutputStream target = pngChooser.getFileContents().getOutputStream(true); // More JNLP silliness. How am I supposed to know what size // an image file will compress to and there is no guidance // in the documentation as to what value can be reasonably // requested here. I've just picked something and gone with // it, which seems to be in line with the philosophy of // the people who designed Java WebStart pngChooser.getFileContents().setMaxLength(500000); ImageIO.write(image, PNGFileFilter.getFormatName(new File(pngChooser.getFileContents().getName())), target); target.close(); } } catch (IOException ioe) { log.error("Error writing image file", ioe); JOptionPane.showMessageDialog(this, "Error: " + ioe.getMessage() + "\nCheck log file for full details", "Error Saving", JOptionPane.ERROR_MESSAGE); } } }
From source file:com.simplexrepaginator.RepaginateFrame.java
protected JButton createInputButton() { JButton b = new JButton("Click or drag to set input files", PDF_1342); b.setHorizontalTextPosition(SwingConstants.RIGHT); b.setIconTextGap(25);//from w w w. j a v a 2s. com b.setTransferHandler(new InputButtonTransferHandler()); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (chooser.showOpenDialog(RepaginateFrame.this) != JFileChooser.APPROVE_OPTION) return; setInput(Arrays.asList(chooser.getSelectedFiles())); if (JOptionPane.showConfirmDialog(RepaginateFrame.this, "Use input paths as output paths?", "Use Input As Output?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { setOutput(new ArrayList<File>(repaginator.getInputFiles())); } } }); return b; }
From source file:com.xilinx.kintex7.MainScreen.java
public void initialize(LandingPage l, String imgName, int mode) { lp = l;// ww w. j a v a 2s. c om blockDiagram = Toolkit.getDefaultToolkit() .getImage(getClass().getResource("/com/xilinx/kintex7/" + imgName)); led1 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/green.png")); led2 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/ledoff.png")); led3 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/red.png")); this.mode = mode; setModeText(mode); dataMismatch0 = dataMismatch2 = errcnt0 = errcnt1 = false; di = null; di = new DriverInfo(); di.init(mode); int ret = di.get_PCIstate(); //ret = di.get_PowerStats(); test1_option = DriverInfo.ENABLE_LOOPBACK; test2_option = DriverInfo.ENABLE_LOOPBACK; // create a new jframe, and pack it frame = new JFrame("Kintex-7 Connectivity TRD Control & Monitoring Interface"); frame.pack(); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final int m = mode; frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // check if tests are running or not if ((testStarted || testStarted1) && ((m != LandingPage.APPLICATION_MODE) || (m != LandingPage.APPLICATION_MODE_P2P))) { int confirmed = JOptionPane.showConfirmDialog(null, "This will stop the tests and uninstall the drivers. Do you want to continue?", "Exit", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { if (testStarted) { di.stopTest(0, test1_option, Integer.parseInt(t1_psize.getText())); testStarted = false; } if (testStarted1) { di.stopTest(1, test2_option, Integer.parseInt(t2_psize.getText())); testStarted1 = false; } timer.cancel(); textArea.removeAll(); di.flush(); di = null; System.gc(); lp.uninstallDrivers(); showDialog("Removing Device Drivers...Please wait..."); } } else { int confirmed = JOptionPane.showConfirmDialog(null, "This will Uninstall the drivers. Do you want to continue?", "Exit", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { timer.cancel(); textArea.removeAll(); di.flush(); di = null; System.gc(); lp.uninstallDrivers(); showDialog("Removing Device Drivers...Please wait..."); } } } }); // make the frame half the height and width Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); height = screenSize.height; width = screenSize.width; minWidth = 1000; minHeight = 700; minFrameWidth = 1024; minFrameHeight = 745; reqHeight = 745; if (width < 1280) reqWidth = 1024; else if (width == 1280) reqWidth = 1280; else if (width < 1600) { reqWidth = width - (width * 4) / 100; reqHeight = height - (height * 3) / 100; } else { reqWidth = reqHeight = height = height - (height * 10) / 100; } frame.setSize(new Dimension(minFrameWidth, minFrameHeight)); frame.setResizable(true); frame.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { frame.setSize(new Dimension(Math.max(minFrameWidth, frame.getWidth()), Math.max(minFrameHeight, frame.getHeight()))); } @Override public void componentMoved(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } @Override public void componentShown(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } @Override public void componentHidden(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } }); frame.setVisible(true); frame.setIconImage( Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/kintex7/icon.png"))); // center the jframe on screen frame.setLocationRelativeTo(null); frame.setContentPane(createContentPane()); keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.RED); StyleConstants.setBold(keyWord, true); logStatus = new SimpleAttributeSet(); StyleConstants.setForeground(logStatus, Color.BLACK); StyleConstants.setBold(logStatus, true); if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) { testStarted = testStarted1 = true; } if (mode == LandingPage.PERFORMANCE_MODE_RAW) { t1_o1.setSelected(true); t1_o2.setEnabled(false); t1_o3.setEnabled(false); t2_o2.setEnabled(false); t2_o3.setEnabled(false); } if (mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { t1_o2.setEnabled(false); t1_o3.setEnabled(false); t2_o2.setEnabled(false); t2_o3.setEnabled(false); t1_o1.setSelected(true); } // initialize max packet size ret = di.get_EngineState(); EngState[] engData = di.getEngState(); maxpkt0 = engData[0].MaxPktSize; minpkt0 = engData[0].MinPktSize; minpkt1 = engData[2].MinPktSize; maxpkt1 = engData[2].MaxPktSize; t1_psize.setText(String.valueOf(maxpkt0)); t2_psize.setText(String.valueOf(maxpkt1)); t1_psize.setToolTipText(minpkt0 + "-" + maxpkt0); t2_psize.setToolTipText(minpkt1 + "-" + maxpkt1); updateLog(di.getPCIInfo().getVersionInfo(), logStatus); updateLog("Configuration: " + modeText, logStatus); // LED status di.get_LedStats(); lstats = di.getLedStats(); setLedStats(lstats); startTimer(); }
From source file:com.att.aro.ui.model.diagnostic.GraphPanelHelper.java
public void SaveImageAs(JViewport pane, String graphPanelSaveDirectory) { JFileChooser fc = new JFileChooser(graphPanelSaveDirectory); // Set up file types String[] fileTypesJPG = new String[2]; String fileDisplayTypeJPG = ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.jpeg"); fileTypesJPG[0] = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpeg"); fileTypesJPG[1] = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpg"); FileFilter filterJPG = new ExtensionFileFilter(fileDisplayTypeJPG, fileTypesJPG); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); String[] fileTypesPng = new String[1]; String fileDisplayTypePng = ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.png"); fileTypesPng[0] = ResourceBundleHelper.getMessageString("fileChooser.contentType.png"); FileFilter filterPng = new ExtensionFileFilter(fileDisplayTypePng, fileTypesPng); fc.addChoosableFileFilter(filterPng); fc.setFileFilter(filterJPG);//from w w w. j av a 2 s.c o m File plotImageFile = null; boolean bSavedOrCancelled = false; while (!bSavedOrCancelled) { if (fc.showSaveDialog(pane) == JFileChooser.APPROVE_OPTION) { String strFile = fc.getSelectedFile().toString(); String strFileLowerCase = strFile.toLowerCase(); String fileDesc = fc.getFileFilter().getDescription(); String fileType = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpg"); if ((fileDesc.equalsIgnoreCase( ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.png")) || strFileLowerCase.endsWith(ResourceBundleHelper.getMessageString("fileType.filters.dot") + fileTypesPng[0].toLowerCase()))) { fileType = fileTypesPng[0]; } if (strFile.length() > 0) { // Save current directory graphPanelSaveDirectory = fc.getCurrentDirectory().getPath(); if ((fileType != null) && (fileType.length() > 0)) { String fileTypeLowerCaseWithDot = ResourceBundleHelper .getMessageString("fileType.filters.dot") + fileType.toLowerCase(); if (!strFileLowerCase.endsWith(fileTypeLowerCaseWithDot)) { strFile += ResourceBundleHelper.getMessageString("fileType.filters.dot") + fileType; } } plotImageFile = new File(strFile); boolean bAttemptToWriteToFile = true; if (plotImageFile.exists()) { if (MessageDialogFactory.showConfirmDialog(pane, MessageFormat.format( ResourceBundleHelper.getMessageString("fileChooser.fileExists"), plotImageFile.getAbsolutePath()), ResourceBundleHelper.getMessageString("fileChooser.confirm"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { bAttemptToWriteToFile = false; } } if (bAttemptToWriteToFile) { try { if (fileType != null && fileType.equalsIgnoreCase(fileTypesPng[0])) { BufferedImage bufImage = ImageHelper.createImage(pane.getBounds().width, pane.getBounds().height); Graphics2D g = bufImage.createGraphics(); pane.paint(g); ImageIO.write(bufImage, "png", plotImageFile); } else { BufferedImage bufImage = ImageHelper.createImage(pane.getBounds().width, pane.getBounds().height); Graphics2D g = bufImage.createGraphics(); pane.paint(g); ImageIO.write(bufImage, "jpg", plotImageFile); } bSavedOrCancelled = true; } catch (IOException e) { MessageDialogFactory.showMessageDialog(pane, ResourceBundleHelper .getMessageString("fileChooser.errorWritingToFile" + plotImageFile.toString())); } } } } else { bSavedOrCancelled = true; } } }
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/* www . ja v a2 s . c o 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; }