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:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java

private void loadReport() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Choose scanner report directory");
    File lastReport = getLastUsedReport();
    if (lastReport != null) {
        fc.setCurrentDirectory(lastReport);
    }//from  w ww.  j  a va 2 s  .c  o  m
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setFileHidingEnabled(false);
    fc.setApproveButtonText("Open scanner report");
    int returnVal = fc.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {
            setLastUsedReport(file);
            loadReport(file);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(frame, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            exit();
        }
    } else {
        exit();
    }

}

From source file:org.spoutcraft.launcher.settings.LauncherDirectories.java

public File selectInstallDir(File workDir) {
    int result = JOptionPane.showConfirmDialog(splash,
            "No installation of technic found. \n\nTechnic Launcher will install at: \n"
                    + workDir.getAbsolutePath() + " \n\nWould you like to change the install directory?",
            "Install Technic Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
    if (result == JOptionPane.YES_OPTION) {
        JFileChooser fileChooser = new JFileChooser(workDir);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int changeInst = fileChooser.showOpenDialog(splash);

        if (changeInst == JFileChooser.APPROVE_OPTION) {
            workDir = fileChooser.getSelectedFile();
            if (!ZipUtils.checkLaunchDirectory(workDir)) {
                JOptionPane.showMessageDialog(splash,
                        "Please select an empty directory, or your default install folder with settings.yml in it.",
                        "Invalid Location", JOptionPane.WARNING_MESSAGE);
                return selectInstallDir(workDir);
            }//from  ww w  . j a v a  2s  .  c o  m
        }
        workDir.mkdirs();
    }
    return workDir;
}

From source file:org.spoutcraft.launcher.util.Utils.java

public static File selectInstallDir(File workDir) {
    int result = JOptionPane.showConfirmDialog(splash,
            "No installation of technic found. \n\nTechnic Launcher will install at: \n"
                    + workDir.getAbsolutePath() + " \n\nWould you like to change the install directory?",
            "Install Technic Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
    if (result == JOptionPane.YES_OPTION) {
        JFileChooser fileChooser = new JFileChooser(workDir);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int changeInst = fileChooser.showOpenDialog(splash);

        if (changeInst == JFileChooser.APPROVE_OPTION) {
            workDir = fileChooser.getSelectedFile();
            if (!FileUtils.checkLaunchDirectory(workDir)) {
                JOptionPane.showMessageDialog(splash,
                        "Please select an empty directory, or your default install folder with settings.yml in it.",
                        "Invalid Location", JOptionPane.WARNING_MESSAGE);
                return selectInstallDir(workDir);
            }/*from ww w.  jav  a 2s.  co m*/
        }
        workDir.mkdirs();
    }
    return workDir;
}

From source file:org.tellervo.desktop.io.ExportUI.java

private void setupGui() {
    // Set icon        
    lblIcon.setIcon(Builder.getIcon("fileexport.png", 128));

    // Disable ok button until file/folder has been selected
    btnOK.setEnabled(false);/*from ww  w  .  j  a v a2  s  . co  m*/

    Help.assignHelpPageToButton(btnHelp, "File_formats");

    // Hide how form items
    //lblHow.setVisible(false);
    //cboHow.setVisible(false);

    groupingModel.add("Single packed file if possible");
    groupingModel.add("Separate files for each series");
    cboGrouping.setModel(groupingModel);
    cboGrouping.setSelectedIndex(1);

    // setup combo boxes
    cboWhat.setModel(whatModel);
    setWhatModel();
    cboExportFormat.setModel(formatModel);
    setupFormatList();
    cboEncoding.setModel(encodingModel);
    setupEncodingList();
    cboEncoding.setSelectedIndex(0);

    // Add action listeners
    btnOK.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            doExport();
        }
    });
    btnCancel.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // just close
            parent.dispose();
        }
    });

    btnBrowse.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

            // Choose directory not file
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setDialogTitle(I18n.getText("export.selectAFolder"));

            // Open at last used directory
            if (exportDirectory != null) {
                fc.setCurrentDirectory(new File(exportDirectory));
            }

            // Show dialog
            int returnVal;
            returnVal = fc.showSaveDialog(parent);

            // Set file/folder in text box
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                txtOutput.setText(file.getAbsoluteFile().toString());

            }

            // If file/folder selected enable OK button
            if (txtOutput.getText() == null || txtOutput.getText().equals("")) {
                btnOK.setEnabled(false);
            } else {
                btnOK.setEnabled(true);
            }

        }
    });

    txtOutput.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (txtOutput.getText() == null || txtOutput.getText().equals("")) {
                btnOK.setEnabled(false);
            } else {
                btnOK.setEnabled(true);
            }
        }
    });

    cboExportFormat.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

        }
    });
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

public static Path selectDirectory(String title) {
    // on mac try to take the AWT FileDialog
    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        try {//w  w w . j a  va  2  s .com
            // open directory chooser
            return openDirectoryDialog(title);
        } catch (Exception e) {
            LOGGER.warn("cannot open AWT directory chooser" + e.getMessage());
        } catch (Error e) {
            LOGGER.warn("cannot open AWT directory chooser" + e.getMessage());
        } finally {
            // reset system property
            System.setProperty("apple.awt.fileDialogForDirectories", "false");
        }
    }

    // open JFileChooser
    return openJFileChooser(JFileChooser.DIRECTORIES_ONLY, title, true, null, null);
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

