Search in sources :

Example 1 with RuleSet

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;
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element)

Example 2 with RuleSet

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);
    }
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Vector(java.util.Vector)

Example 3 with RuleSet

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);
    }
}
Also used : DataElementComperator(pcgen.core.doomsdaybook.DataElementComperator) RuleSet(pcgen.core.doomsdaybook.RuleSet) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Vector(java.util.Vector) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) FileNotFoundException(java.io.FileNotFoundException) DataConversionException(org.jdom2.DataConversionException)

Example 4 with RuleSet

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);
    }
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element)

Example 5 with RuleSet

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;
    }
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) WeightedDataValue(pcgen.core.doomsdaybook.WeightedDataValue) DataValue(pcgen.core.doomsdaybook.DataValue) CRRule(pcgen.core.doomsdaybook.CRRule) HyphenRule(pcgen.core.doomsdaybook.HyphenRule) Rule(pcgen.core.doomsdaybook.Rule) SpaceRule(pcgen.core.doomsdaybook.SpaceRule) FileNotFoundException(java.io.FileNotFoundException) DataConversionException(org.jdom2.DataConversionException)

Aggregations

RuleSet (pcgen.core.doomsdaybook.RuleSet)6 FileNotFoundException (java.io.FileNotFoundException)3 DataConversionException (org.jdom2.DataConversionException)3 DataElement (pcgen.core.doomsdaybook.DataElement)3 Vector (java.util.Vector)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 Element (org.jdom2.Element)2 CRRule (pcgen.core.doomsdaybook.CRRule)2 DataValue (pcgen.core.doomsdaybook.DataValue)2 HyphenRule (pcgen.core.doomsdaybook.HyphenRule)2 Rule (pcgen.core.doomsdaybook.Rule)2 SpaceRule (pcgen.core.doomsdaybook.SpaceRule)2 WeightedDataValue (pcgen.core.doomsdaybook.WeightedDataValue)2 ArrayList (java.util.ArrayList)1 ComboBoxModel (javax.swing.ComboBoxModel)1 DataElementComperator (pcgen.core.doomsdaybook.DataElementComperator)1