From: <bur...@us...> - 2011-02-20 12:47:46
|
Revision: 8039 http://freecol.svn.sourceforge.net/freecol/?rev=8039&view=rev Author: burschik Date: 2011-02-20 12:47:40 +0000 (Sun, 20 Feb 2011) Log Message: ----------- Partially convert ColonyPanel to new production code. Modified Paths: -------------- freecol/trunk/src/net/sf/freecol/client/gui/panel/ColonyPanel.java freecol/trunk/src/net/sf/freecol/client/gui/panel/ProductionLabel.java freecol/trunk/src/net/sf/freecol/server/model/ServerColony.java Modified: freecol/trunk/src/net/sf/freecol/client/gui/panel/ColonyPanel.java =================================================================== --- freecol/trunk/src/net/sf/freecol/client/gui/panel/ColonyPanel.java 2011-02-20 12:06:11 UTC (rev 8038) +++ freecol/trunk/src/net/sf/freecol/client/gui/panel/ColonyPanel.java 2011-02-20 12:47:40 UTC (rev 8039) @@ -44,6 +44,7 @@ import java.util.Iterator; import java.util.List; import java.util.logging.Logger; +import java.util.Map.Entry; import javax.swing.BorderFactory; import javax.swing.ComponentInputMap; @@ -80,12 +81,14 @@ import net.sf.freecol.common.model.Map.Direction; import net.sf.freecol.common.model.ModelMessage; import net.sf.freecol.common.model.Player; +import net.sf.freecol.common.model.ProductionInfo; import net.sf.freecol.common.model.Settlement; import net.sf.freecol.common.model.Specification; import net.sf.freecol.common.model.StringTemplate; import net.sf.freecol.common.model.Tile; import net.sf.freecol.common.model.TileType; import net.sf.freecol.common.model.TradeRoute; +import net.sf.freecol.common.model.TypeCountMap; import net.sf.freecol.common.model.Unit; import net.sf.freecol.common.model.Colony.ColonyChangeEvent; import net.sf.freecol.common.resources.ResourceManager; @@ -139,6 +142,8 @@ private Colony colony; + private java.util.Map<Object, ProductionInfo> productionMap; + private UnitLabel selectedUnitLabel; private JButton exitButton = new JButton(Messages.message("close")); @@ -347,6 +352,7 @@ */ private void initialize(final Colony colony, Unit preSelectedUnit) { setColony(colony); + productionMap = colony.getProductionAndConsumption(); // Set listeners and transfer handlers outsideColonyPanel.removeMouseListener(releaseListener); @@ -418,117 +424,29 @@ public void updateProductionPanel() { netProductionPanel.removeAll(); + productionMap = colony.getProductionAndConsumption(); - int gross = 0, net = 0; - Specification spec = getSpecification(); - - - // food - List<AbstractGoods> ratios; - List<GoodsType> goodsTypes = spec.getFoodGoodsTypeList(); - // TODO: make this generic - net = colony.getFoodProduction() - colony.getFoodConsumption(); - net -= colony.getProductionNetOf(spec.getGoodsType("model.goods.horses")); - if (net != 0) { - GoodsType goodsType = spec.getPrimaryFoodType(); - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } - - // liberty - gross = net = 0; - goodsTypes = spec.getLibertyGoodsTypeList(); - for (GoodsType goodsType : goodsTypes) { - gross += getColony().getProductionOf(goodsType); - net += getColony().getProductionNetOf(goodsType); - } - if (net != 0) { - GoodsType goodsType = spec.getGoodsType("model.goods.bells"); - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } - - - // immigration - gross = net = 0; - goodsTypes = spec.getImmigrationGoodsTypeList(); - for (GoodsType goodsType : goodsTypes) { - gross += getColony().getProductionOf(goodsType); - net += getColony().getProductionNetOf(goodsType); - } - if (net != 0) { - GoodsType goodsType = spec.getGoodsType("model.goods.crosses"); - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } - - - - List<GoodsType> generalGoods = new ArrayList<GoodsType>(spec.getGoodsTypeList()); - generalGoods.removeAll(spec.getFoodGoodsTypeList()); - generalGoods.removeAll(spec.getLibertyGoodsTypeList()); - generalGoods.removeAll(spec.getImmigrationGoodsTypeList()); - generalGoods.removeAll(spec.getFarmedGoodsTypeList()); - - // non-storable goods - goodsTypes = new ArrayList<GoodsType>(generalGoods); - for (GoodsType goodsType : goodsTypes) { - if (!goodsType.isStorable()) { - generalGoods.remove(goodsType); - net = getColony().getProductionNetOf(goodsType); - if (net != 0) { - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } + TypeCountMap<GoodsType> netProduction = new TypeCountMap<GoodsType>(); + for (Entry<Object, ProductionInfo> entry : productionMap.entrySet()) { + ProductionInfo productionInfo = entry.getValue(); + for (AbstractGoods goods : productionInfo.getProduction()) { + netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); } - } - - - // farmed goods - goodsTypes = new ArrayList<GoodsType>(spec.getFarmedGoodsTypeList()); - goodsTypes.removeAll(spec.getFoodGoodsTypeList()); - goodsTypes.removeAll(spec.getLibertyGoodsTypeList()); - goodsTypes.removeAll(spec.getImmigrationGoodsTypeList()); - for (GoodsType goodsType : goodsTypes) { - net = getColony().getProductionNetOf(goodsType); - if (net != 0) { - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); + for (AbstractGoods goods : productionInfo.getStorage()) { + netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); } - } - - - // everything left except military & breedables - goodsTypes = new ArrayList<GoodsType>(generalGoods); - for (GoodsType goodsType : goodsTypes) { - if (!goodsType.isMilitaryGoods() && !goodsType.isBreedable()) { - generalGoods.remove(goodsType); - net = getColony().getProductionNetOf(goodsType); - if (net != 0) { - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } + for (AbstractGoods goods : productionInfo.getConsumption()) { + netProduction.incrementCount(goods.getType().getStoredAs(), -goods.getAmount()); } } - - // military goods - goodsTypes = new ArrayList<GoodsType>(generalGoods); - for (GoodsType goodsType : goodsTypes) { - if (!goodsType.isBreedable()) { - generalGoods.remove(goodsType); - net = getColony().getProductionNetOf(goodsType); - if (net != 0) { - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } + for (GoodsType goodsType : getSpecification().getGoodsTypeList()) { + int amount = netProduction.getCount(goodsType); + if (amount != 0) { + netProductionPanel.add(new ProductionLabel(goodsType, amount, getCanvas())); } } - - // breedable things go last - goodsTypes = new ArrayList<GoodsType>(generalGoods); - for (GoodsType goodsType : goodsTypes) { - generalGoods.remove(goodsType); - net = getColony().getProductionNetOf(goodsType); - if (net != 0) { - netProductionPanel.add(new ProductionLabel(goodsType, net, getCanvas())); - } - } - netProductionPanel.revalidate(); } @@ -1423,29 +1341,9 @@ setLayout(new GridLayout(2, 1)); - TileType tileType = colonyTile.getTile().getType(); - - AbstractGoods primaryGoods = tileType.getPrimaryGoods(); - if (primaryGoods != null) { - GoodsType goodsType = primaryGoods.getType(); - ImageIcon goodsIcon = getLibrary().getGoodsImageIcon(goodsType); - ProductionLabel pl = - new ProductionLabel(goodsType, colonyTile.getProductionOf(goodsType), - getCanvas()); - pl.setSize(getLibrary().getTerrainImageWidth(tileType), goodsIcon.getIconHeight()); - add(pl); + for (AbstractGoods goods : productionMap.get(colonyTile).getProduction()) { + add(new ProductionLabel(goods, getCanvas())); } - - AbstractGoods secondaryGoods = tileType.getSecondaryGoods(); - if (secondaryGoods != null) { - GoodsType goodsType = secondaryGoods.getType(); - ImageIcon goodsIcon = getLibrary().getGoodsImageIcon(goodsType); - ProductionLabel pl = - new ProductionLabel(goodsType, colonyTile.getProductionOf(goodsType), - getCanvas()); - pl.setSize(getLibrary().getTerrainImageWidth(tileType), goodsIcon.getIconHeight()); - add(pl); - } } /** Modified: freecol/trunk/src/net/sf/freecol/client/gui/panel/ProductionLabel.java =================================================================== --- freecol/trunk/src/net/sf/freecol/client/gui/panel/ProductionLabel.java 2011-02-20 12:06:11 UTC (rev 8038) +++ freecol/trunk/src/net/sf/freecol/client/gui/panel/ProductionLabel.java 2011-02-20 12:47:40 UTC (rev 8039) @@ -32,6 +32,7 @@ import net.sf.freecol.client.ClientOptions; import net.sf.freecol.client.gui.Canvas; import net.sf.freecol.client.gui.i18n.Messages; +import net.sf.freecol.common.model.AbstractGoods; import net.sf.freecol.common.model.Goods; import net.sf.freecol.common.model.GoodsType; import net.sf.freecol.common.model.StringTemplate; @@ -108,10 +109,10 @@ /** * Creates a new <code>ProductionLabel</code> instance. * - * @param goods a <code>Goods</code> value + * @param goods a <code>AbstractGoods</code> value * @param parent a <code>Canvas</code> value */ - public ProductionLabel(Goods goods, Canvas parent) { + public ProductionLabel(AbstractGoods goods, Canvas parent) { this(goods.getType(), goods.getAmount(), -1, parent); } @@ -144,7 +145,7 @@ maxIcons = options.getInteger(ClientOptions.MAX_NUMBER_OF_GOODS_IMAGES); displayNumber = options.getInteger(ClientOptions.MIN_NUMBER_FOR_DISPLAYING_GOODS_COUNT); - + setFont(ResourceManager.getFont("SimpleFont", Font.BOLD, 12f)); if (amount < 0) { setForeground(Color.RED); @@ -178,7 +179,7 @@ /** * Returns the parent Canvas object. - * + * * @return This ProductionLabel's Canvas. */ public Canvas getCanvas() { @@ -415,7 +416,7 @@ /** * Paints this ProductionLabel. - * + * * @param g The graphics context in which to do the painting. */ public void paintComponent(Graphics g) { Modified: freecol/trunk/src/net/sf/freecol/server/model/ServerColony.java =================================================================== --- freecol/trunk/src/net/sf/freecol/server/model/ServerColony.java 2011-02-20 12:06:11 UTC (rev 8038) +++ freecol/trunk/src/net/sf/freecol/server/model/ServerColony.java 2011-02-20 12:47:40 UTC (rev 8039) @@ -188,18 +188,7 @@ } } } - } - for (AbstractGoods goods : productionInfo.getProduction()) { - netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); - } - for (AbstractGoods goods : productionInfo.getStorage()) { - netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); - } - for (AbstractGoods goods : productionInfo.getConsumption()) { - netProduction.incrementCount(goods.getType().getStoredAs(), -goods.getAmount()); - } - - if (entry.getKey() instanceof BuildQueue + } else if (entry.getKey() instanceof BuildQueue && !productionInfo.getConsumption().isEmpty()) { // this means we are actually building something BuildQueue queue = (BuildQueue) entry.getKey(); @@ -216,6 +205,16 @@ buildable = csGetBuildable(cs); } + for (AbstractGoods goods : productionInfo.getProduction()) { + netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); + } + for (AbstractGoods goods : productionInfo.getStorage()) { + netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount()); + } + for (AbstractGoods goods : productionInfo.getConsumption()) { + netProduction.incrementCount(goods.getType().getStoredAs(), -goods.getAmount()); + } + } for (Entry<GoodsType, Integer> entry : netProduction.getValues().entrySet()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |