List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
From source file:verdandi.ui.ProjectViewerPanel.java
private void importProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get("import.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setDialogTitle(RB.getString("projectviewer.import.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;/*from w ww .j a v a 2 s . c o m*/ } File importFile = chooser.getSelectedFile(); prefs.put("import.dir", importFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } ObjectInputStream projectsIn = null; try { setCursor(CURSOR_WAIT); projectsIn = new ObjectInputStream(new FileInputStream(importFile)); Object o = projectsIn.readObject(); if (!(o instanceof Collection)) { LOG.error("The file does not contain a valid verdandi project list"); return; } Collection<?> importcoll = (Collection<?>) o; @SuppressWarnings("unchecked") List<CostUnit> projects = (List<CostUnit>) o; new ProjectImporter(projects).start(); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("No verdandi project list?", e); } catch (ClassNotFoundException e) { LOG.error("", e); } finally { setCursor(CURSOR_DEFAULT); if (projectsIn != null) { try { projectsIn.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } }
From source file:verdandi.ui.ProjectViewerPanel.java
private void exportProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File exportDir = new File(prefs.get("export.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(exportDir); chooser.setDialogTitle(RB.getString("projectviewer.export.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;//from ww w .jav a2s . c o m } int[] selectedProjects = projectTable.getSelectedRows(); if (selectedProjects.length == 0) { LOG.debug("NO row selected"); return; } List<CostUnit> projectsToExport = new ArrayList<CostUnit>(); for (int i = 0; i < selectedProjects.length; i++) { // int selModel = projectTable.getFilters().convertRowIndexToModel( // selectedProjects[i]); int selModel = selectedProjects[i]; CostUnit p = tableModel.getProject(selModel); LOG.debug("Adding project to export list: " + p); projectsToExport.add(p); } File exportFile = chooser.getSelectedFile(); LOG.debug("Exporting projects to " + exportFile.getAbsolutePath()); ObjectOutputStream listOut = null; try { listOut = new ObjectOutputStream(new FileOutputStream(exportFile)); listOut.writeObject(projectsToExport); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("", e); } finally { if (listOut != null) { try { listOut.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } prefs.put("export.dir", exportFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } }
From source file:view.CertificateManagementDialog.java
private void btnAddCertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddCertActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(null);/* ww w . j av a 2 s .c o m*/ File[] files = chooser.getSelectedFiles(); final ArrayList<Certificate> toAddList = new ArrayList<>(); for (File file : files) { try { CertificateFactory fact = CertificateFactory.getInstance("X.509"); FileInputStream is = new FileInputStream(file); Certificate cert = fact.generateCertificate(is); toAddList.add(cert); } catch (Exception ex) { } } if (!toAddList.isEmpty()) { String password = getUserInputPassword(); if (password == null) { return; } addCertsToKeystore(toAddList, password); refresh(keystore); } }
From source file:wqm.util.ProcessDataGUI.java
public static void main(String[] args) throws IOException, ParseException { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select data file."); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(true); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); fc.setDialogTitle("Select output location."); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setMultiSelectionEnabled(false); returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File outputDirectory = fc.getSelectedFile(); for (File inputFile : files) { ProcessData//from ww w . j a v a2s. c o m .main(new String[] { inputFile.getAbsolutePath(), outputDirectory.getAbsolutePath() }); } } } }
From source file:xtrememp.PlaylistManager.java
public void openPlaylistDialog() { JFileChooser fileChooser = new JFileChooser(Settings.getLastDir()); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.addChoosableFileFilter(playlistFileFilter); fileChooser.setMultiSelectionEnabled(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Settings.setLastDir(file.getPath()); clearPlaylist();/*from www.jav a 2s . com*/ loadPlaylist(file.getPath()); } }
From source file:xtrememp.PlaylistManager.java
public boolean savePlaylistDialog() { JFileChooser fileChooser = new JFileChooser(Settings.getLastDir()); M3uPlaylistFileFilter m3uFileFilter = new M3uPlaylistFileFilter(); XspfPlaylistFileFilter xspfFileFilter = new XspfPlaylistFileFilter(); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.addChoosableFileFilter(m3uFileFilter); fileChooser.addChoosableFileFilter(xspfFileFilter); fileChooser.setMultiSelectionEnabled(false); if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); FileFilter fileFilter = fileChooser.getFileFilter(); String fileName = file.getName().toLowerCase(); if (fileFilter == m3uFileFilter) { if (!fileName.endsWith(".m3u")) { fileName = fileName.concat(".m3u"); }//from ww w . java 2 s. co m try { return PlaylistIO.saveM3U(playlist, file.getParent() + File.separator + fileName); } catch (PlaylistException ex) { logger.error("Can't save playlist in M3U format", ex); } } if (fileFilter == xspfFileFilter) { if (!fileName.endsWith(".xspf")) { fileName = fileName.concat(".xspf"); } try { return PlaylistIO.saveXSPF(playlist, file.getParent() + File.separator + fileName); } catch (PlaylistException ex) { logger.error("Can't save playlist in XSPF format", ex); } } Settings.setLastDir(file.getParent()); } return false; }
From source file:xtrememp.PlaylistManager.java
public void addFilesDialog(boolean playFirst) { JFileChooser fileChooser = new JFileChooser(Settings.getLastDir()); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.addChoosableFileFilter(audioFileFilter); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(true); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = fileChooser.getSelectedFiles(); Settings.setLastDir(selectedFiles[0].getParent()); addFiles(Arrays.asList(selectedFiles), playFirst); }/* w ww . j a v a2 s . com*/ }
From source file:zsk.JFCMainClient.java
/** * process events of ActionListener// ww w . j a v a 2s. c o m * */ public void actionPerformed(final ActionEvent e) { if (e.getSource().equals(frame.textinputfield)) { if (!e.getActionCommand().equals("")) { if (e.getActionCommand().matches(szYTREGEX)) addYTURLToList(e.getActionCommand()); else { addTextToConsole(e.getActionCommand()); cli(e.getActionCommand().toLowerCase()); } } synchronized (frame.textinputfield) { frame.textinputfield.setText(""); } return; } // let the user choose another dir if (e.getSource().equals(frame.directorybutton)) { debugoutput("frame.directorybutton"); JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); synchronized (frame.directorytextfield) { // we have to set current directory here because it gets lost when fc is lost fc.setCurrentDirectory(new File(frame.directorytextfield.getText())); } debugoutput("current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { return; } String snewdirectory = fc.getSelectedFile().getAbsolutePath(); // append file.seperator if last character is not file.seperator (the user choosed a directory other than root) snewdirectory.concat(snewdirectory.endsWith(System.getProperty("file.separator")) ? "" : System.getProperty("file.separator")); File ftest = new File(snewdirectory); if (ftest.exists()) { if (ftest.isDirectory()) { synchronized (frame.directorytextfield) { frame.directorytextfield.setText(snewdirectory); } config.setProperty("savefolder", snewdirectory); debugoutput("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); output("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); } else { output("not a directory: ".concat(snewdirectory)); } } else { output("directory does not exist: ".concat(snewdirectory)); } return; } // let the user choose another download resolution if (e.getActionCommand().equals(JFCMainClient.frame.hdbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.stdbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.ldbutton.getActionCommand())) { debugoutput("trying: ".concat(e.getActionCommand())); output("trying: ".concat(e.getActionCommand().toUpperCase())); return; } // let the user choose another video format if (e.getActionCommand().equals(JFCMainClient.frame.mpgbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.flvbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.webmbutton.getActionCommand())) { debugoutput("trying: ".concat(e.getActionCommand())); output("trying: ".concat(e.getActionCommand().toUpperCase() .concat(" ".concat(isgerman() ? "(Dateien werden immer nach MIME-Typ benannt!)" : "(files will always be named according to MIME type!)")))); return; } if (e.getActionCommand().equals("quit")) { addTextToConsole(isgerman() ? "Programmende ausgewhlt - beende DownloadThreads, Vorgang kann eine Weile dauern!" : "quit requested - signaling donwload threads to terminate, this may take a while!"); // seems to have to effect: //JFCMainClient.frame.repaint(); JFCMainClient.shutdownAppl(); return; } debugoutput("unknown action. ".concat(e.getSource().toString())); output("unbekannte Aktion"); }