Example usage for javax.swing JFileChooser setAcceptAllFileFilterUsed

List of usage examples for javax.swing JFileChooser setAcceptAllFileFilterUsed

Introduction

In this page you can find the example usage for javax.swing JFileChooser setAcceptAllFileFilterUsed.

Prototype

@BeanProperty(preferred = true, description = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.")
public void setAcceptAllFileFilterUsed(boolean b) 

Source Link

Document

Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.

Usage

From source file:org.apache.cayenne.modeler.dialog.pref.ClasspathPreferences.java

protected void chooseClassEntry(FileFilter filter, String title, int selectionMode) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(selectionMode);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setAcceptAllFileFilterUsed(true);

    getLastDirectory().updateChooser(chooser);

    if (filter != null) {
        chooser.addChoosableFileFilter(filter);
    }//from  w ww .j  a  va 2s. c om

    chooser.setDialogTitle(title);

    File selected = null;
    int result = chooser.showOpenDialog(view);
    if (result == JFileChooser.APPROVE_OPTION) {
        selected = chooser.getSelectedFile();
    }

    if (selected != null) {
        if (!classPathEntries.contains(selected.getAbsolutePath())) {
            // store last dir in preferences
            getLastDirectory().updateFromChooser(chooser);

            int len = classPathEntries.size();
            int key = ++counter;

            String value = selected.getAbsolutePath();
            addChangedPreferences(Integer.toString(key), value);
            classPathEntries.add(value);
            classPathKeys.add(Integer.toString(key));

            tableModel.fireTableRowsInserted(len, len);
        }
    }
}

From source file:org.apache.cayenne.modeler.graph.action.SaveAsImageAction.java

