Example usage for javax.swing.filechooser FileFilter equals

List of usage examples for javax.swing.filechooser FileFilter equals

Introduction

In this page you can find the example usage for javax.swing.filechooser FileFilter equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.fhaes.jsea.JSEAFrame.java

/**
 * Initialize the menu/toolbar actions.//from   w  w w.  j a  v a 2s .  c o m
 */
private void initActions() {

    final JFrame glue = this;

    actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            dispose();
        }
    };

    actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            ChartEditor editor = ChartEditorManager
                    .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart());
            int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE);
            if (result == JOptionPane.OK_OPTION) {
                editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart());
            }
        }
    };

    actionReset = new FHAESAction("Reset", "filenew.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            Object[] options = { "Yes", "No", "Cancel" };
            int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?",
                    "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                    options[2]);

            if (n == JOptionPane.YES_OPTION) {
                setToDefault();
            }
        }
    };

    actionRun = new FHAESAction("Run analysis", "run.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            runAnalysis();
        }
    };

    actionSaveAll = new FHAESAction("Save all results", "save_all.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            File f;
            try {
                f = new File(file.getAbsolutePath() + File.separator + "report.txt");
                saveReportTXT(f);

                f = new File(file.getAbsolutePath() + File.separator + "report.pdf");
                saveReportPDF(f);

                f = new File(file.getAbsolutePath() + File.separator + "chart.png");
                saveChartPNG(f);

                f = new File(file.getAbsolutePath() + File.separator + "chart.pdf");
                saveChartPDF(f);

                f = new File(file.getAbsolutePath() + File.separator + "data.xls");
                saveDataXLS(f);

                f = new File(file.getAbsolutePath());
                saveDataCSV(f);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    actionSaveData = new FHAESAction("Save data tables", "table.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            try {
                saveDataCSV(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    actionSaveReport = new FHAESAction("Save report", "report.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            // Set file filters
            fc.setAcceptAllFileFilterUsed(false);
            TXTFileFilter txtfilter = new TXTFileFilter();
            PDFFilter pdffilter = new PDFFilter();
            fc.addChoosableFileFilter(txtfilter);
            fc.addChoosableFileFilter(pdffilter);
            fc.setFileFilter(txtfilter);
            FileFilter chosenFilter;

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                chosenFilter = fc.getFileFilter();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            // Handle file type and extensions nicely
            if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) {
                if (chosenFilter.equals(txtfilter)) {
                    file = new File(file.getAbsoluteFile() + ".txt");
                } else if (chosenFilter.equals(pdffilter)) {
                    file = new File(file.getAbsoluteFile() + ".pdf");
                }
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt")
                    && chosenFilter.equals("pdf")) {
                chosenFilter = txtfilter;
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf")
                    && chosenFilter.equals("txt")) {
                chosenFilter = pdffilter;
            }

            // If file already exists confirm overwrite
            if (file.exists()) {
                // Check we have write access to this file
                if (!file.canWrite()) {
                    JOptionPane.showMessageDialog(glue, "You do not have write permission to this file",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int n = JOptionPane.showConfirmDialog(glue,
                        "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?",
                        "Overwrite file?", JOptionPane.YES_NO_OPTION);
                if (n != JOptionPane.YES_OPTION) {
                    return;
                }
            }

            // Do save
            try {

                if (chosenFilter.equals(txtfilter)) {
                    saveReportTXT(file);
                } else if (chosenFilter.equals(pdffilter)) {
                    saveReportPDF(file);
                } else {
                    log.error("No export file format chosen.  Shouldn't be able to get here!");
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(glue, "Unable to save report.  Check log file.", "Warning",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }

        }
    };

    actionSaveChart = new FHAESAction("Save chart", "barchart.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            // Set file filters
            fc.setAcceptAllFileFilterUsed(false);
            PNGFilter pngfilter = new PNGFilter();
            PDFFilter pdffilter = new PDFFilter();
            fc.addChoosableFileFilter(pngfilter);
            fc.addChoosableFileFilter(pdffilter);
            fc.setFileFilter(pngfilter);
            FileFilter chosenFilter;

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                chosenFilter = fc.getFileFilter();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            // Handle file type and extensions nicely
            if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) {
                if (chosenFilter.equals(pngfilter)) {
                    file = new File(file.getAbsoluteFile() + ".png");
                } else if (chosenFilter.equals(pdffilter)) {
                    file = new File(file.getAbsoluteFile() + ".pdf");
                }
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png")
                    && chosenFilter.equals("pdf")) {
                chosenFilter = pngfilter;
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf")
                    && chosenFilter.equals("png")) {
                chosenFilter = pdffilter;
            }

            // If file already exists confirm overwrite
            if (file.exists()) {
                // Check we have write access to this file
                if (!file.canWrite()) {
                    JOptionPane.showMessageDialog(glue, "You do not have write permission to this file",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int n = JOptionPane.showConfirmDialog(glue,
                        "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?",
                        "Overwrite file?", JOptionPane.YES_NO_OPTION);
                if (n != JOptionPane.YES_OPTION) {
                    return;
                }
            }

            // Do save
            try {

                if (chosenFilter.equals(pngfilter)) {
                    saveChartPNG(file);

                } else if (chosenFilter.equals(pdffilter)) {

                    saveChartPDF(file);
                } else {
                    log.error("No export file format chosen.  Shouldn't be able to get here!");
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(glue, "Unable to save chart.  Check log file.", "Warning",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }

        }
    };

    actionCopy = new FHAESAction("Copy", "edit_copy.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            copyCurrentSelectionToClipboard();
        }
    };

    actionLagMap = new FHAESAction("LagMap", "lagmap22.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            launchLagMap();
        }
    };

}

From source file:org.openmicroscopy.shoola.util.ui.filechooser.CustomizedFileChooser.java

/**
 * Returns the format corresponding to the specified filter.
 * //  www. ja va  2 s.  c o  m
 * @param selectedFilter The filter specified.
 * @return See above.
 */
private String getFormat(FileFilter selectedFilter) {
    List<FileFilter> filters = model.getFilters();
    if (filters == null)
        return "";
    for (FileFilter filter : filters) {
        if (selectedFilter.equals(filter))
            return filter.getDescription();
    }
    return "";
}

From source file:org.openmicroscopy.shoola.util.ui.filechooser.CustomizedFileChooser.java

/**
 * Returns the extension corresponding to the specified filter.
 * /*from ww  w. jav a 2  s . c om*/
 * @param selectedFilter The filter specified.
 * @return See above.
 */
private String getExtension(FileFilter selectedFilter) {
    List<FileFilter> filters = model.getFilters();
    if (filters == null)
        return "";
    for (FileFilter filter : filters) {
        if (selectedFilter.equals(filter) && filter instanceof CustomizedFileFilter)
            return ((CustomizedFileFilter) filter).getExtension();
    }
    return "";
}