KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > ImageLabel


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.awt;
21
22 import java.awt.AWTEvent JavaDoc;
23 import java.awt.BorderLayout JavaDoc;
24 import java.awt.Color JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Font JavaDoc;
27 import java.awt.Image JavaDoc;
28 import java.awt.Label JavaDoc;
29
30 /**
31  * Component that can display some text and an image
32  *
33  * @author $Author: james $
34  */

35 public class ImageLabel
36     extends BevelPanel {
37
38   private ImageCanvas imageCanvas;
39   private Label JavaDoc textLabel;
40
41   /**
42    * Construct a image label with no text or image
43    */

44   public ImageLabel() {
45     this(null, null);
46   }
47
48   /**
49    * Construct a new image label with an image
50    *
51    * @param image image
52    */

53   public ImageLabel(Image JavaDoc image) {
54     this(null, image);
55   }
56
57   /**
58    * Construct a new image label with some text
59    *
60    * @param text text
61    */

62   public ImageLabel(String JavaDoc text) {
63     this(text, null);
64   }
65
66   /**
67    * Construct a new image label with an image and some text
68    *
69    * @param text text
70    * @param image image
71    */

72   public ImageLabel(String JavaDoc text, Image JavaDoc image) {
73     super(NONE, new BorderLayout JavaDoc(2, 0));
74     imageCanvas = new ImageCanvas();
75     textLabel = new Label JavaDoc() {
76       public Dimension JavaDoc getMinimumSize() {
77         return getPreferredSize();
78       }
79
80       public void processEvent(AWTEvent JavaDoc evt) {
81         ImageLabel.this.dispatchEvent(evt);
82       }
83     };
84     add(imageCanvas, BorderLayout.WEST);
85     add(textLabel, BorderLayout.CENTER);
86     setText(text);
87     setImage(image);
88   }
89
90   /**
91    * Set the image
92    *
93    * @param image image
94    */

95   public void setImage(Image JavaDoc image) {
96     imageCanvas.setImage(image);
97     imageCanvas.setVisible(image != null);
98   }
99
100   /**
101    * Get the image
102    *
103    * @retirm image
104    */

105   public Image JavaDoc getImage() {
106     return imageCanvas.getImage();
107   }
108
109   /**
110    * Set the text
111    *
112    * @param text text
113    */

114   public void setText(String JavaDoc text) {
115     textLabel.setText(text);
116     textLabel.setVisible(text != null);
117   }
118
119   /**
120    * Set the font
121    *
122    * @param font font
123    */

124   public void setFont(Font JavaDoc font) {
125     super.setFont(font);
126     textLabel.setFont(font);
127   }
128
129   /**
130    * Set foreground color of text
131    *
132    * @param color foreground color
133    */

134   public void setForeground(Color JavaDoc foreground) {
135     super.setForeground(foreground);
136     textLabel.setForeground(foreground);
137   }
138 }
139
Popular Tags