svn commit: r14995 - trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2008-06-17 14:22:38-0700
New Revision: 14995

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java

Log:
Implement the new DiagramFactoryInterface

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java?view=diff&rev=14995&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java&r1=14994&r2=14995
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/DiagramFactory.java	2008-06-17 14:22:38-0700
@@ -56,6 +56,8 @@
 */
 public final class DiagramFactory {
 
+    private final Map noStyleProperties = new HashMap();
+
     /**
      * Map from our public enum to our internal implementation classes.
      * This allows use to hide the implementation classes from users of
@@ -80,6 +82,9 @@
    
     private List<ArgoDiagram> diagrams = new ArrayList<ArgoDiagram>();
 
+    private Map<DiagramType, DiagramFactoryInterface> factories =
+        new EnumMap<DiagramType, DiagramFactoryInterface>(DiagramType.class);
+
     private DiagramFactory() {
         super();
         diagramClasses.put(DiagramType.Class, UMLClassDiagram.class);
@@ -101,6 +106,7 @@
 
     /**
      * @return the list of diagrams
+     * @deprecated in 0.26 By Bob Tarling
      */
     public List<ArgoDiagram> getDiagram() {
         // TODO: This list is currently unused in ArgoUML.  Since it's session
@@ -130,9 +136,22 @@
      *                         (only: statemachine - activitygraph)
      * @return the newly instantiated class diagram
      */
-    public ArgoDiagram createDiagram(DiagramType type, Object namespace,
-            Object machine) {
-        return createDiagram(diagramClasses.get(type), namespace, machine);
+    public ArgoDiagram createDiagram(
+            final DiagramType type, 
+            final Object namespace,
+            final Object machine) {
+        
+        DiagramFactoryInterface factory = factories.get(type);
+        if (factory != null) {
+            final ArgoDiagram diagram =
+                factory.createDiagram(namespace, machine);
+            //keep a reference on it in the case where we must add all the
+            //diagrams as project members (loading)
+            diagrams.add(diagram);
+            return diagram;
+        } else {
+            return createDiagram(diagramClasses.get(type), namespace, machine);
+        }
     }
     
     /**
@@ -182,6 +201,8 @@
         }
         
         if (Model.getDiagramInterchangeModel() != null) {
+            // TODO: This is never executed as Ludos DI work was never
+            // finished.
             diagram.getGraphModel().addGraphEventListener(
                  GraphChangeAdapter.getInstance());
             /*
@@ -235,8 +256,6 @@
 //    }
 
 
-    private final Map noStyleProperties = new HashMap();
-
     public Object createRenderingElement(Object diagram, Object model) {
         GraphNodeRenderer rend =
             ((Diagram) diagram).getLayer().getGraphNodeRenderer();
@@ -244,4 +263,16 @@
                 rend.getFigNodeFor(model, 0, 0, noStyleProperties);
         return renderingElement;
     }
+    
+    /**
+     * Register a specific factory class to create diagram instances for a
+     * specific diagram type
+     * @param type the diagram type
+     * @param factory the factory instance
+     */
+    public void registerDiagramFactory(
+            final DiagramType type,
+            final DiagramFactoryInterface factory) {
+        factories.put(type, factory);
+    }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.