Example usage for javax.swing JFileChooser DIRECTORIES_ONLY

List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY

Introduction

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

Prototype

int DIRECTORIES_ONLY

To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.

Click Source Link

Document

Instruction to display only directories.

Usage

From source file:com.jug.MotherMachine.java

/**
 * Shows a JFileChooser set up to accept the selection of folders.
 * If 'cancel' is pressed this method terminates the MotherMachine app.
 *
 * @param guiFrame/* www.j  ava 2  s  .  c  o  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) {
    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) {
        return chooser.getSelectedFile();
    } else {
        System.exit(0);
        return null;
    }
}

From source file:jatoo.app.App.java

/**
 * Provides a simple mechanism for the user to select a directory.
 * //  w ww .j  av a 2s.  c  o  m
 * @param currentDirectory
 *          the current directory to point to
 */
public File selectDirectory(final File currentDirectory) {
    return select(currentDirectory, JFileChooser.DIRECTORIES_ONLY);
}

From source file:coreferenceresolver.gui.MainGUI.java

private void testBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose where your testing file saved");
    inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        testingFilePathTF/*from  ww  w  .j  av  a2 s  . c  o  m*/
                .setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "test.arff");
        noteTF.setText("Create testing file waiting ...");
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TrainingMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(),
                            testingFilePathTF.getText(), false);
                    noteTF.setText("Create testing file done!");
                    String folderPathOpen = testingFilePathTF.getText().substring(0,
                            testingFilePathTF.getText().lastIndexOf(File.separatorChar));
                    Desktop.getDesktop().open(new File(folderPathOpen));
                } catch (Exception ex) {
                    Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    } else {
        noteTF.setText("No testing file location selected");
    }
}

From source file:de.quadrillenschule.azocamsyncd.astromode.gui.AstroModeJPanel.java

private void chooseDirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseDirjButtonActionPerformed
    JFileChooser jfc = new JFileChooser(astroFolderjTextField.getText());
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        astroFolderjTextField.setText(jfc.getSelectedFile().getAbsolutePath());
    }//from  ww w  .j ava  2s .c  om
}

From source file:coreferenceresolver.gui.MainGUI.java

private void applyClassifierBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyClassifierBtnActionPerformed
    JFileChooser inputFileChooser = new JFileChooser(defaulPath);
    inputFileChooser.setDialogTitle("Choose where your classified result file saved");
    inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        resultFilePathTF1.setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator
                + "classified_result.txt");
        noteTF.setText("Create classified result file waiting ...");

        new Thread(new Runnable() {
            @Override/*from w ww.ja  va  2s  .  c om*/
            public void run() {
                try {
                    WekaMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(),
                            trainingFilePathTF.getText(), testingFilePathTF.getText(),
                            resultFilePathTF1.getText());
                    noteTF.setText("Create result file done!");
                    String folderPathOpen = resultFilePathTF1.getText().substring(0,
                            resultFilePathTF1.getText().lastIndexOf(File.separatorChar));
                    Desktop.getDesktop().open(new File(folderPathOpen));
                    //Open the window for predicted chains                    
                    ClassifiedResultGUI.render(true);
                    //Open the window for actual chains                    
                    ClassifiedResultGUI.render(false);
                } catch (Exception ex) {
                    Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();

    } else {
        noteTF.setText("No classified result file location selected");
    }
}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

private String browseDirectory() {
    if (getSelectedProfile() != FileSystemProfile.LOCAL_FILESYSTEM_PROFILE) {
        // browse only supported on LFS
        return null;
    }//from  www  .  j  a va  2s. c  om

    String loadPath = currentDir.getPath();
    JFileChooser chooser = new JFileChooser(loadPath);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int retVal = chooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile().getAbsolutePath();
    } else {
        return null;
    }
}

From source file:la2launcher.MainFrame.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {/* www  . ja  v  a2s. com*/
        JFileChooser fc;
        if (gamePath == null || gamePath.trim().equals("")) {
            fc = new JFileChooser();
        } else {
            if (new File(gamePath).isDirectory()) {
                fc = new JFileChooser(gamePath);
            } else {
                fc = new JFileChooser();
            }
        }
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        fc.showOpenDialog(this);

        File f = fc.getSelectedFile();

        if (f != null) {
            gamePath = f.getAbsolutePath();
            jTextField2.setText(gamePath);
        }

        boolean systemFound = false;
        for (String fname : f.list()) {
            if (fname.toUpperCase().equals("SYSTEM")) {
                systemFound = true;
                break;
            }
        }

        if (!systemFound) {
            JOptionPane.showMessageDialog(this,
                    "?   system.    . ?   ?.");
        }
    } catch (Exception ex) {
        logg("");
        logg(ex);
    }

}

From source file:de.ist.clonto.Ontogui.java

private void loadOntology(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_loadOntology
    if (null != dataset) {
        dataset.end();//from  ww w . j av a2s.com
    }
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        dataset = TDBFactory.createDataset(fc.getSelectedFile().toString());
        ontologyNameField.setText(fc.getSelectedFile().getName());
        ontoPath = fc.getSelectedFile().toPath();
    } else {
        JOptionPane.showMessageDialog(this, "Loading ontology failed");
    }
}

From source file:net.rptools.maptool.launcher.MapToolLauncher.java

