Author: rfeng
Date: Wed Sep 21 20:59:17 2011
New Revision: 1173855

URL: http://svn.apache.org/viewvc?rev=1173855&view=rev
Log:
Calculate the height/width for components/composites based on its content

Added:
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
   (with props)
Modified:
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
    
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
 Wed Sep 21 20:59:17 2011
@@ -35,12 +35,12 @@ public class ComponentArtifact extends A
         this.setyCoordinate(y);
 
         Element rectangle = document.createElementNS(svgNs, "rect");
-        rectangle.setAttributeNS(null, "x", x + "");
-        rectangle.setAttributeNS(null, "y", y + "");
+        rectangle.setAttributeNS(null, "x", String.valueOf(x));
+        rectangle.setAttributeNS(null, "y", String.valueOf(y));
         rectangle.setAttributeNS(null, "rx", getRoundCorner());
         rectangle.setAttributeNS(null, "ry", getRoundCorner());
-        rectangle.setAttributeNS(null, "width", width + "");
-        rectangle.setAttributeNS(null, "height", height + "");
+        rectangle.setAttributeNS(null, "width", String.valueOf(width));
+        rectangle.setAttributeNS(null, "height", String.valueOf(height));
 //        rectangle.setAttributeNS(null, "fill", "#3D59AB");
 //        rectangle.setAttributeNS(null, "stroke", "#104E8B");
 //        rectangle.setAttributeNS(null, "fill-opacity", "0.75");

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
 Wed Sep 21 20:59:17 2011
@@ -36,15 +36,15 @@ public class CompositeArtifact extends A
         this.setyCoordinate(y);
 
         Element rectangle = document.createElementNS(svgNs, "rect");
-        rectangle.setAttributeNS(null, "x", x + "");
-        rectangle.setAttributeNS(null, "y", y + "");
+        rectangle.setAttributeNS(null, "x", String.valueOf(x));
+        rectangle.setAttributeNS(null, "y", String.valueOf(y));
         rectangle.setAttributeNS(null, "rx", getRoundCorner());
         rectangle.setAttributeNS(null, "ry", getRoundCorner());
-        rectangle.setAttributeNS(null, "width", width + "");
-        rectangle.setAttributeNS(null, "height", height + "");
-//        rectangle.setAttributeNS(null, "fill", "#E5E5E5");
-//        rectangle.setAttributeNS(null, "stroke", "#919191");
-//        rectangle.setAttributeNS(null, "alignment-baseline", "middle");
+        rectangle.setAttributeNS(null, "width", String.valueOf(width));
+        rectangle.setAttributeNS(null, "height", String.valueOf(height));
+        //        rectangle.setAttributeNS(null, "fill", "#E5E5E5");
+        //        rectangle.setAttributeNS(null, "stroke", "#919191");
+        //        rectangle.setAttributeNS(null, "alignment-baseline", 
"middle");
         rectangle.setAttributeNS(null, "class", "composite");
 
         return rectangle;

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
 Wed Sep 21 20:59:17 2011
@@ -25,20 +25,20 @@ public final class Constant {
     public static final int COMPONENT_TEXT_SPACING = 20;
 
     public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY = 
20;
-    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY = 
60;
+    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY = 
40;
     public static final int SPACING_FOR_COMPONENT_OF_PROPERTY = 20;
-    public static final int SPACING_FOR_COMPOSITE_OF_PROPERTY = 60;
+    public static final int SPACING_FOR_COMPOSITE_OF_PROPERTY = 40;
 
     public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE 
= 30;
-    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE 
= 90;
+    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE 
= 60;
     public static final int SPACING_FOR_COMPONENT_OF_REFERENCE = 10;
-    public static final int SPACING_FOR_COMPOSITE_OF_REFERENCE = 50;
+    public static final int SPACING_FOR_COMPOSITE_OF_REFERENCE = 30;
 
     public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE = 
30;
-    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE = 
90;
+    public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE = 
60;
     public static final int SPACING_FOR_COMPONENT_OF_SERVICE = 10;
-    public static final int SPACING_FOR_COMPOSITE_OF_SERVICE = 50;
+    public static final int SPACING_FOR_COMPOSITE_OF_SERVICE = 30;
 
-    public static final int SPACING_FOR_TEXT = 1;
+    public static final int SPACING_FOR_TEXT = 2;
 
 }

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
 Wed Sep 21 20:59:17 2011
