List of usage examples for javax.swing JFileChooser FILES_AND_DIRECTORIES
int FILES_AND_DIRECTORIES
To view the source code for javax.swing JFileChooser FILES_AND_DIRECTORIES.
Click Source Link
From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java
public static File chooseFile(final Component parent, final boolean filesOnly, final String title, final File selectedFile, final FileFilter filter) { final JFileChooser chooser = new JFileChooser(selectedFile); chooser.setApproveButtonText("Select"); if (filter != null) chooser.setFileFilter(filter);/*from ww w .j a va 2s .co m*/ chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(false); if (filesOnly) chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); else chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else { return null; } }
From source file:com.simplexrepaginator.RepaginateFrame.java
protected JButton creatOutputButton() { JButton b = new JButton("Click or drag to set output file", PDF_1234); b.setHorizontalTextPosition(SwingConstants.LEFT); b.setIconTextGap(25);//from ww w . j a v a 2 s .c om b.setTransferHandler(new OutputButtonTransferHandler()); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (chooser.showOpenDialog(RepaginateFrame.this) != JFileChooser.APPROVE_OPTION) return; repaginator.setOutputFiles(Arrays.asList(chooser.getSelectedFiles())); output.setText("<html><center>" + StringUtils.join(repaginator.getOutputFiles(), "<br>")); } }); return b; }
From source file:edu.synth.SynthHelper.java
public String openDialogFileChooser(String path, boolean dirOnly, String name, String button, String filterType) {/* ww w . java2 s . co m*/ JFileChooser fileOpen = new JFileChooser(); if (!path.isEmpty()) fileOpen.setCurrentDirectory(new File(path)); else fileOpen.setCurrentDirectory(new File(".")); if (dirOnly) fileOpen.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else { fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); switch (filterType) { case "abn": FileFilter filter = new FileNameExtensionFilter("*.abn - Abundances file", "abn"); fileOpen.setFileFilter(filter); break; case "model": filter = new FileNameExtensionFilter("*.atl - Kurucz's format model file", "atl"); fileOpen.setFileFilter(filter); break; case "lns": filter = new FileNameExtensionFilter("*.lns - Lines file", "lns"); fileOpen.setFileFilter(filter); break; } } fileOpen.setDialogTitle(name); fileOpen.setApproveButtonText(button); int returnVal = fileOpen.showOpenDialog(fileOpen); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedPath = fileOpen.getSelectedFile(); if (selectedPath != null) return selectedPath.getAbsolutePath(); } return ""; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * * @throws IOException/*from ww w. j a va 2 s . c o m*/ */ private void createPdf(JFreeChart chart) throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooseDirectory.setSelectedFile(new File("chart rose plot" + ".pdf")); // in response to the button click, show open dialog int returnVal = chooseDirectory.showSaveDialog(angleDirectPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); PdfSwingWorker pdfSwingWorker = new PdfSwingWorker(directory, chooseDirectory.getSelectedFile().getName(), chart); pdfSwingWorker.execute(); } else { singleCellPreProcessingController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.mgmtp.jfunk.core.JFunk.java
private static List<File> requestScriptsViaGui() { final List<File> scripts = new ArrayList<>(); try {// ww w . j av a2 s .com SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser fileChooser = new JFileChooser(System.getProperty(JFunkConstants.USER_DIR)); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(true); fileChooser.setPreferredSize(new Dimension(800, 450)); int i = fileChooser.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { File[] files = fileChooser.getSelectedFiles(); scripts.addAll(Arrays.asList(files)); } } }); } catch (Exception e) { LOG.error("Error while requesting scripts via GUI", e); } return scripts; }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void loadReference() throws Exception { JFileChooser chooser = new JFileChooser("Please choose a reference file or directory."); chooser.setCurrentDirectory(frame.defaultDirectory); // TODO: detect if all directory formats are not readable and in this case dont allow directory opening chooser.setFileSelectionMode(/*from www . ja v a2 s . c om*/ ReferenceFormats.REFERENCE_FORMATS.directoryFormats.isEmpty() ? JFileChooser.FILES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); for (ReferenceFormat format : ReferenceFormats.REFERENCE_FORMATS.readableFormats) { chooser.addChoosableFileFilter( new FilesystemFilter(format.getFileExtension(), format.getDescription())); } chooser.setAcceptAllFileFilterUsed(true); int returnVal = chooser.showOpenDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } ReferenceFormat format = null; System.out.print("Loading..."); frame.setTitle("Loading..."); File f = chooser.getSelectedFile(); Collection<ReferenceFormat> formats; if (f.isDirectory()) { formats = ReferenceFormats.REFERENCE_FORMATS.directoryFormats; } else { formats = ReferenceFormats.REFERENCE_FORMATS.extensionToFormats .get(f.getName().substring(f.getName().lastIndexOf(".") + 1)); } if (formats == null || formats.isEmpty()) { throw new Exception("No format available that can read files with the " + f.getName().substring(f.getName().lastIndexOf(".") + 1) + " extension."); } if (formats.size() == 1) { format = formats.iterator().next(); } else { format = formatChooser(formats); } if (format == null) { return; } Reference reference = format.readReference(chooser.getSelectedFile(), true, frame.loadLimit); if (!reference.links.isEmpty()) { Link firstLink = reference.links.iterator().next(); frame.dataSourceName1 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.first); frame.dataSourceName2 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.second); } frame.setReference(reference); //frame.loadPositiveNegativeNT(chooser.getSelectedFile()); System.out.println("loading finished, " + reference.links.size() + " links loaded."); }
From source file:net.sf.jclal.gui.view.components.chart.ExternalBasicChart.java
/** * * @return Create the menu that allows load the result from others * experiments./*from w ww.ja va 2 s . c om*/ */ private JMenu createMenu() { final JMenu fileMenu = new JMenu("Options"); final JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileMenu.add("Add report file or directory").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (curveOptions != null) { curveOptions.setVisible(false); curveOptions = null; } int action = f.showOpenDialog(fileMenu); if (action == JFileChooser.APPROVE_OPTION) { loadReportFile(f.getSelectedFile()); } } }); fileMenu.add("Area under learning curve (ALC)").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (comboBox.getItemCount() != 0) { if (!comboBox.getSelectedItem().toString().isEmpty()) { StringBuilder st = new StringBuilder(); st.append("Measure: ").append(comboBox.getSelectedItem()).append("\n\n"); for (int query = 0; query < queryNames.size(); query++) { double value = LearningCurveUtility.getArea(evaluationsCollection.get(query), comboBox.getSelectedItem().toString()); String valueString = String.format("%.3f", value); st.append(queryNames.get(query)).append(": ").append(valueString).append("\n"); } JOptionPane.showMessageDialog(content, st.toString(), "Area under the learning curve", JOptionPane.INFORMATION_MESSAGE); } } } }); fileMenu.add("Clear").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { queryNames = new ArrayList<String>(); evaluationsCollection = new ArrayList<List<AbstractEvaluation>>(); comboBox.removeAllItems(); controlCurveColor = new HashMap<String, Color>(); colors.clear(); data = null; set.clear(); curveOptions.setVisible(false); curveOptions = null; setSeries.clear(); passiveEvaluation = null; } }); fileMenu.add("Curve options").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { data = informationTable(); if (queryNames.isEmpty()) { JOptionPane.showMessageDialog(null, "Please add curves"); return; } if (curveOptions == null) { curveOptions = new LearningCurvesVisualTable(ExternalBasicChart.this); } else { curveOptions.setVisible(true); } } }); final JCheckBox viewPoints = new JCheckBox("View points's shapes"); viewPoints.setSelected(false); viewPoints.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { viewPointsForm = viewPoints.isSelected(); jComboBoxItemStateChanged(); } }); fileMenu.add(viewPoints); final JCheckBox withOutColor = new JCheckBox("View without color"); withOutColor.setSelected(false); withOutColor.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { viewWithOutColor = withOutColor.isSelected(); jComboBoxItemStateChanged(); } }); fileMenu.add(withOutColor); return fileMenu; }
From source file:net.sf.firemox.tools.MToolKit.java
/** * Display a file dialog with many options * /*from ww w . j a v a 2s . co m*/ * @param titreBoite * title of this dialog box * @param etiquetteBouton * button "yes" * @param infoBulle * tooltip * @param raccourciBouton * shortcut for "yes" button * @param fichier * old file * @param fileFilter * file filter to apply * @param parent * is parent of this dialog * @param type * the dialog type * @return the File object corresponding to the user's choice * @see JFileChooser#setDialogType(int) */ private static File showDialogFile(String titreBoite, char raccourciBouton, File fichier, FileFilterPlus fileFilter, JFrame parent, int type) { return showDialogFile(titreBoite, raccourciBouton, fichier, fileFilter, parent, type, JFileChooser.FILES_AND_DIRECTORIES); }
From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java
private void setupTool() { LoggerJAXB.outputJaxpImplementationInfo(); Locale currentLocale = Locale.getDefault(); labels = new ResourceBundlesWrapper(I18N_BASENAMES, currentLocale); retrieveFromDb = new RetrieveFromDb(); apePanel = new APEPanel(labels, getContentPane(), this, retrieveFromDb); Utilities.setXsdList(fillXsdList()); CheckList checkList = new CheckList(); langList = checkList.getLangList();/*from w w w . jav a 2 s .c o m*/ levelList = checkList.getLevelList(); dateNormalization = new DateNormalization(); super.setTitle(labels.getString("title")); Image topLeftIcon = Utilities.icon.getImage(); setIconImage(topLeftIcon); doChecks(); if (isFileMissing(Utilities.LOG_DIR)) { new File(Utilities.LOG_DIR).mkdir(); } File tempDir = new File(Utilities.TEMP_DIR); //In case it didn't deleteOnExit at the previous closing of the program, we clean up. if (tempDir.exists()) { LOG.warn("Probably a problem when deleting the temp files at closure, so we clean up"); eraseOldTempFiles(tempDir); try { FileUtils.deleteDirectory(tempDir); } catch (IOException e) { LOG.error("Could not delete the temp directory. Attempt to delete the directory once more: " + (tempDir.delete() ? "Successful." : "Unsuccessful.")); } } tempDir.mkdir(); tempDir.deleteOnExit(); // ListControlaccessTerms listControlaccessTerms = new ListControlaccessTerms("/Users/yoannmoranville/Documents/Work/APE/data/AD78/"); // listControlaccessTerms.countTerms(); // listControlaccessTerms.displayLogsResults(); // CountCLevels countCLevels = new CountCLevels("/Users/yoannmoranville/Work/APEnet/Projects/data/Ready_APEnet/READY/Finland/HeNAF/FA_EAD/"); // CountCLevels countCLevels = new CountCLevels("/Users/yoannmoranville/Work/APEnet/Projects/data/BORA/ALL/"); // countCLevels.setCopyInAppropriateDirs(true); // countCLevels.changeMainagencycodeForSweden(false); // countCLevels.countLevels(); // SeparateFinnishFiles separateFinnishFiles = new SeparateFinnishFiles(new File("/Users/yoannmoranville/Desktop/files_fi"), TEMP_DIR); makeDefaultXsdMenuItems(); makeDefaultXslMenuItems(); getContentPane().add(apePanel); xmlEadListModel = new ProfileListModel(fileInstances, this); xmlEadList = new JList(xmlEadListModel); xmlEadList.setCellRenderer(new IconListCellRenderer(fileInstances)); xmlEadList.setDragEnabled(true); xmlEadList.setTransferHandler(new ListTransferHandler()); xmlEadList.setDropTarget(new DropTarget(xmlEadList, new ListDropTargetListener(xmlEadList, from))); xmlEadListModel.setList(xmlEadList); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); menuBar.add(optionMenu); menuBar.add(actionMenu); menuBar.add(windowMenu); menuBar.add(helpMenu); fileItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fileMenu.add(fileItem); closeSelectedItem.setEnabled(false); // closeSelectedItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); closeSelectedItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fileMenu.add(closeSelectedItem); saveSelectedItem.setEnabled(false); saveSelectedItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fileMenu.add(saveSelectedItem); saveMessageReportItem.setEnabled(false); saveMessageReportItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fileMenu.add(saveMessageReportItem); // sendFilesWebDAV.setEnabled(false); // fileMenu.add(sendFilesWebDAV); fileMenu.addSeparator(); fileMenu.add(quitItem); optionMenu.add(countryCodeItem); optionMenu.add(repositoryCodeItem); optionMenu.add(digitalObjectTypeItem); optionMenu.add(edmGeneralOptionsItem); optionMenu.add(listDateConversionRulesItem); optionMenu.addSeparator(); optionMenu.add(xsltItem); optionMenu.add(xsdItem); optionMenu.add(defaultXslSelectionSubmenu); optionMenu.add(defaultXsdSelectionSubmenu); optionMenu.addSeparator(); optionMenu.add(checksLoadingFilesItem); optionMenu.add(defaultSaveFolderItem); optionMenu.add(languageMenu); if (Utilities.isDev) { optionMenu.addSeparator(); optionMenu.add(databaseItem); } validateItem.setEnabled(false); validateItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); actionMenu.add(validateItem); convertItem.setEnabled(false); convertItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); actionMenu.add(convertItem); actionMenu.addSeparator(); // TODO: Uncomment when edit will be available. // eacCpfItem.add(this.editEacCpfFile); //add the different EAC-CPF options menu eacCpfItem.add(createEacCpf); actionMenu.add(eacCpfItem); createEag2012Item.add(createEag2012FromExistingEag2012); createEag2012Item.add(createEag2012FromScratch); actionMenu.add(createEag2012Item); summaryWindowItem.setEnabled(true); summaryWindowItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_1, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); windowMenu.add(summaryWindowItem); validationWindowItem.setEnabled(true); validationWindowItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_2, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); windowMenu.add(validationWindowItem); conversionWindowItem.setEnabled(true); conversionWindowItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_3, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); windowMenu.add(conversionWindowItem); edmConversionWindowItem.setEnabled(true); edmConversionWindowItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_4, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); windowMenu.add(edmConversionWindowItem); editionWindowItem.setEnabled(true); editionWindowItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_5, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); windowMenu.add(editionWindowItem); helpMenu.add(internetApexItem); helpMenu.addSeparator(); JMenuItem versionItem = new JMenuItem("APE DPT v" + VERSION_NB); versionItem.setEnabled(false); helpMenu.add(versionItem); createLanguageMenu(); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(true); getContentPane().add(menuBar, BorderLayout.NORTH); apePanel.setFilename(""); createHgListener = new CreateHGListener(retrieveFromDb, labels, getContentPane(), fileInstances, xmlEadList, this); createHGBtn.addActionListener(createHgListener); createHGBtn.setEnabled(false); analyzeControlaccessListener = new AnalyzeControlaccessListener(labels, getContentPane(), fileInstances); analyzeControlaccessBtn.addActionListener(analyzeControlaccessListener); analyzeControlaccessBtn.setEnabled(false); validateItem.addActionListener(new ConvertAndValidateActionListener(this, apePanel.getApeTabbedPane(), ConvertAndValidateActionListener.VALIDATE)); convertItem.addActionListener(new ConvertAndValidateActionListener(this, apePanel.getApeTabbedPane(), ConvertAndValidateActionListener.CONVERT)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(createWest(), BorderLayout.WEST); // convertAndValidateBtn.addActionListener(new ConvertAndValidateActionListener(this, getContentPane())); // validateSelectionBtn.addActionListener(new ValidateSelectionActionListener(this, getContentPane())); // convertEdmSelectionBtn.addActionListener(new ConvertEdmActionListener(labels, this, apePanel)); nameComponents(); wireUp(); setSize(Toolkit.getDefaultToolkit().getScreenSize()); setMinimumSize(Toolkit.getDefaultToolkit().getScreenSize()); setExtendedState(JFrame.MAXIMIZED_BOTH); }