|
From: <th...@us...> - 2007-09-29 19:34:53
|
Revision: 4179
http://pcgen.svn.sourceforge.net/pcgen/?rev=4179&view=rev
Author: thpr
Date: 2007-09-29 11:36:05 -0700 (Sat, 29 Sep 2007)
Log Message:
-----------
Bring CDOM up to 4173
Modified Paths:
--------------
branches/cdom/code/src/java/plugin/doomsdaybook/gui/NameGenPanel.java
branches/cdom/code/src/java/plugin/exporttokens/ClassToken.java
branches/cdom/code/src/java/plugin/exporttokens/DeityToken.java
branches/cdom/code/src/java/plugin/exporttokens/RaceToken.java
branches/cdom/code/src/java/plugin/exporttokens/TemplateToken.java
branches/cdom/code/src/java/plugin/exporttokens/TextToken.java
branches/cdom/code/src/java/plugin/pretokens/test/PreAbilityTester.java
branches/cdom/code/src/java/plugin/pretokens/test/PreSpecialAbilityTester.java
Modified: branches/cdom/code/src/java/plugin/doomsdaybook/gui/NameGenPanel.java
===================================================================
--- branches/cdom/code/src/java/plugin/doomsdaybook/gui/NameGenPanel.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/doomsdaybook/gui/NameGenPanel.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -79,6 +79,8 @@
private JSeparator jSeparator4;
private JTextField name;
private VariableHashMap allVars = new VariableHashMap();
+
+ private Rule lastRule = null;
/** Creates new form NameGenPanel */
public NameGenPanel()
@@ -104,18 +106,18 @@
{
try
{
+ Rule rule = null;
+
if (chkStructure.isSelected())
{
RuleSet rs = (RuleSet) cbCatalog.getSelectedItem();
- Rule rule = rs.getRule();
- ArrayList<DataValue> aName = rule.getData();
- setNameText(aName);
- setMeaningText(aName);
- setPronounciationText(aName);
-
- return rule;
+ rule = rs.getRule();
}
- Rule rule = (Rule) cbStructure.getSelectedItem();
+ else
+ {
+ rule = (Rule) cbStructure.getSelectedItem();
+ }
+
ArrayList<DataValue> aName = rule.getData();
setNameText(aName);
setMeaningText(aName);
@@ -227,10 +229,26 @@
NameButton nb = (NameButton) evt.getSource();
DataElement element = nb.getDataElement();
element.getData();
+
+ Rule rule = this.lastRule;
+
+ if( rule == null)
+ {
+ if (chkStructure.isSelected())
+ {
+ RuleSet rs = (RuleSet) cbCatalog.getSelectedItem();
+ rule = rs.getLastRule();
+ }
+ else
+ {
+ rule = (Rule) cbStructure.getSelectedItem();
+ }
+
+ this.lastRule = rule;
+ }
- RuleSet rs = (RuleSet) cbCatalog.getSelectedItem();
- Rule rule = rs.getLastRule();
ArrayList<DataValue> aName = rule.getLastData();
+
setNameText(aName);
setMeaningText(aName);
setPronounciationText(aName);
@@ -244,14 +262,22 @@
private void cbCatalogActionPerformed(ActionEvent evt)
{ //GEN-FIRST:event_cbCatalogActionPerformed
loadStructureDD();
+ this.clearButtons();
}
-
//GEN-LAST:event_cbCatalogActionPerformed
+ private void cbStructureActionPerformed(ActionEvent evt)
+ { //GEN-FIRST:event_cbStructureActionPerformed
+ this.clearButtons();
+ }
+ //GEN-LAST:event_cbStructureActionPerformed
+
private void cbCategoryActionPerformed(ActionEvent evt)
{ //GEN-FIRST:event_cbCategoryActionPerformed
+ this.loadGenderDD();
loadCatalogDD();
loadStructureDD();
+ this.clearButtons();
}
//GEN-LAST:event_cbCategoryActionPerformed
@@ -260,6 +286,7 @@
{ //GEN-FIRST:event_cbSexActionPerformed
loadCatalogDD();
loadStructureDD();
+ this.clearButtons();
}
//GEN-LAST:event_cbSexActionPerformed
@@ -314,8 +341,8 @@
try
{
- Rule rule = generate();
- displayButtons(rule);
+ this.lastRule = generate();
+ displayButtons(this.lastRule);
}
catch (Exception e)
{
@@ -461,6 +488,13 @@
jPanel12.add(jLabel6);
cbStructure.setEnabled(false);
+ cbStructure.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ cbStructureActionPerformed(evt);
+ }
+ });
jPanel12.add(cbStructure);
chkStructure.setSelected(true);
@@ -558,7 +592,7 @@
String sexKey = (String) cbSex.getSelectedItem();
RuleSet oldRS = (RuleSet) cbCatalog.getSelectedItem();
String catalogKey = "";
-
+
if (oldRS != null)
{
catalogKey = oldRS.getTitle();
@@ -596,14 +630,79 @@
DefaultComboBoxModel catalogModel =
new DefaultComboBoxModel(catalogs);
cbCatalog.setModel(catalogModel);
- cbCatalog.setSelectedIndex(oldSelected);
}
catch (Exception e)
{
Logging.errorPrint(e.getMessage(), e);
}
}
+
+ // Get a list of all the gender categories in the category map
+ private Vector<String> getGenderCategoryNames()
+ {
+ Vector<String> genders = new java.util.Vector<String>();
+ Set<String> keySet = categories.keySet();
+ Iterator<String> itr = keySet.iterator();
+ // Loop through the keys in the categories
+ while (itr.hasNext())
+ {
+ String key = itr.next();
+
+ // if the key starts with "Sex" then save it
+ if (key.startsWith("Sex:"))
+ {
+ genders.add(key.substring(5));
+ }
+ }
+
+ // Return all the found gender types
+ return genders;
+ }
+
+ // Load the gender drop dowd
+ private void loadGenderDD()
+ {
+ Vector<String> genders = getGenderCategoryNames();
+ Vector<String> selectable = new Vector<String>();
+
+ // Get the selected category name
+ String category = (String) cbCategory.getSelectedItem();
+
+ // Get the set of rules for selected category
+ List<RuleSet> categoryRules = categories.get(category);
+
+ // we need to determine if the selected category is supported by the
+ // available genders
+ // loop through the available genders
+ for( int i = 0; i < genders.size(); ++i )
+ {
+ String gender = genders.get(i);
+
+ // Get the list of rules for the current gender
+ List<RuleSet> genderRules = categories.get("Sex: " + gender);
+
+ // now loop through all the rules from the selected category
+ for( int j = 0; j < categoryRules.size(); ++j )
+ {
+ // if the category rule is in the list of gender rules
+ // add the current gender to the selectable gender list
+ // we can stop processing the list once we find a match
+ if( genderRules.contains(categoryRules.get(j)))
+ {
+ selectable.add(gender);
+ break;
+ }
+ }
+ }
+
+ // Sort the genders
+ Collections.sort(selectable);
+
+ // Create a new model for the combobox and set it
+ cbSex.setModel(new DefaultComboBoxModel(selectable));
+ }
+
private void loadCategory(Element category, RuleSet rs)
{
List<RuleSet> cat = categories.get(category.getAttributeValue("title"));
@@ -661,10 +760,10 @@
}
}
- private void loadDropdowns()
+ // Get a list of category names from the categories map
+ private Vector<String> getCategoryNames()
{
Vector<String> cats = new java.util.Vector<String>();
- Vector<String> sexes = new java.util.Vector<String>();
Set<String> keySet = categories.keySet();
Iterator<String> itr = keySet.iterator();
@@ -672,26 +771,31 @@
{
String key = itr.next();
+ // Ignore any category that starts with this
if (key.startsWith("Sex:"))
{
- sexes.add(key.substring(5));
+ continue;
}
- else
- {
- cats.add(key);
- }
+
+ cats.add(key);
}
+ // Sor the selected categories before returning it
Collections.sort(cats);
- Collections.sort(sexes);
-
- DefaultComboBoxModel catModel = new DefaultComboBoxModel(cats);
- DefaultComboBoxModel sexModel = new DefaultComboBoxModel(sexes);
- cbCategory.setModel(catModel);
- cbSex.setModel(sexModel);
-
- loadCatalogDD();
+
+ return cats;
}
+
+ private void loadDropdowns()
+ {
+ // This method now just loads the category dropdown from the list of
+ // category names
+ Vector<String> cats = this.getCategoryNames();
+ cbCategory.setModel(new DefaultComboBoxModel(cats));
+
+ this.loadGenderDD();
+ this.loadCatalogDD();
+ }
private void loadFromDocument(Document nameSet)
throws DataConversionException
Modified: branches/cdom/code/src/java/plugin/exporttokens/ClassToken.java
===================================================================
--- branches/cdom/code/src/java/plugin/exporttokens/ClassToken.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/exporttokens/ClassToken.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -25,19 +25,18 @@
*/
package plugin.exporttokens;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
import pcgen.core.Constants;
import pcgen.core.PCClass;
import pcgen.core.PlayerCharacter;
import pcgen.core.SpecialAbility;
import pcgen.core.utils.CoreUtility;
-import pcgen.core.utils.ListKey;
import pcgen.io.ExportHandler;
import pcgen.io.exporttoken.Token;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
/**
* Deal with tokens below CLASS.x CLASS.x.LEVEL CLASS.x.SALIST
*/
@@ -161,34 +160,21 @@
*/
public static List<String> getClassSpecialAbilityList(PCClass pcclass,
final PlayerCharacter aPC) {
- final List<String> aList = new ArrayList<String>();
final List<String> formattedList = new ArrayList<String>();
- final List<SpecialAbility> abilityList = pcclass
- .getListFor(ListKey.SPECIAL_ABILITY);
+
+ final List<SpecialAbility> saList = new ArrayList<SpecialAbility>();
+ pcclass.addSpecialAbilitiesToList(saList, aPC);
+ pcclass.addSABToList(saList, aPC);
- // Determine the list of abilities from this class
- // that the character is eligible for
- if (abilityList == null || abilityList.isEmpty()) {
- return aList;
+ if (saList.isEmpty())
+ {
+ return formattedList;
}
- for (SpecialAbility saAbility : abilityList) {
- final String aString = saAbility.toString();
-
- // If we've already added the special ability, don't add it again
- if (aList.contains(aString)) {
- break;
- }
-
- // If the PC qualifies for the special ability, then add it
- if (saAbility.pcQualifiesFor(aPC)) {
- aList.add(aString);
- }
- }
-
// From the list of allowed SAs, format the output strings
// to include all of the variables
- for (String str : aList) {
+ for (SpecialAbility sa : saList) {
+ String str = sa.getDisplayName();
if (str == null || str.length() == 0)
{
continue;
Modified: branches/cdom/code/src/java/plugin/exporttokens/DeityToken.java
===================================================================
--- branches/cdom/code/src/java/plugin/exporttokens/DeityToken.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/exporttokens/DeityToken.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -25,16 +25,19 @@
*/
package plugin.exporttokens;
+import pcgen.core.Constants;
import pcgen.core.Deity;
import pcgen.core.Domain;
import pcgen.core.PlayerCharacter;
import pcgen.core.QualifiedObject;
import pcgen.core.SettingsHandler;
+import pcgen.core.SpecialAbility;
import pcgen.core.utils.CoreUtility;
-import pcgen.core.utils.ListKey;
import pcgen.io.ExportHandler;
import pcgen.io.exporttoken.Token;
+import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
/**
@@ -63,6 +66,7 @@
/**
* @see pcgen.io.exporttoken.Token#getTokenName()
*/
+ @Override
public String getTokenName()
{
return TOKENNAME;
@@ -71,6 +75,7 @@
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
+ @Override
public String getToken(String tokenSource, PlayerCharacter pc,
ExportHandler eh)
{
@@ -134,7 +139,7 @@
}
else if ("SA".equals(subTag))
{
- retString = getSAToken(deity);
+ retString = getSAToken(deity, pc);
}
else if ("TITLE".equals(subTag))
{
@@ -287,15 +292,32 @@
* @param deity
* @return the SA sub token
*/
- public static String getSAToken(Deity deity)
+ public static String getSAToken(Deity deity, PlayerCharacter pc)
{
- if (deity.containsListFor(ListKey.SPECIAL_ABILITY))
+ final List<SpecialAbility> saList = new ArrayList<SpecialAbility>();
+ deity.addSpecialAbilitiesToList(saList, pc);
+ deity.addSABToList(saList, pc);
+
+ if (saList.isEmpty())
{
- return CoreUtility.join(deity.getListFor(ListKey.SPECIAL_ABILITY),
- ", ");
+ return Constants.EMPTY_STRING;
}
- return "";
+ StringBuffer returnString = new StringBuffer();
+ boolean firstLine = true;
+ for (SpecialAbility sa : saList)
+ {
+ if (!firstLine)
+ {
+ returnString.append(", "); //$NON-NLS-1$
+ }
+
+ firstLine = false;
+
+ returnString.append(sa.getDisplayName());
+ }
+
+ return returnString.toString();
}
/**
Modified: branches/cdom/code/src/java/plugin/exporttokens/RaceToken.java
===================================================================
--- branches/cdom/code/src/java/plugin/exporttokens/RaceToken.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/exporttokens/RaceToken.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -25,14 +25,18 @@
*/
package plugin.exporttokens;
-import pcgen.core.*;
-import pcgen.core.utils.ListKey;
+import java.util.ArrayList;
+import java.util.List;
+
+import pcgen.core.Constants;
+import pcgen.core.PCClass;
+import pcgen.core.PlayerCharacter;
+import pcgen.core.SettingsHandler;
+import pcgen.core.SpecialAbility;
import pcgen.io.ExportHandler;
import pcgen.io.exporttoken.Token;
import pcgen.util.PropertyFactory;
-import java.util.List;
-
/**
* This class implements support for the RACE set of tokens.
* RACE - Displays characters race.
@@ -90,10 +94,12 @@
{
return Constants.EMPTY_STRING;
}
- final List<SpecialAbility> saList =
- pc.getRace().getListFor(ListKey.SPECIAL_ABILITY);
+
+ final List<SpecialAbility> saList = new ArrayList<SpecialAbility>();
+ pc.getRace().addSpecialAbilitiesToList(saList, pc);
+ pc.getRace().addSABToList(saList, pc);
- if ((saList == null) || saList.isEmpty())
+ if (saList.isEmpty())
{
return Constants.EMPTY_STRING;
}
Modified: branches/cdom/code/src/java/plugin/exporttokens/TemplateToken.java
===================================================================
--- branches/cdom/code/src/java/plugin/exporttokens/TemplateToken.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/exporttokens/TemplateToken.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -25,6 +25,10 @@
*/
package plugin.exporttokens;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
import pcgen.core.PCTemplate;
import pcgen.core.PlayerCharacter;
import pcgen.core.SettingsHandler;
@@ -33,9 +37,6 @@
import pcgen.io.ExportHandler;
import pcgen.io.exporttoken.Token;
-import java.util.List;
-import java.util.StringTokenizer;
-
/**
* Deals with returning the values for the TEMPALTE Token
* and it's Sub Tokens
@@ -58,6 +59,7 @@
/**
* @see pcgen.io.exporttoken.Token#getTokenName()
*/
+ @Override
public String getTokenName()
{
return TOKENNAME;
@@ -66,6 +68,7 @@
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
+ @Override
public String getToken(String tokenSource, PlayerCharacter pc,
ExportHandler eh)
{
@@ -222,9 +225,9 @@
*/
public static String getSAToken(PCTemplate template, PlayerCharacter pc)
{
- List<SpecialAbility> saList =
- template.getSpecialAbilityList(pc.getTotalLevels(), pc
- .totalHitDice());
+ List<SpecialAbility> saList = new ArrayList<SpecialAbility>();
+ template.addSpecialAbilitiesToList(saList, pc);
+ template.addSABToList(saList, pc);
return CoreUtility.join(saList, ", ");
}
Modified: branches/cdom/code/src/java/plugin/exporttokens/TextToken.java
===================================================================
--- branches/cdom/code/src/java/plugin/exporttokens/TextToken.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/exporttokens/TextToken.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -139,25 +139,23 @@
{
final String replaceType = action.substring(7,action.indexOf('{'));
String args = action.substring(action.indexOf('{')+1, action.length()-1);
- int patternEnd = -1;
- String temp = args;
+ int patternEnd = 0;
+
for ( ; ; )
{
- patternEnd = temp.indexOf(',');
- if (patternEnd == -1)
+ patternEnd = args.indexOf(',', patternEnd);
+ if (patternEnd <= 0)
{
break;
}
- if (temp.charAt(patternEnd - 1) != '\\')
+ if (args.charAt(patternEnd - 1) != '\\')
{
break;
}
- else
- {
- temp = temp.substring(patternEnd+1);
- }
+ String temp = args.substring(0, patternEnd - 1);
+ args = temp + args.substring(patternEnd, args.length());
}
- if (patternEnd == -1)
+ if (patternEnd <= 0)
{
Logging.errorPrint("Invalid REPLACE token");
}
Modified: branches/cdom/code/src/java/plugin/pretokens/test/PreAbilityTester.java
===================================================================
--- branches/cdom/code/src/java/plugin/pretokens/test/PreAbilityTester.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/pretokens/test/PreAbilityTester.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -292,10 +292,9 @@
final List<Ability> abilityList = new ArrayList<Ability>();
if (character != null)
{
+ Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
if (categoryName == null)
{
- Collection<AbilityCategory> allCats =
- SettingsHandler.getGame().getAllAbilityCategories();
for (AbilityCategory aCat : allCats)
{
abilityList.addAll(character.getAggregateAbilityList(aCat));
@@ -303,7 +302,13 @@
}
else
{
- abilityList.addAll(character.getAggregateAbilityList(category));
+ for (AbilityCategory aCat : allCats)
+ {
+ if (aCat.getAbilityCategory().equals(category.getKeyName()))
+ {
+ abilityList.addAll(character.getAggregateAbilityList(aCat));
+ }
+ }
}
}
return abilityList;
Modified: branches/cdom/code/src/java/plugin/pretokens/test/PreSpecialAbilityTester.java
===================================================================
--- branches/cdom/code/src/java/plugin/pretokens/test/PreSpecialAbilityTester.java 2007-09-29 18:17:59 UTC (rev 4178)
+++ branches/cdom/code/src/java/plugin/pretokens/test/PreSpecialAbilityTester.java 2007-09-29 18:36:05 UTC (rev 4179)
@@ -26,8 +26,9 @@
*/
package plugin.pretokens.test;
+import java.util.List;
+
import pcgen.cdom.graph.PCGenGraph;
-import pcgen.core.PCTemplate;
import pcgen.core.PlayerCharacter;
import pcgen.core.SpecialAbility;
import pcgen.core.prereq.AbstractPrerequisiteTest;
@@ -36,8 +37,6 @@
import pcgen.core.prereq.PrerequisiteTest;
import pcgen.util.PropertyFactory;
-import java.util.List;
-
/**
* @author wardc
*
@@ -74,27 +73,6 @@
}
}
- //
- // Now check any templates
- //
- for (PCTemplate aTempl : character.getTemplateList())
- {
- final List<SpecialAbility> saList =
- aTempl.getSpecialAbilityList(character.getTotalLevels(),
- character.totalHitDice());
-
- if (saList != null)
- {
- for (SpecialAbility sa : saList)
- {
- if (sa.getKeyName().toUpperCase().startsWith(aString))
- {
- runningTotal++;
- }
- }
- }
- }
-
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|