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.mbari.aved.ui.utils.VideoUtils.java

/**
 * Browse for video clip, or still image archive starting in last imported directory
 *//* www.  j a va2  s  .  c  o  m*/
public static File browseForImageSource(File setCurrentDirectory) throws Exception {
    File f = null;

    // Add a custom file filter and disable the default
    JFileChooser chooser = new JFileChooser();

    chooser.addChoosableFileFilter(new ImageFileFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setDialogTitle("Choose Still Image/Video Source File");
    chooser.setCurrentDirectory(setCurrentDirectory);

    if (chooser.showOpenDialog(Application.getView()) == JFileChooser.APPROVE_OPTION) {
        f = chooser.getSelectedFile();
        UserPreferences.getModel().setImportVideoDir(f.getParent());
    } else {

        // TODO: print dialog message box with something meaningful here
        System.out.println("No Selection ");

        return null;
    }

    return f;
}

From source file:org.nuclos.client.customcomp.resplan.AbstractResPlanExportDialog.java

@PostConstruct
private void init() {
    double border = 10;
    double inset = 5;
    double size[][] = { { border, 100, inset, 200, inset, 30, inset, 65, border }, // Columns
            { border, 20, inset, 20, inset, 30, border } }; // Rows
    final TableLayout tl = new TableLayout(size);
    setLayout(tl);//from  w  w  w .j a v  a 2  s .  co  m

    final SpringLocaleDelegate sld = getSpringLocaleDelegate();
    final JLabel fileLabel = new JLabel(sld.getText("nuclos.resplan.dialog.file"), SwingConstants.RIGHT);
    add(fileLabel, "1, 1");
    file = new JTextField();
    file.setText(save.getPath());
    add(file, "3, 1");

    final JButton browse = new JButton("...");
    add(browse, "5, 1");

    final JLabel typeLabel = new JLabel(sld.getText("nuclos.resplan.dialog.type"), SwingConstants.RIGHT);
    add(typeLabel, "1, 3");
    fileTypes = new JComboBox(new String[] { ImageType.SVG.getFileExtension(), ImageType.EMF.getFileExtension(),
            ImageType.PNG.getFileExtension() });
    fileTypes.setSelectedItem(defaultFileType);
    fileTypes.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            checkFile();
        }
    });
    add(fileTypes, "3, 3");

    browse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser chooser = new JFileChooser(save.getParent());
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.addChoosableFileFilter(new MyFileFilter((String) fileTypes.getSelectedItem()));
            // chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            final int returnVal = chooser.showSaveDialog(parent);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                save = chooser.getSelectedFile();
                checkFile();
            }
        }
    });

    final JPanel buttons = new JPanel(new FlowLayout());
    add(buttons, "1, 5, 7, 5");

    final JButton export = new JButton(sld.getText("nuclos.resplan.dialog.export"));
    buttons.add(export);
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final String filePath = file.getText();
            if (!filePath.equals(save.getPath())) {
                save = new File(filePath);
            }
            checkFile();
            if (save.exists()) {
                String file = save.getAbsolutePath();
                if (save.canWrite()) {
                    int ans = JOptionPane.showConfirmDialog(AbstractResPlanExportDialog.this,
                            sld.getMessage("general.overwrite.file", "general.overwrite.file", file),
                            sld.getMessage("general.overwrite.file.title", "general.overwrite.file.title"),
                            JOptionPane.OK_CANCEL_OPTION);
                    if (ans != JOptionPane.YES_OPTION) {
                        return;
                    }
                } else {
                    JOptionPane.showMessageDialog(AbstractResPlanExportDialog.this,
                            sld.getMessage("general.notwritable.file", "general.notwritable.file", file),
                            sld.getMessage("general.notwritable.file.title", "general.notwritable.file.title"),
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            export();
            storePreferences();
            dispose();
        }
    });

    final JButton cancel = new JButton(sld.getText("general.cancel"));
    buttons.add(cancel);
    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    pack();
    setLocationRelativeTo(parent);
    setVisible(true);
}

