Example usage for javax.swing JFileChooser JFileChooser

List of usage examples for javax.swing JFileChooser JFileChooser

Introduction

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

Prototype

public JFileChooser(FileSystemView fsv) 

Source Link

Document

Constructs a JFileChooser using the given FileSystemView.

Usage

From source file:com.view.Main.java

private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed
    final JFileChooser fileChooser = new JFileChooser(".");
    final FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel files", "xlsx", "xls");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);/*from   w w w.j  av a  2  s  .co  m*/
    int result = fileChooser.showDialog(this, "choose a file");
    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        filePathTextField.setText(selectedFile.getAbsolutePath());
    }

}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveTSV() {
    JFileChooser chooser = new JFileChooser("Save evaluation result as TSV");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }//from   w  w  w.  j a  v a 2s . c o  m
        frame.saveTSV(chooser.getSelectedFile());
    }
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * Prompts for a file using the file chooser dialog
 * /*from  w w w  . jav a2  s . c om*/
 * @param fileExtensions
 *            Accepted file extensions - must be null if filePrefixes is
 *            non-null
 * @param filePrefixes
 *            Accepted file prefixes - must be null if fileExtensions is
 *            non-null
 * @param description
 *            Description of the acceptable files
 * @param createFileIfNonExistant
 *            if true, the file will be created if it does not exist. Also,
 *            the system's "save" will be used instead of the "open" dialog.
 * @param startBrowseDirectory
 *            The directory that the file chooser should start in
 * @param parent
 *            parent component for the file chooser
 * @return the selected file, or null if no file was selected.
 * @throws IOException
 */
public static File promptForFile(List<String> fileExtensions, List<String> filePrefixes,
        final String description, boolean createFileIfNonExistant, File startBrowseDirectory, Component parent)
        throws IOException {
    if (fileExtensions != null && filePrefixes != null) {
        throw new IllegalArgumentException(
                "Only one of the file extensions or file prefixes should be non-null");
    }

    JFileChooser chooser = new JFileChooser(startBrowseDirectory);
    FileFilter filter;

    if (fileExtensions != null) {
        String[] extensionsArray = new String[fileExtensions.size()];
        fileExtensions.toArray(extensionsArray);
        filter = new FileNameExtensionFilter(description, extensionsArray);
    } else {
        final String[] prefixesArray = new String[filePrefixes.size()];
        filePrefixes.toArray(prefixesArray);
        filter = new FileFilter() {

            @Override
            public String getDescription() {
                return description;
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                } else {
                    return StringUtils.startsWithAny(f.getName(), prefixesArray);
                }
            }
        };
    }
    chooser.setFileFilter(filter);

    int returnVal;

    if (createFileIfNonExistant) {
        returnVal = chooser.showSaveDialog(parent);
    } else {
        returnVal = chooser.showOpenDialog(parent);
    }

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        if (createFileIfNonExistant) {
            File file = chooser.getSelectedFile();

            if (!file.exists()) {
                // if only one file extension was supplied and the filename
                // does
                // not end with this extension, add it before
                // creating the file
                if (fileExtensions.size() == 1) {
                    String extension = fileExtensions.get(0);
                    String filePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!filePath.endsWith(extension)) {
                        file = new File(filePath + "." + extension);
                    }
                }

                file.createNewFile();
            }
            return file;
        } else {
            return chooser.getSelectedFile();
        }
    } else {
        return null;
    }
}

From source file:Display.java

