Example usage for javax.swing.filechooser FileFilter FileFilter

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

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java

/**
 * Creates new form WebDavPicturePanel.// ww w. j a  v a 2s  .com
 *
 * @param  editable           DOCUMENT ME!
 * @param  urlProp            DOCUMENT ME!
 * @param  beanCollProp       DOCUMENT ME!
 * @param  bildClassName      DOCUMENT ME!
 * @param  numberProp         DOCUMENT ME!
 * @param  geoFieldProp       DOCUMENT ME!
 * @param  connectionContext  DOCUMENT ME!
 */
public WebDavPicturePanel(final boolean editable, final String urlProp, final String beanCollProp,
        final String bildClassName, final String numberProp, final String geoFieldProp,
        final ConnectionContext connectionContext) {
    this.beanCollProp = beanCollProp;
    this.bildClassName = bildClassName;
    this.numberProp = numberProp;
    this.geoFieldProp = geoFieldProp;
    this.connectionContext = connectionContext;

    String webdavDirectory = null;
    WebDavHelper webdavHelper = null;
    try {
        final ResourceBundle bundle = ResourceBundle.getBundle("WebDav");
        String pass = bundle.getString("password");

        if ((pass != null) && pass.startsWith(PasswordEncrypter.CRYPT_PREFIX)) {
            pass = PasswordEncrypter.decryptString(pass);
        }
        final String user = bundle.getString("user");
        webdavDirectory = bundle.getString(urlProp);

        webdavHelper = new WebDavHelper(Proxy.fromPreferences(), user, pass, false);
    } catch (final Exception ex) {
        final String message = "Fehler beim Initialisieren der Bilderablage.";
        LOG.error(message, ex);
        ObjectRendererUtils.showExceptionWindowToUser(message, ex, null);
    }
    this.webdavDirectory = webdavDirectory;
    this.webdavHelper = webdavHelper;

    initComponents();

    fileChooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(final File f) {
            return f.isDirectory() || IMAGE_FILE_PATTERN.matcher(f.getName()).matches();
        }

        @Override
        public String getDescription() {
            return "Bilddateien";
        }
    });
    fileChooser.setMultiSelectionEnabled(true);

    listRepaintListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            lstFotos.repaint();
        }
    };

    lstFotos.getModel().addListDataListener(new ListDataListener() {

        @Override
        public void intervalAdded(final ListDataEvent e) {
            defineButtonStatus();
        }

        @Override
        public void intervalRemoved(final ListDataEvent e) {
            defineButtonStatus();
        }

        @Override
        public void contentsChanged(final ListDataEvent e) {
            defineButtonStatus();
        }
    });

    timer = new Timer(300, new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (resizeListenerEnabled) {
                //                    if (isShowing()) {
                if (currentResizeWorker != null) {
                    currentResizeWorker.cancel(true);
                }
                currentResizeWorker = new ImageResizeWorker();
                CismetThreadPool.execute(currentResizeWorker);
                //                    } else {
                //                        timer.restart();
                //                    }
            }
        }
    });
    timer.setRepeats(false);

    btnAddImg.setVisible(editable);
    btnRemoveImg.setVisible(editable);
}

From source file:jboost.visualization.HistogramFrame.java

private File selectPDFFile() {

    File fFile = new File("default.pdf");
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            String path = f.getAbsolutePath();
            if (f.isDirectory() || path.endsWith(".pdf"))
                return true;
            else//from  w ww . j a  v  a  2  s . c o m
                return false;
        }

        public String getDescription() {
            return "PDF Files";
        }
    });

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
        return null;
    } else if (result == JFileChooser.APPROVE_OPTION) {
        fFile = fc.getSelectedFile();
        if (fFile.exists()) {
            int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION)
                return null;
        }
        return fFile;
    } else {
        return null;
    }
}

From source file:jboost.visualization.HistogramFrame.java

private File selectDumpFile() {

    File fFile = new File("ExamplesDumpFile.txt");
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            String path = f.getAbsolutePath();
            if (f.isDirectory() || path.endsWith(".txt"))
                return true;
            else/*from  w  w w  .  j av  a  2 s .co  m*/
                return false;
        }

        public String getDescription() {
            return "Text Files";
        }
    });

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
        return null;
    } else if (result == JFileChooser.APPROVE_OPTION) {
        fFile = fc.getSelectedFile();
        if (fFile.exists()) {
            int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION)
                return null;
        }
        return fFile;
    } else {
        return null;
    }
}

