Beispiel #1
0
 /**
  * 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);
     defaultChoiceIndexes = 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]);
   if (defaultItem != null) thisChoice.select(defaultItem);
   else thisChoice.select(0);
   c.gridx = 1;
   c.gridy = y;
   c.anchor = GridBagConstraints.WEST;
   grid.setConstraints(thisChoice, c);
   add(thisChoice);
   choice.addElement(thisChoice);
   int index = thisChoice.getSelectedIndex();
   defaultChoiceIndexes.addElement(new Integer(index));
   if (Recorder.record || macro) saveLabel(thisChoice, label);
   y++;
 }
Beispiel #2
0
 /**
  * Adds a numeric field. The first word of the label must be unique or command recording will not
  * work.
  *
  * @param label the label
  * @param defaultValue value to be initially displayed
  * @param digits number of digits to right of decimal point
  * @param columns width of field in characters
  * @param units a string displayed to the right of the field
  */
 public void addNumericField(
     String label, double defaultValue, int digits, int columns, String units) {
   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 (firstNumericField) c.insets = getInsets(5, 0, 3, 0);
   else c.insets = getInsets(0, 0, 3, 0);
   grid.setConstraints(theLabel, c);
   add(theLabel);
   if (numberField == null) {
     numberField = new Vector(5);
     defaultValues = new Vector(5);
     defaultText = new Vector(5);
   }
   if (IJ.isWindows()) columns -= 2;
   if (columns < 1) columns = 1;
   String defaultString = IJ.d2s(defaultValue, digits);
   if (Double.isNaN(defaultValue)) defaultString = "";
   TextField tf = new TextField(defaultString, columns);
   if (IJ.isLinux()) tf.setBackground(Color.white);
   tf.addActionListener(this);
   tf.addTextListener(this);
   tf.addFocusListener(this);
   tf.addKeyListener(this);
   numberField.addElement(tf);
   defaultValues.addElement(new Double(defaultValue));
   defaultText.addElement(tf.getText());
   c.gridx = 1;
   c.gridy = y;
   c.anchor = GridBagConstraints.WEST;
   tf.setEditable(true);
   // if (firstNumericField) tf.selectAll();
   firstNumericField = false;
   if (units == null || units.equals("")) {
     grid.setConstraints(tf, c);
     add(tf);
   } else {
     Panel panel = new Panel();
     panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
     panel.add(tf);
     panel.add(new Label(" " + units));
     grid.setConstraints(panel, c);
     add(panel);
   }
   if (Recorder.record || macro) saveLabel(tf, label);
   y++;
 }
Beispiel #3
0
 /**
  * Adds a radio button group.
  *
  * @param label group label (or null)
  * @param items radio button labels
  * @param rows number of rows
  * @param columns number of columns
  * @param defaultItem button initially selected
  */
 public void addRadioButtonGroup(
     String label, String[] items, int rows, int columns, String defaultItem) {
   Panel panel = new Panel();
   int n = items.length;
   panel.setLayout(new GridLayout(rows, columns, 0, 0));
   CheckboxGroup cg = new CheckboxGroup();
   for (int i = 0; i < n; i++) {
     Checkbox cb = new Checkbox(items[i], cg, items[i].equals(defaultItem));
     cb.addItemListener(this);
     panel.add(cb);
   }
   if (radioButtonGroups == null) radioButtonGroups = new Vector();
   radioButtonGroups.addElement(cg);
   Insets insets = getInsets(5, 10, 0, 0);
   if (label == null || label.equals("")) {
     label = "rbg" + radioButtonGroups.size();
     insets.top += 5;
   } else {
     setInsets(10, insets.left, 0);
     addMessage(label);
     insets.top = 2;
     insets.left += 10;
   }
   c.gridx = 0;
   c.gridy = y;
   c.gridwidth = 2;
   c.anchor = GridBagConstraints.WEST;
   c.insets = new Insets(insets.top, insets.left, 0, 0);
   grid.setConstraints(panel, c);
   add(panel);
   if (Recorder.record || macro) saveLabel(cg, label);
   y++;
 }
