diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java')
-rwxr-xr-x | sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java | 145 |
1 files changed, 41 insertions, 104 deletions
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; } |