From source file:lu.fisch.moenagade.model.Project.java

public void openImage(Frame frame) {
    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(lastOpenedImage));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {
        @Override//from   w w w . j a  va  2  s.  c o m
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("png") || extension.equals("jpg") || extension.equals("jpeg")) {
                    return true;
                } else {
                    return false;
                }
            }

            return false;
        }

        @Override
        public String getDescription() {
            return "Supported image files (*.jpg, *.png)";
        }
    });
    int returnVal = fc.showDialog(frame, "Add image");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        loadImage(fc.getSelectedFile());
    }

}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

@Override
public Collection<Throwable> call() throws Exception {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    List<BamFileRef> bams = new ArrayList<BamFileRef>();

    final List<String> args = getInputFiles();
    List<File> IN = new ArrayList<File>();

    if (args.isEmpty()) {
        LOG.info("NO BAM provided; Opening dialog");
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileFilter() {
            @Override/*from ww  w.ja  v  a2s  .  co  m*/
            public String getDescription() {
                return "Indexed BAM files.";
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory())
                    return true;
                return acceptBam(f);
            };
        });
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
            return wrapException("user pressed cancel");
        }
        File fs[] = chooser.getSelectedFiles();
        if (fs != null)
            IN.addAll(Arrays.asList(chooser.getSelectedFiles()));
    } else {
        for (String arg : args) {
            File filename = new File(arg);
            if (!acceptBam(filename)) {
                return wrapException(
                        "Cannot use " + filename + " as input Bam. bad extenstion ? index missing ?");
            }
            IN.add(filename);
        }
    }

    for (File in : IN) {
        try {
            bams.add(create(in));
        } catch (Exception err) {
            return wrapException(err);
        }
    }
    if (bams.isEmpty()) {
        return wrapException("No Bam file");
    }
    LOG.info("showing BAM frame");
    final BamFrame frame = new BamFrame(bams);
    frame.igvIP = super.IGV_HOST;
    frame.igvPort = super.IGV_PORT;
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                frame.setBounds(50, 50, screen.width - 100, screen.height - 100);
                frame.setVisible(true);
            }
        });
    } catch (Exception err) {
        err.printStackTrace();
        System.exit(-1);
    }

    return RETURN_OK;
}

From source file:lu.fisch.moenagade.model.Project.java

public void openSound(Frame frame) {
    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(lastOpenedSound));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {
        @Override/*from  w  w w.  ja  v a 2 s  . c  o  m*/
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("wav")) {
                    return true;
                } else {
                    return false;
                }
            }

            return false;
        }

        @Override
        public String getDescription() {
            return "Supported sound files (*.wav)";
        }
    });
    int returnVal = fc.showDialog(frame, "Add sound");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        loadSound(fc.getSelectedFile());
    }

}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

private void fireSaveScreenshotEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireSaveScreenshotEvent
    String dir = GlobalOptions.getProperty("screen.dir");

    JFileChooser chooser = null;//from   w w w .  j  av a 2  s .  c  o m
    try {
        chooser = new JFileChooser(dir);
    } catch (Exception e) {
        JOptionPaneHelper.showErrorBox(this,
                "Konnte Dateiauswahldialog nicht ffnen.\nMglicherweise verwendest du Windows Vista. Ist dies der Fall, beende DS Workbench, klicke mit der rechten Maustaste auf DSWorkbench.exe,\n"
                        + "whle 'Eigenschaften' und deaktiviere dort unter 'Kompatibilitt' den Windows XP Kompatibilittsmodus.",
                "Fehler");
        return;
    }
    chooser.setDialogTitle("Speichern unter...");
    chooser.setSelectedFile(new File("map"));

    final String type = (String) jFileTypeChooser.getSelectedItem();
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(type));
        }

        @Override
        public String getDescription() {
            return "*." + type;
        }
    });

    int ret = chooser.showSaveDialog(jScreenshotControl);

    if (ret == JFileChooser.APPROVE_OPTION) {
        try {
            File f = chooser.getSelectedFile();
            String file = f.getCanonicalPath();
            if (!file.endsWith(type)) {
                file += "." + type;
            }
            File target = new File(file);
            if (target.exists()) {
                //ask if overwrite
                if (JOptionPaneHelper.showQuestionConfirmBox(jScreenshotControl,
                        "Existierende Datei berschreiben?", "berschreiben", "Nein",
                        "Ja") != JOptionPane.YES_OPTION) {
                    return;
                }
            }
            ImageIO.write(mScreenshotPanel.getResult(jTransparancySlider.getValue()), type, target);
            GlobalOptions.addProperty("screen.dir", target.getParent());

        } catch (Exception e) {
            logger.error("Failed to write map shot", e);
        }
    }
}

