diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-13 06:03:58 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-13 06:03:58 +0000 |
commit | a8bf783d679577a3bfdf14e09dc9251c4ee258a5 (patch) | |
tree | a5751c88ec7fcf0de2fa3bfaad7579acf5040639 /collaboration/GSoC-2011-Nirmal | |
parent | e5e2ec296c123604eae67c0763d8ab3b91f692f1 (diff) |
TUSCANY-3496: Add Nirmal's prototype code for the composite diagram GSoC project to the collaboration area
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1102569 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal')
10 files changed, 715 insertions, 0 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml new file mode 100644 index 0000000000..f28981c4bb --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml @@ -0,0 +1,110 @@ +<?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. <groupId>org.apache.tuscany.sca</groupId> +--> +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-composite-diagram</artifactId> + <version>0.0.1</version> + <name>Apache Tuscany SCA Composite Diagram Generator Application</name> + + <dependencies> + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-anim</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-awt-util</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-css</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-dom</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-ext</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-parser</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-svg-dom</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-svggen</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-util</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.apache.xmlgraphics</groupId> + <artifactId>batik-xml</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>xml-apis</groupId> + <artifactId>xml-apis-ext</artifactId> + <version>1.3.04</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + + </dependencies> + + + <build> + <defaultGoal>install</defaultGoal> + <directory>${basedir}/target</directory> + <finalName>${artifactId}-${version}</finalName> + </build> + +</project> diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java new file mode 100644 index 0000000000..9ba591698d --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java @@ -0,0 +1,62 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public abstract class Artifact { + + 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" ; + + public abstract Element addElement(Document document, String svgNs, + int x, int y, int height, int width); + + 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; + } + + + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java new file mode 100644 index 0000000000..a41d5b1100 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java @@ -0,0 +1,67 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Component extends Artifact{ + +// private static final String WIDTH = "200" ; +// private static final String HEIGHT = "130" ; + + +// public Element addElement(Document document, +// String svgNs, int x, int y) { +// +// +// //Element g = document.createElementNS(svgNs, "g"); +// //g.setAttributeNS(null, "transform", "translate(100 100)"); +// // Create the rectangle. +// Element rectangle = document.createElementNS(svgNs, "rect"); +// rectangle.setAttributeNS(null, "x", x+""); +// rectangle.setAttributeNS(null, "y", y+""); +// rectangle.setAttributeNS(null, "rx", ROUND_CORNER); +// rectangle.setAttributeNS(null, "ry", ROUND_CORNER); +// rectangle.setAttributeNS(null, "width", WIDTH); +// rectangle.setAttributeNS(null, "height", HEIGHT); +// rectangle.setAttributeNS(null, "fill", "#3D59AB"); +// rectangle.setAttributeNS(null, "stroke", "#104E8B"); +// rectangle.setAttributeNS(null, "fill-opacity", "0.75"); +// +// +//// Element text = document.createElementNS(svgNs, "text"); +//// text.setAttributeNS(null, "text-anchor", "middle"); +//// text.setAttributeNS(null, "dominant-baseline", "mathematical"); +//// text.setAttributeNS(null, "font-size", "30"); +//// text.setTextContent("A Component"); +// +// //document.appendChild(rectangle); +// //g.appendChild(text); +// +// +// return rectangle; +// } + + + 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", "#3D59AB"); + rectangle.setAttributeNS(null, "stroke", "#104E8B"); + rectangle.setAttributeNS(null, "fill-opacity", "0.75"); + return rectangle; + } + + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java new file mode 100644 index 0000000000..b36b2f2290 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java @@ -0,0 +1,64 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Structure of a "Composite" element in SCA, as a SVG element + * @author nirmal + * + */ +public class Composite extends Artifact{ +// +// private Document document; +// private String svgNs; +// +// public Composite(Document doc, String uri){ +// document = doc; +// svgNs = uri; +// } +// + + +// public static Element addCompositeElement(Document document, String svgNs, +// int x, int y, int width, int height) { +// // Create the rectangle. +// Element rectangle = document.createElementNS(svgNs, "rect"); +// rectangle.setAttributeNS(null, "x", x+""); +// rectangle.setAttributeNS(null, "y", y+""); +// rectangle.setAttributeNS(null, "rx", ROUND_CORNER); +// rectangle.setAttributeNS(null, "ry", ROUND_CORNER); +// 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", "central"); +// +// return rectangle; +// } + + 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", "#E5E5E5"); + rectangle.setAttributeNS(null, "stroke", "#919191"); + rectangle.setAttributeNS(null, "alignment-baseline", "central"); + + return rectangle; + } + + + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java new file mode 100644 index 0000000000..dff95520e9 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java @@ -0,0 +1,50 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Property extends Artifact{ + +// private static final String WIDTH = "20" ; + +// public static Element addPropertyElement(Document document, +// String svgNs, int x, int y) { +// Element rectangle = document.createElementNS(svgNs, "rect"); +// rectangle.setAttributeNS(null, "x", x+""); +// rectangle.setAttributeNS(null, "y", y+""); +// rectangle.setAttributeNS(null, "width", WIDTH); +// rectangle.setAttributeNS(null, "height", WIDTH); +// rectangle.setAttributeNS(null, "fill", "#EEEE00"); +// rectangle.setAttributeNS(null, "stroke", "#EEC900"); +// //rectangle.setAttributeNS(null, "fill-opacity", "0.75"); +// +// return rectangle; +// } + + + public Element addElement(Document document, String svgNs, int x, int y, + int height, int width) { + return this.addElement(document, svgNs, x, y, height); + } + + public Element addElement(Document document, String svgNs, int x, int y, + int height) { + + this.setHeight(height); + this.setWidth(height); + 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"); + + return rectangle; + } + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java new file mode 100644 index 0000000000..912dc08944 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java @@ -0,0 +1,77 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Reference extends Artifact { + +//private static final int COMMON_LENGTH = 20 ; + +// public static Element addReferenceElement(Document document, String svgNs, int midX, int midY) { +// +// // Create the rectangle. +// Element polygon = document.createElementNS(svgNs, "polygon"); +// polygon.setAttributeNS(null, "points", +// ""+ (midX-COMMON_LENGTH) +","+midY+" " + +// ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " + +// ""+ (midX+COMMON_LENGTH) +","+(midY-COMMON_LENGTH)+" " + +// ""+ (midX+(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH*2)+" " + +// ""+ (midX-COMMON_LENGTH) +","+(midY-COMMON_LENGTH*2)+" " + +// ""+ (midX-(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH)+" " +// ); +// polygon.setAttributeNS(null, "fill", "#BF3EFF"); +// polygon.setAttributeNS(null, "stroke", "#68228B"); +// //rectangle.setAttributeNS(null, "alignment-baseline", "central"); +// +// return polygon; +// } +// + + + public Element addElement(Document document, String svgNs, int x, int y, + int height, int width) { + return this.addElement(document, svgNs, x, y, height); + } + + /** + * In a Reference the (x,y) coordinates refers to the outer edge of the polygon + * ______ + * \ \ + * \ \ ___ outer edge + * / / + * /____ / + * + * @param document + * @param svgNs + * @param x + * @param y + * @param height + * @return + */ + public Element addElement(Document document, String svgNs, int x, int y, + int height) { + + this.setHeight(height); + this.setWidth(height); + this.setxCoordinate(x); + this.setyCoordinate(y); + + int length = height/2; + + Element polygon = document.createElementNS(svgNs, "polygon"); + polygon.setAttributeNS(null, "points", + ""+ x +","+y+" " + + ""+ (x-length) +","+(y+length)+" " + + ""+ (x-length*3) +","+(y+length)+" " + + ""+ (x-length*2) +","+(y)+" " + + ""+ (x-length*3) +","+(y-length)+" " + + ""+ (x-length) +","+(y-length)+" " + ); + + polygon.setAttributeNS(null, "fill", "#BF3EFF"); + polygon.setAttributeNS(null, "stroke", "#68228B"); + + return polygon; + } + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java new file mode 100644 index 0000000000..d55d5dd9d6 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java @@ -0,0 +1,75 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Service extends Artifact{ + +// private static final int COMMON_LENGTH = 20 ; + +// public static Element addServiceElement(Document document, String svgNs, int midX, int midY) { +// // Create the rectangle. +// Element polygon = document.createElementNS(svgNs, "polygon"); +// polygon.setAttributeNS(null, "points", +// ""+ (midX-COMMON_LENGTH) +","+midY+" " + +// ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " + +// ""+ (midX+COMMON_LENGTH) +","+(midY-COMMON_LENGTH)+" " + +// ""+ (midX+(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH*2)+" " + +// ""+ (midX-COMMON_LENGTH) +","+(midY-COMMON_LENGTH*2)+" " + +// ""+ (midX-(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH)+" " +// ); +// polygon.setAttributeNS(null, "fill", "#00CD66"); +// polygon.setAttributeNS(null, "stroke", "#008B45"); +// +// return polygon; +// } + + + public Element addElement(Document document, String svgNs, int x, int y, + int height, int width) { + return this.addElement(document, svgNs, x, y, height); + } + + /** + * In a Service the (x,y) coordinates refers to the inner edge of the polygon + * ______ + * \ \ + * inner edge ____ \ \ + * / / + * /____ / + * + * @param document + * @param svgNs + * @param x + * @param y + * @param height + * @return + */ + public Element addElement(Document document, String svgNs, int x, int y, + int height) { + + this.setHeight(height); + this.setWidth(height); + this.setxCoordinate(x); + this.setyCoordinate(y); + + int length = height/2; + + Element polygon = document.createElementNS(svgNs, "polygon"); + polygon.setAttributeNS(null, "points", + ""+ x +","+y+" " + + ""+ (x-length) +","+(y-length)+" " + + ""+ (x+length) +","+(y-length)+" " + + ""+ (x+(length*2)) +","+y+" " + + ""+ (x+length) +","+(y+length)+" " + + ""+ (x-length) +","+(y+length)+" " + ); + + polygon.setAttributeNS(null, "fill", "#00CD66"); + polygon.setAttributeNS(null, "stroke", "#008B45"); + + return polygon; + } + + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java new file mode 100644 index 0000000000..72d3aea69c --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.impl.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", "20"); + text.setTextContent(content); + + return text; + } +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java new file mode 100644 index 0000000000..9a2a0a74b1 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java @@ -0,0 +1,48 @@ +package org.apache.tuscany.sca.impl.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class Wire { + +// <path d="M 100 100 L 300 100 L 200 300 z" +// fill="red" stroke="blue" stroke-width="3" /> + +// public static Element addWireElement(Document document, String svgNs, int x1, int y1, +// int x2, int y2) { +// // Create the rectangle. +// Element polyline = document.createElementNS(svgNs, "polyline"); +// //polyline.setAttributeNS(null,"class", "Connect"); +// polyline.setAttributeNS(null, "points", x1+","+y1+" "+x2+","+y2); +// polyline.setAttributeNS(null, "stroke", "black"); +// polyline.setAttributeNS(null, "stroke-width", "2"); +//// polygon.setAttributeNS(null, "points", +//// ""+ (midX-COMMON_LENGTH) +","+midY+" " + +//// ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " + +//// ""+ (midX+COMMON_LENGTH) +","+(midY-COMMON_LENGTH)+" " + +//// ""+ (midX+(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH*2)+" " + +//// ""+ (midX-COMMON_LENGTH) +","+(midY-COMMON_LENGTH*2)+" " + +//// ""+ (midX-(COMMON_LENGTH/2)) +","+(midY-COMMON_LENGTH)+" " +//// ); +// //polyline.setAttributeNS(null, "fill", "purple"); +// //rectangle.setAttributeNS(null, "alignment-baseline", "central"); +// +// return polyline; +// } + + public Element addElement(Document document, String svgNs, + Reference aReference, Service aService){ + + Element polyline = document.createElementNS(svgNs, "polyline"); + //polyline.setAttributeNS(null,"class", "Connect"); + polyline.setAttributeNS(null, "points", aReference.getxCoordinate()+","+ + aReference.getyCoordinate()+" "+aService.getxCoordinate()+","+ + aService.getyCoordinate()); + polyline.setAttributeNS(null, "stroke", "black"); + polyline.setAttributeNS(null, "stroke-width", "2"); + + return polyline; + } + + +} diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java new file mode 100644 index 0000000000..4246ad903c --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java @@ -0,0 +1,142 @@ +package org.apache.tuscany.sca.main; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.apache.batik.dom.svg.SVGDOMImplementation; +import org.apache.tuscany.sca.impl.artifacts.Component; +import org.apache.tuscany.sca.impl.artifacts.Composite; +import org.apache.tuscany.sca.impl.artifacts.Property; +import org.apache.tuscany.sca.impl.artifacts.Reference; +import org.apache.tuscany.sca.impl.artifacts.Service; +import org.apache.tuscany.sca.impl.artifacts.Text; +import org.apache.tuscany.sca.impl.artifacts.Wire; + + + +public class SVGDiagramGenerator { + + private static final File outFile = new File(System.getProperty("user.dir") + + "/output/test.svg"); + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + fileWriter(buildSVGDocument()); + + } + + + public static Document buildSVGDocument(){ + DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); + String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; + Document doc = impl.createDocument(svgNS, "svg", null); + + // Get the root element (the 'svg' element). + Element svgRoot = doc.getDocumentElement(); + + Composite composite = new Composite(); + + Component comp1 = new Component(); + Component comp2 = new Component(); + Component comp3 = new Component(); + + Property prop1 = new Property(); + Property prop2 = new Property(); + + Service ser1 = new Service(); + Service ser2 = new Service(); + Service ser3 = new Service(); + + Reference ref1 = new Reference(); + Reference ref2 = new Reference(); + + Wire edge1 = new Wire(); + Wire edge2 = new Wire(); + + Element rectangle1 = comp1.addElement(doc, svgNS, 50, 20, 130, 200); + Element text1 = Text.addTextElement(doc, svgNS, 150, 90, "SCA Component"); + + Element property1 = prop1.addElement(doc, svgNS, 120, 10, 20); + Element property2 = prop2.addElement(doc, svgNS, 160, 10, 20); + + Element polygon1 = ser1.addElement(doc, svgNS, 50, 85, 30); + + Element polygon2 = ref1.addElement(doc, svgNS, 270, 60, 30); + Element polygon3 = ref2.addElement(doc, svgNS, 270, 110, 30); + + //Element wire1 = edge1.addElement(doc, svgNS, 270, 60, 390, 85); + + Element rectangle2 = comp2.addElement(doc, svgNS, 400, 20, 130, 200); + Element text2 = Text.addTextElement(doc, svgNS, 500, 90, "SCA Component"); + + Element polygon4 = ser2.addElement(doc, svgNS, 400, 90, 30); + //Element polygon3 = Reference.addReferenceElement(doc, svgNS, 600, 105); + + Element rectangle3 = comp3.addElement(doc, svgNS, 400, 200, 130, 200); + Element text3 = Text.addTextElement(doc, svgNS, 500, 270, "SCA Component"); + + Element polygon5 = ser3.addElement(doc, svgNS, 400, 270, 30); + + Element wire1 = edge1.addElement(doc, svgNS, ref1, ser2); + Element wire2 = edge2.addElement(doc, svgNS, ref2, ser3); + //Element wire2 = Wire.addWireElement(doc, svgNS, 270, 110, 390, 265); + + // Set the width and height attributes on the root 'svg' element. + svgRoot.setAttributeNS(null, "width", "650"); + svgRoot.setAttributeNS(null, "height", "450"); + + Element composi = composite.addElement(doc, svgNS, 0, 0, 350, 650); + Element text4 = Text.addTextElement(doc, svgNS, 75, 320, "Composite"); + + svgRoot.appendChild(composi); + svgRoot.appendChild(text4); + + // Attach the rectangle to the root 'svg' element. + svgRoot.appendChild(rectangle1); + svgRoot.appendChild(text1); + svgRoot.appendChild(property1); + svgRoot.appendChild(property2); + svgRoot.appendChild(polygon1); + svgRoot.appendChild(polygon2); + svgRoot.appendChild(polygon3); + + svgRoot.appendChild(rectangle2); + svgRoot.appendChild(text2); + svgRoot.appendChild(polygon4); + //svgRoot.appendChild(polygon3); + + svgRoot.appendChild(rectangle3); + svgRoot.appendChild(text3); + svgRoot.appendChild(polygon5); + + svgRoot.appendChild(wire1); + svgRoot.appendChild(wire2); + //svgRoot.setAttributeNS(null, "fill", "#CAE1FF"); + //System.out.println(doc.getDocumentElement().getAttribute("width")); + + return doc; + } + + public static void fileWriter(Document doc) throws Exception{ + + FileWriter fileWriter = new FileWriter(outFile); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(bufferedWriter); + transformer.transform(source, result); + + } +} |