Beispiel #1
0
  void initialize() {
    int start, end;

    TextField txt = (TextField) target;

    setText(txt.getText());
    if (txt.echoCharIsSet()) {
      setEchoChar(txt.getEchoChar());
    }

    start = txt.getSelectionStart();
    end = txt.getSelectionEnd();

    if (end > start) {
      select(start, end);
    } else {
      setCaretPosition(start);
    }

    if (!target.isBackgroundSet()) {
      // This is a way to set the background color of the TextArea
      // without calling setBackground - go through native C code
      setTargetBackground(SystemColor.text);
    }
    if (!target.isForegroundSet()) {
      target.setForeground(SystemColor.textText);
    }

    setEditable(txt.isEditable());

    //	oldSelectionStart = -1; // accessibility support
    //	oldSelectionEnd = -1;	// accessibility support

    super.initialize();
  }
Beispiel #2
0
 int pos2x(int pos) {
   TextField txt = (TextField) target;
   FontMetrics fm = getFontMetrics(txt.getFont());
   int x = MARGIN, widths[] = fm.getWidths();
   String text = txt.getText();
   char echoChar = txt.getEchoChar();
   if (echoChar == 0) {
     for (int i = 0; i < pos; i++) {
       x += widths[text.charAt(i)];
     }
   } else {
     x += widths[echoChar] * pos;
   }
   return x;
 }
 public void actionPerformed(ActionEvent e) {
   beta = Double.parseDouble(betaval.getText());
   updatebeta();
   if (e.getSource() == fitavgbutton) {
     fitavg();
   }
   if (e.getSource() == fitglobalbutton) {
     fitglobal();
   }
   if (e.getSource() == clearparamsbutton) {
     resetparams();
   }
   if (e.getSource() == undobutton) {
     undoglobalfit();
   }
   if (e.getSource() == geterrorsbutton) {
     geterrors();
   }
 }
 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();
  }
Beispiel #6
0
  public void print(Graphics g) {
    TextField txt = (TextField) target;
    Dimension d = txt.size();
    int w = d.width - (2 * BORDER);
    int h = d.height - (2 * BORDER);
    Color bg = txt.getBackground();
    Color fg = txt.getForeground();
    Color highlight = bg.brighter();
    String text = txt.getText();
    int moved = 0;
    int selStart = 0;
    int selEnd = 0;

    g.setFont(txt.getFont());
    g.setColor(txt.isEditable() ? highlight : bg);
    g.fillRect(BORDER, BORDER, w, h);

    g.setColor(bg);
    // g.drawRect(0, 0, d.width-1, d.height-1);
    draw3DRect(g, bg, 1, 1, d.width - 3, d.height - 3, false);

    if (text != null) {
      g.clipRect(BORDER, MARGIN, w, d.height - (2 * MARGIN));
      FontMetrics fm = g.getFontMetrics();

      w = d.width - BORDER;
      h = d.height - (2 * MARGIN);
      int xs = pos2x(selStart) - moved;
      int xe = pos2x(selEnd) - moved;

      if ((xs < MARGIN) && (xe > w)) {
        g.setColor(highlight);
        g.fillRect(BORDER, MARGIN, w - BORDER, h);
      } else {
        g.setColor(bg);
        // g.fillRect(BORDER, MARGIN, w - BORDER, h);

        if ((xs >= MARGIN) && (xs <= w)) {
          g.setColor(highlight); // selected text

          if (xe > w) {
            g.fillRect(xs, MARGIN, w - xs, h);
          } else if (xs == xe) {
            // g.fillRect(xs, MARGIN, 1, h);
          } else {
            g.fillRect(xs, MARGIN, xe - xs, h);
          }
        } else if ((xe >= MARGIN) && (xe <= w)) {
          g.setColor(highlight);
          g.fillRect(BORDER, MARGIN, xe - BORDER, h);
        }
      }
      g.setColor(fg);
      int x = MARGIN - moved;
      char echoChar = txt.getEchoChar();
      if (echoChar == 0) {
        g.drawString(text, x, BORDER + MARGIN + fm.getMaxAscent());
      } else {
        char data[] = new char[text.length()];
        for (int i = 0; i < data.length; i++) {
          data[i] = echoChar;
        }
        g.drawChars(data, 0, data.length, x, BORDER + MARGIN + fm.getMaxAscent());
      }
    }

    target.print(g);
  }