Beispiel #4
0
 /**
  * Adds a group of checkboxs using a grid layout.
  *
  * @param rows the number of rows
  * @param columns the number of columns
  * @param labels the labels
  * @param defaultValues the initial states
  * @param headings the column headings Example:
  *     http://imagej.nih.gov/ij/plugins/multi-column-dialog/index.html
  */
 public void addCheckboxGroup(
     int rows, int columns, String[] labels, boolean[] defaultValues, String[] headings) {
   Panel panel = new Panel();
   int nRows = headings != null ? rows + 1 : rows;
   panel.setLayout(new GridLayout(nRows, columns, 6, 0));
   int startCBIndex = cbIndex;
   if (checkbox == null) checkbox = new Vector(12);
   if (headings != null) {
     Font font = new Font("SansSerif", Font.BOLD, 12);
     for (int i = 0; i < columns; i++) {
       if (i > headings.length - 1 || headings[i] == null) panel.add(new Label(""));
       else {
         Label label = new Label(headings[i]);
         label.setFont(font);
         panel.add(label);
       }
     }
   }
   int i1 = 0;
   int[] index = new int[labels.length];
   for (int row = 0; row < rows; row++) {
     for (int col = 0; col < columns; col++) {
       int i2 = col * rows + row;
       if (i2 >= labels.length) break;
       index[i1] = i2;
       String label = labels[i1];
       if (label == null || label.length() == 0) {
         Label lbl = new Label("");
         panel.add(lbl);
         i1++;
         continue;
       }
       if (label.indexOf('_') != -1) label = label.replace('_', ' ');
       Checkbox cb = new Checkbox(label);
       checkbox.addElement(cb);
       cb.setState(defaultValues[i1]);
       cb.addItemListener(this);
       if (Recorder.record || macro) saveLabel(cb, labels[i1]);
       if (IJ.isLinux()) {
         Panel panel2 = new Panel();
         panel2.setLayout(new BorderLayout());
         panel2.add("West", cb);
         panel.add(panel2);
       } else panel.add(cb);
       i1++;
     }
   }
   c.gridx = 0;
   c.gridy = y;
   c.gridwidth = 2;
   c.anchor = GridBagConstraints.WEST;
   c.insets = getInsets(10, 0, 0, 0);
   grid.setConstraints(panel, c);
   add(panel);
   y++;
 }
Beispiel #5
0
 /**
  * Adds a text field.
  *
  * @param label the label
  * @param defaultText text initially displayed
  * @param columns width of the text field
  */
 public void addStringField(String label, String defaultText, int columns) {
   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;
   boolean custom = customInsets;
   if (stringField == null) {
     stringField = new Vector(4);
     defaultStrings = new Vector(4);
     c.insets = getInsets(5, 0, 5, 0);
   } else c.insets = getInsets(0, 0, 5, 0);
   grid.setConstraints(theLabel, c);
   add(theLabel);
   if (custom) {
     if (stringField.size() == 0) c.insets = getInsets(5, 0, 5, 0);
     else c.insets = getInsets(0, 0, 5, 0);
   }
   TextField tf = new TextField(defaultText, columns);
   if (IJ.isLinux()) tf.setBackground(Color.white);
   tf.setEchoChar(echoChar);
   echoChar = 0;
   tf.addActionListener(this);
   tf.addTextListener(this);
   tf.addFocusListener(this);
   tf.addKeyListener(this);
   c.gridx = 1;
   c.gridy = y;
   c.anchor = GridBagConstraints.WEST;
   grid.setConstraints(tf, c);
   tf.setEditable(true);
   add(tf);
   stringField.addElement(tf);
   defaultStrings.addElement(defaultText);
   if (Recorder.record || macro) saveLabel(tf, label);
   y++;
 }
Beispiel #6
0
 String[] openUrlAsList(String address) {
   Vector v = new Vector();
   try {
     URL url = new URL(address);
     InputStream in = url.openStream();
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
     String line;
     while (true) {
       line = br.readLine();
       if (line == null) break;
       if (!line.equals("")) v.addElement(line);
     }
     br.close();
   } catch (Exception e) {
   }
   String[] lines = new String[v.size()];
   v.copyInto((String[]) lines);
   return lines;
 }
Beispiel #7
0
 /**
  * Adds a checkbox; does not make it recordable if isPreview is true. With isPreview true, the
  * checkbox can be referred to as previewCheckbox from hereon.
  */
 private void addCheckbox(String label, boolean defaultValue, boolean isPreview) {
   String label2 = label;
   if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' ');
   if (checkbox == null) {
     checkbox = new Vector(4);
     c.insets = getInsets(15, 20, 0, 0);
   } else c.insets = getInsets(0, 20, 0, 0);
   c.gridx = 0;
   c.gridy = y;
   c.gridwidth = 2;
   c.anchor = GridBagConstraints.WEST;
   Checkbox cb = new Checkbox(label2);
   grid.setConstraints(cb, c);
   cb.setState(defaultValue);
   cb.addItemListener(this);
   cb.addKeyListener(this);
   add(cb);
   checkbox.addElement(cb);
   // ij.IJ.write("addCheckbox: "+ y+" "+cbIndex);
   if (!isPreview && (Recorder.record || macro)) // preview checkbox is not recordable
   saveLabel(cb, label);
   if (isPreview) previewCheckbox = cb;
   y++;
 }
