Search in sources :

Example 1 with CategoryTableModel

use of pcgen.gui2.tabs.ability.CategoryTableModel in project pcgen by PCGen.

the class AbilityChooserTab method createState.

//
//	private final class AbilityTransferHandler extends TransferHandler
//	{
//
//		private CharacterFacade character;
//
//		public AbilityTransferHandler(CharacterFacade character)
//		{
//			this.character = character;
//		}
//
//		private final DataFlavor abilityFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
//				";class=" +
//				AbilityFacade.class.getName(),
//																null);
//
//		@Override
//		public int getSourceActions(JComponent c)
//		{
//			if (selectedAbility != null)
//			{
//				if (selectedTreeViewPanel.isAncestorOf(c))
//				{
//					return MOVE;
//				}
//				if (selectedAbility.isMult())
//				{
//					return COPY;
//				}
//				if (!character.hasAbility(selectedCatagory, selectedAbility))
//				{
//					return MOVE;
//				}
//			}
//			return NONE;
//		}
//
//		@Override
//		protected Transferable createTransferable(JComponent c)
//		{
//			final AbilityFacade transferAbility = selectedAbility;
//			return new Transferable()
//			{
//
//				public DataFlavor[] getTransferDataFlavors()
//				{
//					return new DataFlavor[]
//							{
//								abilityFlavor
//							};
//				}
//
//				public boolean isDataFlavorSupported(DataFlavor flavor)
//				{
//					return abilityFlavor == flavor;
//				}
//
//				public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
//				{
//					if (!isDataFlavorSupported(flavor))
//					{
//						throw new UnsupportedFlavorException(flavor);
//					}
//					return transferAbility;
//				}
//
//			};
//		}
//
//		@Override
//		public boolean canImport(JComponent comp, DataFlavor[] transferFlavors)
//		{
//			return transferFlavors[0] == abilityFlavor;
//		}
//
//		@Override
//		public boolean importData(JComponent comp, Transferable t)
//		{
//			if (selectedTreeViewPanel.isAncestorOf(comp))
//			{
//				try
//				{
//					AbilityFacade ability = (AbilityFacade) t.getTransferData(abilityFlavor);
//					// TODO: add some extra logic
//					character.addAbility(selectedCatagory, ability);
//					return true;
//				}
//				catch (UnsupportedFlavorException ex)
//				{
//					Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
//																			null,
//																			ex);
//				}
//				catch (IOException ex)
//				{
//					Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
//																			null,
//																			ex);
//				}
//				return false;
//			}
//			return true;
//		}
//
//		@Override
//		protected void exportDone(JComponent source, Transferable data,
//								  int action)
//		{
//			if (action == COPY)
//			{
//				return;
//			}
//		}
//
//	}
public Hashtable<Object, Object> createState(CharacterFacade character, ListFacade<AbilityCategoryFacade> categories, ListFacade<AbilityCategoryFacade> fullCategoryList, String title) {
    Hashtable<Object, Object> state = new Hashtable<>();
    CategoryTableModel categoryTableModel = new CategoryTableModel(character, fullCategoryList, categoryBar, categoryTable);
    state.put(CategoryTableModel.class, categoryTableModel);
    ListSelectionModel listModel = new DefaultListSelectionModel();
    listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    state.put(ListSelectionModel.class, listModel);
    state.put(AbilityTreeTableModel.class, new AbilityTreeTableModel(character, categories));
    state.put(AvailableAbilityTreeViewModel.class, new AvailableAbilityTreeViewModel(character, fullCategoryList, listModel, title));
    //state.put(AbilityTransferHandler.class, new AbilityTransferHandler(character));
    state.put(InfoHandler.class, new InfoHandler(character, categories));
    state.put(TreeRendererHandler.class, new TreeRendererHandler(character));
    state.put(AddAction.class, new AddAction(character));
    state.put(RemoveAction.class, new RemoveAction(character));
    state.put(AbilityFilterHandler.class, new AbilityFilterHandler(character));
    state.put(CategoryFilterHandler.class, new CategoryFilterHandler(categoryTableModel));
    return state;
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) AbilityTreeTableModel(pcgen.gui2.tabs.ability.AbilityTreeTableModel) Hashtable(java.util.Hashtable) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 2 with CategoryTableModel

use of pcgen.gui2.tabs.ability.CategoryTableModel in project pcgen by PCGen.

the class AbilityChooserTab method storeState.

@Override
public void storeState(Hashtable<Object, Object> state) {
    ((InfoHandler) state.get(InfoHandler.class)).uninstall();
    ((AvailableAbilityTreeViewModel) state.get(AvailableAbilityTreeViewModel.class)).uninstall();
    categoryTable.setSelectionModel(new DefaultListSelectionModel());
    ((CategoryTableModel) state.get(CategoryTableModel.class)).uninstall();
    ((AddAction) state.get(AddAction.class)).uninstall();
    ((RemoveAction) state.get(RemoveAction.class)).uninstall();
    ((TreeRendererHandler) state.get(TreeRendererHandler.class)).uninstall();
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 3 with CategoryTableModel

use of pcgen.gui2.tabs.ability.CategoryTableModel in project pcgen by PCGen.

the class AbilityChooserTab method ensureCategorySelected.

/**
	 * Ensure that when the tab is displayed a category is selected if any are
	 * available.
	 */
private void ensureCategorySelected() {
    if (categoryTable.getSelectedRowCount() == 0) {
        CategoryTableModel model = (CategoryTableModel) categoryTable.getModel();
        model.refilter();
        if (model.getRowCount() > 0) {
            categoryTable.getSelectionModel().setSelectionInterval(0, 0);
        }
    }
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel)

Example 4 with CategoryTableModel

use of pcgen.gui2.tabs.ability.CategoryTableModel in project pcgen by PCGen.

the class AbilityChooserTab method adviseTodo.

@Override
public void adviseTodo(String fieldName) {
    CategoryTableModel model = (CategoryTableModel) categoryTable.getModel();
    model.refilter();
    for (int i = 0; i < model.getRowCount(); i++) {
        AbilityCategoryFacade category = model.getCategory(i);
        if (category.getName().equals(fieldName)) {
            categoryTable.getSelectionModel().setSelectionInterval(i, i);
            return;
        }
    }
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade)

Aggregations

CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)4 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)2 Hashtable (java.util.Hashtable)1 ListSelectionModel (javax.swing.ListSelectionModel)1 AbilityCategoryFacade (pcgen.facade.core.AbilityCategoryFacade)1 AbilityTreeTableModel (pcgen.gui2.tabs.ability.AbilityTreeTableModel)1