/** * Adds a popup menu. * * @param label the label * @param items the menu items * @param defaultItem the menu item initially selected */ public void addChoice(String label, String[] items, String defaultItem) { String label2 = label; if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' '); Label theLabel = makeLabel(label2); c.gridx = 0; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; if (choice == null) { choice = new Vector(4); c.insets = getInsets(5, 0, 5, 0); } else c.insets = getInsets(0, 0, 5, 0); grid.setConstraints(theLabel, c); add(theLabel); Choice thisChoice = new Choice(); thisChoice.addKeyListener(this); thisChoice.addItemListener(this); for (int i = 0; i < items.length; i++) thisChoice.addItem(items[i]); thisChoice.select(defaultItem); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; grid.setConstraints(thisChoice, c); add(thisChoice); choice.addElement(thisChoice); if (Recorder.record || macro) saveLabel(thisChoice, label); y++; }
public Channels() { super("Channels"); if (instance != null) { instance.toFront(); return; } WindowManager.addWindow(this); instance = this; GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; int margin = 32; if (IJ.isMacOSX()) margin = 20; c.insets = new Insets(10, margin, 10, margin); choice = new Choice(); for (int i = 0; i < modes.length; i++) choice.addItem(modes[i]); choice.select(0); choice.addItemListener(this); add(choice, c); CompositeImage ci = getImage(); int nCheckBoxes = ci != null ? ci.getNChannels() : 3; if (nCheckBoxes > CompositeImage.MAX_CHANNELS) nCheckBoxes = CompositeImage.MAX_CHANNELS; checkbox = new Checkbox[nCheckBoxes]; for (int i = 0; i < nCheckBoxes; i++) { checkbox[i] = new Checkbox("Channel " + (i + 1), true); c.insets = new Insets(0, 25, i < nCheckBoxes - 1 ? 0 : 10, 5); c.gridy = y++; add(checkbox[i], c); checkbox[i].addItemListener(this); } c.insets = new Insets(0, 15, 10, 15); c.fill = GridBagConstraints.NONE; c.gridy = y++; moreButton = new Button(moreLabel); moreButton.addActionListener(this); add(moreButton, c); update(); pm = new PopupMenu(); for (int i = 0; i < menuItems.length; i++) addPopupItem(menuItems[i]); add(pm); addKeyListener(IJ.getInstance()); // ImageJ handles keyboard shortcuts setResizable(false); pack(); if (location == null) { GUI.center(this); location = getLocation(); } else setLocation(location); show(); }
/** Returns the index of the selected item in the next popup menu. */ public int getNextChoiceIndex() { if (choice == null) return -1; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); int index = thisChoice.getSelectedIndex(); if (macro) { String label = (String) labels.get((Object) thisChoice); String oldItem = thisChoice.getSelectedItem(); int oldIndex = thisChoice.getSelectedIndex(); String item = Macro.getValue(macroOptions, label, oldItem); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); thisChoice.select(item); index = thisChoice.getSelectedIndex(); if (index == oldIndex && !item.equals(oldItem)) { // is value a macro variable? Interpreter interp = Interpreter.getInstance(); String s = interp != null ? interp.getStringVariable(item) : null; if (s == null) IJ.error(getTitle(), "\"" + item + "\" is not a valid choice for \"" + label + "\""); else item = s; } } if (recorderOn) { int defaultIndex = ((Integer) (defaultChoiceIndexes.elementAt(choiceIndex))).intValue(); if (!(smartRecording && index == defaultIndex)) { String item = thisChoice.getSelectedItem(); if (!(item.equals("*None*") && getTitle().equals("Merge Channels"))) recordOption(thisChoice, thisChoice.getSelectedItem()); } } choiceIndex++; return index; }
/** Returns the selected item in the next popup menu. */ public String getNextChoice() { if (choice == null) return ""; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); String item = thisChoice.getSelectedItem(); if (macro) { String label = (String) labels.get((Object) thisChoice); item = Macro.getValue(macroOptions, label, item); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); } if (recorderOn) recordOption(thisChoice, item); choiceIndex++; return item; }
public void update() { CompositeImage ci = getImage(); if (ci == null || checkbox == null) return; int n = checkbox.length; int nChannels = ci.getNChannels(); if (nChannels != n && nChannels <= CompositeImage.MAX_CHANNELS) { instance = null; location = getLocation(); close(); new Channels(); return; } boolean[] active = ci.getActiveChannels(); for (int i = 0; i < checkbox.length; i++) checkbox[i].setState(active[i]); int index = 0; switch (ci.getMode()) { case IJ.COMPOSITE: index = 0; break; case IJ.COLOR: index = 1; break; case IJ.GRAYSCALE: index = 2; break; } choice.select(index); }
public void itemStateChanged(ItemEvent e) { beta = Double.parseDouble(betaval.getText()); updatebeta(); boolean avgchanged = false; for (int i = 0; i < ncurves; i++) { if (checkarray[i].getState() != include[i]) { avgchanged = true; if (include[i]) { include[i] = false; } else { include[i] = true; } } } if (avgchanged) { updateavg(); updatebeta(); int1array[ncurves].setText("" + (float) intensity1[ncurves]); e1array[ncurves].setText("" + (float) bright1[ncurves]); n1array[ncurves].setText("" + (float) number1[ncurves]); int2array[ncurves].setText("" + (float) intensity2[ncurves]); e2array[ncurves].setText("" + (float) bright2[ncurves]); n2array[ncurves].setText("" + (float) number2[ncurves]); eccarray[ncurves].setText("" + (float) brightcc[ncurves]); pwavg.updateSeries(avg, 0, true); float[] temp = pwavg.getLimits(); temp[4] = 1.0f; pwavg.setLimits(temp); } if (e.getSource() == dispcurvechoice) { dispcurve = dispcurvechoice.getSelectedIndex(); pwfit.updateSeries(pch[dispcurve], 0, true); pwfit.updateSeries(fit[dispcurve], 1, true); float[] temp = pwfit.getLimits(); temp[4] = 1.0f; pwfit.setLimits(temp); } }
void init(String[] names1, float[][][] pch1, int psfflag1) { setLayout(null); names = names1; pch = pch1; psfflag = psfflag1; ncurves = pch.length; nparams = 11; xpts = pch[0].length; ypts = pch[0][0].length; checkarray = new Checkbox[ncurves]; include = new boolean[ncurves]; namearray = new TextField[ncurves + 1]; int1array = new TextField[ncurves + 1]; intensity1 = new double[ncurves + 1]; e1array = new TextField[ncurves + 1]; n1array = new TextField[ncurves + 1]; bright1 = new double[ncurves + 1]; number1 = new double[ncurves + 1]; int2array = new TextField[ncurves + 1]; intensity2 = new double[ncurves + 1]; e2array = new TextField[ncurves + 1]; n2array = new TextField[ncurves + 1]; bright2 = new double[ncurves + 1]; number2 = new double[ncurves + 1]; eccarray = new TextField[ncurves + 1]; brightcc = new double[ncurves + 1]; eminccarray = new TextField[ncurves + 1]; brightmincc = new double[ncurves + 1]; c2array = new TextField[ncurves + 1]; c2 = new double[ncurves + 1]; nmeas = new int[ncurves + 1]; avg = new float[xpts][ypts]; indices = new int[ncurves]; beta = 0.05; getintbright(); for (int i = 0; i < ncurves; i++) { include[i] = true; indices[i] = i; } updateavg(); int starty = 60; int startx = 10; int yinc = 25; for (int i = 0; i <= ncurves; i++) { if (i != ncurves) { checkarray[i] = new Checkbox("", include[i]); checkarray[i].setBounds(startx, starty + i * yinc, 20, 20); checkarray[i].addItemListener(this); add(checkarray[i]); } namearray[i] = new TextField(names[i]); namearray[i].setBounds(startx + 30, starty + i * yinc, 200, 20); add(namearray[i]); int1array[i] = new TextField("" + (float) intensity1[i]); int1array[i].setBounds(startx + 30 + 210, starty + i * yinc, 40, 20); add(int1array[i]); e1array[i] = new TextField("" + (float) bright1[i]); e1array[i].setBounds(startx + 30 + 210 + 50, starty + i * yinc, 40, 20); add(e1array[i]); n1array[i] = new TextField("" + (float) number1[i]); n1array[i].setBounds(startx + 30 + 210 + 50 + 50, starty + i * yinc, 40, 20); add(n1array[i]); int2array[i] = new TextField("" + (float) intensity2[i]); int2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(int2array[i]); e2array[i] = new TextField("" + (float) bright2[i]); e2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(e2array[i]); n2array[i] = new TextField("" + (float) number2[i]); n2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(n2array[i]); eccarray[i] = new TextField("" + (float) brightcc[i]); eccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eccarray[i]); eminccarray[i] = new TextField("" + (float) brightmincc[i]); eminccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eminccarray[i]); c2[i] = 0.0; c2array[i] = new TextField("" + (float) c2[i]); c2array[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 80, 20); add(c2array[i]); } namelabel = new Label("Filename"); namelabel.setBounds(startx + 30, starty - 25, 100, 20); add(namelabel); intlabel = new Label("<Ig>"); intlabel.setBounds(startx + 30 + 210, starty - 25, 40, 20); add(intlabel); brightlabel = new Label("<eg>"); brightlabel.setBounds(startx + 30 + 210 + 50, starty - 25, 40, 20); add(brightlabel); nlabel = new Label("<Ng>"); nlabel.setBounds(startx + 30 + 210 + 50 + 50, starty - 25, 40, 20); add(nlabel); int2label = new Label("<Ir>"); int2label.setBounds(startx + 30 + 210 + 50 + 50 + 50, starty - 25, 40, 20); add(int2label); bright2label = new Label("<er>"); bright2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(bright2label); n2label = new Label("<Nr>"); n2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(n2label); brightcclabel = new Label("<ecc>"); brightcclabel.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightcclabel); brightccminlabel = new Label("min"); brightccminlabel.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightccminlabel); c2label = new Label("chi^2"); c2label.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 80, 20); add(c2label); int buttonsx = startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 90; fitavgbutton = new Button("Fit Avg"); fitavgbutton.setBounds(buttonsx, starty - 25, 100, 40); fitavgbutton.addActionListener(this); add(fitavgbutton); fitglobalbutton = new Button("Fit Global"); fitglobalbutton.setBounds(buttonsx, starty - 25 + 50, 100, 40); fitglobalbutton.addActionListener(this); add(fitglobalbutton); clearparamsbutton = new Button("Reset Fit Params"); clearparamsbutton.setBounds(buttonsx, starty - 25 + 50 + 50, 100, 40); clearparamsbutton.addActionListener(this); add(clearparamsbutton); checkc2 = false; fitclass = new NLLSfit(this, 0.0001, 50, 0.1); globalfitclass = new NLLSglobalfit(this, 0.0001, 50, 0.1); pchfunc = new pch2D((int) ((double) xpts * 1.5), (int) ((double) ypts * 1.5), psfflag); avgfit = new float[xpts][ypts]; fit = new float[ncurves][xpts][ypts]; xvals = new float[ncurves][xpts][ypts]; for (int i = 0; i < ncurves; i++) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { xvals[i][j][k] = (float) k; fit[i][j][k] = 1.0f; } } } globalc2label = new Label("Global chi^2 = " + (float) 0.0); globalc2label.setBounds(buttonsx, starty - 25 + 50 + 50 + 50, 140, 20); add(globalc2label); dispcurvelabel = new Label("Display Fit #"); dispcurvelabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30, 70, 20); add(dispcurvelabel); dispcurvechoice = new Choice(); for (int i = 0; i < ncurves; i++) { dispcurvechoice.add("" + (i + 1)); } dispcurve = 0; dispcurvechoice.select(0); dispcurvechoice.setBounds(buttonsx + 80, starty - 25 + 50 + 50 + 50 + 30, 40, 20); dispcurvechoice.addItemListener(this); add(dispcurvechoice); betalabel = new Label("Bleedthrough f"); betalabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30, 100, 20); add(betalabel); betaval = new TextField("" + (float) beta); betaval.setBounds(buttonsx + 110, starty - 25 + 50 + 50 + 50 + 30 + 30, 40, 20); betaval.addActionListener(this); add(betaval); beta = Double.parseDouble(betaval.getText()); updatebeta(); undobutton = new Button("Undo Global Fit"); undobutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50, 100, 40); undobutton.addActionListener(this); add(undobutton); geterrorsbutton = new Button("Get Errors"); geterrorsbutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50 + 50, 100, 40); geterrorsbutton.addActionListener(this); add(geterrorsbutton); copylabel = new Label("copyright 2009 Jay Unruh ([email protected]) non-profit use only"); copylabel.setBounds(10, 790, 400, 20); add(copylabel); n_b_label = new Label("N and B Analysis"); n_b_label.setBounds(250, 10, 100, 20); add(n_b_label); pwavg = new PlotWindow3D("Avg", "kg", "kr", "Frequency", avg, 0); pwavg.setLogAxes(false, false, true); pwavg.draw(); pwavg.addPoints(avgfit, true, 0); float[] temp = pwavg.getLimits(); temp[4] = 1.0f; pwavg.setLimits(temp); float[][] temppch = new float[xpts][ypts]; for (int i = 0; i < xpts; i++) { System.arraycopy(pch[dispcurve][i], 0, temppch[i], 0, ypts); } pwfit = new PlotWindow3D("Selected Curve", "kg", "kr", "Frequency", temppch, 0); pwfit.setLogAxes(false, false, true); pwfit.draw(); pwfit.addPoints(fit[dispcurve], true, 0); float[] temp2 = pwfit.getLimits(); temp2[4] = 1.0f; pwfit.setLimits(temp2); resetparams(); repaint(); }