Пример #1
0
 /** Creates a colony with a university and n elder statesmen */
 private Colony getSchoolColony(int n, SchoolLevel slevel) {
   Colony colony = getStandardColony(n);
   for (Unit u : colony.getUnitList()) u.setType(elderStatesmanType);
   BuildingType type = null;
   switch (slevel) {
     case SCHOOLHOUSE:
       type = schoolType;
       break;
     case COLLEGE:
       type = collegeType;
       break;
     case UNIVERSITY:
       type = universityType;
       break;
     default:
       fail("Setup error, cannot setup school");
   }
   Building school = new ServerBuilding(colony.getGame(), colony, type);
   colony.addBuilding(school);
   assertEquals(school.getUnitList().size(), 0);
   colony.addGoods(grainType, 150); // prevent starving during tests
   return colony;
 }
Пример #2
0
  private void update() {

    List<GoodsType> selectedTypes = new ArrayList<GoodsType>();

    reportPanel.removeAll();

    reportPanel.add(selectLabel, "span, split " + (NUMBER_OF_GOODS + 2));

    for (int index = 0; index < NUMBER_OF_GOODS; index++) {
      reportPanel.add(boxes[index]);
      int selectedIndex = boxes[index].getSelectedIndex();
      if (selectedIndex > 0) {
        selectedTypes.add(goodsTypes.get(selectedIndex - 1));
      }
    }

    reportPanel.add(selectButton, "wrap 20");

    if (!selectedTypes.isEmpty()) {

      TypeCountMap<BuildingType> buildingCount = new TypeCountMap<BuildingType>();
      List<List<BuildingType>> basicBuildingTypes = new ArrayList<List<BuildingType>>();
      for (GoodsType goodsType : selectedTypes) {
        List<BuildingType> buildingTypes = new ArrayList<BuildingType>();
        for (BuildingType buildingType : getSpecification().getBuildingTypeList()) {
          if (goodsType.equals(buildingType.getProducedGoodsType())
              || !buildingType.getModifierSet(goodsType.getId()).isEmpty()) {
            BuildingType firstLevel = buildingType.getFirstLevel();
            if (!buildingTypes.contains(firstLevel)) {
              buildingTypes.add(firstLevel);
            }
          }
        }
        basicBuildingTypes.add(buildingTypes);
      }

      JLabel newLabel;

      // labels
      newLabel = new JLabel(Messages.message("Colony"));
      newLabel.setBorder(FreeColPanel.TOPLEFTCELLBORDER);
      reportPanel.add(newLabel, "newline 20");

      for (int index = 0; index < selectedTypes.size(); index++) {
        newLabel = localizedLabel(selectedTypes.get(index).getNameKey());
        newLabel.setBorder(FreeColPanel.TOPCELLBORDER);
        reportPanel.add(newLabel);

        for (BuildingType buildingType : basicBuildingTypes.get(index)) {
          newLabel = localizedLabel(buildingType.getNameKey());
          newLabel.setBorder(FreeColPanel.TOPCELLBORDER);
          reportPanel.add(newLabel);
        }
      }

      int[] totalProduction = new int[selectedTypes.size()];
      for (Colony colony : getFreeColClient().getMySortedColonies()) {
        // colonyButton
        JButton colonyButton = GUI.getLinkButton(colony.getName(), null, colony.getId());
        colonyButton.setBorder(FreeColPanel.LEFTCELLBORDER);
        colonyButton.addActionListener(this);
        reportPanel.add(colonyButton, "newline");

        // production
        for (int index = 0; index < selectedTypes.size(); index++) {
          GoodsType goodsType = selectedTypes.get(index);
          int newValue = colony.getNetProductionOf(goodsType);
          totalProduction[index] += newValue;
          Goods goods = new Goods(colony.getGame(), colony, goodsType, newValue);
          GoodsLabel goodsLabel = new GoodsLabel(goods, getGUI());
          goodsLabel.setHorizontalAlignment(JLabel.LEADING);
          goodsLabel.setBorder(FreeColPanel.CELLBORDER);
          reportPanel.add(goodsLabel);

          for (BuildingType buildingType : basicBuildingTypes.get(index)) {
            Building building = colony.getBuilding(buildingType);
            if (building == null) {
              newLabel = new JLabel();
              newLabel.setBorder(FreeColPanel.CELLBORDER);
              reportPanel.add(newLabel);
            } else {
              buildingCount.incrementCount(building.getType(), 1);
              BuildingPanel buildingPanel = new BuildingPanel(getFreeColClient(), building);
              buildingPanel.setBorder(FreeColPanel.CELLBORDER);
              buildingPanel.initialize();
              reportPanel.add(buildingPanel);
            }
          }
        }
      }
    }
    revalidate();
    repaint();
  }