private static Path openJFileChooser(int mode, String dialogTitle, boolean open, String filename,
        FileNameExtensionFilter filter) {
    JFileChooser fileChooser;//w  w w  .  j  a va  2  s  .  com
    // are we forced to open the legacy file chooser?
    if ("true".equals(System.getProperty("tmm.legacy.filechooser"))) {
        fileChooser = new JFileChooser();
    } else {
        fileChooser = new NativeFileChooser();
    }

    fileChooser.setFileSelectionMode(mode);
    if (lastDir != null) {
        fileChooser.setCurrentDirectory(lastDir.toFile());
    }
    fileChooser.setDialogTitle(dialogTitle);

    int result = -1;
    if (open) {
        result = fileChooser.showOpenDialog(MainWindow.getFrame());
    } else {
        if (StringUtils.isNotBlank(filename)) {
            fileChooser.setSelectedFile(new File(filename));
            fileChooser.setFileFilter(filter);
        }
        result = fileChooser.showSaveDialog(MainWindow.getFrame());
    }

    if (result == JFileChooser.APPROVE_OPTION) {
        if (mode == JFileChooser.DIRECTORIES_ONLY) {
            lastDir = fileChooser.getSelectedFile().toPath();
        } else {
            lastDir = fileChooser.getSelectedFile().getParentFile().toPath();
        }
        return fileChooser.getSelectedFile().toPath();
    }

    return null;
}

From source file:org.wso2.carbon.cluster.ui.ClusterWizard.java

private void btnFolderPathSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFolderPathSelectActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(getParent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        clusterAbsFolderPath = chooser.getSelectedFile().getAbsolutePath();
        txtFolderPath.setText(clusterAbsFolderPath);
    }/*  w  ww.ja v a  2 s.c  o  m*/
}

From source file:org.zaproxy.zap.view.ContextExportDialog.java

public ContextExportDialog(Frame owner) {
    super(owner, "context.import.title", new Dimension(400, 250));
    this.addContextSelectField(CONTEXT_FIELD, null);
    this.addFileSelectField(DIR_FIELD, Constant.getContextsDir(), JFileChooser.DIRECTORIES_ONLY, null);
    this.addTextField(FILE_FIELD, null);
    this.addCheckBoxField(OVERWRITE_FIELD, false);

    super.addFieldListener(CONTEXT_FIELD, new ActionListener() {
        @Override//from  w w  w . ja  va 2s.c  o m
        public void actionPerformed(ActionEvent e) {
            Context ctx = getContextValue(CONTEXT_FIELD);
            if (ctx != null) {
                String fileName = ctx.getName() + CONTEXT_EXT;
                setFieldValue(FILE_FIELD, fileName);
            }
        }
    });
}

From source file:osu.beatmapdownloader.JFrame.java

private void B_DirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_DirectoryActionPerformed
       JFileChooser chooser;/*from   w w w  . ja v  a2s.  com*/

       chooser = new JFileChooser();
       chooser.setCurrentDirectory(new java.io.File("."));
       chooser.setDialogTitle("Open Osu! Installation Directory");
       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
       chooser.setAcceptAllFileFilterUsed(false);
       if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
           File route = chooser.getSelectedFile();
           if (route.toString().endsWith("Songs")) {
               Directory = route.getAbsolutePath();
               T_Directory.setText(Directory);
           } else {
               if (route.isDirectory()) {
                   String[] Files = route.list();
                   boolean found = false;
                   for (String f : Files)
                       if (f.contains("Songs")) {
                           Directory = route + File.separator + f;
                           T_Directory.setText(Directory);
                           set("SongDirectory", Directory);
                           found = true;
                           break;
                       }
                   if (found == false)
                       Alert("Incorrect Osu! Directory");
               }
           }
       }
   }

From source file:pcgen.gui2.converter.panel.WriteDirectoryPanel.java

@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(layout);/*www.  j a v  a 2 s .  c  om*/
    Component label = new JLabel("Please select the Directory where Converted files should be written: ");
    AbstractButton button = new JButton("Browse...");
    button.setMnemonic('r');
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setCurrentDirectory(path.getParentFile());
            chooser.setSelectedFile(path);
            while (true) {
                int open = chooser.showOpenDialog(null);
                if (open == JFileChooser.APPROVE_OPTION) {
                    File fileToOpen = chooser.getSelectedFile();
                    if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) {
                        path = fileToOpen;
                        pc.put(ObjectKey.WRITE_DIRECTORY, path);
                        fileLabel.setText(path.getAbsolutePath());
                        PCGenSettings context = PCGenSettings.getInstance();
                        context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath());
                        showWarning();
                        break;
                    }
                    JOptionPane.showMessageDialog(null,
                            "Selection must be a valid " + "(readable & writeable) Directory");
                    chooser.setCurrentDirectory(path.getParentFile());
                } else if (open == JFileChooser.CANCEL_OPTION) {
                    break;
                }
            }
        }
    });
    panel.add(label);
    panel.add(fileLabel);
    panel.add(button);
    panel.add(warningLabel);
    showWarning();
    layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel);
    layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height,
            SpringLayout.NORTH, panel);
    layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH,
            panel);
    layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel);
    layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel);
    layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel);
    layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel);
    layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel);

    fileLabel.setText(path.getAbsolutePath());
}