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 3054 2009-07-27 10:23:07Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.backward.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  /**
29   * A node figure with an icon and a multi-line, centered text.
30   * 
31   * @author AGH CAST Team
32   */
33  public class NodeFigure extends Figure implements ILabeledFigure {
34  
35  	/**
36  	 * The image figure that is used for displaying the node.
37  	 */
38  	protected ImageFigure icon;
39  
40  	private FlowPage flowPage;
41  
42  	private TextFlow textFlow;
43  
44  	/**
45  	 * Creates an empty figure.
46  	 */
47  	public NodeFigure() {
48  		super();
49  	}
50  
51  	/**
52  	 * Creates new node figure.
53  	 * 
54  	 * @param label
55  	 *            node label
56  	 * @param imageId
57  	 *            node imageId (see {@link ImageFigure#ImageFigure(String)})
58  	 */
59  	public NodeFigure(String label, String imageId) {
60  		init(label, imageId);
61  	}
62  
63  	public IFigure getIcon() {
64  		return icon;
65  	}
66  
67  	/**
68  	 * {@inheritDoc}
69  	 * 
70  	 * @see pl.edu.agh.cast.backward.figure.ILabeledFigure#getLabel()
71  	 */
72  	public String getLabel() {
73  		return textFlow.getText();
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 * 
79  	 * @see pl.edu.agh.cast.backward.figure.ILabeledFigure#setLabel(java.lang.String)
80  	 */
81  	public void setLabel(String label) {
82  		textFlow.setText(label);
83  	}
84  
85  	/**
86  	 * Initializes the node figure.
87  	 * 
88  	 * @param label
89  	 *            node label
90  	 * @param imageId
91  	 *            node imageId (see {@link ImageFigure#ImageFigure(String)})
92  	 */
93  	protected void init(String label, String imageId) {
94  
95  		flowPage = new FlowPage();
96  		textFlow = new TextFlow(label);
97  		flowPage.add(textFlow);
98  		flowPage.setHorizontalAligment(PositionConstants.CENTER);
99  		flowPage.setBackgroundColor(ColorConstants.listBackground);
100 		flowPage.setOpaque(true);
101 
102 		icon = new ImageFigure(imageId);
103 
104 		add(icon);
105 		add(flowPage);
106 
107 		ToolbarLayout layout = new ToolbarLayout();
108 		layout.setStretchMinorAxis(false);
109 		layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
110 		setLayoutManager(layout);
111 
112 	}
113 
114 	public Figure getLabelFigure() {
115 		return flowPage;
116 	}
117 
118 }