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:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java

private void actLoadQuery() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("."));
    fc.setDialogTitle("Load query");
    int returnVal = fc.showOpenDialog(this);
    FileFilter filter = new FileFilter() {
        @Override/*from  w w  w .ja  v  a  2 s .co m*/
        public boolean accept(File f) {
            return f.getAbsolutePath().endsWith(".xml");
        }

        @Override
        public String getDescription() {
            return "xml";
        }
    };
    fc.setFileFilter(filter);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        loadQuery(file);
    }
    updateActions();
    updateStatus();
}

From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java

private void actLoadData() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("."));
    fc.setDialogTitle("Load graph");
    int returnVal = fc.showOpenDialog(this);
    FileFilter filter = new FileFilter() {
        @Override//from   w  ww .  j a  v a2  s  . c o  m
        public boolean accept(File f) {
            return f.getAbsolutePath().endsWith(".graphml");
        }

        @Override
        public String getDescription() {
            return "graphml files";
        }
    };
    fc.setFileFilter(filter);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        loadData(file);
    }
    updateActions();
    updateStatus();
}

From source file:nz.co.fortytwo.freeboard.installer.InstalManager.java

private void addWidgets() {

    JTabbedPane tabPane = new JTabbedPane();
    this.add(tabPane, BorderLayout.CENTER);
    // upload to arduinos
    JPanel uploadPanel = new JPanel();
    uploadPanel.setLayout(new BorderLayout());
    uploadPanel.add(uploadingPanel, BorderLayout.CENTER);
    final JPanel westUploadPanel = new JPanel(new MigLayout());

    String info = "\nUse this panel to upload compiled code to the arduino devices.\n\n"
            + "NOTE: directories with spaces will probably not work!\n\n"
            + "First select the base directory of your Arduino IDE installation, eg C:/devtools/arduino-1.5.2\n\n"
            + "Then select target files to upload, these are ended in '.hex'\n"
            + "\nand can be downloaded from github (https://github.com/rob42),\n"
            + " see the 'Release*' sub-directories\n\n"
            + "Output of the process will display in the right-side window\n\n";
    JTextArea jTextInfo = new JTextArea(info);
    jTextInfo.setEditable(false);//from   w w  w .  java  2s.  c om
    westUploadPanel.add(jTextInfo, "span,wrap");

    westUploadPanel.add(new JLabel("Select Arduino IDE directory:"), "wrap");
    arduinoDirTextField.setEditable(false);
    westUploadPanel.add(arduinoDirTextField, "span 2");
    arduinoIdeChooser.setApproveButtonText("Select");
    arduinoIdeChooser.setAcceptAllFileFilterUsed(false);
    arduinoIdeChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    arduinoIdeChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {

                toolsDir = new File(arduinoIdeChooser.getSelectedFile(),
                        File.separator + "hardware" + File.separator + "tools" + File.separator);
                if (!toolsDir.exists()) {
                    toolsDir = null;
                    JOptionPane.showMessageDialog(westUploadPanel, "Not a valid Arduino IDE directory");
                    return;
                }
                arduinoDirTextField.setText(arduinoIdeChooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    JButton arduinoDirButton = new JButton("Select");
    arduinoDirButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            arduinoIdeChooser.showDialog(westUploadPanel, "Select");

        }
    });
    westUploadPanel.add(arduinoDirButton, "wrap");

    westUploadPanel.add(new JLabel("Select comm port:"));
    westUploadPanel.add(portComboBox, "wrap");

    westUploadPanel.add(new JLabel("Select device:"), "gap unrelated");
    westUploadPanel.add(deviceComboBox, "wrap");

    hexFileChooser.setApproveButtonText("Upload");
    hexFileChooser.setAcceptAllFileFilterUsed(false);
    hexFileChooser.addChoosableFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "*.hex - Hex file";
        }

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            if (f.getName().toUpperCase().endsWith(".HEX")) {
                return true;
            }
            return false;
        }
    });
    westUploadPanel.add(hexFileChooser, "span, wrap");

    uploadPanel.add(westUploadPanel, BorderLayout.WEST);
    tabPane.addTab("Upload", uploadPanel);

    // charts
    JPanel chartPanel = new JPanel();
    chartPanel.setLayout(new BorderLayout());
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Charts", "tiff", "kap", "KAP", "TIFF", "tif",
            "TIF");
    chartFileChooser.setFileFilter(filter);
    chartFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chartFileChooser.setMultiSelectionEnabled(true);
    final JPanel chartWestPanel = new JPanel(new MigLayout());
    String info2 = "\nUse this panel to convert charts into the correct format for FreeBoard.\n"
            + "\nYou need to select the charts or directories containing charts, then click 'Process'.\n "
            + "\nThe results will be in a directory with the same name as the chart, and the chart "
            + "\ndirectory will also be compressed into a zip file ready to transfer to your FreeBoard "
            + "\nserver\n" + "\nOutput of the process will display in the right-side window\n\n";
    JTextArea jTextInfo2 = new JTextArea(info2);
    jTextInfo2.setEditable(false);
    chartWestPanel.add(jTextInfo2, "wrap");

    chartFileChooser.setApproveButtonText("Process");
    chartWestPanel.add(chartFileChooser, "span,wrap");

    final JPanel loggingPanel = new JPanel(new MigLayout());
    loggingGroup.add(infoButton);
    loggingGroup.add(debugButton);
    debugButton.setSelected(logger.isDebugEnabled());
    infoButton.setSelected(!logger.isDebugEnabled());
    infoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (infoButton.isSelected()) {
                LogManager.getRootLogger().setLevel(Level.INFO);
            }
        }
    });
    debugButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (debugButton.isSelected()) {
                LogManager.getRootLogger().setLevel(Level.DEBUG);
            }
        }
    });

    loggingPanel.add(new JLabel("Logging Level"));
    loggingPanel.add(infoButton);
    loggingPanel.add(debugButton);
    chartWestPanel.add(loggingPanel, "span,wrap");

    final JPanel transparentPanel = new JPanel(new MigLayout());
    charsetGroup.add(utf8Button);
    charsetGroup.add(iso8859Button);
    iso8859Button.setSelected(logger.isDebugEnabled());
    utf8Button.setSelected(!logger.isDebugEnabled());
    utf8Button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (utf8Button.isSelected()) {
                charset = "UTF-8";
            }
        }
    });
    iso8859Button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (iso8859Button.isSelected()) {
                charset = "ISO-8859-1";
            }
        }
    });

    transparentPanel.add(new JLabel("KAP Character set:"));
    transparentPanel.add(utf8Button);
    transparentPanel.add(iso8859Button);
    chartWestPanel.add(transparentPanel);

    chartPanel.add(chartWestPanel, BorderLayout.WEST);
    chartPanel.add(processingPanel, BorderLayout.CENTER);
    tabPane.addTab("Charts", chartPanel);

    // IMU calibration
    JPanel calPanel = new JPanel();
    calPanel.setLayout(new BorderLayout());
    JPanel westCalPanel = new JPanel(new MigLayout());
    String info3 = "\nUse this panel to calibrate your ArduIMU.\n"
            + "\nYou should do this as near to the final location as possible,\n"
            + "and like all compasses, as far from wires and magnetic materials \n" + "as possible.\n"
            + "\nSelect your comm port, then click 'Start'.\n "
            + "\nSmoothly and steadily rotate the ArduIMU around all 3 axes (x,y,z)\n"
            + "several times. Then press stop and the calibration will be performed and\n"
            + "uploaded to the ArduIMU\n\n" + "Output of the process will display in the right-side window\n\n";
    JTextArea jTextInfo3 = new JTextArea(info3);
    jTextInfo3.setEditable(false);
    westCalPanel.add(jTextInfo3, "span, wrap");
    westCalPanel.add(new JLabel("Select comm port:"));

    westCalPanel.add(portComboBox1, "wrap");
    JButton startCal = new JButton("Start");
    startCal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            calibrationPanel.process((String) portComboBox.getSelectedItem());
        }
    });
    westCalPanel.add(startCal);
    JButton stopCal = new JButton("Stop");
    stopCal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            calibrationPanel.stopProcess();
        }
    });
    westCalPanel.add(stopCal);

    calPanel.add(westCalPanel, BorderLayout.WEST);
    calPanel.add(calibrationPanel, BorderLayout.CENTER);

    tabPane.addTab("Calibration", calPanel);

}

