diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-16 22:45:18 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-16 22:45:18 +0000 |
commit | 6e4fab25b13f7af6b1b1fa766b111fd529a59490 (patch) | |
tree | 4497c3ada7926b91aa9245de02de60b821f07f8b /sca-java-2.x/trunk/modules/composite-diagram | |
parent | d877f13cb2e737db412311d9ef83d4eeeefde3c7 (diff) |
Externalize the artifact styles into CSS
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171841 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/composite-diagram')
14 files changed, 201 insertions, 37 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 96a1d6ad1c..0441005097 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 @@ -41,9 +41,10 @@ public class ComponentArtifact extends Artifact { 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"); +// rectangle.setAttributeNS(null, "fill", "#3D59AB"); +// rectangle.setAttributeNS(null, "stroke", "#104E8B"); +// rectangle.setAttributeNS(null, "fill-opacity", "0.75"); + rectangle.setAttributeNS(null, "class", "component"); return rectangle; } 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 38285cac2a..6ff6ce567c 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 @@ -42,9 +42,10 @@ public class CompositeArtifact extends Artifact { 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, "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/DashedWire.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java index 4f9c741ab6..229b14e083 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java @@ -58,7 +58,9 @@ public class DashedWire extends WireArtifact { polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color); - polyline.setAttributeNS(null, "stroke-dasharray", "3 3"); +// polyline.setAttributeNS(null, "stroke-dasharray", "3 3"); + polyline.setAttributeNS(null, "class", "wire dashedWire"); + return polyline; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java index 576fa118d1..21bcadf872 100644 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java @@ -45,6 +45,8 @@ public class ImplementationArtifact extends Artifact { 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; } 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 fa2d44f89f..d560fcd68c 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 @@ -45,6 +45,7 @@ public class Layer extends Artifact { 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/NormalWire.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java index 7611c004aa..c3abe8d2e2 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java @@ -38,6 +38,7 @@ public class NormalWire extends WireArtifact { 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/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java index 4b13c0de64..8622c7ad04 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java @@ -46,6 +46,8 @@ public class PropertyArtifact extends Artifact { rectangle.setAttributeNS(null, "fill", "#EEEE00"); rectangle.setAttributeNS(null, "stroke", "#EEC900"); //rectangle.setAttributeNS(null, "fill-opacity", "0.75"); + + rectangle.setAttributeNS(null, "class", "property"); return rectangle; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java index 87ecba2af7..dc561f8e49 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java @@ -74,6 +74,8 @@ public class ReferenceArtifact extends Artifact { polygon.setAttributeNS(null, "fill", "#BF3EFF"); polygon.setAttributeNS(null, "stroke", "#68228B"); + polygon.setAttributeNS(null, "class", "reference"); + return polygon; } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java index d7c312f729..4f305b4ba5 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java @@ -74,7 +74,7 @@ public class ServiceArtifact extends Artifact { polygon.setAttributeNS(null, "fill", "#00CD66"); polygon.setAttributeNS(null, "stroke", "#008B45"); - + polygon.setAttributeNS(null, "class", "service"); return polygon; } 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 new file mode 100644 index 0000000000..6370358c9f --- /dev/null +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java @@ -0,0 +1,108 @@ +/* + * 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 String 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"; + + public Element addElement(Document document, String svgNs, String css) { + + Element style = document.createElementNS(svgNs, "style"); + style.setAttributeNS(null, "type", "text/css"); + + if (css != null) { + this.css = css; + } + try { + this.css = readCSS(); + } catch (IOException e) { + // Ignore + } + CDATASection cdata = document.createCDATASection(this.css); + style.appendChild(cdata); + + return style; + } + + private String readCSS() throws IOException { + InputStream is = getClass().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(); + return sw.toString(); + + } +} diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java index ec4563254a..580209d289 100644 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java @@ -32,7 +32,7 @@ public class Text { 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/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java index 0b3e83b9c2..80466621b6 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java @@ -79,6 +79,8 @@ public abstract class WireArtifact { polyline.setAttributeNS(null, "stroke", color); polyline.setAttributeNS(null, "stroke-width", "2"); polyline.setAttributeNS(null, "fill", "none"); + + polyline.setAttributeNS(null, "class", "wire"); return polyline; } 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 4c6b5d4640..b7ff1b47e7 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 @@ -35,6 +35,7 @@ import org.apache.tuscany.sca.diagram.artifacts.NormalWire; import org.apache.tuscany.sca.diagram.artifacts.PropertyArtifact; import org.apache.tuscany.sca.diagram.artifacts.ReferenceArtifact; import org.apache.tuscany.sca.diagram.artifacts.ServiceArtifact; +import org.apache.tuscany.sca.diagram.artifacts.Style; import org.apache.tuscany.sca.diagram.artifacts.Text; import org.apache.tuscany.sca.diagram.artifacts.WireArtifact; import org.apache.tuscany.sca.diagram.layout.ComponentEntity; @@ -112,6 +113,8 @@ public class DiagramGenerator { svgRoot.setAttributeNS(null, "viewBox", "0 0 " + getDiagramWidth() + " " + getDiagramHeight()); + svgRoot.appendChild(new Style().addElement(doc, svgNS, null)); + addLayer(); addComposite(); @@ -319,15 +322,10 @@ public class DiagramGenerator { Element child = property; if (baseURL != null) { - Element link = doc.createElementNS(svgNS, "a"); - link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" - + ent.getName() - + "/properties/" - + prop); - link.appendChild(property); - child = link; + String url = baseURL + "/components/" + ent.getName() + "/properties/" + prop; + child = createLink(property, url); } - + svgRoot.appendChild(child); svgRoot.appendChild(text); @@ -350,13 +348,8 @@ public class DiagramGenerator { Element child = polygon; if (baseURL != null) { - Element link = doc.createElementNS(svgNS, "a"); - link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" - + ent.getName() - + "/services/" - + ref); - link.appendChild(polygon); - child = link; + String url = baseURL + "/components/" + ent.getName() + "/services/" + ref; + child = createLink(polygon, url); } Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ref); @@ -481,13 +474,8 @@ public class DiagramGenerator { Element child = polygon; if (baseURL != null) { - Element link = doc.createElementNS(svgNS, "a"); - link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" - + ent.getName() - + "/services/" - + ser); - link.appendChild(polygon); - child = link; + String url = baseURL + "/components/" + ent.getName() + "/services/" + ser; + child = createLink(polygon, url); } svgRoot.appendChild(child); @@ -601,10 +589,8 @@ public class DiagramGenerator { Element component = com; if (baseURL != null) { - Element link = doc.createElementNS(svgNS, "a"); - link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" + ent.getName()); - link.appendChild(com); - component = link; + String url = baseURL + "/components/" + ent.getName(); + component = createLink(com, url); } Element text = @@ -618,7 +604,7 @@ public class DiagramGenerator { svgRoot.appendChild(text); comp.setName(ent.getName()); - + if (ent.getImplementation() == null) { return; } @@ -641,9 +627,20 @@ public class DiagramGenerator { ent.getY() + (ent.getHeight() / 4 + Constant.COMPONENT_TEXT_SPACING), ent.getImplementation()); text2.setAttributeNS(null, "font-size", "10"); + if (baseURL != null) { + String url = baseURL + "/components/" + ent.getName() + "/implementation"; + implElement = createLink(implElement, url); + } svgRoot.appendChild(implElement); svgRoot.appendChild(text2); - + + } + + private Element createLink(Element com, String url) { + Element link = doc.createElementNS(svgNS, "a"); + link.setAttributeNS(XLINK_NS, "xlink:href", url); + link.appendChild(com); + return link; } private void addComposite() { diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/resources/org/apache/tuscany/sca/diagram/artifacts/composite-diagram.css b/sca-java-2.x/trunk/modules/composite-diagram/src/main/resources/org/apache/tuscany/sca/diagram/artifacts/composite-diagram.css new file mode 100644 index 0000000000..feb303b99c --- /dev/null +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/resources/org/apache/tuscany/sca/diagram/artifacts/composite-diagram.css @@ -0,0 +1,45 @@ +rect.layer { + fill: #E5E5D0; + stroke: #919191; + alignment-baseline: middle; +} + +rect.composite { + fill: #E5E5E5; + stroke: #919191; + alignment-baseline: middle; +} + +rect.component { + fill: #3D59AB; + stroke: #104E8B; + fill-opacity: 0.75; +} + +rect.property { + fill: #EEEE00; + stroke: #EEC900; +} + +polygon.reference { + fill: #BF3EFF; + stroke: #68228B; +} + +polygon.service { + fill: #00CD66; + stroke: #008B45; +} + +polyline.wire { + stroke-width: 2; + fill: none; +} + +polyline.normalWire { + +} + +polyline.dashedWire { + stroke-dasharray: "3 3"; +}
\ No newline at end of file |