List of usage examples for java.awt FileDialog SAVE
int SAVE
To view the source code for java.awt FileDialog SAVE.
Click Source Link
From source file:org.tinymediamanager.ui.TmmUIHelper.java
public static Path saveFile(String title, String filename, FileNameExtensionFilter filter) { // try to open AWT dialog on OSX if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) { try {//from w w w. ja v a 2 s . co m // open file chooser return openFileDialog(title, FileDialog.SAVE, filename); } catch (Exception e) { LOGGER.warn("cannot open AWT filechooser" + e.getMessage()); } catch (Error e) { LOGGER.warn("cannot open AWT filechooser" + e.getMessage()); } } return openJFileChooser(JFileChooser.FILES_ONLY, title, false, filename, filter); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
/** * * @param columnsFormulasToPrint// w w w .j a v a 2 s . co m * If null, print all columns * @param stripNewLinesInCells * @param filePath * Full path to save file to; if null, user will be prompted. */ public void saveFilteredRowsToFile(List<Integer> columnsFormulasToPrint, boolean stripNewLinesInCells, String filePath) { String saveTo; if (filePath == null) { FileDialog dialog = new FileDialog(new Frame(), "Save filtered rows to", FileDialog.SAVE); dialog.setVisible(true); saveTo = dialog.getDirectory(); if (saveTo == null) return; saveTo += "/" + dialog.getFile(); } else { saveTo = filePath; } PrintWriter out = null; try { out = new PrintWriter(saveTo); StringBuffer b = new StringBuffer(); if (columnsFormulasToPrint == null) { for (int i = 0; i < this.getColumnCount(); i++) { b.append(getColumnName(i)); if (i < getColumnCount() - 1) b.append("\t"); } } else { int index = 0; for (int i : columnsFormulasToPrint) { b.append(getColumnName(i)); if (index + 1 < columnsFormulasToPrint.size()) b.append("\t"); index++; } } out.println(b); for (int i = 0; i < model.getRowCount(); i++) { int rowIndex = convertRowIndexToView(i); if (rowIndex > -1) { if (columnsFormulasToPrint == null) if (stripNewLinesInCells) out.println(getRowAsString(rowIndex).replaceAll("\n", " ")); else out.println(getRowAsString(rowIndex)); else { boolean first = true; for (int column : columnsFormulasToPrint) { if (!first) { out.print("\t"); } first = false; SpreadsheetCell cell = (SpreadsheetCell) getValueAt(rowIndex, column); if (cell != null) { String formula = cell.getFormula(); if (formula != null) { if (stripNewLinesInCells) out.print(formula.replaceAll("\n", " ")); else out.print(formula); } } } out.println(""); } } } out.close(); } catch (FileNotFoundException e) { Utils.printStack(e); Utils.displayMessage("Could not save table", true, LogLevel.ERROR); } }
From source file:processing.app.Sketch.java
/** * Handles 'Save As' for a sketch./*from ww w. j a va2s .c om*/ * <P> * This basically just duplicates the current sketch folder to * a new location, and then calls 'Save'. (needs to take the current * state of the open files and save them to the new folder.. * but not save over the old versions for the old sketch..) * <P> * Also removes the previously-generated .class and .jar files, * because they can cause trouble. */ protected boolean saveAs() throws IOException { // get new name for folder FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE); if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()) || isUntitled()) { // default to the sketchbook folder fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath()); } else { // default to the parent folder of where this was // on macs a .getParentFile() method is required fd.setDirectory(data.getFolder().getParentFile().getAbsolutePath()); } String oldName = data.getName(); fd.setFile(oldName); fd.setVisible(true); String newParentDir = fd.getDirectory(); String newName = fd.getFile(); // user canceled selection if (newName == null) return false; newName = Sketch.checkName(newName); File newFolder = new File(newParentDir, newName); // make sure there doesn't exist a .cpp file with that name already // but ignore this situation for the first tab, since it's probably being // resaved (with the same name) to another location/folder. for (int i = 1; i < data.getCodeCount(); i++) { SketchCode code = data.getCode(i); if (newName.equalsIgnoreCase(code.getPrettyName())) { Base.showMessage(tr("Error"), I18n.format(tr("You can't save the sketch as \"{0}\"\n" + "because the sketch already has a file with that name."), newName)); return false; } } // check if the paths are identical if (newFolder.equals(data.getFolder())) { // just use "save" here instead, because the user will have received a // message (from the operating system) about "do you want to replace?" return save(); } // check to see if the user is trying to save this sketch inside itself try { String newPath = newFolder.getCanonicalPath() + File.separator; String oldPath = data.getFolder().getCanonicalPath() + File.separator; if (newPath.indexOf(oldPath) == 0) { Base.showWarning(tr("How very Borges of you"), tr( "You cannot save the sketch into a folder\n" + "inside itself. This would go on forever."), null); return false; } } catch (IOException e) { //ignore } // if the new folder already exists, then need to remove // its contents before copying everything over // (user will have already been warned) if (newFolder.exists()) { Base.removeDir(newFolder); } // in fact, you can't do this on windows because the file dialog // will instead put you inside the folder, but it happens on osx a lot. // now make a fresh copy of the folder newFolder.mkdirs(); // grab the contents of the current tab before saving // first get the contents of the editor text area if (current.getCode().isModified()) { current.getCode().setProgram(editor.getText()); } // save the other tabs to their new location for (SketchCode code : data.getCodes()) { if (data.indexOfCode(code) == 0) continue; File newFile = new File(newFolder, code.getFileName()); code.saveAs(newFile); } // re-copy the data folder (this may take a while.. add progress bar?) if (data.getDataFolder().exists()) { File newDataFolder = new File(newFolder, "data"); Base.copyDir(data.getDataFolder(), newDataFolder); } // re-copy the code folder if (data.getCodeFolder().exists()) { File newCodeFolder = new File(newFolder, "code"); Base.copyDir(data.getCodeFolder(), newCodeFolder); } // copy custom applet.html file if one exists // http://dev.processing.org/bugs/show_bug.cgi?id=485 File customHtml = new File(data.getFolder(), "applet.html"); if (customHtml.exists()) { File newHtml = new File(newFolder, "applet.html"); Base.copyFile(customHtml, newHtml); } // save the main tab with its new name File newFile = new File(newFolder, newName + ".ino"); data.getCode(0).saveAs(newFile); editor.handleOpenUnchecked(newFile, currentIndex, editor.getSelectionStart(), editor.getSelectionStop(), editor.getScrollPosition()); // Name changed, rebuild the sketch menus //editor.sketchbook.rebuildMenusAsync(); editor.base.rebuildSketchbookMenus(); // Make sure that it's not an untitled sketch setUntitled(false); // let Editor know that the save was successful return true; }
From source file:processing.app.tools.Archiver.java
public void run() { SketchController sketch = editor.getSketchController(); // first save the sketch so that things don't archive strangely boolean success = false; try {/*www . j av a 2 s. co m*/ success = sketch.save(); } catch (Exception e) { e.printStackTrace(); } if (!success) { Base.showWarning(tr("Couldn't archive sketch"), tr("Archiving the sketch has been canceled because\nthe sketch couldn't save properly."), null); return; } File location = sketch.getSketch().getFolder(); String name = location.getName(); File parent = new File(location.getParent()); //System.out.println("loc " + location); //System.out.println("par " + parent); File newbie = null; String namely = null; int index = 0; do { // only use the date if the sketch name isn't the default name useDate = !name.startsWith("sketch_"); if (useDate) { String purty = dateFormat.format(new Date()); String stamp = purty + ((char) ('a' + index)); namely = name + "-" + stamp; newbie = new File(parent, namely + ".zip"); } else { String diggie = numberFormat.format(index + 1); namely = name + "-" + diggie; newbie = new File(parent, namely + ".zip"); } index++; } while (newbie.exists()); // open up a prompt for where to save this fella FileDialog fd = new FileDialog(editor, tr("Archive sketch as:"), FileDialog.SAVE); fd.setDirectory(parent.getAbsolutePath()); fd.setFile(newbie.getName()); fd.setVisible(true); String directory = fd.getDirectory(); String filename = fd.getFile(); // only write the file if not canceled if (filename != null) { newbie = new File(directory, filename); ZipOutputStream zos = null; try { //System.out.println(newbie); zos = new ZipOutputStream(new FileOutputStream(newbie)); // recursively fill the zip file buildZip(location, name, zos); // close up the jar file zos.flush(); editor.statusNotice("Created archive " + newbie.getName() + "."); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(zos); } } else { editor.statusNotice(tr("Archive sketch canceled.")); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.actions.querycrud.core.actions.SaveQueryToFileTask.java
/** * Do in background.// w ww. ja v a2 s. co m * * @return the void * * @throws Exception the exception */ @Override protected Boolean doInBackground() throws Exception { boolean result = false; QueryStatement query = queryService.getActiveQuery(); // open file dialog to get save location FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select location to save", FileDialog.SAVE); fd.setVisible(true); String selectedFile = fd.getFile(); String selectedDirectory = fd.getDirectory(); fileSelected = fd.getFile(); if (selectedDirectory != null && selectedFile != null) { // save to selected location File physicalLocation = new File(selectedDirectory, selectedFile); query.setPhysicalLocation(physicalLocation.toURI()); queryExpressionFileOutputter.save(query, physicalLocation.toURI()); // notify query has changed queryService.queryChanged(query, this); // change result to true result = true; } return result; }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.queryresultspanel.actions.ExportResultTask.java
@Override protected Void doInBackground() throws Exception { // open file dialog to get save location FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select location to save", FileDialog.SAVE); fd.setVisible(true);// ww w.j av a 2 s . com String selectedFile = fd.getFile(); String selectedDirectory = fd.getDirectory(); if (selectedDirectory != null && selectedFile != null && resultSet != null) { try { // save to selected location File file = new File(selectedDirectory, selectedFile); // export to flat file FileWriter fw = new FileWriter(file); fw.flush(); // add column names to data String cols = ""; int colNum = resultSet.getMetaData().getColumnCount(); for (int c = 0; c < colNum; c++) { cols = cols + "\t" + resultSet.getMetaData().getColumnName(c + 1); } // trim line and add new line character cols = cols.trim(); cols = cols + "\n"; // write to file fw.write(cols); float totalRows = resultSetCount; float percent = 0; int counter = 0; // reset resultSet to first row in case its been iterated over before resultSet.beforeFirst(); while (resultSet.next()) { String line = ""; for (int l = 0; l < colNum; l++) { Object o = resultSet.getObject(l + 1); if (o instanceof Date) { o = sdf.format((Date) o); } else if (o instanceof byte[]) { byte[] bytes = (byte[]) o; o = UUID.nameUUIDFromBytes(bytes).toString(); } line = line + "\t" + o.toString(); } // trim line line = line.trim(); // append new line character to line line = line + "\n"; // write to file fw.write(line); // update progress bar percent = (counter / totalRows) * 100; setProgress((int) percent); setMessage("Exported " + counter + " of " + totalRows + " rows"); counter++; } // close file writer fw.close(); } catch (IOException e) { logger.warn("Nested exception is : " + e.fillInStackTrace()); } } return null; }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java
/** * Creates the statements panel.//from w w w . ja v a2 s . c o m * * @param textArea the text area * @param title the title * * @return the j panel */ private synchronized JPanel createStatementsPanel(final JTextArea textArea, String title) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createTitledBorder(title))); // create buttons for copy and export JButton copyButton = new JButton(new AbstractAction("Copy") { public void actionPerformed(ActionEvent event) { StringSelection selection = new StringSelection(textArea.getSelectedText()); // get contents of text area and copy to system clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, QueryStatisticsCollectionPanel.this); } }); JButton exportButton = new JButton(new AbstractAction("Export") { public void actionPerformed(ActionEvent event) { // open a file dialog and export the contents FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select file to export to", FileDialog.SAVE); fd.setVisible(true); String fileName = fd.getFile(); String fileDirectory = fd.getDirectory(); if (fileDirectory != null && fileName != null) { File file = new File(fileDirectory, fileName); try { String contents = textArea.getText(); FileWriter fw = new FileWriter(file); fw.flush(); fw.write(contents); fw.close(); // inform user // manager.getStatusMessageLabel().setText("Successfully saved contents to file "+fileName); logger.info("Successfully saved contents to file " + fileName); } catch (IOException e) { logger.warn(e.fillInStackTrace()); // manager.getStatusMessageLabel().setText("Errors saving contents to file "+fileName); } } } }); // create buttons panel JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS)); buttonsPanel.add(Box.createHorizontalStrut(200)); buttonsPanel.add(copyButton); buttonsPanel.add(exportButton); panel.add(buttonsPanel, BorderLayout.SOUTH); panel.add(new JScrollPane(textArea), BorderLayout.CENTER); return panel; }
From source file:ustc.sse.rjava.RJavaInterface.java
public String rChooseFile(Rengine re, int newFile) { FileDialog fd = new FileDialog(new Frame(), (newFile == 0) ? "Select a file" : "Select a new file", (newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE); fd.setVisible(true);/*from w w w .j a v a2 s . com*/ String res = null; if (fd.getDirectory() != null) res = fd.getDirectory(); if (fd.getFile() != null) res = (res == null) ? fd.getFile() : (res + fd.getFile()); return res; }
From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java
public boolean saveAs() { FileDialog fd = new FileDialog(OpenBSTGUI.getInstance(), Lang.get("editor.saveloc"), FileDialog.SAVE); fd.setLocationRelativeTo(OpenBSTGUI.getInstance()); fd.setVisible(true);/* www . j av a 2s . c o m*/ if (fd.getFile() != null) { final File file = new File(fd.getFile().endsWith(".bst") ? fd.getDirectory() + fd.getFile() : fd.getDirectory() + fd.getFile() + ".bst"); try { doSave(file); lastFileLocation = file; return true; } catch (IOException | BSTException e1) { OpenBST.LOG.error("Failed saving a file", e1); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.savefail"), e1); } } return false; }
From source file:views.View.java
private void fileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileActionPerformed // TODO add your handling code here: FileDialog fd = new FileDialog(this, "Open", FileDialog.SAVE); }