From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Creates a filechooser where the user can select the (comma-seperated)
 * file that he wants to export to. If this file already exists, permission
 * to overwrite is requested, else a new file is created to which the
 * time-metrics of the selected place/transitions are exported.
 * /* www .  j  a v a  2s. co  m*/
 */
private void exportObjectMetrics() {
    // create and initialize the file chooser
    final JFileChooser fc = new JFileChooser();
    NameFilter filt1 = new NameFilter(".csv");
    NameFilter filt2 = new NameFilter(".txt");
    fc.addChoosableFileFilter(filt1);
    fc.addChoosableFileFilter(filt2);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileFilter(filt1);
    // check whether a place is selected
    int result = fc.showDialog(this, "Export");
    if (result == 0) {
        // Export-button was pushed
        File selectedFile = fc.getSelectedFile();
        if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) {
            // create new file, with filetype added to it
            selectedFile = new File(
                    selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1));
        }

        if (!selectedFile.exists()) {
            if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) {
                // actually perform export of place time-metrics
                exportPlaceMetrics(selectedFile);
            } else {
                if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) {
                    // actually perform export of transition time-metrics
                    exportTransitionMetrics(selectedFile);
                } else {
                    // actually perform export of activity time-metrics
                    exportActivityMetrics(selectedFile);
                }
            }
        } else {
            // file already exist, open a confirm dialog containing a
            // 'Yes' Button as well as a 'No' button
            int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?",
                    "Confirm Dialog", 0);
            if (overwrite == 0) {
                // user has selected Yes
                if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) {
                    // actually perform export of place time-metrics
                    exportPlaceMetrics(selectedFile);
                } else {
                    if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) {
                        // actually perform export of transition
                        // time-metrics
                        exportTransitionMetrics(selectedFile);
                    } else {
                        // actually perform export of activity time-metrics
                        exportActivityMetrics(selectedFile);
                    }
                }
            }
        }
    }
}

From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Creates a filechooser where the user can select the (comma-seperated)
 * file that he wants to export to. If this file already exists, permission
 * to overwrite is requested, else a new file is created to which the
 * throughput times of the selected process instances are exported.
 * //w ww.j a v a  2  s.  c  o m
 */
private void exportProcessMetrics() {
    // create and initialize the file chooser
    final JFileChooser fc = new JFileChooser();
    NameFilter filt1 = new NameFilter(".csv");
    NameFilter filt2 = new NameFilter(".txt");
    fc.addChoosableFileFilter(filt1);
    fc.addChoosableFileFilter(filt2);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileFilter(filt1);
    // check whether a place is selected
    int result = fc.showDialog(this, "Export");
    if (result == 0) {
        // Export-button was pushed
        File selectedFile = fc.getSelectedFile();
        if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) {
            // create new file, with filetype added to it
            selectedFile = new File(
                    selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1));
        }
        if (!selectedFile.exists()) {
            try {
                // actually export the throughput times to the file
                replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort,
                        advancedSettings[0]);
            } catch (IOException ex) {
                Message.add("IO exception: " + ex.toString(), 2);
            }
        } else {
            // file already exist, open a confirm dialog containing a
            // 'Yes' Button as well as a 'No' button
            int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?",
                    "Confirm Dialog", 0);
            if (overwrite == 0) {
                // user has selected Yes
                try {
                    // actually export the throughput times to the file
                    replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort,
                            advancedSettings[0]);
                } catch (IOException ex) {
                    Message.add("IO exception: " + ex.toString(), 2);
                }
            }
        }
    }
}

From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Creates a filechooser where the user can select the (comma-seperated)
 * file that he wants to export to. If this file already exists, permission
 * to overwrite is requested, else a new file is created to which the
 * time-metrics of the selected place/transitions are exported.
 *
 *///from www . j  a  v  a2s.c o  m
