use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.
the class CharacterAbilities method getCatIndex.
/**
* Determine where the ability category should be added to the active
* category list. This will keep the activate categories in the same sort
* order as the activity category list.
* @param abilityCategory The category being added
* @return The index at which to insert the category.
*/
private int getCatIndex(AbilityCategory abilityCategory, ListFacade<AbilityCategoryFacade> catList) {
Set<AbilityCategoryFacade> allCategories = dataSetFacade.getAbilities().getKeys();
int index = 0;
for (AbilityCategoryFacade compCat : allCategories) {
if (compCat == abilityCategory || index >= catList.getSize()) {
break;
}
if (catList.getElementAt(index) == compCat) {
index++;
}
}
return index;
}
use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.
the class CharacterAbilities method addElement.
private void addElement(Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap, CNAbilitySelection cnas) {
CNAbility cas = cnas.getCNAbility();
Ability ability = cas.getAbility();
if (!ability.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
// Filter out hidden abilities
return;
}
AbilityCategoryFacade cat = (AbilityCategoryFacade) cas.getAbilityCategory();
DefaultListFacade<AbilityFacade> listFacade = workingAbilityListMap.get(cat);
if (listFacade == null) {
listFacade = new DefaultListFacade<>();
workingAbilityListMap.put(cat, listFacade);
}
if (!listFacade.containsElement(ability)) {
listFacade.addElement(ability);
}
}
use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.
the class CategoryTableModel method ItemChanged.
@Override
public void ItemChanged(ChangeEvent event) {
AbilityCategoryFacade facade = null;
if (installed) {
int selectedRow = categoryTable.getSelectedRow();
if (selectedRow >= 0 && selectedRow < sortedList.getSize()) {
facade = sortedList.getElementAt(selectedRow);
}
}
Object data = event.getSource();
refilter();
for (int i = 0; i < getRowCount(); i++) {
AbilityCategoryFacade rowCat = getCategory(i);
if (rowCat == data) {
fireTableRowsUpdated(i, i);
}
}
if (facade != null) {
for (int i = 0; i < sortedList.getSize(); i++) {
if (facade == sortedList.getElementAt(i)) {
categoryTable.getSelectionModel().setSelectionInterval(i, i);
break;
}
}
}
}
use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.
the class AbilityChooserTab method initComponents.
private void initComponents() {
setOrientation(VERTICAL_SPLIT);
availableTreeViewPanel.setDefaultRenderer(Boolean.class, new BooleanRenderer());
availableTreeViewPanel.setTreeCellRenderer(qualifiedRenderer);
selectedTreeViewPanel.setTreeCellRenderer(abilityRenderer);
FilterBar<CharacterFacade, AbilityFacade> filterBar = new FilterBar<>();
filterBar.addDisplayableFilter(new SearchFilterPanel());
//$NON-NLS-1$
qFilterButton.setText(LanguageBundle.getString("in_igQualFilter"));
filterBar.addDisplayableFilter(qFilterButton);
JPanel availPanel = FilterUtilities.configureFilteredTreeViewPane(availableTreeViewPanel, filterBar);
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
addButton.setHorizontalTextPosition(SwingConstants.LEADING);
box.add(addButton);
box.add(Box.createHorizontalStrut(5));
box.setBorder(new EmptyBorder(0, 0, 5, 0));
availPanel.add(box, BorderLayout.SOUTH);
JPanel selPanel = new JPanel(new BorderLayout());
selPanel.add(new JScrollPane(selectedTreeViewPanel), BorderLayout.CENTER);
AbilityTreeTableModel.initializeTreeTable(selectedTreeViewPanel);
box = Box.createHorizontalBox();
box.add(Box.createHorizontalStrut(5));
box.add(removeButton);
box.add(Box.createHorizontalGlue());
box.setBorder(new EmptyBorder(0, 0, 5, 0));
selPanel.add(box, BorderLayout.SOUTH);
FlippingSplitPane topPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, availPanel, selPanel, "abilityTop");
setTopComponent(topPane);
FilterButton<CharacterFacade, AbilityCategoryFacade> gainedFilterButton = new FilterButton<>("AbilityGained", true);
//$NON-NLS-1$
gainedFilterButton.setText(LanguageBundle.getString("in_gained"));
gainedFilterButton.setEnabled(true);
gainedFilterButton.setFilter(new Filter<CharacterFacade, AbilityCategoryFacade>() {
@Override
public boolean accept(CharacterFacade context, AbilityCategoryFacade element) {
return context.getActiveAbilityCategories().containsElement(element);
}
});
categoryBar.addDisplayableFilter(gainedFilterButton);
JPanel filterPanel = new JPanel(new BorderLayout());
filterPanel.add(categoryBar, BorderLayout.NORTH);
filterPanel.add(new JScrollPane(categoryTable), BorderLayout.CENTER);
FlippingSplitPane bottomPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, "abilityBottom");
bottomPane.setLeftComponent(filterPanel);
bottomPane.setRightComponent(infoPane);
setBottomComponent(bottomPane);
}
use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.
the class CharacterAbilitiesTest method testRebuildAbilityListsMult.
/**
* Test method for {@link pcgen.gui2.facade.CharacterAbilities#rebuildAbilityLists()}.
*/
@Test
public final void testRebuildAbilityListsMult() {
PlayerCharacter pc = getCharacter();
CharacterAbilities ca = new CharacterAbilities(pc, uiDelegate, dataset, todoManager);
ca.rebuildAbilityLists();
ListFacade<AbilityCategoryFacade> categories = ca.getActiveAbilityCategories();
assertNotNull("Categories should not be null", categories);
assertTrue("Feat should be active", categories.containsElement(AbilityCategory.FEAT));
ListFacade<AbilityFacade> abilities = ca.getAbilities(AbilityCategory.FEAT);
assertNotNull("Feat list should not be null", abilities);
assertTrue("Feat list should be empty", abilities.isEmpty());
// Add an entry - note rebuild is implicit
Ability reading = TestHelper.makeAbility("reading", AbilityCategory.FEAT, "interest");
reading.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
StringToken st = new plugin.lsttokens.choose.StringToken();
ParseResult pr = st.parseToken(Globals.getContext(), reading, "STRING|Magazines|Books");
assertTrue(pr.passed());
Globals.getContext().commit();
applyAbility(pc, AbilityCategory.FEAT, reading, "Books");
abilities = ca.getAbilities(AbilityCategory.FEAT);
assertFalse("Feat list should not be empty", abilities.isEmpty());
Ability abilityFromList = (Ability) abilities.getElementAt(0);
assertEquals("Should have found reading", reading, abilityFromList);
assertEquals("Feat list should have one entry", 1, abilities.getSize());
// Now add the choice
pcgenFinalize(abilityFromList, "Magazines", pc, AbilityCategory.FEAT);
ca.rebuildAbilityLists();
abilities = ca.getAbilities(AbilityCategory.FEAT);
assertEquals("Feat list should have one entry", 1, abilities.getSize());
abilityFromList = (Ability) abilities.getElementAt(0);
assertEquals("Should have found reading", reading, abilityFromList);
}
Aggregations