コード例 #1
0
  private void updateSelections() {
    /* Use set intersection/join's to figure out what updates
    have been done */

    /* First, find which temporary bonuses have been removed,
    and which have been added */
    Set<String> newValues = pc.getTempBonusNames();
    Set<String> oldValues = new TreeSet<String>(tempBonusWidgets.keySet());
    oldValues.removeAll(newValues);
    newValues.removeAll(tempBonusWidgets.keySet());

    if (!newValues.isEmpty()) {
      addTempBonus(newValues);
    }
    if (!oldValues.isEmpty()) {
      removeTempBonus(oldValues);
    }

    /* Now, same for equipment sets. */
    newValues.clear();
    oldValues.clear();

    newValues.addAll(equipSet2Set(pc.getEquipSet()));
    oldValues.addAll(eqSetWidgets.keySet());

    oldValues.removeAll(newValues);
    newValues.removeAll(eqSetWidgets.keySet());
    if (!newValues.isEmpty()) {
      addEquipSets(newValues);
    }
    if (!oldValues.isEmpty()) {
      removeEquipSets(oldValues);
    }
  }
コード例 #2
0
  private void addEquipSets(Set<String> eqSetIds) {
    /* just a temporary map to be able to lookup
    the name of an equipment set, given its ID */
    final Map<String, String> setId2Name = new HashMap<String, String>();

    for (EquipSet eset : pc.getEquipSet()) {
      setId2Name.put(eset.getIdPath(), eset.getName());
    }

    /* Create the buttons for the equipment sets. Note that we
    keep an internal reference to the buttons in a map, so that
    we can later remove them given an equipment set ID */
    for (String eqid : eqSetIds) {
      String setName = setId2Name.get(eqid);
      JRadioButton button = new JRadioButton(setName);
      button.setActionCommand(eqid);
      button.addActionListener(this);
      eqSets.add(button);
      eqSetPanel.add(button);
      eqSetWidgets.put(eqid, button);
    }
  }