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:edu.harvard.mcz.imagecapture.jobs.JobAllImageFilesScan.java
@Override public void start() { startTime = new Date(); Singleton.getSingletonInstance().getJobList().addJob((RunnableJob) this); runStatus = RunStatus.STATUS_RUNNING; File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL startPoint = null;//from w w w. ja v a2s . c om // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser.setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } //TODO: Filechooser to pick path, then save (if SCAN_ALL) imagebase property. //Perhaps. Might be undesirable behavior. //Probably better to warn that imagebase is null; } // TODO: Check that startPoint is or is within imagebase. // Check that fileToCheck is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { // run in separate thread and allow cancellation and status reporting // walk through directory tree if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { Singleton.getSingletonInstance().getMainFrame() .setStatusMessage("Scanning " + startPoint.getPath()); Counter counter = new Counter(); // count files to scan countFiles(startPoint, counter); setPercentComplete(0); Singleton.getSingletonInstance().getMainFrame().notifyListener(runStatus, this); counter.incrementDirectories(); // scan if (runStatus != RunStatus.STATUS_TERMINATED) { checkFiles(startPoint, counter); } // report String report = "Scanned " + counter.getDirectories() + " directories.\n"; report += "Created thumbnails in " + thumbnailCounter + " directories"; if (thumbnailCounter == 0) { report += " (May still be in progress)"; } report += ".\n"; if (startPointSpecific == null) { report += "Starting with the base image directory (Preprocess All).\n"; } else { report += "Starting with " + startPoint.getName() + " (" + startPoint.getPath() + ")\n"; report += "First file: " + firstFile + " Last File: " + lastFile + "\n"; } report += "Scanned " + counter.getFilesSeen() + " files.\n"; report += "Created " + counter.getFilesDatabased() + " new image records.\n"; if (counter.getFilesUpdated() > 0) { report += "Updated " + counter.getFilesUpdated() + " image records.\n"; } report += "Created " + counter.getSpecimens() + " new specimen records.\n"; if (counter.getSpecimensUpdated() > 0) { report += "Updated " + counter.getSpecimensUpdated() + " specimen records.\n"; } report += "Found " + counter.getFilesFailed() + " files with problems.\n"; //report += counter.getErrors(); Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Preprocess scan complete"); setPercentComplete(100); Singleton.getSingletonInstance().getMainFrame().notifyListener(runStatus, this); RunnableJobReportDialog errorReportDialog = new RunnableJobReportDialog( Singleton.getSingletonInstance().getMainFrame(), report, counter.getErrors(), "Preprocess Results"); errorReportDialog.setVisible(true); //JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), report, "Preprocess complete", JOptionPane.ERROR_MESSAGE); } // can read directory } SpecimenLifeCycle sls = new SpecimenLifeCycle(); Singleton.getSingletonInstance().getMainFrame().setCount(sls.findSpecimenCount()); } // Imagebase isn't null done(); }
From source file:ElectionGUI.java
private void loadElectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadElectionBtnActionPerformed if (!generalPreferencesCheckBox.isSelected()) { //Confirmation of discarding an election2D that is not saved boolean discard = true; if (election2D != null && !saved) { int response = JOptionPane.showConfirmDialog(null, "Current " + "election is not saved, are you sure you want to load " + "an election?" + eol + "Press \"No\" to save current " + "election in a file.", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { discard = false;// w ww . ja v a 2s . co m } } if (discard) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(folder); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { folder = fileChooser.getCurrentDirectory(); File selectedFile = fileChooser.getSelectedFile(); Parse2dElection parser = new Parse2dElection(); parser.parseFromFile(selectedFile); if (parser.getErr() == null) { election2D = parser.getElection(); nTxtField.setText(String.valueOf(election2D.getNumberOfVoters())); mTxtField.setText(String.valueOf(election2D.getNumberOfCandidates())); kTxtField.setText(String.valueOf(election2D.getCommitteeSize())); xLimit = parser.getxLimit(); xLimitTxtField.setText(String.valueOf(xLimit)); yLimit = parser.getyLimit(); yLimitTxtField.setText(String.valueOf(yLimit)); nClusters = parser.getnClusters(); nClusterTxtField.setText(String.valueOf(nClusters)); mClusters = parser.getmClusters(); mClusterTxtField.setText(String.valueOf(mClusters)); systemTxt.append("-Election loaded." + eol); plotResultsBtn.setEnabled(true); saveElectionBtn.setEnabled(true); consistencyBtn.setEnabled(false); saved = true; } else { systemTxt.append(parser.getErr() + eol); } } else if (result == JFileChooser.CANCEL_OPTION) { systemTxt.append("-Loading cancelled." + eol); } } } else { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(folder); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { folder = fileChooser.getCurrentDirectory(); File selectedFile = fileChooser.getSelectedFile(); ParseGeneralElection parser = new ParseGeneralElection(); parser.parseFromFile(selectedFile); if (parser.getErr() == null) { ArrayList<Voter> voters = parser.getVoters(); ArrayList<Candidate> candidates = parser.getCandidates(); n = voters.size(); m = candidates.size(); try { int x = Integer.parseInt(kTxtField.getText()); if (x < 1 || x > 100 || x > m) { throw (new Exception()); } k = x; } catch (Exception e) { kTxtField.setBackground(Color.cyan); kTxtField.setText("1"); k = 1; systemTxt.append("-Committee size was invalid. It has " + "been set equal to 1." + eol); } electionGP = new Election(k, voters, candidates, false); plotResultsBtn.setEnabled(true); consistencyBtn.setEnabled(false); systemTxt .append("-Election " + selectedFile.getName() + " has been loaded successfully." + eol); } else { systemTxt.append(parser.getErr() + eol); } } else if (result == JFileChooser.CANCEL_OPTION) { systemTxt.append("-Loading cancelled." + eol); } } }
From source file:cn.labthink.ReadAccess060.java
private void jButton_exportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_exportActionPerformed JFileChooser jfc = new JFileChooser(); ExtensionFileFilter filter;/*from w w w . j a va2s . co m*/ if (jTable1.getSelectedRowCount() == 1) { // filter filter = new ExtensionFileFilter("xls", false, true); filter.setDescription("Save Export File"); jfc.setDialogTitle("Create the Export Excel file"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); } else if (jTable1.getSelectedRowCount() > 1) { // filter filter = new ExtensionFileFilter("", false, true); filter.setDescription("Save Export Files"); jfc.setDialogTitle("Choose the Export Directory"); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } else { //? jLabel_info.setText("<html><font color='red'>No Record Selected</font></html>"); return; } //? FileSystemView fsv = FileSystemView.getFileSystemView(); //? jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.SAVE_DIALOG); jfc.setFileFilter(filter); int result = jfc.showSaveDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { if (jTable1.getSelectedRowCount() == 1) { // String filesrc = jfc.getSelectedFile().getAbsolutePath(); if (!filesrc.toLowerCase().endsWith(".xls")) { filesrc = jfc.getSelectedFile().getAbsolutePath() + ".xls"; } outputfile = new File(filesrc); jLabel_info.setText("Exported File:" + outputfile.getAbsolutePath()); } else if (jTable1.getSelectedRowCount() > 1) { // outputfile = jfc.getSelectedFile().isDirectory() ? jfc.getSelectedFile() : jfc.getSelectedFile().getParentFile(); if (outputfile == null) { outputfile = fsv.getHomeDirectory(); } jLabel_info.setText("Exported to path:" + outputfile.getAbsolutePath()); } else { //? return; } } else { return; } if (inputfile == null) { return; } int[] rows = jTable1.getSelectedRows(); if (rows.length == 1) { //? book = null; ExportOneRecord(rows[0]); } else { File path = outputfile; for (int rowindex = 0; rowindex < rows.length; rowindex++) { int k = rows[rowindex]; book = null; outputfile = new File(path.getAbsolutePath() + "/" + jTable1.getValueAt(k, 0) + ".xls"); ExportOneRecord(k); } } // int k = jTable1.getSelectedRow(); // ExportOneRecord(k); }
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 w w . j a va 2 s. co m*/ }
From source file:com.nbt.TreeFrame.java
protected JFileChooser createFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileHidingEnabled(false);/*from w w w .j a va 2 s. c o m*/ fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); String description = "named binary tag"; FileFilter filter = new FileNameExtensionFilter(description, "mcr", "dat", "dat_old"); fc.setFileFilter(filter); Preferences prefs = getPreferences(); String exportFile = prefs.get(KEY_FILE, null); if (exportFile == null) { File cwd = new File("."); fc.setCurrentDirectory(cwd); } else { File selectedFile = new File(exportFile); fc.setSelectedFile(selectedFile); } return fc; }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected SimpleAction createSaveScriptAsAction() { return new SimpleAction("Save as", "Save script as", "document-save-as-2-16x16.png") { @Override/*from w w w .j a v a 2s . co m*/ public void actionPerformed(ActionEvent e) { validateScriptData(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter( AppConstants.ORG_NAME + " script (" + ScriptConstants.FILE_EXT.toLowerCase() + ")", ScriptConstants.FILE_EXT)); File file = ScriptEditor.this.file; if (file == null) { file = createDefaultFilename(); } if (file == null) { file = PreferencesManager.getSingleton().getScriptsDirectory(); } // ensure absolute if (file != null) { file = file.getAbsoluteFile(); } // ensure have filename if (file != null && file.isDirectory()) { file = new File(file, createDefaultPathlessFilename()); } if (file != null) { chooser.setCurrentDirectory(file.getParentFile()); chooser.setSelectedFile(file); } if (chooser.showSaveDialog(ScriptEditor.this) == JFileChooser.APPROVE_OPTION) { save(chooser.getSelectedFile()); } } }; }
From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java
public void openFiletoCurve() throws NumberFormatException { String tempstr = jFormattedTextField_temp.getText(); int tempint = Integer.parseInt(tempstr); dropinterval = tempint;//from w w w . jav a 2s . com //?? //??0?1 double oldzero = -1000; long oldzerotime = -1; double oldstatus = -1; filterds = new double[dropinterval]; SimpleDateFormat sdfx = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]"); // String content; List<String> fileContentStringList = null; JFileChooser jfc = initFileChooser(); //?lastpath String latestPath = (String) datas.get("lastpath"); File currentDir = null; FileSystemView fsv = FileSystemView.getFileSystemView(); if (latestPath == null) { //? currentDir = fsv.getHomeDirectory(); } else { currentDir = new File(latestPath); if (currentDir.exists() && currentDir.isDirectory()) { } else { currentDir = fsv.getHomeDirectory(); } } jfc.setCurrentDirectory(currentDir); int result = jfc.showOpenDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { // String filepath = jfc.getSelectedFile().getAbsolutePath(); //lastpath datas.put("lastpath", jfc.getSelectedFile().isDirectory() ? jfc.getSelectedFile().getAbsolutePath() : jfc.getSelectedFile().getParent()); if (jfc.getSelectedFile() == null) { // System.out.println("!!"); return; } try { fileContentStringList = Files.readLines(jfc.getSelectedFile(), Charsets.ISO_8859_1); } catch (IOException ex) { Logger.getLogger(JIF_DrawChart_w3330.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println("!!"); return; } //??,dropinterval parseFileToDataStructure(fileContentStringList, dropinterval); if (metadatas.size() == 0) { System.out.println("?"); return; } else { chartPanel.getChart().setTitle("" + jfc.getSelectedFile().getName()); System.out.println("" + jfc.getSelectedFile().getName()); System.out.println(String.format("?%d", fileContentStringList.size())); System.out.println(String.format("?%d", metadatas.size())); } //? KalmanFilterHolder kfh_AmbiTemp = new KalmanFilterHolder(25d);//? KalmanFilterHolder kfh_ppm = new KalmanFilterHolder(13d);//? //===============kalman? clearChart();//? tsNotifyFalse();//? //?? for (int i = 0; i < metadatas.size(); i++) { W3330MetaData data = metadatas.get(i); if (oldzero < -1) { oldzero = data.zero; oldzerotime = data.time.getTime(); } else if (oldzero != data.zero) { oldzero = data.zero; oldzerotime = data.time.getTime(); // Color purple = new Color(139, 0, 255); String Labelstr = String.format("%.4f", data.zero); chartDrawHerizonLine(data, purple, Labelstr); } //status 1?? 2 ? 3 4 5?? 6 7?? 8 9? 0 if (oldstatus != data.status) { oldstatus = data.status; // Color purple = new Color(139, 0, 255); String Labelstr; switch ((int) data.status) { case 1: Labelstr = "??"; break; case 2: Labelstr = "?"; break; case 3: Labelstr = ""; break; case 4: Labelstr = ""; break; case 5: Labelstr = "??"; break; case 6: Labelstr = ""; break; case 7: Labelstr = "??"; break; case 8: Labelstr = ""; break; case 9: Labelstr = "?"; break; case 0: Labelstr = ""; break; default: Labelstr = "???status=" + data.status; // throw new AssertionError(); } // Labelstr = String.format("%.4f", data.zero); chartDrawVerticalLine(data, purple, Labelstr); //?ppm kfh_ppm = new KalmanFilterHolder(data.wppm);//? } // data.filter1 = kfh_AmbiTemp.getEstimation(data.temp3); data.filter2 = kfh_ppm.getEstimation(data.wppm); //fitting2 = kalmanfilter2.getStateEstimation()[0]-(fitting-25)*0.78; // fitting2 = wppm-(fitting-25)*0.7;//ppm // fitting = kalmanfilter.getStateEstimation()[0]; // state estimate shouldn't be larger than the measurement noise // double diff = Math.abs(x.getEntry(0) - kalmanfilter.getStateEstimation()[0]); /* //? if (filterpoint < filterds.length) { //? filterds[filterpoint] = temp3; filterpoint++; fitting = wppm; } else { //??? filterds[filterpoint % filterds.length] = temp3; double[] copy = Arrays.copyOf(filterds, filterds.length); Arrays.sort(copy); double total = 0; for (int idx = copy.length / 4; idx < copy.length - copy.length / 4; idx++) { total += copy[idx]; } temp3 = total / (copy.length - copy.length / 4 - copy.length / 4); filterpoint++; //0.78? //???? // fitting = wppm-(filterds[filterpoint%filterds.length]-25)*0.78; fitting = wppm - (temp3 - 25) * 0.78; } */ ts_wppm.addOrUpdate(new Millisecond(data.time), data.wppm); ts_wppm_zero.addOrUpdate(new Millisecond(data.time), data.ppmzero); ts_wvtr.addOrUpdate(new Millisecond(data.time), data.wvtr); //??100??100 ts_flux.addOrUpdate(new Millisecond(data.time), data.flux); //25????25 ts_tempambi.addOrUpdate(new Millisecond(data.time), data.temp3); //38????38 ts_tempcell.addOrUpdate(new Millisecond(data.time), data.temp1); //? //status 1?? 2 ? 3 4 5?? 6 7?? 8 9? 0 ts_status.addOrUpdate(new Millisecond(data.time), data.status); ts_fitting.addOrUpdate(new Millisecond(data.time), data.filter1); data.fitting2 = data.wppm - (data.temp3 - 25) * 1.25;//?? //data.fitting2 = data.wppm *(273.15+25)/(273.15+data.temp3);//?? // data.fitting2= data.wppm+(data.flux-40)*12.4; // ts_fitting2.addOrUpdate(new Millisecond(data.time), data.fitting2); ts_fitting2.addOrUpdate(new Millisecond(data.time), data.filter2); //fitting2 ? /* int step = 20; step = tempint; if (data.zero > 0 && i % step == 0 && i > 2 * step) { //?? double value_wvtr = (data.wppm - data.zero) * 0.02161956; double total = 0; double value_avg = 0; double old1 = (metadatas.get(i - step).wppm - data.zero); double old2 = (metadatas.get(i - step * 2).wppm - data.zero); total = (old1 + old2 + (data.wppm - data.zero)) * 0.02161956; value_avg = total / 3; double diff = (value_wvtr - value_avg) / value_avg; System.out.println(String.format(":%s?%.4f?%.4f???%.4f%%", sdfx.format(data.time), value_wvtr, value_avg, diff * 100)); ts_fitting2.addOrUpdate(new Millisecond(data.time), data.wppm - old1 - data.zero); } */ } tsNotifyTrue();// }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
@Override public void doExport(IExporter exporter) throws IOException { JFileChooser fileChooser = new JFileChooser(); String currentDirectory = System.getProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL); if (currentDirectory != null) { File savePath = new File(currentDirectory); if (savePath.exists() && savePath.isDirectory()) { fileChooser.setCurrentDirectory(savePath); }/*from w ww . jav a 2s . c o m*/ } String fileExtension = exporter.getExtensionName(); ExtensionFileFilter extensionFilter = new ExtensionFileFilter(exporter.toString(), "." + fileExtension); fileChooser.addChoosableFileFilter(extensionFilter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); // String selectedDescription = fileChooser.getFileFilter().getDescription(); if (!filename.toLowerCase().endsWith("." + fileExtension)) { filename = filename + "." + fileExtension; } File selectedFile = new File(filename); int confirm = JOptionPane.YES_OPTION; if (selectedFile.exists()) { confirm = JOptionPane.showConfirmDialog(this, selectedFile.getName() + " exists, overwrite?", "Confirm Overwriting", JOptionPane.YES_NO_OPTION); } else { selectedFile.createNewFile(); } if (confirm == JOptionPane.YES_OPTION) { exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getParent()); } } }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
private File loadFileChooser(boolean dir, FileFilter filter, String text) { File result = null;/*www . j av a 2 s. c om*/ JFileChooser fc = new JFileChooser(); //Create a file chooser disableNewFolderButton(fc); if (text != null) { fc.setSelectedFile(new File(text)); } if (dir) { fc.setDialogTitle(""); File lastDir = new File( Preferences.userRoot().get("lastDir", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastDir); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); jTextField1.setText(result.getAbsolutePath()); Preferences.userRoot().put("lastDir", result.getParentFile().getAbsolutePath()); } } else { File lastSaved = null; File lastSelected = null; if (filter != null) { fc.setDialogTitle("Save As..."); lastSaved = new File( Preferences.userRoot().get("lastSaved", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSaved); fc.setFileFilter(filter); } else { fc.setDialogTitle(""); lastSelected = new File( Preferences.userRoot().get("lastSelected", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSelected); fc.setAcceptAllFileFilterUsed(true); } if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); if (lastSaved != null) { Preferences.userRoot().put("lastSaved", result.getParentFile().getAbsolutePath()); } if (lastSelected != null) { Preferences.userRoot().put("lastSelected", result.getParentFile().getAbsolutePath()); } } } return result; }
From source file:marytts.tools.redstart.AdminWindow.java
private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_OpenActionPerformed // Allow user to choose a different voice (prompt set) without exiting the tool // Create a file chooser final JFileChooser openDialog = new JFileChooser(); // Set the current directory to the voice currently in use openDialog.setCurrentDirectory(getVoiceFolderPath()); openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = openDialog.showDialog(AdminWindow.this, "Open Voice"); if (result == JFileChooser.APPROVE_OPTION) { File voice = openDialog.getSelectedFile(); setVoiceFolderPath(voice); // Set to the selected the voice folder path Test.output("Open voice: " + voice); setupVoice();/*from w ww . java2 s . c om*/ } else { Test.output("Open command cancelled."); } }