From: <cpm...@us...> - 2009-02-06 05:52:23
|
Revision: 9290 http://pcgen.svn.sourceforge.net/pcgen/?rev=9290&view=rev Author: cpmeister Date: 2009-02-06 05:52:18 +0000 (Fri, 06 Feb 2009) Log Message: ----------- UI Update Modified Paths: -------------- branches/cdomui/code/src/java/pcgen/gui/generator/GeneratorManager.java branches/cdomui/code/src/java/pcgen/gui/generator/stat/MutableStandardModeGenerator.java branches/cdomui/code/src/java/pcgen/gui/generator/stat/PurchaseModePanel.java branches/cdomui/code/src/java/pcgen/gui/generator/stat/StandardModePanel.java branches/cdomui/code/src/java/pcgen/gui/generator/stat/StatGeneratorSelectionModel.java Modified: branches/cdomui/code/src/java/pcgen/gui/generator/GeneratorManager.java =================================================================== --- branches/cdomui/code/src/java/pcgen/gui/generator/GeneratorManager.java 2009-02-06 03:44:22 UTC (rev 9289) +++ branches/cdomui/code/src/java/pcgen/gui/generator/GeneratorManager.java 2009-02-06 05:52:18 UTC (rev 9290) @@ -91,1532 +91,1528 @@ public final class GeneratorManager { - public static final class GeneratorType<E> - { + public static final class GeneratorType<E> + { - private static final Map<String, GeneratorType<?>> typeMap = new HashMap<String, GeneratorType<?>>(); - public static final GeneratorType<WeightedGenerator<AlignmentFacade>> ALIGNMENT = new GeneratorType<WeightedGenerator<AlignmentFacade>>("AlignmentGenerator", - "ALIGNMENT_GENERATOR", - DefaultAlignmentGenerator.class, - null); - public static final GeneratorType<WeightedGenerator<Gender>> GENDER = new GeneratorType<WeightedGenerator<Gender>>("GenderGenerator", - "GENDER_GENERATOR", - null, - null); - public static final GeneratorType<InfoFacadeGenerator<SkillFacade>> SKILL = new GeneratorType<InfoFacadeGenerator<SkillFacade>>("SkillGenerator", - "SKILL_GENERATOR", - DefaultSkillGenerator.class, - DefaultMutableSkillGenerator.class); - public static final GeneratorType<StandardModeGenerator> STANDARDMODE = new GeneratorType<StandardModeGenerator>("StandardModeGenerator", - "STANDARDMODE_GENERATOR", - DefaultStandardModeGenerator.class, - DefaultMutableStandardModeGenerator.class); - public static final GeneratorType<PurchaseModeGenerator> PURCHASEMODE = new GeneratorType<PurchaseModeGenerator>("PurchaseModeGenerator", - "PURCHASEMODE_GENERATOR", - DefaultPurchaseModeGenerator.class, - DefaultMutablePurchaseModeGenerator.class); - public static final GeneratorType<InfoFacadeGenerator<RaceFacade>> RACE = new GeneratorType<InfoFacadeGenerator<RaceFacade>>("RaceGenerator", - "RACE_GENERATOR", - DefaultRaceGenerator.class, - DefaultMutableRaceGenerator.class); - public static final GeneratorType<InfoFacadeGenerator<ClassFacade>> CLASS = new GeneratorType<InfoFacadeGenerator<ClassFacade>>("ClassGenerator", - "CLASS_GENERATOR", - DefaultClassGenerator.class, - DefaultMutableClassGenerator.class); - public static final GeneratorType<AbilityBuild> ABILITYBUILD = new GeneratorType<AbilityBuild>("AbilityBuild", - "ABILITY_BUILD", - DefaultAbilityBuild.class, - DefaultMutableAbilityBuild.class); - public static final GeneratorType<InfoFacadeGenerator<AbilityFacade>> ABILITY = new GeneratorType<InfoFacadeGenerator<AbilityFacade>>("Ability", - "ABILITY_GENERATOR", - DefaultAbilityGenerator.class, - DefaultMutableAbilityGenerator.class); - private Class<? extends E> baseClass; - private Class<? extends E> mutableClass; - private String name; - private String element; + private static final Map<String, GeneratorType<?>> typeMap = new HashMap<String, GeneratorType<?>>(); + public static final GeneratorType<WeightedGenerator<AlignmentFacade>> ALIGNMENT = new GeneratorType<WeightedGenerator<AlignmentFacade>>("AlignmentGenerator", + "ALIGNMENT_GENERATOR", + DefaultAlignmentGenerator.class, + null); + public static final GeneratorType<WeightedGenerator<Gender>> GENDER = new GeneratorType<WeightedGenerator<Gender>>("GenderGenerator", + "GENDER_GENERATOR", + null, + null); + public static final GeneratorType<InfoFacadeGenerator<SkillFacade>> SKILL = new GeneratorType<InfoFacadeGenerator<SkillFacade>>("SkillGenerator", + "SKILL_GENERATOR", + DefaultSkillGenerator.class, + DefaultMutableSkillGenerator.class); + public static final GeneratorType<StandardModeGenerator> STANDARDMODE = new GeneratorType<StandardModeGenerator>("StandardModeGenerator", + "STANDARDMODE_GENERATOR", + DefaultStandardModeGenerator.class, + DefaultMutableStandardModeGenerator.class); + public static final GeneratorType<PurchaseModeGenerator> PURCHASEMODE = new GeneratorType<PurchaseModeGenerator>("PurchaseModeGenerator", + "PURCHASEMODE_GENERATOR", + DefaultPurchaseModeGenerator.class, + DefaultMutablePurchaseModeGenerator.class); + public static final GeneratorType<InfoFacadeGenerator<RaceFacade>> RACE = new GeneratorType<InfoFacadeGenerator<RaceFacade>>("RaceGenerator", + "RACE_GENERATOR", + DefaultRaceGenerator.class, + DefaultMutableRaceGenerator.class); + public static final GeneratorType<InfoFacadeGenerator<ClassFacade>> CLASS = new GeneratorType<InfoFacadeGenerator<ClassFacade>>("ClassGenerator", + "CLASS_GENERATOR", + DefaultClassGenerator.class, + DefaultMutableClassGenerator.class); + public static final GeneratorType<AbilityBuild> ABILITYBUILD = new GeneratorType<AbilityBuild>("AbilityBuild", + "ABILITY_BUILD", + DefaultAbilityBuild.class, + DefaultMutableAbilityBuild.class); + public static final GeneratorType<InfoFacadeGenerator<AbilityFacade>> ABILITY = new GeneratorType<InfoFacadeGenerator<AbilityFacade>>("Ability", + "ABILITY_GENERATOR", + DefaultAbilityGenerator.class, + DefaultMutableAbilityGenerator.class); + private Class<? extends E> baseClass; + private Class<? extends E> mutableClass; + private String name; + private String element; - private GeneratorType(String name, String element, - Class<? extends E> baseClass, - Class<? extends E> mutableClass) - { - this.name = name; - this.element = element; - this.baseClass = baseClass; - this.mutableClass = mutableClass; - typeMap.put(element, this); - } + private GeneratorType(String name, String element, + Class<? extends E> baseClass, + Class<? extends E> mutableClass) + { + this.name = name; + this.element = element; + this.baseClass = baseClass; + this.mutableClass = mutableClass; + typeMap.put(element, this); + } - public static GeneratorType<?> getGeneratorType(String element) - { - return typeMap.get(element); - } + public static GeneratorType<?> getGeneratorType(String element) + { + return typeMap.get(element); + } - } + } - private static class DocumentHandler extends DefaultJDOMFactory implements EntityResolver - { + private static class DocumentHandler extends DefaultJDOMFactory implements EntityResolver + { - private final Map<String, Document> documentMap; - private final SAXBuilder builder; - private final XMLOutputter outputter; + private final Map<String, Document> documentMap; + private final SAXBuilder builder; + private final XMLOutputter outputter; - public DocumentHandler() - { - documentMap = new HashMap<String, Document>(); - builder = new SAXBuilder(); - builder.setEntityResolver(this); - builder.setFactory(this); - outputter = new XMLOutputter(); - outputter.setFormat(Format.getPrettyFormat()); - } + public DocumentHandler() + { + documentMap = new HashMap<String, Document>(); + builder = new SAXBuilder(); + builder.setEntityResolver(this); + builder.setFactory(this); + outputter = new XMLOutputter(); + outputter.setFormat(Format.getPrettyFormat()); + } - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException - { - if (publicId != null) - { - if (publicId.equals("PCGEN-GENERATORS")) - { - String fileName = SettingsHandler.getPcgenSystemDir() + - File.separator + - "generators" + - File.separator + - new File(systemId).getName(); - return new InputSource(new FileInputStream(fileName)); - } + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException + { + if (publicId != null) + { + if (publicId.equals("PCGEN-GENERATORS")) + { + String fileName = SettingsHandler.getPcgenSystemDir() + + File.separator + + "generators" + + File.separator + + new File(systemId).getName(); + return new InputSource(new FileInputStream(fileName)); + } - } - return null; - } + } + return null; + } - public Document getDocument(URI uri) - { - String systemId = uri.toString(); - Document document = documentMap.get(systemId); - if (document == null) - { - try - { - document = builder.build(systemId); - } - catch (JDOMException ex) - { - Logging.log(Logging.XML_ERROR, "Failed to created document", - ex); - } - catch (IOException ex) - { - Logging.log(Logging.XML_ERROR, - "Error occured while accessing file", - ex); - } - documentMap.put(systemId, document); - } - return document; - } + public Document getDocument(URI uri) + { + String systemId = uri.toString(); + Document document = documentMap.get(systemId); + if (document == null) + { + try + { + document = builder.build(systemId); + } + catch (JDOMException ex) + { + Logging.log(Logging.XML_ERROR, "Failed to created document", + ex); + } + catch (IOException ex) + { + Logging.log(Logging.XML_ERROR, + "Error occured while accessing file", + ex); + } + documentMap.put(systemId, document); + } + return document; + } - @Override - public Element element(String name) - { - return new GeneratorElement(name); - } + @Override + public Element element(String name) + { + return new GeneratorElement(name); + } - } - private static DocumentHandler documentHandler = new DocumentHandler(); - private static AbstractFilter generatorFilter = new AbstractFilter() - { + } + private static DocumentHandler documentHandler = new DocumentHandler(); + private static AbstractFilter generatorFilter = new AbstractFilter() + { - public boolean matches(Object obj) - { - if (obj instanceof Element) - { - Element element = (Element) obj; - String name = element.getName(); - return !name.matches("BUILD") && - GeneratorType.getGeneratorType(name) != null; - } - return false; - } + public boolean matches(Object obj) + { + if (obj instanceof Element) + { + Element element = (Element) obj; + String name = element.getName(); + return !name.matches("BUILD") && + GeneratorType.getGeneratorType(name) != null; + } + return false; + } - }; - private static AbstractFilter buildFilter = new AbstractFilter() - { + }; + private static AbstractFilter buildFilter = new AbstractFilter() + { - public boolean matches(Object obj) - { - if (obj instanceof Element) - { - Element element = (Element) obj; - return element.getName().matches("BUILD"); - } - return false; - } + public boolean matches(Object obj) + { + if (obj instanceof Element) + { + Element element = (Element) obj; + return element.getName().matches("BUILD"); + } + return false; + } - }; - private static Filter refFilter = new Filter() - { + }; + private static Filter refFilter = new Filter() + { - public boolean matches(Object obj) - { - if (obj instanceof Element) - { - Element element = (Element) obj; - if (element.getName().endsWith("_REF")) - { - return true; - } - } - return false; - } + public boolean matches(Object obj) + { + if (obj instanceof Element) + { + Element element = (Element) obj; + if (element.getName().endsWith("_REF")) + { + return true; + } + } + return false; + } - }; + }; - @SuppressWarnings("unchecked") - private void loadGenerators(Document document) - { - if (loadedDocuments.contains(document)) - { - return; - } - GeneratorElement root = (GeneratorElement) document.getRootElement(); - boolean mutable; - if (root.getName().equals("BUILDSET")) - { - mutable = Boolean.parseBoolean(root.getAttributeValue("mutable")); - } - else - { - mutable = false; - } + @SuppressWarnings("unchecked") + private void loadGenerators(Document document) + { + if (loadedDocuments.contains(document)) + { + return; + } + GeneratorElement root = (GeneratorElement) document.getRootElement(); + boolean mutable; + if (root.getName().equals("BUILDSET")) + { + mutable = Boolean.parseBoolean(root.getAttributeValue("mutable")); + } + else + { + mutable = false; + } - Iterator<GeneratorElement> elementIterator = document.getDescendants(generatorFilter); - while (elementIterator.hasNext()) - { - GeneratorElement element = elementIterator.next(); - loadGenerator(element, mutable); - } + Iterator<GeneratorElement> elementIterator = document.getDescendants(generatorFilter); + while (elementIterator.hasNext()) + { + GeneratorElement element = elementIterator.next(); + loadGenerator(element, mutable); + } - elementIterator = document.getDescendants(buildFilter); - while (elementIterator.hasNext()) - { - GeneratorElement element = elementIterator.next(); - loadGenerator(element, mutable); - } - loadedDocuments.add(document); - } + elementIterator = document.getDescendants(buildFilter); + while (elementIterator.hasNext()) + { + GeneratorElement element = elementIterator.next(); + loadGenerator(element, mutable); + } + loadedDocuments.add(document); + } - @SuppressWarnings("unchecked") - private void loadGenerator(GeneratorElement element, boolean mutable) - { + @SuppressWarnings("unchecked") + private void loadGenerator(GeneratorElement element, boolean mutable) + { - List<GeneratorElement> sourceElements = element.getChildren("SOURCE"); - if (sourceElements != null) - { - Set<String> sources = dataset.getSources(); - for (Element source : sourceElements) - { - if (!sources.contains(source.getText())) - { - return; - } - } - } - List<GeneratorElement> refElements = element.getContent(refFilter); - if (refElements != null) - { - Document basedoc = element.getDocument(); - for (GeneratorElement refElement : refElements) - { - String name = refElement.getAttributeValue("name"); - String catagory = refElement.getAttributeValue("catagory"); - GeneratorType<?> type = GeneratorType.getGeneratorType(refElement.getName().replaceFirst("_REF", - "")); - if (!generatorMap.containsKey(type, catagory, name)) - { - String generatorUri = refElement.getAttributeValue("uri"); - if (generatorUri != null) - { - URI uri = null; - Document document = null; - try - { - uri = new URI(generatorUri); - URI baseuri = URI.create(basedoc.getBaseURI()); - uri = baseuri.resolve(uri); - document = documentHandler.getDocument(uri); - } - catch (URISyntaxException ex) - { - Logging.log(Logging.XML_ERROR, - "Invalid URI specified in:\n" + - documentHandler.outputter.outputString(refElement) + - "\nlocated in " + - basedoc.getBaseURI(), ex); - return; - } - if (document == null) - { - Logging.log(Logging.XML_ERROR, - "Unable to resolve reference to " + uri); - return; - } - else - { - loadGenerators(document); - } - } - } - if (!generatorMap.containsKey(type, catagory, name)) - { - Logging.log(Logging.XML_ERROR, "Invalid Reference in " + - basedoc.getBaseURI() + ", ignoring " + - documentHandler.outputter.outputString(element)); - return; - } - } - } - String name = element.getAttributeValue("name"); - String catagory = element.getAttributeValue("catagory"); - GeneratorType<?> type = GeneratorType.getGeneratorType(element.getName()); - try - { - Class<?> c; - if (mutable) - { - c = type.mutableClass; - } - else - { - c = type.baseClass; - } - Object obj = c.getConstructor(GeneratorElement.class).newInstance(element); - generatorMap.put(type, catagory, name, obj); - } - catch (Exception ex) - { - Logging.errorPrint("Unable to create generator", - ex); - } - } + List<GeneratorElement> sourceElements = element.getChildren("SOURCE"); + if (sourceElements != null) + { + Set<String> sources = dataset.getSources(); + for (Element source : sourceElements) + { + if (!sources.contains(source.getText())) + { + return; + } + } + } + List<GeneratorElement> refElements = element.getContent(refFilter); + if (refElements != null) + { + Document basedoc = element.getDocument(); + for (GeneratorElement refElement : refElements) + { + String name = refElement.getAttributeValue("name"); + String catagory = refElement.getAttributeValue("catagory"); + GeneratorType<?> type = GeneratorType.getGeneratorType(refElement.getName().replaceFirst("_REF", + "")); + if (!generatorMap.containsKey(type, catagory, name)) + { + String generatorUri = refElement.getAttributeValue("uri"); + if (generatorUri != null) + { + URI uri = null; + Document document = null; + try + { + uri = new URI(generatorUri); + URI baseuri = URI.create(basedoc.getBaseURI()); + uri = baseuri.resolve(uri); + document = documentHandler.getDocument(uri); + } + catch (URISyntaxException ex) + { + Logging.log(Logging.XML_ERROR, + "Invalid URI specified in:\n" + + documentHandler.outputter.outputString(refElement) + + "\nlocated in " + + basedoc.getBaseURI(), ex); + return; + } + if (document == null) + { + Logging.log(Logging.XML_ERROR, + "Unable to resolve reference to " + uri); + return; + } + else + { + loadGenerators(document); + } + } + } + if (!generatorMap.containsKey(type, catagory, name)) + { + Logging.log(Logging.XML_ERROR, "Invalid Reference in " + + basedoc.getBaseURI() + ", ignoring " + + documentHandler.outputter.outputString(element)); + return; + } + } + } + String name = element.getAttributeValue("name"); + String catagory = element.getAttributeValue("catagory"); + GeneratorType<?> type = GeneratorType.getGeneratorType(element.getName()); + try + { + Class<?> c; + if (mutable) + { + c = type.mutableClass; + } + else + { + c = type.baseClass; + } + Object obj = c.getConstructor(GeneratorElement.class).newInstance(element); + generatorMap.put(type, catagory, name, obj); + } + catch (Exception ex) + { + Logging.errorPrint("Unable to create generator", + ex); + } + } - private <T> List<T> getGeneratorList(Document document, - GeneratorType<T> type) - { - return null; - } + private <T> List<T> getGeneratorList(Document document, + GeneratorType<T> type) + { + return null; + } - private final DataSetFacade dataset; - // The second and third keys are "catagory" and "name" respectively - private final TripleKeyMap<GeneratorType<?>, String, String, Object> generatorMap; - private final Set<Document> loadedDocuments; + private final DataSetFacade dataset; + // The second and third keys are "catagory" and "name" respectively + private final TripleKeyMap<GeneratorType<?>, String, String, Object> generatorMap; + private final Set<Document> loadedDocuments; - public GeneratorManager(DataSetFacade dataset) - { - this.dataset = dataset; - this.generatorMap = new TripleKeyMap<GeneratorType<?>, String, String, Object>(); - this.loadedDocuments = new HashSet<Document>(); + public GeneratorManager(DataSetFacade dataset) + { + this.dataset = dataset; + this.generatorMap = new TripleKeyMap<GeneratorType<?>, String, String, Object>(); + this.loadedDocuments = new HashSet<Document>(); - loadAnyGenerators(); - loadSingletonGenerators(); + loadAnyGenerators(); + loadSingletonGenerators(); - GameModeFacade gameMode = dataset.getGameMode(); - Document document = documentHandler.getDocument(gameMode.getGeneratorFile().toURI()); - if (document != null) - { - loadGenerators(document); - } - for (File file : dataset.getGeneratorFiles()) - { - document = documentHandler.getDocument(file.toURI()); - if (document != null) - { - loadGenerators(document); - } - } - } + GameModeFacade gameMode = dataset.getGameMode(); + Document document = documentHandler.getDocument(gameMode.getGeneratorFile().toURI()); + if (document != null) + { + loadGenerators(document); + } + for (File file : dataset.getGeneratorFiles()) + { + document = documentHandler.getDocument(file.toURI()); + if (document != null) + { + loadGenerators(document); + } + } + } - private void loadAnyGenerators() - { - loadAnyWeightedGenerator(GeneratorType.ALIGNMENT, - dataset.getGameMode().getAlignments()); - loadAnyWeightedGenerator(GeneratorType.GENDER, - new DefaultGenericListModel<Gender>(Arrays.asList(Gender.values()))); - AbilityCatagoryManager catagoryManager = new AbilityCatagoryManager(); - catagoryManager.setModel(dataset.getAbilityCatagories()); - loadAnyInfoFacadeGenerator(GeneratorType.RACE, dataset.getRaces()); - loadAnyInfoFacadeGenerator(GeneratorType.CLASS, dataset.getClasses()); - } + private void loadAnyGenerators() + { + loadAnyWeightedGenerator(GeneratorType.ALIGNMENT, + dataset.getGameMode().getAlignments()); + loadAnyWeightedGenerator(GeneratorType.GENDER, + new DefaultGenericListModel<Gender>(Arrays.asList(Gender.values()))); + AbilityCatagoryManager catagoryManager = new AbilityCatagoryManager(); + catagoryManager.setModel(dataset.getAbilityCatagories()); + loadAnyInfoFacadeGenerator(GeneratorType.RACE, dataset.getRaces()); + loadAnyInfoFacadeGenerator(GeneratorType.CLASS, dataset.getClasses()); + } - private <T> void loadAnyWeightedGenerator(GeneratorType<WeightedGenerator<T>> type, - GenericListModel<T> model) - { - AnyWeightedGenerator<T> generator = new AnyWeightedGenerator<T>(model); - generatorMap.put(type, null, generator.toString(), generator); - } + private <T> void loadAnyWeightedGenerator(GeneratorType<WeightedGenerator<T>> type, + GenericListModel<T> model) + { + AnyWeightedGenerator<T> generator = new AnyWeightedGenerator<T>(model); + generatorMap.put(type, null, generator.toString(), generator); + } - private <T extends InfoFacade> void loadAnyInfoFacadeGenerator(GeneratorType<InfoFacadeGenerator<T>> type, - GenericListModel<T> model) - { - AnyInfoFacadeGenerator<T> generator = new AnyInfoFacadeGenerator<T>(model); - generatorMap.put(type, null, generator.toString(), generator); - } + private <T extends InfoFacade> void loadAnyInfoFacadeGenerator(GeneratorType<InfoFacadeGenerator<T>> type, + GenericListModel<T> model) + { + AnyInfoFacadeGenerator<T> generator = new AnyInfoFacadeGenerator<T>(model); + generatorMap.put(type, null, generator.toString(), generator); + } - private void loadSingletonGenerators() - { - loadSingletonWeightedGenerators(GeneratorType.ALIGNMENT, - dataset.getGameMode().getAlignments()); - loadSingletonWeightedGenerators(GeneratorType.GENDER, - new DefaultGenericListModel<Gender>(Arrays.asList(Gender.values()))); - loadSingletonInfoFacadeGenerators(GeneratorType.RACE, dataset.getRaces()); - loadSingletonInfoFacadeGenerators(GeneratorType.CLASS, - dataset.getClasses()); - } + private void loadSingletonGenerators() + { + loadSingletonWeightedGenerators(GeneratorType.ALIGNMENT, + dataset.getGameMode().getAlignments()); + loadSingletonWeightedGenerators(GeneratorType.GENDER, + new DefaultGenericListModel<Gender>(Arrays.asList(Gender.values()))); + loadSingletonInfoFacadeGenerators(GeneratorType.RACE, dataset.getRaces()); + loadSingletonInfoFacadeGenerators(GeneratorType.CLASS, + dataset.getClasses()); + } - private <T> void loadSingletonWeightedGenerators(GeneratorType<WeightedGenerator<T>> type, - GenericListModel<T> model) - { - SingletonWeightedGeneratorManager<T> manager = new SingletonWeightedGeneratorManager<T>(type); - manager.setModel(model); - } + private <T> void loadSingletonWeightedGenerators(GeneratorType<WeightedGenerator<T>> type, + GenericListModel<T> model) + { + SingletonWeightedGeneratorManager<T> manager = new SingletonWeightedGeneratorManager<T>(type); + manager.setModel(model); + } - private <T extends InfoFacade> void loadSingletonInfoFacadeGenerators(GeneratorType<InfoFacadeGenerator<T>> type, - GenericListModel<T> model) - { - SingletonInfoFacadeGeneratorManager<T> manager = new SingletonInfoFacadeGeneratorManager<T>(type); - manager.setModel(model); - } + private <T extends InfoFacade> void loadSingletonInfoFacadeGenerators(GeneratorType<InfoFacadeGenerator<T>> type, + GenericListModel<T> model) + { + SingletonInfoFacadeGeneratorManager<T> manager = new SingletonInfoFacadeGeneratorManager<T>(type); + manager.setModel(model); + } - private class AbilityCatagoryManager extends AbstractGenericListDataListener<AbilityCatagoryFacade> - { + private class AbilityCatagoryManager extends AbstractGenericListDataListener<AbilityCatagoryFacade> + { - private final Map<AbilityCatagoryFacade, AnyInfoFacadeGenerator<AbilityFacade>> catagoryMap; + private final Map<AbilityCatagoryFacade, AnyInfoFacadeGenerator<AbilityFacade>> catagoryMap; - public AbilityCatagoryManager() - { - this.catagoryMap = new HashMap<AbilityCatagoryFacade, AnyInfoFacadeGenerator<AbilityFacade>>(); - } + public AbilityCatagoryManager() + { + this.catagoryMap = new HashMap<AbilityCatagoryFacade, AnyInfoFacadeGenerator<AbilityFacade>>(); + } - @Override - protected void addData(Collection<? extends AbilityCatagoryFacade> data) - { - for (AbilityCatagoryFacade abilityCatagoryFacade : data) - { - AnyInfoFacadeGenerator<AbilityFacade> generator = new AnyInfoFacadeGenerator<AbilityFacade>(dataset.getAbilities(abilityCatagoryFacade)); - generatorMap.put(GeneratorType.ABILITY, - abilityCatagoryFacade.getName(), - generator.toString(), generator); - catagoryMap.put(abilityCatagoryFacade, generator); - } - } + @Override + protected void addData(Collection<? extends AbilityCatagoryFacade> data) + { + for (AbilityCatagoryFacade abilityCatagoryFacade : data) + { + AnyInfoFacadeGenerator<AbilityFacade> generator = new AnyInfoFacadeGenerator<AbilityFacade>(dataset.getAbilities(abilityCatagoryFacade)); + generatorMap.put(GeneratorType.ABILITY, + abilityCatagoryFacade.getName(), + generator.toString(), generator); + catagoryMap.put(abilityCatagoryFacade, generator); + } + } - @Override - protected void removeData(Collection<? extends AbilityCatagoryFacade> data) - { - for (AbilityCatagoryFacade abilityCatagoryFacade : data) - { - generatorMap.remove(GeneratorType.ABILITY, - abilityCatagoryFacade.getName(), - catagoryMap.remove(abilityCatagoryFacade).toString()); - } - } + @Override + protected void removeData(Collection<? extends AbilityCatagoryFacade> data) + { + for (AbilityCatagoryFacade abilityCatagoryFacade : data) + { + generatorMap.remove(GeneratorType.ABILITY, + abilityCatagoryFacade.getName(), + catagoryMap.remove(abilityCatagoryFacade).toString()); + } + } - } + } - private class SingletonWeightedGeneratorManager<E> extends AbstractGenericListDataListener<E> - { + private class SingletonWeightedGeneratorManager<E> extends AbstractGenericListDataListener<E> + { - private final GeneratorType<? extends Generator<E>> type; + private final GeneratorType<? extends Generator<E>> type; - public SingletonWeightedGeneratorManager(GeneratorType<? extends Generator<E>> type) - { - this.type = type; - } + public SingletonWeightedGeneratorManager(GeneratorType<? extends Generator<E>> type) + { + this.type = type; + } - @Override - protected void addData(Collection<? extends E> data) - { - for (E e : data) - { - SingletonWeightedGenerator<E> generator = createGenerator(e); - generatorMap.put(type, null, generator.toString(), - generator); - } - } + @Override + protected void addData(Collection<? extends E> data) + { + for (E e : data) + { + SingletonWeightedGenerator<E> generator = createGenerator(e); + generatorMap.put(type, null, generator.toString(), + generator); + } + } - protected SingletonWeightedGenerator<E> createGenerator(E item) - { - return new SingletonWeightedGenerator<E>(item); - } + protected SingletonWeightedGenerator<E> createGenerator(E item) + { + return new SingletonWeightedGenerator<E>(item); + } - @Override - protected void removeData(Collection<? extends E> data) - { - for (E e : data) - { - generatorMap.remove(type, null, e.toString()); - } - } + @Override + protected void removeData(Collection<? extends E> data) + { + for (E e : data) + { + generatorMap.remove(type, null, e.toString()); + } + } - } + } - private class SingletonInfoFacadeGeneratorManager<E extends InfoFacade> - extends SingletonWeightedGeneratorManager<E> - { + private class SingletonInfoFacadeGeneratorManager<E extends InfoFacade> + extends SingletonWeightedGeneratorManager<E> + { - public SingletonInfoFacadeGeneratorManager(GeneratorType<? extends Generator<E>> type) - { - super(type); - } + public SingletonInfoFacadeGeneratorManager(GeneratorType<? extends Generator<E>> type) + { + super(type); + } - @Override - protected SingletonWeightedGenerator<E> createGenerator(E item) - { - return new SingletonInfoFacadeGenerator<E>(item); - } + @Override + protected SingletonWeightedGenerator<E> createGenerator(E item) + { + return new SingletonInfoFacadeGenerator<E>(item); + } - } + } - public static final void main(String[] arg) - { + public static final void main(String[] arg) + { - File file = new File("build/classes/generators/DefaultStandardGenerators.xml"); - System.out.println(GeneratorType.getGeneratorType("ABILITY_BUILD").name); - } + File file = new File("build/classes/generators/DefaultStandardGenerators.xml"); + System.out.println(GeneratorType.getGeneratorType("ABILITY_BUILD").name); + } - public static <T extends InfoFacade> InfoFacadeGenerator<T> createSingletonGenerator(T item) - { - return new SingletonInfoFacadeGenerator<T>(item); - } + public static <T extends InfoFacade> InfoFacadeGenerator<T> createSingletonGenerator(T item) + { + return new SingletonInfoFacadeGenerator<T>(item); + } - private static Document getCustomGeneratorDocument(DataSetFacade data, - String generatorType) - { - File file = new File(SettingsHandler.getPcgenCustomDir(), - data.getGameMode() + File.separator + - "custom" + generatorType + "s.xml"); - Document document = null; - if (!file.exists()) - { - Element root = new Element("GENERATORSET"); - root.setAttribute("mutable", "true"); - DocType type = new DocType("GENERATORSET", "PCGEN-GENERATORS", - generatorType + ".dtd"); - document = new Document(root, type, file.toURI().toString()); - } - else - { - // document = buildDocument(file); - } - return document; - } + private static Document getCustomGeneratorDocument(DataSetFacade data, + String generatorType) + { + File file = new File(SettingsHandler.getPcgenCustomDir(), + data.getGameMode() + File.separator + + "custom" + generatorType + "s.xml"); + Document document = null; + if (!file.exists()) + { + Element root = new Element("GENERATORSET"); + root.setAttribute("mutable", "true"); + DocType type = new DocType("GENERATORSET", "PCGEN-GENERATORS", + generatorType + ".dtd"); + document = new Document(root, type, file.toURI().toString()); + } + else + { + // document = buildDocument(file); + } + return document; + } - public static MutablePurchaseModeGenerator createMutablePurchaseModeGenerator(String name, - DataSetFacade data, - PurchaseModeGenerator template) - { - Document document = getCustomGeneratorDocument(data, - "PurchaseModeGenerator"); - if (document != null) - { - GeneratorElement generatorElement = new GeneratorElement("GENERATOR"); - generatorElement.setAttribute("name", name). - setAttribute("points", "0"); - Element cost = new Element("COST"); - cost.setAttribute("score", "0").setText("0"); - document.getRootElement().addContent(generatorElement.addContent(cost)); + public static MutablePurchaseModeGenerator createMutablePurchaseModeGenerator(String name, + DataSetFacade data, + PurchaseModeGenerator template) + { + Document document = getCustomGeneratorDocument(data, + "PurchaseModeGenerator"); + if (document != null) + { + GeneratorElement generatorElement = new GeneratorElement("GENERATOR"); + generatorElement.setAttribute("name", name). + setAttribute("points", "0"); + Element cost = new Element("COST"); + cost.setAttribute("score", "0").setText("0"); + document.getRootElement().addContent(generatorElement.addContent(cost)); - MutablePurchaseModeGenerator generator = new DefaultMutablePurchaseModeGenerator(generatorElement); - if (template != null) - { - int min = template.getMinScore(); - int max = template.getMaxScore(); - generator.setMinScore(min); - generator.setMaxScore(max); - generator.setPoints(template.getPoints()); - for (int i = min; i <= max; i++) - { - generator.setScoreCost(i, template.getScoreCost(i)); - } - } - return generator; - } - return null; - } + MutablePurchaseModeGenerator generator = new DefaultMutablePurchaseModeGenerator(generatorElement); + if (template != null) + { + int min = template.getMinScore(); + int max = template.getMaxScore(); + generator.setMinScore(min); + generator.setMaxScore(max); + generator.setPoints(template.getPoints()); + for (int i = min; i <= max; i++) + { + generator.setScoreCost(i, template.getScoreCost(i)); + } + } + return generator; + } + return null; + } - public static MutableStandardModeGenerator createMutableStandardModeGenerator(String name, - DataSetFacade data, - StandardModeGenerator template) - { - Document document = getCustomGeneratorDocument(data, - "StandardModeGenerator"); - if (document != null) - { - GeneratorElement generatorElement = new GeneratorElement("GENERATOR"); - generatorElement.setAttribute("name", name). - setAttribute("assignable", "true"); - document.getRootElement().addContent(generatorElement); - for (int x = 0; x < 6; x++) - { - generatorElement.addContent(new Element("STAT")); - } + public static MutableStandardModeGenerator createMutableStandardModeGenerator(String name, + DataSetFacade data, + StandardModeGenerator template) + { + Document document = getCustomGeneratorDocument(data, + "StandardModeGenerator"); + if (document != null) + { + GeneratorElement generatorElement = new GeneratorElement("GENERATOR"); + generatorElement.setAttribute("name", name). + setAttribute("assignable", "true"); + document.getRootElement().addContent(generatorElement); + for (int x = 0; x < 6; x++) + { + generatorElement.addContent(new Element("STAT")); + } - MutableStandardModeGenerator generator = new DefaultMutableStandardModeGenerator(generatorElement); - if (template != null) - { - generator.setAssignable(template.isAssignable()); - /* - * Its safe to resuse the list since the expression - * lists arn't modified after they are put into the generator - */ - generator.setDiceExpressions(template.getDiceExpressions()); - } - return generator; - } - return null; - } + DefaultMutableStandardModeGenerator generator = new DefaultMutableStandardModeGenerator(generatorElement); + if (template != null) + { + generator.setAssignable(template.isAssignable()); + Collections.copy(generator.diceExpressions, template.getDiceExpressions()); + } + return generator; + } + return null; + } - public static <T extends InfoFacade> MutableInfoFacadeGenerator<T> createMutableFacadeGenerator(GeneratorType<InfoFacadeGenerator<T>> type, - String name, - DataSetFacade data, - MutableInfoFacadeGenerator<T> template) - { - Document document = getCustomGeneratorDocument(data, - type.name); - if (document != null) - { + public static <T extends InfoFacade> MutableInfoFacadeGenerator<T> createMutableFacadeGenerator(GeneratorType<InfoFacadeGenerator<T>> type, + String name, + DataSetFacade data, + MutableInfoFacadeGenerator<T> template) + { + Document document = getCustomGeneratorDocument(data, + type.name); + if (document != null) + { - Element generatorElement = new Element("GENERATOR"); - generatorElement.setAttribute("name", name). - setAttribute("type", "random"); - document.getRootElement().addContent(generatorElement); - try - { - MutableInfoFacadeGenerator<T> generator = (MutableInfoFacadeGenerator<T>) type.mutableClass.getConstructor(Element.class, - DataSetFacade.class).newInstance(generatorElement, - data); - if (template != null) - { - generator.setRandomOrder(template.isRandomOrder()); - for (T facade : template.getAll()) - { - generator.setWeight(facade, - template.getWeight(facade)); - } - } - return generator; - } - catch (Exception ex) - { - Logging.errorPrint("Unable to parse " + document.getBaseURI(), - ex); - } - } + Element generatorElement = new Element("GENERATOR"); + generatorElement.setAttribute("name", name). + setAttribute("type", "random"); + document.getRootElement().addContent(generatorElement); + try + { + MutableInfoFacadeGenerator<T> generator = (MutableInfoFacadeGenerator<T>) type.mutableClass.getConstructor(Element.class, + DataSetFacade.class).newInstance(generatorElement, + data); + if (template != null) + { + generator.setRandomOrder(template.isRandomOrder()); + for (T facade : template.getAll()) + { + generator.setWeight(facade, + template.getWeight(facade)); + } + } + return generator; + } + catch (Exception ex) + { + Logging.errorPrint("Unable to parse " + document.getBaseURI(), + ex); + } + } - return null; - } + return null; + } - private class DefaultCharacterBuild - { - } + private class DefaultCharacterBuild + { + } - public static class DefaultCharacterBuildEditor extends PropertyEditorSupport - { + public static class DefaultCharacterBuildEditor extends PropertyEditorSupport + { - @Override - public Component getCustomEditor() - { - DefaultCharacterBuild build = (GeneratorManager.DefaultCharacterBuild) this.getValue(); + @Override + public Component getCustomEditor() + { + DefaultCharacterBuild build = (GeneratorManager.DefaultCharacterBuild) this.getValue(); - return super.getCustomEditor(); - } + return super.getCustomEditor(); + } - } + } - private class DefaultCharacterBuilder implements CharacterBuild - { + private class DefaultCharacterBuilder implements CharacterBuild + { - private WeightedGenerator<AlignmentFacade> alignmentGenerator; + private WeightedGenerator<AlignmentFacade> alignmentGenerator; - public DefaultCharacterBuilder(Element element) throws MissingDataException - { + public DefaultCharacterBuilder(Element element) throws MissingDataException + { - } + } - public Generator<AlignmentFacade> getAlignmentGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public Generator<AlignmentFacade> getAlignmentGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public Generator<Gender> getGenderGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public Generator<Gender> getGenderGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public Generator<Integer> getStatGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public Generator<Integer> getStatGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public InfoFacadeGenerator<RaceFacade> getRaceGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public InfoFacadeGenerator<RaceFacade> getRaceGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public InfoFacadeGenerator<ClassFacade> getClassGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public InfoFacadeGenerator<ClassFacade> getClassGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public InfoFacadeGenerator<SkillFacade> getSkillGenerator() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public InfoFacadeGenerator<SkillFacade> getSkillGenerator() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public AbilityBuild getAbilityBuild() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public AbilityBuild getAbilityBuild() + { + throw new UnsupportedOperationException("Not supported yet."); + } - public GeneratorManager getGeneratorManager() - { - throw new UnsupportedOperationException("Not supported yet."); - } + public GeneratorManager getGeneratorManager() + { + throw new UnsupportedOperationException("Not supported yet."); + } - } + } - private class AnyWeightedGenerator<E> extends AbstractWeightedGenerator<E> - { + private static class AnyWeightedGenerator<E> extends AbstractWeightedGenerator<E> + { - private final AbstractGenericListDataListener<E> listener = new AbstractGenericListDataListener<E>() - { + private final AbstractGenericListDataListener<E> listener = new AbstractGenericListDataListener<E>() + { - @Override - protected void addData(Collection<? extends E> data) - { - for (E e : data) - { - priorityMap.put(e, 1); - } - } + @Override + protected void addData(Collection<? extends E> data) + { + for (E e : data) + { + priorityMap.put(e, 1); + } + } - @Override - protected void removeData(Collection<? extends E> data) - { - for (E e : data) - { - priorityMap.remove(e); - } - } + @Override + protected void removeData(Collection<? extends E> data) + { + for (E e : data) + { + priorityMap.remove(e); + } + } - }; + }; - public AnyWeightedGenerator(GenericListModel<E> model) - { - super("Any"); - listener.setModel(model); - } + public AnyWeightedGenerator(GenericListModel<E> model) + { + super("Any"); + listener.setModel(model); + } - @Override - protected E getFacade(String name) - { - return null; - } + @Override + protected E getFacade(String name) + { + return null; + } - } + } - private class AnyInfoFacadeGenerator<E extends InfoFacade> extends AnyWeightedGenerator<E> - implements InfoFacadeGenerator<E> - { + private static class AnyInfoFacadeGenerator<E extends InfoFacade> extends AnyWeightedGenerator<E> + implements InfoFacadeGenerator<E> + { - public AnyInfoFacadeGenerator(GenericListModel<E> model) - { - super(model); - } + public AnyInfoFacadeGenerator(GenericListModel<E> model) + { + super(model); + } - @Override - protected E getFacade(String name) - { - return null; - } + @Override + protected E getFacade(String name) + { + return null; + } - public boolean isRandomOrder() - { - return true; - } + public boolean isRandomOrder() + { + return true; + } - public Set<String> getSources() - { - return null; - } + public Set<String> getSources() + { + return null; + } - } + } - private class DefaultAlignmentGenerator extends AbstractWeightedGenerator<AlignmentFacade> - { + private class DefaultAlignmentGenerator extends AbstractWeightedGenerator<AlignmentFacade> + { - //private Queue<E> queue = null; - public DefaultAlignmentGenerator(GeneratorElement element) throws MissingDataException - { - super(element); + //private Queue<E> queue = null; + public DefaultAlignmentGenerator(GeneratorElement element) throws MissingDataException + { + super(element); - } + } - @Override - protected AlignmentFacade getFacade(String name) - { - return dataset.getGameMode().getAlignment(name); - } + @Override + protected AlignmentFacade getFacade(String name) + { + return dataset.getGameMode().getAlignment(name); + } - } + } - private abstract static class AbstractGenerator<E> implements Generator<E> - { + private abstract static class AbstractGenerator<E> implements Generator<E> + { - private String name; - protected GeneratorElement element; + private String name; + protected GeneratorElement element; - public AbstractGenerator(String name) - { - this.name = name; - } + public AbstractGenerator(String name) + { + this.name = name; + } - public AbstractGenerator(GeneratorElement element) - { - this.name = element.getAttributeValue("name"); - this.element = element; - } + public AbstractGenerator(GeneratorElement element) + { + this.name = element.getAttributeValue("name"); + this.element = element; + } - public List<E> getAll() - { - return Collections.emptyList(); - } + public List<E> getAll() + { + return Collections.emptyList(); + } - public void reset() - { + public void reset() + { - } + } - @Override - public String toString() - { - return name; - } + @Override + public String toString() + { + return name; + } - } + } - private static abstract class AbstractWeightedGenerator<E> extends AbstractGenerator<E> - implements WeightedGenerator<E> - { + private static abstract class AbstractWeightedGenerator<E> extends AbstractGenerator<E> + implements WeightedGenerator<E> + { - protected Map<E, Integer> priorityMap = new HashMap<E, Integer>(); - private Queue<E> queue = null; + protected Map<E, Integer> priorityMap = new HashMap<E, Integer>(); + private Queue<E> queue = null; - public AbstractWeightedGenerator(String name) - { - super(name); - queue = new LinkedList<E>(); - } + public AbstractWeightedGenerator(String name) + { + super(name); + queue = new LinkedList<E>(); + } - public AbstractWeightedGenerator(GeneratorElement element) throws MissingDataException - { - super(element); - init(element); - } + public AbstractWeightedGenerator(GeneratorElement element) throws MissingDataException + { + super(element); + init(element); + } - @SuppressWarnings("unchecked") - protected void init(GeneratorElement element) throws MissingDataException - { + @SuppressWarnings("unchecked") + protected void init(GeneratorElement element) throws MissingDataException + { - element.removeChildren("SOURCE"); + element.removeChildren("SOURCE"); - List<Element> children = element.getChildren(); - for (Element child : children) - { - String elementName = child.getText(); - Integer weight = Integer.valueOf(child.getAttributeValue("weight")); - E facade = getFacade(elementName); - if (facade == null) - { - throw new MissingDataException(elementName + - " not found in DataSetFacade"); - } - priorityMap.put(facade, weight); - } - queue = new LinkedList<E>(); - } + List<Element> children = element.getChildren(); + for (Element child : children) + { + String elementName = child.getText(); + Integer weight = Integer.valueOf(child.getAttributeValue("weight")); + E facade = getFacade(elementName); + if (facade == null) + { + throw new MissingDataException(elementName + + " not found in DataSetFacade"); + } + priorityMap.put(facade, weight); + } + queue = new LinkedList<E>(); + } - protected abstract E getFacade(String name); + protected abstract E getFacade(String name); - @Override - public final List<E> getAll() - { - return new ArrayLis... [truncated message content] |