private boolean ignoreArrowKeys(ImagePlus imp) { Frame frame = WindowManager.getFrontWindow(); String title = frame.getTitle(); if (title != null && title.equals("ROI Manager")) return true; // Control Panel? if (frame != null && frame instanceof javax.swing.JFrame) return true; ImageWindow win = imp.getWindow(); // LOCI Data Browser window? if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci")) return true; return false; }
void saveWindowLocations() { Frame frame = WindowManager.getFrame("B&C"); if (frame != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Threshold"); if (frame != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Results"); if (frame != null) { Prefs.saveLocation(TextWindow.LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.WIDTH_KEY, d.width); Prefs.set(TextWindow.HEIGHT_KEY, d.height); } frame = WindowManager.getFrame("Log"); if (frame != null) { Prefs.saveLocation(TextWindow.LOG_LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width); Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height); } }
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(); }
public BandAdjuster() { super("Threshold Colour"); if (instance != null) { instance.toFront(); return; } imp = WindowManager.getCurrentImage(); if (imp == null) { IJ.beep(); IJ.showStatus("No image"); return; } IJ.run("Select None"); thread = new Thread(this, "BandAdjuster"); WindowManager.addWindow(this); instance = this; IJ.register(PasteController.class); ij = IJ.getInstance(); Font font = new Font("SansSerif", Font.PLAIN, 10); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); labelh = new Label("Hue", Label.CENTER); add(labelh, c); c.gridx = 1; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(7, 0, 0, 0); labelf = new Label("Filter type", Label.RIGHT); add(labelf, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(plot, c); // checkboxes panelh = new Panel(); filterTypeH = new CheckboxGroup(); bandPassH = new Checkbox("Pass"); bandPassH.setCheckboxGroup(filterTypeH); bandPassH.addItemListener(this); panelh.add(bandPassH); bandStopH = new Checkbox("Stop"); bandStopH.setCheckboxGroup(filterTypeH); bandStopH.addItemListener(this); panelh.add(bandStopH); bandPassH.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelh, c); // minHue slider minSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider, c); minSlider.addAdjustmentListener(this); minSlider.setUnitIncrement(1); // minHue slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label1 = new Label(" ", Label.LEFT); label1.setFont(font); add(label1, c); // maxHue sliderHue maxSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider, c); maxSlider.addAdjustmentListener(this); maxSlider.setUnitIncrement(1); // maxHue slider label c.gridx = 1; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label2 = new Label(" ", Label.LEFT); label2.setFont(font); add(label2, c); // ===== c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labels = new Label("Saturation", Label.CENTER); add(labels, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(splot, c); // checkboxes panels = new Panel(); filterTypeS = new CheckboxGroup(); bandPassS = new Checkbox("Pass"); bandPassS.setCheckboxGroup(filterTypeS); bandPassS.addItemListener(this); panels.add(bandPassS); bandStopS = new Checkbox("Stop"); bandStopS.setCheckboxGroup(filterTypeS); bandStopS.addItemListener(this); panels.add(bandStopS); bandPassS.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panels, c); // minSat slider minSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider2, c); minSlider2.addAdjustmentListener(this); minSlider2.setUnitIncrement(1); // minSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label3 = new Label(" ", Label.LEFT); label3.setFont(font); add(label3, c); // maxSat slider maxSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider2, c); maxSlider2.addAdjustmentListener(this); maxSlider2.setUnitIncrement(1); // maxSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label4 = new Label(" ", Label.LEFT); label4.setFont(font); add(label4, c); // ===== c.gridx = 0; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labelb = new Label("Brightness", Label.CENTER); add(labelb, c); c.gridx = 0; c.gridwidth = 1; c.gridy = y; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(bplot, c); // checkboxes panelb = new Panel(); filterTypeB = new CheckboxGroup(); bandPassB = new Checkbox("Pass"); bandPassB.setCheckboxGroup(filterTypeB); bandPassB.addItemListener(this); panelb.add(bandPassB); bandStopB = new Checkbox("Stop"); bandStopB.setCheckboxGroup(filterTypeB); bandStopB.addItemListener(this); panelb.add(bandStopB); bandPassB.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelb, c); // minBri slider minSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider3, c); minSlider3.addAdjustmentListener(this); minSlider3.setUnitIncrement(1); // minBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label5 = new Label(" ", Label.LEFT); label5.setFont(font); add(label5, c); // maxBri slider maxSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider3, c); maxSlider3.addAdjustmentListener(this); maxSlider3.setUnitIncrement(1); // maxBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label6 = new Label(" ", Label.LEFT); label6.setFont(font); add(label6, c); // ===== panelt = new Panel(); threshold = new Checkbox("Threshold"); threshold.addItemListener(this); panelt.add(threshold); invert = new Checkbox("Invert"); invert.addItemListener(this); panelt.add(invert); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelt, c); // buttons panel = new Panel(); // panel.setLayout(new GridLayout(2, 2, 0, 0)); originalB = new Button("Original"); originalB.setEnabled(false); originalB.addActionListener(this); originalB.addKeyListener(ij); panel.add(originalB); filteredB = new Button("Filtered"); filteredB.setEnabled(false); filteredB.addActionListener(this); filteredB.addKeyListener(ij); panel.add(filteredB); stackB = new Button("Stack"); stackB.addActionListener(this); stackB.addKeyListener(ij); panel.add(stackB); helpB = new Button("Help"); helpB.addActionListener(this); helpB.addKeyListener(ij); panel.add(helpB); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panel, c); panelMode = new Panel(); sampleB = new Button("Sample"); sampleB.addActionListener(this); sampleB.addKeyListener(ij); panelMode.add(sampleB); colourMode = new CheckboxGroup(); hsb = new Checkbox("HSB"); hsb.setCheckboxGroup(colourMode); hsb.addItemListener(this); panelMode.add(hsb); hsb.setState(true); rgb = new Checkbox("RGB"); rgb.setCheckboxGroup(colourMode); rgb.addItemListener(this); panelMode.add(rgb); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelMode, c); addKeyListener(ij); // ImageJ handles keyboard shortcuts pack(); GUI.center(this); setVisible(true); ip = setup(imp); if (ip == null) { imp.unlock(); IJ.beep(); IJ.showStatus("RGB image cannot be thresholded"); return; } thread.start(); }