From source file:org.ayound.js.debug.ui.DebugMainFrame.java

private void initAction() {
    actionOpen = new AbstractAction(Messages.getString("DebugMainFrame.Open")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser(); // 
            fileDialog.setFileFilter(new FileFilter() {

                @Override/*from   ww w.j av  a  2 s. c o m*/
                public boolean accept(File f) {
                    String fileName = f.getName().toLowerCase();
                    if (fileName.endsWith(".htm") //$NON-NLS-1$
                            || fileName.endsWith(".html") //$NON-NLS-1$
                            || fileName.endsWith(".js") || f.isDirectory()) { //$NON-NLS-1$
                        return true;
                    } else {
                        return false;
                    }

                }

                @Override
                public String getDescription() {
                    return ".htm,.html,.js"; //$NON-NLS-1$
                }
            });
            int result = fileDialog.showOpenDialog(DebugMainFrame.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                openHtmlFile(fileDialog.getSelectedFile());
            }

        }
    };
    actionClose = new AbstractAction(Messages.getString("DebugMainFrame.Close")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            int index = mainPane.getSelectedIndex();
            if (index > -1) {
                mainPane.remove(index);
            }
        }
    };
    actionExit = new AbstractAction(Messages.getString("DebugMainFrame.Exit")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    ImageIcon startIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/launch_run.gif")); //$NON-NLS-1$
    actionDebugStart = new AbstractAction(Messages.getString("DebugMainFrame.Start"), startIcon) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            startDebug();
        }
    };
    ImageIcon endIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/terminate_co.gif")); //$NON-NLS-1$
    actionDebugEnd = new AbstractAction(Messages.getString("DebugMainFrame.End"), endIcon) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            endDebug();
        }
    };
    actionDebugEnd.setEnabled(false);
    actionHelp = new AbstractAction(Messages.getString("DebugMainFrame.Content")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            String locale = DebugMainFrame.this.getLocale().toString();
            String helpPath = "help/index_" + locale + ".html";
            File testFile = new File(new File(getBaseDir()), helpPath); //$NON-NLS-1$
            final String url = "file:///" + testFile.getAbsolutePath().replace('\\', '/'); //$NON-NLS-1$

            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    try {
                        // TODO Auto-generated method stub
                        JFrame someWindow = new JFrame();
                        JEditorPane htmlPane = new JEditorPane(url);
                        htmlPane.setEditable(false);
                        someWindow.setSize(800, 600);
                        someWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
                        someWindow.setVisible(true);
                        someWindow.add(new JScrollPane(htmlPane));
                    } catch (IOException ioe) {
                        System.err.println(Messages.getString("DebugMainFrame.ErrorDisplay") + url); //$NON-NLS-1$
                    }
                }
            });

        }
    };
    actionAbout = new AbstractAction(Messages.getString("DebugMainFrame.About")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(DebugMainFrame.this,
                    Messages.getString("DebugMainFrame.AboutContent"), //$NON-NLS-1$
                    Messages.getString("DebugMainFrame.ApplicationName"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
        }
    };
    actionLanguageChinese = new AbstractAction("Chinese") {

        public void actionPerformed(ActionEvent e) {
            DebugUIUtil.updateUI(Locale.SIMPLIFIED_CHINESE);
        }
    };
    actionLanguageEnglish = new AbstractAction("English") {

        public void actionPerformed(ActionEvent e) {
            DebugUIUtil.updateUI(Locale.ENGLISH);
        }
    };
}

From source file:org.ayound.js.debug.ui.DebugMainFrame.java

private void initToolBar() {
    toolBar = new JToolBar();

    Container debugInfoContainer = new Box(BoxLayout.LINE_AXIS);
    toolBar.add(debugInfoContainer);//from   ww  w .  j  a  v a2s .c  om

    JLabel urlLabel = new JLabel(Messages.getString("DebugMainFrame.UrlLabel")); //$NON-NLS-1$
    debugInfoContainer.add(urlLabel);

    urlText = new JTextField(20);
    String historyUrl = ConfigUtil.getPropertie("url");
    if (historyUrl == null) {
        File testFile = new File(new File(getBaseDir()), "test/test.htm"); //$NON-NLS-1$
        urlText.setText(testFile.getAbsolutePath().replace('\\', '/'));
    } else {
        urlText.setText(historyUrl);
    }
    debugInfoContainer.add(urlText);

    urlButton = new JButton(Messages.getString("DebugMainFrame.Select")); //$NON-NLS-1$
    urlButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            JFileChooser fileDialog = new JFileChooser(); // 
            fileDialog.setFileFilter(new FileFilter() {

                @Override
                public boolean accept(File f) {
                    String fileName = f.getName().toLowerCase();
                    if (fileName.endsWith(".htm") //$NON-NLS-1$
                            || fileName.endsWith(".html") //$NON-NLS-1$
                            || f.isDirectory()) {
                        return true;
                    } else {
                        return false;
                    }

                }

                @Override
                public String getDescription() {
                    return ".htm,.html"; //$NON-NLS-1$
                }
            });
            int result = fileDialog.showOpenDialog(DebugMainFrame.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                urlText.setText(fileDialog.getSelectedFile().getAbsolutePath());
            }
        }
    });
    debugInfoContainer.add(urlButton);

    JLabel portLabel = new JLabel(Messages.getString("DebugMainFrame.PortLabel")); //$NON-NLS-1$
    debugInfoContainer.add(portLabel);

    portText = new JTextField(2);
    portText.setText("8088"); //$NON-NLS-1$
    debugInfoContainer.add(portText);

    JLabel browserLabel = new JLabel(Messages.getString("DebugMainFrame.BrowserLabel")); //$NON-NLS-1$
    debugInfoContainer.add(browserLabel);

    browserText = new JTextField(20);
    debugInfoContainer.add(browserText);
    String historyBrowser = ConfigUtil.getPropertie("browser");
    if (historyBrowser != null) {
        browserText.setText(historyBrowser);
        // .setText("C:\\Program Files\\Internet Explorer\\iexplore.exe");
        // //$NON-NLS-1$
    }

    browserButton = new JButton(Messages.getString("DebugMainFrame.Select")); //$NON-NLS-1$
    browserButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            JFileChooser fileDialog = new JFileChooser(); // 
            fileDialog.setFileFilter(new FileFilter() {

                @Override
                public boolean accept(File f) {
                    String fileName = f.getName().toLowerCase();
                    if (fileName.endsWith(".exe") || f.isDirectory()) { //$NON-NLS-1$
                        return true;
                    } else {
                        return false;
                    }

                }

                @Override
                public String getDescription() {
                    return ".exe(windows)"; //$NON-NLS-1$
                }
            });
            int result = fileDialog.showOpenDialog(DebugMainFrame.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                browserText.setText(fileDialog.getSelectedFile().getAbsolutePath());
            }
        }
    });
    debugInfoContainer.add(browserButton);

    toolBar.addSeparator();

    JButton startBtn = toolBar.add(actionDebugStart);
    startBtn.setToolTipText(Messages.getString("DebugMainFrame.StartDebug")); //$NON-NLS-1$

    JButton endBtn = toolBar.add(actionDebugEnd);
    endBtn.setToolTipText(Messages.getString("DebugMainFrame.EndDebug")); //$NON-NLS-1$

    getContentPane().add(toolBar, BorderLayout.BEFORE_FIRST_LINE);
}

