List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java
private void saveNetwork() { if (saveFileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { File saveFile = saveFileChooser.getSelectedFile(); new SwingWorker<Void, Void>() { @Override//from w ww .jav a 2s . c o m protected Void doInBackground() throws Exception { synchronized (network) { new Data(network).save(saveFile); } return null; } @Override protected void done() { } }.execute(); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * * @throws IOException// w w w . j a v a 2 s .co m */ private void createPdf(JFreeChart chart) throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooseDirectory.setSelectedFile(new File("chart rose plot" + ".pdf")); // in response to the button click, show open dialog int returnVal = chooseDirectory.showSaveDialog(angleDirectPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); PdfSwingWorker pdfSwingWorker = new PdfSwingWorker(directory, chooseDirectory.getSelectedFile().getName(), chart); pdfSwingWorker.execute(); } else { singleCellPreProcessingController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.mgmtp.jfunk.core.JFunk.java
private static List<File> requestScriptsViaGui() { final List<File> scripts = new ArrayList<>(); try {/*from ww w . jav a 2 s.com*/ SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser fileChooser = new JFileChooser(System.getProperty(JFunkConstants.USER_DIR)); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(true); fileChooser.setPreferredSize(new Dimension(800, 450)); int i = fileChooser.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { File[] files = fileChooser.getSelectedFiles(); scripts.addAll(Arrays.asList(files)); } } }); } catch (Exception e) { LOG.error("Error while requesting scripts via GUI", e); } return scripts; }
From source file:bridge.toolkit.ControllerJFrame.java
private void SCPMBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { int returnVal = SCPMFileChooser.showOpenDialog(ControllerJFrame.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = SCPMFileChooser.getSelectedFile(); SCPMField.setText(file.getAbsolutePath()); }/*from w w w .ja v a 2 s . co m*/ }
From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java
/** * Verzeichnis fr die Daten auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * //from ww w .j a v a 2s .c o m * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.08.2012 */ private void chooseDataDir() { JFileChooser fileChooser; int retVal; // // Einen Dateiauswahldialog Creieren // fileChooser = new JFileChooser(); fileChooser.setLocale(Locale.getDefault()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle(fileChooserDirTitle); fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG); fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip); // das existierende Logfile voreinstellen fileChooser.setSelectedFile(SpxPcloggerProgramConfig.databaseDir); retVal = fileChooser.showDialog(this, approveDirButtonText); // Mal sehen, was der User gewollt hat if (retVal == JFileChooser.APPROVE_OPTION) { // Ja, ich wollte das so databaseDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath()); wasChangedParameter = true; } }
From source file:edu.synth.SynthHelper.java
public String openDialogFileChooser(String path, boolean dirOnly, String name, String button, String filterType) {/*w w w .j a v a2s . com*/ JFileChooser fileOpen = new JFileChooser(); if (!path.isEmpty()) fileOpen.setCurrentDirectory(new File(path)); else fileOpen.setCurrentDirectory(new File(".")); if (dirOnly) fileOpen.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else { fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); switch (filterType) { case "abn": FileFilter filter = new FileNameExtensionFilter("*.abn - Abundances file", "abn"); fileOpen.setFileFilter(filter); break; case "model": filter = new FileNameExtensionFilter("*.atl - Kurucz's format model file", "atl"); fileOpen.setFileFilter(filter); break; case "lns": filter = new FileNameExtensionFilter("*.lns - Lines file", "lns"); fileOpen.setFileFilter(filter); break; } } fileOpen.setDialogTitle(name); fileOpen.setApproveButtonText(button); int returnVal = fileOpen.showOpenDialog(fileOpen); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedPath = fileOpen.getSelectedFile(); if (selectedPath != null) return selectedPath.getAbsolutePath(); } return ""; }
From source file:dotaSoundEditor.Controls.ItemPanel.java
@Override protected File promptUserForNewFile(String wavePath) { DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); String waveString = selectedTreeNode.getUserObject().toString(); String allowedExtension = FilenameUtils.getExtension(waveString).replace("\"", ""); JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = allowedExtension.equals("wav") ? new FileNameExtensionFilter("WAVs", "wav") : new FileNameExtensionFilter("MP3s", "mp3"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);/*from ww w. j a v a 2 s . co m*/ chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); int startIndex = -1; int endIndex = -1; //Get the actual value for the wavestring key-value pair. if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); String waveStringNormalizedFilePath = waveStringFilePath.substring(0, waveStringFilePath.lastIndexOf("\"")); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace(")", ""); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace("\"", ""); Path destPath = Paths.get(installDir, "/dota/sound/" + waveStringNormalizedFilePath); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); if (waveString.contains("//")) { waveString = waveString .replace(waveString.substring(waveString.indexOf("//"), waveString.length()), ""); } waveString = waveString.replace(waveStringFilePath, "\"" + waveStringNormalizedFilePath + "\" //Replaced by: " + chosenFile.getFileName().toString()); selectedTreeNode.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:com.jvms.i18neditor.editor.Editor.java
public void showImportProjectDialog() { String path = null;/*w ww.j a v a 2s . c o m*/ if (project != null) { path = project.getPath().toString(); } JFileChooser fc = new JFileChooser(path); fc.setDialogTitle(MessageBundle.get("dialogs.project.import.title")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { importProject(Paths.get(fc.getSelectedFile().getPath()), true); } }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.ChartDisplayPanel.java
/** * Displays a dialog for saving the complex parameter data into a text file. * <p>/*from w w w .j a v a 2 s.c om*/ * If the user presses the "Save" button of the shown dialog, the complex parameter is * saved to the chosen file. * </p> */ private void saveChartData() { JFileChooser saveFileDialog = new JFileChooser(); int saveIt = saveFileDialog.showSaveDialog(this); if (saveIt == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { File file = saveFileDialog.getSelectedFile(); if (Utils.canSave(file, this)) { writer = new FileWriter(file); visualizer.getComplexParam().save(writer, false); } } catch (IOException ex) { Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_OERROR); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { // Fall through } } } } }