本文整理汇总了Java中ij.io.SaveDialog.getDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java SaveDialog.getDirectory方法的具体用法?Java SaveDialog.getDirectory怎么用?Java SaveDialog.getDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.io.SaveDialog
的用法示例。
在下文中一共展示了SaveDialog.getDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveText
import ij.io.SaveDialog; //导入方法依赖的package包/类
private void saveText(String title, double[] data) throws IOException {
SaveDialog saveDialog = new SaveDialog("Save", title, ".txt");
File file = new File(saveDialog.getDirectory() + saveDialog.getFileName());
FileWriter filewriter = new FileWriter(file);
for (int i=0; i<data.length; i++) {
filewriter.write(String.valueOf(data[i]) + "\n");
if (i%10000 == 0) {
IJ.log((double)i/data.length + "%");
}
}
IJ.log("100%");
// ProgressBar pb = new ProgressBar(400, 100);
// for (int i=0; i<data.length; i++) {
// filewriter.write(String.valueOf(data[i]));
// pb.show((double)i/data.length);
// }
filewriter.close();
}
示例2: write
import ij.io.SaveDialog; //导入方法依赖的package包/类
private static String write(String string, String path, boolean append) {
if (path==null || path.equals("")) {
String msg = append?"Append String...":"Save String...";
SaveDialog sd = new SaveDialog(msg, "Untitled", ".txt");
String name = sd.getFileName();
if (name==null) return null;
path = sd.getDirectory() + name;
}
try {
BufferedWriter out = new BufferedWriter(new FileWriter(path, append));
out.write(string);
out.close();
} catch (IOException e) {
return ""+e;
}
return null;
}
示例3: run
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void run(String arg) {
ImagePlus imp = WindowManager.getCurrentImage();
if (imp == null) {
IJ.showMessage(noImages);
return;
}
String name = arg;
if (arg == null || arg.equals("")) {
name = imp.getTitle();
}
SaveDialog sd = new SaveDialog(plugInName+"...", name, ".nrrd");
String file = sd.getFileName();
if (file == null) return;
String directory = sd.getDirectory();
save(imp, directory, file);
}
示例4: promptForFile
import ij.io.SaveDialog; //导入方法依赖的package包/类
public static File promptForFile(final String title, final String suggestion,
final String ending)
{
final SaveDialog sd = new SaveDialog(title, suggestion, ending);
final String dir = sd.getDirectory();
if (null == dir) return null;
String filename = sd.getFileName();
if (!filename.toLowerCase().endsWith(ending)) filename += ending;
final File file = new File(dir, filename);
// check if file exists
if (!IJ.isMacOSX()) {
if (file.exists()) {
final YesNoCancelDialog yn =
new YesNoCancelDialog(IJ.getInstance(), "Overwrite?", "File " +
filename + " exists!\nOverwrite?");
if (!yn.yesPressed()) return null;
}
}
return file;
}
示例5: saveAsU3D
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void saveAsU3D() {
final SaveDialog sd = new SaveDialog("Save meshes as u3d...", "", ".u3d");
final String dir = sd.getDirectory();
final String name = sd.getFileName();
if (dir == null || name == null) return;
try {
U3DExporter.export(univ, dir + name);
final String tex = U3DExporter.getTexStub(univ, dir + name);
IJ.log("% Here are a few latex example lines");
IJ.log("% You can compile them for example via");
IJ.log("% pdflatex yourfilename.tex");
IJ.log("");
IJ.log(tex);
record(EXPORT, "U3D", dir + name);
}
catch (final Exception e) {
IJ.error(e.getMessage());
}
}
示例6: saveText
import ij.io.SaveDialog; //导入方法依赖的package包/类
private void saveText(String title, String out) throws IOException {
SaveDialog saveDialog = new SaveDialog("Save", title, ".txt");
File file = new File(saveDialog.getDirectory() + saveDialog.getFileName());
FileWriter filewriter = new FileWriter(file);
filewriter.write(out);
filewriter.close();
}
示例7: run
import ij.io.SaveDialog; //导入方法依赖的package包/类
@Override
public void run(String arg) {
List<InterestPoint> ipts = IJFacade.getLastResult();
if (ipts == null) {
IJ.error(title, "No cached result.\nRun 'Find Interest Points' first.");
return;
}
String proposedName = "surf";
ImagePlus img = WindowManager.getCurrentImage();
if (img != null) {
proposedName = img.getTitle().split(":")[0] + "__" + proposedName;
}
SaveDialog sd = new SaveDialog(title, proposedName, ".txt");
String dir = sd.getDirectory();
String fileName = sd.getFileName();
if (fileName == null)
return;
String fullName = dir + fileName;
boolean inclDescriptor = true; // TODO make true by default + dialog!
IJ.showStatus("SURF: Saving Interest Points to File " + fullName);
InterestPoint.saveToFile(ipts, fullName, inclDescriptor);
}
示例8: save
import ij.io.SaveDialog; //导入方法依赖的package包/类
void save() {
TextArea ta1 = gd.getTextArea1();
ta1.selectAll();
String text = ta1.getText();
ta1.select(0, 0);
if (text==null || text.length()==0)
return;
text += "\n";
SaveDialog sd = new SaveDialog("Save as Text...", "kernel", ".txt");
String name = sd.getFileName();
if (name == null)
return;
String directory = sd.getDirectory();
PrintWriter pw = null;
try {
FileOutputStream fos = new FileOutputStream(directory+name);
BufferedOutputStream bos = new BufferedOutputStream(fos);
pw = new PrintWriter(bos);
}
catch (IOException e) {
IJ.error("" + e);
return;
}
IJ.wait(250); // give system time to redraw ImageJ window
pw.print(text);
pw.close();
}
示例9: run
import ij.io.SaveDialog; //导入方法依赖的package包/类
/**
* Main processing method for the VtkEncoder plugin
*
* @param arg If equal "ASCII" file will be saved in text format otherwise in binary format
* (MSB).
*/
@Override
public void run(final String arg) {
final ImagePlus imp = WindowManager.getCurrentImage();
if (imp == null) {
IJ.showMessage(DIALOG_CAPTION, "No image to save.");
return;
}
final SaveDialog saveDialog = new SaveDialog("Save as VTK", imp.getTitle(), ".vtk");
if (saveDialog.getFileName() == null) {
return;
}
IJ.showStatus("Saving current image as '" + saveDialog.getFileName() + "'...");
final String fileName = saveDialog.getDirectory() + File.separator + saveDialog.getFileName();
try {
final long tStart = System.currentTimeMillis();
VtkEncoder.save(fileName, imp, "ASCII".compareToIgnoreCase(arg) == 0);
final long tStop = System.currentTimeMillis();
IJ.showStatus("Saving of '" + saveDialog.getFileName() + "' completed in " + (tStop - tStart) + " ms.");
} catch (final Exception ex) {
ex.printStackTrace();
String msg = ex.getMessage();
if (msg == null) {
msg = "";
} else {
msg = "\n" + msg;
}
IJ.showMessage(DIALOG_CAPTION, "Error writing file '" + fileName + "'." + msg);
}
}
示例10: run
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void run(String arg) {
ImagePlus imp = WindowManager.getCurrentImage();
if (null == imp) return;
SaveDialog sd = new SaveDialog("Save Viva File", "copy_"+imp.getTitle(), ".viv");
if(sd.getDirectory()!=null & sd.getFileName()!=null){
String dir = sd.getDirectory();
if (null == dir) return; // user canceled dialog
dir = dir.replace('\\', '/'); // Windows safe
if (!dir.endsWith("/")) dir += "/";
new SEQProjectionSource().saveViva(imp, dir + sd.getFileName());
}
}
示例11: saveView
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void saveView() {
final SaveDialog sd = new SaveDialog("Save view...", "", ".view");
final String dir = sd.getDirectory();
final String name = sd.getFileName();
if (dir == null || name == null) return;
try {
univ.saveView(dir + name);
}
catch (final Exception e) {
IJ.error(e.getMessage());
}
}
示例12: saveSession
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void saveSession() {
final SaveDialog sd =
new SaveDialog("Save session...", "session", ".scene");
final String dir = sd.getDirectory();
final String name = sd.getFileName();
if (dir == null || name == null) return;
try {
univ.saveSession(dir + name);
}
catch (final Exception e) {
IJ.error(e.getMessage());
}
}
示例13: savePointList
import ij.io.SaveDialog; //导入方法依赖的package包/类
public void savePointList() {
String dir = OpenDialog.getDefaultDirectory();
String fileName = getName();
final ImagePlus image = contents.firstEntry().getValue().image;
if (image != null) {
final FileInfo fi = image.getFileInfo();
dir = fi.directory;
fileName = fi.fileName;
}
final SaveDialog sd =
new SaveDialog("Save points annotation file as...", dir, fileName,
".points");
if (sd.getFileName() == null) return;
final File file = new File(sd.getDirectory(), sd.getFileName());
if (file.exists() &&
!IJ.showMessageWithCancel("File exists", "Overwrite " + file + "?")) return;
try {
final PrintStream out = new PrintStream(file);
for (final Integer frame : contents.keySet()) {
final ContentInstant ci = contents.get(frame);
if (ci.getPointList().size() != 0) {
out.println("# frame " + frame);
ci.savePointList(out);
}
}
out.close();
}
catch (final IOException e) {
IJ.error("Could not save points to " + file);
}
}
示例14: exportChart
import ij.io.SaveDialog; //导入方法依赖的package包/类
/**
* 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;
}
}
示例15: run
import ij.io.SaveDialog; //导入方法依赖的package包/类
@Override
public void run(final String arg) {
// Get current image
final ImagePlus imp = WindowManager.getCurrentImage();
if (imp == null) {
IJ.noImage();
return;
}
// Verify type
if (imp.getType() == ImagePlus.COLOR_256 || imp.getType() == ImagePlus.COLOR_RGB) {
IJ.error(TITLE, "COLOR_256 and COLOR_RGB images are not supported.");
return;
}
// Should the image be single file
final GenericDialog dialog = new GenericDialog(TITLE);
dialog.addCheckbox("Save_in_single_file", saveInSingleFile);
dialog.addMessage("" +
"Write current image in MetaImage format used by ITK. \n" +
"Option \"Save in single file\" indicates whether the image should be saved in a single \n" +
"file (extension *.mha) or the header and the image data should be saved in separate \n" +
"files (with extensions *.mhd and *.raw respectively.) ");
dialog.addHelp(HELP_URL);
dialog.showDialog();
if (dialog.wasCanceled()) {
return;
}
saveInSingleFile = dialog.getNextBoolean();
// Get file name
final String extension = saveInSingleFile ? ".mha" : ".mhd";
final SaveDialog saveDialog = new SaveDialog(TITLE, imp.getTitle(), extension);
if (saveDialog.getFileName() == null) {
return;
}
// Save the image
final File file = new File(saveDialog.getDirectory(), saveDialog.getFileName());
try {
MiEncoder.write(imp, file.getAbsolutePath(), saveInSingleFile);
} catch (final MiException ex) {
ex.printStackTrace();
IJ.error(TITLE, ex.getMessage());
return;
}
IJ.showStatus("MetaImage " + saveDialog.getFileName() + " saved.");
}