Esempio n. 1
0
 String getPath() {
   OpenDialog od = new OpenDialog("Open", "");
   String dir = od.getDirectory();
   String name = od.getFileName();
   if (name == null) return null;
   else return dir + name;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Displays a file open dialog box and then opens the tiff, dicom, fits, pgm, jpeg, bmp, gif, lut,
  * roi, or text file selected by the user. Displays an error message if the selected file is not
  * in a supported format. This is the method that ImageJ's File/Open command uses to open files.
  *
  * @see ij.IJ#open()
  * @see ij.IJ#open(String)
  * @see ij.IJ#openImage()
  * @see ij.IJ#openImage(String)
  */
 public void open() {
   OpenDialog od = new OpenDialog("Open", "");
   String directory = od.getDirectory();
   String name = od.getFileName();
   if (name != null) {
     String path = directory + name;
     error = false;
     open(path);
     if (!error) Menus.addOpenRecentItem(path);
   }
 }
 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);
 }
Esempio n. 6
0
 /**
  * Displays a JFileChooser and then opens the tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or
  * text files selected by the user. Displays error messages if one or more of the selected files
  * is not in one of the supported formats. This is the method that ImageJ's File/Open command uses
  * to open files if "Open/Save Using JFileChooser" is checked in EditOptions/Misc.
  */
 public void openMultiple() {
   Java2.setSystemLookAndFeel();
   // run JFileChooser in a separate thread to avoid possible thread deadlocks
   try {
     EventQueue.invokeAndWait(
         new Runnable() {
           public void run() {
             JFileChooser fc = new JFileChooser();
             fc.setMultiSelectionEnabled(true);
             File dir = null;
             String sdir = OpenDialog.getDefaultDirectory();
             if (sdir != null) dir = new File(sdir);
             if (dir != null) fc.setCurrentDirectory(dir);
             int returnVal = fc.showOpenDialog(IJ.getInstance());
             if (returnVal != JFileChooser.APPROVE_OPTION) return;
             omFiles = fc.getSelectedFiles();
             if (omFiles.length == 0) { // getSelectedFiles does not work on some JVMs
               omFiles = new File[1];
               omFiles[0] = fc.getSelectedFile();
             }
             omDirectory = fc.getCurrentDirectory().getPath() + File.separator;
           }
         });
   } catch (Exception e) {
   }
   if (omDirectory == null) return;
   OpenDialog.setDefaultDirectory(omDirectory);
   for (int i = 0; i < omFiles.length; i++) {
     String path = omDirectory + omFiles[i].getName();
     open(path);
     if (i == 0 && Recorder.record) Recorder.recordPath("open", path);
     if (i == 0 && !error) Menus.addOpenRecentItem(path);
   }
 }
Esempio n. 7
0
 /** Opens a tab or comma delimited text file. */
 public static void openTable(String path) {
   String name = "";
   if (path == null || path.equals("")) {
     OpenDialog od = new OpenDialog("Open Table...");
     String dir = od.getDirectory();
     name = od.getFileName();
     if (name == null) return;
     else path = dir + name;
   }
   try {
     ResultsTable rt = ResultsTable.open(path);
     if (rt != null) {
       rt.showRowNumbers(false);
       rt.show(name);
     }
   } catch (IOException e) {
     IJ.error("Open Table", e.getMessage());
   }
 }
Esempio n. 8
0
 /**
  * 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);
   }
 }
Esempio n. 9
0
  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();
  }
Esempio n. 10
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();
   }
 }
Esempio n. 11
0
 /**
  * Opens and displays the specified tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text
  * file. Displays an error message if the file is not in a supported format.
  *
  * @see ij.IJ#open(String)
  * @see ij.IJ#openImage(String)
  */
 public void open(String path) {
   boolean isURL = path.indexOf("://") > 0;
   if (isURL && isText(path)) {
     openTextURL(path);
     return;
   }
   if (path.endsWith(".jar") || path.endsWith(".class")) {
     (new PluginInstaller()).install(path);
     return;
   }
   boolean fullPath =
       path.startsWith("/") || path.startsWith("\\") || path.indexOf(":\\") == 1 || isURL;
   if (!fullPath) {
     String defaultDir = OpenDialog.getDefaultDirectory();
     if (defaultDir != null) path = defaultDir + path;
     else path = (new File(path)).getAbsolutePath();
   }
   if (!silentMode) IJ.showStatus("Opening: " + path);
   long start = System.currentTimeMillis();
   ImagePlus imp = openImage(path);
   if (imp == null && isURL) return;
   if (imp != null) {
     WindowManager.checkForDuplicateName = true;
     if (isRGB48) openRGB48(imp);
     else imp.show(getLoadRate(start, imp));
   } else {
     switch (fileType) {
       case LUT:
         imp = (ImagePlus) IJ.runPlugIn("ij.plugin.LutLoader", path);
         if (imp.getWidth() != 0) imp.show();
         break;
       case ROI:
         IJ.runPlugIn("ij.plugin.RoiReader", path);
         break;
       case JAVA_OR_TEXT:
       case TEXT:
         if (IJ.altKeyDown()) { // open in TextWindow if alt key down
           new TextWindow(path, 400, 450);
           IJ.setKeyUp(KeyEvent.VK_ALT);
           break;
         }
         File file = new File(path);
         int maxSize = 250000;
         long size = file.length();
         if (size >= 28000) {
           String osName = System.getProperty("os.name");
           if (osName.equals("Windows 95")
               || osName.equals("Windows 98")
               || osName.equals("Windows Me")) maxSize = 60000;
         }
         if (size < maxSize) {
           Editor ed = (Editor) IJ.runPlugIn("ij.plugin.frame.Editor", "");
           if (ed != null) ed.open(getDir(path), getName(path));
         } else new TextWindow(path, 400, 450);
         break;
       case OJJ: // ObjectJ project
         IJ.runPlugIn("ObjectJ_", path);
         break;
       case TABLE: // ImageJ Results table
         openResultsTable(path);
         break;
       case RAW:
         IJ.runPlugIn("ij.plugin.Raw", path);
         break;
       case UNKNOWN:
         String msg =
             "File is not in a supported format, a reader\n"
                 + "plugin is not available, or it was not found.";
         if (path != null) {
           if (path.length() > 64) path = (new File(path)).getName();
           if (path.length() <= 64) {
             if (IJ.redirectingErrorMessages()) msg += " \n   " + path;
             else msg += " \n	 \n" + path;
           }
         }
         if (openUsingPlugins) msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set.";
         IJ.wait(IJ.isMacro() ? 500 : 100); // work around for OS X thread deadlock problem
         IJ.error("Opener", msg);
         error = true;
         break;
     }
   }
 }