@SuppressWarnings("unchecked") // FIXME in Java7 private void updateBuildingList() { DefaultListModel buildings = (DefaultListModel) buildingList.getModel(); DefaultListModel current = (DefaultListModel) buildQueueList.getModel(); buildings.clear(); loop: for (BuildingType buildingType : getSpecification().getBuildingTypeList()) { // compare colony.getNoBuildReason() List<String> lockReason = new ArrayList<String>(); Building colonyBuilding = colony.getBuilding(buildingType); if (current.contains(buildingType) || hasBuildingType(buildingType)) { // only one building of any kind continue; } else if (unbuildableTypes.contains(buildingType)) { continue; } else if (!buildingType.needsGoodsToBuild()) { // pre-built continue; } else if (unbuildableTypes.contains(buildingType.getUpgradesFrom())) { // impossible upgrade path unbuildableTypes.add(buildingType); continue; } if (buildingType.getRequiredPopulation() > unitCount) { lockReason.add( Messages.message( StringTemplate.template("colonyPanel.populationTooSmall") .addAmount("%number%", buildingType.getRequiredPopulation()))); } for (Entry<String, Boolean> entry : buildingType.getRequiredAbilities().entrySet()) { if (colony.hasAbility(entry.getKey()) != entry.getValue() && FeatureContainer.hasAbility(featureContainer, entry.getKey(), null, null) != entry.getValue()) { List<FreeColGameObjectType> sources = getSpecification().getTypesProviding(entry.getKey(), entry.getValue()); if (sources.isEmpty()) { // no type provides the required ability unbuildableTypes.add(buildingType); continue loop; } else { lockReason.add(Messages.message(sources.get(0).getNameKey())); } } } if (buildingType.getLimits() != null) { for (Limit limit : buildingType.getLimits()) { if (!limit.evaluate(colony)) { lockReason.add(Messages.message(limit.getDescriptionKey())); } } } if (buildingType.getUpgradesFrom() != null && !current.contains(buildingType.getUpgradesFrom())) { if (colonyBuilding == null || colonyBuilding.getType() != buildingType.getUpgradesFrom()) { lockReason.add(Messages.message(buildingType.getUpgradesFrom().getNameKey())); } } if (lockReason.isEmpty()) { lockReasons.put(buildingType, null); } else { lockReasons.put( buildingType, Messages.message( StringTemplate.template("colonyPanel.requires") .addName("%string%", Utils.join("/", lockReason)))); } if (lockReason.isEmpty() || showAll.isSelected()) { buildings.addElement(buildingType); } } }
@SuppressWarnings("unchecked") // FIXME in Java7 private void updateUnitList() { final Specification spec = getSpecification(); DefaultListModel units = (DefaultListModel) unitList.getModel(); units.clear(); loop: for (UnitType unitType : buildableUnits) { // compare colony.getNoBuildReason() List<String> lockReason = new ArrayList<String>(); if (unbuildableTypes.contains(unitType)) { continue; } if (unitType.getRequiredPopulation() > unitCount) { lockReason.add( Messages.message( StringTemplate.template("colonyPanel.populationTooSmall") .addAmount("%number%", unitType.getRequiredPopulation()))); } if (unitType.getLimits() != null) { for (Limit limit : unitType.getLimits()) { if (!limit.evaluate(colony)) { lockReason.add(Messages.message(limit.getDescriptionKey())); } } } if (!(colony.hasAbility(Ability.BUILD, unitType, getGame().getTurn()) || FeatureContainer.hasAbility(featureContainer, Ability.BUILD, unitType, null))) { boolean builderFound = false; for (Ability ability : spec.getAbilities(Ability.BUILD)) { if (ability.appliesTo(unitType) && ability.getValue() && ability.getSource() != null && !unbuildableTypes.contains(ability.getSource())) { builderFound = true; lockReason.add(Messages.getName(ability.getSource())); break; } } if (!builderFound) { unbuildableTypes.add(unitType); continue; } } for (Entry<String, Boolean> entry : unitType.getRequiredAbilities().entrySet()) { if (colony.hasAbility(entry.getKey()) != entry.getValue() && FeatureContainer.hasAbility(featureContainer, entry.getKey(), null, null) != entry.getValue()) { List<FreeColGameObjectType> sources = spec.getTypesProviding(entry.getKey(), entry.getValue()); if (sources.isEmpty()) { // no type provides the required ability unbuildableTypes.add(unitType); continue loop; } else { lockReason.add(Messages.message(sources.get(0).getNameKey())); } } } if (lockReason.isEmpty()) { lockReasons.put(unitType, null); } else { lockReasons.put( unitType, Messages.message( StringTemplate.template("colonyPanel.requires") .addName("%string%", Utils.join("/", lockReason)))); } if (lockReason.isEmpty() || showAll.isSelected()) { units.addElement(unitType); } } }