@SuppressWarnings("unchecked")
Display() {/*from   w  ww  .  j av  a 2s.  c  o  m*/
    super(Reference.NAME);
    cardLayout = new CardLayout();
    panel.setLayout(cardLayout);
    final int java7Update = Utils.Validators.java7Update.check();
    final int java8Update = Utils.Validators.java8Update.check();
    try {
        URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY);
        JSONParser parser = new JSONParser();
        Object json = parser.parse(new URLReader(host));
        final JSONArray array = (JSONArray) json;
        JSONObject nameObject1 = (JSONObject) array.get(0);
        XPackInstaller.selected_url = nameObject1.get("url").toString();
        XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString());
        XPackInstaller.profile = nameObject1.get("profile").toString();
        XPackInstaller.canAcceptOptional = Boolean
                .parseBoolean(nameObject1.get("canAcceptOptional").toString());
        if (!XPackInstaller.canAcceptOptional) {
            checkOptifine.setEnabled(false);
            checkOptifine.setSelected(false);
            zainstalujMoCreaturesCheckBox.setEnabled(false);
            zainstalujMoCreaturesCheckBox.setSelected(false);
            optionalText.setEnabled(false);
        } else {
            checkOptifine.setEnabled(true);
            zainstalujMoCreaturesCheckBox.setEnabled(true);
            optionalText.setEnabled(true);
        }
        for (Object anArray : array) {
            comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name"));
        }
        comboBox1.addActionListener(e -> {
            int i = 0;
            while (true) {
                JSONObject nameObject = (JSONObject) array.get(i);
                String name1 = nameObject.get("name").toString();
                if (name1 == comboBox1.getSelectedItem()) {
                    XPackInstaller.canAcceptOptional = Boolean
                            .parseBoolean(nameObject.get("canAcceptOptional").toString());
                    XPackInstaller.selected_url = nameObject.get("url").toString();
                    XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString());
                    XPackInstaller.profile = nameObject.get("profile").toString();
                    if (!XPackInstaller.canAcceptOptional) {
                        checkOptifine.setEnabled(false);
                        checkOptifine.setSelected(false);
                        zainstalujMoCreaturesCheckBox.setEnabled(false);
                        zainstalujMoCreaturesCheckBox.setSelected(false);
                        optionalText.setEnabled(false);
                    } else {
                        checkOptifine.setEnabled(true);
                        zainstalujMoCreaturesCheckBox.setEnabled(true);
                        optionalText.setEnabled(true);
                    }
                    break;
                }
                i++;
            }
            int javaStatus;
            if (XPackInstaller.javaVersion == 8) {
                javaStatus = java8Update;
            } else {
                javaStatus = java7Update;
            }
            if (javaStatus == 0) {
                javaversion.setText("TAK");
                javaversion.setForeground(Reference.COLOR_DARK_GREEN);
            } else if (javaStatus == 1) {
                javaversion.setText("NIE");
                javaversion.setForeground(Reference.COLOR_DARK_ORANGE);
            } else if (javaStatus == 2) {
                if (XPackInstaller.javaVersion == 8) {
                    javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!");
                } else {
                    javaversion.setText("Nie posiadasz najnowszej wersji JRE7!");
                }
                javaversion.setForeground(Color.RED);
            }
            if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK")
                    && javaarch.getText().equals("TAK")
                    && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
                XPackInstaller.canGoForward = true;
                button2.setText("Dalej");
            } else {
                XPackInstaller.canGoForward = false;
                button2.setText("Anuluj");
            }
        });
    } catch (FileNotFoundException | ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd",
                JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }

    pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> {
        if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) {
            PathLauncherLabel.setEnabled(true);
            textField1.setEnabled(true);
            button3.setEnabled(true);
            XPackInstaller.installLauncher = true;
            labelLauncher.setEnabled(true);
            progressBar3.setEnabled(true);
        } else {
            PathLauncherLabel.setEnabled(false);
            textField1.setEnabled(false);
            button3.setEnabled(false);
            XPackInstaller.installLauncher = false;
            labelLauncher.setEnabled(false);
            progressBar3.setEnabled(false);
        }
    });
    button3.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
        chooser.setApproveButtonText("Wybierz");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Wybierz ciek");
        int returnValue = chooser.showOpenDialog(getContentPane());
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            try {
                XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath();
            } catch (IOException x) {
                x.printStackTrace();
            }
            textField1.setText(XPackInstaller.launcher_path);
        }
    });
    slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2);
    slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue());
    button1.addActionListener(e -> {
        if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) {
            File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe");
            if (textField1.getText().equals("")) {
                JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!",
                        "Bd", JOptionPane.ERROR_MESSAGE);
            } else if (launcher.exists()) {
                JOptionPane.showMessageDialog(panel,
                        "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                cardLayout.next(panel);
            }
        } else {
            cardLayout.next(panel);
            if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK")
                    && javaarch.getText().equals("NIE")
                    && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
                XPackInstaller.canGoForward = false;
                button2.setText("Anuluj");
                JOptionPane.showMessageDialog(gui,
                        "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.",
                        "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    if (Utils.Validators.systemArchitecture.check()) {
        osarch.setText("TAK");
        osarch.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        osarch.setText("NIE");
        osarch.setForeground(Color.RED);
    }
    if (Utils.Validators.ramAmount.check()) {
        Ram.setText("TAK");
        Ram.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        Ram.setText("NIE");
        Ram.setForeground(Color.RED);
    }
    if (Utils.Validators.javaArchitecture.check()) {
        javaarch.setText("TAK");
        javaarch.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        javaarch.setText("NIE");
        javaarch.setForeground(Color.RED);
    }
    int javaStatus;

    if (XPackInstaller.javaVersion == 8) {
        javaStatus = java8Update;
    } else {
        javaStatus = java7Update;
    }

    if (javaStatus == 0) {
        javaversion.setText("TAK");
        javaversion.setForeground(Reference.COLOR_DARK_GREEN);
    } else if (javaStatus == 1) {
        javaversion.setText("NIE");
        javaversion.setForeground(Reference.COLOR_DARK_ORANGE);
    } else if (javaStatus == 2) {
        javaversion.setText("Nie posiadasz najnowszej wersji JRE!");
        javaversion.setForeground(Color.RED);
    }
    if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK")
            && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
        XPackInstaller.canGoForward = true;
        button2.setText("Dalej");
    } else {
        XPackInstaller.canGoForward = false;
        button2.setText("Anuluj");
    }
    button2.addActionListener(e -> {
        if (XPackInstaller.canGoForward) {
            cardLayout.next(panel);
        } else {
            System.exit(1);
        }
    });
    wsteczButton.addActionListener(e -> cardLayout.previous(panel));
    try {
        editorPane1.setPage("http://xpack.pl/licencja.html");
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd",
                JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }
    licenseC.addActionListener(e -> {
        if (licenseC.isSelected()) {
            dalejButton.setEnabled(true);
        } else {
            dalejButton.setEnabled(false);
        }
    });
    try {
        File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller");
        if (mainDir.exists()) {
            FileUtils.deleteDirectory(mainDir);
            if (!mainDir.mkdir()) {
                JOptionPane.showMessageDialog(gui,
                        "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("Nie udao si utworzy katalogu!");
                System.exit(1);
            }
        } else {
            if (!mainDir.mkdir()) {
                JOptionPane.showMessageDialog(gui,
                        "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("Nie udao si utworzy katalogu!");
                System.exit(1);
            }
        }
        File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods");
        if (!optionalDir.mkdir()) {
            JOptionPane.showMessageDialog(gui,
                    "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                    JOptionPane.ERROR_MESSAGE);
            System.out.println("Nie udao si utworzy katalogu!");
            System.exit(1);
        }
        dalejButton.addActionListener(e -> {
            cardLayout.next(panel);
            try {
                progressBar1.setValue(0);
                if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) {
                    DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine,
                            optionalDir.getAbsolutePath());
                    task2.addPropertyChangeListener(evt -> {
                        if (evt.getPropertyName().equals("progress")) {
                            labelmodpack.setText("Pobieranie Optifine HD w toku...");
                            if (task2.isDone()) {
                                task3();
                            }
                            optifineProgress = (Integer) evt.getNewValue();
                            progressBar1.setValue(optifineProgress);
                        }
                    });
                    task2.execute();
                } else if (checkOptifine.isSelected()) {
                    DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine,
                            optionalDir.getAbsolutePath());
                    task2.addPropertyChangeListener(evt -> {
                        if (evt.getPropertyName().equals("progress")) {
                            labelmodpack.setText("Pobieranie Optifine HD w toku...");
                            if (task2.isDone()) {
                                task();
                            }
                            optifineProgress = (Integer) evt.getNewValue();
                            progressBar1.setValue(optifineProgress);
                        }
                    });
                    task2.execute();
                } else if (zainstalujMoCreaturesCheckBox.isSelected()) {
                    task3();
                } else {
                    task();
                }
            } catch (Exception exx) {
                exx.printStackTrace();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }

    final JScrollBar bar = scrollPane1.getVerticalScrollBar();
    bar.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int extent = bar.getModel().getExtent();
            int total = extent + bar.getValue();
            int max = bar.getMaximum();
            if (total == max) {
                licenseC.setEnabled(true);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            int extent = bar.getModel().getExtent();
            int total = extent + bar.getValue();
            int max = bar.getMaximum();
            if (total == max) {
                licenseC.setEnabled(true);
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    bar.addMouseWheelListener(e -> {
        int extent = bar.getModel().getExtent();
        int total = extent + bar.getValue();
        int max = bar.getMaximum();
        if (total == max) {
            licenseC.setEnabled(true);
        }
    });
    scrollPane1.setWheelScrollingEnabled(true);
    scrollPane1.addMouseWheelListener(e -> {
        int extent = bar.getModel().getExtent();
        int total = extent + bar.getValue();
        int max = bar.getMaximum();
        if (total == max) {
            licenseC.setEnabled(true);
        }
    });
    panel.add(panel3);
    panel.add(panel1);
    panel.add(panel2);
    panel.add(panel4);
    add(panel);
}

From source file:filesscanner.MainWindow.java

private JFileChooser ShowChooser(File f) {
    JFileChooser chooser = new JFileChooser(f);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    return chooser;
}

From source file:Compare.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String userDir = System.getProperty("user.home");
    JFileChooser folder = new JFileChooser(userDir + "/Desktop");
    folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folder.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files  (*.xls)", "xls");
    folder.setFileFilter(xmlfilter);/*w  w w.j ava 2 s.  co  m*/
    int returnvalue = folder.showSaveDialog(this);

    File myfolder = null;
    if (returnvalue == JFileChooser.APPROVE_OPTION) {
        myfolder = folder.getSelectedFile();
        //            System.out.println(myfolder);         
    }

    if (myfolder != null) {
        JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder);
    }

    listofFiles(myfolder);
    sortByName();

    DefaultTableModel model = (DefaultTableModel) FileDetails.getModel();

    int count = 1;
    for (Files filename : filenames1) {
        String size = Long.toString(filename.Filesize) + "Bytes";
        model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation });
    }

}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

private JButton createLoadButton() {
    JButton load = new JButton("Load");
    load.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PersistentLayout pl = (PersistentLayout) vv.getGraphLayout();
            try {
                JFileChooser chooser = new JFileChooser(currentDir);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileFilter(new LayoutFileFilter());
                int result = chooser.showOpenDialog(GraphViewerPanel.this);
                if (result == JFileChooser.APPROVE_OPTION) {
                    currentDir = chooser.getCurrentDirectory();
                    String absolutePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!absolutePath.endsWith(".layout")) {
                        absolutePath += ".layout";
                    }//from www . jav  a2  s  .c  om
                    pl.restore(absolutePath);
                    vv.repaint();
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(GraphViewerPanel.this,
                        "Error restoring layout: " + e1.getMessage());
            }
        }
    });
    return load;
}

