View Javadoc

1   /*
2    * BasicLabel.java Created @ Jun 9, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  
14  package org.gscg.common.gui.components;
15  
16  import info.clearthought.layout.TableLayout;
17  
18  import java.awt.Color;
19  import java.awt.Component;
20  import java.awt.Font;
21  
22  import javax.swing.JLabel;
23  import javax.swing.JPanel;
24  
25  /***
26   * The BasicLabel is used in a table to show a String in a cell.
27   * <p>
28   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
29   * Delft, the Netherlands. All rights reserved.
30   * 
31   * See for project information <a href="http://www.simulation.tudelft.nl/">
32   * www.simulation.tudelft.nl </a>.
33   * 
34   * The source code and binary code of this software is proprietary information
35   * of Delft University of Technology.
36   * 
37   * @author <a
38   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
39   *         van Houten </a>
40   * 
41   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
42   *         </a>
43   * 
44   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:53 $
45   * @since 1.0.0
46   */
47  public class BasicLabel extends JPanel
48  {
49  	/*** the serial version uid */
50  	private static final long serialVersionUID = 11L;
51  
52  	/*** the label */
53  	protected JLabel label = new JLabel();
54  
55  	/*** the background color */
56  	protected Color background = null;
57  
58  	/***
59  	 * constructs a new BasicLabel
60  	 * 
61  	 * @param text the text of the label
62  	 * @param width the width of the label
63  	 * @param height the height of the label
64  	 */
65  	public BasicLabel(final String text, final double width, final double height)
66  	{
67  		this(text, width, height, new Color(255, 255, 255));
68  	}
69  
70  	/***
71  	 * constructs a new BasicLabel
72  	 * 
73  	 * @param text the text of the label
74  	 * @param width the width of the label
75  	 * @param height the height of the label
76  	 * @param background the background
77  	 */
78  	public BasicLabel(final String text, final double width,
79  			final double height, final Color background)
80  	{
81  		super();
82  		this.label.setText(text);
83  		this.background = background;
84  
85  		double[][] layout = {{width}, {height}};
86  		this.initialize(layout);
87  	}
88  
89  	/***
90  	 * Method initialize initializes the main panel. This panel is used to add
91  	 * all other panel to.
92  	 * 
93  	 * @param layout the layout
94  	 */
95  	private void initialize(final double[][] layout)
96  	{
97  		this.setLayout(new TableLayout(layout));
98  
99  		this.setBackground(this.background);
100 
101 		this.label.setAlignmentX(Component.LEFT_ALIGNMENT);
102 		this.label.setAlignmentY(Component.CENTER_ALIGNMENT);
103 
104 		this.add(this.label, "0,0,L,C");
105 	}
106 
107 	/***
108 	 * @see java.awt.Component#setBackground(java.awt.Color)
109 	 */
110 	public void setBackground(final Color bg)
111 	{
112 		super.setBackground(bg);
113 		this.label.setBackground(bg);
114 	}
115 
116 	/***
117 	 * @see java.awt.Component#setFont(java.awt.Font)
118 	 */
119 	public void setFont(final Font font)
120 	{
121 		super.setFont(font);
122 
123 		if (this.label == null)
124 		{
125 			this.label = new JLabel();
126 		}
127 		this.label.setFont(font);
128 	}
129 
130 	/***
131 	 * @see java.awt.Component#setForeground(java.awt.Color)
132 	 */
133 	public void setForeground(final Color fg)
134 	{
135 		super.setForeground(fg);
136 		this.label.setForeground(fg);
137 	}
138 
139 	/***
140 	 * @return Returns the label.
141 	 */
142 	public JLabel getLabel()
143 	{
144 		return this.label;
145 	}
146 }