@Override
public void performAction(ActionEvent e) {
    // find start directory in preferences
    FSPath lastDir = getApplication().getFrameController().getLastDirectory();

    // configure dialog
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    lastDir.updateChooser(chooser);/*from w  w  w.j a  v a2 s .  c om*/

    chooser.setAcceptAllFileFilterUsed(false);

    String ext = "png";
    chooser.addChoosableFileFilter(FileFilters.getExtensionFileFilter(ext, "PNG Images"));

    int status = chooser.showSaveDialog(Application.getFrame());
    if (status == JFileChooser.APPROVE_OPTION) {
        lastDir.updateFromChooser(chooser);

        String path = chooser.getSelectedFile().getPath();
        if (!path.endsWith("." + ext)) {
            path += "." + ext;
        }

        try {

            JGraph graph = dataDomainGraphTab.getGraph();
            BufferedImage img = graph.getImage(null, 0);

            try (OutputStream out = new FileOutputStream(path);) {
                ImageIO.write(img, ext, out);
                out.flush();
            }

        } catch (IOException ex) {
            logObj.error("Could not save image", ex);
            JOptionPane.showMessageDialog(Application.getFrame(), "Could not save image.", "Error saving image",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.domainmath.gui.MainFrame.java

/**
 * Creates file chooser dialog box and allows the user to select files
 * and importData selected files in fileTab.
 *///from w w w  .  j a v a2s.c o  m
public void open() {
    JFileChooser fc = new JFileChooser();

    // set current directory.
    if (fileTab.getTabCount() > 0) {
        File f = new File(fileTab.getToolTipTextAt(fileTab.getSelectedIndex()));
        fc.setCurrentDirectory(f.getParentFile());
    } else {
        fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    }

    FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files  (*.m)", "m");

    fc.setAcceptAllFileFilterUsed(false);

    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(true);
    fc.setFileView(new ScriptFileView());
    File file1[];
    int returnVal = fc.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file1 = fc.getSelectedFiles();

        this.setCurrentDirFileTab(fc.getCurrentDirectory().getAbsolutePath());
        for (int i = 0; i < file1.length; i++) {
            if (!fileNameList.contains(file1[i].getAbsolutePath())) {
                open(file1[i], i);

            } else {
                System.out.println(file1[i].getAbsolutePath() + " already open!");
            }
        }
    }
}

From source file:org.domainmath.gui.MainFrame.java

public void saveplot() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileFilter(DomainMathFileFilter.SAVE_PLOT_FILE_FILTER);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);//from www  .jav a  2s  .  c  om

    File file_plot;
    String name;
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        System.err.println(fc.getFileFilter().getDescription());
        file_plot = fc.getSelectedFile();
        name = file_plot.getName();
        evaluateWithOutput("saveas(1," + "'" + file_plot.getAbsolutePath() + "');");

    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.gui.LoginLocalFolderPanel.java

private void chooseFolder() {
    // Prompt user to choose their Cockpit home directory.
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setDialogTitle("Choose Cockpit Home Folder");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setApproveButtonText("Choose Folder");
    fileChooser.setCurrentDirectory(cockpitHomeFolder);

    int returnVal = fileChooser.showOpenDialog(ownerFrame);
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;/*from   w  w w .j  a va  2 s.c o m*/
    } else {
        this.cockpitHomeFolder = fileChooser.getSelectedFile();
        this.folderPathTextField.setText(this.cockpitHomeFolder.getAbsolutePath());
        refreshStoredCredentialsTable();
    }
}

From source file:org.fhaes.gui.ShapeFileDialog.java

/**
 * Prompt the user for an output filename
 * //from w  ww  . j  a v a2 s. c o  m
 * @param filter
 * @return
 */
private File getOutputFile(FileFilter filter) {

    String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
    File outputFile;

    // Create a file chooser
    final JFileChooser fc = new JFileChooser(lastVisitedFolder);

    fc.setAcceptAllFileFilterUsed(true);

    if (filter != null) {
        fc.addChoosableFileFilter(filter);
        fc.setFileFilter(filter);
    }

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setDialogTitle("Save as...");

    // In response to a button click:
    int returnVal = fc.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        outputFile = fc.getSelectedFile();

        if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") {
            log.debug("Output file extension not set by user");

            if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription())) {
                log.debug("Adding shp extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".shp");
            }
        } else {
            log.debug("Output file extension set my user to '"
                    + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
        }

        App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
    } else {
        return null;
    }

    if (outputFile.exists()) {
        Object[] options = { "Overwrite", "No", "Cancel" };
        int response = JOptionPane.showOptionDialog(this,
                "The file '" + outputFile.getName() + "' already exists.  Are you sure you want to overwrite?",
                "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
                options, // the titles of buttons
                options[0]); // default button title

        if (response != JOptionPane.YES_OPTION) {
            return null;
        }
    }

    return outputFile;
}

From source file:org.geopublishing.geopublisher.GpUtil.java

/**
 * Performs a file OPEN choose as a fallback
 * //  w ww . j  a  va 2  s.  c o  m
 * @param parent
 *            component for the dialog (can be {@code null})
 * @param startFolder
 *            start folder for the chooser (if {@code null} "/" is used)
 * @param filter
 *            defines which files can be selected. Only the last filter in
 *            the list will be offered due to limitations
 * @return {@code null} if the dialog was not approved
 */
public static File chooseFileOpenFallback(Component parent, File startFolder, String title,
        FileExtensionFilter... filters) {
    if (startFolder == null)
        startFolder = new File("/");

    if (startFolder.isFile())
        startFolder = startFolder.getParentFile();

    JFileChooser chooser = new JFileChooser(startFolder);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);

    if (filters != null) {
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setFileFilter(filters[0].toJFileChooserFilter());
    }
    if (title != null)
        chooser.setDialogTitle(title);

    int ret = chooser.showOpenDialog(parent);
    if (ret == JFileChooser.APPROVE_OPTION)
        return chooser.getSelectedFile();
    return null;
}

From source file:org.gofleet.module.routing.RoutingMap.java

