|
From: <jde...@us...> - 2011-01-31 12:02:13
|
Revision: 14487
http://pcgen.svn.sourceforge.net/pcgen/?rev=14487&view=rev
Author: jdempsey
Date: 2011-01-31 12:02:06 +0000 (Mon, 31 Jan 2011)
Log Message:
-----------
Implement EquipmentSet facade layer
* Add tallying of weight
Issue#: CODE-503
Modified Paths:
--------------
sandbox/cdomui/code/src/java/pcgen/gui2/facade/CharacterFacadeImpl.java
sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java
Modified: sandbox/cdomui/code/src/java/pcgen/gui2/facade/CharacterFacadeImpl.java
===================================================================
--- sandbox/cdomui/code/src/java/pcgen/gui2/facade/CharacterFacadeImpl.java 2011-01-31 10:42:44 UTC (rev 14486)
+++ sandbox/cdomui/code/src/java/pcgen/gui2/facade/CharacterFacadeImpl.java 2011-01-31 12:02:06 UTC (rev 14487)
@@ -25,6 +25,8 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -86,7 +88,11 @@
import pcgen.core.facade.TempBonusFacade;
import pcgen.core.facade.TodoFacade;
import pcgen.core.facade.UIDelegate;
+import pcgen.core.facade.EquipmentListFacade.EquipmentListEvent;
+import pcgen.core.facade.EquipmentListFacade.EquipmentListListener;
import pcgen.core.facade.TodoFacade.CharacterTab;
+import pcgen.core.facade.event.ListEvent;
+import pcgen.core.facade.event.ListListener;
import pcgen.core.facade.util.DefaultListFacade;
import pcgen.core.facade.util.ListFacade;
import pcgen.core.pclevelinfo.PCLevelInfo;
@@ -115,7 +121,7 @@
* @author James Dempsey <jde...@us...>
* @version $Revision$
*/
-public class CharacterFacadeImpl implements CharacterFacade
+public class CharacterFacadeImpl implements CharacterFacade, EquipmentListListener, ListListener<EquipmentFacade>
{
private Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> abilityListMap;
@@ -241,6 +247,9 @@
hpRef = new DefaultReferenceFacade<Integer>(0);
purchasedEquip = new EquipmentListFacadeImpl(pc.getEquipmentList());
+ carriedWeightRef = new DefaultReferenceFacade<String>();
+ loadRef = new DefaultReferenceFacade<String>();
+ weightLimitRef = new DefaultReferenceFacade<String>();
initEquipSet(pc);
GameMode game = (GameMode) dataSet.getGameMode();
@@ -249,9 +258,6 @@
statTotalLabelText = new DefaultReferenceFacade<String>();
statTotalText = new DefaultReferenceFacade<String>();
todoList = new DefaultListFacade<TodoFacade>();
- carriedWeightRef = new DefaultReferenceFacade<String>();
- loadRef = new DefaultReferenceFacade<String>();
- weightLimitRef = new DefaultReferenceFacade<String>();
charLevelsFacade = new CharacterLevelsFacadeImpl(pc, delegate);
updateScorePurchasePool(false);
@@ -293,6 +299,12 @@
}
}
}
+
+ EquipmentSetFacade set = equipSet.getReference();
+ set.getEquippedItems().addListListener(this);
+ set.getEquippedItems().addEquipmentListListener(this);
+ refreshTotalWeight();
+
}
/**
@@ -1458,7 +1470,16 @@
*/
public void setEquipmentSet(EquipmentSetFacade set)
{
+ EquipmentSetFacade oldSet = equipSet.getReference();
+ if (oldSet != null)
+ {
+ oldSet.getEquippedItems().removeListListener(this);
+ oldSet.getEquippedItems().removeEquipmentListListener(this);
+ }
equipSet.setReference(set);
+ set.getEquippedItems().addListListener(this);
+ set.getEquippedItems().addEquipmentListListener(this);
+ refreshTotalWeight();
}
/**
@@ -2291,4 +2312,46 @@
return weightLimitRef;
}
+ /* (non-Javadoc)
+ * @see pcgen.core.facade.EquipmentListFacade.EquipmentListListener#quantityChanged(pcgen.core.facade.EquipmentListFacade.EquipmentListEvent)
+ */
+ public void quantityChanged(EquipmentListEvent e)
+ {
+ refreshTotalWeight();
+ }
+
+ /* (non-Javadoc)
+ * @see pcgen.core.facade.event.ListListener#elementAdded(pcgen.core.facade.event.ListEvent)
+ */
+ public void elementAdded(ListEvent<EquipmentFacade> e)
+ {
+ refreshTotalWeight();
+ }
+
+ /* (non-Javadoc)
+ * @see pcgen.core.facade.event.ListListener#elementRemoved(pcgen.core.facade.event.ListEvent)
+ */
+ public void elementRemoved(ListEvent<EquipmentFacade> e)
+ {
+ refreshTotalWeight();
+ }
+
+ /* (non-Javadoc)
+ * @see pcgen.core.facade.event.ListListener#elementsChanged(pcgen.core.facade.event.ListEvent)
+ */
+ public void elementsChanged(ListEvent<EquipmentFacade> e)
+ {
+ refreshTotalWeight();
+ }
+
+ /**
+ * Refreshes the total weight by reading it from the current equipment set.
+ */
+ private void refreshTotalWeight()
+ {
+ NumberFormat format = new DecimalFormat("#,##0.##");
+ String weight = format.format(((EquipmentSetFacadeImpl) equipSet.getReference()).getTotalWeight());
+ carriedWeightRef.setReference(weight);
+ }
+
}
Modified: sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java
===================================================================
--- sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java 2011-01-31 10:42:44 UTC (rev 14486)
+++ sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java 2011-01-31 12:02:06 UTC (rev 14487)
@@ -75,6 +75,7 @@
private DataSetFacade dataSet;
private Map<String, BodyStructure> bodyStructMap;
private UIDelegate delegate;
+ private double totalWeight = 0;
/**
* Create a new Equipment Set Facade implementation for an existing
@@ -159,6 +160,7 @@
EquipPathImpl epi = new EquipPathImpl(root, es.getIdPath(), fullPath);
paths.addElement(epi);
updateTotalQuantity(es.getItem(), es.getItem().getQty().intValue());
+ updateTotalWeight(es.getItem(), es.getItem().getQty(), root);
// add to list for recursive calls
children.add(es);
@@ -179,6 +181,22 @@
}
/**
+ * Add the weight for the item to the total for the set.
+ *
+ * @param equip The equipment item being added
+ * @param quantity The number being added (or negative if being removed)
+ * @param root The BodyStructure in which the item is being placed or removed
+ */
+ private void updateTotalWeight(Equipment equip, float quantity, BodyStructureFacade root)
+ {
+ if (!Constants.S_NOTCARRIED.equals(root.toString()))
+ {
+ double weight = equip.getWeightAsDouble(theCharacter)*quantity;
+ totalWeight += weight;
+ }
+ }
+
+ /**
* returns new id_Path with the last id one higher than the current
* highest id for EquipSets with the same ParentIdPath
* @TODO: This needs to be moved to the core.
@@ -258,6 +276,7 @@
.getIdPath());
es.setQty(es.getQty() + quantity);
fireQuantityChanged(existing);
+ updateTotalWeight(existingItem, quantity, parent.getRoot());
updateTotalQuantity(existingItem, quantity);
return;
}
@@ -282,6 +301,7 @@
fullPath[fullPath.length-1] = equipment;
EquipPathImpl epi = new EquipPathImpl(ep.getRoot(), newSet.getIdPath(), fullPath);
paths.addElement(epi);
+ updateTotalWeight(item, quantity, parent.getRoot());
updateTotalQuantity(item, quantity);
}
@@ -338,6 +358,7 @@
eSet.setQty((float) newQty);
fireQuantityChanged(path);
}
+ updateTotalWeight(eqI, quantity*-1, path.getRoot());
updateTotalQuantity(eqI, quantity*-1);
}
@@ -557,6 +578,14 @@
}
/**
+ * @return The total carried weight for this equipment set.
+ */
+ double getTotalWeight()
+ {
+ return totalWeight;
+ }
+
+ /**
* @return The core EquipSet that this facade represents.
*/
EquipSet getEquipSet()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|