From source file:org.cds06.speleograph.actions.OpenAction.java

/**
 * Construct the import action./*from w  w w.j a  va2s . com*/
 *
 * @param component The parent component used to display dialogs.
 */
public OpenAction(JComponent component, Class<? extends DataFileReader> reader) {
    super(I18nSupport.translate("actions.openFile"));
    try {
        this.reader = reader.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        log.info("Can not create action for reader " + reader.getName());
        throw new IllegalArgumentException(e);
    }
    putValue(NAME, this.reader.getButtonText());
    parent = component;
    fileFilter = new OrFileFilter(DirectoryFileFilter.DIRECTORY, this.reader.getFileFilter());
    chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return fileFilter.accept(f);
        }

        @Override
        public String getDescription() {
            return OpenAction.this.getDescription();
        }
    });
}

From source file:org.colombbus.tangara.CommandSelection.java

private FileFilter createTangaraFileFilter() {
    return new FileFilter() {
        @Override/*from   w  w w  .  j ava2s. c o  m*/
        public boolean accept(File file) {
            if (file.isDirectory())
                return true;
            return FileUtils.isTangaraFile(file);
        }

        @Override
        public String getDescription() {
            return Messages.getString("EditorFrame.file.programFilesDescription");
        }
    };
}

From source file:org.colombbus.tangara.CommandSelection.java

private FileFilter createTextFileFilter() {
    return new FileFilter() {
        @Override/*from   w  w  w .j  a va2 s .c o  m*/
        public boolean accept(File file) {
            if (file.isDirectory())
                return true;
            return FileUtils.isTextFile(file);
        }

        @Override
        public String getDescription() {
            return Messages.getString("EditorFrame.file.commandFilesDescription");
        }
    };
}

From source file:org.colombbus.tangara.EditorFrame.java

/**
 * This method initializes the design of the frame.
 *
 *//*from ww w  .j av  a 2s .c o  m*/
private void initialize() {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = graphicsEnvironment.getMaximumWindowBounds();
    setPreferredSize(bounds.getSize());

    this.setJMenuBar(getBanner());

    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    // Sets the main menu (the one separated by jsplitPane1)
    this.setContentPane(getBasePanel());
    this.setTitle(Messages.getString("EditorFrame.application.title")); //$NON-NLS-1$
    addWindowListener(this.windowListener);
    try {
        // Associates the icon (frame.icon = icon_tangara.png) to Tangara
        URL url = EditorFrame.class.getResource(ICON_PATH);
        MediaTracker attenteChargement = new MediaTracker(this);
        Image image = Toolkit.getDefaultToolkit().getImage(url);
        attenteChargement.addImage(image, 0);
        attenteChargement.waitForAll();
        setIconImage(image);
    } catch (InterruptedException e) {
        LOG.warn("Error while loading icon"); //$NON-NLS-1$
    }
    // fileChooser allows to easily choose a file
    // when you open (FILE->OPEN...) you have the choice between .txt or
    // .tgr
    fileChooser = new JFileChooser(Program.instance().getCurrentDirectory());

    // for TangaraFile ".tgr"
    fileChooser.addChoosableFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            if (f.isDirectory())
                return true;
            return FileUtils.isTangaraFile(f);
        }

        @Override
        public String getDescription() {
            return Messages.getString("EditorFrame.file.programFilesDescription"); //$NON-NLS-1$
        }
    });

    fileChooserWithoutFilter = new JFileChooser(Program.instance().getCurrentDirectory());
    pack();
    setVisible(true);
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}

From source file:org.docwhat.iated.ui.PreferencesDialog.java

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Please select your editor");

    chooser.setCurrentDirectory(new File(getDefaultAppDirectory()));

    chooser.setFileFilter(new FileFilter() {
        public boolean accept(File f) {
            if (OS.isFamilyMac() && f.isDirectory() && f.getName().toLowerCase().endsWith(".app")) {
                return (true);
            }//from   w  w  w.  jav a2s.  c  o  m
            return f.canExecute();
        }

        public String getDescription() {
            return "Applications";
        }
    });

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        editorField.setText(chooser.getSelectedFile().getPath());
    }
}