public boolean getParticlesTableFile() { java.lang.String ptable_dir = prefs.get("QuickPALM.ptable_dir", "."); java.lang.String ptable_file = prefs.get("QuickPALM.ptable_file", "Particles Table.xls"); OpenDialog chooser = new OpenDialog("Load Particles Table", ptable_dir, ptable_file); ptablefile = chooser.getDirectory() + chooser.getFileName(); prefs.set("QuickPALM.ptable_dir", chooser.getDirectory()); prefs.set("QuickPALM.ptable_file", chooser.getFileName()); return true; }
public boolean getCalibrationFile() { java.lang.String cal_dir = prefs.get("QuickPALM.cal_dir", "."); java.lang.String cal_file = prefs.get("QuickPALM.cal_file", "Astigmatism calibration.xls"); OpenDialog chooser = new OpenDialog("Astigmatism calibration", cal_dir, cal_file); calfile = chooser.getDirectory() + chooser.getFileName(); prefs.set("QuickPALM.cal_dir", chooser.getDirectory()); prefs.set("QuickPALM.cal_file", chooser.getFileName()); return true; }
public void run(String arg) { OpenDialog od = new OpenDialog("Install Plugin, Macro or Script...", arg); String directory = od.getDirectory(); String name = od.getFileName(); if (name == null) return; if (!validExtension(name)) { IJ.error("Plugin Installer", errorMessage()); return; } String path = directory + name; install(path); }
String showDialog() { if (defaultDir == null) defaultDir = Menus.getMacrosPath(); OpenDialog od = new OpenDialog("Install Macros", defaultDir, fileName); String name = od.getFileName(); if (name == null) return null; String dir = od.getDirectory(); if (!(name.endsWith(".txt") || name.endsWith(".ijm"))) { IJ.showMessage("Macro Installer", "File name must end with \".txt\" or \".ijm\" ."); return null; } fileName = name; defaultDir = dir; return dir + name; }
public void run(String arg) { String ijDir = System.getProperty("ij.dir"); if (!ijDir.endsWith("/")) ijDir += "/"; if (arg == null || "".equals(arg)) { OpenDialog dialog = new OpenDialog("Which Fiji component", ijDir + "plugins", ""); if (dialog.getDirectory() == null) return; arg = dialog.getDirectory() + dialog.getFileName(); } if (arg.startsWith(ijDir)) arg = arg.substring(ijDir.length()); final JFrame frame = new JFrame("Building " + arg + "..."); Container panel = frame.getContentPane(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JTextArea textArea = new JTextArea("Calling Fiji Build\n", 25, 80); textArea.setFont(new Font("Courier", Font.PLAIN, 12)); textArea.setEditable(false); panel.add(new JScrollPane(textArea)); final JButton okay = new JButton("okay"); okay.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); } }); okay.setEnabled(false); okay.setAlignmentX(Component.CENTER_ALIGNMENT); panel.add(okay); frame.pack(); frame.setLocationRelativeTo(null); okay.requestFocus(); frame.setVisible(true); try { Fake fake = new Fake(); fake.out = fake.err = new PrintStream(new JTextAreaOutputStream(textArea)); Parser parser = fake.parse(new FileInputStream(ijDir + "/Fakefile"), new File(ijDir)); final Rule all = parser.parseRules(Arrays.asList(arg.split("\\s+"))); all.make(); fake.out.println("Finished."); frame.setTitle("Built " + arg); okay.setEnabled(true); } catch (Exception e) { IJ.handleException(e); } }
/** * Open a file. If it's a directory, ask to open all images as a sequence in a stack or * individually. */ public void openFile(File f) { if (IJ.debugMode) IJ.log("DragAndDrop.openFile: " + f); try { if (null == f) return; String path = f.getCanonicalPath(); if (f.exists()) { if (f.isDirectory()) openDirectory(f, path); else { if (openAsVirtualStack && (path.endsWith(".tif") || path.endsWith(".TIF"))) (new FileInfoVirtualStack()).run(path); else (new Opener()).openAndAddToRecent(path); OpenDialog.setLastDirectory(f.getParent() + File.separator); OpenDialog.setLastName(f.getName()); } } else { IJ.log("File not found: " + path); } } catch (Throwable e) { if (!Macro.MACRO_CANCELED.equals(e.getMessage())) IJ.handleException(e); } }
public void run(String arg) { boolean display = false; File test = new File(arg); display = !test.exists(); OpenDialog od = new OpenDialog("Open mkt file...", arg); if (od != null) { String file = od.getFileName(); if (file == null) return; String directory = od.getDirectory(); directory = directory.replace('\\', '/'); // Windows safe if (!directory.endsWith("/")) directory += "/"; arg = directory + file; } try { FileProjectionSource fileSource = new MKTProjectionSource(); fileSource.initStream(arg); ImagePlusDataSink sink = new ImagePlusDataSink(); Grid2D imp = fileSource.getNextProjection(); int i = 0; while (imp != null) { sink.process(imp, i); i++; imp = fileSource.getNextProjection(); } sink.close(); setStack(ImageUtil.wrapGrid3D(sink.getResult(), "").getStack()); setTitle(new File(arg).getName()); fileSource.close(); if (display) show(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); double sfreq = 20000.0; gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null); String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"}; gd.addChoice("PSF Type?", psfchoice, psfchoice[0]); String[] filetypechoice = { "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File" }; gd.addChoice("File Type?", filetypechoice, filetypechoice[0]); boolean ch2green = true; gd.addCheckbox("Ch2 is green?", ch2green); gd.showDialog(); if (gd.wasCanceled()) { return; } sfreq = gd.getNextNumber(); int psfflag = gd.getNextChoiceIndex(); int fileflag = gd.getNextChoiceIndex(); ch2green = gd.getNextBoolean(); int nfiles = 0; Object[] histograms = null; int xmax = 0; int ymax = 0; String[] names = null; if (fileflag < 2) { jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length / 2; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = organize_c3_files(filearray); for (int i = 0; i < nfiles; i++) { try { int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0); int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0); int length3 = (int) (((double) filearray[2 * i].length()) / 2.0); int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0); InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i])); InputStream instream2 = new BufferedInputStream(new FileInputStream(filearray[2 * i + 1])); if (fileflag == 0) { int[] pmdata = new int[length1]; int[] pmdata2 = new int[length2]; if (!ioclass.skipstreambytes(instream, 128)) { showioerror(); instream.close(); return; } if (!ioclass.skipstreambytes(instream2, 128)) { showioerror(); instream2.close(); return; } if (!ioclass.readintelintfile(instream, length1, pmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelintfile(instream2, length2, pmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000); } else { histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000); } } else { float[] tmdata = new float[length3]; float[] tmdata2 = new float[length4]; if (!ioclass.readintelshortfile(instream, length3, tmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata); } else { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2); } } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } instream.close(); instream2.close(); } catch (IOException e) { showioerror(); return; } } } else { if (fileflag == 2) { ImageWindow iw = WindowManager.getCurrentWindow(); float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); sfreq = 1.0 / ((double) tempxvals[0][1]); nfiles = trajectories.length / 2; if (nfiles > 25) { nfiles = 25; } names = new String[nfiles + 1]; names[nfiles] = "avg"; histograms = new Object[nfiles]; for (int i = 0; i < nfiles; i++) { names[i] = "trajectory " + (i + 1); if (ch2green) { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]); } else { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]); } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } else { // here we read tab delimited lines from files jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = new String[nfiles + 1]; names[nfiles] = "avg"; for (int i = 0; i < nfiles; i++) { try { names[i] = filearray[i].getName(); BufferedReader d = new BufferedReader(new FileReader(filearray[i])); String[] lines = new String[256]; int counter = 0; do { lines[counter] = d.readLine(); counter++; } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256); int numcolumns = 0; for (int j = 0; j < counter - 1; j++) { int temp = getncolumns(lines[j]); if (temp > numcolumns) { numcolumns = temp; } } float[][] temphist2 = null; if (ch2green) { temphist2 = new float[numcolumns][counter - 1]; } else { temphist2 = new float[counter - 1][numcolumns]; } for (int k = 0; k < counter - 1; k++) { float[] temp = tab_delim2float(lines[k]); for (int j = 0; j < numcolumns; j++) { if (ch2green) { temphist2[j][k] = temp[j]; } else { temphist2[k][j] = temp[j]; } } } histograms[i] = temphist2; d.close(); } catch (IOException e) { showioerror(); return; } } for (int i = 0; i < nfiles; i++) { if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } } // note that here x is green and y is red float[][][] pch = new float[nfiles][xmax][ymax]; for (int i = 0; i < nfiles; i++) { for (int j = 0; j < ((float[][]) histograms[i]).length; j++) { for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) { pch[i][j][k] = ((float[][]) histograms[i])[j][k]; } } } final PCH2DFitWindow cw = new PCH2DFitWindow(); cw.init(names, pch, psfflag); final Frame f = new Frame("PCH 2D Analysis"); f.setLocation(10, 10); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.add(cw); f.pack(); f.setResizable(false); Insets ins = f.getInsets(); cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65; cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right; f.setSize(cw.totalSize); f.setVisible(true); cw.requestFocus(); }
/** Create a file chooser configured for image writing, adding a panel for image writer options */ public JFileChooser createFileChooser() { // use bio-formats to obtain file filters for available formats FileFilter[] ffs = GUITools.buildFileFilters(new ImageWriter()); Vector<FileFilter> ffv = new Vector<FileFilter>(ffs.length - 1); // remove non-image writers if (ffs != null) { for (int i = 0; i < ffs.length; i++) { if (ffs[i] instanceof ExtensionFileFilter) { if (!((ExtensionFileFilter) ffs[i]).getExtension().equals("java")) { ffv.add(ffs[i]); } } else { ffv.add(ffs[i]); } } } ffs = new FileFilter[ffv.size()]; ffs = ffv.toArray(ffs); // use bio-formats to create a file chooser with a preview panel JFileChooser jfc = GUITools.buildFileChooser(ffs, true); // set initial directory of the file chooser String idir = ALDEnvironmentConfig.getConfigValue("mitobo", null, "savedir"); if (idir == null) idir = ALDEnvironmentConfig.getConfigValue("mitobo", null, "imagedir"); if (idir == null) idir = OpenDialog.getLastDirectory(); if (idir == null) idir = OpenDialog.getDefaultDirectory(); if (idir != null) jfc.setCurrentDirectory(new File(idir)); // remove file filter that accepts any file extension jfc.setAcceptAllFileFilterUsed(false); // install the image writer options panel in the file chooser this.iwop = new ImageWriterOptionsPane(jfc); if (this.img != null) { double dt = ImageIOUtils.toSeconds(this.img.getStepsizeT(), this.img.getUnitT()); if (dt > 0) this.iwop.setDefaultFps((int) Math.round(1.0 / dt)); } else if (this.imp != null) { if (this.imp.getCalibration() != null) { int fps = (int) Math.round(this.imp.getCalibration().fps); if (fps > 0) this.iwop.setDefaultFps(fps); } } // listen to changed property of the writer options panel this.iwop.addPropertyChangeListener(this); // set default/initial file filter to OME-TIFF if possible if (ffs != null) { for (int i = 0; i < ffs.length; i++) { if (ffs[i] instanceof ExtensionFileFilter) { if (((ExtensionFileFilter) ffs[i]).getExtension().equals("ome.tif")) { jfc.setFileFilter(ffs[i]); } } } } return jfc; }
@Override public void run(ImageProcessor arg0) { JFileChooser fc = this.createFileChooser(); // set image title (without extension) as default file name String origtitle = null; if (this.img != null) origtitle = this.img.getTitle(); else if (this.imp != null) origtitle = this.imp.getTitle(); if (origtitle != null) { int dotID = origtitle.indexOf("."); if (dotID != -1) { String name = origtitle.substring(0, dotID); fc.setSelectedFile(new File(name + ".ome.tiff")); } } while (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File outfile = fc.getSelectedFile(); if (outfile == null) { IJ.error("File save dialog returned 'null'"); return; } // if a specific format file filter was chosen, but the selected filename does not // match the formats extension, add the extension FileFilter ff = fc.getFileFilter(); if (ff instanceof ExtensionFileFilter) { ExtensionFileFilter eff = (ExtensionFileFilter) ff; // #TODO: bio-formats release 4.2.2 contains a bug in the ExtensionFileFilter.accept(.) // method, // therefore the extensions are matched manually. Substitute the for-loop with // accept()-method when // using a new release String[] exts = eff.getExtensions(); boolean extmatch = false; for (String ext : exts) { if (outfile.getName().endsWith(ext)) { extmatch = true; break; } } if (!extmatch) { outfile = new File(outfile.getAbsolutePath() + "." + eff.getExtension()); } } // set initial directory of the file chooser for future call if (outfile.getParent() != null) { OpenDialog.setLastDirectory(outfile.getParent()); OpenDialog.setDefaultDirectory(outfile.getParent()); } // determine overwrite flag if file exists boolean overwrite = false; if (outfile.exists()) { int ret = JOptionPane.showConfirmDialog( null, "Do you want to overwrite existing file '" + outfile.getName() + "'?", "File exists", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.YES_OPTION) overwrite = true; else continue; } // create a MiToBo image writer instance ImageWriterMTB writer = null; try { if (this.img != null) { writer = new ImageWriterMTB(this.img, outfile.getAbsolutePath()); } else { writer = new ImageWriterMTB(this.imp, outfile.getAbsolutePath()); } } catch (ALDOperatorException e) { IJ.error("Image writer instantiation failed: " + e.getMessage()); } if (writer != null) { // listener for status and progress bar update writer.addStatusListener(this); // configure and run the writer try { writer.setOverwrite(overwrite); if (this.compression != null) { writer.setCompression(this.compression); } if (this.fps > 0) { writer.setFps(this.fps); } if (this.quality != -1) { writer.setQuality(this.quality); } if (this.codec != -1) { writer.setCodec(this.codec); } writer.runOp(null); } catch (ALDOperatorException e) { IJ.error("Writing of file '" + outfile.getName() + "' failed: " + e.getMessage()); e.printStackTrace(); } catch (FormatException e) { IJ.error("Writing of file '" + outfile.getName() + "' failed: " + e.getMessage()); e.printStackTrace(); } catch (ALDProcessingDAGException e) { IJ.error("Writing of file '" + outfile.getName() + "' failed: " + e.getMessage()); e.printStackTrace(); } } return; } }
public void run(String arg) { Frame[] niframes = WindowManager.getNonImageWindows(); String[] titles = new String[niframes.length + 1]; for (int i = 0; i < niframes.length; i++) { titles[i] = niframes[i].getTitle(); } titles[niframes.length] = "Clipboard"; GenericDialog gd = new GenericDialog("Windows"); boolean importfile = false; gd.addCheckbox("Import from file?", importfile); gd.addChoice("Windows", titles, titles[0]); boolean hasxvals = false; gd.addCheckbox("X Vals Column?", hasxvals); boolean multix = false; gd.addCheckbox("Multi_X_Columns?", multix); boolean skipendzeros = false; gd.addCheckbox("Skip_end_zeros?", skipendzeros); String[] delimiters = {"Tab", "Comma", "Space"}; gd.addChoice("Delimiter", delimiters, delimiters[0]); gd.showDialog(); if (gd.wasCanceled()) { return; } importfile = gd.getNextBoolean(); int index = gd.getNextChoiceIndex(); hasxvals = gd.getNextBoolean(); multix = gd.getNextBoolean(); skipendzeros = gd.getNextBoolean(); int delimindex = gd.getNextChoiceIndex(); if (multix) hasxvals = true; String textdata = ""; if (importfile) { OpenDialog od = new OpenDialog("Open File", "", ".txt"); String directory = od.getDirectory(); String name = od.getFileName(); if (name == null) { return; } try { File infile = new File(directory + name); BufferedReader b = new BufferedReader(new FileReader(infile)); textdata = (new jdataio()).readstringfile(b); b.close(); } catch (IOException e) { return; } } else { if (index == niframes.length) { // here we get the data from the clipboard Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { textdata = (String) t.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException e) { } catch (IOException e) { } if (textdata.equals("")) { IJ.error("Error copying from clipboard."); return; } } else { if (niframes[index] instanceof Editor) { Editor tw = (Editor) niframes[index]; textdata = tw.getText(); } else { if (niframes[index] instanceof TextWindow) { TextWindow tw = (TextWindow) niframes[index]; textdata = tw.getTextPanel().getText(); } else { IJ.showMessage("Not a valid text window"); return; } } } } if (textdata == null) { IJ.showMessage("Error in Obtaining String"); return; } if (textdata.indexOf("\r") >= 0) { textdata = textdata.replace('\r', '\n'); } char[] delims = {'\t', ',', ' '}; delimit_string ds = new delimit_string(delims[delimindex]); String[] rows = ds.getrows(textdata); int lines = rows.length; int columns = ds.getnumcolumns(rows[0]); int ycolumns = columns; if (hasxvals) { if (multix) { ycolumns /= 2; } else { ycolumns--; } } if (multix) { float[][] ydata = new float[ycolumns][lines]; float[][] xdata = new float[ycolumns][lines]; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); for (int j = 0; j < ycolumns; j++) { ydata[j][i] = temp[2 * j + 1]; xdata[j][i] = temp[2 * j]; } } int[] npts = new int[ycolumns]; for (int i = 0; i < ycolumns; i++) { npts[i] = lines; } if (skipendzeros) { for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; while ((xdata[i][counter] == 0.0f || Float.isNaN(xdata[i][counter])) && counter > 0) { xdata[i][counter] = 0.0f; ydata[i][counter] = 0.0f; npts[i]--; counter--; } } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } else { float[][] tempydata = new float[ycolumns][lines]; float[] tempxdata = new float[lines]; float[][] xdata = null; float[][] ydata = null; int startcolumn = 0; if (hasxvals) startcolumn = 1; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); if (hasxvals) { tempxdata[i] = temp[0]; } else { tempxdata[i] = (float) (i + 1); } for (int j = 0; j < ycolumns; j++) { tempydata[j][i] = temp[j + startcolumn]; } } int[] npts = new int[ycolumns]; npts[0] = lines; if (skipendzeros) { int maxpts = 0; for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; npts[i] = lines; while ((tempydata[i][counter] == 0.0f || Float.isNaN(tempydata[i][counter])) && counter > 0) { npts[i]--; counter--; } if (npts[i] > maxpts) maxpts = npts[i]; IJ.log("" + npts[i]); } ydata = new float[ycolumns][maxpts]; xdata = new float[ycolumns][maxpts]; for (int i = 0; i < ycolumns; i++) { // npts[i]=npts[0]; System.arraycopy(tempxdata, 0, xdata[i], 0, npts[i]); System.arraycopy(tempydata[i], 0, ydata[i], 0, npts[i]); } } else { ydata = tempydata; xdata = new float[ycolumns][]; for (int i = 0; i < ycolumns; i++) { npts[i] = npts[0]; xdata[i] = tempxdata.clone(); } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } }