Beispiel #1
0
 /**
  * This function analyses an event and calls the right methods to take care of the user's
  * requests.
  *
  * @param event The incoming ActionEvent.
  */
 @Override
 public void actionPerformed(ActionEvent event) {
   final String FAIL = "FAIL";
   if (colony.getOwner() == getMyPlayer()) {
     String command = event.getActionCommand();
     List<BuildableType> buildables = getBuildableTypes(buildQueueList);
     while (!buildables.isEmpty() && lockReasons.get(buildables.get(0)) != null) {
       getGUI()
           .showInformationMessage(
               buildables.get(0),
               StringTemplate.template("colonyPanel.unbuildable")
                   .addName("%colony%", colony.getName())
                   .add("%object%", buildables.get(0).getNameKey()));
       command = FAIL;
       removeBuildable(buildables.remove(0));
     }
     getController().setBuildQueue(colony, buildables);
     if (FAIL.equals(command)) { // Let the user reconsider.
       updateAllLists();
       return;
     } else if (OK.equals(command)) {
       // do nothing?
     } else if (BUY.equals(command)) {
       getController().payForBuilding(colony);
     } else {
       logger.warning("Unsupported command " + command);
     }
   }
   getGUI().removeFromCanvas(this);
 }
 /** {@inheritDoc} */
 @Override
 public Component getListCellRendererComponent(
     JList<? extends TradeRouteStop> list,
     TradeRouteStop value,
     int index,
     boolean isSelected,
     boolean hasFocus) {
   JPanel panel = (isSelected) ? SELECTED_COMPONENT : NORMAL_COMPONENT;
   panel.removeAll();
   panel.setForeground(list.getForeground());
   panel.setFont(list.getFont());
   Location location = value.getLocation();
   ImageLibrary lib = getImageLibrary();
   JLabel icon, name;
   if (location instanceof Europe) {
     Europe europe = (Europe) location;
     Image image = lib.getSmallerMiscIconImage(europe.getOwner().getNation());
     icon = new JLabel(new ImageIcon(image));
     name = Utility.localizedLabel(europe);
   } else if (location instanceof Colony) {
     Colony colony = (Colony) location;
     icon =
         new JLabel(
             new ImageIcon(
                 ImageLibrary.getSettlementImage(colony, lib.getScaleFactor() * 0.5f)));
     name = new JLabel(colony.getName());
   } else {
     throw new IllegalStateException("Bogus location: " + location);
   }
   panel.add(icon, "spany");
   panel.add(name, "span, wrap");
   for (GoodsType cargo : value.getCargo()) {
     panel.add(new JLabel(new ImageIcon(lib.getSmallerIconImage(cargo))));
   }
   return panel;
 }
  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();
  }