Search in sources :

Example 1 with DataElementComperator

use of pcgen.core.doomsdaybook.DataElementComperator 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)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 ComboBoxModel (javax.swing.ComboBoxModel)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 DataConversionException (org.jdom2.DataConversionException)1 DataElementComperator (pcgen.core.doomsdaybook.DataElementComperator)1 RuleSet (pcgen.core.doomsdaybook.RuleSet)1