From: <cpm...@us...> - 2011-11-15 00:23:24
|
Revision: 15535 http://pcgen.svn.sourceforge.net/pcgen/?rev=15535&view=rev Author: cpmeister Date: 2011-11-15 00:23:17 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Changed SpellSupportFacade Modified Paths: -------------- sandbox/uisync/code/src/java/pcgen/core/facade/SpellSupportFacade.java sandbox/uisync/code/src/java/pcgen/gui2/facade/SpellSupportFacadeImpl.java sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellNodeDataView.java sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellTreeViewModel.java Modified: sandbox/uisync/code/src/java/pcgen/core/facade/SpellSupportFacade.java =================================================================== --- sandbox/uisync/code/src/java/pcgen/core/facade/SpellSupportFacade.java 2011-11-14 22:29:50 UTC (rev 15534) +++ sandbox/uisync/code/src/java/pcgen/core/facade/SpellSupportFacade.java 2011-11-15 00:23:17 UTC (rev 15535) @@ -29,20 +29,20 @@ public interface SpellSupportFacade { - public ListFacade<SpellNode> getAvailableSpellNodes(); + public ListFacade<? extends SuperNode> getAvailableSpellNodes(); /** * The returned list will be used to build the tree for all known spells. This includes * known spells, innate spells, etc... * @return a list containing the nodes for all known spells */ - public ListFacade<SpellNode> getAllKnownSpellNodes(); + public ListFacade<? extends SuperNode> getAllKnownSpellNodes(); - public ListFacade<SpellNode> getKnownSpellNodes(); + public ListFacade<? extends SuperNode> getKnownSpellNodes(); - public ListFacade<SpellNode> getPreparedSpellNodes(); + public ListFacade<? extends SuperNode> getPreparedSpellNodes(); - public ListFacade<SpellNode> getBookSpellNodes(); + public ListFacade<? extends SuperNode> getBookSpellNodes(); /** * Adds the spell identified by the <code>SpellNode</code> to the list of known spells for @@ -90,9 +90,25 @@ */ public String getClassInfo(ClassFacade spellcaster); - public static interface SpellNode + public static interface SuperNode { + } + public static interface RootNode extends SuperNode + { + } + + public static interface SpellListNode extends RootNode + { + } + + public static interface SpellBookNode extends RootNode + { + } + + public static interface SpellNode extends SuperNode + { + public ClassFacade getSpellcastingClass(); public String getSpellLevel(); @@ -106,7 +122,7 @@ * the root is the spell book name etc... * @return the root node string */ - public String getRootNode(); + public RootNode getRootNode(); } Modified: sandbox/uisync/code/src/java/pcgen/gui2/facade/SpellSupportFacadeImpl.java =================================================================== --- sandbox/uisync/code/src/java/pcgen/gui2/facade/SpellSupportFacadeImpl.java 2011-11-14 22:29:50 UTC (rev 15534) +++ sandbox/uisync/code/src/java/pcgen/gui2/facade/SpellSupportFacadeImpl.java 2011-11-15 00:23:17 UTC (rev 15535) @@ -31,6 +31,7 @@ import javax.swing.JOptionPane; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import pcgen.base.lang.StringUtil; @@ -263,7 +264,7 @@ { pc.setDirty(true); SpellNodeImpl spellListNode = - new SpellNodeImpl(null, null, "", spellList); + new SpellNodeImpl(null, null, "", new RootNodeImpl(spellList)); preparedSpellNodes.addElement(spellListNode); preparedSpellLists.add(spellListNode); } @@ -563,7 +564,7 @@ SpellNodeImpl node = new SpellNodeImpl(spellImplem, pcClass, String.valueOf(spellInfo.getActualLevel()), - isKnown ? null : book); + isKnown ? null : new RootNodeImpl(book)); boolean isSpellBook = pc.getSpellBookByName(book).getType() == SpellBook.TYPE_SPELL_BOOK; // Add to list @@ -589,7 +590,7 @@ if (spellBook.getType() == SpellBook.TYPE_PREPARED_LIST) { SpellNodeImpl spellListNode = - new SpellNodeImpl(null, null, "", spellBook.getName()); + new SpellNodeImpl(null, null, "", new RootNodeImpl(spellBook.getName())); preparedSpellLists.add(spellListNode); addDummyNodeIfSpellListEmpty(spellBook.getName()); } @@ -637,7 +638,7 @@ SpellNodeImpl node = new SpellNodeImpl(spellImplem, spell.getSpellcastingClass(), String.valueOf(spellInfo.getActualLevel()), isKnown ? null - : bookName); + : new RootNodeImpl(bookName)); return node; } @@ -697,8 +698,51 @@ return castingClasses; } + public class RootNodeImpl implements RootNode + { - + private final String text; + + public RootNodeImpl(String text) + { + this.text = text; + } + + @Override + public String toString() + { + return text; + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 83 * hash + (this.text != null ? this.text.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final RootNodeImpl other = (RootNodeImpl) obj; + if ((this.text == null) ? (other.text != null) : !this.text.equals(other.text)) + { + return false; + } + return true; + } + + } + /** * The Class <code>SpellNodeImpl</code> holds the information required to * display and process a spell. It covers spells that are available, known, @@ -708,19 +752,20 @@ */ public class SpellNodeImpl implements SpellNode { + private final SpellFacade spell; private final ClassFacade cls; - private final String rootNode; + private final RootNode rootNode; private final String level; - public SpellNodeImpl (SpellFacade spell, ClassFacade cls, String level, String rootNode) + public SpellNodeImpl(SpellFacade spell, ClassFacade cls, String level, RootNode rootNode) { this.spell = spell; this.cls = cls; this.level = level; this.rootNode = rootNode; } - + /* (non-Javadoc) * @see pcgen.core.facade.SpellSupportFacade.SpellNode#getSpellcastingClass() */ @@ -748,7 +793,7 @@ /* (non-Javadoc) * @see pcgen.core.facade.SpellSupportFacade.SpellNode#getRootNode() */ - public String getRootNode() + public RootNode getRootNode() { return rootNode; } Modified: sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellNodeDataView.java =================================================================== --- sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellNodeDataView.java 2011-11-14 22:29:50 UTC (rev 15534) +++ sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellNodeDataView.java 2011-11-15 00:23:17 UTC (rev 15535) @@ -5,11 +5,12 @@ import org.apache.commons.lang.StringUtils; import pcgen.core.facade.SpellFacade; import pcgen.core.facade.SpellSupportFacade.SpellNode; +import pcgen.core.facade.SpellSupportFacade.SuperNode; import pcgen.gui2.util.treeview.DataView; import pcgen.gui2.util.treeview.DataViewColumn; import pcgen.gui2.util.treeview.DefaultDataViewColumn; -class SpellNodeDataView implements DataView<SpellNode> +class SpellNodeDataView implements DataView<SuperNode> { private final List<? extends DataViewColumn> columns; @@ -26,17 +27,24 @@ new DefaultDataViewColumn("Source", String.class)); } - public List<?> getData(SpellNode obj) + public List<?> getData(SuperNode obj) { - SpellFacade spell = obj.getSpell(); - if (spell == null) + if (obj instanceof SpellNode) { + SpellFacade spell = ((SpellNode) obj).getSpell(); + if (spell == null) + { + return Arrays.asList(null, null, null, null, null, null, null); + } + return Arrays.asList(spell.getSchool(), spell.getSubschool(), + StringUtils.join(spell.getDescriptors(), ", "), + spell.getComponents(), spell.getRange(), + spell.getDuration(), spell.getSource()); + } + else + { return Arrays.asList(null, null, null, null, null, null, null); } - return Arrays.asList(spell.getSchool(), spell.getSubschool(), - StringUtils.join(spell.getDescriptors(), ", "), - spell.getComponents(), spell.getRange(), - spell.getDuration(), spell.getSource()); } public List<? extends DataViewColumn> getDataColumns() Modified: sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellTreeViewModel.java =================================================================== --- sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellTreeViewModel.java 2011-11-14 22:29:50 UTC (rev 15534) +++ sandbox/uisync/code/src/java/pcgen/gui2/tabs/spells/SpellTreeViewModel.java 2011-11-15 00:23:17 UTC (rev 15535) @@ -21,9 +21,11 @@ package pcgen.gui2.tabs.spells; import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; -import pcgen.core.facade.CharacterFacade; import pcgen.core.facade.SpellSupportFacade.SpellNode; +import pcgen.core.facade.SpellSupportFacade.SuperNode; import pcgen.core.facade.util.DefaultListFacade; import pcgen.core.facade.util.ListFacade; import pcgen.gui2.util.treeview.DataView; @@ -35,21 +37,21 @@ * * @author Connor Petty <cpm...@us...> */ -public class SpellTreeViewModel implements TreeViewModel<SpellNode> +public class SpellTreeViewModel implements TreeViewModel<SuperNode> { private final SpellNodeDataView dataView; - private final ListFacade<SpellNode> spellNodes; + private final ListFacade<? extends SuperNode> spellNodes; private final ListFacade<SpellTreeView> treeViews; - public SpellTreeViewModel(ListFacade<SpellNode> spellNodes, boolean showcolumns) + public SpellTreeViewModel(ListFacade<? extends SuperNode> spellNodes, boolean showcolumns) { this.spellNodes = spellNodes; this.treeViews = new DefaultListFacade<SpellTreeView>(Arrays.asList(SpellTreeView.values())); this.dataView = new SpellNodeDataView(showcolumns); } - public ListFacade<? extends TreeView<SpellNode>> getTreeViews() + public ListFacade<? extends TreeView<SuperNode>> getTreeViews() { return treeViews; } @@ -59,17 +61,17 @@ return 0; } - public DataView<SpellNode> getDataView() + public DataView<SuperNode> getDataView() { return dataView; } - public ListFacade<SpellNode> getDataModel() + public ListFacade<SuperNode> getDataModel() { - return spellNodes; + return (ListFacade<SuperNode>) spellNodes; } - private enum SpellTreeView implements TreeView<SpellNode> + private enum SpellTreeView implements TreeView<SuperNode> { CLASS_LEVEL_SPELL("Class/Level/Spell"); @@ -86,24 +88,33 @@ } @SuppressWarnings("unchecked") - public List<TreeViewPath<SpellNode>> getPaths(SpellNode pobj) + public List<TreeViewPath<SuperNode>> getPaths(SuperNode node) { - TreeViewPath<SpellNode> path; - switch (this) + TreeViewPath<SuperNode> path; + if (node instanceof SpellNode) { - case CLASS_LEVEL_SPELL: - if (pobj.getRootNode() == null) - { - path = new TreeViewPath<SpellNode>(pobj, pobj.getSpellcastingClass(), pobj.getSpellLevel()); - } - else - { - path = new TreeViewPath<SpellNode>(pobj, pobj.getRootNode(), pobj.getSpellcastingClass(), pobj.getSpellLevel()); - } - break; - default: - throw new InternalError(); + SpellNode pobj = (SpellNode) node; + switch (this) + { + case CLASS_LEVEL_SPELL: + LinkedList<Object> pathList = new LinkedList<Object>(); + Collections.addAll(pathList, pobj.getRootNode(), pobj.getSpellcastingClass(), pobj.getSpellLevel()); + pathList.removeAll(Collections.singleton(null)); + if (pobj.getSpell() == null) + { + pathList.removeLast(); + } + path = new TreeViewPath<SuperNode>(pobj, pathList.toArray()); + break; + default: + throw new InternalError(); + } + } + else + { + path = new TreeViewPath<SuperNode>(node); + } return Arrays.asList(path); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |