--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.image.impl;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Rectangle2D;\r
+import java.awt.image.BufferedImage;\r
+import java.util.EnumSet;\r
+\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.g2d.image.ImageUtils;\r
+import org.simantics.scenegraph.Node;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.nodes.ImageNode;\r
+\r
+/**\r
+ * Adapts {@link BufferedImage} to {@link Image}\r
+ * \r
+ * @See {@link ImageUtils}\r
+ * @author Toni Kalajainen\r
+ */\r
+public class AWTImage extends AbstractImage implements Image {\r
+\r
+ static EnumSet<Feature> feats = EnumSet.noneOf(Feature.class);\r
+\r
+ BufferedImage bi;\r
+ Rectangle2D rect;\r
+\r
+ public AWTImage(BufferedImage bi) {\r
+ assert(bi!=null);\r
+ this.bi = bi;\r
+ rect = new Rectangle2D.Double(bi.getMinX(),bi.getMinY(),bi.getWidth(), bi.getHeight());\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBounds() {\r
+ return rect;\r
+ }\r
+\r
+ @Override\r
+ public Shape getOutline() {\r
+ return rect;\r
+ }\r
+\r
+ @Override\r
+ public Node init(G2DParentNode parent) {\r
+ ImageNode node = parent.getOrCreateNode("image", ImageNode.class);\r
+ node.setImage(bi);\r
+ return node;\r
+ }\r
+\r
+ @Override\r
+ public EnumSet<Feature> getFeatures() {\r
+ return feats;\r
+ }\r
+\r
+}\r