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.scenegraph.g2d.nodes;
14 import java.awt.Graphics2D;
15 import java.awt.geom.AffineTransform;
16 import java.awt.geom.Rectangle2D;
17 import java.awt.image.BufferedImage;
18 import java.io.ByteArrayInputStream;
19 import java.io.IOException;
21 import javax.imageio.ImageIO;
23 import org.simantics.scenegraph.g2d.G2DNode;
25 public class ImageNode extends G2DNode {
27 private static final long serialVersionUID = -4982578347433716440L;
29 protected Boolean visible = Boolean.TRUE;
30 protected BufferedImage img = null;
33 public void setVisible(Boolean visible) {
34 this.visible = visible;
37 public boolean isVisible() {
42 public void setImage(byte[] buf) {
44 img = ImageIO.read(new ByteArrayInputStream(buf));
45 } catch (IOException e) {
49 public void setImage(BufferedImage src) {
54 public void render(Graphics2D g) {
55 if (!visible || img == null) return;
57 AffineTransform ot = null;
58 if (!transform.isIdentity()) {
59 ot = g.getTransform();
60 g.transform(transform);
63 // G2DParentNode parent = (G2DParentNode) getParent();
64 // if(parent != null) {
65 // Rectangle2D b = parent.getBoundsInLocal();
66 // g.drawImage(img, (int)b.getMinX(), (int)b.getMinY(), (int)b.getWidth()+(int)b.getMinX(), (int)b.getHeight()+(int)b.getMinY(), 0, 0, img.getWidth(), img.getHeight(), null);
68 g.drawImage(img, 0, 0, null);
75 public Rectangle2D getBoundsInLocal() {
76 return new Rectangle2D.Double(img.getMinX(), img.getMinY(), img.getWidth(), img.getHeight());