Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #5
0
  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);
    }
  }
Example #6
0
  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();
    }
  }
Example #7
0
 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();
   }
 }