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.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;/*w w w . j a v a 2 s . c om*/ List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:com.github.cmisbox.ui.UI.java
public File getWatchFolder() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); chooser.showOpenDialog(null);/*from www . java2 s .c om*/ return chooser.getSelectedFile(); }
From source file:modmanager.MainWindow.java
private void selectSkyrimDirectory(boolean force) { skyrimDirectoryChooser.setDialogTitle("Select Skyrim folder"); skyrimDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); boolean chosen = false; while (skyrimDirectoryChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { /**// www . j av a 2 s . co m * Use a while loop to check for valid skyrim installation ... */ if (!FileUtils.getFile(skyrimDirectoryChooser.getSelectedFile(), "TESV.exe").exists()) { int result = JOptionPane.showConfirmDialog(this, "It seems that this directory does not contain Skyrim!\nContinue anyways?", "Invalid Skyrim directory", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION) { break; } if (result == JOptionPane.YES_OPTION) { chosen = true; break; } } else { chosen = true; break; } } if (force && !chosen) { System.exit(0); } modifications.setSkyrimDirectory(skyrimDirectoryChooser.getSelectedFile()); }
From source file:kihira.tails.client.gui.GuiExport.java
@Override protected void actionPerformed(GuiButton button) { //Export to file if (button.id == 0 || button.id == 1 || button.id == 2) { AbstractClientPlayer player = this.mc.thePlayer; File file;//from ww w . j a v a2 s . co m this.exportMessage = ""; this.exportLoc = null; if (button.id == 0) file = new File(System.getProperty("user.home")); else if (button.id == 1) file = new File(System.getProperty("user.dir")); else { JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); } else return; } if (file.exists() && file.canWrite()) { this.exportLoc = file.toURI(); file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e)); e.printStackTrace(); } } BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player); if (image != null) { try { ImageIO.write(image, "png", file); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e)); e.printStackTrace(); } } else { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!")); file.delete(); } } if (Strings.isNullOrEmpty(this.exportMessage)) { savePartsData(); this.openFolderButton.visible = true; setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file)); } } if (button.id == 3 && this.exportLoc != null) { try { Desktop.getDesktop().browse(this.exportLoc); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e)); e.printStackTrace(); } } //Upload if (button.id == 10) { final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer); Runnable runnable = new Runnable() { @Override public void run() { exportMessage = I18n.format("tails.uploading"); new ImgurUpload().uploadImage(image); } }; runnable.run(); } }
From source file:de.erdesignerng.visual.editor.openxavaexport.OpenXavaExportEditor.java
private void commandChooseSrcDirectory() { JFileChooser theChooser = new JFileChooser(); theChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (theChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File theBaseDirectory = theChooser.getSelectedFile(); editingView.getSrcDirectory().setText(theBaseDirectory.toString()); }// w ww . j av a 2 s.c o m }
From source file:edu.ku.brc.specify.tools.LocalizerSearchHelper.java
/** * @param baseDir//from w w w . j av a 2 s .c om * @return */ public Vector<Pair<String, String>> findOldL10NKeys(final String[] fileNames) { initLucene(true); //if (srcCodeFilesDir == null) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (srcCodeFilesDir != null) { chooser.setSelectedFile(new File(FilenameUtils.getName(srcCodeFilesDir.getAbsolutePath()))); chooser.setSelectedFile(new File(srcCodeFilesDir.getParent())); } if (chooser.showOpenDialog(UIRegistry.getMostRecentWindow()) == JFileChooser.APPROVE_OPTION) { srcCodeFilesDir = new File(chooser.getSelectedFile().getAbsolutePath()); } else { return null; } } indexSourceFiles(); Vector<Pair<String, String>> fullNotFoundList = new Vector<Pair<String, String>>(); try { ConversionLogger convLogger = new ConversionLogger(); convLogger.initialize("resources", "Resources"); for (String fileName : fileNames) { Vector<Pair<String, String>> notFoundList = new Vector<Pair<String, String>>(); Vector<String> terms = new Vector<String>(); String propFileName = baseDir.getAbsolutePath() + "/" + fileName; File resFile = new File(propFileName + ".properties"); if (resFile.exists()) { List<?> lines = FileUtils.readLines(resFile); for (String line : (List<String>) lines) { if (!line.startsWith("#")) { int inx = line.indexOf("="); if (inx > -1) { String[] toks = StringUtils.split(line, "="); if (toks.length > 1) { terms.add(toks[0]); } } } } } else { System.err.println("Doesn't exist: " + resFile.getAbsolutePath()); } String field = "contents"; QueryParser parser = new QueryParser(Version.LUCENE_36, field, analyzer); for (String term : terms) { Query query; try { if (term.equals("AND") || term.equals("OR")) continue; query = parser.parse(term); String subTerm = null; int hits = getTotalHits(query, 10); if (hits == 0) { int inx = term.indexOf('.'); if (inx > -1) { subTerm = term.substring(inx + 1); hits = getTotalHits(parser.parse(subTerm), 10); if (hits == 0) { int lastInx = term.lastIndexOf('.'); if (lastInx > -1 && lastInx != inx) { subTerm = term.substring(lastInx + 1); hits = getTotalHits(parser.parse(subTerm), 10); } } } } if (hits == 0 && !term.endsWith("_desc")) { notFoundList.add(new Pair<String, String>(term, subTerm)); log.debug("'" + term + "' was not found " + (subTerm != null ? ("SubTerm[" + subTerm + "]") : "")); } } catch (ParseException e) { e.printStackTrace(); } } String fullName = propFileName + ".html"; TableWriter tblWriter = convLogger.getWriter(FilenameUtils.getName(fullName), propFileName); tblWriter.startTable(); tblWriter.logHdr("Id", "Full Key", "Sub Key"); int cnt = 1; for (Pair<String, String> pair : notFoundList) { tblWriter.log(Integer.toString(cnt++), pair.first, pair.second != null ? pair.second : " "); } tblWriter.endTable(); fullNotFoundList.addAll(notFoundList); if (notFoundList.size() > 0 && resFile.exists()) { List<String> lines = (List<String>) FileUtils.readLines(resFile); Vector<String> linesCache = new Vector<String>(); for (Pair<String, String> p : notFoundList) { linesCache.clear(); linesCache.addAll(lines); int lineInx = 0; for (String line : linesCache) { if (!line.startsWith("#")) { int inx = line.indexOf("="); if (inx > -1) { String[] toks = StringUtils.split(line, "="); if (toks.length > 1) { if (toks[0].equals(p.first)) { lines.remove(lineInx); break; } } } } lineInx++; } } FileUtils.writeLines(resFile, linesCache); } } convLogger.closeAll(); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LocalizerSearchHelper.class, ex); ex.printStackTrace(); } return fullNotFoundList; }
From source file:net.pms.newgui.Wizard.java
public static void run(final PmsConfiguration configuration) { // Total number of questions int numberOfQuestions = Platform.isMac() ? 4 : 5; // The current question number int currentQuestionNumber = 1; String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ") .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString(); Object[] okOptions = { Messages.getString("Dialog.OK") }; Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") }; Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"), Messages.getString("Wizard.10") }; if (!Platform.isMac()) { // Ask if they want UMS to start minimized int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]); if (whetherToStartMinimized == JOptionPane.YES_OPTION) { configuration.setMinimized(true); } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) { configuration.setMinimized(false); }//from ww w.j a v a 2s .c om } // Ask if their network is wired, etc. int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]); switch (networkType) { case JOptionPane.YES_OPTION: // Wired (Gigabit) configuration.setMaximumBitrate("0"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.NO_OPTION: // Wired (100 Megabit) configuration.setMaximumBitrate("90"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.CANCEL_OPTION: // Wireless configuration.setMaximumBitrate("30"); configuration.setMPEG2MainSettings("Automatic (Wireless)"); configuration.setx264ConstantRateFactor("Automatic (Wireless)"); break; default: break; } // Ask if they want to hide advanced options int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) { configuration.setHideAdvancedOptions(true); } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) { configuration.setHideAdvancedOptions(false); } // Ask if they want to scan shared folders int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) { configuration.setScanSharedFoldersOnStartup(true); } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) { configuration.setScanSharedFoldersOnStartup(false); } // Ask to set at least one shared folder JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"), String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(Messages.getString("Wizard.12")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath()); } else { // If the user cancels this option, the default directories will be used. } } }); } catch (InterruptedException | InvocationTargetException e) { LOGGER.error("Error when saving folders: ", e); } // The wizard finished, do not ask them again configuration.setRunWizard(false); // Save all changes try { configuration.save(); } catch (ConfigurationException e) { LOGGER.error("Error when saving changed configuration: ", e); } }
From source file:com.streamhub.StreamHubLicenseGenerator.java
private JPanel createActionsRow() { JPanel actionsRow = new JPanel(new FlowLayout()); File baseFolder = new File(DEFAULT_CUSTOMERS_DIRECTORY); JButton generate = new JButton("Generate"); generate.addActionListener(new ActionListener() { @Override//from w w w . j a va 2 s .c o m public void actionPerformed(ActionEvent e) { for (JPanel row : macAddressPanels) { try { String macAddress = ((JTextField) row.getComponent(1)).getText(); if (macAddress.length() > 0) { String startDate = ((JTextField) row.getComponent(3)).getText(); String expiryDate = ((JTextField) row.getComponent(5)).getText(); String edition = ((JComboBox) row.getComponent(6)).getSelectedItem().toString(); macAddress = macAddress.replaceAll("-", ":").trim(); String name = ((JTextField) row.getComponent(8)).getText().trim(); String numUsers = ((JTextField) row.getComponent(10)).getText(); String licenseString = startDate + "-" + expiryDate + "-" + numUsers + "-" + macAddress + "-" + edition + ":" + name; String hashInput = licenseString + USELESS_KEY; MessageDigest m = MessageDigest.getInstance("SHA-512"); m.update(hashInput.getBytes(), 0, hashInput.length()); String hash = "==" + new BigInteger(1, m.digest()).toString(16) + "=="; StringBuilder licenseText = new StringBuilder(); licenseText.append("--").append(licenseString).append("--"); licenseText.append(CRLF); licenseText.append(hash); licenseText.append(CRLF); System.out.println(name + ":"); System.out.println(); System.out.println(licenseText); File licenseDir = new File(folderChooser.getSelectedFile(), name); if (!licenseDir.isDirectory() && !licenseDir.exists()) { licenseDir.mkdir(); } File licenseFile = new File(licenseDir, "license.txt"); System.out.println("writing to " + licenseFile.getAbsolutePath()); FileUtils.writeStringToFile(licenseFile, licenseText.toString()); } } catch (Exception exception) { System.out.println("Could not generate license"); exception.printStackTrace(); } } } }); final JButton chooseFolder = new JButton("Choose Folder"); final JTextField folderDisplay = new JTextField(baseFolder.getAbsolutePath()); folderChooser = new JFileChooser(baseFolder); folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folderChooser.setSelectedFile(baseFolder); chooseFolder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == chooseFolder) { int returnVal = folderChooser.showOpenDialog(StreamHubLicenseGenerator.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File folder = folderChooser.getSelectedFile(); folderDisplay.setText(folder.getAbsolutePath()); } } } }); actionsRow.add(folderDisplay); actionsRow.add(chooseFolder); actionsRow.add(generate); return actionsRow; }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Selects a directory (path).//from w w w . j a v a2s.c om * * @param lang * language * @return chosen directory path */ public String selectDirectory(NatLang lang) { JFileChooser dirChooser = new JFileChooser(lastDirectoryPath); dirChooser.setLocale(lang.getLocale()); dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setToolTipText(lang.getText("selectDirectory")); dirChooser.setDialogTitle(lang.getText("selectDirectory")); dirChooser.showDialog(null, lang.getText("selectDirectory")); File f = dirChooser.getSelectedFile(); if (f != null) { lastDirectoryPath = f.getPath(); return lastDirectoryPath; } else { return null; } }
From source file:de.jcup.egradle.other.GroovyParserSourceCollector.java
private void start(String[] args) throws IOException { File groovyProjectDirectory;//w w w .j a v a 2 s .c o m if (args.length == 0) { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(null); groovyProjectDirectory = fc.getSelectedFile(); } else { groovyProjectDirectory = new File(args[0]); } if (groovyProjectDirectory == null) { System.err.println("canceled"); System.exit(1); } System.out.println("use groovy sources at:" + groovyProjectDirectory.getAbsolutePath()); assertDirectoryExists(groovyProjectDirectory); File groovyTempDirectory = new File(groovyProjectDirectory, "/target/tmp/groovydoc"); File target = new File("./..//egradle-plugin-main/src/main/java-groovy"); assertDirectoryExists(target); execute(groovyTempDirectory, target); System.out.println("DONE"); }