List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:org.pmedv.jake.commands.OpenPlayerViewCommand.java
@Override public void execute() { final ApplicationContext ctx = AppContext.getApplicationContext(); final ApplicationWindow win = (ApplicationWindow) ctx.getBean(BeanDirectory.WINDOW_APPLICATION); /**// www . ja v a2 s. co m * Get last selected folder to simplify file browsing */ if (AppContext.getLastSelectedFolder() == null) AppContext.setLastSelectedFolder(System.getProperty("user.home")); JFileChooser fc = new JFileChooser(AppContext.getLastSelectedFolder()); fc.setDialogTitle("Open directory"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(win); if (result == JFileChooser.CANCEL_OPTION) return; AppContext.setLastSelectedFolder(fc.getSelectedFile().getAbsolutePath()); List<File> files = new ArrayList<File>(); FileUtils.findFile(files, fc.getSelectedFile(), ".mp3", true, true); final PlayerController controller = new PlayerController(files); JakeUtil.updateRecentFiles(fc.getSelectedFile().getAbsolutePath()); View view = new View(fc.getSelectedFile().getAbsolutePath(), null, controller.getPlayerView()); view.addListener(new DockingWindowAdapter() { @Override public void windowClosing(DockingWindow arg0) throws OperationAbortedException { if (controller.getPlayer() != null) controller.getPlayer().close(); controller.getPlayFileCommand().setPlaying(false); } }); openEditor(view); }
From source file:net.rptools.maptool.client.macro.impl.SaveAliasesMacro.java
public void execute(MacroContext context, String macro, MapToolMacroContext executionContext) { File aliasFile = null;/*from w ww . ja v a 2s.co m*/ if (macro.length() > 0) { aliasFile = new File(macro); } else { JFileChooser chooser = MapTool.getFrame().getSaveFileChooser(); chooser.setDialogTitle("savealiases.dialogTitle"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(MapTool.getFrame()) != JFileChooser.APPROVE_OPTION) { return; } aliasFile = chooser.getSelectedFile(); } if (aliasFile.getName().indexOf(".") < 0) { aliasFile = new File(aliasFile.getAbsolutePath() + ".alias"); } if (aliasFile.exists() && !MapTool.confirm(I18N.getText("msg.confirm.fileExists"))) { return; } try { StringBuilder builder = new StringBuilder(); builder.append("# ").append(I18N.getText("savealiases.created")).append(" ") .append(new SimpleDateFormat().format(new Date())).append("\n\n"); Map<String, String> aliasMap = MacroManager.getAliasMap(); List<String> aliasList = new ArrayList<String>(); aliasList.addAll(aliasMap.keySet()); Collections.sort(aliasList); for (String key : aliasList) { String value = aliasMap.get(key); builder.append(key).append(":").append(value).append("\n"); // LATER: this character should be externalized and shared with the load alias macro } FileUtils.writeByteArrayToFile(aliasFile, builder.toString().getBytes("UTF-8")); MapTool.addLocalMessage(I18N.getText("aliases.saved")); } catch (FileNotFoundException fnfe) { MapTool.addLocalMessage( I18N.getText("savealiases.couldNotSave", I18N.getText("msg.error.fileNotFound"))); } catch (IOException ioe) { MapTool.addLocalMessage(I18N.getText("savealiases.couldNotSave", ioe)); } }
From source file:avoking.com.documentos.scheduler.startup.Main.java
public String getPathDocs(JFileChooser fc) { fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int opc = fc.showOpenDialog(null); if (opc == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f != null) { if (f.isDirectory()) return f.getAbsolutePath(); else/*from w w w .ja v a 2s.co m*/ return f.getParentFile().getAbsolutePath(); } else { // JOptionPane.showMessageDialog(null, "Selecciona una ruta valida!!", "Directorio incorrecto", JOptionPane.WARNING_MESSAGE); return ""; } } else return ""; }
From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }//from w w w . j a v a2 s .c om } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java
private String choosePath(String pfad) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pfad)); chooser.setDialogTitle("DB Pfad"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null : chooser.getSelectedFile().getPath() + File.separator; }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a file (path)./*from w w w . j a v a2s . co m*/ * * @param lang * language * @return chosen file path */ public String selectFile(NatLang lang) { JFileChooser fileChooser = new JFileChooser(lastFilePath); fileChooser.setLocale(lang.getLocale()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setToolTipText(lang.getText("selectFile")); fileChooser.setDialogTitle(lang.getText("selectFile")); fileChooser.showDialog(null, lang.getText("selectFile")); File f = fileChooser.getSelectedFile(); if (f != null) { lastFilePath = f.getPath(); return lastFilePath; } else { return null; } }
From source file:view.MainFrame.java
private void menuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemOpenActionPerformed // TODO add your handling code here: JFileChooser filech = new JFileChooser(); filech.setFileSelectionMode(JFileChooser.FILES_ONLY); filech.setFileFilter(new FileNameExtensionFilter("WAV Files", "wav")); int ret = filech.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { try {//from w w w .java2 s . c o m wavFile = WavFile.openWavFile(filech.getSelectedFile()); textArea.append(wavFile.getInfoString()); samples = new double[wavFile.getNumChannels() * (int) wavFile.getSampleRate()]; int nFrames = wavFile.readFrames(samples, (int) wavFile.getSampleRate()); textArea.append(nFrames + " frames lidos.\n"); double valuesX[] = new double[samples.length]; for (int i = 0; i < samples.length; i++) { valuesX[i] = i; } showChart(wavFile.getNumChannels() * (int) wavFile.getSampleRate(), samples, valuesX, "Amostra", "Amplitude", "Amplitude das Amostras do ?udio", "Audio"); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (WavFileException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a directory (path)./*from w w w .j a v a 2 s . c o m*/ * * @param lang * language * @return chosen directory path */ public String selectDirectory(NatLang lang) { JFileChooser dirChooser = new JFileChooser(lastDirectoryPath); dirChooser.setLocale(lang.getLocale()); dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setToolTipText(lang.getText("selectDirectory")); dirChooser.setDialogTitle(lang.getText("selectDirectory")); dirChooser.showDialog(null, lang.getText("selectDirectory")); File f = dirChooser.getSelectedFile(); if (f != null) { lastDirectoryPath = f.getPath(); return lastDirectoryPath; } else { return null; } }
From source file:org.jax.maanova.plot.SaveChartAction.java
/** * {@inheritDoc}/*from w w w. j a va 2 s .c o m*/ */ public void actionPerformed(ActionEvent e) { JFreeChart myChart = this.chart; Dimension mySize = this.size; if (myChart == null || mySize == null) { LOG.severe("Failed to save graph image because of a null value"); MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(), "Internal error: Failed to save graph image.", "Image Save Failed"); } else { // use the remembered starting dir MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager .getInstance(); JMaanovaApplicationState applicationState = configurationManager.getApplicationState(); FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory(); File rememberedImageDir = null; if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) { rememberedImageDir = new File(rememberedJaxbImageDir.getFileName()); } // select the image file to save JFileChooser fileChooser = new JFileChooser(rememberedImageDir); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setApproveButtonText("Save Graph"); fileChooser.setDialogTitle("Save Graph as Image"); fileChooser.setMultiSelectionEnabled(false); fileChooser.addChoosableFileFilter(PngFileFilter.getInstance()); fileChooser.setFileFilter(PngFileFilter.getInstance()); int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame()); if (response == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); // tack on the extension if there isn't one // already if (!PngFileFilter.getInstance().accept(selectedFile)) { String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION; selectedFile = new File(selectedFile.getParentFile(), newFileName); } if (selectedFile.exists()) { // ask the user if they're sure they want to overwrite String message = "Exporting the graph image to " + selectedFile.getAbsolutePath() + " will overwrite an " + " existing file. Would you like to continue anyway?"; if (LOG.isLoggable(Level.FINE)) { LOG.fine(message); } boolean overwriteOk = MessageDialogUtilities .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile); if (!overwriteOk) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("overwrite canceled"); } return; } } try { ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height); File parentDir = selectedFile.getParentFile(); if (parentDir != null) { // update the "recent image directory" ObjectFactory objectFactory = new ObjectFactory(); FileType latestJaxbImageDir = objectFactory.createFileType(); latestJaxbImageDir.setFileName(parentDir.getAbsolutePath()); applicationState.setRecentImageExportDirectory(latestJaxbImageDir); } } catch (Exception ex) { LOG.log(Level.SEVERE, "failed to save graph image", ex); } } } }
From source file:CompareFiles.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); // folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);/*from w w w . ja v a 2s . com*/ int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); jLabel2.setText(myfolder.toString()); } }