]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/AWTImage.java
e547a663e8e8844024f110485ee85ba81d7ee302
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / image / impl / AWTImage.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.image.impl;
13
14 import java.awt.Shape;
15 import java.awt.geom.Rectangle2D;
16 import java.awt.image.BufferedImage;
17 import java.util.EnumSet;
18
19 import org.simantics.g2d.image.Image;
20 import org.simantics.g2d.image.ImageUtils;
21 import org.simantics.scenegraph.Node;
22 import org.simantics.scenegraph.g2d.G2DParentNode;
23 import org.simantics.scenegraph.g2d.nodes.ImageNode;
24
25 /**
26  * Adapts {@link BufferedImage} to {@link Image}
27  * 
28  * @See {@link ImageUtils}
29  * @author Toni Kalajainen
30  */
31 public class AWTImage extends AbstractImage implements Image {
32
33     static EnumSet<Feature> feats = EnumSet.noneOf(Feature.class);
34
35     BufferedImage bi;
36     Rectangle2D rect;
37
38     public AWTImage(BufferedImage bi) {
39         assert(bi!=null);
40         this.bi = bi;
41         rect = new Rectangle2D.Double(bi.getMinX(),bi.getMinY(),bi.getWidth(), bi.getHeight());
42     }
43
44     @Override
45     public Rectangle2D getBounds() {
46         return rect;
47     }
48
49     @Override
50     public Shape getOutline() {
51         return rect;
52     }
53
54     @Override
55     public Node init(G2DParentNode parent) {
56         ImageNode node = parent.getOrCreateNode("image", ImageNode.class);
57         node.setImage(bi);
58         return node;
59     }
60
61     @Override
62     public EnumSet<Feature> getFeatures() {
63         return feats;
64     }
65
66 }