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:cs.cirg.cida.CIDAView.java
@Action public void loadExperiment() { JFileChooser chooser = new JFileChooser(experimentController.getDataDirectory()); FileNameExtensionFilter filter = new FileNameExtensionFilter(CIDAConstants.DIALOG_TXT_CSV_MSG, "txt", "csv"); chooser.setFileFilter(filter);//from www. j a v a 2s .c o m chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this.getComponent()); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File[] files = chooser.getSelectedFiles(); String[] experimentNames = null; experimentNames = new String[files.length]; for (int i = 0; i < files.length; ++i) { File dataFile = files[i]; String tmpName = dataFile.getName().substring(0, dataFile.getName().lastIndexOf(".")); if (editResultsNameCheckBox.isSelected()) { CIDAInputDialog dialog = new CIDAInputDialog(this.getFrame(), CIDAConstants.RENAME_EXPERIMENT_MSG, tmpName); dialog.displayPrompt(); tmpName = dialog.getInput(); } experimentNames[i] = tmpName; } experimentController.addExperiments(files, experimentNames); this.selectExperiment(); } catch (CIlibIOException ex) { CIDAPromptDialog dialog = exceptionController.handleException(this.getFrame(), ex, CIDAConstants.EXCEPTION_OCCURRED); dialog.displayPrompt(); } } }
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 {//from w w w. j a v a2s. c om 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);// w ww . j a v a 2s . c o m 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:filterviewplugin.FilterViewSettingsTab.java
private void chooseIcon(final String filterName) { String iconPath = mIcons.get(filterName); JFileChooser chooser = new JFileChooser( iconPath == null ? new File("") : (new File(iconPath)).getParentFile()); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); String msg = mLocalizer.msg("iconFiles", "Icon Files ({0})", "*.png,*.jpg, *.gif"); String[] extArr = { ".png", ".jpg", ".gif" }; chooser.setFileFilter(new ExtensionFileFilter(extArr, msg)); chooser.setDialogTitle(mLocalizer.msg("chooseIcon", "Choose icon for '{0}'", filterName)); Window w = UiUtilities.getLastModalChildOf(FilterViewPlugin.getInstance().getSuperFrame()); if (chooser.showDialog(w, Localizer.getLocalization(Localizer.I18N_SELECT)) == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File dir = new File(FilterViewSettings.getIconDirectoryName()); if (!dir.isDirectory()) { dir.mkdir();/*www .j a va 2s . c o m*/ } String ext = chooser.getSelectedFile().getName(); ext = ext.substring(ext.lastIndexOf('.')); Icon icon = FilterViewPlugin.getInstance().getIcon(chooser.getSelectedFile().getAbsolutePath()); if (icon.getIconWidth() > MAX_ICON_WIDTH || icon.getIconHeight() > MAX_ICON_HEIGHT) { JOptionPane.showMessageDialog(w, mLocalizer.msg("iconSize", "The icon size must be at most {0}x{1}.", MAX_ICON_WIDTH, MAX_ICON_HEIGHT)); return; } try { IOUtilities.copy(chooser.getSelectedFile(), new File(dir, filterName + ext)); } catch (IOException e1) { e1.printStackTrace(); } mIcons.put(filterName, filterName + ext); mFilterList.updateUI(); } } }
From source file:it.unibas.spicygui.controllo.mapping.ActionGenerateAndTranslate.java
private void checkForPKConstraints(MappingTask mappingTask, HashSet<String> pkTableNames, int scenarioNo) throws DAOException { if (!pkTableNames.isEmpty()) { NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation( NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_TABLES), DialogDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(notifyDescriptor); if (notifyDescriptor.getValue().equals(NotifyDescriptor.YES_OPTION)) { String[] format = { NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_CSV), NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_JSON) }; int formatResponse = JOptionPane.showOptionDialog(null, NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_OUTPUT), NbBundle.getMessage(Costanti.class, Costanti.PK_OUTPUT_TITLE), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, format, format[0]); if (formatResponse != JOptionPane.CLOSED_OPTION) { JFileChooser chooser = vista.getFileChooserSalvaFolder(); File file;/*from www . j a v a 2 s .co m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT)); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (formatResponse == 0) { DAOCsv daoCsv = new DAOCsv(); daoCsv.exportPKConstraintCSVinstances(mappingTask, pkTableNames, file.getAbsolutePath(), scenarioNo); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); } else if (formatResponse == 1) { DAOJson daoJson = new DAOJson(); daoJson.exportPKConstraintJsoninstances(mappingTask, pkTableNames, file.getAbsolutePath(), scenarioNo); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); } } } } } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Prompts for a file using the file chooser dialog * //from ww w . jav a 2 s . c o m * @param fileExtensions * Accepted file extensions - must be null if filePrefixes is * non-null * @param filePrefixes * Accepted file prefixes - must be null if fileExtensions is * non-null * @param description * Description of the acceptable files * @param createFileIfNonExistant * if true, the file will be created if it does not exist. Also, * the system's "save" will be used instead of the "open" dialog. * @param startBrowseDirectory * The directory that the file chooser should start in * @param parent * parent component for the file chooser * @return the selected file, or null if no file was selected. * @throws IOException */ public static File promptForFile(List<String> fileExtensions, List<String> filePrefixes, final String description, boolean createFileIfNonExistant, File startBrowseDirectory, Component parent) throws IOException { if (fileExtensions != null && filePrefixes != null) { throw new IllegalArgumentException( "Only one of the file extensions or file prefixes should be non-null"); } JFileChooser chooser = new JFileChooser(startBrowseDirectory); FileFilter filter; if (fileExtensions != null) { String[] extensionsArray = new String[fileExtensions.size()]; fileExtensions.toArray(extensionsArray); filter = new FileNameExtensionFilter(description, extensionsArray); } else { final String[] prefixesArray = new String[filePrefixes.size()]; filePrefixes.toArray(prefixesArray); filter = new FileFilter() { @Override public String getDescription() { return description; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } else { return StringUtils.startsWithAny(f.getName(), prefixesArray); } } }; } chooser.setFileFilter(filter); int returnVal; if (createFileIfNonExistant) { returnVal = chooser.showSaveDialog(parent); } else { returnVal = chooser.showOpenDialog(parent); } if (returnVal == JFileChooser.APPROVE_OPTION) { if (createFileIfNonExistant) { File file = chooser.getSelectedFile(); if (!file.exists()) { // if only one file extension was supplied and the filename // does // not end with this extension, add it before // creating the file if (fileExtensions.size() == 1) { String extension = fileExtensions.get(0); String filePath = chooser.getSelectedFile().getAbsolutePath(); if (!filePath.endsWith(extension)) { file = new File(filePath + "." + extension); } } file.createNewFile(); } return file; } else { return chooser.getSelectedFile(); } } else { return null; } }
From source file:firmadigital.Firma.java
private void cmdExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarActionPerformed JFileChooser fileChooser = new JFileChooser(); txtUbicacion.setText(""); lblNombreArchivo.setText(""); lblRutaArchivo.setText(""); String signFileName = txtUbicacion.getText(); File directory = new File(signFileName).getParentFile(); fileChooser.setCurrentDirectory(directory); FileNameExtensionFilter filter; filter = new FileNameExtensionFilter("XML file", "xml"); fileChooser.setFileFilter(filter);// ww w . ja v a 2 s.c o m fileChooser.setFileHidingEnabled(true); /*Remove All File option*/ fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacion.setText(selectedFile); lblNombreArchivo.setText(fileChooser.getSelectedFile().getName()); lblRutaArchivo.setText(fileChooser.getSelectedFile().getParent()); } }
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;// ww w . j a 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."); } } // 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:com.jtk.pengelolaanujian.view.dosenpengampu.UploadNilai.java
private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { url = fileChooser.getSelectedFile().getAbsolutePath(); textUrl.setText(url);//from w w w .j a v a2 s.co m } }