Search in sources :

Example 1 with AbilityCategoryFacade

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;
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade)

Example 2 with AbilityCategoryFacade

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);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) AbilityFacade(pcgen.facade.core.AbilityFacade)

Example 3 with AbilityCategoryFacade

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;
            }
        }
    }
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade)

Example 4 with AbilityCategoryFacade

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) FilterButton(pcgen.gui2.filter.FilterButton) Box(javax.swing.Box) CharacterFacade(pcgen.facade.core.CharacterFacade) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) FilterBar(pcgen.gui2.filter.FilterBar) BorderLayout(java.awt.BorderLayout) AbilityFacade(pcgen.facade.core.AbilityFacade) SearchFilterPanel(pcgen.gui2.filter.SearchFilterPanel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 5 with AbilityCategoryFacade

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);
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) ParseResult(pcgen.rules.persistence.token.ParseResult) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) AbilityFacade(pcgen.facade.core.AbilityFacade) StringToken(plugin.lsttokens.choose.StringToken) Test(org.junit.Test)

Aggregations

AbilityCategoryFacade (pcgen.facade.core.AbilityCategoryFacade)9 AbilityFacade (pcgen.facade.core.AbilityFacade)6 Ability (pcgen.core.Ability)4 CNAbility (pcgen.cdom.content.CNAbility)3 Test (org.junit.Test)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 BorderLayout (java.awt.BorderLayout)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Box (javax.swing.Box)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 EmptyBorder (javax.swing.border.EmptyBorder)1 AbilityCategory (pcgen.core.AbilityCategory)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1 DefaultListFacade (pcgen.facade.util.DefaultListFacade)1 FilterBar (pcgen.gui2.filter.FilterBar)1 FilterButton (pcgen.gui2.filter.FilterButton)1 SearchFilterPanel (pcgen.gui2.filter.SearchFilterPanel)1 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)1