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:electroStaticUI.ElectroStaticUIContainer.java

private void buildFileMenu() {
    //create Exit menu item
    exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic(KeyEvent.VK_X);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);/*  w  ww. j  a  va  2 s .  c  om*/
        }
    });

    //open
    open = new JMenuItem("Open");
    open.setMnemonic(KeyEvent.VK_P);
    open.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fChooser = new JFileChooser();
            int status = fChooser.showSaveDialog(null);
        }
    });

    //close
    close = new JMenuItem("Close");
    close.setMnemonic(KeyEvent.VK_C);

    //export
    export = new JMenuItem("Export");
    export.setMnemonic(KeyEvent.VK_E);
    export.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fChooser = new JFileChooser();
            fChooser.setMultiSelectionEnabled(false);
            fChooser.setAcceptAllFileFilterUsed(false);
            FileNameExtensionFilter svgFilter = new FileNameExtensionFilter("Save Vector Plot(svg)", ".svg");
            FileNameExtensionFilter pngFilter = new FileNameExtensionFilter("Save Voltage Surface Plot(png)",
                    ".png");
            fChooser.addChoosableFileFilter(svgFilter);
            fChooser.addChoosableFileFilter(pngFilter);
            fChooser.setFileFilter(svgFilter);
            int status = fChooser.showSaveDialog(rootPane);
            if (status == JFileChooser.APPROVE_OPTION) {
                if (fChooser.getFileFilter() == svgFilter) {
                    try {
                        saveAsName = fChooser.getSelectedFile().getCanonicalPath();
                        Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(),
                                displayPanel.getHeight());
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                } else if (fChooser.getFileFilter() == pngFilter) {
                    try {
                        saveAsName = fChooser.getSelectedFile().getCanonicalPath();
                        Save.saveChart3dToPNG(DefaultValues.get3dChartToSave(), saveAsName);
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            }
        }
    });

    //save
    save = new JMenuItem("Save");
    save.setMnemonic(KeyEvent.VK_S);
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fChooser = new JFileChooser();
            int status = fChooser.showSaveDialog(null);
            if (status == JFileChooser.APPROVE_OPTION) {
                try {
                    System.out.println("Height: " + displayPanel.getWidth());
                    System.out.println("Width: " + displayPanel.getHeight());
                    saveAsName = fChooser.getSelectedFile().getCanonicalPath();
                    Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(),
                            displayPanel.getHeight());
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }

        }
    });

    //saveAs
    saveAs = new JMenuItem("Save As");
    saveAs.setMnemonic(KeyEvent.VK_A);
    saveAs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fChooser = new JFileChooser();
            int status = fChooser.showSaveDialog(null);
            if (status == JFileChooser.APPROVE_OPTION)
                try {
                    System.out.println("Height: " + displayPanel.getWidth());
                    System.out.println("Width: " + displayPanel.getHeight());
                    saveAsName = fChooser.getSelectedFile().getCanonicalPath();
                    System.out.println(saveAsName);
                    Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(),
                            displayPanel.getHeight());
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
            try {
                Save.saveChartToSVG(UserInput.getElectricFieldChart(), saveAsName, displayPanel.getWidth(),
                        displayPanel.getHeight());
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });

    //JMenu object for file menu
    fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    //fileMenu.add(newFile);
    //fileMenu.add(open);
    //fileMenu.add(close);
    fileMenu.add(export);
    //fileMenu.add(save);
    //fileMenu.add(saveAs);
    fileMenu.add(exitItem);
}

From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java

private File loadFileChooser(javax.swing.filechooser.FileFilter ff, String saveName) {
    File result;/*from  www  .  j a v a2s .c  om*/
    JFileChooser fc = new JFileChooser(); //Create a file chooser
    fc.setMultiSelectionEnabled(false);
    if (ff != null) {
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileFilter(ff);
    } else {
        fc.setAcceptAllFileFilterUsed(true);
    }
    if (saveName == null) {
        fc.setDialogTitle("");
        if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
        } else {
            result = null;
        }
    } else {
        fc.setDialogTitle("Save As...");
        fc.setSelectedFile(new File(saveName));
        if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
        } else {
            result = null;
        }
    }
    return result;
}

From source file:SciTK.Plot.java

