Example #1
0
 /**
  * 新增視窗物件 設定物件屬性 內容
  *
  * @param o 物件instances
  * @param reg 物件位置
  * @param name 物件名稱
  * @param value 物件標籤 或 內容
  */
 protected void addObject(Object o, Rectangle reg, String name, String value) {
   if (o instanceof Label) {
     ((Label) o).setText(value);
     ((Label) o).setName(name);
     ((Label) o).setBounds(reg);
     ((Label) o).addMouseListener(this);
     this.add((Label) o);
   } else if (o instanceof TextField) {
     ((TextField) o).setText(value);
     ((TextField) o).setName(name);
     ((TextField) o).setBounds(reg);
     ((TextField) o).addMouseListener(this);
     ((TextField) o).addTextListener(this);
     ((TextField) o).addKeyListener(this);
     if (value.equalsIgnoreCase("password")) ((TextField) o).setEchoChar('*');
     this.add((TextField) o);
   } else if (o instanceof Button) {
     int len = (int) ((float) reg.width / FONTWIDTH);
     ((Button) o).setLabel(StringUtil_.splitStringSpace(value, len));
     ((Button) o).setName(name);
     ((Button) o).setBounds(reg);
     ((Button) o).addMouseListener(this);
     this.add((Button) o);
   } else if (o instanceof TextArea) {
     ((TextArea) o).setText(value);
     ((TextArea) o).setName(name);
     ((TextArea) o).setBounds(reg);
     ((TextArea) o).addMouseListener(this);
     ((TextArea) o).addTextListener(this);
     ((TextArea) o).addKeyListener(this);
     this.add((TextArea) o);
   } else if (o instanceof Choice) {
     String[] values = value.split(",");
     for (int ii = 0; ii < values.length; ii++) ((Choice) o).addItem(values[ii]);
     ((Choice) o).setName(name);
     ((Choice) o).setBounds(reg);
     ((Choice) o).addMouseListener(this);
     ((Choice) o).addItemListener(this);
     this.add((Choice) o);
   } else if (o instanceof Checkbox) {
     ((Checkbox) o).setLabel(value);
     ((Checkbox) o).setName(name);
     ((Checkbox) o).setBounds(reg);
     ((Checkbox) o).addMouseListener(this);
     ((Checkbox) o).addItemListener(this);
     this.add((Checkbox) o);
   } else if (o instanceof CheckboxGroup) {
     String[] values = value.split(",");
     for (int ii = 0; ii < values.length; ii++) {
       Checkbox chk = new Checkbox();
       chk.setLabel(values[ii]);
       chk.setName(name + ii);
       chk.setBounds(reg);
       reg.y += 25;
       chk.addMouseListener(this);
       chk.addItemListener(this);
       chk.setCheckboxGroup((CheckboxGroup) o);
       this.add(chk);
     }
   } else if (o instanceof List) {
     String[] values = value.split(",");
     ((List) o).setName(name);
     ((List) o).setBounds(reg);
     ((List) o).addMouseListener(this);
     ((List) o).addItemListener(this);
     for (int ii = 0; ii < values.length; ii++) ((List) o).add(values[ii]);
     this.add(((List) o));
   }
 }
