List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:it.isislab.dmason.tools.batch.BatchWizard.java
public File SaveFileChooser() { JFileChooser fileChooser = new JFileChooser(); // fileChooser.setCurrentDirectory(new File(FTP_HOME)); fileChooser.setSelectedFile(/* w w w.j ava2 s . c om*/ new File(FilenameUtils.removeExtension(simulationFile.getName()) + "_" + configFileName)); int n = fileChooser.showSaveDialog(BatchWizard.this); if (n == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); } else return null; }
From source file:com.freedomotic.jfrontend.MainWindow.java
/** * /* w w w . j ava 2 s .c o m*/ * @param evt */ private void mnuNewEnvironmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuNewEnvironmentActionPerformed // we are about to make changes to environments: we'd better save current status mnuSaveActionPerformed(null); File oldEnv = api.environments().findAll().get(0).getSource(); //creates a new environment coping it from a template File template = new File( Info.PATHS.PATH_DATA_FOLDER + "/furn/templates/template-square/template-square.xenv"); LOG.info("Opening new environment template file \"{}\"", template.getAbsolutePath()); setEnvironment(api.environments().findAll().get(0)); try { EnvironmentLogic enL = api.environments().loadEnvironmentFromFile(template); if (enL != null) { //EnvObjectPersistence.loadObjects(EnvironmentPersistence.getEnvironments().get(0).getObjectFolder(), false); final JFileChooser fc = new JFileChooser(oldEnv.getParentFile().getParentFile()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle(api.getI18n().msg("select_env_folder_save")); fc.setSelectedFile(oldEnv.getParentFile()); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); if (!folder.getName().isEmpty()) { if (!folder.getAbsolutePath().equalsIgnoreCase(oldEnv.getParentFile().getAbsolutePath())) { // we are making a new environment set api.environments().deleteAll(); } EnvironmentLogic newenv = api.environments().copy(enL); newenv.setSource(new File(folder + "/" + newenv.getPojo().getUUID() + ".xenv")); setEnvironment(newenv); api.environments().saveAs(newenv, folder); } } else { LOG.info("Save command cancelled by user."); //reload the old file api.environments().init(oldEnv.getParentFile()); setEnvironment(api.environments().findAll().get(0)); } } } catch (Exception e) { LOG.error(Freedomotic.getStackTraceInfo(e)); } setWindowedMode(); }
From source file:org.vimarsha.ui.DataLoaderForm.java
public DataLoaderForm() { for (String str : UIHandler.getInstance().getArchitectureList()) { architectureComboBox.addItem(str); architectureComboBox.setSelectedItem(null); }/* ww w . j a v a 2s . c o m*/ architectureComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { UIHandler.getInstance().setArchitecture((String) architectureComboBox.getSelectedItem()); trainingModelTextBox.setText(UIHandler.getInstance().getTrainingModel()); } }); openRAWFileButton.addActionListener(new ActionListener() { File file = null; @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser fc = new JFileChooser("."); int returnVal = fc.showOpenDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); } if ((UIHandler.getInstance().setRawFile(file) == 100) && (UIHandler.getInstance().convertRawToArff() == 100)) { saveToARFFFileButton.setEnabled(true); attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray()); testDataTextField.setText(UIHandler.getInstance().getTestDataName()); } } }); openARFFFileButton.addActionListener(new ActionListener() { File file = null; @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser fc = new JFileChooser("."); int returnVal = fc.showOpenDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); UIHandler.getInstance().setArffFile(file); attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray()); saveToARFFFileButton.setEnabled(true); testDataTextField.setText(UIHandler.getInstance().getTestDataName()); } } }); saveToARFFFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { File file = null; JFileChooser fc = new JFileChooser("."); int returnVal = fc.showSaveDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.println(fc.getSelectedFile()); UIHandler.getInstance().saveAsArff(fc.getSelectedFile()); } } }); attributeList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent listSelectionEvent) { int selectedEvent = attributeList.getSelectedIndex(); attributesSummaryTable .setModel(UIHandler.getInstance().getArffAttributeInfo(attributeList.getSelectedIndex())); DefaultCategoryDataset data = UIHandler.getInstance().getBarChartDataSet(selectedEvent); drawBarChart(data); } }); }
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 va 2s . c o 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:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format.//from w ww . ja va 2s. com * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(new ExtensionFileFilter("All files", "")); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filename))); PngEncoder encoder = new PngEncoder(chartBuffer, true, 0, 9); out.write(encoder.pngEncode()); out.close(); } }
From source file:com.t3.client.AppActions.java
public static void doSaveCampaignAs(final Observer callback) { Campaign campaign = TabletopTool.getCampaign(); JFileChooser chooser = TabletopTool.getFrame().getSaveCmpgnFileChooser(); int saveStatus = chooser.showSaveDialog(TabletopTool.getFrame()); if (saveStatus == JFileChooser.APPROVE_OPTION) { File campaignFile = chooser.getSelectedFile(); if (!campaignFile.getName().contains(".")) { campaignFile = new File(campaignFile.getAbsolutePath() + AppConstants.CAMPAIGN_FILE_EXTENSION); }/* w w w .j av a 2s.c o m*/ if (campaignFile.exists() && !TabletopTool.confirm("msg.confirm.overwriteExistingCampaign")) { return; } doSaveCampaign(campaign, campaignFile, callback); AppState.setCampaignFile(campaignFile); AppPreferences.setSaveDir(campaignFile.getParentFile()); AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile()); TabletopTool.getFrame().setTitleViaRenderer(TabletopTool.getFrame().getCurrentZoneRenderer()); } }
From source file:net.rptools.maptool.client.AppActions.java
public static void doSaveCampaignAs(final Observer callback) { Campaign campaign = MapTool.getCampaign(); JFileChooser chooser = MapTool.getFrame().getSaveCmpgnFileChooser(); int saveStatus = chooser.showSaveDialog(MapTool.getFrame()); if (saveStatus == JFileChooser.APPROVE_OPTION) { File campaignFile = chooser.getSelectedFile(); if (campaignFile.exists() && !MapTool.confirm("msg.confirm.overwriteExistingCampaign")) { return; }// w ww . j a va2s .c o m if (campaignFile.getName().indexOf(".") < 0) { campaignFile = new File(campaignFile.getAbsolutePath() + AppConstants.CAMPAIGN_FILE_EXTENSION); } doSaveCampaign(campaign, campaignFile, callback); AppState.setCampaignFile(campaignFile); AppPreferences.setSaveDir(campaignFile.getParentFile()); MapTool.getFrame().setTitleViaRenderer(MapTool.getFrame().getCurrentZoneRenderer()); } }
From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java
/** * Open a JFileChooser and return the file that the user specified for saving. Takes a parameter that specifies the type of file. Either * TAB or PNG./*from w ww .ja va 2 s . c om*/ * * @return */ private File getFileFromSaveDialog(String fileTypeToSave) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null); JFileChooser fc = new JFileChooser(lastVisitedFolder); File outputFile; if (fileTypeToSave == "TAB") { TABFilter filterTAB = new TABFilter(); fc.addChoosableFileFilter(filterTAB); fc.setFileFilter(filterTAB); fc.setDialogTitle("Export table as text file..."); } else if (fileTypeToSave == "PDF") { PDFFilter filterPDF = new PDFFilter(); fc.addChoosableFileFilter(filterPDF); fc.setFileFilter(filterPDF); fc.setDialogTitle("Export chart as PDF..."); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { outputFile = fc.getSelectedFile(); if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") { log.debug("Output file extension not set by user"); if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription())) { log.debug("Adding csv extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".csv"); } else if (fc.getFileFilter().getDescription().equals(new PDFFilter().getDescription())) { log.debug("Adding pdf extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".pdf"); } } else { log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'"); } App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath()); } else { return null; } if (outputFile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; // notes about parameters: null (don't use custom icon), options (the titles of buttons), options[0] (default button title) int response = JOptionPane.showOptionDialog(App.mainFrame, "The file '" + outputFile.getName() + "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (response != JOptionPane.YES_OPTION) return null; } return outputFile; }
From source file:com.marginallyclever.makelangelo.MainGUI.java
private void SaveFileDialog() { // Note: source for ExampleFileFilter can be found in FileChooserDemo, // under the demo/jfc directory in the Java 2 SDK, Standard Edition. String s = recentFiles.get(0); String filename = (s.length() > 0) ? filename = s : ""; FileFilter filterGCODE = new FileNameExtensionFilter(translator.get("FileTypeGCode"), "ngc"); JFileChooser fc = new JFileChooser(new File(filename)); fc.addChoosableFileFilter(filterGCODE); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fc.getSelectedFile().getAbsolutePath(); if (!selectedFile.toLowerCase().endsWith(".ngc")) { selectedFile += ".ngc"; }/* ww w .j a va 2s . c om*/ try { gcode.Save(selectedFile); } catch (IOException e) { Log("<span style='color:red'>" + translator.get("Failed") + e.getMessage() + "</span>\n"); return; } } }
From source file:com.commander4j.db.JDBUserReport.java
private String promptUserforSave() { JFileChooser saveTYPE = new JFileChooser(); String filename = getExportFilename(); if (isPromptSaveAsRequired()) { try {//w w w . ja va2s .c o m File f = new File(new File(getExportFilename()).getCanonicalPath()); saveTYPE.setCurrentDirectory(f); if (getDestination().equals("EXCEL")) saveTYPE.addChoosableFileFilter(new JFileFilterXLS()); if (getDestination().equals("JASPER_REPORT")) saveTYPE.addChoosableFileFilter(new JFileFilterPDF()); if (getDestination().equals("PDF")) saveTYPE.addChoosableFileFilter(new JFileFilterPDF()); if (getDestination().equals("CSV")) saveTYPE.addChoosableFileFilter(new JFileFilterCSV()); if (getDestination().equals("ACCESS")) saveTYPE.addChoosableFileFilter(new JFileFilterMDB()); saveTYPE.setSelectedFile(new File(getExportFilename())); int result = saveTYPE.showSaveDialog(Common.mainForm); if (result == 0) { File selectedFile; selectedFile = saveTYPE.getSelectedFile(); if (selectedFile != null) { filename = selectedFile.getAbsolutePath(); } } } catch (Exception ex) { } } return filename; }