List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
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; }/* w w w.j av a 2s.c o m*/ File[] files = chooser.getSelectedFiles(); Set fileSet = new TreeSet(); getFiles(files, fileSet); return fileSet; }
From source file:pi.bestdeal.gui.InterfacePrincipale.java
private void ButtonRapportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonRapportActionPerformed int idd = (int) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 0); String pattern = null;/*from ww w. j av a 2 s . c o m*/ String path; FileNameExtensionFilter filter = new FileNameExtensionFilter("JASPER files", "jasper"); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); chooser.setMultiSelectionEnabled(false); if (returnVal == JFileChooser.APPROVE_OPTION) { pattern = chooser.getSelectedFile().getPath(); } FileNameExtensionFilter filterpath = new FileNameExtensionFilter("PDF files", "pdf"); JFileChooser chooserpath = new JFileChooser(); chooserpath.setFileFilter(filterpath); int returnSave = chooserpath.showSaveDialog(this); if (returnSave == JFileChooser.APPROVE_OPTION) { path = chooserpath.getSelectedFile().getPath(); if (!path.contains("pdf")) { path = path + ".pdf"; String a = "\\"; } pattern = pattern.replace("\\", "\\" + "\\"); path = path.replace("\\", "\\" + "\\"); ReportCreator creator = new ReportCreator(); int a = creator.CreateReportDeal(pattern, idd, path); if (a == 1) { File file = new File(path.toString()); try { Desktop.getDesktop().open(file); } catch (IOException ex) { Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:com.floreantpos.ui.model.PizzaItemForm.java
private void doSelectImageFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow()); if (option == JFileChooser.APPROVE_OPTION) { File imageFile = fileChooser.getSelectedFile(); try {/*from w w w .j av a 2 s . c o m*/ byte[] itemImage = FileUtils.readFileToByteArray(imageFile); int imageSize = itemImage.length / 1024; if (imageSize > 20) { POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$ itemImage = null; return; } ImageIcon imageIcon = new ImageIcon( new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH)); lblImagePreview.setIcon(imageIcon); MenuItem menuItem = (MenuItem) getBean(); menuItem.setImageData(itemImage); } catch (IOException e) { PosLog.error(getClass(), e); } } }
From source file:forge.gui.ImportDialog.java
@SuppressWarnings("serial") public ImportDialog(final String forcedSrcDir, final Runnable onDialogClose) { this.forcedSrcDir = forcedSrcDir; _topPanel = new FPanel(new MigLayout("insets dialog, gap 0, center, wrap, fill")); _topPanel.setOpaque(false);/*from w w w . j a v a 2 s .co m*/ _topPanel.setBackgroundTexture(FSkin.getIcon(FSkinProp.BG_TEXTURE)); isMigration = !StringUtils.isEmpty(forcedSrcDir); // header _topPanel.add(new FLabel.Builder().text((isMigration ? "Migrate" : "Import") + " profile data").fontSize(15) .build(), "center"); // add some help text if this is for the initial data migration if (isMigration) { final FPanel blurbPanel = new FPanel(new MigLayout("insets panel, gap 10, fill")); blurbPanel.setOpaque(false); final JPanel blurbPanelInterior = new JPanel( new MigLayout("insets dialog, gap 10, center, wrap, fill")); blurbPanelInterior.setOpaque(false); blurbPanelInterior.add(new FLabel.Builder().text("<html><b>What's this?</b></html>").build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder() .text("<html>Over the last several years, people have had to jump through a lot of hoops to" + " update to the most recent version. We hope to reduce this workload to a point where a new" + " user will find that it is fairly painless to update. In order to make this happen, Forge" + " has changed where it stores your data so that it is outside of the program installation directory." + " This way, when you upgrade, you will no longer need to import your data every time to get things" + " working. There are other benefits to having user data separate from program data, too, and it" + " lays the groundwork for some cool new features.</html>") .build(), "growx, w 50:50:"); blurbPanelInterior.add( new FLabel.Builder().text("<html><b>So where's my data going?</b></html>").build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder().text( "<html>Forge will now store your data in the same place as other applications on your system." + " Specifically, your personal data, like decks, quest progress, and program preferences will be" + " stored in <b>" + ForgeConstants.USER_DIR + "</b> and all downloaded content, such as card pictures," + " skins, and quest world prices will be under <b>" + ForgeConstants.CACHE_DIR + "</b>. If, for whatever" + " reason, you need to set different paths, cancel out of this dialog, exit Forge, and find the <b>" + ForgeConstants.PROFILE_TEMPLATE_FILE + "</b> file in the program installation directory. Copy or rename" + " it to <b>" + ForgeConstants.PROFILE_FILE + "</b> and edit the paths inside it. Then restart Forge and use" + " this dialog to move your data to the paths that you set. Keep in mind that if you install a future" + " version of Forge into a different directory, you'll need to copy this file over so Forge will know" + " where to find your data.</html>") .build(), "growx, w 50:50:"); blurbPanelInterior.add(new FLabel.Builder().text( "<html><b>Remember, your data won't be available until you complete this step!</b></html>") .build(), "growx, w 50:50:"); final FScrollPane blurbScroller = new FScrollPane(blurbPanelInterior, true, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); blurbPanel.add(blurbScroller, "hmin 150, growy, growx, center, gap 0 0 5 5"); _topPanel.add(blurbPanel, "gap 10 10 20 0, growy, growx, w 50:50:"); } // import source widgets final JPanel importSourcePanel = new JPanel(new MigLayout("insets 0, gap 10")); importSourcePanel.setOpaque(false); importSourcePanel.add(new FLabel.Builder().text("Import from:").build()); _txfSrc = new FTextField.Builder().readonly().build(); importSourcePanel.add(_txfSrc, "pushx, growx"); _btnChooseDir = new FLabel.ButtonBuilder().text("Choose directory...").enabled(!isMigration).build(); final JFileChooser _fileChooser = new JFileChooser(); _fileChooser.setMultiSelectionEnabled(false); _fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); _btnChooseDir.setCommand(new UiCommand() { @Override public void run() { // bring up a file open dialog and, if the OK button is selected, apply the filename // to the import source text field if (JFileChooser.APPROVE_OPTION == _fileChooser.showOpenDialog(JOptionPane.getRootFrame())) { final File f = _fileChooser.getSelectedFile(); if (!f.canRead()) { FOptionPane.showErrorDialog("Cannot access selected directory (Permission denied)."); } else { _txfSrc.setText(f.getAbsolutePath()); } } } }); importSourcePanel.add(_btnChooseDir, "h pref+8!, w pref+12!"); // add change handler to the import source text field that starts up a // new analyzer. it also interacts with the current active analyzer, // if any, to make sure it cancels out before the new one is initiated _txfSrc.getDocument().addDocumentListener(new DocumentListener() { boolean _analyzerActive; // access synchronized on _onAnalyzerDone String prevText; private final Runnable _onAnalyzerDone = new Runnable() { @Override public synchronized void run() { _analyzerActive = false; notify(); } }; @Override public void removeUpdate(final DocumentEvent e) { } @Override public void changedUpdate(final DocumentEvent e) { } @Override public void insertUpdate(final DocumentEvent e) { // text field is read-only, so the only time this will get updated // is when _btnChooseDir does it final String text = _txfSrc.getText(); if (text.equals(prevText)) { // only restart the analyzer if the directory has changed return; } prevText = text; // cancel any active analyzer _cancel = true; if (!text.isEmpty()) { // ensure we don't get two instances of this function running at the same time _btnChooseDir.setEnabled(false); // re-disable the start button. it will be enabled if the previous analyzer has // already successfully finished _btnStart.setEnabled(false); // we have to wait in a background thread since we can't block in the GUI thread final SwingWorker<Void, Void> analyzerStarter = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { // wait for active analyzer (if any) to quit synchronized (_onAnalyzerDone) { while (_analyzerActive) { _onAnalyzerDone.wait(); } } return null; } // executes in gui event loop thread @Override protected void done() { _cancel = false; synchronized (_onAnalyzerDone) { // this will populate the panel with data selection widgets final _AnalyzerUpdater analyzer = new _AnalyzerUpdater(text, _onAnalyzerDone, isMigration); analyzer.run(); _analyzerActive = true; } if (!isMigration) { // only enable the directory choosing button if this is not a migration dialog // since in that case we're permanently locked to the starting directory _btnChooseDir.setEnabled(true); } } }; analyzerStarter.execute(); } } }); _topPanel.add(importSourcePanel, "gaptop 20, pushx, growx"); // prepare import selection panel (will be cleared and filled in later by an analyzer) _selectionPanel = new JPanel(); _selectionPanel.setOpaque(false); _topPanel.add(_selectionPanel, "growx, growy, gaptop 10"); // action button widgets final Runnable cleanup = new Runnable() { @Override public void run() { SOverlayUtils.hideOverlay(); } }; _btnStart = new FButton("Start import"); _btnStart.setEnabled(false); _btnCancel = new FButton("Cancel"); _btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { _cancel = true; cleanup.run(); if (null != onDialogClose) { onDialogClose.run(); } } }); final JPanel southPanel = new JPanel(new MigLayout("ax center")); southPanel.setOpaque(false); southPanel.add(_btnStart, "center, w pref+144!, h pref+12!"); southPanel.add(_btnCancel, "center, w pref+144!, h pref+12!, gap 72"); _topPanel.add(southPanel, "growx"); }
From source file:com.floreantpos.ui.model.MenuItemForm.java
protected void doSelectImageFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow()); if (option == JFileChooser.APPROVE_OPTION) { File imageFile = fileChooser.getSelectedFile(); try {//from w ww.j a v a 2s. c o m byte[] itemImage = FileUtils.readFileToByteArray(imageFile); int imageSize = itemImage.length / 1024; if (imageSize > 20) { POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$ itemImage = null; return; } ImageIcon imageIcon = new ImageIcon( new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH)); lblImagePreview.setIcon(imageIcon); MenuItem menuItem = (MenuItem) getBean(); menuItem.setImageData(itemImage); } catch (IOException e) { PosLog.error(getClass(), e); } } }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
private void importMarketLogs() { File inputDir = null;/*from w w w . ja va 2 s . com*/ 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:com.igormaznitsa.zxpoly.MainForm.java
private File chooseFileForSave(final String title, final File initial, final FileFilter filter) { final JFileChooser chooser = new JFileChooser(initial); chooser.addChoosableFileFilter(filter); chooser.setAcceptAllFileFilterUsed(true); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(title);/*from www . j a v a 2 s .c om*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); final File result; if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } else { result = null; } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageFrame.java
protected File[] askUserForImageFiles() { ImageFilter imageFilter = new ImageFilter(); JFileChooser fileChooser = new JFileChooser( WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMAGES_FILE_PATH)); fileChooser.setFileFilter(imageFilter); fileChooser.setDialogTitle(getResourceString("WB_CHOOSE_IMAGES")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(true); int userAction = fileChooser.showOpenDialog(this); AppPreferences localPrefs = AppPreferences.getLocalPrefs(); // remember the directory the user was last in localPrefs.put(WorkbenchTask.IMAGES_FILE_PATH, fileChooser.getCurrentDirectory().getAbsolutePath()); if (userAction == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFiles(); }/* w w w .ja va 2 s. co m*/ // if for any reason we got to this point... return null; }
From source file:com.igormaznitsa.zxpoly.MainForm.java
private File chooseFileForOpen(final String title, final File initial, final AtomicReference<FileFilter> selectedFilter, final FileFilter... filter) { final JFileChooser chooser = new JFileChooser(initial); for (final FileFilter f : filter) { chooser.addChoosableFileFilter(f); }/* w w w.ja va2 s .c o m*/ chooser.setAcceptAllFileFilterUsed(false); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(title); chooser.setFileFilter(filter[0]); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); final File result; if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); if (selectedFilter != null) { selectedFilter.set(chooser.getFileFilter()); } } else { result = null; } return result; }
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 {/*w w w .j a va 2s . c o m*/ 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()); } } } } }