From 34a34d6d27295dbdd5b6be0fcec14854e9d62a6e Mon Sep 17 00:00:00 2001 From: Rafael Chaves <> Date: Sat, 29 Dec 2007 08:58:14 +0000 Subject: [PATCH] first cut of typed settings --- .../META-INF/MANIFEST.MF | 1 + .../engine/tests/SettingKeyTests.java | 2 +- .../umlgraph/engine/tests/SettingTests.java | 338 +++++++++--------- .../org.umlgraph.engine/META-INF/MANIFEST.MF | 4 +- .../{options => }/ClassDiagramOptions.java | 28 +- .../engine/{options => }/ClassOptions.java | 24 +- .../engine/{options => }/DiagramOptions.java | 22 +- .../engine/{options => }/EdgeOptions.java | 14 +- .../engine/{options => }/NodeOptions.java | 21 +- .../engine/{options => }/PackageOptions.java | 10 +- .../umlgraph/engine/options/SettingKey.java | 117 ------ .../org/umlgraph/engine/options/Settings.java | 282 --------------- 12 files changed, 239 insertions(+), 624 deletions(-) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/ClassDiagramOptions.java (67%) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/ClassOptions.java (72%) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/DiagramOptions.java (58%) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/EdgeOptions.java (76%) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/NodeOptions.java (73%) rename umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/{options => }/PackageOptions.java (80%) delete mode 100644 umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/SettingKey.java delete mode 100644 umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/Settings.java diff --git a/umlgraph_ng/org.umlgraph.engine.tests/META-INF/MANIFEST.MF b/umlgraph_ng/org.umlgraph.engine.tests/META-INF/MANIFEST.MF index b34d820..801157a 100644 --- a/umlgraph_ng/org.umlgraph.engine.tests/META-INF/MANIFEST.MF +++ b/umlgraph_ng/org.umlgraph.engine.tests/META-INF/MANIFEST.MF @@ -5,3 +5,4 @@ Bundle-SymbolicName: org.umlgraph.engine.tests Bundle-Version: 1.0.0 Require-Bundle: org.junit, org.umlgraph.engine +Export-Package: org.umlgraph.engine.tests diff --git a/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingKeyTests.java b/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingKeyTests.java index b5ff946..27fd067 100644 --- a/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingKeyTests.java +++ b/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingKeyTests.java @@ -4,7 +4,7 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.umlgraph.engine.options.SettingKey; +import org.umlgraph.settings.SettingKey; public class SettingKeyTests extends TestCase { public SettingKeyTests(String name) { diff --git a/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingTests.java b/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingTests.java index ac1b601..ac11369 100644 --- a/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingTests.java +++ b/umlgraph_ng/org.umlgraph.engine.tests/src/org/umlgraph/engine/tests/SettingTests.java @@ -1,96 +1,47 @@ package org.umlgraph.engine.tests; -import java.util.Collection; - -import org.umlgraph.engine.options.Settings; - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.umlgraph.settings.SettingDefinitions; +import org.umlgraph.settings.Settings; + public class SettingTests extends TestCase { - public void testBasic() { - Settings root = new Settings(); - root.set("@option2", "foo"); - root.set("@option3", Boolean.TRUE); - - assertNull(root.get("@option1")); - assertEquals("foo", root.get("@option2")); - assertTrue(root. get("@option3")); + public static class TestBasicDefinitions implements SettingDefinitions { + public static String option1; + public static String option2; + public static Boolean option3; } - public void testDefault() { - Settings root = new Settings(); - root.set("@option1", "foo"); - root.setDefault("@option2", Boolean.TRUE); - root.set("@option3", 42); - root.setDefault("@option3", 52); - - assertEquals("foo", root.get("@option1")); - assertEquals(Boolean.TRUE, root.get("@option2")); - assertEquals(42, root.get("@option3")); + public static class TestDefault implements SettingDefinitions { + public static String option1 = "bar"; + public static Boolean option2 = true; + public static Integer option3 = 52; } - public void testRemoval() { - Settings root = new Settings(); - root.set("@option1", "foo"); - root.setDefault("@option1", "bar"); - assertEquals("foo", root.get("@option1")); - - root.set("@option1", null); - assertEquals("bar", root.get("@option1")); - - root.setDefault("@option1", null); - assertNull(root.get("@option1")); - + public static class TestFallbackDefinitions implements SettingDefinitions { + public static String option1; + public static String option2; + public static Boolean option3; + public static Integer option4; } - public void testDefaultFirstLevel() { - Settings root = new Settings(); - root.set("context1@option1", "foo"); - root.setDefault("context1@option2", Boolean.TRUE); - root.set("context1@option3", 42); - root.setDefault("context1@option3", 52); - - assertEquals("foo", root.get("context1@option1")); - assertEquals(Boolean.TRUE, root.get("context1@option2")); - assertEquals(42, root.get("context1@option3")); + public static class TestRemovalDefinitions implements SettingDefinitions { + public static String option1 = "bar"; + public static String option2; } - public void testDefaultSecondLevel() { - Settings root = new Settings(); - root.set("context1/context2@option1", "foo"); - root.setDefault("context1/context2@option2", Boolean.TRUE); - root.set("context1/context2@option3", 42); - root.setDefault("context1/context2@option3", 52); - - assertEquals("foo", root.get("context1/context2@option1")); - assertEquals(Boolean.TRUE, root.get("context1/context2@option2")); - assertEquals(42, root.get("context1/context2@option3")); + public static Test suite() { + return new TestSuite(SettingTests.class); } - public void testFirstLevel() { - Settings root = new Settings(); - root.set("context1@option2", "foo"); - root.set("context1@option3", Boolean.TRUE); - - assertNull(root.get("context1@option1")); - assertEquals("foo", root.get("context1@option2")); - assertTrue(root. get("context1@option3")); + public SettingTests(String name) { + super(name); } - - public void testSecondLevel() { - Settings root = new Settings(); - root.set("context1/context2/@option2", "foo"); - root.set("context1/context2/@option3", Boolean.TRUE); - - assertNull(root.get("context1/context2/@option1")); - assertEquals("foo", root.get("context1/context2/@option2")); - assertTrue(root. get("context1/context2/@option3")); - } - + public void testBasicFallback() { - Settings root = new Settings(); + Settings root = new Settings(TestFallbackDefinitions.class); root.set("@option2", "foo"); root.set("@option3", Boolean.TRUE); root.set("context1/@option3", Boolean.FALSE); @@ -116,87 +67,8 @@ public class SettingTests extends TestCase { assertEquals(42, root.get("context1/context2@option4")); } - public void testFallbackWithDefaults() { - Settings root = new Settings(); - root.set("@option1", "foo"); - root.setDefault("@option2", Boolean.TRUE); - - root.setDefault("context1/@option1", "zoo"); - - root.setDefault("context1/context2/@option1", null); - - assertEquals("zoo", root.get("context1@option1")); - assertEquals(Boolean.TRUE, root.get("context1@option2")); - assertNull(root.get("context1@option1", false)); - - assertEquals("zoo", root.get("context1/context2@option1")); - assertEquals(Boolean.TRUE, root.get("context1/context@option2")); - } - - public void testSetToDefault() { - Settings root = new Settings(); - root.set("@option1", "foo"); - root.setDefault("@option1", "bar"); - - root.set("context1/@option1", "zoo"); - root.set("context1/@option2", Boolean.TRUE); - - assertEquals("zoo", root.get("context1/context2@option1")); - root.setToDefault("context1/context2@option1"); - assertEquals("bar", root.get("context1/context2@option1")); - - assertEquals(true, root.get("context1/context2@option2")); - try { - root.setToDefault("context1/context2@option2"); - fail("should have failed"); - } catch (IllegalStateException ise) { - // expected - } - } - - public void testDefaultCancellation() { - Settings root = new Settings(); - root.set("@option2", "foo"); - root.setDefault("@option3", Boolean.TRUE); - root.set("context1/@option3", Boolean.FALSE); - root.set("context1/@option4", 42); - root.set("context1/context2/@option1", "zoo"); - root.set("context1/context2/@option2", "bar"); - root.set("context1/context2/@option3", Boolean.TRUE); - - assertNull(root.get("@option1")); - assertNull(root.get("context1/@option1")); - assertEquals("zoo", root.get("context1/context2/@option1")); - - assertEquals("foo", root.get("@option2")); - assertEquals("foo", root.get("context1/@option2")); - assertEquals("bar", root.get("context1/context2@option2")); - - assertEquals(Boolean.TRUE, root.get("@option3")); - assertEquals(Boolean.FALSE, root.get("context1/@option3")); - assertEquals(Boolean.TRUE, root.get("context1/context2@option3")); - - assertEquals(null, root.get("@option4")); - assertEquals(42, root.get("context1/@option4")); - assertEquals(42, root.get("context1/context2@option4")); - } - - public void testOptionKeys() { - Settings root = new Settings(); - root.set("@option2", "foo"); - root.set("@option3", Boolean.TRUE); - root.setDefault("@option4", 42); - - Collection keys = root.getOptionKeys(); - assertEquals(2, keys.size()); - assertFalse(keys.contains("option1")); - assertTrue(keys.contains("option2")); - assertTrue(keys.contains("option3")); - assertFalse(keys.contains("option4")); - } - public void testContextCreation() { - Settings root = new Settings(); + Settings root = new Settings(TestBasicDefinitions.class); Settings context1 = root.node("context1"); assertNotNull(context1); Settings context2 = root.node("context1/context2"); @@ -212,20 +84,8 @@ public class SettingTests extends TestCase { assertTrue(root.nodeExists("context1/context3")); } - public void testParenting() { - Settings root = new Settings(); - Settings context1 = root.node("context1"); - Settings context2 = root.node("context1/context2"); - Settings context3 = root.node("context1/context3"); - - assertNull(root.getParent()); - assertSame(root, context1.getParent()); - assertSame(context1, context2.getParent()); - assertSame(context1, context3.getParent()); - } - public void testContextCreationByOption() { - Settings root = new Settings(); + Settings root = new Settings(TestBasicDefinitions.class); root.set("@option1", "foo"); root.set("context1@option2", "bar"); root.set("context1/context2@option3", "zoo"); @@ -237,11 +97,147 @@ public class SettingTests extends TestCase { assertFalse(root.nodeExists("context2")); } - public SettingTests(String name) { - super(name); + public void testDefault() { + Settings root = new Settings(TestDefault.class); + root.set("@option1", "foo"); + root.set("@option3", 42); + + assertEquals("foo", root.get("@option1")); + assertEquals(Boolean.TRUE, root.get("@option2")); + assertEquals(42, root.get("@option3")); + root.set("@option3", null); + assertEquals(52, root.get("@option3")); } - public static Test suite() { - return new TestSuite(SettingTests.class); + public void testDefaultCancellation() { + Settings root = new Settings(TestBasicDefinitions.class); + root.set("@option2", "foo"); + root.set("context1/@option3", Boolean.FALSE); + root.set("context1/@option4", 42); + root.set("context1/context2/@option1", "zoo"); + root.set("context1/context2/@option2", "bar"); + root.set("context1/context2/@option3", Boolean.TRUE); + + assertNull(root.get("@option1")); + assertNull(root.get("context1/@option1")); + assertEquals("zoo", root.get("context1/context2/@option1")); + + assertEquals("foo", root.get("@option2")); + assertEquals("foo", root.get("context1/@option2")); + assertEquals("bar", root.get("context1/context2@option2")); + + assertEquals(null, root.get("@option3")); + assertEquals(Boolean.FALSE, root.get("context1/@option3")); + assertEquals(Boolean.TRUE, root.get("context1/context2@option3")); + } + + public void testDefaultFirstLevel() { + Settings root = new Settings(TestDefault.class); + root.set("context1@option1", "foo"); + root.set("context1@option3", 42); + + assertEquals("foo", root.get("context1@option1")); + assertEquals(Boolean.TRUE, root.get("context1@option2")); + assertEquals(42, root.get("context1@option3")); + } + + public void testDefaultSecondLevel() { + Settings root = new Settings(TestDefault.class); + root.set("context1/context2@option1", "foo"); + root.set("context1/context2@option3", 42); + + assertEquals("foo", root.get("context1/context2@option1")); + assertEquals(Boolean.TRUE, root.get("context1/context2@option2")); + assertEquals(42, root.get("context1/context2@option3")); + } + + public void testFallbackWithDefaults() { + Settings root = new Settings(TestDefault.class); + root.set("@option1", "zoo"); + + assertEquals("zoo", root.get("context1@option1")); + assertEquals(Boolean.TRUE, root.get("context1@option2")); + assertNull(root.get("context1@option1", false)); + + root.set("@option1", null); + assertEquals("bar", root.get("context1/context2@option1")); + assertEquals(Boolean.TRUE, root.get("context1/context@option2")); + } + + public void testFirstLevel() { + Settings root = new Settings(TestBasicDefinitions.class); + root.set("context1@option2", "foo"); + root.set("context1@option3", Boolean.TRUE); + + assertNull(root.get("context1@option1")); + assertEquals("foo", root.get("context1@option2")); + assertTrue(root. get("context1@option3")); + } + + public void testParenting() { + Settings root = new Settings(TestBasicDefinitions.class); + Settings context1 = root.node("context1"); + Settings context2 = root.node("context1/context2"); + Settings context3 = root.node("context1/context3"); + + assertNull(root.getParent()); + assertSame(root, context1.getParent()); + assertSame(context1, context2.getParent()); + assertSame(context1, context3.getParent()); + } + + public void testRemoval() { + Settings root = new Settings(TestRemovalDefinitions.class); + root.set("@option1", "foo"); + root.set("@option2", "zoo"); + assertEquals("foo", root.get("@option1")); + assertEquals("zoo", root.get("@option2")); + + root.set("@option1", null); + root.set("@option2", null); + assertEquals("bar", root.get("@option1")); + assertNull(root.get("@option2")); + } + + public void testRoot() { + Settings root = new Settings(TestBasicDefinitions.class); + root.set("@option2", "foo"); + root.set("@option3", Boolean.TRUE); + + assertNull(root.get("@option1")); + assertEquals("foo", root.get("@option2")); + assertTrue(root. get("@option3")); + } + + public void testSecondLevel() { + Settings root = new Settings(TestBasicDefinitions.class); + root.set("context1/context2/@option2", "foo"); + root.set("context1/context2/@option3", Boolean.TRUE); + + assertNull(root.get("context1/context2/@option1")); + assertEquals("foo", root.get("context1/context2/@option2")); + assertTrue(root. get("context1/context2/@option3")); + } + + public void testSetToDefault() { + Settings root = new Settings(TestDefault.class); + root.set("@option1", "foo"); + + root.set("context1/@option1", "zoo"); + root.set("context1/@option2", Boolean.TRUE); + + assertEquals("zoo", root.get("context1/context2@option1")); + root.setToDefault("context1/context2@option1"); + assertEquals("bar", root.get("context1/context2@option1")); + + assertEquals(true, root.get("context1/context2@option2")); + // clear default value + TestDefault.option2 = null; + try { + root.setToDefault("context1/context2@option2"); + fail("should have failed"); + } catch (IllegalStateException ise) { + // expected + } } } diff --git a/umlgraph_ng/org.umlgraph.engine/META-INF/MANIFEST.MF b/umlgraph_ng/org.umlgraph.engine/META-INF/MANIFEST.MF index 3c9948c..a96e010 100644 --- a/umlgraph_ng/org.umlgraph.engine/META-INF/MANIFEST.MF +++ b/umlgraph_ng/org.umlgraph.engine/META-INF/MANIFEST.MF @@ -4,5 +4,5 @@ Bundle-Name: UMLGraph Bundle-SymbolicName: org.umlgraph.engine Bundle-Version: 5.0.0.qualifier Bundle-Vendor: umlgraph.org -Require-Bundle: org.eclipse.equinox.preferences -Export-Package: org.umlgraph.engine.options +Require-Bundle: org.umlgraph.settings;visibility:=reexport +Export-Package: org.umlgraph.engine diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassDiagramOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassDiagramOptions.java similarity index 67% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassDiagramOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassDiagramOptions.java index ce12df4..8c25607 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassDiagramOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassDiagramOptions.java @@ -15,39 +15,41 @@ * $Id$ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** * Constants for class diagram options. */ -public interface ClassDiagramOptions { +public class ClassDiagramOptions implements SettingDefinitions { /** - * Produce fully-qualified class names (boolean). + * Produce fully-qualified class names. */ - String QUALIFIED_NAMES = "classDiagramQualifiedNames"; + public static boolean classDiagramQualifiedNames; /** * When using qualified class names, put the package name in the line after the class name, in order to reduce the width of class nodes. */ - String POSTFIX_QUALIFIED_NAMES = "classDiagramPostfixQualifiedNames"; + public static boolean classDiagramPostfixQualifiedNames; /** - * Try to automatically infer dependencies between classes by inspecting operation and attribute types. See the class diagram inference chapter for more details. Disabled by default. (boolean) + * Try to automatically infer dependencies between classes by inspecting operation and attribute types. See the class diagram inference chapter for more details. Disabled by default. */ - String INFER_DEPENDENCY = "classDiagramInferDependency"; + public static boolean classDiagramInferDependency; /** - * Try to automatically infer association relationships between classes by inspecting attribute types. See the class diagram inference chapter for further details. Disabled by default. (boolean) + * Try to automatically infer association relationships between classes by inspecting attribute types. See the class diagram inference chapter for further details. Disabled by default. */ - String INFER_ASSOCIATIONS = "classDiagramInferUsage"; + public static boolean classDiagramInferUsage; /** - * The type of relationship inferred when -inferrel is activated. Defaults to "navassoc" (see the class modelling chapter for a list of relationship types). (String) + * The type of relationship inferred when -inferrel is activated. Defaults to "navassoc" (see the class modelling chapter for a list of relationship types). */ - String INFER_ASSOCIATION_TYPE = "classDiagramInferAssociationType"; + public static String classDiagramInferAssociationType; /** - * Specifies the lowest visibility level of elements used to infer dependencies among classes. Possible values are private, package, protected, public, in this order. The default value is private. Use higher levels to limit the number of inferred dependencies. (String) + * Specifies the lowest visibility level of elements used to infer dependencies among classes. Possible values are private, package, protected, public, in this order. The default value is private. Use higher levels to limit the number of inferred dependencies. */ - String INFER_DEPENDENCY_VISIBILITY = "classDiagramInferDependencyVisibility"; + public static String classDiagramInferDependencyVisibility; } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassOptions.java similarity index 72% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassOptions.java index 552f728..dd302ec 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/ClassOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/ClassOptions.java @@ -16,55 +16,57 @@ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** * Constants for class options. */ -public interface ClassOptions { +public class ClassOptions implements SettingDefinitions { /** * Specify the font name to use inside abstract class nodes (String). */ - String FONT_NAME_ABSTRACT_CLASS = "classAbstractFontName"; + public static String classAbstractFontName; /** * Specify the font name to use for the class names (String). */ - String FONT_NAME_CLASS_NAME = "classNameFontName"; + public static String classNameFontName; /** * Specify the font name use for the class name of abstract classes * (String). */ - String FONT_NAME_ABSTRACT_CLASS_NAME = "classAbstractNameFontName"; + public static String classAbstractNameFontName; /** * Specify the font size to use for the class names (int). */ - String FONT_SIZE_CLASS_NAME = "classNameFontSize"; + public static int classNameFontSize; /** * Show class attributes (boolean). */ - String SHOW_ATTRIBUTES = "classShowAttributes"; + public static boolean classShowAttributes; /** * Show class operations (Java methods) */ - String SHOW_OPERATIONS = "classShowOperations"; + public static boolean classShowOperations; /** * Adorn class elements according to their visibility (private, public, protected, package) (boolean). */ - String SHOW_VISIBILITY = "classShowVisibility"; + public static boolean classShowVisibility; /** * Add type information to attributes and operations (boolean) */ - String SHOW_TYPES = "classFeatureTypes"; + public static boolean classFeatureTypes; /** * For enumerations, also show the values they can take. (boolean) */ - String SHOW_ENUM_VALUES = "classShowEnumValues"; + public static boolean classShowEnumValues; } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/DiagramOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/DiagramOptions.java similarity index 58% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/DiagramOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/DiagramOptions.java index e939834..5284dd5 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/DiagramOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/DiagramOptions.java @@ -16,24 +16,32 @@ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** * Generic constants for options applicable to all types of UML diagrams. */ -public interface DiagramOptions { +public class DiagramOptions implements SettingDefinitions { /** * Layout the graph in the horizontal direction (boolean). */ - String HORIZONTAL = "diagramHorizontal"; - + public static boolean diagramHorizontal; + /** * Specify the graph's background color. */ - String BACKGROUND_COLOR = "diagramBackgroundColor"; + public static String diagramBackgroundColor; /** - * Specify entities to hide from the graph. Matching is done using a non-anchored regular match. For instance, "-hide (Big|\.)Widget" would hide "com.foo.widgets.Widget" and "com.foo.widgets.BigWidget". Can also be used without arguments, in this case it will hide everything (useful in the context of views to selectively unhide some portions of the graph, see the view chapter for further details). */ - String hide(); + * Specify entities to hide from the graph. Matching is done using a + * non-anchored regular match. For instance, "-hide (Big|\.)Widget" would + * hide "com.foo.widgets.Widget" and "com.foo.widgets.BigWidget". Can also + * be used without arguments, in this case it will hide everything (useful + * in the context of views to selectively unhide some portions of the graph, + * see the view chapter for further details). + */ + // TODO String hide(); } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/EdgeOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/EdgeOptions.java similarity index 76% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/EdgeOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/EdgeOptions.java index c53521f..6845ba4 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/EdgeOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/EdgeOptions.java @@ -16,26 +16,28 @@ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** * Constants for edge options. */ -public interface EdgeOptions { +public class EdgeOptions implements SettingDefinitions { /** * Specify the font name to use for edge labels (String). */ - public String FONT_NAME = "edgeFontName"; + public static String edgeFontName; /** * Specify the font size to use for edge labels (int). */ - public String FONT_SIZE = "edgeFontSize"; + public static int edgeFontSize; /** * Specify the font color to use for edge labels (String). */ - public String FONT_COLOR = "edgeFontColor"; + public static String edgeFontColor; /** * Specify the color for drawing edges. */ - public String COLOR = "edgeColor"; + public static String edgeColor; } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/NodeOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/NodeOptions.java similarity index 73% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/NodeOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/NodeOptions.java index aaa0642..ffb6587 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/NodeOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/NodeOptions.java @@ -16,39 +16,40 @@ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** - * Constants for node options. + * Node options. */ -public interface NodeOptions { +public class NodeOptions implements SettingDefinitions { /** * Specify the color to use to fill the shapes (String). */ - public String FILL_COLOR = "nodeFillColor"; + public static String nodeFillColor; /** * Specify the font name to use inside nodes (String). */ - public String FONT_NAME = "nodeFontName"; + public static String nodeFontName; /** * Specify the font size to use inside nodes (int). */ - public String FONT_SIZE = "nodeFontSize"; + public static int nodeFontSize; /** * Specify the font name to use for the tags (String). */ - public String FONT_NAME_TAG = "nodeTagFontName"; + public static String nodeTagFontName; /** * Specify the font size to use for the tags (int). */ - public String FONT_SIZE_TAG = "nodeTagFontSize"; + public static int nodeTagFontSize; /** * Specify the font color to use inside nodes (String). */ - public String FONT_COLOR = "nodeFontColor"; - + public static String nodeFontColor; } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/PackageOptions.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/PackageOptions.java similarity index 80% rename from umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/PackageOptions.java rename to umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/PackageOptions.java index d32cd83..9727e98 100644 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/PackageOptions.java +++ b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/PackageOptions.java @@ -16,22 +16,24 @@ * */ -package org.umlgraph.engine.options; +package org.umlgraph.engine; + +import org.umlgraph.settings.SettingDefinitions; /** * Constants for package options. */ -public interface PackageOptions { +public class PackageOptions implements SettingDefinitions { /** * Specify the font name to use for the package names (used only when the * package name is postfixed, see -postfixpackage). */ - String FONT_NAME_PACKAGE_NAME = "packageNameFontName"; + public static String packageNameFontName; /** * Specify the font size to use for the package names (used only when it * package name is postfixed, see -postfixpackage). */ - String FONT_SIZE_PACKAGE_NAME = "packageNameFontSize"; + public static int packageNameFontSize; } diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/SettingKey.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/SettingKey.java deleted file mode 100644 index edd5f8f..0000000 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/SettingKey.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * (C) Copyright 2007-2008 Abstratt Technologies - * - * Permission to use, copy, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id$ - * - */ -package org.umlgraph.engine.options; - -import java.util.Arrays; -import java.util.StringTokenizer; - -/** - * A key for accessing a specific setting. - */ -public class SettingKey { - private static final String PATH_DELIMITER = "/"; - private static final String OPTION_DELIMITER = "@"; - private static final String[] EMPTY_CONTEXT_PATH = {}; - - private String[] nodePath; - private String key; - - public SettingKey(String[] nodePath, String key) { - this.nodePath = nodePath; - this.key = key; - } - - public SettingKey(String stringKey) { - int atIndex = stringKey.indexOf(OPTION_DELIMITER); - if (atIndex >= 0) { - if (atIndex == stringKey.length() - 1) - throw new IllegalArgumentException("argument: " + stringKey); - key = stringKey.substring(atIndex + 1); - if (atIndex == 0) { - nodePath = EMPTY_CONTEXT_PATH; - return; - } - } - String nodePathStr = atIndex < 0 ? stringKey : stringKey.substring(0, - atIndex); - StringTokenizer pathSegmenter = new StringTokenizer(nodePathStr, - PATH_DELIMITER); - nodePath = new String[pathSegmenter.countTokens()]; - int i = 0; - while (pathSegmenter.hasMoreTokens()) - nodePath[i++] = pathSegmenter.nextToken(); - } - - public String[] getNodePath() { - return nodePath; - } - - public boolean isRoot() { - return nodePath.length == 0; - } - - public boolean hasKey() { - return key != null; - } - - - public String getKey() { - return key; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + Arrays.hashCode(nodePath); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final SettingKey other = (SettingKey) obj; - if (key == null) { - if (other.key != null) - return false; - } else if (!key.equals(other.key)) - return false; - if (!Arrays.equals(nodePath, other.nodePath)) - return false; - return true; - } - - @Override - public String toString() { - StringBuffer result = new StringBuffer(PATH_DELIMITER); - for (int i = 0; i < nodePath.length; i++) { - result.append(nodePath[i]); - result.append(PATH_DELIMITER); - } - if (hasKey()) { - result.append(OPTION_DELIMITER); - result.append(key); - } - return result.toString(); - } -} \ No newline at end of file diff --git a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/Settings.java b/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/Settings.java deleted file mode 100644 index 7e33f5c..0000000 --- a/umlgraph_ng/org.umlgraph.engine/src/org/umlgraph/engine/options/Settings.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * (C) Copyright 2007-2008 Abstratt Technologies - * - * Permission to use, copy, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id$ - * - */ - -package org.umlgraph.engine.options; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * A typed hierarchic preferences mechanism that takes advantage of - * generics for providing a simpler protocol. - * - * Features: - *
    - *
  • default values
  • - *
  • contexts are hierarchic, option value lookup falls back to parent - * if option is not found at the current level
  • - *
  • - * options are typed, so an attempt at setting them with the wrong value - * type causes an exception - *
  • - *
  • - * option contexts are statically typed, meaning that set of - * available options for a context is defined at compile time - * and trying to set an unexpected option value causes an - * exception. - *
  • - *
- * Non-features: - *
    - *
  • - * persistence - *
  • - *
- */ -public class Settings { - /* - * The child setting nodes. - */ - private Map children = new HashMap(); - /* - * The setting values defined for this setting node. - */ - private Map values = new HashMap(); - /* - * The default values defined for this setting node. - */ - private Map defaultValues = new HashMap(); - - private Settings parent; - - - public Settings() { - - } - - private Settings(Settings parent) { - this.parent = parent; - } - /** - * Returns the setting node corresponding to the given path. If the node - * does not exist, returns a new empty node. - * - * @param path - * the setting node path - * @return the setting node corresponding to the given path - */ - public Settings node(String[] path) { - return createNode(path, 0); - } - - public Settings node(String path) { - return node(new SettingKey(path).getNodePath()); - } - - /** - * Creates a setting node under the given path, or returns the existing one. - */ - private Settings createNode(String[] path, int start) { - if (path.length == start) - return this; - Settings found = children.get(path[start]); - if (found == null) - children.put(path[start], found = new Settings(this)); - if (start == path.length - 1) - return found; - return found.createNode(path, start + 1); - } - - /** - * Returns whether the given node exists. - */ - public boolean nodeExists(String[] path) { - return existingNode(path) != null; - } - - public boolean nodeExists(String path) { - return nodeExists(new SettingKey(path).getNodePath()); - } - - /** - * Returns an existing setting node corresponding to the given path. - * - * @param path - * the setting path - * @return the settings object, or null - */ - public Settings existingNode(String[] segments) { - Settings current = this; - for (String segment : segments) { - current = current.children.get(segment); - if (current == null) - return null; - } - return current; - } - - public Settings existingNode(String path) { - return existingNode(new SettingKey(path).getNodePath()); - } - - /** - * Returns the value of the option corresponding to the given key. If - * acceptDefault is true and a value for the option does not - * exist, returns the default value. Otherwise, returns null. - * - * @param key - * the option key - * @param acceptDefault - * whether a default value should be returned - * @return the value for the given key, or null - */ - public T get(SettingKey key, boolean acceptDefault) { - if (!acceptDefault) { - Settings node = existingNode(key.getNodePath()); - return node == null ? null : (T) node.values.get(key.getKey()); - } - Settings node = lastExistingNode(key.getNodePath(), 0); - return node.searchValue(key.getKey()); - } - - private T searchValue(String key) { - T ownValue = (T) values.get(key); - if (ownValue != null) - return ownValue; - T ownDefaultValue = (T) defaultValues.get(key); - if (ownDefaultValue != null) - return ownDefaultValue; - return (T) (parent == null ? null : parent.searchValue(key)); - } - - private T searchDefaultValue(String key) { - T ownDefaultValue = (T) defaultValues.get(key); - if (ownDefaultValue != null) - return ownDefaultValue; - return (T) (parent == null ? null : parent.searchDefaultValue(key)); - } - - - private Settings lastExistingNode(String[] nodePath, int start) { - if (start == nodePath.length) - return this; - Settings immediateChild = children.get(nodePath[start]); - return immediateChild == null ? this : immediateChild.lastExistingNode(nodePath, start+1); - } - - /** - * Returns the value of the option corresponding to the given path. If - * acceptDefault is true and a value for the option does not - * exist, returns the default value. Otherwise, returns null. - * This is just a convenience method for {@link #get(SettingKey, boolean)}. - * - * @param path - * the option path - * @param acceptDefault - * whether a default value should be returned - * @return the value for the given path, or null - */ - - public T get(String path, boolean acceptDefault) { - return get(new SettingKey(path), acceptDefault); - } - - public T get(String path) { - return get(new SettingKey(path), true); - } - - /** - * Sets the value for the given option. - * - * @param key - * the option key - * @param value - * the new value, or null - */ - public void set(SettingKey key, T value) { - if (value == null) { - Settings node = existingNode(key.getNodePath()); - if (node != null) - node.values.remove(key.getKey()); - } else { - Settings node = createNode(key.getNodePath(), 0); - node.values.put(key.getKey(), value); - } - } - - public void set(String path, T value) { - set(new SettingKey(path), value); - } - - public void setToDefault(String path) { - setToDefault(new SettingKey(path)); - } - - /** - * Sets the given option to its current default value. - * - * @param settingKey the key to set to default - */ - public void setToDefault(SettingKey settingKey) { - T defaultValue = node(settingKey.getNodePath()).searchDefaultValue(settingKey.getKey()); - if (defaultValue == null) - throw new IllegalStateException(); - set(settingKey, defaultValue); - } - - /** - * Sets the default value for the given option. - * - * @param key - * the option key - * @param value - * the new value, or null - */ - public void setDefault(SettingKey key, T defaultValue) { - if (defaultValue == null) { - Settings node = existingNode(key.getNodePath()); - if (node != null) - node.defaultValues.remove(key.getKey()); - } else { - Settings node = createNode(key.getNodePath(), 0); - node.defaultValues.put(key.getKey(), defaultValue); - } - } - - public void setDefault(String path, T defaultValue) { - setDefault(new SettingKey(path), defaultValue); - } - - /** - * Returns all options set for this context. - * - * @return - */ - public Collection getOptionKeys() { - return this.values.keySet(); - } - - /** - * Returns the parent settings, or null if this is a root setting. - * - * @return the parent settings, or null - */ - public Settings getParent() { - return parent; - } -}