From source file:com.jug.MoMA.java

/**
 * Shows a JFileChooser set up to accept the selection of folders. If
 * 'cancel' is pressed this method terminates the MotherMachine app.
 *
 * @param guiFrame/*from  w w  w  .  j a v a 2  s.co m*/
 *            parent frame
 * @param path
 *            path to the folder to open initially
 * @return an instance of {@link File} pointing at the selected folder.
 */
private File showFolderChooser(final JFrame guiFrame, final String path) {
    File selectedFile = null;

    if (SystemUtils.IS_OS_MAC) {
        // --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS ---
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        final FileDialog fd = new FileDialog(guiFrame, "Select folder containing image sequence...",
                FileDialog.LOAD);
        fd.setDirectory(path);
        //         fd.setLocation(50,50);
        fd.setVisible(true);
        selectedFile = new File(fd.getDirectory() + "/" + fd.getFile());
        if (fd.getFile() == null) {
            System.exit(0);
            return null;
        }
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
    } else {
        // --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC ---
        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File(path));
        chooser.setDialogTitle("Select folder containing image sequence...");
        chooser.setFileFilter(new FileFilter() {

            @Override
            public final boolean accept(final File file) {
                return file.isDirectory();
            }

            @Override
            public String getDescription() {
                return "We only take directories";
            }
        });
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) {
            selectedFile = chooser.getSelectedFile();
        } else {
            System.exit(0);
            return null;
        }
    }

    return selectedFile;
}

From source file:net.sourceforge.entrainer.gui.EntrainerFX.java

private JFileChooser getWavFileChooser() {
    JFileChooser wavChooser = new JFileChooser(new File(System.getProperty("user.dir") + "/wav"));
    wavChooser.setDialogTitle("WAV File Chooser, select or enter WAV file for recording");

    wavChooser.setFileFilter(new FileFilter() {
        @Override//from   ww  w . ja va  2  s.co m
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().indexOf(".wav") > 0;
        }

        @Override
        public String getDescription() {
            return "WAV files";
        }
    });

    return wavChooser;
}

From source file:com.lfv.lanzius.server.LanziusServer.java

private void menuChoiceLoadConfiguration() {
    if (isSwapping)
        return;//from w ww  .  j  av a 2  s. com
    log.info("Menu: Load configuration");
    JFileChooser fc = new JFileChooser("data/configurations");
    fc.setDialogTitle("Load configuration...");
    fc.setMultiSelectionEnabled(false);
    fc.setFileFilter(new FileFilter() {
        public boolean accept(File f) {
            return !f.isHidden() && (f.isDirectory() || f.getName().endsWith(".xml"));
        }

        public String getDescription() {
            return "Configuration (*.xml)";
        }
    });

    int returnVal = JFileChooser.APPROVE_OPTION;
    if (Config.SERVER_AUTOLOAD_CONFIGURATION == null)
        returnVal = fc.showOpenDialog(frame);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file;
        if (Config.SERVER_AUTOLOAD_CONFIGURATION == null)
            file = fc.getSelectedFile();
        else
            file = new File(Config.SERVER_AUTOLOAD_CONFIGURATION);
        log.info("Loading configuration " + file);
        if (file.exists()) {
            if (buildConfigurationDocument(file)) {
                isConfigLoaded = true;
                updateView();
            } else
                JOptionPane.showMessageDialog(frame,
                        "Invalid configuration file! Make sure that all required tags are defined!", "Error!",
                        JOptionPane.ERROR_MESSAGE);
        } else
            JOptionPane.showMessageDialog(frame, "Unable to load configuration! File not found!", "Error!",
                    JOptionPane.ERROR_MESSAGE);
    }
}