List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY
int DIRECTORIES_ONLY
To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.
Click Source Link
From source file:net.technicpack.launcher.ui.InstallerFrame.java
protected void selectStandard() { File installDir = new File(standardInstallDir.getText()); while (!installDir.exists()) { installDir = installDir.getParentFile(); }//from w w w . ja va 2 s. c o m JFileChooser chooser = new JFileChooser(installDir); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = chooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile().listFiles().length > 0) { JOptionPane.showMessageDialog(this, resources.getString("modpackoptions.move.errortext"), resources.getString("modpackoptions.move.errortitle"), JOptionPane.OK_OPTION); return; } standardInstallDir.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:net.technicpack.launcher.ui.LauncherFrame.java
protected void launchModpack() { ModpackModel pack = modpackSelector.getSelectedPack(); boolean requiresInstall = false; if (pack == null || (pack.getInstalledPack() == null && (pack.getPackInfo() == null || !pack.getPackInfo().isComplete()))) return;/* w w w . j a va 2s. c om*/ if (pack.getInstalledDirectory() == null) { requiresInstall = true; pack.save(); modpackSelector.forceRefresh(); } if (requiresInstall) { try { if (pack.getPackInfo().shouldForceDirectory() && FilenameUtils.directoryContains(directories.getLauncherDirectory().getCanonicalPath(), pack.getInstalledDirectory().getCanonicalPath())) { JFileChooser chooser = new JFileChooser(directories.getLauncherDirectory()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setCurrentDirectory(directories.getLauncherDirectory()); int result = chooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (file.list().length > 0) { JOptionPane.showMessageDialog(this, resources.getString("modpackoptions.move.errortext"), resources.getString("modpackoptions.move.errortitle"), JOptionPane.WARNING_MESSAGE); return; } else if (FileUtils.directoryContains(directories.getLauncherDirectory(), file)) { JOptionPane.showMessageDialog(this, resources.getString("launcher.launch.requiresmove"), resources.getString("launcher.launch.requiretitle"), JOptionPane.WARNING_MESSAGE); return; } pack.setInstalledDirectory(file); } } } catch (IOException ex) { Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex); } } boolean forceInstall = false; Version installedVersion = pack.getInstalledVersion(); //Force a full install (check cache, redownload, unzip files) if we have no current installation of this modpack if (installedVersion == null) forceInstall = true; else if (pack.getBuild() != null && !pack.isLocalOnly()) { //Ask the user if they want to update to the newer version if: //1- the pack build is RECOMMENDED & the recommended version is diff from the installed version //2- the pack build is LATEST & the latest version is diff from the installed version //3- the pack build is neither LATEST or RECOMMENDED & the pack build is diff from the installed version boolean requestInstall = false; if (pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED) && pack.getPackInfo().getRecommended() != null && !pack.getPackInfo().getRecommended().equalsIgnoreCase(installedVersion.getVersion())) requestInstall = true; else if (pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST) && pack.getPackInfo().getLatest() != null && !pack.getPackInfo().getLatest().equalsIgnoreCase(installedVersion.getVersion())) requestInstall = true; else if (!pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED) && !pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST) && !pack.getBuild().equalsIgnoreCase(installedVersion.getVersion())) requestInstall = true; //If the user says yes, update, then force a full install if (requestInstall) { int result = JOptionPane.showConfirmDialog(this, resources.getString("launcher.install.query"), resources.getString("launcher.install.query.title"), JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); if (result == JOptionPane.YES_OPTION) { forceInstall = true; } } } //If we're forcing an install, then derive the installation build from the pack build //otherwise, just use the installed version String installBuild = null; if (forceInstall && !pack.isLocalOnly()) { installBuild = pack.getBuild(); if (installBuild.equalsIgnoreCase(InstalledPack.RECOMMENDED)) installBuild = pack.getPackInfo().getRecommended(); else if (installBuild.equalsIgnoreCase(InstalledPack.LATEST)) installBuild = pack.getPackInfo().getLatest(); } else installBuild = installedVersion.getVersion(); if (requiresInstall) { installer.justInstall(resources, pack, installBuild, forceInstall, this, installProgress); } else { installer.installAndRun(resources, pack, installBuild, forceInstall, this, installProgress); } installProgress.setVisible(true); installProgressPlaceholder.setVisible(false); userChanged(userModel.getCurrentUser()); invalidate(); }
From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java
private void jButtonSelectImagesFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectImagesFolderActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTestImagesFolderLocation(path); testImagesFolderLocation.setText(path); } else {/*from w ww . j a v a 2 s. c om*/ String path = RuntimeConfiguration.getInstance().getTestImagesFolderLocation(); if (StringUtils.isNotBlank(path)) { testImagesFolderLocation.setText(path); } } }
From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java
private void jButtonSelectConfigurationFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectConfigurationFolderActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTestConfigurationsFolderLocation(path); configurationsFolderLocation.setText(path); } else {/*from ww w. ja v a 2s . c o m*/ String path = RuntimeConfiguration.getInstance().getTestConfigurationsFolderLocation(); if (StringUtils.isNotBlank(path)) { configurationsFolderLocation.setText(path); } } }
From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java
private void jButtonSelectFalseImagesFolder1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectFalseImagesFolder1ActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTestFalseImagesFolderLocation(path); testFalseImagesFolderLocation.setText(path); } else {/*from w w w. j a v a2s . co m*/ String path = RuntimeConfiguration.getInstance().getTestFalseImagesFolderLocation(); if (StringUtils.isNotBlank(path)) { testFalseImagesFolderLocation.setText(path); } } }
From source file:nick.gaImageRecognitionGui.panel.JPanelTraining.java
private void jButtonSelectTrainingFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectTrainingFolderActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TRAINING_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTrainingFolderPath(path); trainingFolderLocation.setText(path); } else {/*w ww . j a va2 s . c o m*/ String path = RuntimeConfiguration.getInstance().getTrainingFolderPath(); if (StringUtils.isNotBlank(path)) { trainingFolderLocation.setText(path); } } }
From source file:nick.gaImageRecognitionGui.panel.JPanelTraining.java
private void jButtonSelectFalseImagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectFalseImagesActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TRAINING_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTrainingFalseImagesFolderPath(path); falseImagesFolderLoc.setText(path); } else {//from w w w . jav a 2 s. c o m String path = RuntimeConfiguration.getInstance().getTrainingFalseImagesFolderPath(); if (StringUtils.isNotBlank(path)) { falseImagesFolderLoc.setText(path); } } }
From source file:nl.b3p.applet.local.Files.java
/** * Show a directory selector dialog.//from w w w . j av a 2s. c o m * * @param title The title for the dialog. * @return the selected directory or null if the dialog was canceled */ public static String selectDirectory(Component component, String title) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(component) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().toString(); } else { return null; } }
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);/* ww w.j a v a2 s . 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:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java
private void addFavourite() { final JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select favourite directory"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { final DefaultListModel model = (DefaultListModel) lstFavourites.getModel(); model.addElement(fc.getSelectedFile().getAbsolutePath()); }/*from ww w . j ava 2 s .c o m*/ checkButtons(); }