1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.elements;
14 import java.awt.Point;
16 import org.simantics.g2d.image.Image;
17 import org.simantics.scenegraph.Node;
18 import org.simantics.scenegraph.g2d.G2DParentNode;
19 import org.simantics.utils.datastructures.cache.IFactory;
20 import org.simantics.utils.datastructures.cache.ProvisionException;
23 * This is a SVG implementation to the PaintableSymbol interface.
25 public class SVGImage extends org.simantics.g2d.svg.SVGImage {
27 public SVGImage(String nodeIdentifier, String document, Point targetSize) {
28 super(nodeIdentifier, document, targetSize);
31 public SVGImage(String nodeIdentifier, String document) {
32 super(nodeIdentifier, document);
35 public static IFactory<Image> createFactoryFromString(String nodeIdentifier, String svgDocument, Point targetSize) {
36 return new SVGFactory(nodeIdentifier, svgDocument, targetSize);
39 static class SVGFactory implements IFactory<Image> {
40 String nodeIdentifier;
43 public SVGFactory(String nodeIdentifier, String document) {
44 this(nodeIdentifier, document, null);
46 public SVGFactory(String nodeIdentifier, String document, Point referenceSize) {
47 if (nodeIdentifier == null)
48 throw new NullPointerException("nodeIdentifier is null");
50 throw new NullPointerException("document is null");
52 this.nodeIdentifier = nodeIdentifier;
53 this.document = document;
54 this.targetSize = referenceSize;
57 public Image get() throws ProvisionException {
58 return new SVGImage(nodeIdentifier, document, targetSize);
61 public boolean equals(Object obj) {
66 if (!obj.getClass().equals(getClass()))
69 SVGFactory other = (SVGFactory)obj;
71 if (!nodeIdentifier.equals(other.nodeIdentifier))
73 if (targetSize != null) {
74 if (!targetSize.equals(other.targetSize))
77 if (other.targetSize != null)
81 return document.equals(other.document);
84 public int hashCode() {
85 return nodeIdentifier.hashCode() * 31 + document.hashCode() + 123;
90 public Node init(G2DParentNode parent) {
91 // FIXME: mipmaps enabled here by default, since some apps just don't work without them.
92 // Figure out a way to pass the mipmap argument from above
94 SVGNode node = parent.getOrCreateNode(nodeIdentifier, SVGNode.class);
95 node.setData(svgDocument);
96 node.setTargetSize(targetSize);