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:edu.harvard.mcz.imagecapture.jobs.JobRecheckForTemplates.java
private List<ICImage> getFileList() { List<ICImage> files = new ArrayList<ICImage>(); if (scan != SCAN_ALL) { String pathToCheck = ""; // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;// w w w . j a v a 2 s . c o m // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); // retrieve a list of image records in the selected directory ICImageLifeCycle ils = new ICImageLifeCycle(); ICImage pattern = new ICImage(); pattern.setPath(pathToCheck); pattern.setTemplateId(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS); files = ils.findByExample(pattern); if (files != null) { log.debug(files.size()); } } } } } else { try { // retrieve a list of all image records with no template ICImageLifeCycle ils = new ICImageLifeCycle(); files = ils.findNotDrawerNoTemplateImages(); if (files != null) { log.debug(files.size()); } } catch (HibernateException e) { log.error(e.getMessage()); runStatus = RunStatus.STATUS_FAILED; String message = "Error loading the list of images with no templates. " + e.getMessage(); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Error loading image records.", JOptionPane.YES_NO_OPTION); } } log.debug("Found " + files.size() + " Image files without templates in directory to check."); return files; }
From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java
/** * Remove was pressed// w ww . jav a2 s . c om */ protected void removePressed() { if (mList.getSelectedValue() == null) { return; } mDeleting = true; int result = JOptionPane.showConfirmDialog(this, mLocalizer.msg("Delete", "Delete Parameter?"), mLocalizer.msg("Additional", "Additional Parameters"), JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { mSelectedEntry = null; int num = mList.getSelectedIndex(); mListModel.removeElement(mList.getSelectedValue()); if (num + 1 > mListModel.size()) { mList.setSelectedIndex(mListModel.size() - 1); } else if (mListModel.size() > 0) { mList.setSelectedIndex(num); } } mDeleting = false; }
From source file:com.floreantpos.config.ui.DatabaseConfigurationDialog.java
public void actionPerformed(ActionEvent e) { try {//from w w w. j a v a 2s . c om String command = e.getActionCommand(); Database selectedDb = (Database) databaseCombo.getSelectedItem(); final String providerName = selectedDb.getProviderName(); final String databaseURL = tfServerAddress.getText(); final String databasePort = tfServerPort.getText(); final String databaseName = tfDatabaseName.getText(); final String user = tfUserName.getText(); final String pass = new String(tfPassword.getPassword()); final String connectionString = selectedDb.getConnectString(databaseURL, databasePort, databaseName); final String hibernateDialect = selectedDb.getHibernateDialect(); final String driverClass = selectedDb.getHibernateConnectionDriverClass(); if (CANCEL.equalsIgnoreCase(command)) { dispose(); return; } setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Application.getInstance().setSystemInitialized(false); saveConfig(selectedDb, providerName, databaseURL, databasePort, databaseName, user, pass, connectionString, hibernateDialect); if (TEST.equalsIgnoreCase(command)) { try { DatabaseUtil.checkConnection(connectionString, hibernateDialect, driverClass, user, pass); } catch (DatabaseConnectionException e1) { JOptionPane.showMessageDialog(this, Messages.getString("DatabaseConfigurationDialog.32")); //$NON-NLS-1$ return; } connectionSuccess = true; JOptionPane.showMessageDialog(this, Messages.getString("DatabaseConfigurationDialog.31")); //$NON-NLS-1$ } else if (UPDATE_DATABASE.equals(command)) { int i = JOptionPane.showConfirmDialog(this, Messages.getString("DatabaseConfigurationDialog.0"), //$NON-NLS-1$ Messages.getString("DatabaseConfigurationDialog.1"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ if (i != JOptionPane.YES_OPTION) { return; } //isAuthorizedToPerformDbChange(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); boolean databaseUpdated = DatabaseUtil.updateDatabase(connectionString, hibernateDialect, driverClass, user, pass); if (databaseUpdated) { connectionSuccess = true; JOptionPane.showMessageDialog(DatabaseConfigurationDialog.this, Messages.getString("DatabaseConfigurationDialog.2")); //$NON-NLS-1$ } else { JOptionPane.showMessageDialog(DatabaseConfigurationDialog.this, Messages.getString("DatabaseConfigurationDialog.3")); //$NON-NLS-1$ } } else if (CREATE_DATABASE.equals(command)) { int i = JOptionPane.showConfirmDialog(this, Messages.getString("DatabaseConfigurationDialog.33"), //$NON-NLS-1$ Messages.getString("DatabaseConfigurationDialog.34"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ if (i != JOptionPane.YES_OPTION) { return; } i = JOptionPane.showConfirmDialog(this, Messages.getString("DatabaseConfigurationDialog.4"), //$NON-NLS-1$ Messages.getString("DatabaseConfigurationDialog.5"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ boolean generateSampleData = false; if (i == JOptionPane.YES_OPTION) generateSampleData = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String createDbConnectString = selectedDb.getCreateDbConnectString(databaseURL, databasePort, databaseName); boolean databaseCreated = DatabaseUtil.createDatabase(createDbConnectString, hibernateDialect, driverClass, user, pass, generateSampleData); if (databaseCreated) { JOptionPane.showMessageDialog(DatabaseConfigurationDialog.this, Messages.getString("DatabaseConfigurationDialog.6") + //$NON-NLS-1$ Messages.getString("DatabaseConfigurationDialog.7")); //$NON-NLS-1$ Main.restart(); connectionSuccess = true; } else { JOptionPane.showMessageDialog(DatabaseConfigurationDialog.this, Messages.getString("DatabaseConfigurationDialog.36")); //$NON-NLS-1$ } } else if (SAVE.equalsIgnoreCase(command)) { if (connectionSuccess) { Application.getInstance().initializeSystem(); } dispose(); } } catch (Exception e2) { PosLog.error(getClass(), e2); POSMessageDialog.showMessage(this, e2.getMessage()); } finally { setCursor(Cursor.getDefaultCursor()); } }
From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java
private void exportPressed() { File chosenFile = null;/*from w ww . j a v a 2s.c om*/ FileWriter fw = null; String title; if (cert != null) { title = res.getString("DViewCertCsrPem.ExportPemCertificate.Title"); } else { title = res.getString("DViewCertCsrPem.ExportPemCsr.Title"); } try { String certPem = jtaPem.getText(); JFileChooser chooser = FileChooserFactory.getX509FileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DViewCertCsrPem.ChooseExportFile.button")); if (rtnValue != JFileChooser.APPROVE_OPTION) { return; } chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); if (chosenFile.isFile()) { String message = MessageFormat.format(res.getString("DViewCertCsrPem.OverWriteFile.message"), chosenFile); int selected = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION); if (selected != JOptionPane.YES_OPTION) { return; } } fw = new FileWriter(chosenFile); fw.write(certPem); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DViewCertCsrPem.NoWriteFile.message"), chosenFile), title, JOptionPane.WARNING_MESSAGE); return; } catch (Exception ex) { DError.displayError(this, ex); return; } finally { IOUtils.closeQuietly(fw); } JOptionPane.showMessageDialog(this, res.getString("DViewCertCsrPem.ExportPemCertificateSuccessful.message"), title, JOptionPane.INFORMATION_MESSAGE); }
From source file:com.esp8266.mkspiffs.ESP8266FS.java
private void createAndUpload() { if (!PreferencesData.get("target_platform").contentEquals("esp8266")) { System.err.println();//from ww w.ja v a2s . co m editor.statusError("SPIFFS Not Supported on " + PreferencesData.get("target_platform")); return; } if (!BaseNoGui.getBoardPreferences().containsKey("build.spiffs_start") || !BaseNoGui.getBoardPreferences().containsKey("build.spiffs_end")) { System.err.println(); editor.statusError("SPIFFS Not Defined for " + BaseNoGui.getBoardPreferences().get("name")); return; } long spiStart, spiEnd, spiPage, spiBlock; try { spiStart = getIntPref("build.spiffs_start"); spiEnd = getIntPref("build.spiffs_end"); spiPage = getIntPref("build.spiffs_pagesize"); if (spiPage == 0) spiPage = 256; spiBlock = getIntPref("build.spiffs_blocksize"); if (spiBlock == 0) spiBlock = 4096; } catch (Exception e) { editor.statusError(e); return; } TargetPlatform platform = BaseNoGui.getTargetPlatform(); //Make sure mkspiffs binary exists String mkspiffsCmd; if (PreferencesData.get("runtime.os").contentEquals("windows")) mkspiffsCmd = "mkspiffs.exe"; else mkspiffsCmd = "mkspiffs"; File tool = new File(platform.getFolder() + "/tools", mkspiffsCmd); if (!tool.exists() || !tool.isFile()) { tool = new File(platform.getFolder() + "/tools/mkspiffs", mkspiffsCmd); if (!tool.exists()) { tool = new File(PreferencesData.get("runtime.tools.mkspiffs.path"), mkspiffsCmd); if (!tool.exists()) { System.err.println(); editor.statusError("SPIFFS Error: mkspiffs not found!"); return; } } } Boolean isNetwork = false; File espota = new File(platform.getFolder() + "/tools"); File esptool = new File(platform.getFolder() + "/tools"); String serialPort = PreferencesData.get("serial.port"); //make sure the serial port or IP is defined if (serialPort == null || serialPort.isEmpty()) { System.err.println(); editor.statusError("SPIFFS Error: serial port not defined!"); return; } //find espota if IP else find esptool if (serialPort.split("\\.").length == 4) { isNetwork = true; String espotaCmd = "espota.py"; espota = new File(platform.getFolder() + "/tools", espotaCmd); if (!espota.exists() || !espota.isFile()) { System.err.println(); editor.statusError("SPIFFS Error: espota not found!"); return; } } else { String esptoolCmd = platform.getTool("esptool").get("cmd"); esptool = new File(platform.getFolder() + "/tools", esptoolCmd); if (!esptool.exists() || !esptool.isFile()) { esptool = new File(platform.getFolder() + "/tools/esptool", esptoolCmd); if (!esptool.exists()) { esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd); if (!esptool.exists()) { System.err.println(); editor.statusError("SPIFFS Error: esptool not found!"); return; } } } } //load a list of all files int fileCount = 0; File dataFolder = new File(editor.getSketch().getFolder(), "data"); if (!dataFolder.exists()) { dataFolder.mkdirs(); } if (dataFolder.exists() && dataFolder.isDirectory()) { File[] files = dataFolder.listFiles(); if (files.length > 0) { for (File file : files) { if ((file.isDirectory() || file.isFile()) && !file.getName().startsWith(".")) fileCount++; } } } String dataPath = dataFolder.getAbsolutePath(); String toolPath = tool.getAbsolutePath(); String sketchName = editor.getSketch().getName(); String imagePath = getBuildFolderPath(editor.getSketch()) + "\\" + sketchName + ".spiffs.bin"; String resetMethod = BaseNoGui.getBoardPreferences().get("upload.resetmethod"); String uploadSpeed = BaseNoGui.getBoardPreferences().get("upload.speed"); String uploadAddress = BaseNoGui.getBoardPreferences().get("build.spiffs_start"); Object[] options = { "Yes", "No" }; String title = "SPIFFS Create"; String message = "No files have been found in your data folder!\nAre you sure you want to create an empty SPIFFS image?"; if (fileCount == 0 && JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]) != JOptionPane.YES_OPTION) { System.err.println(); editor.statusError("SPIFFS Warning: mkspiffs canceled!"); return; } editor.statusNotice("SPIFFS Creating Image..."); System.out.println("[SPIFFS] data : " + dataPath); System.out.println("[SPIFFS] size : " + ((spiEnd - spiStart) / 1024)); System.out.println("[SPIFFS] page : " + spiPage); System.out.println("[SPIFFS] block : " + spiBlock); try { if (listenOnProcess(new String[] { toolPath, "-c", dataPath, "-p", spiPage + "", "-b", spiBlock + "", "-s", (spiEnd - spiStart) + "", imagePath }) != 0) { System.err.println(); editor.statusError("SPIFFS Create Failed!"); return; } } catch (Exception e) { editor.statusError(e); editor.statusError("SPIFFS Create Failed!"); return; } title = "SPIFFS Copy"; message = "Would you like a copy of the SPIFFS image in your project folder?"; if (JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) { File source = new File(imagePath); File dest = new File(editor.getSketch().getFolder(), "\\" + sketchName + ".spiffs.bin"); try { Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); System.out.println("Copied SPIFFS image"); } catch (IOException e) { System.out.println(e); editor.statusError("Copy SPIFFS image failed"); } } editor.statusNotice("SPIFFS Uploading Image..."); System.out.println("[SPIFFS] upload : " + imagePath); if (isNetwork) { String pythonCmd; if (PreferencesData.get("runtime.os").contentEquals("windows")) pythonCmd = "python.exe"; else pythonCmd = "python"; System.out.println("[SPIFFS] IP : " + serialPort); System.out.println(); sysExec(new String[] { pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath }); } else { System.out.println("[SPIFFS] address: " + uploadAddress); System.out.println("[SPIFFS] reset : " + resetMethod); System.out.println("[SPIFFS] port : " + serialPort); System.out.println("[SPIFFS] speed : " + uploadSpeed); System.out.println(); sysExec(new String[] { esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath }); } }
From source file:QueryConnector.java
private static boolean confirm(String msg) { return JOptionPane.showConfirmDialog(null, msg, tr("CONFIRM_DIALOG_TITLE"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; }
From source file:kevin.gvmsgarch.App.java
private static ContactFilter buildFilter() { ContactFilter retval = null;//from w ww . ja v a2 s .c o m int optionPaneResult; // optionPaneResult = JOptionPane.showConfirmDialog(null, "Do you want to enable filtering?", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); String[] options = new String[] { "Yes", "No" }; optionPaneResult = JOptionPane.showOptionDialog(null, "Do you want to enable filtering?", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (optionPaneResult == 0) { JOptionPane.showMessageDialog(null, filterExplanation); String contactName = JOptionPane .showInputDialog("Filter String (contact display name or phone number)"); if (contactName == null || contactName.trim().isEmpty()) { retval = new NullFilter(); } else { if (contactName.trim().equals("Unknown")) { retval = new UnknownFilter(); } else { retval = new NameNumberFilter(contactName); } } } else if (optionPaneResult == JOptionPane.NO_OPTION) { retval = new NullFilter(); } return retval; }
From source file:net.sf.jabref.exporter.SaveDatabaseAction.java
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException { SaveSession session;/*from www . j a v a2 s .com*/ frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs) .withEncoding(encoding); BibDatabaseWriter databaseWriter = new BibDatabaseWriter(); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), prefs, panel.getSelectedEntries()); } else { session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); } panel.registerUndoableChanges(session); } catch (UnsupportedCharsetException ex2) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization .lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } catch (SaveException ex) { if (ex == SaveException.FILE_LOCKED) { throw ex; } if (ex.specificEntry()) { // Error occured during processing of // be. Highlight it: int row = panel.mainTable.findEntry(ex.getEntry()); int topShow = Math.max(0, row - 3); panel.mainTable.setRowSelectionInterval(row, row); panel.mainTable.scrollTo(topShow); panel.showEntry(ex.getEntry()); } else { LOGGER.error("Problem saving file", ex); } JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } finally { frame.unblock(); } boolean commit = true; if (!session.getWriter().couldEncodeAll()) { FormBuilder builder = FormBuilder.create() .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters()); ta.setEditable(false); builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1); builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding); if (choice == null) { commit = false; } else { Charset newEncoding = Charset.forName((String) choice); return saveDatabase(file, selectedOnly, newEncoding); } } else if (answer == JOptionPane.CANCEL_OPTION) { commit = false; } } try { if (commit) { session.commit(file); panel.setEncoding(encoding); // Make sure to remember which encoding we used. } else { session.cancel(); } } catch (SaveException e) { int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { session.setUseBackup(false); session.commit(file); panel.setEncoding(encoding); } else { commit = false; } } return commit; }
From source file:gdt.jgui.tool.JEntityEditor.java
/** * Get the context menu.// w w w .j av a2 s .c om * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("EntityEditor:getConextMenu:menu selected"); if (editCellItem != null) menu.remove(editCellItem); if (deleteItemsItem != null) menu.remove(deleteItemsItem); if (copyItem != null) menu.remove(copyItem); if (pasteItem != null) menu.remove(pasteItem); if (cutItem != null) menu.remove(cutItem); if (hasEditingCell()) { //menu.addSeparator(); editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getEditCellLocator(); if (locator$ != null) JConsoleHandler.execute(console, locator$); } }); menu.add(editCellItem); } if (hasSelectedRows()) { deleteItemsItem = new JMenuItem("Delete items"); deleteItemsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete selected items ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { deleteRows(); } } }); menu.add(deleteItemsItem); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { element$ = null; content = getContent(true); } }); menu.add(copyItem); cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = tabbedPane.getSelectedIndex(); element$ = tabbedPane.getTitleAt(i); content = getContent(true); } }); menu.add(cutItem); } if (content != null) { pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pasteTable(content); int j = tabbedPane.getSelectedIndex(); if (element$ != null) { int cnt = tabbedPane.getComponentCount(); for (int i = 0; i < cnt; i++) { if (element$.equals(tabbedPane.getTitleAt(i))) { tabbedPane.setSelectedIndex(i); cutTable(content); tabbedPane.setSelectedIndex(j); } } } } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); console.back(); } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); menu.addSeparator(); JMenuItem addItemItem = new JMenuItem("Add item"); addItemItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addRow(); } }); menu.add(addItemItem); JMenuItem addElementItem = new JMenuItem("Add element"); addElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String element$ = "new element"; //addElement(element$); String locator$ = getRenameElementLocator(element$); JConsoleHandler.execute(console, locator$); } }); menu.add(addElementItem); JMenuItem deleteElementItem = new JMenuItem("Delete element"); deleteElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete element ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { tabbedPane.remove(tabbedPane.getSelectedComponent()); } } }); menu.add(deleteElementItem); JMenuItem renameElementItem = new JMenuItem("Rename element"); renameElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = tabbedPane.getSelectedIndex(); String locator$ = getRenameElementLocator(tabbedPane.getTitleAt(i)); JConsoleHandler.execute(console, locator$); } }); menu.add(renameElementItem); menu.addSeparator(); if (hasEditingCell()) { editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getEditCellLocator(); if (locator$ != null) JConsoleHandler.execute(console, locator$); } }); menu.add(editCellItem); } return menu; }
From source file:edu.harvard.mcz.imagecapture.jobs.JobRepeatOCR.java
private List<File> getFileList() { String pathToCheck = ""; if (scan != SCAN_ALL) { // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;/* w w w.jav a2s . co m*/ // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } //TODO: Filechooser to pick path, then save (if SCAN_ALL) imagebase property. //Perhaps. Might be undesirable behavior. //Probably better to warn that imagebase is null; } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { // run in separate thread and allow cancellation and status reporting // walk through directory tree if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); } } } } // Retrieve a list of all specimens in state OCR SpecimenLifeCycle sls = new SpecimenLifeCycle(); Specimen pattern = new Specimen(); pattern.setWorkFlowStatus(WorkFlowStatus.STAGE_0); List<Specimen> specimens = sls.findByExample(pattern); ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < specimens.size(); i++) { Specimen s = specimens.get(i); Set<ICImage> images = s.getICImages(); Iterator<ICImage> iter = images.iterator(); while (iter.hasNext() && runStatus != RunStatus.STATUS_TERMINATED) { ICImage image = (ICImage) iter.next(); if (scan == SCAN_ALL || image.getPath().startsWith(pathToCheck)) { // Add image for specimen to list to check File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); files.add(imageFile); counter.incrementFilesSeen(); } } } String message = "Found " + files.size() + " Specimen records on which to repeat OCR."; log.debug(message); Singleton.getSingletonInstance().getMainFrame().setStatusMessage(message); return files; }