diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-04-12 09:14:28 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2012-04-12 09:14:28 +0000 |
commit | bad1f71da1978610806427e2e2a2f96a2fb5b88e (patch) | |
tree | 334e5c38ba5cc33fd853e37c640728ec020862fb /sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts | |
parent | 57c2c65b9d869afc1be14926da2ece51ab52231b (diff) |
Tag 2.0 RC1
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1325166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts')
15 files changed, 1100 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java new file mode 100644 index 0000000000..4751cff023 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java @@ -0,0 +1,156 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public abstract class Artifact { + + private String name; + private String containerName; + private int height; + private int width; + private int xCoordinate; + private int yCoordinate; + private Document doc; + private String svgNs; + private static final String ROUND_CORNER = "20"; + + /** + * Abstract method + * @param document DOM document + * @param svgNs namespace URI + * @param x x-coordinate + * @param y y-coordinate + * @param height height of the shape + * @param width width of the shape + * @return DOM Element + */ + public abstract Element addElement(Document document, String svgNs, int x, int y, int height, int width); + + // public abstract Element addElement(Document document, String svgNs, + // int x, int y); + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getxCoordinate() { + return xCoordinate; + } + + public void setxCoordinate(int xCoordinate) { + this.xCoordinate = xCoordinate; + } + + public int getyCoordinate() { + return yCoordinate; + } + + public void setyCoordinate(int yCoordinate) { + this.yCoordinate = yCoordinate; + } + + public Document getDoc() { + return doc; + } + + public void setDoc(Document doc) { + this.doc = doc; + } + + public String getSvgNs() { + return svgNs; + } + + public void setSvgNs(String svgNs) { + this.svgNs = svgNs; + } + + public static String getRoundCorner() { + return ROUND_CORNER; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setContainerName(String containerName) { + this.containerName = containerName; + } + + public String getContainerName() { + return containerName; + } + + /** + * Parse the component/service|reference/binding names + * @param compoundName + * @return An array of names + */ + public static String[] parseNames(String compoundName) { + String[] names = new String[] {"", "", ""}; + if (compoundName != null) { + String[] parts = compoundName.split("/"); + for (int i = 0; i < parts.length; i++) { + names[i] = parts[i]; + } + } + return names; + } + + public static boolean matches(String compoundName, String... parts) { + String names[] = parseNames(compoundName); + if (parts.length > names.length) { + return false; + } + for (int i = 0; i < parts.length; i++) { + if (parts[i].length() > 0 && names[i].length() > 0 && !names[i].equals(parts[i])) { + return false; + } + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Artifact [containerName=").append(containerName).append(", name=").append(name).append("]"); + return builder.toString(); + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java new file mode 100755 index 0000000000..6a9480d4ea --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ComponentArtifact extends Artifact { + + /** + * Create an element with specified height and width + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + 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", 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"); + rectangle.setAttributeNS(null, "class", "component"); + return rectangle; + } + + /** + * Create an element with default height and width + */ + public Element addElement(Document document, String svgNs, int x, int y) { + + return addElement(document, svgNs, x, y, Constant.COMPONENT_DEFAULT_HEIGHT, Constant.COMPONENT_DEFAULT_WIDTH); + + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java new file mode 100755 index 0000000000..4f67dfbb3b --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Structure of a "Composite" element in SCA, as a SVG element + * + */ +public class CompositeArtifact extends Artifact { + + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + 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", 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; + } + + // //OBSOLETE + // public Element addElement(Document document, String svgNs, int x, int y) { + // return null; + // } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java new file mode 100755 index 0000000000..c27d82dd6d --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java @@ -0,0 +1,46 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.diagram.artifacts; + +public final class Constant { + + public static final int COMPONENT_DEFAULT_WIDTH = 200; + public static final int COMPONENT_DEFAULT_HEIGHT = 130; + 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 = 40; + public static final int SPACING_FOR_COMPONENT_OF_PROPERTY = 20; + 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 = 60; + public static final int SPACING_FOR_COMPONENT_OF_REFERENCE = 10; + 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 = 60; + public static final int SPACING_FOR_COMPONENT_OF_SERVICE = 10; + public static final int SPACING_FOR_COMPOSITE_OF_SERVICE = 30; + + public static final int SPACING_FOR_TEXT = 2; + + public static final int MAX_LEVELS = 8; + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java new file mode 100755 index 0000000000..229b14e083 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java @@ -0,0 +1,83 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class DashedWire extends WireArtifact { + + @Override + public Element addElement(Document document, String svgNs, Object a, Object b, int changingFactor, String color) { + + Element polyline = document.createElementNS(svgNs, "polyline"); + int x1 = 0, x2 = 0, y1 = 0, y2 = 0; + + if (a instanceof ServiceArtifact && b instanceof ServiceArtifact) { + + ServiceArtifact aService1 = (ServiceArtifact)a; + ServiceArtifact aService2 = (ServiceArtifact)b; + + x1 = aService1.getxCoordinate() + aService1.getHeight() * 3 / 2; + y1 = aService1.getyCoordinate() + aService1.getHeight() / 2; + + x2 = aService2.getxCoordinate() + aService2.getHeight() / 2; + y2 = aService2.getyCoordinate() + aService2.getHeight() / 2; + + } + + else if (a instanceof ReferenceArtifact && b instanceof ReferenceArtifact) { + + ReferenceArtifact aReference1 = (ReferenceArtifact)a; + ReferenceArtifact aReference2 = (ReferenceArtifact)b; + + x1 = aReference1.getxCoordinate() + aReference1.getHeight() * 3 / 2; + y1 = aReference1.getyCoordinate() + aReference1.getHeight() / 2; + + x2 = aReference2.getxCoordinate() + aReference2.getHeight() / 2; + y2 = aReference2.getyCoordinate() + aReference2.getHeight() / 2; + + } + + polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color); + +// polyline.setAttributeNS(null, "stroke-dasharray", "3 3"); + polyline.setAttributeNS(null, "class", "wire dashedWire"); + + + return polyline; + } + + /** + * <script type="text/ecmascript"><![CDATA[ + <SCRIPT LANGUAGE="JavaScript"> + + var test = document.open("store_diagram.svg"); + + </SCRIPT> + ]]></script> + + <!--rect x="0" y="0" alignment-baseline="central" fill="#E5E5D0" width="1400" rx="20" ry="20" height="560" stroke="#919191"/><rect x="200" y="100" alignment-baseline="central" fill="#E5E5E5" width="1000" rx="20" ry="20" height="360" stroke="#919191"/><text x="700" font-size="20" dominant-baseline="mathematical" y="120" text-anchor="middle"> + + <a xlink:href="store_diagram.svg" xlink:show="new">MyValueComposite2</a></text--> + + */ + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java new file mode 100644 index 0000000000..21bcadf872 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java @@ -0,0 +1,62 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ImplementationArtifact extends Artifact { + + /** + * Create an element with specified height and width + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + rectangle.setAttributeNS(null, "x", x + ""); + rectangle.setAttributeNS(null, "y", 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", "purple"); + rectangle.setAttributeNS(null, "stroke", "black"); + rectangle.setAttributeNS(null, "stroke-width", "1"); + rectangle.setAttributeNS(null, "fill-opacity", "0.1"); + + rectangle.setAttributeNS(null, "class", "implementation"); + return rectangle; + } + + /** + * Create an element with default height and width + */ + public Element addElement(Document document, String svgNs, int x, int y) { + + return addElement(document, svgNs, x, y, Constant.COMPONENT_DEFAULT_HEIGHT/2, Constant.COMPONENT_DEFAULT_WIDTH/2); + + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java new file mode 100755 index 0000000000..858226f801 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Structure of a "Outermost layer" : not a SCA artifact + * + */ +public class Layer extends Artifact { + + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + rectangle.setAttributeNS(null, "x", x + ""); + rectangle.setAttributeNS(null, "y", 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", "#E5E5D0"); +// rectangle.setAttributeNS(null, "stroke", "#919191"); +// rectangle.setAttributeNS(null, "alignment-baseline", "middle"); + rectangle.setAttributeNS(null, "class", "layer"); + + return rectangle; + } + + public Element addElement(Document document, String svgNs, int x, int y, int height, int width, String fillColor) { + + Element rect = addElement(document, svgNs, x, y, height, width); + rect.setAttributeNS(null, "fill", fillColor); + + return rect; + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java new file mode 100755 index 0000000000..3e1e368681 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * An "a" element to link two SVG diagrams: not a SCA artifact + * + */ +public class Link { + + public Element addElement(Document document, String svgNs, String fileName, String compName) { + + Element link = document.createElementNS(svgNs, "a"); + link.setAttributeNS(null, "xlink:href", fileName); + link.setAttributeNS(null, "xlink:show", "new"); + link.setTextContent(" [" + compName + "] "); + + return link; + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java new file mode 100755 index 0000000000..c3abe8d2e2 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class NormalWire extends WireArtifact { + + @Override + public Element addElement(Document document, String svgNs, Object a, Object b, int changingFactor, String color) { + + ReferenceArtifact aReference = (ReferenceArtifact)a; + ServiceArtifact aService = (ServiceArtifact)b; + + Element polyline = document.createElementNS(svgNs, "polyline"); + int x1 = aReference.getxCoordinate() + aReference.getHeight() * 3 / 2; + int y1 = aReference.getyCoordinate() + aReference.getHeight() / 2; + + int x2 = aService.getxCoordinate() + aService.getHeight() / 2; + int y2 = aService.getyCoordinate() + aService.getHeight() / 2; + + polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color); + polyline.setAttributeNS(null, "class", "wire normalWire"); + + return polyline; + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java new file mode 100755 index 0000000000..8622c7ad04 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class PropertyArtifact extends Artifact { + + /** + * Property is a square. + * ___ + * | | + * |___| + * + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + rectangle.setAttributeNS(null, "x", x + ""); + rectangle.setAttributeNS(null, "y", y + ""); + rectangle.setAttributeNS(null, "width", height + ""); + rectangle.setAttributeNS(null, "height", height + ""); + rectangle.setAttributeNS(null, "fill", "#EEEE00"); + rectangle.setAttributeNS(null, "stroke", "#EEC900"); + //rectangle.setAttributeNS(null, "fill-opacity", "0.75"); + + rectangle.setAttributeNS(null, "class", "property"); + + return rectangle; + } + + public Element addElement(Document document, String svgNs, int x, int y, int height) { + + return addElement(document, svgNs, x, y, height, height); + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java new file mode 100755 index 0000000000..dc561f8e49 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java @@ -0,0 +1,88 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ReferenceArtifact extends Artifact { + + /** + * In a Reference the (x,y) coordinates refers to the top corner edge of the polygon + * (x,y)______ + * \ \ + * \ \ + * / / + * /____ / + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + int halfOfHeight = height / 2; + + Element polygon = document.createElementNS(svgNs, "polygon"); + polygon.setAttributeNS(null, "points", "" + x + + "," + + y + + " " + + "" + + (x + 2 * halfOfHeight) + + "," + + (y) + + " " + + "" + + (x + 3 * halfOfHeight) + + "," + + (y + halfOfHeight) + + " " + + "" + + (x + 2 * halfOfHeight) + + "," + + (y + 2 * halfOfHeight) + + " " + + "" + + (x) + + "," + + (y + 2 * halfOfHeight) + + " " + + "" + + (x + halfOfHeight) + + "," + + (y + halfOfHeight) + + " "); + + polygon.setAttributeNS(null, "fill", "#BF3EFF"); + polygon.setAttributeNS(null, "stroke", "#68228B"); + polygon.setAttributeNS(null, "class", "reference"); + + + return polygon; + } + + public Element addElement(Document document, String svgNs, int x, int y, int height) { + + return this.addElement(document, svgNs, x, y, height, height * 3 / 2); + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java new file mode 100755 index 0000000000..4f305b4ba5 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java @@ -0,0 +1,95 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ServiceArtifact extends Artifact { + + /** + * In a Service the (x,y) coordinates refers to the top corner edge of the polygon + * (x,y)______ + * \ \ + * \ \ + * / / + * /____ / + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + int halfOfHeight = height / 2; + + Element polygon = document.createElementNS(svgNs, "polygon"); + polygon.setAttributeNS(null, "points", "" + x + + "," + + y + + " " + + "" + + (x + 2 * halfOfHeight) + + "," + + (y) + + " " + + "" + + (x + 3 * halfOfHeight) + + "," + + (y + halfOfHeight) + + " " + + "" + + (x + 2 * halfOfHeight) + + "," + + (y + 2 * halfOfHeight) + + " " + + "" + + (x) + + "," + + (y + 2 * halfOfHeight) + + " " + + "" + + (x + halfOfHeight) + + "," + + (y + halfOfHeight) + + " "); + + polygon.setAttributeNS(null, "fill", "#00CD66"); + polygon.setAttributeNS(null, "stroke", "#008B45"); + polygon.setAttributeNS(null, "class", "service"); + return polygon; + } + + /** + * Width is 3/2 times of the height + * @param document + * @param svgNs + * @param x + * @param y + * @param height + * @return + */ + public Element addElement(Document document, String svgNs, int x, int y, int height) { + + return this.addElement(document, svgNs, x, y, height, height * 3 / 2); + } + +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java new file mode 100644 index 0000000000..14e4e7e909 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java @@ -0,0 +1,118 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringWriter; + +import org.w3c.dom.CDATASection; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * CSS style element + */ +public class Style { + private static final String DEFAULT_CSS = "rect.composite {" + " fill: #E5E5E5;" + + " stroke: #919191;" + + " alignment-baseline: middle;" + + " }\n" + + " rect.component {" + + " fill: #3D59AB;" + + " stroke: #104E8B;" + + " fill-opacity: 0.75;" + + " }\n" + + " rect.property {" + + " fill: #EEEE00;" + + " stroke: #EEC900;" + + " }\n" + + " polygon.reference {" + + " fill: #BF3EFF;" + + " stroke: #68228B;" + + " }\n" + + " polygon.service {" + + " fill: #00CD66;" + + " stroke: #008B45;" + + " }\n" + + " polyline.wire {" + + " stroke-width: 2;" + + " fill: none;" + + " }\n" + + " polyline.normalWire {" + + " }\n" + + " polyline.dashedWire {" + + " stroke-dasharray: 3,3;" + + " }\n" + + " rect.layer {" + + " fill: #E5E5D0;" + + " stroke: #919191;" + + " alignment-baseline: middle;" + + " }\n"; + + private static volatile String css; + + public Element addElement(Document document, String svgNs, String styleSheet) { + + Element style = document.createElementNS(svgNs, "style"); + style.setAttributeNS(null, "type", "text/css"); + + if (styleSheet == null) { + try { + if (css == null) { + css = readCSS(); + } + } catch (IOException e) { + // Ignore + css = DEFAULT_CSS; + } + styleSheet = css; + } + + CDATASection cdata = document.createCDATASection(styleSheet); + style.appendChild(cdata); + + return style; + } + + private static String readCSS() throws IOException { + InputStream is = Style.class.getResourceAsStream("composite-diagram.css"); + InputStreamReader reader = new InputStreamReader(is, "UTF-8"); + + StringWriter sw = new StringWriter(); + char[] buf = new char[4096]; + while (true) { + int size = reader.read(buf); + if (size < 0) { + break; + } else { + sw.write(buf, 0, size); + } + } + reader.close(); + String template = sw.toString(); + // return template.replaceFirst("/\\*(?:.|[\\n\\r])*?\\*/", ""); // Unfortunately it causes StackOverFlow in Apache Jenkins build + int i1 = template.indexOf("/*"); + int i2 = template.indexOf("*/", i1); + String result = template.substring(0, i1) + template.substring(i2 + 2, template.length()); + return result; + } +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java new file mode 100644 index 0000000000..580209d289 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java @@ -0,0 +1,38 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Text { + + public static Element addTextElement(Document document, String svgNs, int x, int y, String content) { + Element text = document.createElementNS(svgNs, "text"); + text.setAttributeNS(null, "x", x + ""); + text.setAttributeNS(null, "y", y + ""); + //text.setAttributeNS(null, "text-anchor", "middle"); + text.setAttributeNS(null, "dominant-baseline", "mathematical"); + text.setAttributeNS(null, "font-size", "15"); + text.setTextContent(content); + text.setAttributeNS(null, "class", "name"); + return text; + } +} diff --git a/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java new file mode 100755 index 0000000000..80466621b6 --- /dev/null +++ b/sca-java-2.x/tags/2.0-RC1/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java @@ -0,0 +1,88 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public abstract class WireArtifact { + + public abstract Element addElement(Document document, + String svgNs, + Object a, + Object b, + int changingFactor, + String color); + + public Element setWireAttributes(int x1, int y1, int x2, int y2, Element polyline, int changingFactor, String color) { + + if (y1 == y2 && x2 > x1) { + polyline.setAttributeNS(null, "points", x1 + "," + y1 + " " + x2 + "," + y2); + } else if (y1 == y2 && x1 > x2) { + polyline.setAttributeNS(null, "points", x1 + "," + + y1 + + " " + + (x1 + changingFactor) + + "," + + y1 + + " " + + (x1 + changingFactor) + + "," + + (y1 - (changingFactor * 2)) + + " " + + (x2 - changingFactor) + + "," + + (y1 - (changingFactor * 2)) + + " " + + (x2 - changingFactor) + + "," + + (y1) + + " " + + (x2) + + "," + + (y1)); + + } else { + polyline.setAttributeNS(null, "points", x1 + "," + + y1 + + " " + + (x1 + changingFactor) + + "," + + y1 + + " " + + (x1 + changingFactor) + + "," + + y2 + + " " + + x2 + + "," + + y2); + } + + polyline.setAttributeNS(null, "stroke", color); + polyline.setAttributeNS(null, "stroke-width", "2"); + polyline.setAttributeNS(null, "fill", "none"); + + polyline.setAttributeNS(null, "class", "wire"); + + return polyline; + } + +} |