use of pcgen.core.doomsdaybook.RuleSet in project pcgen by PCGen.
the class NameGenPanel method loadRuleSet.
private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException {
RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"), ruleSet.getAttributeValue("usage"));
java.util.List<?> elements = ruleSet.getChildren();
ListIterator<?> elementsIterator = elements.listIterator();
int num = 0;
while (elementsIterator.hasNext()) {
Element child = (Element) elementsIterator.next();
String elementName = child.getName();
if (elementName.equals("CATEGORY")) {
loadCategory(child, rs);
} else if (elementName.equals("RULE")) {
rs.add(loadRule(child, rs.getId() + num));
}
num++;
}
return rs;
}
use of pcgen.core.doomsdaybook.RuleSet in project pcgen by PCGen.
the class NameGenPanel method loadGenderDD.
// Load the gender drop dowd
private void loadGenderDD() {
List<String> genders = getGenderCategoryNames();
Vector<String> selectable = new Vector<>();
String gender = (String) cbSex.getSelectedItem();
// Get the selected category name
String category = (String) cbCategory.getSelectedItem();
// Get the set of rules for selected category
List<RuleSet> categoryRules = categories.get(category);
// loop through the available genders
for (String genderString : genders) {
// Get the list of rules for the current gender
List<RuleSet> genderRules = categories.get("Sex: " + genderString);
// now loop through all the rules from the selected category
for (RuleSet categoryRule : categoryRules) {
// we can stop processing the list once we find a match
if (genderRules.contains(categoryRule)) {
selectable.add(genderString);
break;
}
}
}
// Sort the genders
Collections.sort(selectable);
// Create a new model for the combobox and set it
cbSex.setModel(new DefaultComboBoxModel(selectable));
if (gender != null && selectable.contains(gender)) {
cbSex.setSelectedItem(gender);
}
}
use of pcgen.core.doomsdaybook.RuleSet in project pcgen by PCGen.
the class NameGenPanel method loadCatalogDD.
//GEN-LAST:event_jButton1ActionPerformed
private void loadCatalogDD() {
try {
String catKey = (String) cbCategory.getSelectedItem();
String sexKey = (String) cbSex.getSelectedItem();
RuleSet oldRS = (RuleSet) cbCatalog.getSelectedItem();
String catalogKey = "";
if (oldRS != null) {
catalogKey = oldRS.getTitle();
}
List<RuleSet> cats = categories.get(catKey);
List<RuleSet> sexes = categories.get("Sex: " + sexKey);
List<RuleSet> join = new ArrayList<>(cats);
join.retainAll(sexes);
join.sort(new DataElementComperator());
Vector<RuleSet> catalogs = new Vector<>();
int oldSelected = -1;
int n = 0;
for (final RuleSet rs : join) {
if (rs.getUsage().equals("final")) {
catalogs.add(rs);
if (rs.getTitle().equals(catalogKey)) {
oldSelected = n;
}
n++;
}
}
ComboBoxModel catalogModel = new DefaultComboBoxModel(catalogs);
cbCatalog.setModel(catalogModel);
if (oldSelected >= 0)
cbCatalog.setSelectedIndex(oldSelected);
} catch (Exception e) {
Logging.errorPrint(e.getMessage(), e);
}
}
use of pcgen.core.doomsdaybook.RuleSet in project pcgen by PCGen.
the class NameGenPanel method loadFromDocument.
private void loadFromDocument(Document nameSet) throws DataConversionException {
Element generator = nameSet.getRootElement();
java.util.List<?> rulesets = generator.getChildren("RULESET");
java.util.List<?> lists = generator.getChildren("LIST");
ListIterator<?> listIterator = lists.listIterator();
while (listIterator.hasNext()) {
Element list = (Element) listIterator.next();
loadList(list);
}
for (final Object ruleset : rulesets) {
Element ruleSet = (Element) ruleset;
RuleSet rs = loadRuleSet(ruleSet);
allVars.addDataElement(rs);
}
}
use of pcgen.core.doomsdaybook.RuleSet in project pcgen by PCGen.
the class NameGenPanel method generate.
/**
* Generate a Rule
* @return new Rule
*/
public Rule generate() {
try {
Rule rule;
if (chkStructure.isSelected()) {
RuleSet rs = (RuleSet) cbCatalog.getSelectedItem();
rule = rs.getRule();
} else {
rule = (Rule) cbStructure.getSelectedItem();
}
ArrayList<DataValue> aName = rule.getData();
setNameText(aName);
setMeaningText(aName);
setPronounciationText(aName);
return rule;
} catch (Exception e) {
Logging.errorPrint(e.getMessage(), e);
return null;
}
}
Aggregations