|
From: <jde...@us...> - 2006-03-01 11:59:47
|
Revision: 43 Author: jdempsey Date: 2006-03-01 03:58:57 -0800 (Wed, 01 Mar 2006) ViewCVS: http://svn.sourceforge.net/pcgen/?rev=43&view=rev Log Message: ----------- Spells tab revamp pt1 [ 1082837 ] Some classes need both spellbooks and memorised spell lists [ 1094612 ] Pages for Spellbook [ 1104393 ] Spellbook as containers [ 1199739 ] Prepared Spells spell book on Spells tab Modified Paths: -------------- Trunk/pcgen/build.xml Trunk/pcgen/code/src/java/pcgen/core/Constants.java Trunk/pcgen/code/src/java/pcgen/core/GameMode.java Trunk/pcgen/code/src/java/pcgen/core/Globals.java Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java Trunk/pcgen/code/src/java/pcgen/core/utils/IntegerKey.java Trunk/pcgen/code/src/java/pcgen/core/utils/StringKey.java Trunk/pcgen/code/src/java/pcgen/gui/filter/FilterDialogFactory.java Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSpells.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java Trunk/pcgen/code/src/java/pcgen/gui/utils/Utility.java Trunk/pcgen/code/src/java/pcgen/io/IOConstants.java Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Creator.java Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java Trunk/pcgen/code/src/java/plugin/charactersheet/gui/ClassSpellLevelPane.java Added Paths: ----------- Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoKnownSpells.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoPreparedSpells.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoSpellBooks.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoSpellsSubTab.java Trunk/pcgen/code/src/java/plugin/lsttokens/equipment/NumPagesToken.java Trunk/pcgen/code/src/java/plugin/lsttokens/equipment/PageUsageToken.java Property Changed: ---------------- Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java Modified: Trunk/pcgen/build.xml =================================================================== --- Trunk/pcgen/build.xml 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/build.xml 2006-03-01 11:58:57 UTC (rev 43) @@ -2294,6 +2294,20 @@ </patternset> </fileset> </jar> + <jar jarfile="${lstplugins.dir}/EquipmentLstToken-NUMPAGES.jar" manifest="${src.java.dir}/plugin/lsttokens/manifest.mf"> + <fileset dir="${build.classes.dir}"> + <patternset> + <include name="plugin/lsttokens/equipment/NumPagesToken.class" /> + </patternset> + </fileset> + </jar> + <jar jarfile="${lstplugins.dir}/EquipmentLstToken-PAGEUSAGE.jar" manifest="${src.java.dir}/plugin/lsttokens/manifest.mf"> + <fileset dir="${build.classes.dir}"> + <patternset> + <include name="plugin/lsttokens/equipment/PageUsageToken.class" /> + </patternset> + </fileset> + </jar> <jar jarfile="${lstplugins.dir}/EquipmentLstToken-PROFICIENCY.jar" manifest="${src.java.dir}/plugin/lsttokens/manifest.mf"> <fileset dir="${build.classes.dir}"> <patternset> Modified: Trunk/pcgen/code/src/java/pcgen/core/Constants.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Constants.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/Constants.java 2006-03-01 11:58:57 UTC (rev 43) @@ -123,6 +123,9 @@ /** htmlxml */ String s_standard_outputsheet_directory = "htmlxml"; + // Types + String s_TYPE_SPELLBOOK= "SPELLBOOK"; + /** Tab names */ String[] tabNames = { @@ -142,6 +145,9 @@ "Resources", "TempMod", "NaturalWeapons", + "Known", + "Prepared", + "Spellbooks", }; // Encumberence Constants (String) @@ -347,6 +353,12 @@ int TAB_TEMPBONUS = 14; /** 15 */ int TAB_NATWEAPONS = 15; + /** 16 */ + int TAB_KNOWN_SPELLS = 16; + /** 17 */ + int TAB_PREPARED_SPELLS = 17; + /** 18 */ + int TAB_SPELLBOOKS = 18; /** For accessing <code>CategorisableStore</code>. */ Modified: Trunk/pcgen/code/src/java/pcgen/core/GameMode.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/GameMode.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/GameMode.java 2006-03-01 11:58:57 UTC (rev 43) @@ -188,6 +188,9 @@ tInfo[Constants.TAB_SPELLS].tabName = "in_spells"; tInfo[Constants.TAB_SUMMARY].tabName = "in_summary"; tInfo[Constants.TAB_SOURCES].tabName = "Source Materials"; + tInfo[Constants.TAB_KNOWN_SPELLS].tabName = "in_known_spells"; + tInfo[Constants.TAB_PREPARED_SPELLS].tabName = "in_prepared_spells"; + tInfo[Constants.TAB_SPELLBOOKS].tabName = "in_spellbooks"; } /** Modified: Trunk/pcgen/code/src/java/pcgen/core/Globals.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Globals.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/Globals.java 2006-03-01 11:58:57 UTC (rev 43) @@ -197,6 +197,8 @@ public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** EMPTY_STRING_ARRAY*/ public static final String[] EMPTY_STRING_ARRAY = new String[0]; + /** Name of the default innate spell book. */ + public static final String INNATE_SPELL_BOOK_NAME = "Innate"; static { Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2006-03-01 11:58:57 UTC (rev 43) @@ -521,6 +521,44 @@ } /** + * Set the number of pages for this object + * @param aString + */ + public final void setNumPages(final int value) + { + integerChar.setCharacteristic(IntegerKey.NUM_PAGES, value); + } + + /** + * Get the number of pages of this object + * @return the number of pages of this object + */ + public final int getNumPages() + { + Integer characteristic = integerChar.getCharacteristic(IntegerKey.NUM_PAGES); + return characteristic == null ? 0 : characteristic.intValue(); + } + + /** + * Set the page usage formula for this object + * @param aString + */ + public final void setPageUsage(final String aString) + { + stringChar.setCharacteristic(StringKey.PAGE_USAGE, aString); + } + + /** + * Get the page usage formula of this object + * @return the page usage formula of this object + */ + public final String getPageUsage() + { + String characteristic = stringChar.getCharacteristic(StringKey.PAGE_USAGE); + return characteristic == null ? "" : characteristic; + } + + /** * Get the list of temporary bonuses for this list * @return the list of temporary bonuses for this list */ Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-03-01 11:58:57 UTC (rev 43) @@ -64,6 +64,7 @@ public static final int MONKBONUS = 4; private static final BigDecimal BIG_ONE = new BigDecimal("1.00"); private static String lastVariable = null; + //TODO: These are never actually set to a non empty/zero value. Can the code be removed? private static String loopVariable = ""; private static int loopValue = 0; @@ -121,6 +122,7 @@ private List pcLevelInfo = new ArrayList(); private List processedBonusList = new ArrayList(); private final List spellBooks = new ArrayList(); + private Map spellBookMap = new HashMap(); private List tempBonusItemList = new ArrayList(); private List tempBonusList = new ArrayList(); private Set tempBonusFilters = new TreeSet(); @@ -254,8 +256,10 @@ miscList.add(""); miscList.add(""); miscList.add(""); - addSpellBook(Globals.getDefaultSpellBook()); - addSpellBook("Innate"); + addSpellBook(new SpellBook(Globals.getDefaultSpellBook(), + SpellBook.TYPE_KNOWN_SPELLS)); + addSpellBook(new SpellBook(Globals.INNATE_SPELL_BOOK_NAME, + SpellBook.TYPE_KNOWN_SPELLS)); populateSkills(SettingsHandler.getSkillsTab_IncludeSkills()); spellTracker = new PCSpellTracker(this); setStringFor(StringKey.HANDED, "Right"); @@ -2827,6 +2831,36 @@ } /** + * Set the name of the spellbook to auto add new known spells to. + * @param aString The new spellbook name. + */ + public void setSpellBookNameToAutoAddKnown(final String aString) + { + setStringFor(StringKey.SPELLBOOK_AUTO_ADD_KNOWN, aString); + } + + /** + * Get the name of the spellbook to auto add new known spells to. + * @return spellbook name + */ + public String getSpellBookNameToAutoAddKnown() + { + return getSafeStringFor(StringKey.SPELLBOOK_AUTO_ADD_KNOWN); + } + + + /** + * Retrieve a spell book object given the name of the spell book. + * + * @param name The name of the spell book to be retrieved. + * @return The spellbook (or null if not present). + */ + public SpellBook getSpellBookByName(final String name) + { + return (SpellBook) spellBookMap.get(name); + } + + /** * Get spell books * @return spellBooks */ @@ -3615,6 +3649,13 @@ { equipmentMasterList.add(eq); } + + if (eq.isType(Constants.s_TYPE_SPELLBOOK)) + { + SpellBook book = new SpellBook(eq.getName(), SpellBook.TYPE_SPELL_BOOK); + book.setEquip(eq); + addSpellBook(book); + } setDirty(true); } @@ -3955,6 +3996,11 @@ public void removeEquipment(final Equipment eq) { + if (eq.isType(Constants.s_TYPE_SPELLBOOK)) + { + delSpellBook(eq.getName()); + } + equipmentList.remove(eq); equipmentMasterList.remove(eq); setDirty(true); @@ -7482,6 +7528,9 @@ specialKnown = aClass.getSpecialtyKnownForLevel(aClass.getLevel(), spellLevel, this); } + SpellBook spellBook = getSpellBookByName(bookName); + int numPages = 0; + // known is the maximun spells that can be known this level // listNum is the current spells already memorized this level // cast is the number of spells that can be cast at this level @@ -7489,12 +7538,21 @@ // lower-level spells // in re BUG [569517] // sk4p 13 Dec 2002 - if (aClass.getMemorizeSpells() && aClass.getSpellBookUsed() && !isDefault) + if (spellBook.getType() == SpellBook.TYPE_SPELL_BOOK) { - // If a class can Memorize spells and this is not - // the default spellbook, then let them add as many - // spells as they want to. This is to simulate finding - // a spellbook with spells in it. + // If this is a spellbook rather than known spells + // or prepared spells, then let them add spells up to + // the page limit of the book. + setSpellLevelTemp(spellLevel); + numPages = getVariableValue(acs.getSpell(), + spellBook.getPageFormula(), "").intValue(); + // Check number of pages remaining in the book + if (numPages+spellBook.getNumPagesUsed() > spellBook.getNumPages()) + { + return "There are not enough pages left to add this spell to the spell book."; + } + spellBook.setNumPagesUsed(numPages+spellBook.getNumPagesUsed()); + spellBook.setNumSpells(spellBook.getNumSpells() + 1); } else if (!aClass.getMemorizeSpells() && !availableSpells(adjSpellLevel, aClass, bookName, true, acs.isSpecialtySpell(), this)) @@ -7591,10 +7649,12 @@ { final Ability aFeat = (Ability) fi.next(); ppCost += (int)aFeat.bonusTo("PPCOST", theSpell.getName(), this, this); - } + } si.setActualPPCost(ppCost); } } + // Set number of pages on the spell + si.setNumPages(numPages); setDirty(true); return ""; } @@ -7608,15 +7668,37 @@ { if (aName!=null && (aName.length() > 0) && !spellBooks.contains(aName)) { - spellBooks.add(aName); - setDirty(true); + return addSpellBook(new SpellBook(aName, + SpellBook.TYPE_PREPARED_LIST)); + } - return true; + return false; + } + + /** + * return value indicates if book was actually added or not + * @param aName + * @return TRUE or FALSE + */ + public boolean addSpellBook(final SpellBook book) + { + + if (book != null) + { + String aName = book.getName(); + if (!spellBooks.contains(aName)) + { + spellBooks.add(aName); + spellBookMap.put(aName, book); + setDirty(true); + + return true; + } } return false; } - + public PCTemplate addTemplate(final PCTemplate inTemplate) { if (inTemplate == null) @@ -8709,6 +8791,13 @@ + " even though it is an auto known spell"); } + SpellBook spellBook = getSpellBookByName(bookName); + if (spellBook.getType() == SpellBook.TYPE_SPELL_BOOK) + { + spellBook.setNumPagesUsed(spellBook.getNumPagesUsed() + - si.getNumPages()); + spellBook.setNumSpells(spellBook.getNumSpells() - 1); + } si.setTimes(si.getTimes() - 1); if (si.getTimes() <= 0) @@ -8964,24 +9053,48 @@ */ public boolean delSpellBook(final String aName) { - if ((aName.length() > 0) && !aName.equals(Globals.getDefaultSpellBook()) && spellBooks.contains(aName)) + if ((aName.length() > 0) + && !aName.equals(Globals.getDefaultSpellBook()) + && spellBooks.contains(aName)) { - spellBooks.remove(aName); - setDirty(true); + return delSpellBook((SpellBook) spellBookMap.get(aName)); + } - for (Iterator i = classList.iterator(); i.hasNext();) + return false; + } + + /** + * return value indicates whether or not a book was actually removed + * @param aName + * @return true or false + */ + public boolean delSpellBook(final SpellBook book) + { + if (book != null) + { + String aName = book.getName(); + if (!aName.equals(Globals.getDefaultSpellBook()) + && spellBooks.contains(aName)) { - final PCClass aClass = (PCClass) i.next(); - final List aList = aClass.getSpellSupport().getCharacterSpell(null, aName, -1); + spellBooks.remove(aName); + spellBookMap.remove(aName); + setDirty(true); - for (int j = aList.size() - 1; j >= 0; --j) + for (Iterator i = classList.iterator(); i.hasNext();) { - final CharacterSpell cs = (CharacterSpell) aList.get(j); - cs.removeSpellInfo(cs.getSpellInfoFor(aName, -1, -1)); + final PCClass aClass = (PCClass) i.next(); + final List aList = aClass.getSpellSupport() + .getCharacterSpell(null, aName, -1); + + for (int j = aList.size() - 1; j >= 0; --j) + { + final CharacterSpell cs = (CharacterSpell) aList.get(j); + cs.removeSpellInfo(cs.getSpellInfoFor(aName, -1, -1)); + } } + + return true; } - - return true; } return false; @@ -11237,6 +11350,11 @@ } } + /** + * Scan through the list of doains the character has to ensure that + * they are all still valid. Any invalid domains will be removed from + * the character. + */ void validateCharacterDomains() { if (!isImporting()) Added: Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java (rev 0) +++ Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java 2006-03-01 11:58:57 UTC (rev 43) @@ -0,0 +1,233 @@ +/* + * SpellBook.java + * Copyright 2006 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Jan 6, 2006 + * + * $Id: $ + * + */ +package pcgen.core.character; + +import pcgen.core.Equipment; + +/** + * <code>SpellBook</code> contains details of a prepared spell list or + * a spell book. The term spell book was used as that is the term used + * throughout the rest of the code. + * + * Last Editor: $Author: $ + * Last Edited: $Date: $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: $ + */ + +public class SpellBook +{ + + /** Spell book type indicating a list of known spells. */ + public static final int TYPE_KNOWN_SPELLS = 1; + /** Spell book type indicating a list of prepared spells. */ + public static final int TYPE_PREPARED_LIST = 2; + /** Spell book type indicating a written spell book. */ + public static final int TYPE_SPELL_BOOK = 3; + + private String name; + private int type; + private int numPages; + private int numPagesUsed; + private int numSpells; + private String pageFormula; + private String description; + private Equipment equip; + + /** + * Create a new spell book with the basic details. + * + * @param name The name of the spellbook + * @param type The type of spell book, be it prepared spells or written book. + */ + public SpellBook(String name, int type) + { + super(); + + this.name = name; + this.type = type; + } + + + /** + * @see java.lang.Object#toString() + */ + public String toString() + { + StringBuffer result = new StringBuffer(name); + if (type == TYPE_SPELL_BOOK) + { + result.append(" ["); + result.append(numPagesUsed); + result.append("/"); + result.append(numPages); + result.append("]"); + } + return result.toString(); + } + + /** + * @return Returns the description. + */ + public final String getDescription() + { + return description; + } + + /** + * @param description The description to set. + */ + public final void setDescription(String description) + { + this.description = description; + } + + /** + * @return Returns the equip. + */ + public final Equipment getEquip() + { + return equip; + } + + /** + * @param equip The equip to set. + */ + public final void setEquip(Equipment equip) + { + this.equip = equip; + this.setNumPages(equip.getNumPages()); + this.setPageFormula(equip.getPageUsage()); + } + + /** + * @return Returns the name. + */ + public final String getName() + { + return name; + } + + /** + * @param name The name to set. + */ + public final void setName(String name) + { + this.name = name; + } + + /** + * Get the number of pages in the book. + * @return Returns the numPages. + */ + public final int getNumPages() + { + return numPages; + } + + /** + * Set the number of pages in the book. + * @param numPages The numPages to set. + */ + public final void setNumPages(int numPages) + { + this.numPages = numPages; + } + + /** + * Get the pageFormula + * @return Returns the pageFormula. + */ + public final String getPageFormula() + { + return pageFormula; + } + + /** + * Set the page formula + * @param pageFormula The pageFormula to set. + */ + public final void setPageFormula(String pageFormula) + { + this.pageFormula = pageFormula; + } + + /** + * Get the spell book type. + * @return Returns the type. + */ + public final int getType() + { + return type; + } + + /** + * Set the spell book type. + * @param type The type to set. + */ + public final void setType(int type) + { + this.type = type; + } + + + /** + * Get the number of pages used. + * @return The number of pages used. + */ + public final int getNumPagesUsed() + { + return numPagesUsed; + } + + + /** + * Set the number of pages used. + * @param numPagesUsed The number of pages used. + */ + public final void setNumPagesUsed(int numPagesUsed) + { + this.numPagesUsed = numPagesUsed; + } + + + /** + * @return Returns the numSpells. + */ + public final int getNumSpells() + { + return numSpells; + } + + + /** + * @param numSpells The numSpells to set. + */ + public final void setNumSpells(int numSpells) + { + this.numSpells = numSpells; + } + +} \ No newline at end of file Modified: Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java 2006-03-01 11:58:57 UTC (rev 43) @@ -48,6 +48,7 @@ private int actualLevel = -1; private int times; // times the spell is in this list private int actualPPCost = -1; + private int numPages = 0; /** * added package-private constructor to enforce usage of public constructor @@ -113,6 +114,16 @@ return times; } + public final int getNumPages() + { + return numPages; + } + + public final void setNumPages(int numPages) + { + this.numPages = numPages; + } + public void addFeatsToList(final List aList) { if (featList == null) Modified: Trunk/pcgen/code/src/java/pcgen/core/utils/IntegerKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/utils/IntegerKey.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/utils/IntegerKey.java 2006-03-01 11:58:57 UTC (rev 43) @@ -26,7 +26,7 @@ /** * @author Tom Parker <th...@so...> * - * This is a Typesafe enumeration of legal String Characteristics of an object. + * This is a Typesafe enumeration of legal Integer Characteristics of an object. */ public final class IntegerKey { @@ -39,6 +39,8 @@ public static final IntegerKey HIT_DIE = new IntegerKey(); /** Key to a characteristic defining the level of the object. */ public static final IntegerKey LEVEL = new IntegerKey(); + /** Key to a characteristic defining the number of pages of the object. */ + public static final IntegerKey NUM_PAGES = new IntegerKey(); /** Key to a characteristic defining the loading rank of the object. */ public static final IntegerKey RANK = new IntegerKey(); /** Key to a characteristic defining how visible the object is. */ Modified: Trunk/pcgen/code/src/java/pcgen/core/utils/StringKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/utils/StringKey.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/core/utils/StringKey.java 2006-03-01 11:58:57 UTC (rev 43) @@ -68,6 +68,7 @@ public static final StringKey MASTER_HP_FORMULA = new StringKey(); public static final StringKey NAME = new StringKey(); public static final StringKey OUTPUT_NAME = new StringKey(); + public static final StringKey PAGE_USAGE = new StringKey(); public static final StringKey PHOBIAS = new StringKey(); public static final StringKey PLAYERS_NAME = new StringKey(); public static final StringKey PORTRAIT_PATH = new StringKey(); @@ -82,6 +83,7 @@ public static final StringKey SKIN_COLOR = new StringKey(); public static final StringKey SOURCE_FILE = new StringKey(); public static final StringKey SPEECH_TENDENCY = new StringKey(); + public static final StringKey SPELLBOOK_AUTO_ADD_KNOWN = new StringKey(); public static final StringKey SR_FORMULA = new StringKey(); public static final StringKey SUB_REGION = new StringKey(); public static final StringKey TEMP_DESCRIPTION = new StringKey(); Modified: Trunk/pcgen/code/src/java/pcgen/gui/filter/FilterDialogFactory.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/filter/FilterDialogFactory.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/gui/filter/FilterDialogFactory.java 2006-03-01 11:58:57 UTC (rev 43) @@ -753,8 +753,6 @@ availableModel.clear(); selectedModel.clear(); -// availableModel.addElement("Active tab does not support filtering."); -// selectedModel.addElement("Active tab does not support filtering."); availableModel.addElement(displayOnlyFilter); selectedModel.addElement(displayOnlyFilter); Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-03-01 11:58:57 UTC (rev 43) @@ -103,6 +103,12 @@ in_InfoTempMod=Temporary Bonuses +in_InfoKnown=Known Spells + +in_InfoPrepared=Prepared Spells + +in_InfoSpellbooks=Spell Books + #Other Universal stuff in_sourceLabel=Source @@ -2515,6 +2521,10 @@ InfoSpells.level.title=Level\u003A +InfoSpells.print=Print + +InfoSpells.print.preview=Print Preview + InHandEquipped=Treat Weapons In Hand As Equipped For Attacks InfoSpells.add=Add @@ -2831,8 +2841,32 @@ InfoSpells.remove.spell=Remove Spell from Spellbook +InfoSpells.set.auto.book=Auto add new known spells to Spellbook + InfoSpells.Todo.Remain=Spells remain to be selected. +InfoKnownSpells.sort.avail.spells.by=Sort Spells By\u003A + +InfoKnownSpells.sort.select.spells.by=Sort Known Spells By\u003A + +InfoPreparedSpells.sort.avail.spells.by=Sort Known Spells By\u003A + +InfoPreparedSpells.sort.select.spells.by=Sort Prepared Spells By\u003A + +InfoPreparedSpells.metamagic=Metamagic Feat\u003A + +InfoPreparedSpells.preparedList=Spell List\u003A + +InfoPreparedSpells.add.list=Add a new prepared spell list. + +InfoPreparedSpells.del.list=Remove the prepared spell list. + +InfoPreparedSpells.add.list.fail=Could not add the prepared spell list {0}. + +InfoSpellBooks.sort.avail.spells.by=Sort Spells By\u003A + +InfoSpellBooks.sort.select.spells.by=Sort Recorded Spells By\u003A + #ToolBar Tips InfoSpells.source.title=SOURCE\u003A Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSpells.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSpells.java 2006-03-01 11:49:58 UTC (rev 42) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSpells.java 2006-03-01 11:58:57 UTC (rev 43) @@ -28,99 +28,47 @@ */ package pcgen.gui.tabs; -import pcgen.core.*; -import pcgen.core.bonus.Bonus; -import pcgen.core.bonus.BonusUtilities; -import pcgen.core.character.CharacterSpell; -import pcgen.core.character.SpellInfo; -import pcgen.core.spell.Spell; -import pcgen.core.utils.MessageType; -import pcgen.core.utils.ShowMessageDelegate; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JTabbedPane; +import javax.swing.SwingUtilities; + +import pcgen.core.Constants; +import pcgen.core.GameMode; +import pcgen.core.PlayerCharacter; +import pcgen.core.SettingsHandler; import pcgen.gui.CharacterInfoTab; -import pcgen.gui.GuiConstants; -import pcgen.gui.PCGen_Frame1; -import pcgen.gui.filter.FilterAdapterPanel; import pcgen.gui.filter.FilterConstants; -import pcgen.gui.filter.FilterFactory; -import pcgen.gui.panes.FlippingSplitPane; -import pcgen.gui.tabs.spells.SpellModel; -import pcgen.gui.utils.*; -import pcgen.util.FOPHandler; -import pcgen.util.Logging; +import pcgen.gui.filter.Filterable; +import pcgen.gui.tabs.spells.InfoKnownSpells; +import pcgen.gui.tabs.spells.InfoPreparedSpells; +import pcgen.gui.tabs.spells.InfoSpellBooks; import pcgen.util.PropertyFactory; -import pcgen.util.chooser.ChooserFactory; -import pcgen.util.chooser.ChooserInterface; -import javax.swing.*; -import javax.swing.border.TitledBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableColumn; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.event.*; -import java.io.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * <code>InfoSpells</code> creates a new tabbed panel. * - * @author Bryan McRoberts <mer...@us...>, Jayme Cox <jay...@ne...> - * created den 11 maj 2001 + * @author Bryan McRoberts <mer...@us...>, Jayme Cox <jay...@ne...>, James Dempsey <jde...@us...> * @version $Revision: 1.99 $ */ -public class InfoSpells extends FilterAdapterPanel implements CharacterInfoTab +public class InfoSpells extends JTabbedPane implements CharacterInfoTab, + Filterable { static final long serialVersionUID = 755097384157285101L; - private static List bookList = new ArrayList(); - private static String currSpellBook = Globals.getDefaultSpellBook(); - private static int splitOrientation = JSplitPane.HORIZONTAL_SPLIT; - private static int primaryViewMode = 0; - private static int secondaryViewMode = 1; - private static int primaryViewSelectMode = 0; - private static int secondaryViewSelectMode = 1; - private static boolean needsUpdate = true; - private static String addMsg = ""; - private final JLabel avaLabel = new JLabel(PropertyFactory.getString("InfoSpells.sort.spells.by")); //$NON-NLS-1$ - private final JLabel selLabel = new JLabel(PropertyFactory.getString("InfoSpells.sort.spellbooks.by")); //$NON-NLS-1$ - private FlippingSplitPane asplit; - private FlippingSplitPane bsplit; - private FlippingSplitPane splitPane; - private JButton addBookButton; - private JButton addSpellButton; - private JButton delBookButton; - private JButton delSpellButton; - private JButton printHtml; - private JButton printPdf; - private JButton selectSpellSheetButton = new JButton(PropertyFactory.getString("InfoSpells.select.spellsheet")); //$NON-NLS-1$ - private JCheckBox shouldAutoSpells = new JCheckBox(PropertyFactory.getString("InfoSpells.autoload")); //$NON-NLS-1$ - private JComboBoxEx primaryViewComboBox = new JComboBoxEx(); - private JComboBoxEx secondaryViewComboBox = new JComboBoxEx(); - private JComboBoxEx primaryViewSelectComboBox = new JComboBoxEx(); - private JComboBoxEx secondaryViewSelectComboBox = new JComboBoxEx(); - private JLabelPane classLabel = new JLabelPane(); - private JLabelPane infoLabel = new JLabelPane(); - private JMenuItem addMMMenu; - private JMenuItem addMenu; - private JPanel botPane = new JPanel(); - private JPanel topPane = new JPanel(); - private JTextField selectSpellSheetField = new JTextField(); - private JTextField spellBookNameText = new JTextField(); - private JTreeTable availableTable; // available Spells - private JTreeTable selectedTable; // spellbook Spells - private JTreeTableSorter availableSort = null; - private JTreeTableSorter selectedSort = null; - private Spell lastSpell = null; - private List characterMetaMagicFeats = new ArrayList(); - private SpellModel availableModel = null; // Model for JTreeTable - private SpellModel selectedModel = null; // Model for JTreeTable - private String lastClass = ""; //$NON-NLS-1$ - private TreePath selPath; - private boolean hasBeenSized = false; + private static final int KNOWN_INDEX = 0; + private static final int PREPARED_INDEX = 1; + private static final int SPELLBOOKS_INDEX = 2; + private InfoKnownSpells known; + private InfoPreparedSpells prepared; + private InfoSpellBooks spellbooks; + + private PlayerCharacter pc; private int serial = 0; private boolean readyForRefresh = false; @@ -133,24 +81,22 @@ public InfoSpells(PlayerCharacter pc) { this.pc = pc; + known = new InfoKnownSpells(pc); + prepared = new InfoPreparedSpells(pc); + spellbooks = new InfoSpellBooks(pc); + // do not remove this as we will use the component's name // to save component specific settings setName(Constants.tabNames[Constants.TAB_SPELLS]); - addMsg = SettingsHandler.getGame().getAddWithMetamagicMessage(); - if (addMsg.length() == 0) - { - addMsg = PropertyFactory.getString("InfoSpells.add.with.metamagic"); - } - SwingUtilities.invokeLater(new Runnable() + { + public void run() { - public void run() - { - initComponents(); - initActionListeners(); - } - }); + initComponents(); + // initActionListeners(); + } + }); } public void setPc(PlayerCharacter pc) @@ -158,8 +104,6 @@ if(this.pc != pc || pc.getSerial() > serial) { this.pc = pc; - selectedModel.setCharacter(pc); - availableModel.setCharacter(pc); serial = pc.getSerial(); forceRefresh(); } @@ -199,30 +143,9 @@ public List getToDos() { List toDoList = new ArrayList(); - - boolean hasFree = false; - for (Iterator iter = pc.getClassList().iterator(); iter.hasNext();) - { - PCClass aClass = (PCClass) iter.next(); - - if (((aClass.getKnownList().size() > 0) && aClass.getKnownList()!= null) || aClass.hasKnownSpells(pc) ) - { - int highestSpellLevel = aClass.getHighestLevelSpell(); - for (int i = 0; i <= highestSpellLevel; ++i) - { - if (pc.availableSpells(i, aClass, Globals.getDefaultSpellBook(), true, true, pc)) - { - hasFree = true; - break; - } - } - } - } - - if (hasFree) - { - toDoList.add(PropertyFactory.getString("InfoSpells.Todo.Remain")); //$NON-NLS-1$ - } + toDoList.addAll(known.getToDos()); + toDoList.addAll(prepared.getToDos()); + toDoList.addAll(spellbooks.getToDos()); return toDoList; } @@ -239,8 +162,11 @@ { if(readyForRefresh) { - needsUpdate = true; - updateCharacterInfo(); + setNeedsUpdate(true); + + known.setPc(pc); + prepared.setPc(pc); + spellbooks.setPc(pc); } else { @@ -248,6 +174,18 @@ } } + public void setNeedsUpdate(boolean b) + { + if (known == null) + { + return; + } + + known.setNeedsUpdate(b); + prepared.setNeedsUpdate(b); + spellbooks.setNeedsUpdate(b); + } + public JComponent getView() { return this; @@ -259,708 +197,168 @@ **/ public final boolean isMatchAnyEnabled() { + if (getSelectedIndex() == KNOWN_INDEX) + { + return known.isMatchAnyEnabled(); + } + else if (getSelectedIndex() == PREPARED_INDEX) + { + return prepared.isMatchAnyEnabled(); + } + else if (getSelectedIndex() == SPELLBOOKS_INDEX) + { + return spellbooks.isMatchAnyEnabled(); + } + return true; } /** - * @param flag - * @deprecated Unused -remove 5.9.5 - */ - public static void setNeedsUpdate(boolean flag) - { - needsUpdate = flag; - } - - /** * specifies whether the "negate/reverse" option should be available * @return true **/ public final boolean isNegateEnabled() { - return true; - } - - /** - * specifies the filter selection mode - * @return FilterConstants.DISABLED_MODE = -2 - **/ - public final int getSelectionMode() - { - return FilterConstants.DISABLED_MODE; - } - - /** - * implementation of Filterable interface - **/ - public final void initializeFilters() - { - FilterFactory.registerAllSourceFilters(this); - FilterFactory.registerAllSpellFilters(this); - - setKitFilter("SPELL"); //$NON-NLS-1$ - } - - /** - * implementation of Filterable interface - **/ - public final void refreshFiltering() - { - updateAvailableModel(); - updateSelectedModel(); - } - - /** - * set the class info text in the Class Info panel - * to the currently selected Character Class - * @param aClass - */ - private void setClassLabelText(PCClass aClass) - { - if (aClass != null) + if (getSelectedIndex() == KNOWN_INDEX) { - lastClass = aClass.getName(); - - int highestSpellLevel = aClass.getHighestLevelSpell(); - StringBuffer b = new StringBuffer(); - b.append("<html><table border=1><tr><td><font size=-2><b>"); //$NON-NLS-1$ - b.append(aClass.piSubString()).append(" ["); //$NON-NLS-1$ - b.append(String.valueOf(aClass.getLevel() + (int) pc.getTotalBonusTo("PCLEVEL", aClass.getName()))); //$NON-NLS-1$ - b.append("]</b></font></td>"); //$NON-NLS-1$ - - for (int i = 0; i <= highestSpellLevel; ++i) - { - b.append("<td><font size=-2><b><center> ").append(i).append(" </b></center></font></td>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - b.append("</tr>"); //$NON-NLS-1$ - b.append("<tr><td><font size=-1><b>Cast</b></font></td>"); //$NON-NLS-1$ - - for (int i = 0; i <= highestSpellLevel; ++i) - { - b.append("<td><font size=-1><center>").append(getNumCast(aClass, i, pc)).append("</center></font></td>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - // Making sure KnownList can be handled safely and produces the correct behaviour - if (((aClass.getKnownList().size() > 0) && aClass.getKnownList()!= null) || aClass.hasKnownSpells(pc) ) - { - b.append("<tr><td><font size=-1><b>Known</b></font></td>"); //$NON-NLS-1$ - - for (int i = 0; i <= highestSpellLevel; ++i) - { - final int a = aClass.getKnownForLevel(aClass.getLevel(), i, pc); - final int bonus = aClass.getSpecialtyKnownForLevel(aClass.getLevel(), i, pc); - StringBuffer bString = new StringBuffer(); - - if (bonus > 0) - { - bString.append('+').append(bonus); - } - - b.append("<td><font size=-1><center>").append(a).append(bString).append("</center></font></td>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - b.append("<tr><td><font size=-1><b>DC</b></font></td>"); //$NON-NLS-1$ - - for (int i = 0; i <= highestSpellLevel; ++i) - { - b.append("<td><font size=-1><center>").append(getDC(aClass, i, pc)).append("</center></font></td>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - b.append("</tr></table>"); //$NON-NLS-1$ - - b.append(PropertyFactory.getString("InfoSpells.caster.type")); //$NON-NLS-1$ - b.append("<b>").append(aClass.getSpellType()).append("</b><br>"); //$NON-NLS-1$ //$NON-NLS-2$ - b.append(PropertyFactory.getString("InfoSpells.stat.bonus")); //$NON-NLS-1$ - b.append("<b>").append(aClass.getSpellBaseStat()).append("</b><br>"); //$NON-NLS-1$ //$NON-NLS-2$ - - if (aClass.getSpecialtyListString(pc).length() != 0) - { - b.append(PropertyFactory.getString("InfoSpells.school")); //$NON-NLS-1$ - b.append("<b>").append(aClass.getSpecialtyListString(pc)).append("</b><br>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - if (aClass.getProhibitedString().length() != 0) - { - b.append(PropertyFactory.getString("InfoSpells.prohibited.school")); //$NON-NLS-1$ - b.append("<b>").append(aClass.getProhibitedString()).append("</b><br>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - String bString = aClass.getSource(); - - if (bString.length() > 0) - { - b.append("<b>").append(PropertyFactory.getString("InfoSpells.source")).append("</b>").append(bString); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - b.append("</html>"); //$NON-NLS-1$ - classLabel.setText(b.toString()); + return known.isNegateEnabled(); } - } - - private static int getDC(PCClass aClass, int level, PlayerCharacter pc) - { - Spell aSpell = new Spell(); - int DC = aSpell.getDCForPlayerCharacter(pc, null, aClass, level); - - return DC; - } - - /* - * set the spell Info text in the Spell Info panel to the - * currently selected spell - */ - private void setInfoLabelText(SpellInfo si) - { - if (si == null) + else if (getSelectedIndex() == PREPARED_INDEX) { - return; + return prepared.isNegateEnabled(); } - - CharacterSpell cs = si.getOwner(); - lastSpell = cs.getSpell(); //even if that's null - - Spell aSpell = lastSpell; - - if (aSpell != null) + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - StringBuffer b = new StringBuffer(); - b.append("<html><font size=+1><b>").append(aSpell.piSubString()).append("</b></font>"); //$NON-NLS-1$ //$NON-NLS-2$ - - final String addString = si.toString(); // would add [featList] - - if (addString.length() > 0) - { - b.append(" ").append(addString); //$NON-NLS-1$ - } - - b.append(" <b>").append(PropertyFactory.getString("InfoSpells.level.title")).append("</b> "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (cs.getOwner() != null) - { - - int[] levels = aSpell.levelForKey(cs.getOwner().getSpellKey(), pc); - - for (int index = 0; index < levels.length; ++index) - { - if (index > 0) - { - b.append(','); - } - - b.append(levels[index]); - } - } - else - b.append(aSpell.getLevelString()); - - b.append(PropertyFactory.getFormattedString("InfoSpells.html.spell.details", //$NON-NLS-1$ - new Object[] { - aSpell.getSchool(), - aSpell.getSubschool(), - aSpell.descriptor(), - aSpell.getComponentList(), - aSpell.getCastingTime(), - pc.parseSpellString(aSpell, aSpell.getDuration(), cs.getOwner()), - aSpell.getRange(), - pc.parseSpellString(aSpell, aSpell.getTarget(), cs.getOwner()), - aSpell.getSaveInfo(), - aSpell.getSpellResistance(), - pc.parseSpellString(aSpell, aSpell.getDescription(), cs.getOwner()) - })); - - - if (Spell.hasPPCost()) - { - b.append(" <b>PP Cost</b>: ").append(aSpell.getPPCost()); - } - - final String cString = aSpell.preReqHTMLStrings(pc, false); - if (cString.length() > 0) - { - b.append(" <b>Requirements</b>: ").append(cString); - } - - String spellSource = aSpell.getSource(); - - if (spellSource.length() > 0) - { - b.append(" <b>").append(PropertyFactory.getString("InfoSpells.source.title")).append("</b> ").append(spellSource); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - b.append("</html>"); //$NON-NLS-1$ - infoLabel.setText(b.toString()); + return spellbooks.isNegateEnabled(); } - } - private static String getNumCast(PCClass aClass, int level, PlayerCharacter pc) - { - int cLevel = aClass.getLevel(); - String sbook = Globals.getDefaultSpellBook(); -// final String cast = aClass.getCastForLevel(cLevel, level, sbook, pc) - final String cast = aClass.getCastForLevel(cLevel, level, sbook, true, false, pc) - + aClass.getBonusCastForLevelString(cLevel, level, sbook, pc); - - return cast; + return true; } - private static int getSelectedIndex(ListSelectionEvent e) + /** + * specifies the filter selection mode + * @return FilterConstants.DISABLED_MODE = -2 + **/ + public final int getSelectionMode() { - final DefaultListSelectionModel model = (DefaultListSelectionModel) e.getSource(); - - if (model == null) + if (getSelectedIndex() == KNOWN_INDEX) { - return -1; + return known.getSelectionMode(); } - - return model.getMinSelectionIndex(); - } - - private class AvailableClickHandler implements ClickHandler - { - public void singleClickEvent() { - // Do Nothing - } - - public void doubleClickEvent() + else if (getSelectedIndex() == PREPARED_INDEX) { - addSpellButton(); + return prepared.getSelectionMode(); } - public boolean isSelectable(Object obj) + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - return !(obj instanceof String); + return spellbooks.getSelectionMode(); } - } - private class SelectedClickHandler implements ClickHandler - { - public void singleClickEvent() { - // Do Nothing - } - - public void doubleClickEvent() - { - delSpellButton(); - } - public boolean isSelectable(Object obj) - { - return !(obj instanceof String); - } + return FilterConstants.DISABLED_MODE; } - private final void createTreeTables() + /** + * implementation of Filterable interface + **/ + public final void initializeFilters() { - availableTable = new JTreeTable(availableModel); - availableTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - - final JTree atree = availableTable.getTree(); - atree.setRootVisible(false); - atree.setShowsRootHandles(true); - atree.setCellRenderer(new LabelTreeCellRenderer()); - - availableTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() - { - public void valueChanged(ListSelectionEvent e) - { - if (!e.getValueIsAdjusting()) - { - final int idx = getSelectedIndex(e); - - if (idx < 0) - { - return; - } - - if (!atree.isSelectionEmpty()) - { - TreePath avaCPath = atree.getSelectionPath(); - String className = ""; //$NON-NLS-1$ - - if (primaryViewMode == GuiConstants.INFOSPELLS_VIEW_CLASS) - { - className = avaCPath.getPathComponent(1).toString(); - } - else if ((secondaryViewMode == GuiConstants.INFOSPELLS_VIEW_LEVEL) && (avaCPath.getPathCount() > 2)) - { - className = avaCPath.getPathComponent(2).toString(); - } - else if (lastClass != null) - { - className = lastClass; - } - - //className may have HTML encoding, so get rid of it - className = Utility.stripHTML(className); - - PCClass aClass = pc.getClassNamed(className); - - if (!className.equalsIgnoreCase(lastClass) && (className.length() > 0) && (aClass != null)) - { - setClassLabelText(aClass); - } - } - - final Object temp = atree.getPathForRow(idx).getLastPathComponent(); - - if (temp == null) - { - lastSpell = null; - infoLabel.setText(); - - return; - } - - PObjectNode fNode = (PObjectNode) temp; - - if (fNode.getItem() instanceof SpellInfo) - { - CharacterSpell spellA = ((SpellInfo) fNode.getItem()).getOwner(); - - if (spellA.getSpell() != null) - { - addSpellButton.setEnabled(true); - addMenu.setEnabled(true); - addMMMenu.setEnabled(true); - setInfoLabelText((SpellInfo) fNode.getItem()); - } - } - else - { - addSpellButton.setEnabled(false); - addMenu.setEnabled(false); - addMMMenu.setEnabled(false); - } - } - } - }); - - // now do the selectedTable and selectedTree - selectedTable = new JTreeTable(selectedModel); - selectedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - final JTree selectedTree = selectedTable.getTree(); - selectedTree.setRootVisible(false); - selectedTree.setShowsRootHandles(true); - selectedTree.setCellRenderer(new LabelTreeCellRenderer()); - - selectedTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() - { - public void valueChanged(ListSelectionEvent e) - { - if (!e.getValueIsAdjusting()) - { - final int idx = getSelectedIndex(e); - - if (idx < 0) - { - return; - } - - TreePath selCPath = selectedTree.getSelectionPath(); - - if (!selectedTree.isSelectionEmpty()) - { - spellBookNameText.setText(selCPath.getPathComponent(1).toString()); - spellBookNameTextActionPerformed(); - } - - final Object temp = selectedTree.getPathForRow(idx).getLastPathComponent(); - - if (temp == null) - { - lastSpell = null; - infoLabel.setText(); - - return; - } - - PObjectNode fNode = (PObjectNode) temp; - - if (fNode.getItem() instanceof SpellInfo) - { - CharacterSpell spellA = ((SpellInfo) fNode.getItem()).getOwner(); - - if (spellA.getSpell() != null) - { - delSpellButton.setEnabled(true); - setInfoLabelText((SpellInfo) fNode.getItem()); - } - } - } - } - }); - - availableTable.addMouseListener(new JTreeTableMouseAdapter(availableTable, new AvailableClickHandler(), true)); - selectedTable.addMouseListener(new JTreeTableMouseAdapter(selectedTable, new SelectedClickHandler(), true)); - - // create the rightclick popup menus - hookupPopupMenu(availableTable); - hookupPopupMenu(selectedTable); - } - - private void setSelectedIndex(JTreeTable aTable, int idx) - { - aTable.setRowSelectionInterval(idx, idx); - } - - /* - * - * This is used to add new spellbooks when the - * spellBookNameText JTextField is edited - * - */ - private void addBookButton() - { - final String aString = spellBookNameText.getText(); - - if (aString.equals(currSpellBook)) + if (getSelectedIndex() == KNOWN_INDEX) { - return; + known.initializeFilters(); } - - // added to prevent spellbooks being given the same name as a class - for (Iterator i = Globals.getClassList().iterator(); i.hasNext();) + else if (getSelectedIndex() == PREPARED_INDEX) { - PCClass current = (PCClass) i.next(); - - if ((aString.equals(current.getName()))) - { - JOptionPane.showMessageDialog(null, PropertyFactory.getString("in_spellbook_name_error"), //$NON-NLS-1$ - Constants.s_APPNAME, JOptionPane.ERROR_MESSAGE); - spellBookNameText.setText(""); //$NON-NLS-1$ - - return; - } + prepared.initializeFilters(); } - - if (pc.addSpellBook(aString)) + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - pc.setDirty(true); - spellBookNameText.setText(aString); - spellBookNameTextActionPerformed(); - updateSelectedModel(); + spellbooks.initializeFilters(); } - else - { - Logging.errorPrint("addBookButton:failed"); //$NON-NLS-1$ - - return; - } } - private final void createAvailableModel() + /** + * implementation of Filterable interface + **/ + public final void refreshFiltering() { - updateBookList(); - if (availableModel == null) + if (getSelectedIndex() == KNOWN_INDEX) { - availableModel = new SpellModel(this, primaryViewMode, secondaryViewMode, true, bookList, currSpellBook); + known.refreshFiltering(); } - else + else if (getSelectedIndex() == PREPARED_INDEX) { - availableModel.resetModel(primaryViewMode, secondaryViewMode, true, bookList, currSpellBook); - if (currSpellBook.equals("")) //$NON-NLS-1$ - { - currSpellBook = Globals.getDefaultSpellBook(); - } - spellBookNameText.setText(currSpellBook); + prepared.refreshFiltering(); } - - if (availableSort != null) + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - availableSort.setRoot((PObjectNode) availableModel.getRoot()); - availableSort.sortNodeOnColumn(); + spellbooks.refreshFiltering(); } } /** - * - * add all metamagic feats to arrayList - * + * delegates filter related stuff to gear tab + * @return removed filters **/ - private void createFeatList() + public List getRemovedFilters() { - //Calculate the aggregate feat list - pc.aggregateFeatList(); - pc.setAggregateFeatsStable(true); - pc.setAutomaticFeatsStable(true); - pc.setVirtualFeatsStable(true); - - // get the list of metamagic feats for the PC - characterMetaMagicFeats.clear(); - List feats = pc.aggregateFeatList(); - Globals.sortPObjectList(feats); - - for (Iterator i = feats.iterator(); i.hasNext();) + if (getSelectedIndex() == KNOWN_INDEX) { - Ability aFeat = (Ability) i.next(); - - if (aFeat.isType("Metamagic")) //$NON-NLS-1$ - { - characterMetaMagicFeats.add(aFeat.getName()); - } + return known.getRemovedFilters(); } - } - - /** - * Creates the SpellModel that will be used. - **/ - private final void createModels() - { - createAvailableModel(); - createSelectedModel(); - } - - private final void createSelectedModel() - { - updateBookList(); - if (selectedModel == null) + else if (getSelectedIndex() == PREPARED_INDEX) { - selectedModel = new SpellModel(this, primaryViewSelectMode, secondaryViewSelectMode, false, bookList, currSpellBook); + return prepared.getRemovedFilters(); } - else + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - selectedModel.resetModel(primaryViewSelectMode, secondaryViewSelectMode, false, bookList, currSpellBook); - if (currSpellBook.equals("")) //$NON-NLS-1$ - { - currSpellBook = Globals.getDefaultSpellBook(); - } - spellBookNameText.setText(currSpellBook); + return spellbooks.getRemovedFilters(); } - if (selectedSort != null) - { - selectedSort.setRoot((PObjectNode) selectedModel.getRoot()); - selectedSort.sortNodeOnColumn(); - } + return null; } - - private void delBookButton() + /** + * delegates filter related stuff to gear tab + * @return selected filters + **/ + public List getSelectedFilters() { - String aString = spellBookNameText.getText(); - - if (aString.equalsIgnoreCase(Globals.getDefaultSpellBook())) + if (getSelectedIndex() == KNOWN_INDEX) { - Logging.errorPrint(PropertyFactory.getString("InfoSpells.can.not.delete.default.spellbook")); //$NON-NLS-1$ - - return; + return known.getSelectedFilters(); } - - if (pc.delSpellBook(aString)) + else if (getSelectedIndex() == PREPARED_INDEX) { - pc.setDirty(true); - currSpellBook = Globals.getDefaultSpellBook(); - - updateAvailableModel(); - updateSelectedModel(); + return prepared.getSelectedFilters(); } - else + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - Logging.errorPrint("delBookButton:failed "); //$NON-NLS-1$ - - return; + return spellbooks.getSelectedFilters(); } - } - private void updateBookList() - { - for (Iterator iBook = pc.getSpellBooks().iterator(); iBook.hasNext();) - { - // build spell book list - String sBook = (String) iBook.next(); - if (!bookList.contains(sBook)) - { - bookList.add(sBook); - } - } - + return null; } - /** - * Exports Spell through selected output sheet to a file + * delegates filter related stuff to gear tab + * @return filter mode **/ - private void exportSpellsToFile() + public int getFilterMode() { - final String template = SettingsHandler.getSelectedSpellSheet(); - String ext = template.substring(template.lastIndexOf('.')); - - JFileChooser fcExport = new JFileChooser(); - fcExport.setCurrentDirectory(SettingsHandler.getPcgPath()); - - fcExport.setDialogTitle(PropertyFactory.getString("InfoSpells.export.spells.for") + pc.getDisplayName()); //$NON-NLS-1$ - - if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) + if (getSelectedIndex() == KNOWN_INDEX) { - return; + return known.getFilterMode(); } - - final String aFileName = fcExport.getSelectedFile().getAbsolutePath(); - - if (aFileName.length() < 1) + else if (getSelectedIndex() == PREPARED_INDEX) { - ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("InfoSpells.must.set.filename"), "PCGen", MessageType.ERROR); //$NON-NLS-1$ //$NON-NLS-2$ - - return; + return prepared.getFilterMode(); } - - try + else if (getSelectedIndex() == SPELLBOOKS_INDEX) { - final File outFile = new File(aFileName); - - if (outFile.isDirectory()) - { - ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("InfoSpells.can.not.overwrite.directory"), "PCGen", MessageType.ERROR); //$NON-NLS-1$ //$NON-NLS-2$ - - return; - } - - if (outFile.exists()) - { - int reallyClose = JOptionPane.showConfirmDialog(this, - PropertyFactory.getFormattedString(PropertyFactory.getString("InfoSpells.confirm.overwrite"),outFile.getName()), //$NON-NLS-1$ - PropertyFactory.getFormattedString(PropertyFactory.getString("InfoSpells.overwritnig"), outFile.getName()), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$ - - if (reallyClose != JOptionPane.YES_OPTION) - { - return; - } - } - - if (ext.equalsIgnoreCase(".htm") || ext.equalsIgnoreCase(".html")) //$NON-NLS-1$ //$NON-NLS-2$ - { - BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8")); //$NON-NLS-1$ - Utility.printToWriter(w, template, pc); - } - else if (ext.equalsIgnoreCase(".fo") || ext.equalsIgnoreCase(".pdf")) //$NON-NLS-1$ //$NON-NLS-2$ - { - File tmpFile = File.createTempFile("tempSpells_", ".fo"); //$NON-NLS-1$ //$NON-NLS-2$ - BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8")); //$NON-NLS-1$ - Utility.printToWriter(w, template, pc); - - FOPHandler fh = new FOPHandler(); - - // setting up pdf renderer - fh.setMode(FOPHandler.PDF_MODE); - fh.setInputFile(tmpFile); - fh.setOutputFile(outFile); - - // render to awt - fh.run(); - - tmpFile.deleteOnExit(); - - String errMessage = fh.getErrorMessage(); - - if (errMessage.length() > 0) - { - ShowMessageDelegate.showMessageDialog(errMessage, "PCGen", MessageType.ERROR); //$NON-NLS-1$ - } - } + return spellbooks.getFilterMode(); } - catch (IOException ex) - { - ShowMessageDelegate.showMessageDialog(PropertyFactory.getFormattedString("InfoSpells.export.failed.retry", pc.getDisplayName()), "PCGen", MessageType.ERROR); //$NON-NLS-1$ //$NON-NLS-2$ - Logging.errorPrint(PropertyFactory.getFormattedString("InfoSpells.export.failed", pc.getDisplayName()), ex); //$NON-NLS-1$ - } + + return FilterConstants.MATCH_ALL; } /** @@ -968,213 +366,8 @@ */ private void formComponentShown() { - requestFocus(); - PCGen_Frame1.setMessageAreaTextWithoutSaving(""); //$NON-NLS-1$ - - refresh(); - - int s = splitPane.getDividerLocation(); - int t = bsplit.getDividerLocation(); - int u = asplit.getDividerLocation(); - int width; - - if (!hasBeenSized) - { - hasBeenSized = true; - s = SettingsHandler.getPCGenOption("InfoSpells.splitPane", (int) ((this.getSize().getWidth() * 2) / 10)); //$NON-NLS-1$ - t = SettingsHandler.getPCGenOption("InfoSpells.bsplit", (int) (this.getSize().getHeight() - 101)); //$NON-NLS-1$ - u = SettingsHandler.getPCGenOption("InfoSpells.asplit", (int) (this.getSize().getWidth() - 408)); //$NON-NLS-1$ - - // set the prefered width on selectedTable - for (int i = 0; i < selectedTable.getColumnCount(); ++i) - { - TableColumn sCol = selectedTable.getColumnModel().getColumn(i); - width = Globals.getCustColumnWidth("SpellSel", i); //$NON-NLS-1$ - - if (width != 0) - { - sCol.setPreferredWidth(width); - } - - sCol.addPropertyChangeListener(new ResizeColumnListener(selectedTable, "SpellSel", i)); //$NON-NLS-1$ - } - - // set the prefered width on availableTable - for (int i = 0; i < availableTable.getColumnCount(); ++i) - { - TableColumn sCol = availableTable.getColumnModel().getColumn(i); - width = Globals.getCustColumnWidth("SpellAva", i); //$NON-NLS-1$ - - if (width != 0) - { - sCol.setPreferredWidth(width); - } - - sCol.addPropertyChangeListener(new ResizeColumnListener(availableTable, "SpellAva", i)); //$NON-NLS-1$ - } - } - - if (s > 0) - { - splitPane.setDividerLocation(s); - SettingsHandler.setPCGenOption("InfoSpells.splitPane", s); //$NON-NLS-1$ - } - - if (t > 0) - { - bsplit.setDividerLocation(t); - SettingsHandler.setPCGenOption("InfoSpells.bsplit", t); //$NON-NLS-1$ - } - - if (u > 0) - { - asplit.setDividerLocation(u); - SettingsHandler.setPCGenOption("InfoSpells.asplit", u); //$NON-NLS-1$ - } } - private void hookupPopupMenu(JTreeTable treeTable) - { - treeTable.addMouseListener(new SpellPopupListener(treeTable, new SpellPopupMenu(treeTable))); - } - - private void initActionListeners() - { - addComponentListener(new ComponentAdapter() - { - public void componentShown(ComponentEvent evt) - { - formComponentShown(); - } - }); - addComponentListener(new ComponentAdapter() - { - public void componentResized(ComponentEvent e) - { - int s = splitPane.getDividerLocation(); - - if (s > 0) - { - SettingsHandler.setPCGenOption("InfoSpells.splitPane", s); //$NON-NLS-1$ - } - - s = asplit.getDividerLocation(); - - if (s > 0) - { - SettingsHandler.setPCGenOption("InfoSpells.asplit", s); //$NON-NLS-1$ - } - - s = bsplit.getDividerLocation(); - - if (s > 0) - { - SettingsHandler.setPCGenOption("InfoSpells.bsplit", s); //$NON-NLS-1$ - } - } - }); - shouldAutoSpells.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - pc.setAutoSpells(shouldAutoSpells.isSelected()); - } - }); - addSpellButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - addSpellButton(); - } - }); - delSpellButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - delSpellButton(); - } - }); - spellBookNameText.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - spellBookNameTextActionPerformed(); - } - }); - addBookButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - addBookButton(); - } - }); - delBookButton.addActionListener(new ActionListener() - { - public void actionPerforme... [truncated message content] |