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: NodeFigure.java
13   * Created: 2007-00-00
14   * Author: fox, awos
15   * $Id: NodeFigure.java 3244 2009-08-24 14:25:43Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.figure;
19  
20  import org.eclipse.draw2d.ColorConstants;
21  import org.eclipse.draw2d.Figure;
22  import org.eclipse.draw2d.IFigure;
23  import org.eclipse.draw2d.PositionConstants;
24  import org.eclipse.draw2d.ToolbarLayout;
25  import org.eclipse.draw2d.text.FlowPage;
26  import org.eclipse.draw2d.text.TextFlow;
27  
28  import pl.edu.agh.cast.resource.ImageSize;
29  
30  /**
31   * A node figure with an icon and a multi-line, centered text.
32   *
33   * @author AGH CAST Team
34   */
35  public class NodeFigure extends Figure implements ILabeledFigure {
36  
37  	/**
38  	 * The image figure that is used for displaying the node.
39  	 */
40  	protected ImageFigure icon;
41  
42  	private FlowPage flowPage;
43  
44  	private TextFlow textFlow;
45  
46  	/**
47  	 * Creates an empty figure.
48  	 */
49  	public NodeFigure() {
50  		super();
51  	}
52  
53  	/**
54  	 * Creates new node figure.
55  	 *
56  	 * @param label
57  	 *            node label
58  	 * @param resourceId
59  	 *            node resource id
60  	 * @param size
61  	 *            image size
62  	 */
63  	public NodeFigure(String label, String resourceId, ImageSize size) {
64  		init(label, resourceId, size);
65  	}
66  
67  	public IFigure getIcon() {
68  		return icon;
69  	}
70  
71  	/**
72  	 * {@inheritDoc}
73  	 *
74  	 * @see pl.edu.agh.cast.backward.figure.ILabeledFigure#getLabel()
75  	 */
76  	public String getLabel() {
77  		return textFlow.getText();
78  	}
79  
80  	/**
81  	 * {@inheritDoc}
82  	 *
83  	 * @see pl.edu.agh.cast.backward.figure.ILabeledFigure#setLabel(java.lang.String)
84  	 */
85  	public void setLabel(String label) {
86  		textFlow.setText(label);
87  	}
88  
89  	/**
90  	 * Initializes the node figure.
91  	 *
92  	 * @param label
93  	 *            node label
94  	 * @param resourceId
95  	 *            node resource id
96  	 * @param size
97  	 *            size of figure image
98  	 */
99  	protected void init(String label, String resourceId, ImageSize size) {
100 		this.init(label, resourceId, size);
101 	}
102 
103 	/**
104 	 * Initializes the node figure.
105 	 *
106 	 * @param label
107 	 *            node label
108 	 * @param resourceId
109 	 *            node resource id
110 	 * @param size
111 	 *            size of figure image
112 	 * @param defaultResourceId
113 	 *            node default resource id
114 	 */
115 	protected void init(String label, String resourceId, ImageSize size, String defaultResourceId) {
116 
117 		flowPage = new FlowPage();
118 		textFlow = new TextFlow(label);
119 		flowPage.add(textFlow);
120 		flowPage.setHorizontalAligment(PositionConstants.CENTER);
121 		flowPage.setBackgroundColor(ColorConstants.listBackground);
122 		flowPage.setOpaque(true);
123 
124 		icon = new ImageFigure(resourceId, size, defaultResourceId);
125 
126 		add(icon);
127 		add(flowPage);
128 
129 		ToolbarLayout layout = new ToolbarLayout();
130 		layout.setStretchMinorAxis(false);
131 		layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
132 		setLayoutManager(layout);
133 
134 	}
135 
136 	public Figure getLabelFigure() {
137 		return flowPage;
138 	}
139 
140 }