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:lejos.pc.charting.LogChartFrame.java
private void selectFolderButton_actionPerformed(ActionEvent e) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser jfc = new JFileChooser(new File(FQPathTextArea.getText(), "")); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Select"); jfc.setDialogTitle("Select Directory"); jfc.setDialogType(JFileChooser.OPEN_DIALOG); this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); int returnVal = jfc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { FQPathTextArea.setText(getCanonicalName(jfc.getSelectedFile())); jfc.setCurrentDirectory(jfc.getSelectedFile()); System.out.println("folder set to \"" + getCanonicalName(jfc.getSelectedFile()) + "\""); }//w ww .j a v a 2 s .co m }
From source file:com.freedomotic.jfrontend.MainWindow.java
/** * //from w ww. ja v a 2 s . c om * @param evt */ private void mnuNewEnvironmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuNewEnvironmentActionPerformed // we are about to make changes to environments: we'd better save current status mnuSaveActionPerformed(null); File oldEnv = api.environments().findAll().get(0).getSource(); //creates a new environment coping it from a template File template = new File( Info.PATHS.PATH_DATA_FOLDER + "/furn/templates/template-square/template-square.xenv"); LOG.info("Opening new environment template file \"{}\"", template.getAbsolutePath()); setEnvironment(api.environments().findAll().get(0)); try { EnvironmentLogic enL = api.environments().loadEnvironmentFromFile(template); if (enL != null) { //EnvObjectPersistence.loadObjects(EnvironmentPersistence.getEnvironments().get(0).getObjectFolder(), false); final JFileChooser fc = new JFileChooser(oldEnv.getParentFile().getParentFile()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle(api.getI18n().msg("select_env_folder_save")); fc.setSelectedFile(oldEnv.getParentFile()); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); if (!folder.getName().isEmpty()) { if (!folder.getAbsolutePath().equalsIgnoreCase(oldEnv.getParentFile().getAbsolutePath())) { // we are making a new environment set api.environments().deleteAll(); } EnvironmentLogic newenv = api.environments().copy(enL); newenv.setSource(new File(folder + "/" + newenv.getPojo().getUUID() + ".xenv")); setEnvironment(newenv); api.environments().saveAs(newenv, folder); } } else { LOG.info("Save command cancelled by user."); //reload the old file api.environments().init(oldEnv.getParentFile()); setEnvironment(api.environments().findAll().get(0)); } } } catch (Exception e) { LOG.error(Freedomotic.getStackTraceInfo(e)); } setWindowedMode(); }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void changeBaseDir() { File baseDir = new File(iliasProperties.getBaseDirectory()); JFileChooser fileChooser = new JFileChooser(baseDir); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(mainFrame)) { String s = fileChooser.getSelectedFile().getAbsolutePath(); JOptionPane.showMessageDialog(mainFrame, "Der neue Speicherort ist jetzt " + s, "Neuer Speicherort", JOptionPane.INFORMATION_MESSAGE); iliasProperties.setBaseDirectory(s); saveProperties(iliasProperties); } else {/*from w ww . j a va 2 s . c o m*/ JOptionPane.showMessageDialog(mainFrame, "Der alte Speicherort wird beibehalten " + baseDir.getAbsolutePath(), "Speicherort", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.yifanlu.PSXperiaTool.Interface.GUI.java
private void chooseConvertOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseConvertOutputActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); convertOutputInput.setText(file.getPath()); }/* ww w.j a v a 2s . c o m*/ }
From source file:configuration.Util.java
public static String[] simpleSearchBox(String type, boolean multi, boolean hide) { JFrame f = createSearchFrame(); JFileChooser jf;//from ww w . jav a2 s .com jf = new JFileChooser(config.getExplorerPath()); if (type.contains("d") || type.contains("D")) jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else if (type.contains("f") || type.contains("F")) jf.setFileSelectionMode(JFileChooser.FILES_ONLY); else jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jf.setAcceptAllFileFilterUsed(false); jf.setMultiSelectionEnabled(multi); jf.setFileHidingEnabled(hide); int result = jf.showOpenDialog(f); f.dispose(); if (result == JFileChooser.APPROVE_OPTION) { if (multi) { //--Save new filepath and files File[] files = jf.getSelectedFiles(); String[] path = new String[files.length]; for (int i = 0; i < files.length; i++) { path[i] = getCanonicalPath(files[i].getPath()); } return path; } else { File file = jf.getSelectedFile(); String[] path = new String[1]; path[0] = getCanonicalPath(file.getPath()); return path; } } String[] empty = new String[0]; return empty; }
From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java
public void actionPerformed(ActionEvent arg0) { JMenuItem source = (JMenuItem) (arg0.getSource()); if (source.getText().equals(MENU_ABOUT)) { JOptionPane.showMessageDialog(this, WDBearManager.VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "\n" + "Supports any WDB version\n" + "\n" + "Thanks to:\n" + "DarkMan for testing,\n" + "John for the 1.10 specs, Annunaki for helping with the header,\n" + "Andrikos for the 1.6.x WDB specs, Pyro's WDBViewer, WDDG Forum,\n" + "blizzhackers, etc etc\n\n" + "This program uses: \n" + "JGoodies from http://www.jgoodies.com/\n" + "Hypersonic SQL database 1.7.3\n" + "Apache Log4J, Xerces\n" + "Jakarta Commons Logging and CLI\n" + "Castor from ExoLab\n" + "MySQL JDBC connector 3.1.7\n" + "HTTPUNIT from Russell Gold\n" + "Jython 2.1\n" + "Refer to directory 'licenses' for more details about the software used\n" + "PLEASE:\n" + "If you like this program and find it usefull:\n" + "Please donate money to a charity oranization of your choice.\n" + "I recommend any organization that fights cancer.\n\n" + "License:\n" + "WDBearMgr is placed under the GNU GPL. \n" + "For further information, see the page :\n" + "http://www.gnu.org/copyleft/gpl.html.\n" + "See licenses/GPL_license.html\n" + "\n" + "For a different license please contact the author.", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return;/* ww w. j av a 2s . co m*/ } else if (source.getText().equals(MENU_HELP)) { JFrame myFrame = new JFrame("doc/html/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/html/index.html"); urlHTML = scriptFile.toURL();//this.getClass().getResource("/scripts/"+source.getName()+".py"); // .out.println( urlHTML ); // .out.println( urlHTML.toExternalForm() ); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/html/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_JDOCS)) { JFrame myFrame = new JFrame("doc/javadoc/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/javadoc/index.html"); urlHTML = scriptFile.toURL(); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/javadoc/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_CHECKUPDATE)) { Properties dbProps = null; String filName = PROPS_CHECK_UPDATE; try { dbProps = ReadPropertiesFile.readProperties(filName); String updFile = dbProps.getProperty(KEY_UPD_FILE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find update information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } String updSite = dbProps.getProperty(KEY_WDBMGR_SITE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find SITE information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } URL urlUpdScript = new URL(updFile); BufferedReader in = new BufferedReader(new InputStreamReader(urlUpdScript.openStream())); String versionTXT = in.readLine(); String downloadName = in.readLine(); in.close(); if (versionTXT.equals(WDBearManager.VERSION_INFO)) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "You are using the latest version, no updates available", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return; } else { // Read version.txt String versionInfo = (String) dbProps.getProperty(KEY_VERSION_INFO); URL urlversionInfo = new URL(versionInfo); BufferedReader brVInfo = new BufferedReader(new InputStreamReader(urlversionInfo.openStream())); StringBuffer sbuVInfo = new StringBuffer(); String strLine = ""; boolean foundStart = false; while ((strLine = brVInfo.readLine()) != null) { if (strLine.startsWith("---")) { break; } if (foundStart == true) { sbuVInfo.append(strLine); sbuVInfo.append("\n"); continue; } if (strLine.startsWith(versionTXT)) { foundStart = true; continue; } } brVInfo.close(); int n = JOptionPane.showConfirmDialog(this, "New version available - Please visit " + updSite + "\n\n" + versionTXT + "\n" + "\n" + "You are using version:\n" + WDBearManager.VERSION_INFO + "\n" + "\n" + "Do you want to download this version?\n\n" + "Version information:\n" + sbuVInfo.toString(), VERSION_INFO + "by kizura", JOptionPane.YES_NO_OPTION); // JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" // + "by kizura\n" + WDBManager.EMAIL + "\n\n" // + "New version available - Please visit " + updSite, // "Warning " // + VERSION_INFO, JOptionPane.WARNING_MESSAGE); if (n == 0) { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Please select download location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { URL urlUpd = new URL(downloadName); BufferedInputStream bin = new BufferedInputStream(urlUpd.openStream()); System.out.println( new File(chooser.getSelectedFile(), urlUpd.getFile()).getAbsolutePath()); File thisFile = new File(chooser.getSelectedFile(), urlUpd.getFile()); BufferedOutputStream bout = new BufferedOutputStream( new FileOutputStream(thisFile)); byte[] bufFile = new byte[102400]; int bytesRead = 0; while ((bytesRead = bin.read(bufFile)) != -1) { bout.write(bufFile, 0, bytesRead); } bin.close(); bout.close(); JOptionPane.showMessageDialog(this, "Update downloaded successfully" + "\n" + "Please check '" + thisFile.getAbsolutePath() + "'", "Success " + WDBearManager.VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); //String msg = WriteCSV.writeCSV(chooser.getSelectedFile(), this.items); } catch (Exception ex) { String msg = ex.getMessage(); JOptionPane.showMessageDialog(this, msg + "\n" + "Error downloading update", "Error " + WDBearManager.VERSION_INFO, JOptionPane.ERROR_MESSAGE); } } } // user selected "download" return; } } catch (Exception ex) { ex.printStackTrace(); } } else { System.exit(0); } }
From source file:com.josescalia.tumblr.form.PreferenceForm.java
private void btnChooseFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseFolderActionPerformed folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnValue = folderChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { setDefaultDownloadPath(folderChooser.getSelectedFile().getPath()); }// w ww.j a va 2 s. c o m }
From source file:md.mclama.com.ModManager.java
public void findPath() { chooser = new JFileChooser(); if (gamePath != null) chooser.setCurrentDirectory(new java.io.File(gamePath)); else//from w w w .j a v a 2 s. c om chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { con.log("Log", "getCurrentDirectory(): " + chooser.getCurrentDirectory()); con.log("Log", "getSelectedFile() : " + chooser.getSelectedFile()); gamePath = "" + chooser.getSelectedFile(); if (gamePath.endsWith("/mods")) { gamePath = gamePath.replace("/mods", ""); } con.log("Log", gamePath); txtGamePath.setText(gamePath); validatePath(); checkAccess(); getMods(); writeData(); } else { con.log("Log", "No Selection "); } }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
private void exportActiveOutlineToAtom() { if (MindRaider.profile.getActiveOutline() == null) { JOptionPane.showMessageDialog(MindRaiderMainWindow.this, Messages.getString("MindRaiderJFrame.exportNotebookWarning"), Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE); return;/*from www. j a v a2s .co m*/ } JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator + "sharing"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String dstDirectory = fc.getSelectedFile().getAbsolutePath(); Utils.createDirectory(dstDirectory); final String dstFileName = dstDirectory + File.separator + "MindRaider-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + "-" + Utils.getCurrentDataTimeAsPrettyString() + ".atom.xml"; logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName)); MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_ATOM, dstFileName); } else { logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser")); } }
From source file:com.pianobakery.complsa.MainGui.java
public void createNewProjectFolder() { try {/* www .ja v a2 s .c om*/ JFrame frame = new JFrame(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(openFolder); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Create Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setSelectedFile(new File("Workingfile")); frame.getContentPane().add(chooser); chooser.setApproveButtonText("Choose"); //Disable Save as ArrayList<JPanel> jpanels = new ArrayList<JPanel>(); for (Component c : chooser.getComponents()) { if (c instanceof JPanel) { jpanels.add((JPanel) c); } } jpanels.get(0).getComponent(0).setVisible(false); frame.pack(); frame.setLocationRelativeTo(null); int whatChoose = chooser.showSaveDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { File selFile = chooser.getSelectedFile(); File currDir = chooser.getCurrentDirectory(); Path parentDir = Paths.get(chooser.getCurrentDirectory().getParent()); String parentDirName = parentDir.getFileName().toString(); logger.debug("Chooser SelectedFile: " + selFile.toString()); logger.debug("getCurrentDirectory(): " + currDir.toString()); logger.debug("Chooser parentdir: " + parentDir); logger.debug("Parentdirname: " + parentDirName); if (selFile.getName().equals(parentDirName)) { wDir = currDir; } else { wDir = chooser.getSelectedFile(); } logger.debug("WDIR is: " + wDir.toString()); wDirText.setText(wDir.toString()); enableUIElements(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); logger.debug("Exeption: " + ex.toString()); } }