@@ -42,9 +42,9 @@ public class Layer extends Artifact {
         rectangle.setAttributeNS(null, "ry", getRoundCorner());
         rectangle.setAttributeNS(null, "width", width + "");
         rectangle.setAttributeNS(null, "height", height + "");
-        rectangle.setAttributeNS(null, "fill", "#E5E5D0");
-        rectangle.setAttributeNS(null, "stroke", "#919191");
-        rectangle.setAttributeNS(null, "alignment-baseline", "middle");
+//        rectangle.setAttributeNS(null, "fill", "#E5E5D0");
+//        rectangle.setAttributeNS(null, "stroke", "#919191");
+//        rectangle.setAttributeNS(null, "alignment-baseline", "middle");
         rectangle.setAttributeNS(null, "class", "layer");
 
         return rectangle;

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
 Wed Sep 21 20:59:17 2011
@@ -33,7 +33,7 @@ public class Link {
         Element link = document.createElementNS(svgNs, "a");
         link.setAttributeNS(null, "xlink:href", fileName);
         link.setAttributeNS(null, "xlink:show", "new");
-        link.setTextContent(" " + compName + " ,");
+        link.setTextContent(" [" + compName + "] ");
 
         return link;
     }

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
 Wed Sep 21 20:59:17 2011
@@ -108,7 +108,8 @@ public class Style {
             }
         }
         reader.close();
-        return sw.toString();
-
+        String template = sw.toString();
+        // Remove the ASF license header
+        return template.replaceFirst("/\\*(?:.|[\\n\\r])*?\\*/", "");
     }
 }

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
 Wed Sep 21 20:59:17 2011