Beispiel #8
0
 /**
  * Add an Object implementing the DialogListener interface. This object will be notified by its
  * dialogItemChanged method of input to the dialog. The first DialogListener will be also called
  * after the user has typed 'OK' or if the dialog has been invoked by a macro; it should read all
  * input fields of the dialog. For other listeners, the OK button will not cause a call to
  * dialogItemChanged; the CANCEL button will never cause such a call.
  *
  * @param dl the Object that wants to listen.
  */
 public void addDialogListener(DialogListener dl) {
   if (dialogListeners == null) dialogListeners = new Vector();
   dialogListeners.addElement(dl);
   if (IJ.debugMode) IJ.log("GenericDialog: Listener added: " + dl);
 }
Beispiel #9
0
  /**
   * Adds a slider (scroll bar) to the dialog box. Floating point values will be used if
   * (maxValue-minValue)<=5.0 and either minValue or maxValue are non-integer.
   *
   * @param label the label
   * @param minValue the minimum value of the slider
   * @param maxValue the maximum value of the slider
   * @param defaultValue the initial value of the slider
   */
  public void addSlider(String label, double minValue, double maxValue, double defaultValue) {
    if (defaultValue < minValue) defaultValue = minValue;
    if (defaultValue > maxValue) defaultValue = maxValue;
    int columns = 4;
    int digits = 0;
    double scale = 1.0;
    if ((maxValue - minValue) <= 5.0
        && (minValue != (int) minValue
            || maxValue != (int) maxValue
            || defaultValue != (int) defaultValue)) {
      scale = 20.0;
      minValue *= scale;
      maxValue *= scale;
      defaultValue *= scale;
      digits = 2;
    }
    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;
    c.insets = new Insets(0, 0, 3, 0);
    grid.setConstraints(theLabel, c);
    add(theLabel);

    if (slider == null) {
      slider = new Vector(5);
      sliderIndexes = new int[MAX_SLIDERS];
      sliderScales = new double[MAX_SLIDERS];
    }
    Scrollbar s =
        new Scrollbar(
            Scrollbar.HORIZONTAL, (int) defaultValue, 1, (int) minValue, (int) maxValue + 1);
    GUI.fix(s);
    slider.addElement(s);
    s.addAdjustmentListener(this);
    s.setUnitIncrement(1);

    if (numberField == null) {
      numberField = new Vector(5);
      defaultValues = new Vector(5);
      defaultText = new Vector(5);
    }
    if (IJ.isWindows()) columns -= 2;
    if (columns < 1) columns = 1;
    TextField tf = new TextField(IJ.d2s(defaultValue / scale, digits), columns);
    if (IJ.isLinux()) tf.setBackground(Color.white);
    tf.addActionListener(this);
    tf.addTextListener(this);
    tf.addFocusListener(this);
    tf.addKeyListener(this);
    numberField.addElement(tf);
    sliderIndexes[slider.size() - 1] = numberField.size() - 1;
    sliderScales[slider.size() - 1] = scale;
    defaultValues.addElement(new Double(defaultValue / scale));
    defaultText.addElement(tf.getText());
    tf.setEditable(true);
    firstSlider = false;

    Panel panel = new Panel();
    GridBagLayout pgrid = new GridBagLayout();
    GridBagConstraints pc = new GridBagConstraints();
    panel.setLayout(pgrid);
    pc.gridx = 0;
    pc.gridy = 0;
    pc.gridwidth = 1;
    pc.ipadx = 85;
    pc.anchor = GridBagConstraints.WEST;
    pgrid.setConstraints(s, pc);
    panel.add(s);
    pc.ipadx = 0; // reset
    // text field
    pc.gridx = 1;
    pc.insets = new Insets(5, 5, 0, 0);
    pc.anchor = GridBagConstraints.EAST;
    pgrid.setConstraints(tf, pc);
    panel.add(tf);

    grid.setConstraints(panel, c);
    c.gridx = 1;
    c.gridy = y;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 0, 0, 0);
    grid.setConstraints(panel, c);
    add(panel);
    y++;
    if (Recorder.record || macro) saveLabel(tf, label);
  }