Example #1
0
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      BuildableType item = (BuildableType) value;
      JPanel panel = isSelected ? selectedPanel : itemPanel;
      panel.removeAll();

      ((ImageIcon) imageLabel.getIcon())
          .setImage(ResourceManager.getImage(item.getId() + ".image", buildingDimension));

      nameLabel.setText(Messages.message(item.getNameKey()));
      panel.setToolTipText(lockReasons.get(item));
      panel.add(imageLabel, "span 1 2");
      if (lockReasons.get(item) == null) {
        panel.add(nameLabel, "wrap");
      } else {
        panel.add(nameLabel, "split 2");
        panel.add(lockLabel, "wrap");
      }

      List<AbstractGoods> required = item.getRequiredGoods();
      int size = required.size();
      for (int i = 0; i < size; i++) {
        AbstractGoods goods = required.get(i);
        ImageIcon icon =
            new ImageIcon(ResourceManager.getImage(goods.getType().getId() + ".image", 0.66));
        JLabel goodsLabel =
            new JLabel(Integer.toString(goods.getAmount()), icon, SwingConstants.CENTER);
        if (i == 0 && size > 1) {
          panel.add(goodsLabel, "split " + size);
        } else {
          panel.add(goodsLabel);
        }
      }
      return panel;
    }
Example #2
0
    @Override
    @SuppressWarnings({"deprecation", "unchecked"}) // FIXME in Java7
    public void mousePressed(MouseEvent e) {
      if (!enabled && e.getClickCount() == 1 && !e.isConsumed()) {
        enabled = true;
      }

      if (enabled) {
        JList source = (JList) e.getSource();
        if ((e.getButton() == MouseEvent.BUTTON3 || e.isPopupTrigger())) {
          int index = source.locationToIndex(e.getPoint());
          BuildableType type = (BuildableType) source.getModel().getElementAt(index);
          getGUI().showColopediaPanel(type.getId());
        } else if ((e.getClickCount() > 1 && !e.isConsumed())) {
          DefaultListModel model = (DefaultListModel) buildQueueList.getModel();
          if (source.getSelectedIndex() == -1) {
            source.setSelectedIndex(source.locationToIndex(e.getPoint()));
          }
          for (Object type : source.getSelectedValues()) {
            if (add) {
              model.addElement(type);
            } else {
              model.removeElement(type);
            }
          }
          updateAllLists();
        }
      }
    }
Example #3
0
  private void initialize(BuildableType buildable) {

    removeAll();

    if (buildable == null) {
      String clickToBuild = Messages.message(getDefaultLabel());
      int breakingPoint = Messages.getBreakingPoint(clickToBuild);
      if (breakingPoint > 0) {
        add(new JLabel(clickToBuild.substring(0, breakingPoint)), "span, align center");
        add(new JLabel(clickToBuild.substring(breakingPoint + 1)), "span, align center");
      } else {
        add(new JLabel(clickToBuild), "span, align center");
      }
    } else {
      int turnsToComplete = colony.getTurnsToComplete(buildable);
      String turnsStr = Messages.getTurnsText(turnsToComplete);
      add(
          new JLabel(new ImageIcon(ResourceManager.getImage(buildable.getId() + ".image", 0.75))),
          "spany");
      add(
          new JLabel(
              Messages.message(
                  StringTemplate.template("colonyPanel.currentlyBuilding")
                      .addName("%buildable%", buildable))));

      add(
          new JLabel(
              Messages.message(
                  StringTemplate.template("turnsToComplete.long").addName("%number%", turnsStr))));

      for (AbstractGoods requiredGoods : buildable.getGoodsRequired()) {
        int amountNeeded = requiredGoods.getAmount();
        int amountAvailable = colony.getGoodsCount(requiredGoods.getType());
        int amountProduced = colony.getAdjustedNetProductionOf(requiredGoods.getType());
        add(
            new FreeColProgressBar(
                gui, requiredGoods.getType(), 0, amountNeeded, amountAvailable, amountProduced),
            "height 20:");
      }
    }

    revalidate();
    repaint();
  }