/** 
* Save displayed chart as vector graphics 
*///from  ww  w.ja  v  a  2s  .  c  om
public void saveVectorGraphics() {
    Rectangle r = chart_panel.getBounds(); // get size of chart

    // file selection:
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new ExtensionFileFilter("SVG", new String[] { "svg,SVG" }));
    fc.addChoosableFileFilter(new ExtensionFileFilter("PS", new String[] { "ps,PS" }));
    fc.addChoosableFileFilter(new ExtensionFileFilter("EPS", new String[] { "eps,EPS" }));
    // remove default option:
    fc.setAcceptAllFileFilterUsed(false);

    // Select a file using the JFileChooser dialog:
    int fc_return = fc.showSaveDialog(Plot.this);

    // if the user actually wants to save:
    if (fc_return == JFileChooser.APPROVE_OPTION) {
        //get the file:
        File save_file = fc.getSelectedFile();
        // and the type of extension (from file chooser)
        String extension = fc.getFileFilter().getDescription();
        try // try/catch for IO errors
        {
            // For each type of extension, check to see if the name includes the
            // correct extension and then save the image to file.
            // Default extension is EPS
            if (extension == "SVG") {
                // sanity check extension:
                if (!save_file.getName().endsWith(".svg") && !save_file.getName().endsWith(".SVG"))
                    save_file = new File(save_file.getAbsolutePath() + ".svg");
                exportChartAsSVG(chart, r, save_file);
            } else if (extension == "PS") {
                // sanity check extension:
                if (!save_file.getName().endsWith(".ps") && !save_file.getName().endsWith(".PS"))
                    save_file = new File(save_file.getAbsolutePath() + ".ps");
                exportChartAsPS(chart, r, save_file, "ps");
            } else {
                // sanity check extension:
                if (!save_file.getName().endsWith(".eps") && !save_file.getName().endsWith(".EPS"))
                    save_file = new File(save_file.getAbsolutePath() + ".eps");
                exportChartAsPS(chart, r, save_file, "eps");
            }
        } catch (IOException e) {
            DialogError emsg = new DialogError(this, " There was an error saving the file."
                    + System.getProperty("line.separator") + e.getMessage());
        }
    }
}

From source file:base.BasePlayer.AddGenome.java

static void downloadGenome(String urls) {
    try {//  w  w w  .ja  va 2s  .c  om

        URL fastafile = AddGenome.genomeHash.get(urls)[0];
        String targetDir = "";
        //boolean writable = true;

        File test = new File(Main.genomeDir.getCanonicalPath() + "/test");

        //File f = new File(Main.genomeDir.getCanonicalPath());         

        if (test.mkdir()) {
            /*if(fastafile.getFile().contains("GRCh38")) {
                      
                  if((test.getFreeSpace()/1048576) < (60000000000L/1048576)) {
              Main.showError("Sorry, you need more than 60GB of disk space to install GRCh38.\nGRCh38 FASTA file size is ~50GB uncompressed.\nThis drive has " +test.getFreeSpace()/1048576/1000 +"GB.", "Note");
              test.delete();
              return;
                  }                                                    
               }
            else*/ if ((test.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                Main.showError("Sorry, you need more than 5GB of disk space.\nThis drive has "
                        + test.getFreeSpace() / 1048576 / 1000 + "GB.", "Note");
                test.delete();
                return;
            }
            test.delete();

            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
            File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
            URL gfffile = AddGenome.genomeHash.get(urls)[1];
            targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                    + FilenameUtils.getName(gfffile.getFile()) + "/";
            File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
            AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
            genomeadd.createGenome = true;
            genomeadd.execute();
        } else {
            try {

                JFileChooser chooser = new JFileChooser();
                chooser.setAcceptAllFileFilterUsed(false);
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setDialogTitle("Select a local directory for genome files...");
                File outfile = null;

                while (true) {
                    int returnVal = chooser.showSaveDialog((Component) AddGenome.panel);

                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        outfile = chooser.getSelectedFile();
                        File genomedir = new File(outfile.getCanonicalPath() + "/genomes");
                        if (new File(outfile.getCanonicalPath() + "/genomes").mkdir()) {
                            if (fastafile.getFile().contains("GRCh38")) {
                                if ((outfile.getFreeSpace() / 1048576) < (200000000000L / 1048576)) {
                                    Main.showError(
                                            "Please, select local drive with more than 60GB of disk space.\nGRCh38 FASTA file is ~50GB uncompressed.\nThis drive has "
                                                    + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                            "Note");
                                    genomedir.delete();
                                    continue;
                                }
                            } else if ((outfile.getFreeSpace() / 1048576) < (5000000000L / 1048576)) {
                                Main.showError(
                                        "Please, select local drive with more than 5GB of disk space.\nThis drive has "
                                                + outfile.getFreeSpace() / 1048576 / 1000 + "GB.",
                                        "Note");
                                genomedir.delete();
                                continue;
                            }
                        } else {
                            Main.showError(
                                    "No writing permissions for this directory. \nPlease, select new directory for genomes.",
                                    "Error");
                            continue;
                        }

                        /*if (!new File(outfile.getCanonicalPath() +"/genomes").mkdir()) {
                           Main.showError("Could not create genome directory in " +outfile.getCanonicalPath(), "Error");
                           continue;
                        }*/

                        break;
                    }
                    if (returnVal == JFileChooser.CANCEL_OPTION) {
                        outfile = null;
                        downloading = false;
                        break;
                    }
                }
                if (outfile != null) {
                    Main.genomeDir = new File(outfile.getCanonicalPath() + "/genomes");
                    genomedirectory.setText(Main.genomeDir.getCanonicalPath());
                    Main.writeToConfig("genomeDir=" + Main.genomeDir.getCanonicalPath());
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/";
                    File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile()));
                    URL gfffile = AddGenome.genomeHash.get(urls)[1];
                    targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/"
                            + FilenameUtils.getName(gfffile.getFile()) + "/";
                    File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile()));
                    AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                    genomeadd.createGenome = true;
                    genomeadd.execute();
                }
                downloading = false;
                /* new File(outfile.getCanonicalPath() +"/genomes").mkdir();
                File fasta = new File(targetDir +FilenameUtils.getName(fastafile.getFile()));                     
                        
                URL gfffile= AddGenome.genomeHash.get(urls)[1];
                targetDir = AddGenome.userDir +"/genomes/" +urls +"/annotation/" +FilenameUtils.getName(gfffile.getFile()) +"/";
                File gff = new File(targetDir +FilenameUtils.getName(gfffile.getFile()));
                        
                AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls);
                genomeadd.createGenome = true;
                genomeadd.execute();
                */
            } catch (Exception ex) {
                downloading = false;
                ex.printStackTrace();
            }

        }

    } catch (Exception e) {
        downloading = false;
        e.printStackTrace();
    }

}