private void exportObjectMetrics() {
    //create and initialize the file chooser
    final JFileChooser fc = new JFileChooser();
    NameFilter filt1 = new NameFilter(".csv");
    NameFilter filt2 = new NameFilter(".txt");
    fc.addChoosableFileFilter(filt1);
    fc.addChoosableFileFilter(filt2);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileFilter(filt1);
    //check whether a place is selected
    int result = fc.showDialog(this, "Export");
    if (result == 0) {
        //Export-button was pushed
        File selectedFile = fc.getSelectedFile();
        if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) {
            //create new file, with filetype added to it
            selectedFile = new File(
                    selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1));
        }

        if (!selectedFile.exists()) {
            if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) {
                //actually perform export of place time-metrics
                exportPlaceMetrics(selectedFile);
            } else {
                if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) {
                    //actually perform export of transition time-metrics
                    exportTransitionMetrics(selectedFile);
                } else {
                    //actually perform export of activity time-metrics
                    exportActivityMetrics(selectedFile);
                }
            }
        } else {
            //file already exist, open a confirm dialog containing a
            //'Yes' Button as well as a 'No' button
            int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?",
                    "Confirm Dialog", 0);
            if (overwrite == 0) {
                //user has selected Yes
                if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) {
                    //actually perform export of place time-metrics
                    exportPlaceMetrics(selectedFile);
                } else {
                    if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) {
                        //actually perform export of transition time-metrics
                        exportTransitionMetrics(selectedFile);
                    } else {
                        //actually perform export of activity time-metrics
                        exportActivityMetrics(selectedFile);
                    }
                }
            }
        }
    }
}

From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Creates a filechooser where the user can select the (comma-seperated)
 * file that he wants to export to. If this file already exists, permission
 * to overwrite is requested, else a new file is created to which the
 * throughput times of the selected process instances are exported.
 *
 *//*from  ww w .  j av a 2 s.co m*/
private void exportProcessMetrics() {
    //create and initialize the file chooser
    final JFileChooser fc = new JFileChooser();
    NameFilter filt1 = new NameFilter(".csv");
    NameFilter filt2 = new NameFilter(".txt");
    fc.addChoosableFileFilter(filt1);
    fc.addChoosableFileFilter(filt2);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileFilter(filt1);
    //check whether a place is selected
    int result = fc.showDialog(this, "Export");
    if (result == 0) {
        //Export-button was pushed
        File selectedFile = fc.getSelectedFile();
        if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) {
            //create new file, with filetype added to it
            selectedFile = new File(
                    selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1));
        }
        if (!selectedFile.exists()) {
            try {
                //actually export the throughput times to the file
                replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort,
                        advancedSettings[0]);
            } catch (IOException ex) {
                Message.add("IO exception: " + ex.toString(), 2);
            }
        } else {
            //file already exist, open a confirm dialog containing a
            //'Yes' Button as well as a 'No' button
            int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?",
                    "Confirm Dialog", 0);
            if (overwrite == 0) {
                //user has selected Yes
                try {
                    //actually export the throughput times to the file
                    replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort,
                            advancedSettings[0]);
                } catch (IOException ex) {
                    Message.add("IO exception: " + ex.toString(), 2);
                }
            }
        }
    }
}

From source file:org.scify.talkandplay.gui.configuration.EntertainmentTab.java

private void setListeners() {

    musicPathTextField.addMouseListener(new MouseAdapter() {
        @Override/*from  www .  jav  a 2  s .  c  o m*/
        public void mouseClicked(MouseEvent me) {
            JFileChooser chooser = new JFileChooser();

            chooser.setDialogTitle(" ");
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                musicPathTextField.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    videoPathTextField.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            JFileChooser chooser = new JFileChooser();

            chooser.setDialogTitle(" ");
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                videoPathTextField.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    musicPathTextField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent fe) {
            if (" ".equals(musicPathTextField.getText())) {
                musicPathTextField.setText("");
            }
        }

        public void focusLost(FocusEvent fe) {
            if (musicPathTextField.getText().isEmpty()) {
                musicPathTextField.setText(" ");
            } else if (!musicPathTextField.getText().endsWith("/")) {
                musicPathTextField.setText(musicPathTextField.getText() + "/");
            }
        }
    });

    videoPathTextField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent fe) {
            if (" video".equals(videoPathTextField.getText())) {
                videoPathTextField.setText("");
            }
        }

        public void focusLost(FocusEvent fe) {
            if (videoPathTextField.getText().isEmpty()) {
                videoPathTextField.setText(" video");
            } else if (!videoPathTextField.getText().endsWith("/")) {
                videoPathTextField.setText(videoPathTextField.getText() + "/");
            }
        }
    });

    songSumTextField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent fe) {
            if ("".equals(songSumTextField.getText())) {
                songSumTextField.setText("");
            }
        }

        public void focusLost(FocusEvent fe) {
            if (songSumTextField.getText().isEmpty()) {
                songSumTextField.setText("");
            }
        }
    });

    backButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            parent.goBack();
        }
    });
}