From source file:filterviewplugin.FilterViewSettingsTab.java

private void chooseIcon(final String filterName) {
    String iconPath = mIcons.get(filterName);

    JFileChooser chooser = new JFileChooser(
            iconPath == null ? new File("") : (new File(iconPath)).getParentFile());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    String msg = mLocalizer.msg("iconFiles", "Icon Files ({0})", "*.png,*.jpg, *.gif");
    String[] extArr = { ".png", ".jpg", ".gif" };

    chooser.setFileFilter(new ExtensionFileFilter(extArr, msg));
    chooser.setDialogTitle(mLocalizer.msg("chooseIcon", "Choose icon for '{0}'", filterName));

    Window w = UiUtilities.getLastModalChildOf(FilterViewPlugin.getInstance().getSuperFrame());

    if (chooser.showDialog(w,
            Localizer.getLocalization(Localizer.I18N_SELECT)) == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File dir = new File(FilterViewSettings.getIconDirectoryName());

            if (!dir.isDirectory()) {
                dir.mkdir();/*  w  w  w  .  ja  v a2  s .c o  m*/
            }

            String ext = chooser.getSelectedFile().getName();
            ext = ext.substring(ext.lastIndexOf('.'));

            Icon icon = FilterViewPlugin.getInstance().getIcon(chooser.getSelectedFile().getAbsolutePath());

            if (icon.getIconWidth() > MAX_ICON_WIDTH || icon.getIconHeight() > MAX_ICON_HEIGHT) {
                JOptionPane.showMessageDialog(w, mLocalizer.msg("iconSize",
                        "The icon size must be at most {0}x{1}.", MAX_ICON_WIDTH, MAX_ICON_HEIGHT));
                return;
            }

            try {
                IOUtilities.copy(chooser.getSelectedFile(), new File(dir, filterName + ext));
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            mIcons.put(filterName, filterName + ext);
            mFilterList.updateUI();
        }
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveReferenceXML() {
    JFileChooser chooser = new JFileChooser(
            "Save as alignment xml format. YOUR EVALUATION WILL NOT BE SAVED, ONLY A COPY OF THE INPUT.");
    chooser.setCurrentDirectory(new File("."));
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }//from  ww w . j  av  a  2 s  .  c o m
        frame.saveReferenceXML(chooser.getSelectedFile(), true);
    }
}

From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java

/**
 *
 *///from   w  w  w.  java  2s.c  o m
public void open() {
    // Create a file chooser with the current directory set to the
    // application home
    String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath();
    JFileChooser fileDialog = new JFileChooser(prefsDir);

    fileDialog.setFileFilter(connectionFileFilter);

    // Show it
    int ret = fileDialog.showOpenDialog(this);

    // If we've approved the selection then process
    if (ret == fileDialog.APPROVE_OPTION) {
        PreferencesStore.put(PREF_CONNECTION_FILE_DIRECTORY,
                fileDialog.getCurrentDirectory().getAbsolutePath());

        // Get the file
        File f = fileDialog.getSelectedFile();
        open(f);
    }
}