From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java

private void cmdDatadirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDatadirActionPerformed
    try {/*w  w w .  j  ava  2 s  .  co m*/
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("."));
        chooser.setDialogTitle("Eligir ubicacin de la base de datos.");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            txtDatadir.setText(chooser.getSelectedFile().getPath());
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,
                Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage());
        LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex);
    }
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void exportRecords() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AbbFileFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    int value = chooser.showSaveDialog(this);
    if (value == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        disableAllControls();/*from   ww w  . j  a v a  2  s. c  o m*/
        new Thread() {
            @Override
            public void run() {
                try {
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif")));
                    setStatusText("?...");
                    FacadeUtil.shutdown();
                    // .abb?
                    setStatusText("?...");
                    List<String> exclusion = Arrays.asList();
                    if (!file.getName().endsWith(".abb")) {
                        ZIPUtil.compress(new File(Constants.DATA_DIR),
                                new File(file.getAbsolutePath() + ".abb"), exclusion);
                    } else {
                        ZIPUtil.compress(new File(Constants.DATA_DIR), file, exclusion);
                    }
                    setStatusText("??...");
                    FacadeUtil.restart();
                    enableAllControls();
                    setStatusText("");
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png")));
                    JOptionPane.showMessageDialog(MainFrame.this, String.format("?"), "?",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(MainFrame.this, String.format(""), "",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }.start();
    }
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void importRecords() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AbbFileFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    int value = chooser.showOpenDialog(this);
    if (value == JFileChooser.APPROVE_OPTION) {
        // ?/*from   ww w.  j  a  v  a2s  .  c  om*/
        disableAllControls();
        new Thread() {
            @Override
            public void run() {
                try {
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif")));
                    setStatusText("?...");
                    FacadeUtil.shutdown();
                    File file = chooser.getSelectedFile();
                    setStatusText("??...");
                    FileUtils.cleanDirectory(new File(Constants.DATA_DIR));
                    setStatusText("??...");
                    ZIPUtil.decompress(file, new File(Constants.HOME_DIR));
                    setStatusText("?...");
                    FacadeUtil.restart();
                    // ??
                    setStatusText("????...");
                    categories = categoryFacade.listBySale();
                    // ????
                    setStatusText("?...");
                    searchRecords();
                    enableAllControls();
                    setStatusText("");
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png")));
                    JOptionPane.showMessageDialog(MainFrame.this, "???", "?",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(MainFrame.this, e.getMessage(), "",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }.start();
    }
}

From source file:ffx.ui.KeywordPanel.java

/**
 * <p>// www.ja v  a2s  .com
 * keySaveAs</p>
 */
public void keySaveAs() {
    if (!fileOpen) {
        return;
    }
    JFileChooser d = MainPanel.resetFileChooser();
    d.setDialogTitle("Save KEY File");
    d.setAcceptAllFileFilterUsed(false);
    if (currentKeyFile != null) {
        d.setCurrentDirectory(currentKeyFile.getParentFile());
        d.setSelectedFile(currentKeyFile);
    }
    d.setFileFilter(new KeyFileFilter());
    int result = d.showSaveDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        currentKeyFile = d.getSelectedFile();
        keySave(currentKeyFile);
    }
}

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);//  w w  w.ja  va 2  s .  co  m
    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: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 ww w.j  a v a2s .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.");

}