From source file:org.scify.talkandplay.gui.users.UserFormPanel.java

private void uploadImageLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uploadImageLabelMouseClicked
    userImage = "";
    JFileChooser chooser = new JFileChooser();

    chooser.setDialogTitle(" ");
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(//from w w w  .  j a v  a  2 s  .  c o m
            new FileNameExtensionFilter("Image Files", "png", "jpg", "jpeg", "JPG", "JPEG", "gif"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        userImage = chooser.getSelectedFile().getAbsolutePath();
        uploadImageLabel.setIcon(guiHelper.getIcon(userImage));
    }
}

From source file:org.signserver.admin.gui.ViewCertificateFrame.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
    if (certificate != null) {
        final JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        final FileFilter pemFilter = new FileNameExtensionFilter("X.509 Certificate (PEM)", "pem");
        final FileFilter pemChainFilter = new FileNameExtensionFilter("X.509 Certificate with chain (PEM)",
                "pem");
        final FileFilter derFilter = new FileNameExtensionFilter("X.509 Certificate (DER)", "cer", "crt",
                "der");
        chooser.addChoosableFileFilter(pemFilter);
        chooser.addChoosableFileFilter(derFilter);
        chooser.addChoosableFileFilter(pemChainFilter);
        chooser.setDialogTitle("Save certificate as file");

        if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();

            try {
                if (chooser.getFileFilter() == derFilter) {
                    // DER file
                    FileUtils.writeByteArrayToFile(file, certificate.getEncoded());
                } else {
                    // PEM file
                    BufferedOutputStream out = null;
                    try {
                        out = new BufferedOutputStream(new FileOutputStream(file));
                        PEMWriter pemWriter = new PEMWriter(new OutputStreamWriter(out));
                        if (chooser.getFileFilter() == pemFilter) {
                            pemWriter.writeObject(certificate);
                        } else {
                            for (X509Certificate cert : certificates) {
                                pemWriter.writeObject(cert);
                            }/*from  w  ww  . j  a va  2s .com*/
                        }
                        pemWriter.close();
                    } finally {
                        IOUtils.closeQuietly(out);
                    }
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,
                        "Exporting certificate failed:\n" + ex.getLocalizedMessage(), "Export",
                        JOptionPane.ERROR_MESSAGE);
            } catch (CertificateEncodingException ex) {
                JOptionPane.showMessageDialog(this,
                        "Unable to encode certificate:\n" + ex.getLocalizedMessage(), "Export",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

From source file:org.surmon.pattern.importer.ImportAction.java

/**
 * Creates and shows import dialog. Also handles user interaction with the
 * dialog./*  w  ww.  ja va 2s.  c  o m*/
 */
public static void createAndShowDialog() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Import data");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(true);

    Collection<? extends PDataImporter> importers = Lookup.getDefault().lookupAll(PDataImporter.class);

    // find all importers and set the filters for open dialog
    for (PDataImporter importer : importers) {
        chooser.addChoosableFileFilter(importer.getExtensionFilter());
    }

    // open and wait for result
    int returnVal = chooser.showOpenDialog(null);

    // process the result from open dialog
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();

        if (file.exists()) {
            final String extension = FilenameUtils.getExtension(file.getName());
            final PDataImporter importer = selectImporter(importers, extension);
            if (importer != null) {
                executeImport(importer, file);
            } else {
                NotifyDescriptor nd = new NotifyDescriptor.Message(
                        "File " + extension + " doesn't contain image data or is not supported.");
                DialogDisplayer.getDefault().notify(nd);
            }
        }
    }
}