@@ -62,12 +62,12 @@ public class DiagramGenerator {
 
     private int lastUsedChangingFactor = 0;
 
-    enum changingFactor {
+    enum ChangingFactor {
         a(20), b(25), c(30), d(35), e(40), f(15);
 
         private final int val;
 
-        private changingFactor(int x) {
+        private ChangingFactor(int x) {
             val = x;
         }
 
@@ -77,7 +77,7 @@ public class DiagramGenerator {
 
     };
 
-    enum color {
+    enum Color {
         black
     }//, violet, red, green};
 
@@ -190,15 +190,15 @@ public class DiagramGenerator {
         if (!comp.getIncludedComposites().isEmpty()) {
 
             Layer inclusionLayer = new Layer();
-            int constant = 5;
+            int constant = 10;
             int x0 = comp.getX() + constant;
-            int y0 = comp.getY() + comp.getHeight() - 
(Constant.COMPONENT_DEFAULT_HEIGHT / 2 + constant);
-            int height = Constant.COMPONENT_DEFAULT_HEIGHT / 2;
+            int y0 = comp.getY() + comp.getHeight() - (80 + constant);
+            int height = 80;
             int width = comp.getWidth() - constant * 2;
 
-            Element layerElt = inclusionLayer.addElement(doc, svgNS, x0, y0, 
height, width, "#E5E5C0");
+            Element layerElt = inclusionLayer.addElement(doc, svgNS, x0, y0, 
height, width);
 
-            Element text = Text.addTextElement(doc, svgNS, x0 + constant, y0 + 
constant * 2, "Included Composites");
+            Element text = Text.addTextElement(doc, svgNS, x0 + constant, y0 + 
constant * 2, "Included Composites: ");
 
             svgRoot.appendChild(layerElt);
             svgRoot.appendChild(text);
@@ -255,8 +255,8 @@ public class DiagramGenerator {
      */
     private String getColor() {
 
-        previousWireColor = previousWireColor % color.values().length;
-        return color.values()[previousWireColor++].toString();
+        previousWireColor = previousWireColor % Color.values().length;
+        return Color.values()[previousWireColor++].toString();
     }
 
     /**
@@ -264,8 +264,8 @@ public class DiagramGenerator {
      */
     private int getChangingFactor() {
 
-        lastUsedChangingFactor = lastUsedChangingFactor % 
changingFactor.values().length;
-        return changingFactor.values()[lastUsedChangingFactor++].getVal();
+        lastUsedChangingFactor = lastUsedChangingFactor % 
ChangingFactor.values().length;
+        return ChangingFactor.values()[lastUsedChangingFactor++].getVal();
 
     }
 
@@ -312,7 +312,7 @@ public class DiagramGenerator {
     }
 
     private void addComponentProperties(ComponentEntity ent) {
-        int propLen = ent.getPropLength();
+        int propLen = ent.getPropWidth();
         int x = ent.getX() + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY;
         int y = ent.getY() - propLen / 2;
 
@@ -559,7 +559,7 @@ public class DiagramGenerator {
     }
 
     private void addCompositeProperties() {
-        int propLen = comp.getPropLength();
+        int propLen = comp.getPropWidth();
 
         int x =
             comp.getX() + getStartingPoint(comp.getWidth(), propLen, 
Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY, comp

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
 Wed Sep 21 20:59:17 2011
@@ -20,6 +20,7 @@
 package org.apache.tuscany.sca.diagram.layout;
 
 import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.tuscany.sca.diagram.artifacts.Constant;
 
@@ -30,50 +31,36 @@ import org.apache.tuscany.sca.diagram.ar
  */
 public class ComponentEntity extends Entity {
 
-    // private String componentName;
-    // private int X, Y, level=-1, lane=-1, refHeight, serHeight, propLength;
-    // private final int height= Component.DEFAULT_HEIGHT, width= 
Component.DEFAULT_WIDTH;
-    // public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / 
(Service.MAXIMUM_HEIGHT+Service.SPACING);
-    // public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / 
(Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers
-    // public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / 
(Property.MAXIMUM_HEIGHT+Property.SPACING); 
-
-    private HashMap<String, String> referenceToServiceMap = new 
HashMap<String, String>();
-
-    //private HashSet<String> connectedEntities = new HashSet<String>();
+    private Map<String, String> referenceToServiceMap = new HashMap<String, 
String>();
 
     public ComponentEntity() {
-
         setStartPosition(200);
         setHeight(Constant.COMPONENT_DEFAULT_HEIGHT);
         setWidth(Constant.COMPONENT_DEFAULT_WIDTH);
 
-        setDefaultNoOfSers(Constant.COMPONENT_DEFAULT_HEIGHT / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE + 
Constant.SPACING_FOR_COMPONENT_OF_SERVICE));
-        setDefaultNoOfRefs(Constant.COMPONENT_DEFAULT_HEIGHT / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE + 
Constant.SPACING_FOR_COMPONENT_OF_REFERENCE));
-        setDefaultNoOfProps(Constant.COMPONENT_DEFAULT_WIDTH / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY + 
Constant.SPACING_FOR_COMPONENT_OF_PROPERTY));
+        
setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE);
+        setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE);
+        
setPropWidth(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY);
     }
 
-    public void referenceHeight() {
-        if (getDefaultNoOfRefs() < getNoOfRefs()) {
+    public void build() {
+        // Find the services height
+        int size1 = services.size();
+        int total1 = size1 * serHeight + (size1 + 1) * 
Constant.SPACING_FOR_COMPONENT_OF_SERVICE;
 
-            setRefHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfRefs()) - 
Constant.SPACING_FOR_COMPONENT_OF_REFERENCE);
-        } else
-            
setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE);
-    }
+        // Find the references height
+        int size2 = references.size();
+        int total2 = size2 * refHeight + (size2 + 1) * 
Constant.SPACING_FOR_COMPONENT_OF_REFERENCE;
 
-    public void serviceHeight() {
-        if (getDefaultNoOfSers() < getNoOfSers()) {
+        int total = Math.max(total1, total2);
+        height = Math.max(total, height);
 
-            setSerHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfSers()) - 
Constant.SPACING_FOR_COMPONENT_OF_SERVICE);
-        } else
-            
setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE);
-    }
+        // Find the properties width
+        int size3 = properties.size();
+        int total3 = size3 * propWidth + (size3 + 1) * 
Constant.SPACING_FOR_COMPONENT_OF_PROPERTY;
 
-    public void propertyLength() {
-        if (getDefaultNoOfProps() < getNoOfProps()) {
+        width = Math.max(width, total3);
 
-            setPropLength((Constant.COMPONENT_DEFAULT_WIDTH / getNoOfProps()) 
- Constant.SPACING_FOR_COMPONENT_OF_PROPERTY);
-        } else
-            
setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY);
     }
 
     /**
@@ -108,7 +95,7 @@ public class ComponentEntity extends Ent
         return referenceToServiceMap.get(ref);
     }
 
-    public HashMap<String, String> getReferenceToServiceMap() {
+    public Map<String, String> getReferenceToServiceMap() {
         return referenceToServiceMap;
     }
 

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
 Wed Sep 21 20:59:17 2011
@@ -39,8 +39,8 @@ public class CompositeEntity extends Ent
     // public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / 
(Property.MAXIMUM_HEIGHT+Property.SPACING); 
 
     private final String fileNameSuffix = "_diagram";
-    private int maxInternalLevel = 0;
-    private int maxInternalLane = 0;
+    private int maxInternalLevel = -1;
+    private int maxInternalLane = -1;
     private ComponentEntity[] componentList;
     private int[][] connections;
     private HashMap<String, String> promoteAService = new HashMap<String, 
String>();
@@ -50,7 +50,6 @@ public class CompositeEntity extends Ent
     //private HashSet<String> connectedEntities = new HashSet<String>();
 
     public CompositeEntity(String name) {
-
         setStartPosition(200);
         setLevel(0);
         setLane(0);
@@ -59,101 +58,57 @@ public class CompositeEntity extends Ent
         setY(getStartPosition() / 2);
 
         setName(name);
-        //componentList = comps;
-        //setConnections(conns);
-
-    }
-
-    public void referenceHeight() {
-        //System.err.println(getDefaultNoOfRefs() + " kkkkkkk "+getNoOfRefs());
-
-        if (getDefaultNoOfRefs() < getNoOfRefs()) {
 
-            setRefHeight((getHeight() / getNoOfRefs()) - 
Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE);
-        } else
-            
setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE);
+        
setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE);
+        setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE);
+        
setPropWidth(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY);
     }
 
-    public void serviceHeight() {
-        if (getDefaultNoOfSers() < getNoOfSers()) {
-            setSerHeight((getHeight() / getNoOfSers()) - 
Constant.SPACING_FOR_COMPOSITE_OF_SERVICE);
-        } else
-            
setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE);
-    }
-
-    public void propertyLength() {
-        if (getDefaultNoOfProps() < getNoOfProps()) {
-
-            setPropLength((getWidth() / getNoOfProps()) - 
Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY);
-        } else
-            
setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY);
-    }
-
-    // /**
-    //  * Put a value to referenceToServiceMap
-    //  * @param ref
-    //  * @param ser
-    //  * @return successfully added or not
-    //  */
-    // //assumption there can not be two services for the same reference
-    // public boolean addToRefToSerMap(String ref, String ser){
-    //         //ref = ref.toLowerCase();
-    //         //ser = ser.toLowerCase();
-    //         
-    //         if (referenceToServiceMap.containsKey(ref))
-    //                 return false;
-    //         
-    //         referenceToServiceMap.put(ref, ser);
-    //         return true;
-    // }
-    // 
-    // /**
-    //  * Retrieve a service name for a given reference
-    //  * @param ref
-    //  * @return service name
-    //  */
-    // public String getSerOfRef(String ref){
-    //         //ref = ref.toLowerCase();
-    //         
-    //         if (!referenceToServiceMap.containsKey(ref))
-    //                 return null;
-    //         
-    //         return referenceToServiceMap.get(ref);
-    // }
-    // 
-    // public HashMap<String, String> getReferenceToServiceMap() {
-    //         return referenceToServiceMap;
-    // }
-    // 
-    // public void setReferenceToServiceMap(
-    //                 HashMap<String, String> referenceToServiceMap) {
-    //         this.referenceToServiceMap = referenceToServiceMap;
-    // }
+    public void build() {
+        int h = 0;
+        int w = 0;
 
-    public void calcHeight(int initPoint) {
-        setHeight((Constant.COMPONENT_DEFAULT_HEIGHT * getSpaceFactor()) * 
(maxInternalLevel + 1) + initPoint);
-    }
+        int lastHeight = 0;
+        // int lastWidth = 0;
+        for (ComponentEntity ent : componentList) {
 
-    public void calcWidth(int initPoint) {
-        //System.err.println("maxInternalLane "+maxInternalLane);
-        setWidth((Constant.COMPONENT_DEFAULT_WIDTH * getSpaceFactor()) * 
(maxInternalLane + 1) + initPoint);
-    }
+            if (ent.getLevel() > maxInternalLevel) {
+                maxInternalLevel = ent.getLevel();
+                lastHeight = ent.getHeight();
+                h += ent.getHeight() * getSpaceFactor();
+            }
+            if (ent.getLane() > maxInternalLane) {
+                maxInternalLane = ent.getLane();
+                // lastWidth = ent.getWidth();
+                w += ent.getWidth() * getSpaceFactor();
+            }
+        }
 
-    private int max(int a, int b) {
-        if (a >= b)
-            return a;
-        return b;
-    }
+        // For last level, no spacing is needed
+        h -= lastHeight * (getSpaceFactor() - 1);
+        // w -= lastWidth * (getSpaceFactor() - 1);
+
+        // Find the services height
+        int size1 = services.size();
+        int total1 = size1 * serHeight + (size1 + 1) * 
Constant.SPACING_FOR_COMPOSITE_OF_SERVICE;
+
+        // Find the references height
+        int size2 = references.size();
+        int total2 = size2 * refHeight + (size2 + 1) * 
Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE;
 
-    public void setMaxInternalProperties() {
+        int total = Math.max(total1, total2);
 
-        for (ComponentEntity ent : componentList) {
+        if (!includedComposites.isEmpty()) {
+            height = Math.max(total, h) + 80 + getY();
+        } else {
+            height = Math.max(total, h) + getY();
+        }
 
-            maxInternalLevel = max(maxInternalLevel, ent.getLevel());
-            maxInternalLane = max(maxInternalLane, ent.getLane());
+        // Find the properties width
+        int size3 = properties.size();
+        int total3 = size3 * propWidth + (size3 + 1) * 
Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY;
 
-        }
-        //System.out.println("++++++ "+maxInternalLevel+" +++++ 
"+maxInternalLane);
+        width = Math.max(w, total3) + getX();
     }
 
     public int getMaxInternalLevel() {
@@ -228,24 +183,6 @@ public class CompositeEntity extends Ent
         return connections;
     }
 
-    public void setAttributes() {
-
-        setMaxInternalProperties();
-
-        //System.out.println("++++++ "+this.maxInternalLevel);
-
-        calcHeight(getY());
-        calcWidth(getX());
-
-        setDefaultNoOfSers(getHeight() / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE + 
Constant.SPACING_FOR_COMPOSITE_OF_SERVICE));
-        setDefaultNoOfRefs(getHeight() / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE + 
Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE));
-        setDefaultNoOfProps(getWidth() / 
(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY + 
Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY));
-
-        referenceHeight();
-        serviceHeight();
-        propertyLength();
-    }
-
     public ArrayList<String> getIncludedComposites() {
         return includedComposites;
     }

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
 Wed Sep 21 20:59:17 2011
@@ -22,41 +22,32 @@ import java.util.ArrayList;
 import java.util.HashSet;
 
 public abstract class Entity {
+    protected int id = -1; //a unique integer id (0..n)
+    protected String name; // a unique name
+    protected int spaceFactor = 2; //which determines the free space 
surrounded by this
+    protected int x; // x coordinate
+    protected int y; // y coordinate
+    protected int level = -1; // corresponding row which this entity is placed
+    protected int lane = -1; // corresponding column which this entity is 
placed
+    protected boolean isPossitionSet = false;
+    protected int height; // height of the entity
+    protected int width; // width of the entity
+    protected int refHeight; // height of a reference element
+    protected int serHeight; // height of a service element
+    protected int propWidth; // length of a property element
+    
+    protected int startPosition = 0;
+    protected Entity parent = null;
 
-    private int id = -1; //a unique integer id (0..n)
-    private String name; // a unique name
-    private int spaceFactor = 2; //which determines the free space surrounded 
by this
-    private int x; // x coordinate
-    private int y; // y coordinate
-    private int level = -1; // corresponding row which this entity is placed
-    private int lane = -1; // corresponding column which this entity is placed
-    private boolean isPossitionSet = false;
-    private int height; // height of the entity
-    private int width; // width of the entity
-    private int refHeight; // height of a reference element
-    private int serHeight; // height of a service element
-    private int propLength; // length of a property element
-    private int defaultNoOfSers; // default # of service elements
-    private int defaultNoOfRefs; // default # of reference elements
-    private int defaultNoOfProps; // default # of property elements
-    private int startPosition = 0;
-    private Entity parent = null;
-
-    private ArrayList<String> references = new ArrayList<String>();
-
-    private ArrayList<String> services = new ArrayList<String>();
-
-    private ArrayList<String> properties = new ArrayList<String>();
+    protected ArrayList<String> references = new ArrayList<String>();
 
-    private HashSet<String> adjacentEntities = new HashSet<String>();
-    
-    private String implementation;
+    protected ArrayList<String> services = new ArrayList<String>();
 
-    public abstract void referenceHeight();
+    protected ArrayList<String> properties = new ArrayList<String>();
 
-    public abstract void serviceHeight();
+    protected HashSet<String> adjacentEntities = new HashSet<String>();
 
-    public abstract void propertyLength();
+    protected String implementation;
 
     public String getName() {
         return name;
@@ -71,7 +62,7 @@ public abstract class Entity {
     }
 
     public void setX(int init) {
-        this.x = init + width * spaceFactor * lane;
+        this.x = init + getWidth() * spaceFactor * lane;
     }
 
     public int getY() {
@@ -79,7 +70,7 @@ public abstract class Entity {
     }
 
     public void setY(int init) {
-        this.y = init + height * spaceFactor * level;
+        this.y = init + getHeight() * spaceFactor * level;
     }
 
     public int getLevel() {
@@ -130,36 +121,12 @@ public abstract class Entity {
         this.serHeight = serHeight;
     }
 
-    public int getPropLength() {
-        return propLength;
-    }
-
-    public void setPropLength(int propLength) {
-        this.propLength = propLength;
-    }
-
-    public int getDefaultNoOfSers() {
-        return defaultNoOfSers;
-    }
-
-    public void setDefaultNoOfSers(int defaultNoOfSers) {
-        this.defaultNoOfSers = defaultNoOfSers;
-    }
-
-    public int getDefaultNoOfRefs() {
-        return defaultNoOfRefs;
-    }
-
-    public void setDefaultNoOfRefs(int defaultNoOfRefs) {
-        this.defaultNoOfRefs = defaultNoOfRefs;
+    public int getPropWidth() {
+        return propWidth;
     }
 
-    public int getDefaultNoOfProps() {
-        return defaultNoOfProps;
-    }
-
-    public void setDefaultNoOfProps(int defaultNoOfProps) {
-        this.defaultNoOfProps = defaultNoOfProps;
+    public void setPropWidth(int propLength) {
+        this.propWidth = propLength;
     }
 
     public int getNoOfRefs() {
@@ -275,7 +242,7 @@ public abstract class Entity {
     public Entity getParent() {
         return parent;
     }
-    
+
     public String getImplementation() {
         return implementation;
     }
@@ -291,5 +258,8 @@ public abstract class Entity {
         return builder.toString();
     }
 
-
+    /**
+     * Adjust the items and coordinates
+     */
+    public abstract void build();
 }

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
 Wed Sep 21 20:59:17 2011
@@ -77,7 +77,7 @@ public class EntityBuilder {
 
         addInclusions(docEle);
 
-        composite.setAttributes();
+        composite.build();
 
         return composite;
     }
@@ -345,9 +345,7 @@ public class EntityBuilder {
                 setReferences(nVal, elts[i]);
                 setProperties(nVal, elts[i]);
 
-                elts[i].referenceHeight();
-                elts[i].serviceHeight();
-                elts[i].propertyLength();
+                elts[i].build();
             }
         }
 

Modified: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java?rev=1173855&r1=1173854&r2=1173855&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java
 Wed Sep 21 20:59:17 2011
@@ -88,7 +88,7 @@ public class TuscanyCompositeEntityBuild
 
         addInclusions();
 
-        composite.setAttributes();
+        composite.build();
 
         return composite;
     }
@@ -231,9 +231,7 @@ public class TuscanyCompositeEntityBuild
             setReferences(aComp.getReferences(), elts[i]);
             setProperties(aComp.getProperties(), elts[i]);
 
-            elts[i].referenceHeight();
-            elts[i].serviceHeight();
-            elts[i].propertyLength();
+            elts[i].build();
         }
 
         return elts;

Added: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml?rev=1173855&view=auto
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
 (added)
+++ 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
 Wed Sep 21 20:59:17 2011
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+           targetNamespace="http://sample";
+           xmlns:sample="http://sample";
+           name="Calculator2">
+
+    <component name="CalculatorServiceComponent">
+        <implementation.java class="calculator.CalculatorServiceImpl" />
+        <reference name="addService" target="AddServiceComponent" />
+        <reference name="subtractService" target="SubtractServiceComponent" />
+        <reference name="multiplyService" target="MultiplyServiceComponent" />
+        <reference name="divideService" target="DivideServiceComponent" />
+        
+        <reference name="addService2" target="AddServiceComponent2" />
+        <reference name="subtractService2" target="SubtractServiceComponent2" 
/>
+        <reference name="multiplyService2" target="MultiplyServiceComponent2" 
/>
+        <reference name="divideService2" target="DivideServiceComponent2" />
+    </component>
+
+    <component name="AddServiceComponent">
+        <implementation.java class="calculator.AddServiceImpl" />
+    </component>
+
+    <component name="SubtractServiceComponent">
+        <implementation.java class="calculator.SubtractServiceImpl" />
+    </component>
+
+    <component name="MultiplyServiceComponent">
+        <implementation.java class="calculator.MultiplyServiceImpl" />
+    </component>
+
+    <component name="DivideServiceComponent">
+        <implementation.java class="calculator.DivideServiceImpl" />
+    </component>
+
+    <component name="AddServiceComponent2">
+        <implementation.java class="calculator.AddServiceImpl" />
+    </component>
+
+    <component name="SubtractServiceComponent2">
+        <implementation.java class="calculator.SubtractServiceImpl" />
+    </component>
+
+    <component name="MultiplyServiceComponent2">
+        <implementation.java class="calculator.MultiplyServiceImpl" />
+    </component>
+
+    <component name="DivideServiceComponent2">
+        <implementation.java class="calculator.DivideServiceImpl" />
+    </component>
+
+</composite>
\ No newline at end of file

Propchange: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to