Java Code Examples for ij.io.SaveDialog#getFileName()

The following examples show how to use ij.io.SaveDialog#getFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShollAnalysisDialog.java    From SNT with GNU General Public License v3.0 6 votes vote down vote up
public void exportGraphAsSVG() {

			final SaveDialog sd = new SaveDialog("Export graph as...", "sholl" + suggestedSuffix, ".svg");

			if (sd.getFileName() == null) {
				return;
			}

			final File saveFile = new File(sd.getDirectory(), sd.getFileName());
			if ((saveFile != null) && saveFile.exists()) {
				if (!IJ.showMessageWithCancel("Export graph...",
						"The file " + saveFile.getAbsolutePath() + " already exists.\n" + "Do you want to replace it?"))
					return;
			}

			IJ.showStatus("Exporting graph to " + saveFile.getAbsolutePath());

			try {
				exportChartAsSVG(chart, chartPanel.getBounds(), saveFile);
			} catch (final IOException ioe) {
				IJ.error("Saving to " + saveFile.getAbsolutePath() + " failed");
				return;
			}

		}
 
Example 2
Source File: PlotUtils.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Exports the specified JFreeChart to a SVG or PDF file. Destination file
 * is specified by the user in a save dialog prompt. An error message is
 * displayed if the file could not be saved. Does nothing if {@code chart}
 * is {@code null}.
 *
 * @param chart
 *            the <a href="http://javadoc.imagej.net/JFreeChart/" target=
 *            "_blank">JFreeChart </a> to export.
 * @param bounds
 *            the Rectangle delimiting the boundaries within which the chart
 *            should be drawn.
 * @param extension
 *            The file extension. Either ".svg" or ".pdf"
 * @see #exportChartAsSVG(JFreeChart, Rectangle)
 * @see #exportChartAsPDF(JFreeChart, Rectangle)
 */
static void exportChart(final JFreeChart chart, final Rectangle bounds, final String extension) {
	if (chart == null)
		return;
	final String defaultName = (chart.getTitle() == null) ? "Chart" : chart.getTitle().getText();
	final SaveDialog sd = new SaveDialog("Export graph as...", defaultName, extension);
	if (sd.getFileName() == null)
		return;
	final File saveFile = new File(sd.getDirectory(), sd.getFileName());
	if ((saveFile != null) && saveFile.exists()) {
		if (!IJ.showMessageWithCancel("Export graph...",
				saveFile.getAbsolutePath() + " already exists.\nReplace it?"))
			return;
	}
	try {
		if (extension.toLowerCase().endsWith(".svg"))
			exportChartAsSVG(chart, bounds, saveFile);
		else if (extension.toLowerCase().endsWith(".pdf"))
			exportChartAsPDF(chart, bounds, saveFile);
		IJ.showStatus("Graph saved, " + saveFile.getAbsolutePath());
	} catch (final Exception e) {
		IJ.error("Error", "Saving to " + saveFile.getAbsolutePath() + " failed");
		if (IJ.debugMode)
			IJ.handleException(e);
		return;
	}
}
 
Example 3
Source File: ShollAnalysisDialog.java    From SNT with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
	final Object source = e.getSource();
	final ShollResults results;
	synchronized (this) {
		results = getCurrentResults();
	}
	if (results == null) {
		IJ.error("The sphere separation field must be a number, not '" + sampleSeparation.getText() + "'");
		return;
	}
	if (source == makeShollImageButton) {
		results.makeShollCrossingsImagePlus(originalImage);

	} else if (source == analyzeButton) {

		final Thread newThread = new Thread(new Runnable() {
			@Override
			public void run() {
				analyzeButton.setEnabled(false);
				analyzeButton.setLabel("Running Analysis. Please wait...");
				results.analyzeWithShollAnalysisPlugin(getExportPath(), shollpafm.getPathsStructured().length);
				analyzeButton.setLabel("Analyze Profile (Sholl Analysis v" + Sholl_Utils.version() + ")...");
				analyzeButton.setEnabled(true);
			}
		});
		newThread.start();
		return;

	} else if (source == exportProfileButton) {

		// We only only to save the detailed profile. Summary profile will
		// be handled by sholl.Sholl_Analysis

		final SaveDialog sd = new SaveDialog("Export data as...", getExportPath(),
				originalImage.getTitle() + "-sholl" + results.getSuggestedSuffix(), ".csv");

		if (sd.getFileName() == null) {
			return;
		}

		final File saveFile = new File(exportPath = sd.getDirectory(), sd.getFileName());
		if ((saveFile != null) && saveFile.exists()) {
			if (!IJ.showMessageWithCancel("Export data...",
					"The file " + saveFile.getAbsolutePath() + " already exists.\n" + "Do you want to replace it?"))
				return;
		}

		IJ.showStatus("Exporting CSV data to " + saveFile.getAbsolutePath());

		try {
			results.exportDetailToCSV(saveFile);
		} catch (final IOException ioe) {
			IJ.error("Saving to " + saveFile.getAbsolutePath() + " failed");
			return;
		}

	} else if (source == drawShollGraphButton) {
		graphFrame.setVisible(true);
	}
}
 
Example 4
Source File: Render.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static public void exportSVG(ProjectThing thing, double z_scale) {
	StringBuffer data = new StringBuffer();
	data.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n")
	    .append("<svg\n")
	    .append("\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n")
	    .append("\txmlns:cc=\"http://web.resource.org/cc/\"\n")
	    .append("\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n")
	    .append("\txmlns:svg=\"http://www.w3.org/2000/svg\"\n")
	    .append("\txmlns=\"http://www.w3.org/2000/svg\"\n")
	    //.append("\twidth=\"1500\"\n")
	    //.append("\theight=\"1000\"\n")
	    .append("\tid=\"").append(thing.getProject().toString()).append("\">\n")
	;
	// traverse the tree at node 'thing'
	thing.exportSVG(data, z_scale, "\t");

	data.append("</svg>");

	// save the file
	final SaveDialog sd = new SaveDialog("Save .svg", OpenDialog.getDefaultDirectory(), "svg");
	String dir = sd.getDirectory();
	if (null == dir) return;
	if (IJ.isWindows()) dir = dir.replace('\\', '/');
	if (!dir.endsWith("/")) dir += "/";
	String file_name = sd.getFileName();
	String file_path = dir + file_name;
	File f = new File(file_path);
	if (f.exists()) {
		YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), "Overwrite?", "File " + file_name + " exists! Overwrite?");
		if (!d.yesPressed()) {
			return;
		}
	}
	String contents = data.toString();
	try {
		DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f), data.length()));
		dos.writeBytes(contents);
		dos.flush();
	} catch (Exception e) {
		IJError.print(e);
		Utils.log("ERROR: Most likely did NOT save your file.");
	}
}