Example usage for org.jfree.ui FilesystemFilter FilesystemFilter

List of usage examples for org.jfree.ui FilesystemFilter FilesystemFilter

Introduction

In this page you can find the example usage for org.jfree.ui FilesystemFilter FilesystemFilter.

Prototype

public FilesystemFilter(final String fileext, final String descr) 

Source Link

Document

Creates a new filter.

Usage

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   w  w  w. jav a  2s .c  o m
            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:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveReference(boolean mustSupportEvaluation, boolean includeEvaluation)
        throws FileNotFoundException {
    Set<ReferenceFormat> formats = mustSupportEvaluation
            ? ReferenceFormats.REFERENCE_FORMATS.evaluationIncludingFormats
            : ReferenceFormats.REFERENCE_FORMATS.formats;
    formats.retainAll(ReferenceFormats.REFERENCE_FORMATS.writeableFormats);

    ReferenceFormat format = formatChooser(formats);
    if (format == null) {
        return;// www.  j  a  va2s. c  o  m
    }

    JFileChooser chooser = new JFileChooser("Save reference. Please choose a file.");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    chooser.setFileSelectionMode(
            format.readsDirectory() ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
    if (format.getFileExtension() != null) {
        chooser.addChoosableFileFilter(
                new FilesystemFilter(format.getFileExtension(), format.getDescription()));
    } else {
        chooser.setAcceptAllFileFilterUsed(true);
    }

    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    System.out.print("Saving...");
    format.writeReference(frame.reference, chooser.getSelectedFile(), includeEvaluation);
    //frame.loadPositiveNegativeNT(chooser.getSelectedFile());
    System.out.println("saving finished.");
}