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.giswater.controller.MenuController.java
private String chooseFileSetup(String fileName) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("EXE extension file", "exe"); chooser.setFileFilter(filter);//from ww w . j a v a 2s .com chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("file_exe")); File file = new File(usersFolder + fileName); chooser.setCurrentDirectory(file); chooser.setSelectedFile(file); int returnVal = chooser.showOpenDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".exe"; fileSql = new File(path); } } return path; }
From source file:org.jab.docsearch.DocSearch.java
private void doOpen() { JFileChooser fdo = new JFileChooser(); fdo.setCurrentDirectory(new File(defaultSaveFolder)); int fileGotten = fdo.showDialog(this, I18n.getString("button.open")); if (fileGotten == JFileChooser.APPROVE_OPTION) { File file = fdo.getSelectedFile(); String fileName = file.toString(); // get document stream and save it if (!fileName.startsWith("http")) { setPage(fileString + fileName); } else {//ww w .j a va 2 s . c om setPage(fileName); } } // end if approved }
From source file:org.jab.docsearch.DocSearch.java
private void doSave() { setStatus(I18n.getString("tooltip.save")); // defaultSaveFolder JFileChooser fds = new JFileChooser(); fds.setDialogTitle(I18n.getString("windowtitle.save")); String saveName;/*from w w w. jav a 2s . c o m*/ if (curPage.equals("results")) { saveName = "results.htm"; } else if (curPage.equals("home")) { saveName = "home.htm"; } else { saveName = Utils.getNameOnly(curPage); } saveName = FileUtils.addFolder(defaultSaveFolder, saveName); fds.setCurrentDirectory(new File(defaultSaveFolder)); fds.setSelectedFile(new File(saveName)); int fileGotten = fds.showDialog(this, I18n.getString("button.save")); if (fileGotten == JFileChooser.APPROVE_OPTION) { File saveFile = fds.getSelectedFile(); setStatus(I18n.getString("button.save") + saveFile); // get document stream and save it String saveText = editorPane.getText(); PrintWriter pw = null; try { pw = new PrintWriter(new FileWriter(saveFile)); pw.print(saveText); } catch (IOException ioe) { logger.fatal("doSave() failed with IOException", ioe); showMessage(dsErrSaFi, "\n" + saveFile); } finally { IOUtils.closeQuietly(pw); } } }
From source file:org.jab.docsearch.DocSearch.java
private void getSeachLogReport() { JFileChooser fdo = new JFileChooser(); fdo.setCurrentDirectory(new File(fEnv.getWorkingDirectory())); int fileGotten = fdo.showDialog(this, I18n.getString("select")); if (fileGotten == JFileChooser.APPROVE_OPTION) { File file = fdo.getSelectedFile(); try {/*from w ww. ja va 2 s .c om*/ LogAnalysis.doLogAnalysis(this, file.toString()); } catch (IOException ioe) { logger.fatal("getSeachLogReport() failed", ioe); setStatus(I18n.getString("error_status_log_report") + ioe.toString()); } } }
From source file:org.javaswift.cloudie.CloudiePanel.java
protected void onDownloadStoredObject() { Container container = getSelectedContainer(); List<StoredObject> obj = getSelectedStoredObjects(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(lastFolder); if (obj.size() == 1) { chooser.setSelectedFile(new File(obj.get(0).getName())); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } else {//from ww w. j a va 2s . c o m chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); for (StoredObject so : obj) { File target = selected; if (target.isDirectory()) { target = new File(selected, so.getName()); } if (target.exists()) { if (confirm("File '" + target.getName() + "' already exists. Overwrite?")) { doSaveStoredObject(target, container, so); } } else { doSaveStoredObject(target, container, so); } } lastFolder = selected.isFile() ? selected.getParentFile() : selected; } }
From source file:org.javaswift.cloudie.CloudiePanel.java
protected void onCreateStoredObject() { Container container = getSelectedContainer(); JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.setCurrentDirectory(lastFolder); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = chooser.getSelectedFiles(); ops.createStoredObjects(container, selectedFiles, callback); lastFolder = chooser.getCurrentDirectory(); }//from w w w. j a v a 2 s.c om }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Event handler for this application, handles all menu items. *//*from w ww .ja v a 2 s . co m*/ public void actionPerformed(ActionEvent event) { if (event.getSource().equals(loginButton)) { new Thread() { @Override public void run() { listObjects(); } }.start(); } // Object Events else if ("ViewObjectProperties".equals(event.getActionCommand())) { listObjectProperties(); } else if ("RefreshObjects".equals(event.getActionCommand())) { new Thread() { @Override public void run() { listObjects(); } }.start(); } else if ("TogglePublicPrivate".equals(event.getActionCommand())) { new Thread() { @Override public void run() { S3Object object = getSelectedObjects()[0]; String aclStatus = objectTableModel.getObjectAclStatus(object); boolean originalAclWasPublic = ACL_PUBLIC_DESCRIPTION.equals(aclStatus); ToggleAclDialog dialog = new ToggleAclDialog(ownerFrame, originalAclWasPublic, null, cockpitLiteProperties.getProperties()); dialog.setVisible(true); // Update ACL setting. S3Object minimalObject = new S3Object(object.getKey()); AccessControlList newAcl = (dialog.isPublicAclSet() ? AccessControlList.REST_CANNED_PUBLIC_READ : AccessControlList.REST_CANNED_PRIVATE); if (newAcl != null) { if (AccessControlList.REST_CANNED_PRIVATE.equals(newAcl)) { minimalObject.addMetadata(Constants.REST_HEADER_PREFIX + "acl", "private"); } else if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(newAcl)) { minimalObject.addMetadata(Constants.REST_HEADER_PREFIX + "acl", "public-read"); } } updateObjectsAccessControlLists(new S3Object[] { minimalObject }, newAcl); dialog.dispose(); } }.start(); } else if ("GeneratePublicGetURL".equals(event.getActionCommand())) { generatePublicGetUrl(); } else if ("DeleteObjects".equals(event.getActionCommand())) { deleteSelectedObjects(); } else if ("DownloadObjects".equals(event.getActionCommand())) { try { downloadSelectedObjects(); } catch (Exception ex) { String message = "Unable to download objects from S3"; log.error(message, ex); ErrorDialog.showDialog(ownerFrame, this, cockpitLiteProperties.getProperties(), message, ex); } } else if ("UploadFiles".equals(event.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setDialogTitle("Choose file(s) 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(); new Thread() { @Override public void run() { prepareForFilesUpload(uploadFiles); } }.start(); } else if (event.getSource().equals(filterObjectsCheckBox)) { if (filterObjectsCheckBox.isSelected()) { filterObjectsPanel.setVisible(true); } else { filterObjectsPanel.setVisible(false); filterObjectsPrefix.setText(""); } } // Ooops... else { log.warn("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event); } }
From source file:org.kse.gui.actions.ImportCaReplyFromFileAction.java
private File chooseCaFile() { JFileChooser chooser = FileChooserFactory.getCaReplyFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("ImportCaReplyFromFileAction.ImportCaReply.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(frame, res.getString("ImportCaReplyFromFileAction.ImportCaReply.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File openFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(openFile); return openFile; }/*from www . ja v a 2 s . c o m*/ return null; }
From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java
private void browsePolicyPressed() { JFileChooser chooser = FileChooserFactory.getZipFileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(res.getString("DUpgradeCryptoStrength.Title.ChoosePolicyZip.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(this, res.getString("DUpgradeCryptoStrength.Title.PolicyZipChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); if (!chosenFile.isFile()) { JOptionPane.showMessageDialog(DUpgradeCryptoStrength.this, res.getString("DUpgradeCryptoStrength.NotPolicyZip.message"), res.getString("DUpgradeCryptoStrength.Title"), JOptionPane.WARNING_MESSAGE); return; }/*from w w w. j a va 2s .c om*/ processPolicyZipFile(chosenFile); } }
From source file:org.kse.gui.dialogs.importexport.DImportKeyPairOpenSsl.java
private void privateKeyBrowsePressed() { JFileChooser chooser = FileChooserFactory.getOpenSslPvkFileChooser(); File currentFile = new File(jtfPrivateKeyPath.getText()); if ((currentFile.getParentFile() != null) && (currentFile.getParentFile().exists())) { chooser.setCurrentDirectory(currentFile.getParentFile()); } else {/* w w w . j ava 2s .com*/ chooser.setCurrentDirectory(CurrentDirectory.get()); } chooser.setDialogTitle(res.getString("DImportKeyPairOpenSsl.ChoosePrivateKey.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(this, res.getString("DImportKeyPairOpenSsl.PrivateKeyFileChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); jtfPrivateKeyPath.setText(chosenFile.toString()); jtfPrivateKeyPath.setCaretPosition(0); } }