Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

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

Introduction

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

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

From source file:org.drools.mas.SimpleClient.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    JFileChooser openFileChooser = new JFileChooser();
    openFileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Model File", "mod"));

    int showDialog = openFileChooser.showDialog(this, "Open");
    if (showDialog == JFileChooser.APPROVE_OPTION) {
        try {/*from  ww w.j  a v a 2  s .co m*/
            File selectedFile = openFileChooser.getSelectedFile();
            if (!selectedFile.exists()) {
                JOptionPane.showMessageDialog(this, "File: " + selectedFile.getCanonicalPath(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            String toString = IOUtils.toString(new FileInputStream(selectedFile));

            List facts = (List) ObjectSerializerFactory.getObjectSerializerInstance().deserialize(toString);

            this.factTableModel.clear();
            for (Object fact : facts) {
                this.factTableModel.addFact(fact);
            }

            this.factTableModel.fireTableDataChanged();

            this.setTitle(selectedFile.getName());
        } catch (Exception ex) {
            Logger.getLogger(SimpleClient.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Error opening file: " + ex.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.esa.snap.core.gpf.ui.OperatorMenu.java

private FileNameExtensionFilter createParameterFileFilter() {
    return new FileNameExtensionFilter("GPF Parameter Files (XML)", "xml");
}

From source file:org.giswater.controller.MenuController.java

private String chooseSqlFile(boolean save) {

    String path = "";
    JFileChooser chooser = new JFileChooser();
    FileFilter filter = new FileNameExtensionFilter("SQL extension file", "sql");
    chooser.setFileFilter(filter);/*from  w w  w.  j a v a 2s . c o  m*/
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle(Utils.getBundleString("MenuController.file_sql"));
    File file = new File(PropertiesDao.getLastSqlPath());
    chooser.setCurrentDirectory(file.getParentFile());
    int returnVal;
    if (save) {
        returnVal = chooser.showSaveDialog(mainFrame);
    } else {
        returnVal = chooser.showOpenDialog(mainFrame);
    }
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileSql = chooser.getSelectedFile();
        path = fileSql.getAbsolutePath();
        if (path.lastIndexOf(".") == -1) {
            path += ".sql";
            fileSql = new File(path);
        }
        PropertiesDao.setLastSqlPath(path);
    }
    return path;

}

From source file:org.giswater.controller.MenuController.java

private File gswChooseFile(boolean save) {

    String path = "";
    File file = null;//w  ww  .ja v a2 s.c  o m
    JFileChooser chooser = new JFileChooser();
    FileFilter filter = new FileNameExtensionFilter("GSW extension file", "gsw");
    chooser.setFileFilter(filter);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle(Utils.getBundleString("MenuController.gsw_file"));
    File fileProp = new File(prop.get("FILE_GSW", Utils.getLogFolder()));
    chooser.setCurrentDirectory(fileProp.getParentFile());
    int returnVal;
    if (save) {
        returnVal = chooser.showSaveDialog(mainFrame);
    } else {
        returnVal = chooser.showOpenDialog(mainFrame);
    }
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        path = file.getAbsolutePath();
        if (path.lastIndexOf(".") == -1) {
            path += ".gsw";
            file = new File(path);
        }
    }

    return file;

}

From source file:org.giswater.controller.MenuController.java

private String chooseFileSetup(String fileName) {

    String path = "";
    JFileChooser chooser = new JFileChooser();
    FileFilter filter = new FileNameExtensionFilter("EXE extension file", "exe");
    chooser.setFileFilter(filter);//  w  w  w . j a  v a2  s .  co  m
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle(Utils.getBundleString("file_exe"));
    File file = new File(usersFolder + fileName);
    chooser.setCurrentDirectory(file);
    chooser.setSelectedFile(file);
    int returnVal = chooser.showOpenDialog(mainFrame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileSql = chooser.getSelectedFile();
        path = fileSql.getAbsolutePath();
        if (path.lastIndexOf(".") == -1) {
            path += ".exe";
            fileSql = new File(path);
        }
    }
    return path;

}

From source file:org.graphwalker.GUI.App.java

private void load() {
    status.setStopped();//from ww w.  ja v a2s.co  m
    statusBar.setMessage("Stopped");

    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("XML files", "xml");
    fileChooser.setFileFilter(filter);
    int returnVal = fileChooser.showOpenDialog(getContentPane());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        xmlFile = fileChooser.getSelectedFile();
        logger.debug("Got file: " + xmlFile.getAbsolutePath());
        loadModel();
        if (appEvent != null) {
            appEvent.getLoadEvent();
        }
    }
}

From source file:org.gtdfree.GTDFree.java

private JFileChooser getFileChooser() {
    if (fileChooser == null) {
        fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(new File(System.getProperty("user.home", "."))); //$NON-NLS-1$ //$NON-NLS-2$
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setFileHidingEnabled(false);
        fileChooser.setFileFilter(new FileNameExtensionFilter(Messages.getString("GTDFree.FileFilter"), "xml")); //$NON-NLS-1$ //$NON-NLS-2$
    }//  w  ww .j av a 2  s .co  m
    return fileChooser;
}

From source file:org.jwebsocket.ui.TestDialog.java

/**
 *
 * @param aDefaultFilename// w  w  w.ja  v  a  2  s . c o  m
 */
public void saveLogs(String aDefaultFilename) {
    if (aDefaultFilename == null || aDefaultFilename.equals("")) {
        aDefaultFilename = "jWebSocketTests_" + new SimpleDateFormat("YYYY-MM-dd").format(new Date()) + ".log";
    }
    JFileChooser lChooser = new JFileChooser();
    FileNameExtensionFilter lFilter = new FileNameExtensionFilter("*.log files", "log");
    lChooser.setFileFilter(lFilter);
    lChooser.setSelectedFile(new File(aDefaultFilename));
    int lReturnVal = lChooser.showSaveDialog(this);
    if (lReturnVal == JFileChooser.APPROVE_OPTION) {
        FileWriter lWriter = null;
        try {
            File lFile = lChooser.getSelectedFile();
            lWriter = new FileWriter(lFile);
            lWriter.write(txaLog.getText());
        } catch (IOException aException) {
            mLog(aException.getMessage());
        } finally {
            try {
                if (lWriter != null) {
                    lWriter.close();
                }
            } catch (IOException aIoException) {
                mLog(aIoException.getMessage());
            }
        }
    }
}

From source file:org.lz1aq.jatu.SimpleRadioPanel.java

/**
 * Method called within the constructor to do initializations different than
 * the ones done by the Form Editor/*from w w  w  .ja v a 2s.c  o  m*/
 */
private void init() {
    // Configure the FileChooser
    this.chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter("Python files", "py"));
    chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));

}

From source file:org.p_vcd.ui.VcdDialog.java

private void selectFileButton() {
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);/*from  w w w.  j av a  2s. c om*/
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(
            new FileNameExtensionFilter("images and videos", Parameters.get().getImageAndVideoExtensions()));
    File def = Parameters.get().getDefaultDir_QuerySelection();
    if (def != null)
        fc.setCurrentDirectory(def);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Parameters.get().updateDefaultDir_QuerySelection(fc.getCurrentDirectory());
        queryFile = fc.getSelectedFile();
        lbl_queryFile.setText(queryFile.getAbsolutePath());
        radio_queryFile.setSelected(true);
    }
}