private void newPlan(LatLon from) {
    JDialog d = new JDialog(basicWindow.getFrame(), "Generating New Plan");
    try {//  w w  w  .  j av a 2  s  .c  om
        JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(new RoutingFilter());
        fc.setAcceptAllFileFilterUsed(true);
        int returnVal = fc.showOpenDialog(basicWindow.getFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            log.debug("Opening: " + file.getName());

            JProgressBar progressBar = new JProgressBar(0, getNumberLines(file) * 2);
            progressBar.setValue(0);
            progressBar.setPreferredSize(new Dimension(150, 50));
            progressBar.setStringPainted(true);

            d.add(progressBar);
            d.pack();
            d.setVisible(true);

            TSPPlan[] param = processFile(file, progressBar);

            Map<String, String> values = getValues(from);

            double[] origin = new double[2];
            origin[0] = new Double(values.get("origin_x"));
            origin[1] = new Double(values.get("origin_y"));

            TSPPlan[] res = calculateRouteOnWS(new Integer(values.get("maxDistance")),
                    new Integer(values.get("maxTime")), origin, new Integer(values.get("startTime")), param,
                    new Integer(values.get("timeSpentOnStop")));

            progressBar.setValue(progressBar.getMaximum() - res.length);

            processTSPPlan(res, progressBar);

        } else {
            log.trace("Open command cancelled by user.");
        }
    } catch (Throwable t) {
        log.error("Error computing new plan", t);
        JOptionPane.showMessageDialog(basicWindow.getFrame(),
                "<html><p>" + i18n.getString("Main.Error") + ":</p><p>" + t.toString() + "</p><html>",
                i18n.getString("Main.Error"), JOptionPane.ERROR_MESSAGE);
    } finally {
        d.setVisible(false);
        d.dispose();
    }

}

From source file:org.iobserve.mobile.instrument.start.InstrumenterTest.java

/**
 * Executes the instrumentation./*w w w .  j a  va2 s  .co m*/
 * 
 * @param argv
 *            not needed
 * @throws KeyStoreException
 *             caused by the instrumentation
 * @throws NoSuchAlgorithmException
 *             caused by the instrumentation
 * @throws CertificateException
 *             caused by the instrumentation
 * @throws IOException
 *             caused by the instrumentation
 * @throws ZipException
 *             caused by the instrumentation
 * @throws URISyntaxException
 *             caused by the instrumentation
 */
public static void main(final String[] argv) throws KeyStoreException, NoSuchAlgorithmException,
        CertificateException, IOException, ZipException, URISyntaxException {
    final File toInstrument;
    if (SELECTAPK) {
        final JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(new FileFilter() {
            @Override
            public String getDescription() {
                return null;
            }

            @Override
            public boolean accept(final File f) {
                if (f.isDirectory()) {
                    return true;
                }

                if (FilenameUtils.getExtension(f.getAbsolutePath()).equals("apk")) {
                    return true;
                }
                return false;
            }
        });
        fc.setAcceptAllFileFilterUsed(false);
        final int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            toInstrument = fc.getSelectedFile();
        } else {
            return;
        }
    } else {
        toInstrument = new File("app-debug.apk");
    }

    if (toInstrument.exists()) {
        final APKInstrumenter instr = new APKInstrumenter(true, new File("lib/release.keystore"),
                "androiddebugkey", "android");
        instr.instrumentAPK(toInstrument, new File("instr-output.apk"));
    } else {
        System.err.println("APK doesn't exist.");
    }
}

From source file:org.jcurl.core.jnlp.FileDialogSwing.java

private static JFileChooser createFileChooser(final String pathHint, final String[] extensions,
        final boolean showDir) {
    final JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);/*from   w w w  .  ja v  a 2  s  .  co m*/
    fc.setAcceptAllFileFilterUsed(true);
    fc.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(final File f) {
            if (f == null)
                return false;
            if (showDir && f.isDirectory())
                return true;
            for (final String element : extensions)
                if (f.getName().endsWith("." + element))
                    return true;
            return false;
        }

        @Override
        public String getDescription() {
            final StringBuilder b = new StringBuilder();
            for (final String element : extensions)
                b.append("*.").append(element).append(", ");
            if (b.length() > 0)
                b.setLength(b.length() - 2);
            return b.toString();
        }
    });
    return fc;
}