List of usage examples for javax.swing JFileChooser CANCEL_OPTION
int CANCEL_OPTION
To view the source code for javax.swing JFileChooser CANCEL_OPTION.
Click Source Link
From source file:edu.ku.brc.specify.Specify.java
/** * //from w ww.j a va 2 s . c o m */ protected void exportPrefs() { AppPreferences remotePrefs = AppPreferences.getRemote(); Properties props = remotePrefs.getProperties(); try { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); String title = getResourceString("Specify.SELECT_FILE_OR_DIR");//$NON-NLS-1$ if (chooser.showDialog(null, title) != JFileChooser.CANCEL_OPTION) { File destFile = chooser.getSelectedFile(); props.store(new FileOutputStream(destFile), "User Prefs"); //$NON-NLS-1$ } else { throw new NoSuchElementException("The External File Repository needs a valid directory."); //$NON-NLS-1$ } } catch (Exception ex) { log.error(ex); // XXX Error Dialog } }
From source file:com.hexidec.ekit.EkitCore.java
/** * Method for obtaining a File for input/output using a JFileChooser dialog *//* ww w.ja v a2s. c o m*/ private File getFileFromChooser(String startDir, int dialogType, String[] exts, String desc) { JFileChooser jfileDialog = new JFileChooser(startDir); jfileDialog.setDialogType(dialogType); jfileDialog.setFileFilter(new MutableFilter(exts, desc)); int optionSelected = JFileChooser.CANCEL_OPTION; if (dialogType == JFileChooser.OPEN_DIALOG) { optionSelected = jfileDialog.showOpenDialog(this); } else if (dialogType == JFileChooser.SAVE_DIALOG) { optionSelected = jfileDialog.showSaveDialog(this); } else // default to an OPEN_DIALOG { optionSelected = jfileDialog.showOpenDialog(this); } if (optionSelected == JFileChooser.APPROVE_OPTION) { return jfileDialog.getSelectedFile(); } return (File) null; }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter);// w w w. j a va 2 s . c o m chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); } return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }
From source file:org.andrewberman.sync.PDFDownloader.java
static File chooseDirectory() throws Exception { JFileChooser fc = new JFileChooser(); // fc.setDialogTitle("Choose Output Directory"); // Start in current directory fc.setCurrentDirectory(new File(".")); // Choose only directories only. fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Open chooser dialog int result = fc.showSaveDialog(new JFrame()); if (result == JFileChooser.CANCEL_OPTION) { out.println("Directory choice was canceled. Exiting..."); // System.exit(1); throw new Exception(); }/*from w ww . java2 s. c om*/ File f = fc.getSelectedFile(); out.println("Chosen directory:" + f); return f; }
From source file:org.cds06.speleograph.actions.OpenAction.java
/** * Invoked when an action occurs.//from w w w. j a v a 2s . c o m */ @Override public void actionPerformed(ActionEvent e) { chooser.setCurrentDirectory(SpeleoGraphApp.getWorkingDirectory()); File file = null; if (SpeleoGraphApp.isMac()) { do { if (file != null && !fileFilter.accept(file)) { JOptionPane.showMessageDialog(SpeleoGraphApp.getInstance(), I18nSupport.translate("actions.open.formaterror"), I18nSupport.translate("error"), JOptionPane.ERROR_MESSAGE); } FileDialog chooserMac = new FileDialog(SpeleoGraphApp.getInstance()); chooserMac.setDirectory(SpeleoGraphApp.getWorkingDirectory().getAbsolutePath()); chooserMac.setVisible(true); if (chooserMac.getFile() == null) return; file = FileUtils.getFile(chooserMac.getDirectory(), chooserMac.getFile()); if (file.isDirectory()) return; } while (!fileFilter.accept(file)); } else { int result = chooser.showOpenDialog(parent); switch (result) { case JFileChooser.APPROVE_OPTION: file = chooser.getSelectedFile(); if (file.isDirectory()) return; break; case JFileChooser.CANCEL_OPTION: default: SpeleoGraphApp.setWorkingDirectory(chooser.getCurrentDirectory()); return; } } try { SpeleoGraphApp.setWorkingDirectory(file.getParentFile()); reader.readFile(file); } catch (FileReadingError e1) { log.error("Error when try to read a SpeleoGraph File", e1); } }
From source file:org.cds06.speleograph.actions.SaveAction.java
/** * Invoked when an action occurs./*w w w . jav a 2 s . co m*/ */ @Override public void actionPerformed(ActionEvent e) { chooser.setCurrentDirectory(SpeleoGraphApp.getWorkingDirectory()); int result = chooser.showSaveDialog(parent); File file; switch (result) { case JFileChooser.APPROVE_OPTION: file = chooser.getSelectedFile(); if (file.isDirectory()) return; break; case JFileChooser.CANCEL_OPTION: default: SpeleoGraphApp.setWorkingDirectory(chooser.getCurrentDirectory()); return; } try { SpeleoGraphApp.setWorkingDirectory(file.getParentFile()); writer.save(file); } catch (IOException e1) { //log.error("Error when try to read a SpeleoGraph File", e1); } }
From source file:org.colombbus.tangara.net.FileReceptionDialog.java
private void setTargetFile() { File targetDir = Configuration.instance().getUserHome(); JFileChooser chooserDlg = new JFileChooser(targetDir); String filterMsg = Messages.getString("FileReceptionDialog.filter.allFiles"); SimpleFileFilter filter = new SimpleFileFilter(filterMsg); chooserDlg.setFileFilter(filter);/*w w w . j a va 2 s . c o m*/ File originalSelFile = new File(targetDir, sourceFilename); File curSelFile = originalSelFile; boolean showDialog = true; while (showDialog) { chooserDlg.setSelectedFile(curSelFile); int userAction = chooserDlg.showSaveDialog(owner); curSelFile = chooserDlg.getSelectedFile(); switch (userAction) { case JFileChooser.CANCEL_OPTION: showDialog = false; break; case JFileChooser.APPROVE_OPTION: if (curSelFile.exists()) { String title = Messages.getString("FileReceptionDialog.overwrite.title"); String msgPattern = Messages.getString("FileReceptionDialog.overwrite.message"); String overwriteMsg = MessageFormat.format(msgPattern, curSelFile.getName()); Object[] options = { Messages.getString("FileReceptionDialog.yes"), Messages.getString("FileReceptionDialog.no") }; int userChoice = JOptionPane.showOptionDialog(owner, overwriteMsg, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a // custom Icon options, // the titles of buttons options[0]); if (userChoice == JOptionPane.OK_OPTION) { if (saveFileAs(curSelFile)) { showDialog = false; } } } else if (saveFileAs(curSelFile)) { showDialog = false; } break; case JFileChooser.ERROR_OPTION: LOG.error("Error in file chooser dialog"); // TODO what to do in case of error ? Retry ? showDialog = false; break; } } }
From source file:org.executequery.components.FileChooserDialog.java
private void resetLastOpenFilePath(int result) { if (result != JFileChooser.CANCEL_OPTION) { File file = getSelectedFile(); String lastOpenFilePath = file.getPath(); if (file.isFile() || !file.exists()) { lastOpenFilePath = file.getParent(); }/*from w ww. j a va2 s. co m*/ SystemProperties.setStringProperty("user", LAST_OPEN_FILE_PATH, lastOpenFilePath); } }
From source file:org.executequery.gui.drivers.AbstractDriverPanel.java
public void browseDrivers(ActionEvent e) { if (databaseDriver.isDefaultSunOdbc()) { return;//www . j a v a2s. c om } FileSelector jarFiles = new FileSelector(new String[] { "jar" }, getString("AbstractDriverPanel.javaArchiveFiles")); FileSelector zipFiles = new FileSelector(new String[] { "zip" }, getString("AbstractDriverPanel.zipArchiveFiles")); final FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(zipFiles); fileChooser.addChoosableFileFilter(jarFiles); fileChooser.setDialogTitle(getString("AbstractDriverPanel.selectJdbcDrivers")); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(true); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), getString("AbstractDriverPanel.select")); if (result == JFileChooser.CANCEL_OPTION) { return; } ThreadUtils.startWorker(new Runnable() { public void run() { try { GUIUtilities.showWaitCursor(); File[] files = fileChooser.getSelectedFiles(); for (int i = 0; i < files.length; i++) { String path = files[i].getAbsolutePath(); if (!jarPathListModel.contains(path)) { jarPathListModel.addElement(path); } } databaseDriver.setPath(jarPathsFormatted()); populateDriverClassCombo(); } finally { GUIUtilities.showNormalCursor(); } } }); }
From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java
public void save() { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fileChooser.showSaveDialog((JDialog) parent); if (result == JFileChooser.CANCEL_OPTION) { return;/* w w w. j ava2 s. c om*/ } if (fileChooser.getSelectedFile() != null) { try { GUIUtilities.showWaitCursor(); new ByteArrayFileWriter().write(fileChooser.getSelectedFile(), recordDataItemByteArray()); } catch (IOException e) { if (Log.isDebugEnabled()) { Log.debug("Error writing LOB to file", e); } GUIUtilities.displayErrorMessage("Error writing LOB data to file:\n" + e.getMessage()); return; } finally { GUIUtilities.showNormalCursor(); } } close(); }