Search in sources :

Example 1 with AbilityTreeTableModel

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

the class AbilityTreeTableModel method initializeTreeTable.

/**
	 * Initialise a tree table that will be backed by an AbilityTreeTableModel.
	 * @param treeTable The tree table to be initialized.
	 */
public static void initializeTreeTable(JTreeTable treeTable) {
    //$NON-NLS-1$ //$NON-NLS-2$
    treeTable.getTree().putClientProperty("JTree.lineStyle", "Horizontal");
    treeTable.setAutoCreateColumnsFromModel(false);
    DefaultTableColumnModel model = new DefaultTableColumnModel();
    TableCellRenderer headerRenderer = treeTable.getTableHeader().getDefaultRenderer();
    model.addColumn(Utilities.createTableColumn(0, "in_featSelectedAbilities", headerRenderer, //$NON-NLS-1$
    true));
    model.addColumn(//$NON-NLS-1$
    Utilities.createTableColumn(//$NON-NLS-1$
    1, //$NON-NLS-1$
    "in_featChoices", headerRenderer, true));
    treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    treeTable.setColumnModel(model);
    treeTable.setDefaultRenderer(String.class, new TableCellUtilities.AlignRenderer(SwingConstants.LEFT, true));
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities)

Example 2 with AbilityTreeTableModel

use of pcgen.gui2.tabs.ability.AbilityTreeTableModel 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)

Aggregations

Hashtable (java.util.Hashtable)1 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)1 ListSelectionModel (javax.swing.ListSelectionModel)1 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 AbilityTreeTableModel (pcgen.gui2.tabs.ability.AbilityTreeTableModel)1 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)1 TableCellUtilities (pcgen.gui2.util.table.TableCellUtilities)1