List of usage examples for javax.swing JFileChooser SAVE_DIALOG
int SAVE_DIALOG
To view the source code for javax.swing JFileChooser SAVE_DIALOG.
Click Source Link
JFileChooser
supports a "Save" file operation. From source file:com.hexidec.ekit.EkitCore.java
public void writeOutFragment(HTMLDocument doc, String containingTag) throws IOException, BadLocationException { File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsHTML, Translatrix.getTranslationString("FiletypeHTML")); if (whatFile != null) { writeOutFragment(doc, containingTag, whatFile); }//w w w.j a va2s .c o m }
From source file:com.hexidec.ekit.EkitCore.java
public void writeOutRTF(StyledDocument doc) throws IOException, BadLocationException { File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsRTF, Translatrix.getTranslationString("FiletypeRTF")); if (whatFile != null) { writeOutRTF(doc, whatFile);/*ww w . j a v a2s .com*/ } }
From source file:com.hexidec.ekit.EkitCore.java
/** * Method for serializing the document out to a file *///from w w w . jav a 2s . c o m public void serializeOut(HTMLDocument doc) throws IOException { File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsSer, Translatrix.getTranslationString("FiletypeSer")); if (whatFile != null) { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(whatFile)); oos.writeObject(doc); oos.flush(); oos.close(); } refreshOnUpdate(); }
From source file:com.hexidec.ekit.EkitCore.java
/** * Method for obtaining a File for input/output using a JFileChooser dialog */// w w w.j av a 2s . co m private File getFileFromChooser(String startDir, int dialogType, String[] exts, String desc) { JFileChooser jfileDialog = new JFileChooser(startDir); jfileDialog.setDialogType(dialogType); jfileDialog.setFileFilter(new MutableFilter(exts, desc)); int optionSelected = JFileChooser.CANCEL_OPTION; if (dialogType == JFileChooser.OPEN_DIALOG) { optionSelected = jfileDialog.showOpenDialog(this); } else if (dialogType == JFileChooser.SAVE_DIALOG) { optionSelected = jfileDialog.showSaveDialog(this); } else // default to an OPEN_DIALOG { optionSelected = jfileDialog.showOpenDialog(this); } if (optionSelected == JFileChooser.APPROVE_OPTION) { return jfileDialog.getSelectedFile(); } return (File) null; }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
private void buttonExportToCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExportToCSVActionPerformed final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(getLocaleMessage("save.statictic")); fc.setFileFilter(new FileFilter() { @Override/* w w w.j a va 2s . c o m*/ public boolean accept(File f) { return !f.isFile() || f.getAbsolutePath().toLowerCase().endsWith(".csv"); } @Override public String getDescription() { return getLocaleMessage("files.type.csv"); } }); //fc.setCurrentDirectory(new File("config")); //fc.setSelectedFile(new File(configuration.getSystemName())); fc.setDialogType(JFileChooser.SAVE_DIALOG); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file; //This is where a real application would open the file. if (!fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".csv")) { file = new File(fc.getSelectedFile().getAbsoluteFile() + ".csv"); } else { file = fc.getSelectedFile(); } Spring.getInstance().getHt().getSessionFactory().openSession().doWork((Connection connection) -> { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dateChooserStartCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); final String std = Uses.format_for_rep.format(gc.getTime()); gc.setTime(dateChooserFinishCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); gc.add(GregorianCalendar.HOUR, 24); final String find = Uses.format_for_rep.format(gc.getTime()); final String sql = " SELECT " + " s.client_id as id, " + " concat(c.service_prefix , c.number) as num, " + " c.input_data as inp, " + " DATE_FORMAT(s.client_stand_time, '%d.%m.%y %H:%i') as stnd, " + " sv.name as srv, " + " DATE_FORMAT(s.user_start_time, '%d.%m.%y %H:%i') as strt, " + " DATE_FORMAT(s.user_finish_time, '%d.%m.%y %H:%i') as fin, " + " u.name as usr, " + " s.client_wait_period as wt, " + " s.user_work_period as wrk, " + " IFNULL(r.name, '') as res " + " FROM statistic s left join results r on s.results_id=r.id, clients c, users u, services sv " + " WHERE s.client_id=c.id and s.user_id=u.id and s.service_id=sv.id " + " and s.client_stand_time>='" + std + "' and s.client_stand_time<='" + find + "'"; try (ResultSet set = connection.createStatement().executeQuery(sql)) { final Writer writer; try { writer = new OutputStreamWriter(new FileOutputStream(file), "cp1251").append(""); writer.append(""); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.number")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.data")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.stand_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.service_name")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.start_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.finish_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.user")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.wait")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.work")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.result")); writer.append('\n'); while (set.next()) { writer.append(set.getString("id")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("num")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("inp")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("stnd")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append( set.getString("srv").replace(cbSeparateCSV.getSelectedItem().toString(), " ")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("strt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("fin")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("usr")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wrk")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("res")); writer.append('\n'); } //generate whatever data you want writer.flush(); writer.close(); } catch (IOException ex) { throw new ClientException(ex); } } JOptionPane.showMessageDialog(fc, getLocaleMessage("stat.saved"), getLocaleMessage("stat.saving"), JOptionPane.INFORMATION_MESSAGE); }); } }
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.ja v a2 s . c o 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.apache.cayenne.modeler.dialog.db.merge.MergerOptions.java
/** * Allows user to save generated SQL in a file. */// w w w. j a v a 2 s. co m public void storeSQLAction() { JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.SAVE_DIALOG); fc.setDialogTitle("Save SQL Script"); Resource projectDir = getApplication().getProject().getConfigurationResource(); if (projectDir != null) { fc.setCurrentDirectory(new File(projectDir.getURL().getPath())); } if (fc.showSaveDialog(getView()) == JFileChooser.APPROVE_OPTION) { refreshGeneratorAction(); try { File file = fc.getSelectedFile(); FileWriter fw = new FileWriter(file); PrintWriter pw = new PrintWriter(fw); pw.print(textForSQL); pw.flush(); pw.close(); } catch (IOException ex) { reportError("Error Saving SQL", ex); } } }
From source file:org.kepler.gui.kar.ExportArchiveAction.java
/** * Invoked when an action occurs./* ww w. j a v a2 s .c om*/ * * @param e * ActionEvent */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); _saveSucceeded = false; // grab the new KAR lsid after the file is saved // in case we need it for later KeplerLSID theNewKARLSID = null; // save the window size, position, and zoom if (_parent instanceof BasicGraphFrame) { try { ((BasicGraphFrame) _parent).updateWindowAttributes(); } catch (Exception exception) { MessageHandler.error("Failed to save window size, position and zoom while writing KAR.", exception); } } // //////////////////////////////////////////////// // Only this part should be different depending on // where the KAR is being exported from boolean continueExport = handleAction(e); if (!continueExport) { return; } // //////////////////////////////////////////////// // Force single item KAR if there is only one // item in the KAR // This may or may not be good/necessary if (_savekar.getSaveInitiatorList().size() == 1) { setSingleItemKAR(true); } else { setSingleItemKAR(false); } File saveFile = null; if (_nonInteractiveSave) { saveFile = _saveFile; } else { if (useTempFile) { // Use a temporary file for saving to in order to simulate // the old upload to repository function // don't really want to be doing this... ComponentEntity ce = _savekar.getSaveInitiatorList().get(0); String tempFileName = ce.getName() + ".kar"; File tempDir = DotKeplerManager.getInstance().getTransientModuleDirectory("core"); saveFile = new File(tempDir, tempFileName); } else { // Create a file filter that accepts .kar files. ExtensionFilenameFilter filter = new ExtensionFilenameFilter("kar"); // Avoid white boxes in file chooser, see // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801 JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix(); Color background = null; PtFileChooser chooser = null; try { background = jFileChooserBugFix.saveBackground(); chooser = new PtFileChooser(_parent, "Save", JFileChooser.SAVE_DIALOG); if (_parent instanceof BasicGraphFrame) { chooser.setCurrentDirectory(((BasicGraphFrame) _parent).getLastDirectory()); } chooser.addChoosableFileFilter(filter); if (_defaultFileName != null) { chooser.setSelectedFile(new File(_defaultFileName)); } int returnVal = chooser.showDialog(_parent, "Save"); if (returnVal == JFileChooser.APPROVE_OPTION) { // process the given file saveFile = chooser.getSelectedFile(); if (saveFile.exists() && !PtGUIUtilities.useFileDialog()) { if (!MessageHandler.yesNoQuestion("Overwrite \"" + saveFile.getName() + "\"?")) { saveFile = null; } } } } finally { jFileChooserBugFix.restoreBackground(background); } } } if (saveFile == null) return; _savekar.setFile(saveFile); // see if the name has changed. // make sure there's a reference to the workflow; it could be null when, // e.g., exporting a run in the WRM. if (_workflow != null) { String newName = FileUtil.getFileNameWithoutExtension(saveFile.getName()); if (!newName.equals(_workflow.getName())) { try { // rename the frame title and workflow xml file in the kar RenameUtil.renameComponentEntity(_workflow, newName); } catch (Exception exception) { MessageHandler.error("Error renaming workflow.", exception); } } } // See if this file already exists if (_savekar.getFile().exists()) { try { // Get the LSID of the existing kar KARFile existingKARFile = new KARFile(_savekar.getFile()); KeplerLSID existingFileLSID = existingKARFile.getLSID(); // Delete the old kar from the library LibraryManager lm = LibraryManager.getInstance(); lm.deleteKAR(_savekar.getFile()); // increment the revision and set it existingFileLSID.incrementRevision(); _savekar.specifyLSID(existingFileLSID); // save the new kar file theNewKARLSID = _savekar.saveToDisk(_parent, _overrideModuleDependencies); } catch (Exception e1) { e1.printStackTrace(); } } else { theNewKARLSID = _savekar.saveToDisk(_parent, _overrideModuleDependencies); } if (theNewKARLSID != null) { _saveSucceeded = true; // Add JFrame=>KARFile mapping to KARManager, unless ifRefreshFrameAfterSave, // in which case the mapping is added during ActorMetadataKAREntry.open, or if // mapKARToCurrentFrame was explicitly set false. if (!isRefreshFrameAfterSave() && mapKARToCurrentFrame()) { try { KARFile karFile = new KARFile(_savekar.getFile()); KARManager.getInstance().add(_parent, karFile); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } if (_parent instanceof KeplerGraphFrame) { try { ((KeplerGraphFrame) _parent).updateHistory(_savekar.getFile().getAbsolutePath()); } catch (IOException e1) { MessageHandler.error("Unable to update history menu.", e1); } } if (_parent instanceof BasicGraphFrame) { ((BasicGraphFrame) _parent).setLastDirectory(saveFile.getParentFile()); } } // After the KAR has been saved to disk we add it to the cache // then add it to the library and refresh the JTrees if (!useTempFile) { // If it is saved in a local repository update the library LocalRepositoryManager lrm = LocalRepositoryManager.getInstance(); if (lrm.isInLocalRepository(_savekar.getFile())) { _savekar.saveToCache(); LibraryManager lm = LibraryManager.getInstance(); try { lm.addKAR(_savekar.getFile()); } catch (Exception e2) { JOptionPane.showMessageDialog(_parent, "Error adding kar to library: " + e2.getMessage()); } try { lm.refreshJTrees(); } catch (IllegalActionException e2) { e2.printStackTrace(); } } else { // JOptionPane.showMessageDialog(_parent, // "KAR file successfully saved to a folder that is not designated as a Local Repository. In order for the contents of this KAR to show up in the component library, you can move the KAR file to a Local Repository and restart Kepler, or you can add the folder as a local repository by using the Component 'Sources' button."); } } // Now we // 1. check to see if there is a remote repository selected by the user // for saving // 2. double check with the user that they want to send the KAR // to the remote repository, // 3. then upload it try { if (_upload) { RepositoryManager rm = RepositoryManager.getInstance(); Repository remoteRepo = rm.getSaveRepository(); if (remoteRepo != null) { boolean continueWithUpload = true; int choice = JOptionPane.showConfirmDialog(_parent, "Would you like to upload this KAR to the remote repository?\n" + " " + remoteRepo.getName() + " at " + remoteRepo.getRepository() + "\n", "Upload To Repository", JOptionPane.YES_NO_OPTION); if (choice != JOptionPane.YES_OPTION) { continueWithUpload = false; } if (continueWithUpload) { try { ComponentUploader uploader = new ComponentUploader(_parent); KARFile kf2upload = new KARFile(getSaveKAR().getFile()); uploader.upload(kf2upload); } catch (Exception ee) { ee.printStackTrace(); } } } } if (isRefreshFrameAfterSave()) { // Open a new frame and close the old one KARFile karf; try { //move old frame close before new frame open. //It will fix the bug http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5200 without having memory leak. karf = new KARFile(_savekar.getFile()); karf.openKARContents(_parent, false); karf.close(); // dispose the old window after opening a new one _parent.dispose(); } catch (Exception e1) { e1.printStackTrace(); } } } catch (IOException e1) { e1.printStackTrace(); } catch (Exception e1) { e1.printStackTrace(); } }
From source file:org.pentaho.reporting.designer.core.actions.report.SaveReportUtilities.java
/** * Prompts the user for the name of the report file which should be created * * @param parent the parent component of which the file chooser dialog will be a child * @param defaultFile the initially selected file. * @return The <code>File</code> which the report should be saved into, or <code>null</code> if the user does not want * to continue with the save operation// www. ja va 2s .c om */ public static File promptReportFilename(final Component parent, final File defaultFile) { final FileFilter filter = new FilesystemFilter(new String[] { DEFAULT_EXTENSION }, ActionMessages.getString("ReportBundleFileExtension.Description"), true); final CommonFileChooser fileChooser = FileChooserService.getInstance().getFileChooser("report"); fileChooser.setSelectedFile(defaultFile); fileChooser.setFilters(new FileFilter[] { filter }); logger.debug("Prompting for save filename"); // NON-NLS if (fileChooser.showDialog(parent, JFileChooser.SAVE_DIALOG) == false) { logger.debug("Save filename - cancel option selected");// NON-NLS return null; } final File selectedFile = validateFileExtension(fileChooser.getSelectedFile(), parent); if (selectedFile == null) { // Cancel on another dialog return null; } // Once the filename has stabelized, check for overwrite if (selectedFile.exists()) { logger.debug("Selected file exists [" + selectedFile.getName() + "] - prompting for overwrite...");// NON-NLS final int overwrite = JOptionPane.showConfirmDialog(parent, ActionMessages.getString("SaveReportUtilities.OverwriteDialog.Message", selectedFile.getAbsolutePath()), ActionMessages.getString("SaveReportUtilities.OverwriteDialog.Title"), JOptionPane.YES_NO_OPTION); if (overwrite == JOptionPane.NO_OPTION) { return null; } } return selectedFile; }
From source file:org.pentaho.reporting.designer.core.editor.styles.styleeditor.StyleDefinitionUtilities.java
/** * Prompts the user for the name of the report file which should be created * * @param parent the parent component of which the file chooser dialog will be a child * @param defaultFile the initially selected file. * @return The <code>File</code> which the report should be saved into, or <code>null</code> if the user does not want * to continue with the save operation/*from w ww . ja v a 2s .c o m*/ */ public static File promptReportFilename(final Component parent, final File defaultFile) { final FileFilter filter = new FilesystemFilter(new String[] { DEFAULT_EXTENSION }, Messages.getString("StyleDefinitionUtilities.FileDescription"), true); final CommonFileChooser fileChooser = FileChooserService.getInstance().getFileChooser(FILE_CHOOSER_TYPE); fileChooser.setSelectedFile(defaultFile); fileChooser.setFilters(new FileFilter[] { filter }); logger.debug("Prompting for save filename"); // NON-NLS if (fileChooser.showDialog(parent, JFileChooser.SAVE_DIALOG) == false) { logger.debug("Save filename - cancel option selected");// NON-NLS return null; } final File selectedFile = validateFileExtension(fileChooser.getSelectedFile(), parent); if (selectedFile == null) { // Cancel on another dialog return null; } // Once the filename has stabelized, check for overwrite if (selectedFile.exists()) { logger.debug("Selected file exists [" + selectedFile.getName() + "] - prompting for overwrite...");// NON-NLS final int overwrite = JOptionPane.showConfirmDialog(parent, Messages.getString("StyleDefinitionUtilities.OverwriteDialog.Message", selectedFile.getAbsolutePath()), Messages.getString("StyleDefinitionUtilities.OverwriteDialog.Title"), JOptionPane.YES_NO_OPTION); if (overwrite == JOptionPane.NO_OPTION) { return null; } } return selectedFile; }