View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: ImageFigure.java
13   * Created: 2007-00-00
14   * Author: cast
15   * $Id: ImageFigure.java 3054 2009-07-27 10:23:07Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.figure;
19  
20  import org.eclipse.draw2d.Figure;
21  import org.eclipse.draw2d.Graphics;
22  import org.eclipse.draw2d.geometry.Dimension;
23  import org.eclipse.swt.graphics.Image;
24  import org.eclipse.swt.graphics.Rectangle;
25  
26  import pl.edu.agh.cast.backward.figure.icons.NodeIconProvider;
27  import pl.edu.agh.cast.util.Images;
28  
29  /**
30   * A {@link Figure} with an {@link Image}.
31   *
32   * The images are provided by {@link Images} helper class.
33   *
34   * @author AGH CAST Team
35   */
36  public class ImageFigure extends Figure {
37  
38  	private Image image;
39  
40  	/**
41  	 * Use ImageFigure(String imageId) constructor to create this figure.
42  	 */
43  	@SuppressWarnings("unused")
44  	private ImageFigure() {
45  	}
46  
47  	/**
48  	 * Creates new figure with an image with given Id.
49  	 *
50  	 * @param imageId
51  	 *            id of the image to be used
52  	 */
53  	public ImageFigure(String imageId) {
54  		image = Images.getInstance().get(imageId);
55  		if (image == null) {
56  			image = Images.getInstance().get(NodeIconProvider.getInstance().getDefaultIcon().getIconId());
57  		}
58  	}
59  
60  	/**
61  	 * {@inheritDoc}
62  	 *
63  	 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
64  	 */
65  	@Override
66  	protected void paintFigure(Graphics gc) {
67  		gc.drawImage(image, getBounds().getTopLeft());
68  		// super.paintFigure(gc);
69  	}
70  
71  	/**
72  	 * {@inheritDoc}
73  	 *
74  	 * @see org.eclipse.draw2d.Figure#setBounds(org.eclipse.draw2d.geometry.Rectangle)
75  	 */
76  	@Override
77  	public void setBounds(org.eclipse.draw2d.geometry.Rectangle bounds) {
78  		super.setBounds(bounds);
79  	}
80  
81  	/**
82  	 * {@inheritDoc}
83  	 *
84  	 * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
85  	 */
86  	@Override
87  	public Dimension getMinimumSize(int arg0, int arg1) {
88  		Rectangle bounds = image.getBounds();
89  		return new Dimension(bounds.width, bounds.height);
90  	}
91  
92  	/**
93  	 * {@inheritDoc}
94  	 *
95  	 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
96  	 */
97  	@Override
98  	public Dimension getPreferredSize(int x, int y) {
99  		return getMinimumSize(x, y);
100 	}
101 
102 }