From c273cc2dbd9ad3ccf07d4018e4262617d4ba1793 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 21 Sep 2011 20:59:17 +0000 Subject: Calculate the height/width for components/composites based on its content git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1173855 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/diagram/artifacts/ComponentArtifact.java | 8 +- .../sca/diagram/artifacts/CompositeArtifact.java | 14 +- .../tuscany/sca/diagram/artifacts/Constant.java | 14 +- .../tuscany/sca/diagram/artifacts/Layer.java | 6 +- .../apache/tuscany/sca/diagram/artifacts/Link.java | 2 +- .../tuscany/sca/diagram/artifacts/Style.java | 5 +- .../sca/diagram/generator/DiagramGenerator.java | 28 ++-- .../sca/diagram/layout/ComponentEntity.java | 51 +++----- .../sca/diagram/layout/CompositeEntity.java | 145 ++++++--------------- .../apache/tuscany/sca/diagram/layout/Entity.java | 96 +++++--------- .../tuscany/sca/diagram/layout/EntityBuilder.java | 6 +- .../layout/TuscanyCompositeEntityBuilder.java | 6 +- 12 files changed, 136 insertions(+), 245 deletions(-) (limited to 'sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca') diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java index 0441005097..6a9480d4ea 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java @@ -35,12 +35,12 @@ public class ComponentArtifact extends Artifact { 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"); diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java index 6ff6ce567c..4f67dfbb3b 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java @@ -36,15 +36,15 @@ public class CompositeArtifact extends Artifact { 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; diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java index ceeb5f5f5e..a5e3e91fbc 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java @@ -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; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java index d560fcd68c..858226f801 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java @@ -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; diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java index a0cbee344c..3e1e368681 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java @@ -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; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java index 3467e5d9d0..08554dcc61 100644 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java @@ -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])*?\\*/", ""); } } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java index 9b72d7d25a..9b20e97f83 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java @@ -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 diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java index 626394fd44..50da28ec67 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java @@ -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.artifacts.Constant; */ 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 referenceToServiceMap = new HashMap(); - - //private HashSet connectedEntities = new HashSet(); + private Map referenceToServiceMap = new HashMap(); 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 Entity { return referenceToServiceMap.get(ref); } - public HashMap getReferenceToServiceMap() { + public Map getReferenceToServiceMap() { return referenceToServiceMap; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java index 258dcbcaa3..02e98c56d5 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java @@ -39,8 +39,8 @@ public class CompositeEntity extends Entity { // 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 promoteAService = new HashMap(); @@ -50,7 +50,6 @@ public class CompositeEntity extends Entity { //private HashSet connectedEntities = new HashSet(); public CompositeEntity(String name) { - setStartPosition(200); setLevel(0); setLane(0); @@ -59,101 +58,57 @@ public class CompositeEntity extends Entity { 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); - } - - 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); + 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 propertyLength() { - if (getDefaultNoOfProps() < getNoOfProps()) { + public void build() { + int h = 0; + int w = 0; - setPropLength((getWidth() / getNoOfProps()) - Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY); - } else - setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY); - } + int lastHeight = 0; + // int lastWidth = 0; + for (ComponentEntity ent : componentList) { - // /** - // * 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 getReferenceToServiceMap() { - // return referenceToServiceMap; - // } - // - // public void setReferenceToServiceMap( - // HashMap referenceToServiceMap) { - // this.referenceToServiceMap = referenceToServiceMap; - // } + 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(); + } + } - public void calcHeight(int initPoint) { - setHeight((Constant.COMPONENT_DEFAULT_HEIGHT * getSpaceFactor()) * (maxInternalLevel + 1) + initPoint); - } + // For last level, no spacing is needed + h -= lastHeight * (getSpaceFactor() - 1); + // w -= lastWidth * (getSpaceFactor() - 1); - public void calcWidth(int initPoint) { - //System.err.println("maxInternalLane "+maxInternalLane); - setWidth((Constant.COMPONENT_DEFAULT_WIDTH * getSpaceFactor()) * (maxInternalLane + 1) + initPoint); - } + // Find the services height + int size1 = services.size(); + int total1 = size1 * serHeight + (size1 + 1) * Constant.SPACING_FOR_COMPOSITE_OF_SERVICE; - private int max(int a, int b) { - if (a >= b) - return a; - return b; - } + // 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 Entity { 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 getIncludedComposites() { return includedComposites; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java index 469c59cf4f..54becf82f2 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java @@ -22,41 +22,32 @@ import java.util.ArrayList; import java.util.HashSet; public abstract class Entity { - - 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 references = new ArrayList(); - - private ArrayList services = new ArrayList(); - - private ArrayList properties = new ArrayList(); - - private HashSet adjacentEntities = new HashSet(); + 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 - private String implementation; + protected int startPosition = 0; + protected Entity parent = null; + + protected ArrayList references = new ArrayList(); + + protected ArrayList services = new ArrayList(); - public abstract void referenceHeight(); + protected ArrayList properties = new ArrayList(); - public abstract void serviceHeight(); + protected HashSet adjacentEntities = new HashSet(); - 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 getPropWidth() { + return propWidth; } - public int getDefaultNoOfRefs() { - return defaultNoOfRefs; - } - - public void setDefaultNoOfRefs(int defaultNoOfRefs) { - this.defaultNoOfRefs = defaultNoOfRefs; - } - - 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(); } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java index 64ac2db409..a936d83871 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java @@ -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(); } } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java index e133064ae7..dc9d3be55b 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java @@ -88,7 +88,7 @@ public class TuscanyCompositeEntityBuilder { addInclusions(); - composite.setAttributes(); + composite.build(); return composite; } @@ -231,9 +231,7 @@ public class TuscanyCompositeEntityBuilder { setReferences(aComp.getReferences(), elts[i]); setProperties(aComp.getProperties(), elts[i]); - elts[i].referenceHeight(); - elts[i].serviceHeight(); - elts[i].propertyLength(); + elts[i].build(); } return elts; -- cgit v1.2.3