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);
}
}
Aggregations