예제 #1
0
 private void updateAllLists() {
   DefaultListModel current = (DefaultListModel) buildQueueList.getModel();
   featureContainer = new FeatureContainer();
   for (Object type : current.toArray()) {
     if (getMinimumIndex((BuildableType) type) >= 0) {
       FeatureContainer.addFeatures(featureContainer, (BuildableType) type);
     } else {
       current.removeElement(type);
     }
   }
   // ATTENTION: buildings must be updated first, since units
   // might depend on the build ability of an unbuildable
   // building
   updateBuildingList();
   updateUnitList();
   updateBuyBuildingButton();
   // work-around to re-initialize construction panel
   PropertyChangeEvent event =
       new PropertyChangeEvent(
           colony, ConstructionPanel.EVENT, null, getBuildableTypes(buildQueueList));
   constructionPanel.propertyChange(event);
 }
예제 #2
0
  @SuppressWarnings("unchecked") // FIXME in Java7
  public BuildQueuePanel(FreeColClient freeColClient, GUI gui, Colony colony) {

    super(
        freeColClient,
        gui,
        new MigLayout("wrap 3", "[260:][390:, fill][260:]", "[][][300:400:][]"));
    this.colony = colony;
    this.unitCount = colony.getUnitCount();
    featureContainer = new FeatureContainer();

    for (UnitType unitType : getSpecification().getUnitTypeList()) {
      if (unitType.needsGoodsToBuild() && !unitType.hasAbility(Ability.BORN_IN_COLONY)) {
        buildableUnits.add(unitType); // can be built
      }
    }

    DefaultListModel current = new DefaultListModel();
    for (BuildableType type : colony.getBuildQueue()) {
      current.addElement(type);
      FeatureContainer.addFeatures(featureContainer, type);
    }

    cellRenderer = getCellRenderer();

    // remove previous listeners
    for (ItemListener listener : compact.getItemListeners()) {
      compact.removeItemListener(listener);
    }
    compact.setText(Messages.message("colonyPanel.compactView"));
    compact.addItemListener(this);

    // remove previous listeners
    for (ItemListener listener : showAll.getItemListeners()) {
      showAll.removeItemListener(listener);
    }
    showAll.setText(Messages.message("colonyPanel.showAll"));
    showAll.addItemListener(this);

    buildQueueList = new JList(current);
    buildQueueList.setTransferHandler(buildQueueHandler);
    buildQueueList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    buildQueueList.setDragEnabled(true);
    buildQueueList.setCellRenderer(cellRenderer);
    buildQueueList.addMouseListener(new BuildQueueMouseAdapter(false));

    Action deleteAction =
        new AbstractAction() {
          @SuppressWarnings("deprecation") // FIXME in Java7
          public void actionPerformed(ActionEvent e) {
            for (Object type : buildQueueList.getSelectedValues()) {
              removeBuildable(type);
            }
            updateAllLists();
          }
        };

    buildQueueList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "delete");
    buildQueueList.getActionMap().put("delete", deleteAction);

    Action addAction =
        new AbstractAction() {
          @SuppressWarnings("deprecation") // FIXME in Java7
          public void actionPerformed(ActionEvent e) {
            DefaultListModel model = (DefaultListModel) buildQueueList.getModel();
            for (Object type : ((JList) e.getSource()).getSelectedValues()) {
              model.addElement(type);
            }
            updateAllLists();
          }
        };

    BuildQueueMouseAdapter adapter = new BuildQueueMouseAdapter(true);
    DefaultListModel units = new DefaultListModel();
    unitList = new JList(units);
    unitList.setTransferHandler(buildQueueHandler);
    unitList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    unitList.setDragEnabled(true);
    unitList.setCellRenderer(cellRenderer);
    unitList.addMouseListener(adapter);

    unitList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "add");
    unitList.getActionMap().put("add", addAction);

    DefaultListModel buildings = new DefaultListModel();
    buildingList = new JList(buildings);
    buildingList.setTransferHandler(buildQueueHandler);
    buildingList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    buildingList.setDragEnabled(true);
    buildingList.setCellRenderer(cellRenderer);
    buildingList.addMouseListener(adapter);

    buildingList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "add");
    buildingList.getActionMap().put("add", addAction);

    JLabel headLine = new JLabel(Messages.message("colonyPanel.buildQueue"));
    headLine.setFont(bigHeaderFont);

    buyBuilding = new JButton(Messages.message("colonyPanel.buyBuilding"));
    buyBuilding.setActionCommand(BUY);
    buyBuilding.addActionListener(this);

    constructionPanel = new ConstructionPanel(gui, colony, false);
    constructionPanel.setOpaque(false);
    StringTemplate buildingNothing =
        StringTemplate.template("colonyPanel.currentlyBuilding").add("%buildable%", "nothing");
    constructionPanel.setDefaultLabel(buildingNothing);

    updateAllLists();

    add(headLine, "span 3, align center, wrap 40");
    add(new JLabel(Messages.message("colonyPanel.units")), "align center");
    add(new JLabel(Messages.message("colonyPanel.buildQueue")), "align center");
    add(new JLabel(Messages.message("colonyPanel.buildings")), "align center");
    add(new JScrollPane(unitList), "grow");
    add(constructionPanel, "split 2, flowy");
    add(new JScrollPane(buildQueueList), "grow");
    add(new JScrollPane(buildingList), "grow, wrap 20");
    add(buyBuilding, "span, split 4");
    add(compact);
    add(showAll);
    add(okButton, "tag ok");
  }