diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-21 20:59:17 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-21 20:59:17 +0000 |
commit | c273cc2dbd9ad3ccf07d4018e4262617d4ba1793 (patch) | |
tree | bec71105682b970b8f0e58bff8b1fd748f9582ba | |
parent | 6fc9f8704b54553bbb31935e272405bee83f1e59 (diff) |
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
13 files changed, 206 insertions, 245 deletions
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<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 Entity { return referenceToServiceMap.get(ref); } - public HashMap<String, String> getReferenceToServiceMap() { + public Map<String, String> 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<String, String> promoteAService = new HashMap<String, String>(); @@ -50,7 +50,6 @@ public class CompositeEntity extends Entity { //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 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<String, String> getReferenceToServiceMap() { - // return referenceToServiceMap; - // } - // - // public void setReferenceToServiceMap( - // HashMap<String, String> 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<String> 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<String> references = new ArrayList<String>(); - - private ArrayList<String> services = new ArrayList<String>(); - - private ArrayList<String> properties = new ArrayList<String>(); - - private HashSet<String> adjacentEntities = new HashSet<String>(); + 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<String> references = new ArrayList<String>(); + + 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 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; diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml b/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml new file mode 100755 index 0000000000..ff2723dac7 --- /dev/null +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/test/resources/input/Calculator2.xml @@ -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 |