Example #2
0
  /** Fancies up the importer dialog to look much nicer. */
  private void rebuildDialog(GenericDialog gd) {
    // extract GUI components from dialog and add listeners
    List<Checkbox> boxes = null;
    List<Choice> choices = null;
    List<Label> labels = null;
    Label colorModeLabel = null;
    Label stackFormatLabel = null;
    Label stackOrderLabel = null;
    Component[] c = gd.getComponents();
    if (c != null) {
      boxes = new ArrayList<Checkbox>();
      choices = new ArrayList<Choice>();
      labels = new ArrayList<Label>();
      for (int i = 0; i < c.length; i++) {
        if (c[i] instanceof Checkbox) {
          Checkbox item = (Checkbox) c[i];
          item.addFocusListener(this);
          item.addItemListener(this);
          item.addMouseListener(this);
          boxes.add(item);
        } else if (c[i] instanceof Choice) {
          Choice item = (Choice) c[i];
          item.addFocusListener(this);
          item.addItemListener(this);
          item.addMouseListener(this);
          choices.add(item);
        } else if (c[i] instanceof Label) labels.add((Label) c[i]);
      }
      int boxIndex = 0, choiceIndex = 0, labelIndex = 0;
      autoscaleBox = boxes.get(boxIndex++);
      colorModeChoice = choices.get(choiceIndex++);
      colorModeLabel = labels.get(labelIndex++);
      concatenateBox = boxes.get(boxIndex++);
      cropBox = boxes.get(boxIndex++);
      groupFilesBox = boxes.get(boxIndex++);
      ungroupFilesBox = boxes.get(boxIndex++);
      openAllSeriesBox = boxes.get(boxIndex++);
      boxIndex++; // quiet
      // recordBox         = boxes.get(boxIndex++);
      showMetadataBox = boxes.get(boxIndex++);
      showOMEXMLBox = boxes.get(boxIndex++);
      showROIsBox = boxes.get(boxIndex++);
      specifyRangesBox = boxes.get(boxIndex++);
      splitZBox = boxes.get(boxIndex++);
      splitTBox = boxes.get(boxIndex++);
      splitCBox = boxes.get(boxIndex++);
      stackFormatChoice = choices.get(choiceIndex++);
      stackFormatLabel = labels.get(labelIndex++);
      stackOrderChoice = choices.get(choiceIndex++);
      stackOrderLabel = labels.get(labelIndex++);
      swapDimsBox = boxes.get(boxIndex++);
      virtualBox = boxes.get(boxIndex++);
      stitchTilesBox = boxes.get(boxIndex++);
    }
    verifyOptions(null);

    // TODO: The info table and focus logic could be split into
    // its own class, rather than being specific to this dialog.

    // associate information for each option
    infoTable = new HashMap<Component, String>();
    infoTable.put(autoscaleBox, options.getAutoscaleInfo());
    infoTable.put(colorModeChoice, options.getColorModeInfo());
    infoTable.put(colorModeLabel, options.getColorModeInfo());
    infoTable.put(concatenateBox, options.getConcatenateInfo());
    infoTable.put(cropBox, options.getCropInfo());
    infoTable.put(groupFilesBox, options.getGroupFilesInfo());
    infoTable.put(ungroupFilesBox, options.getUngroupFilesInfo());
    infoTable.put(openAllSeriesBox, options.getOpenAllSeriesInfo());
    // infoTable.put(recordBox, options.getRecordInfo());
    infoTable.put(showMetadataBox, options.getShowMetadataInfo());
    infoTable.put(showOMEXMLBox, options.getShowOMEXMLInfo());
    infoTable.put(showROIsBox, options.getShowROIsInfo());
    infoTable.put(specifyRangesBox, options.getSpecifyRangesInfo());
    infoTable.put(splitZBox, options.getSplitFocalPlanesInfo());
    infoTable.put(splitTBox, options.getSplitTimepointsInfo());
    infoTable.put(splitCBox, options.getSplitChannelsInfo());
    infoTable.put(stackFormatChoice, options.getStackFormatInfo());
    infoTable.put(stackFormatLabel, options.getStackFormatInfo());
    infoTable.put(stackOrderChoice, options.getStackOrderInfo());
    infoTable.put(stackOrderLabel, options.getStackOrderInfo());
    infoTable.put(swapDimsBox, options.getSwapDimensionsInfo());
    infoTable.put(virtualBox, options.getVirtualInfo());
    infoTable.put(stitchTilesBox, options.getStitchTilesInfo());

    // rebuild dialog using FormLayout to organize things more nicely

    String cols =
        // first column
        "pref, 3dlu, pref:grow, "
            +
            // second column
            "10dlu, pref, "
            +
            // third column
            "10dlu, fill:150dlu";

    String rows =
        // Stack viewing        | Metadata viewing
        "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, "
            +
            // Dataset organization | Memory management
            "9dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, "
            + "3dlu, pref, "
            +
            // Color options        | Split into separate windows
            "9dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref";

    // TODO: Change "Use virtual stack" and "Record modifications to virtual
    // stack" checkboxes to "Stack type" choice with options:
    //   "Normal", "Virtual" or "Smart virtual"

    PanelBuilder builder = new PanelBuilder(new FormLayout(cols, rows));
    CellConstraints cc = new CellConstraints();

    // populate 1st column
    int row = 1;
    builder.addSeparator("Stack viewing", cc.xyw(1, row, 3));
    row += 2;
    builder.add(stackFormatLabel, cc.xy(1, row));
    builder.add(stackFormatChoice, cc.xy(3, row));
    row += 2;
    builder.add(stackOrderLabel, cc.xy(1, row));
    builder.add(stackOrderChoice, cc.xy(3, row));
    row += 4;
    builder.addSeparator("Dataset organization", cc.xyw(1, row, 3));
    row += 2;
    builder.add(groupFilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(ungroupFilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(swapDimsBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(openAllSeriesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(concatenateBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.add(stitchTilesBox, xyw(cc, 1, row, 3));
    row += 2;
    builder.addSeparator("Color options", cc.xyw(1, row, 3));
    row += 2;
    builder.add(colorModeLabel, cc.xy(1, row));
    builder.add(colorModeChoice, cc.xy(3, row));
    row += 2;
    builder.add(autoscaleBox, xyw(cc, 1, row, 3));
    row += 2;

    // populate 2nd column
    row = 1;
    builder.addSeparator("Metadata viewing", cc.xy(5, row));
    row += 2;
    builder.add(showMetadataBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.add(showOMEXMLBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.add(showROIsBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.addSeparator("Memory management", cc.xy(5, row));
    row += 2;
    builder.add(virtualBox, xyw(cc, 5, row, 1));
    row += 2;
    // builder.add(recordBox, xyw(cc, 5, row, 1));
    // row += 2;
    builder.add(specifyRangesBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.add(cropBox, xyw(cc, 5, row, 1));
    row += 4;
    builder.addSeparator("Split into separate windows", cc.xy(5, row));
    row += 2;
    builder.add(splitCBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.add(splitZBox, xyw(cc, 5, row, 1));
    row += 2;
    builder.add(splitTBox, xyw(cc, 5, row, 1));
    // row += 4;

    // information section
    builder.addSeparator("Information", cc.xy(7, 1));
    // row += 2;
    infoPane = new JEditorPane();
    infoPane.setContentType("text/html");
    infoPane.setEditable(false);
    infoPane.setText("<html>" + INFO_DEFAULT);
    builder.add(new JScrollPane(infoPane), cc.xywh(7, 3, 1, row));
    // row += 2;

    gd.removeAll();
    gd.add(builder.getPanel());

    WindowTools.addScrollBars(gd);
    gd.setBackground(Color.white); // HACK: workaround for JPanel in a Dialog
  }