List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:net.sf.keystore_explorer.gui.actions.ExamineFileAction.java
private File chooseFile() { JFileChooser chooser = FileChooserFactory.getCertFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("ExamineFileAction.ExamineFile.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("ExamineFileAction.ExamineFile.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File openFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(openFile); return openFile; }//from ww w . j a va 2 s.co m return null; }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public File fileChooser(JTextField jtf, String ext, String openOrSave) { jfcFiles = new JFileChooser(jtf.getText()); if (!ext.equals("")) jfcFiles.addChoosableFileFilter(new MyFileFilter(ext)); jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int state;/* www . ja v a 2s . com*/ if (openOrSave.equals("open")) state = jfcFiles.showOpenDialog(null); else state = jfcFiles.showSaveDialog(null); if (state == JFileChooser.APPROVE_OPTION) { File file = checkFileExtension(ext); jtf.setText(file.getPath()); log.info("Opening: " + file.getName() + "."); return file; } else { log.info("Open command cancelled by user."); return null; } }
From source file:net.sf.profiler4j.console.Console.java
public void openProject() { if (client.isConnected()) { int ret = JOptionPane.showConfirmDialog(mainFrame, "Proceed and disconnect?", "Open Profiling Project", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; }//from www. ja va 2s. c o m } if (checkUnsavedChanges()) { return; } if (client.isConnected()) { disconnect(); if (client.isConnected()) { return; } } JFileChooser fc = new JFileChooser(lastDir); fc.addChoosableFileFilter(projectFilter); if (fc.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { File selFile = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document doc = null; try { doc = builder.build(selFile); } catch (JDOMException e) { error("XML Error", e); } catch (IOException e) { error("I/O Error", e); } if (doc != null) { Project p = new Project(); Element el = doc.getRootElement(); p.setHostname(el.getChildText("Host")); p.setPort(Integer.parseInt(el.getChildText("Port"))); Element rulesEl = el.getChild("Rules"); p.setAccess(Rule.AccessOption.valueOf(rulesEl.getAttributeValue("access"))); p.setBeanprops(Boolean.parseBoolean(rulesEl.getAttributeValue("beanProps"))); p.getRules().clear(); for (Iterator i = rulesEl.getChildren("Rule").iterator(); i.hasNext();) { Element r = (Element) i.next(); Rule rule = new Rule(r.getText(), Rule.Action.valueOf(r.getAttributeValue("action"))); p.getRules().add(rule); } // Backwards compatible way to read the export pattern // If it is not there, we leave the defaults as they are, // otherwise we set the saved setting. Element export = el.getChild(PROJECT_XML_ELEMENT__EXPORT_PATTERN); if (null != export) { String enabled = export.getAttributeValue(PROJECT_XML_ATTRIBUTE__ENABLED); p.setExportAutomaticallyEnabled(Boolean.valueOf(enabled)); p.setExportPattern(export.getAttributeValue(PROJECT_XML_ATTRIBUTE__PATTERN)); } p.setFile(selFile); p.clearChanged(); this.project = p; lastDir = selFile.getParentFile(); } } }
From source file:com.stam.batchmove.SelectionFrame.java
private void selectSourceDirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectSourceDirBtnActionPerformed fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Choose source directory"); int retVal = fileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { File selection = fileChooser.getSelectedFile(); String selectedFolder = selection.getAbsolutePath(); sourceDir.setText(selectedFolder); }//from w w w . j ava2s . co m }
From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java
private File loadFileChooser(javax.swing.filechooser.FileFilter ff, String saveName) { File result;//from www . j a v a 2 s. c o m JFileChooser fc = new JFileChooser(); //Create a file chooser fc.setMultiSelectionEnabled(false); if (ff != null) { fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(ff); } else { fc.setAcceptAllFileFilterUsed(true); } if (saveName == null) { fc.setDialogTitle(""); if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); } else { result = null; } } else { fc.setDialogTitle("Save As..."); fc.setSelectedFile(new File(saveName)); if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); } else { result = null; } } return result; }
From source file:edu.harvard.i2b2.adminTool.dataModel.PatientIDConversionFactory.java
private String getKey() { String path = null;/*from w w w .j a v a 2 s .c o m*/ String key = UserInfoBean.getInstance().getKey(); if (key == null) { if ((path = getNoteKeyDrive()) == null) { Object[] possibleValues = { "Type in the key", "Browse to find the file containing the key" }; String selectedValue = (String) JOptionPane.showInputDialog(null, "You have selected an item associated with a report\n" + "which contains protected health information.\n" + "You need a decryption key to perform this operation.\n" + "How would you like to enter the key?\n" + "(If the key is on a floppy disk, insert the disk then\n select " + "\"Browse to find the file containing the key\")", "Notes Viewer", JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]); if (selectedValue == null) { return "Not a valid key"; } if (selectedValue.equalsIgnoreCase("Type in the key")) { key = JOptionPane.showInputDialog(this, "Please input the decryption key"); if (key == null) { return "Not a valid key"; } } else { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.CANCEL_OPTION) { return "Not a valid key"; } File f = null; if (returnVal == JFileChooser.APPROVE_OPTION) { f = chooser.getSelectedFile(); System.out.println("Open this file: " + f.getAbsolutePath()); BufferedReader in = null; try { in = new BufferedReader(new FileReader(f.getAbsolutePath())); String line = null; while ((line = in.readLine()) != null) { if (line.length() > 0) { key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); } } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } } } else { System.out.println("Found key file: " + path); BufferedReader in = null; try { in = new BufferedReader(new FileReader(path)); String line = null; while ((line = in.readLine()) != null) { if (line.length() > 0) { key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); } } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } } if (key == null) { return null; } else { UserInfoBean.getInstance().setKey(key); } return key; }
From source file:forge.gui.ImportDialog.java
@SuppressWarnings("serial") public ImportDialog(final String forcedSrcDir, final Runnable onDialogClose) { this.forcedSrcDir = forcedSrcDir; _topPanel = new FPanel(new MigLayout("insets dialog, gap 0, center, wrap, fill")); _topPanel.setOpaque(false);/*from w w w . j ava 2 s . co m*/ _topPanel.setBackgroundTexture(FSkin.getIcon(FSkinProp.BG_TEXTURE)); isMigration = !StringUtils.isEmpty(forcedSrcDir); // header _topPanel.add(new FLabel.Builder().text((isMigration ? "Migrate" : "Import") + " profile data").fontSize(15) .build(), "center"); // add some help text if this is for the initial data migration if (isMigration) { final FPanel blurbPanel = new FPanel(new MigLayout("insets panel, gap 10, fill")); blurbPanel.setOpaque(false); final JPanel blurbPanelInterior = new JPanel( new MigLayout("insets dialog, gap 10, center, wrap, fill")); blurbPanelInterior.setOpaque(false); blurbPanelInterior.add(new FLabel.Builder().text("<html><b>What's this?</b></html>").build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder() .text("<html>Over the last several years, people have had to jump through a lot of hoops to" + " update to the most recent version. We hope to reduce this workload to a point where a new" + " user will find that it is fairly painless to update. In order to make this happen, Forge" + " has changed where it stores your data so that it is outside of the program installation directory." + " This way, when you upgrade, you will no longer need to import your data every time to get things" + " working. There are other benefits to having user data separate from program data, too, and it" + " lays the groundwork for some cool new features.</html>") .build(), "growx, w 50:50:"); blurbPanelInterior.add( new FLabel.Builder().text("<html><b>So where's my data going?</b></html>").build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder().text( "<html>Forge will now store your data in the same place as other applications on your system." + " Specifically, your personal data, like decks, quest progress, and program preferences will be" + " stored in <b>" + ForgeConstants.USER_DIR + "</b> and all downloaded content, such as card pictures," + " skins, and quest world prices will be under <b>" + ForgeConstants.CACHE_DIR + "</b>. If, for whatever" + " reason, you need to set different paths, cancel out of this dialog, exit Forge, and find the <b>" + ForgeConstants.PROFILE_TEMPLATE_FILE + "</b> file in the program installation directory. Copy or rename" + " it to <b>" + ForgeConstants.PROFILE_FILE + "</b> and edit the paths inside it. Then restart Forge and use" + " this dialog to move your data to the paths that you set. Keep in mind that if you install a future" + " version of Forge into a different directory, you'll need to copy this file over so Forge will know" + " where to find your data.</html>") .build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder().text( "<html><b>Remember, your data won't be available until you complete this step!</b></html>") .build(), "growx, w 50:50:"); final FScrollPane blurbScroller = new FScrollPane(blurbPanelInterior, true, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); blurbPanel.add(blurbScroller, "hmin 150, growy, growx, center, gap 0 0 5 5"); _topPanel.add(blurbPanel, "gap 10 10 20 0, growy, growx, w 50:50:"); } // import source widgets final JPanel importSourcePanel = new JPanel(new MigLayout("insets 0, gap 10")); importSourcePanel.setOpaque(false); importSourcePanel.add(new FLabel.Builder().text("Import from:").build()); _txfSrc = new FTextField.Builder().readonly().build(); importSourcePanel.add(_txfSrc, "pushx, growx"); _btnChooseDir = new FLabel.ButtonBuilder().text("Choose directory...").enabled(!isMigration).build(); final JFileChooser _fileChooser = new JFileChooser(); _fileChooser.setMultiSelectionEnabled(false); _fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); _btnChooseDir.setCommand(new UiCommand() { @Override public void run() { // bring up a file open dialog and, if the OK button is selected, apply the filename // to the import source text field if (JFileChooser.APPROVE_OPTION == _fileChooser.showOpenDialog(JOptionPane.getRootFrame())) { final File f = _fileChooser.getSelectedFile(); if (!f.canRead()) { FOptionPane.showErrorDialog("Cannot access selected directory (Permission denied)."); } else { _txfSrc.setText(f.getAbsolutePath()); } } } }); importSourcePanel.add(_btnChooseDir, "h pref+8!, w pref+12!"); // add change handler to the import source text field that starts up a // new analyzer. it also interacts with the current active analyzer, // if any, to make sure it cancels out before the new one is initiated _txfSrc.getDocument().addDocumentListener(new DocumentListener() { boolean _analyzerActive; // access synchronized on _onAnalyzerDone String prevText; private final Runnable _onAnalyzerDone = new Runnable() { @Override public synchronized void run() { _analyzerActive = false; notify(); } }; @Override public void removeUpdate(final DocumentEvent e) { } @Override public void changedUpdate(final DocumentEvent e) { } @Override public void insertUpdate(final DocumentEvent e) { // text field is read-only, so the only time this will get updated // is when _btnChooseDir does it final String text = _txfSrc.getText(); if (text.equals(prevText)) { // only restart the analyzer if the directory has changed return; } prevText = text; // cancel any active analyzer _cancel = true; if (!text.isEmpty()) { // ensure we don't get two instances of this function running at the same time _btnChooseDir.setEnabled(false); // re-disable the start button. it will be enabled if the previous analyzer has // already successfully finished _btnStart.setEnabled(false); // we have to wait in a background thread since we can't block in the GUI thread final SwingWorker<Void, Void> analyzerStarter = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { // wait for active analyzer (if any) to quit synchronized (_onAnalyzerDone) { while (_analyzerActive) { _onAnalyzerDone.wait(); } } return null; } // executes in gui event loop thread @Override protected void done() { _cancel = false; synchronized (_onAnalyzerDone) { // this will populate the panel with data selection widgets final _AnalyzerUpdater analyzer = new _AnalyzerUpdater(text, _onAnalyzerDone, isMigration); analyzer.run(); _analyzerActive = true; } if (!isMigration) { // only enable the directory choosing button if this is not a migration dialog // since in that case we're permanently locked to the starting directory _btnChooseDir.setEnabled(true); } } }; analyzerStarter.execute(); } } }); _topPanel.add(importSourcePanel, "gaptop 20, pushx, growx"); // prepare import selection panel (will be cleared and filled in later by an analyzer) _selectionPanel = new JPanel(); _selectionPanel.setOpaque(false); _topPanel.add(_selectionPanel, "growx, growy, gaptop 10"); // action button widgets final Runnable cleanup = new Runnable() { @Override public void run() { SOverlayUtils.hideOverlay(); } }; _btnStart = new FButton("Start import"); _btnStart.setEnabled(false); _btnCancel = new FButton("Cancel"); _btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { _cancel = true; cleanup.run(); if (null != onDialogClose) { onDialogClose.run(); } } }); final JPanel southPanel = new JPanel(new MigLayout("ax center")); southPanel.setOpaque(false); southPanel.add(_btnStart, "center, w pref+144!, h pref+12!"); southPanel.add(_btnCancel, "center, w pref+144!, h pref+12!, gap 72"); _topPanel.add(southPanel, "growx"); }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void savePositiveNegativeNT() throws IOException { JFileChooser chooser = new JFileChooser("Save as multiple nt files. Please choose a directory"); chooser.setCurrentDirectory(frame.defaultDirectory); if (geoFile != null) { chooser.setCurrentDirectory(geoFile); }/* w w w . j av a 2 s. co m*/ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int returnVal = chooser.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { frame.savePositiveNegativeNT(chooser.getSelectedFile()); } }
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;//from w ww .ja v a 2 s. 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; }
From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java
/** * Show a dialog to export//from w w w . j a va2s . c o m * a CSV-file that contains the * shown {@link TransactionSum}s * for each month, year or day. */ protected void showExportCSVDialog() { JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(true); fc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(final File aF) { return aF.isDirectory() || aF.getName().endsWith(".csv"); } @Override public String getDescription() { return "CSV-file"; } }); int dialogResult = fc.showSaveDialog(this); if (dialogResult != JFileChooser.APPROVE_OPTION) { return; } File file = fc.getSelectedFile(); if (file.exists()) { int confirmation = JOptionPane.showConfirmDialog(this, "File exists. Replace file?"); if (confirmation != JOptionPane.YES_OPTION) { showExportCSVDialog(); return; } } ExportGranularities gran = (ExportGranularities) myExportGranularityCombobox.getSelectedItem(); try { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); exportCSV(file, gran); } finally { setCursor(Cursor.getDefaultCursor()); } }