예제 #1
0
 /** @see net.rptools.maptool.client.ui.token.BooleanTokenOverlay#clone() */
 @Override
 public Object clone() {
   BooleanTokenOverlay overlay = new XTokenOverlay(getName(), getColor(), getWidth());
   overlay.setOrder(getOrder());
   overlay.setGroup(getGroup());
   overlay.setMouseover(isMouseover());
   overlay.setOpacity(getOpacity());
   overlay.setShowGM(isShowGM());
   overlay.setShowOwner(isShowOwner());
   overlay.setShowOthers(isShowOthers());
   return overlay;
 }
  private void updateStatesPanel() {
    // Group the states first into individual panels
    List<BooleanTokenOverlay> overlays =
        new ArrayList<BooleanTokenOverlay>(TabletopTool.getCampaign().getTokenStatesMap().values());
    Map<String, JPanel> groups = new TreeMap<String, JPanel>();
    groups.put("", new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow")));
    for (BooleanTokenOverlay overlay : overlays) {
      String group = overlay.getGroup();
      if (group != null && (group = group.trim()).length() != 0) {
        JPanel panel = groups.get(group);
        if (panel == null) {
          panel = new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow"));
          panel.setBorder(BorderFactory.createTitledBorder(group));
          groups.put(group, panel);
        }
      }
    }
    // Add the group panels and bar panel to the states panel
    JPanel panel = getStatesPanel();
    panel.removeAll();
    FormLayout layout = new FormLayout("0px:grow");
    panel.setLayout(layout);
    int row = 1;
    for (JPanel gPanel : groups.values()) {
      layout.appendRow(new RowSpec("pref"));
      layout.appendRow(new RowSpec("2px"));
      panel.add(gPanel, new CellConstraints(1, row));
      row += 2;
    }
    layout.appendRow(new RowSpec("pref"));
    layout.appendRow(new RowSpec("2px"));
    JPanel barPanel = new JPanel(new FormLayout("right:pref 2px pref 5px right:pref 2px pref"));
    panel.add(barPanel, new CellConstraints(1, row));

    // Add the individual check boxes.
    for (BooleanTokenOverlay state : overlays) {
      String group = state.getGroup();
      panel = groups.get("");
      if (group != null && (group = group.trim()).length() != 0) panel = groups.get(group);
      int x = panel.getComponentCount() % 4;
      int y = panel.getComponentCount() / 4;
      if (x == 0) {
        layout = (FormLayout) panel.getLayout();
        if (y != 0) layout.appendRow(new RowSpec("2px"));
        layout.appendRow(new RowSpec("pref"));
      }
      panel.add(new JCheckBox(state.getName()), new CellConstraints(x * 2 + 1, y * 2 + 1));
    }
    // Add sliders to the bar panel
    if (TabletopTool.getCampaign().getTokenBarsMap().size() > 0) {
      layout = (FormLayout) barPanel.getLayout();
      barPanel.setName("bar");
      barPanel.setBorder(BorderFactory.createTitledBorder("Bars"));
      int count = 0;
      row = 0;
      for (BarTokenOverlay bar : TabletopTool.getCampaign().getTokenBarsMap().values()) {
        int working = count % 2;
        if (working == 0) { // slider row
          layout.appendRow(new RowSpec("pref"));
          row += 1;
        }
        JPanel labelPanel = new JPanel(new FormLayout("pref", "pref 2px:grow pref"));
        barPanel.add(labelPanel, new CellConstraints(1 + working * 4, row));
        labelPanel.add(
            new JLabel(bar.getName() + ":"),
            new CellConstraints(1, 1, CellConstraints.RIGHT, CellConstraints.TOP));
        JSlider slider = new JSlider(0, 100);
        JCheckBox hide = new JCheckBox("Hide");
        hide.putClientProperty("JSlider", slider);
        hide.addChangeListener(
            new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent e) {
                JSlider js = (JSlider) ((JCheckBox) e.getSource()).getClientProperty("JSlider");
                js.setEnabled(!((JCheckBox) e.getSource()).isSelected());
              }
            });
        labelPanel.add(hide, new CellConstraints(1, 3, CellConstraints.RIGHT, CellConstraints.TOP));
        slider.setName(bar.getName());
        slider.setPaintLabels(true);
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(20);
        slider.createStandardLabels(20);
        slider.setMajorTickSpacing(10);
        barPanel.add(slider, new CellConstraints(3 + working * 4, row));
        if (working != 0) { // spacer row
          layout.appendRow(new RowSpec("2px"));
          row += 1;
        }
        count += 1;
      }
    }
  }