List of usage examples for javax.swing JFileChooser getCurrentDirectory
public File getCurrentDirectory()
From source file:com.pianobakery.complsa.MainGui.java
public void chooseNewProjectFolder() { try {/*from ww w .j av a 2s . c o m*/ JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(openFolder); //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Choose Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); chooser.setApproveButtonText("Choose"); int whatChoose = chooser.showOpenDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { String text = chooser.getSelectedFile().toString(); wDirText.setText(text); wDir = chooser.getSelectedFile(); logger.debug("WDir is: " + wDir.toString()); logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory()); logger.debug("getSelectedFile() : " + chooser.getSelectedFile()); enableUIElements(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); } }
From source file:com.mirth.connect.client.ui.Frame.java
public File browseForFile(String fileExtension) { JFileChooser importFileChooser = new JFileChooser(); if (fileExtension != null) { importFileChooser.setFileFilter(new MirthFileFilter(fileExtension)); }/*from w w w . j a va2s . co m*/ File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { importFileChooser.setCurrentDirectory(currentDir); } if (importFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { userPreferences.put("currentDirectory", importFileChooser.getCurrentDirectory().getPath()); return importFileChooser.getSelectedFile(); } return null; }
From source file:com.mirth.connect.client.ui.Frame.java
public void doExportAlerts() { JFileChooser exportFileChooser = new JFileChooser(); exportFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { exportFileChooser.setCurrentDirectory(currentDir); }/*from w w w . jav a 2s.c o m*/ int returnVal = exportFileChooser.showSaveDialog(this); File exportFile = null; File exportDirectory = null; if (returnVal == JFileChooser.APPROVE_OPTION) { userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath()); try { exportDirectory = exportFileChooser.getSelectedFile(); List<AlertModel> alerts; try { alerts = mirthClient.getAllAlerts(); } catch (ClientException e) { alertThrowable(this, e); return; } for (AlertModel alert : alerts) { ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance(); String channelXML = serializer.serialize(alert); exportFile = new File(exportDirectory.getAbsolutePath() + "/" + alert.getName() + ".xml"); if (exportFile.exists()) { if (!alertOption(this, "The file " + alert.getName() + ".xml already exists. Would you like to overwrite it?")) { continue; } } FileUtils.writeStringToFile(exportFile, channelXML, UIConstants.CHARSET); } alertInformation(this, "All files were written successfully to " + exportDirectory.getPath() + "."); } catch (IOException ex) { alertError(this, "File could not be written."); } } }
From source file:com.mirth.connect.client.ui.Frame.java
/** * Creates a File with the default defined file filter type, but does not yet write to it. * /*from www . j av a 2s .co m*/ * @param defaultFileName * @param fileExtension * @return */ public File createFileForExport(String defaultFileName, String fileExtension) { JFileChooser exportFileChooser = new JFileChooser(); if (defaultFileName != null) { exportFileChooser.setSelectedFile(new File(defaultFileName)); } if (fileExtension != null) { exportFileChooser.setFileFilter(new MirthFileFilter(fileExtension)); } File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { exportFileChooser.setCurrentDirectory(currentDir); } if (exportFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { userPreferences.put("currentDirectory", exportFileChooser.getCurrentDirectory().getPath()); File exportFile = exportFileChooser.getSelectedFile(); if ((exportFile.getName().length() < 4) || !FilenameUtils.getExtension(exportFile.getName()).equalsIgnoreCase(fileExtension)) { exportFile = new File(exportFile.getAbsolutePath() + "." + fileExtension.toLowerCase()); } if (exportFile.exists()) { if (!alertOption(this, "This file already exists. Would you like to overwrite it?")) { return null; } } return exportFile; } else { return null; } }
From source file:com.pianobakery.complsa.MainGui.java
public void createNewProjectFolder() { try {//from ww w .ja v a 2 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()); } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Loads a new Image into a WB Row./*from ww w . ja v a 2 s . co m*/ * XXX Note this needs to to be refactored so both the WorkbenchTask and this class use the same image load method. * * @param row the row of the new card image * @return true if the row was set */ protected boolean loadNewImage(final WorkbenchRow row) { ImageFilter imageFilter = new ImageFilter(); JFileChooser fileChooser = new JFileChooser( WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMAGES_FILE_PATH)); fileChooser.setFileFilter(imageFilter); int userAction = fileChooser.showOpenDialog(this); AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.put(WorkbenchTask.IMAGES_FILE_PATH, fileChooser.getCurrentDirectory().getAbsolutePath()); if (userAction == JFileChooser.APPROVE_OPTION) { String fullPath = fileChooser.getSelectedFile().getAbsolutePath(); if (imageFilter.isImageFile(fullPath)) { File chosenFile = fileChooser.getSelectedFile(); row.setCardImage(chosenFile); row.setCardImageFullPath(chosenFile.getAbsolutePath()); if (row.getLoadStatus() != WorkbenchRow.LoadStatus.Successful) { if (!WorkbenchTask.showLoadStatus(row, false)) { return false; } } return true; } // turn off alwaysOnTop for Swing repaint reasons (prevents a lock up) if (imageFrame != null) { imageFrame.setAlwaysOnTop(false); } JOptionPane.showMessageDialog(UIRegistry.getMostRecentWindow(), String.format(getResourceString("WB_WRONG_IMAGE_TYPE"), new Object[] { FilenameUtils.getExtension(fullPath) }), UIRegistry.getResourceString("WARNING"), JOptionPane.ERROR_MESSAGE); } return false; }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter);//from ww w . j av a 2s . co m chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); } return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }
From source file:org.archiviststoolkit.importer.ImportUtils.java
public static File chooseFile(Component parent, SimpleFileFilter fileFilter) { UserPreferences userPrefs = UserPreferences.getInstance(); JFileChooser chooser; if (userPrefs.getSavePath() == null) { chooser = new JFileChooser(); } else {/*from w w w .j a v a 2 s . co m*/ chooser = new JFileChooser(userPrefs.getSavePath()); } if (fileFilter != null) { chooser.setFileFilter(fileFilter); } // chooser.setCurrentDirectory("."); if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) { return null; } else { userPrefs.setSavePath(chooser.getCurrentDirectory().getPath()); return chooser.getSelectedFile(); } }
From source file:org.colombbus.tangara.CommandSelection.java
private void succeedSavingFile(JFileChooser fileChooser, File destinationFile) { String message;//ww w . j a v a 2 s .com if (mode == MODE_PROGRAM_CREATION) message = MessageFormat.format(Messages.getString("CommandSelection.programCreation.saveOk"), destinationFile.getName()); else message = MessageFormat.format(Messages.getString("CommandSelection.fileCreation.saveOk"), destinationFile.getName()); myParent.printInfo(message); myParent.setCurrentDirectory(fileChooser.getCurrentDirectory()); }
From source file:org.domainmath.gui.MainFrame.java
/** * Creates file chooser dialog box and allows the user to select files * and importData selected files in fileTab. *///from ww w . jav a2s . c om public void open() { JFileChooser fc = new JFileChooser(); // set current directory. if (fileTab.getTabCount() > 0) { File f = new File(fileTab.getToolTipTextAt(fileTab.getSelectedIndex())); fc.setCurrentDirectory(f.getParentFile()); } else { fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); } FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(true); fc.setFileView(new ScriptFileView()); File file1[]; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file1 = fc.getSelectedFiles(); this.setCurrentDirFileTab(fc.getCurrentDirectory().getAbsolutePath()); for (int i = 0; i < file1.length; i++) { if (!fileNameList.contains(file1[i].getAbsolutePath())) { open(file1[i], i); } else { System.out.println(file1[i].getAbsolutePath() + " already open!"); } } } }