List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
From source file:org.domainmath.gui.MainFrame.java
public void saveHistoryAs() { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileFilter(filter);/*from ww w. j av a 2s .c om*/ fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Save As"); File file_save; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getAbsolutePath(); if (!path.endsWith(".m")) { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } else { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } } }
From source file:org.domainmath.gui.MainFrame.java
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setMultiSelectionEnabled(false);//from w w w . jav a2 s. co m Path browse_file; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { browse_file = fc.getSelectedFile().toPath(); setDir(browse_file.toString()); requestToChangeDir(browse_file.toString()); fileTreePanel.updateFileTree(fc.getSelectedFile()); } }
From source file:org.domainmath.gui.MainFrame.java
public void saveplot() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileFilter(DomainMathFileFilter.SAVE_PLOT_FILE_FILTER); fc.setAcceptAllFileFilterUsed(false); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false);//from ww w . java 2s . c om File file_plot; String name; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { System.err.println(fc.getFileFilter().getDescription()); file_plot = fc.getSelectedFile(); name = file_plot.getName(); evaluateWithOutput("saveas(1," + "'" + file_plot.getAbsolutePath() + "');"); } }
From source file:org.esa.snap.core.gpf.ui.OperatorMenu.java
private void applyCurrentDirectory(JFileChooser fileChooser) { if (appContext != null) { String homeDirPath = SystemUtils.getUserHomeDir().getPath(); String lastDir = appContext.getPreferences().getPropertyString(lastDirPreferenceKey, homeDirPath); fileChooser.setCurrentDirectory(new File(lastDir)); }//from ww w.j a v a 2s . c o m }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java
/** * Event handler for this application, handles all menu items. *//*www . ja v a 2 s . c o m*/ public void actionPerformed(ActionEvent event) { // Service Menu Events if ("LoginEvent".equals(event.getActionCommand())) { loginEvent(null); } else if ("LogoutEvent".equals(event.getActionCommand())) { logoutEvent(); } else if (event.getActionCommand() != null && event.getActionCommand().startsWith("LoginSwitch")) { String loginName = event.getActionCommand().substring("LoginSwitch:".length()); AWSCredentials awsCredentials = (AWSCredentials) loginAwsCredentialsMap.get(loginName); loginEvent(awsCredentials); } else if ("QuitEvent".equals(event.getActionCommand())) { System.exit(0); } // Bucket Events. else if ("ViewBucketProperties".equals(event.getActionCommand())) { listBucketProperties(); } else if ("RefreshBuckets".equals(event.getActionCommand())) { listAllBuckets(); } else if ("CreateBucket".equals(event.getActionCommand())) { createBucketAction(); } else if ("DeleteBucket".equals(event.getActionCommand())) { deleteSelectedBucket(); } else if ("ManageDistributions".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); String[] bucketNames = new String[buckets.length]; for (int i = 0; i < buckets.length; i++) { bucketNames[i] = buckets[i].getName(); } ManageDistributionsDialog.showDialog(ownerFrame, cloudFrontService, bucketNames, this); } else if ("AddThirdPartyBucket".equals(event.getActionCommand())) { addThirdPartyBucket(); } else if ("UpdateBucketACL".equals(event.getActionCommand())) { updateBucketAccessControlList(); } else if ("UpdateBucketRequesterPaysStatus".equals(event.getActionCommand())) { updateBucketRequesterPaysSetting(); } // Object Events else if ("ViewOrModifyObjectAttributes".equals(event.getActionCommand())) { displayObjectsAttributesDialog(); } else if ("CopyObjects".equals(event.getActionCommand())) { copyObjects(); } else if ("RefreshObjects".equals(event.getActionCommand())) { listObjects(); } else if ("UpdateObjectACL".equals(event.getActionCommand())) { displayAclModificationDialog(); } else if ("GeneratePublicGetURLs".equals(event.getActionCommand())) { generatePublicGetUrls(); } else if ("GenerateTorrentURL".equals(event.getActionCommand())) { generateTorrentUrl(); } else if ("DeleteObjects".equals(event.getActionCommand())) { deleteSelectedObjects(); } else if ("DownloadObjects".equals(event.getActionCommand())) { downloadSelectedObjects(); } else if ("UploadFiles".equals(event.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setDialogTitle("Choose files to upload"); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setApproveButtonText("Upload files"); fileChooser.setCurrentDirectory(fileChoosersLastUploadDirectory); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } final File[] uploadFiles = fileChooser.getSelectedFiles(); if (uploadFiles.length == 0) { return; } // Save the chosen directory location for next time. fileChoosersLastUploadDirectory = uploadFiles[0].getParentFile(); uploadFiles(uploadFiles); } else if (event.getSource().equals(filterObjectsCheckBox)) { if (filterObjectsCheckBox.isSelected()) { filterObjectsPanel.setVisible(true); } else { filterObjectsPanel.setVisible(false); filterObjectsPrefix.setText(""); if (filterObjectsDelimiter.getSelectedIndex() != 0) { filterObjectsDelimiter.setSelectedIndex(0); } } } // Tools events else if ("BucketLogging".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); BucketLoggingDialog.showDialog(ownerFrame, s3ServiceMulti.getS3Service(), buckets, this); } // Preference Events else if ("PreferencesDialog".equals(event.getActionCommand())) { PreferencesDialog.showDialog(cockpitPreferences, ownerFrame, this); // Save a user's preferences if requested, otherwise wipe any existing preferences file. File cockpitPreferencesPropertiesFile = new File(cockpitHomeDirectory, Constants.COCKPIT_PROPERTIES_FILENAME); if (cockpitPreferences.isRememberPreferences()) { try { Properties properties = cockpitPreferences.toProperties(); if (!cockpitHomeDirectory.exists()) { cockpitHomeDirectory.mkdir(); } properties.list(new PrintStream(new FileOutputStream(cockpitPreferencesPropertiesFile))); } catch (IOException e) { String message = "Unable to save your preferences"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else if (cockpitPreferencesPropertiesFile.exists()) { // User elected not to store preferences, delete the existing preferences file. cockpitPreferencesPropertiesFile.delete(); } if (cockpitPreferences.isEncryptionPasswordSet()) { try { encryptionUtil = new EncryptionUtil(cockpitPreferences.getEncryptionPassword(), cockpitPreferences.getEncryptionAlgorithm(), EncryptionUtil.DEFAULT_VERSION); } catch (Exception e) { String message = "Unable to start encryption utility"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else { encryptionUtil = null; } } // Ooops... else { log.debug("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.gui.LoginLocalFolderPanel.java
private void chooseFolder() { // Prompt user to choose their Cockpit home directory. JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setDialogTitle("Choose Cockpit Home Folder"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Choose Folder"); fileChooser.setCurrentDirectory(cockpitHomeFolder); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return;//from w ww . j a v a2s . c o m } else { this.cockpitHomeFolder = fileChooser.getSelectedFile(); this.folderPathTextField.setText(this.cockpitHomeFolder.getAbsolutePath()); refreshStoredCredentialsTable(); } }
From source file:org.evors.rs.ui.frames.PopulationViewer.java
public void showOpenDialog() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(UIUtils.getUserDir("/user/")); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { try {/*w w w. j av a 2s.c o m*/ loadJSONPopulation(RobotExperiment.fromDirectory(fc.getSelectedFile().getParent()), JSONPopulation.fromJSONFile(fc.getSelectedFile())); } catch (IOException ex) { System.out.println(ex.toString()); } } else { this.dispose(); } }
From source file:org.evors.rs.ui.frames.PopulationViewer.java
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(UIUtils.getUserDir("/user/")); int result = fc.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { PrintWriter out = null;// w w w . ja v a 2 s . c om try { FileUtils.copyFile(new File(exp.getLayout().getFilename()), new File(fc.getSelectedFile().getParent() + "layout.json")); FileUtils.copyFile(new File(exp.getWorld().getFilename()), new File(fc.getSelectedFile().getParent() + "world.json")); JSONPopulation pop = ((PopulationTM) jTable1.getModel()).getPop(); out = new PrintWriter(fc.getSelectedFile()); out.print(pop.toJSONString()); } catch (FileNotFoundException ex) { Logger.getLogger(PopulationViewer.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PopulationViewer.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } } }
From source file:org.giswater.controller.MenuController.java
private String chooseSqlFile(boolean save) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("SQL extension file", "sql"); chooser.setFileFilter(filter);/*from w ww . ja v a 2 s .co m*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.file_sql")); File file = new File(PropertiesDao.getLastSqlPath()); chooser.setCurrentDirectory(file.getParentFile()); int returnVal; if (save) { returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".sql"; fileSql = new File(path); } PropertiesDao.setLastSqlPath(path); } return path; }
From source file:org.giswater.controller.MenuController.java
private File gswChooseFile(boolean save) { String path = ""; File file = null;//from w w w . j av a 2 s. c o m JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("GSW extension file", "gsw"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.gsw_file")); File fileProp = new File(prop.get("FILE_GSW", Utils.getLogFolder())); chooser.setCurrentDirectory(fileProp.getParentFile()); int returnVal; if (save) { returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); path = file.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".gsw"; file = new File(path); } } return file; }