List of usage examples for javax.swing JFileChooser getSelectedFiles
public File[] getSelectedFiles()
From source file:com.haulmont.cuba.desktop.gui.components.DesktopFileMultiUploadField.java
public DesktopFileMultiUploadField() { fileUploading = AppBeans.get(FileUploadingAPI.NAME); final JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); DesktopResources resources = App.getInstance().getResources(); Messages messages = AppBeans.get(Messages.NAME); String caption = messages.getMessage(getClass(), "upload.selectFiles"); impl = new JButton(); impl.setAction(new AbstractAction(caption, resources.getIcon(DEFAULT_ICON)) { @Override/* w w w. j a v a 2s . c om*/ public void actionPerformed(ActionEvent e) { if (fileChooser.showOpenDialog(impl) == JFileChooser.APPROVE_OPTION) { processFiles(fileChooser.getSelectedFiles()); } } }); DesktopComponentsHelper.adjustSize(impl); }
From source file:com.stanley.captioner.MainFrame.java
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed {//GEN-HEADEREND:event_addButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg"); fileChooser.setFileFilter(filter);/*from www. j a va2 s.com*/ if (lastAddDirectory != null) { fileChooser.setCurrentDirectory(lastAddDirectory); } int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastAddDirectory = fileChooser.getCurrentDirectory(); DefaultTableModel model = (DefaultTableModel) videoTable.getModel(); File files[] = fileChooser.getSelectedFiles(); for (File file : files) { boolean alreadyExists = false; for (int i = model.getRowCount() - 1; i >= 0; i--) { String path = (String) model.getValueAt(i, 0); if (file.getAbsolutePath().equals(path)) { alreadyExists = true; } } if (!alreadyExists) { model.addRow(getVideoInfo(file)); } } } }
From source file:it.staiger.jmeter.protocol.http.config.gui.DynamicFilePanel.java
/** * Fills the table with the file parameters from the import settings panel *///from ww w.j a v a2 s. c om private void importFiles() { String relPath = folder.getText(); String replace = relPath + File.separator; if (relPath.isEmpty()) { relPath = FileDialoger.getLastJFCDirectory(); replace = ""; } JFileChooser chooser = new JFileChooser(new File(relPath)); chooser.setMultiSelectionEnabled(true); chooser.setDialogTitle("select files");// $NON-NLS-1$ if (chooser.showOpenDialog(GuiPackage.getInstance().getMainFrame()) == JFileChooser.APPROVE_OPTION) { File[] files = chooser.getSelectedFiles(); for (File file : files) { String path = file.getAbsolutePath().replace(replace, ""); String name = file.getName(); int last = name.lastIndexOf("."); if (last != -1) name = name.substring(0, last); HTTPFileArg hFile = new HTTPFileArg(path, name, attachmentsCT.getText()); addFile(hFile); } FileDialoger.setLastJFCDirectory(files[0].getAbsolutePath()); } }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void fileOpen() { // todo keep working directory JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); FileServiceTool.addChoosableFileFilters(chooser); if (!(chooser.showOpenDialog(mainWindow) == JFileChooser.APPROVE_OPTION)) return;//from w w w .j a v a 2 s .com final File[] selected = chooser.getSelectedFiles(); final FileService service = FileServiceTool.lookupFileService(chooser); if (service == null) { JOptionPane.showMessageDialog(mainWindow, "Could not find service to open file."); return; } Runnable run = new Runnable() { public void run() { for (File file : selected) { service.open(file); } } }; SwingUtilities.invokeLater(WorkIndicator.create(getWindow(), run)); }
From source file:duthientan.mmanm.com.Main.java
private void BntOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BntOpenFileActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = fileChooser.getSelectedFiles(); JLFILEPATH.setText(selectedFiles.length + " files is selected"); JLMD5.setText("Caculating"); filePath = new ArrayList<>(); new Thread(new Runnable() { @Override// w ww . jav a 2s. c o m public void run() { try { String mD5 = ""; for (File f : selectedFiles) { filePath.add(f.getPath()); FileInputStream fis = new FileInputStream(f); mD5 += f.getName() + " : " + org.apache.commons.codec.digest.DigestUtils.md5Hex(fis) + "<br>"; fis.close(); } JLMD5.setText("<html>" + mD5 + "</html>"); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } }
From source file:ca.osmcanada.osvuploadr.JPMain.java
private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed try {// ww w .ja v a2s . com JFileChooser fc = new JFileChooser(); if (!last_dir.isEmpty()) { fc.setCurrentDirectory(new java.io.File(last_dir)); // start at application current directory } fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { if (fc.getSelectedFiles().length == 1) { int response = JOptionPane.showConfirmDialog(null, new String(r.getString("immediate_sub_folders").getBytes(), "UTF-8"), new String(r.getString("add_subfolders").getBytes(), "UTF-8"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { File folder = fc.getSelectedFile(); listDir.add(folder.getPath()); last_dir = folder.getPath(); } else if (response == JOptionPane.YES_OPTION) { //Get a list of subdirectories String[] subDirs = fc.getSelectedFile().list(new FilenameFilter() { @Override public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); for (String subDir : subDirs) { listDir.add(new File(fc.getSelectedFile() + "/" + subDir).getPath()); } } } else if (fc.getSelectedFiles().length > 1) { File[] folders = fc.getSelectedFiles(); for (File folder : folders) { listDir.add(folder.getPath()); last_dir = folder.getPath(); } } } } catch (UnsupportedEncodingException ex) { } }
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser fc = new JFileChooser(); int ff = fc.getChoosableFileFilters().length; FileFilter[] fft = fc.getChoosableFileFilters(); for (int i = 0; i < ff; i++) { fc.removeChoosableFileFilter(fft[i]); }//from ww w. ja v a2 s . com fc.addChoosableFileFilter(new DocumentFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setDialogTitle(prosa); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR); int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument")); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); uploadFiles(files, unit, viewComponentId, documentId); Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory(); } this.setCursor(Cursor.getDefaultCursor()); }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
private void importMarketLogs() { File inputDir = null;/*from w ww . j a v a 2 s . c om*/ if (appConfigProvider.getAppConfig().hasLastMarketLogImportDirectory()) { inputDir = appConfigProvider.getAppConfig().getLastMarketLogImportDirectory(); if (!inputDir.exists() || !inputDir.isDirectory()) { inputDir = null; } } final JFileChooser chooser = inputDir != null ? new JFileChooser(inputDir) : new JFileChooser(); chooser.setFileHidingEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(true); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File[] files = chooser.getSelectedFiles(); if (!ArrayUtils.isEmpty(files)) { appConfigProvider.getAppConfig().setLastMarketLogImportDirectory(files[0].getParentFile()); try { appConfigProvider.save(); } catch (IOException e) { log.error("importMarketLogs(): Failed to save configuration", e); } importMarketLogs(files); } } }
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
private Set getFiles() { JFileChooser chooser = new JFileChooser(DODDLEConstants.PROJECT_HOME); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int retval = chooser.showOpenDialog(DODDLE_OWL.rootPane); if (retval != JFileChooser.APPROVE_OPTION) { return null; }//from w w w. ja v a 2 s .c o m File[] files = chooser.getSelectedFiles(); Set fileSet = new TreeSet(); getFiles(files, fileSet); return fileSet; }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void loadFilesActionPerformed(ActionEvent evt) throws TrackProfilerException { JFileChooser chooser = null; if (this.folderWithTracks != null) { chooser = new JFileChooser(this.folderWithTracks); } else {//from w w w . j av a2s . c om chooser = new JFileChooser(); } TrackFileFilter filter = new TrackFileFilter(); filter.addExtension(PLT_EXTENSION); filter.addExtension(WPT_EXTENSION); filter.setDescription(new Message(Messages.PLT_AND_WPT_FILES).toString()); chooser.setFileFilter(filter); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = chooser.getSelectedFiles(); for (int i = 0; i < selectedFiles.length; i++) { File selectedFile = selectedFiles[i]; this.folderWithTracks = selectedFile.getParentFile(); if (selectedFile.getName().toLowerCase().endsWith("." + PLT_EXTENSION)) { //$NON-NLS-1$ try { loadTrack(selectedFile); } catch (FileNotFoundException e) { throw new TrackProfilerException( new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName()); } } } for (int i = 0; i < selectedFiles.length; i++) { File selectedFile = selectedFiles[i]; this.folderWithTracks = selectedFile.getParentFile(); if (selectedFile.getName().toLowerCase().endsWith("." + WPT_EXTENSION)) { //$NON-NLS-1$ try { loadWaypoints(selectedFile); } catch (FileNotFoundException e) { throw new TrackProfilerException( new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName()); } } } } }