private JPanel buildAdvancedPanel() {
    final JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.setBorder(new LineBorder(Color.BLACK));

    final JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new BorderLayout());

    final JPanel argPanel = new JPanel();
    argPanel.setLayout(new BorderLayout());

    jtfArgs.setInfo(CopiedFromOtherJars.getText("msg.info.javaArgumentsHere")); //$NON-NLS-1$
    jtfArgs.setText(extraArgs);/* ww w.  j  a v a 2 s  .  co m*/
    jtfArgs.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaArgumentsHere")); //$NON-NLS-1$
    jtfArgs.setCaretPosition(0);
    jtfArgs.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                jbLaunch.requestFocusInWindow();
            }
        }
    });
    jtfArgs.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent arg0) {
            jtfArgs.selectAll();
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            jtfArgs.setCaretPosition(0);
            if (!jtfArgs.getText().trim().equals(extraArgs)) {
                extraArgs = jtfArgs.getText();
                jcbEnableAssertions.setSelected(extraArgs.contains(ASSERTIONS_OPTION));
                if (extraArgs.contains(DATADIR_OPTION)) {
                    extraArgs = cleanExtraArgs(extraArgs);
                }
                updateCommand();
            }
        }
    });

    argPanel.add(jtfArgs, BorderLayout.CENTER);
    controlPanel.add(argPanel, BorderLayout.NORTH);

    final JPanel holdPanel = new JPanel();
    holdPanel.setLayout(new GridLayout(0, 1));

    jcbRelativePath.setText(CopiedFromOtherJars.getText("msg.info.useRelativePathnames")); //$NON-NLS-1$
    jcbRelativePath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.useRelativePathnames")); //$NON-NLS-1$
    jcbRelativePath.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            updateCommand();
        }
    });
    //      jcbRelativePath.setSelected(false); // since initComponents() is called after reading the config, don't do this here

    jcbConsole.setText(CopiedFromOtherJars.getText("msg.info.launchWithConsole")); //$NON-NLS-1$
    jcbConsole.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.launchWithConsole")); //$NON-NLS-1$
    jcbConsole.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            startConsole = jcbConsole.isSelected();
            updateCommand();
        }
    });
    jcbConsole.setSelected(startConsole);

    jbPath.setText(jbPathText);
    jbPath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.dirForAltJava")); //$NON-NLS-1$
    jbPath.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (jbPath.getText().equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.setJavaVersion"))) { //$NON-NLS-1$
                final JFileChooser jfc = new JFileChooser();
                if (!javaDir.isEmpty()) {
                    jfc.setCurrentDirectory(new File(javaDir));
                } else {
                    jfc.setCurrentDirectory(new File(".")); //$NON-NLS-1$
                }
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                final int returnVal = jfc.showOpenDialog(jbPath);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    final File f = jfc.getSelectedFile();
                    final String test = f.getPath() + File.separator;

                    // Lee: naive search for java command. will improve in the future
                    final List<String> fileList = Arrays.asList(f.list());
                    boolean javaFound = false;

                    for (final String fileName : fileList) {
                        final File check = new File(f, fileName);
                        final String lc = check.getName().toLowerCase();
                        if (lc.equals("java") || (IS_WINDOWS && lc.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ 
                            javaFound = true;
                            break;
                        }
                    }
                    if (javaFound) {
                        jbPath.setText(CopiedFromOtherJars.getText("msg.info.resetToDefaultJava")); //$NON-NLS-1$
                        javaDir = test;
                        updateCommand();
                    } else {
                        logMsg(Level.SEVERE, "Java executable not found in {0}", //$NON-NLS-1$
                                "msg.error.javaCommandNotFound", f); //$NON-NLS-2$
                    }
                }
            } else {
                jbPath.setText(CopiedFromOtherJars.getText("msg.info.setJavaVersion")); //$NON-NLS-1$
                javaDir = EMPTY;
            }
        }
    });

    holdPanel.add(jcbRelativePath);
    holdPanel.add(jcbConsole);
    holdPanel.add(jbPath);
    controlPanel.add(holdPanel, BorderLayout.SOUTH);

    final JPanel logPanel = new JPanel();
    logPanel.setLayout(new GridLayout(0, 1));
    logPanel.setBorder(
            new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logPanel.border"))); //$NON-NLS-1$
    for (final LoggingConfig config : logConfigs) {
        config.chkbox.setText(config.getProperty("desc")); //$NON-NLS-1$
        config.chkbox.setToolTipText(config.getProperty("ttip")); //$NON-NLS-1$
        logPanel.add(config.chkbox);
    }
    p.add(logPanel, BorderLayout.CENTER);
    p.add(controlPanel, BorderLayout.SOUTH);
    return p;
}

From source file:VentanaPrincipal.java

private void descargarFichero() throws IOException {
    String directorio = lblRuta.getText();
    cliente.changeWorkingDirectory(directorio);
    JFileChooser chooser = new JFileChooser();
    cliente.enterLocalPassiveMode();//from   w  w  w  . j  av  a 2  s . co  m
    cliente.setFileType(FTP.BINARY_FILE_TYPE);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        BufferedOutputStream out = new BufferedOutputStream(
                new FileOutputStream(chooser.getSelectedFile().getAbsolutePath() + "/" + listFicheros
                        .getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-"))));
        if (cliente.retrieveFile(
                listFicheros.getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-")),
                out))
            lblMens.setText("Descargado correctamente ");
        else
            lblMens.setText("No se ha podido descargar");
        out.close();
    }
}