001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: /**
012: * A Label is piece of text.
013: *
014: * @author Robin Sharp
015: */
016:
017: import java.awt.*;
018: import java.io.*;
019: import java.util.*;
020: import java.awt.event.*;
021:
022: import com.javelin.swinglets.event.*;
023:
024: public class SLabel extends SComponent {
025: /**
026: * Creates a <code>JLabel</code> instance with the specified
027: * text, image, and horizontal alignment.
028: */
029: public SLabel(SIcon icon, String text, SLink link) {
030: if (text != null)
031: setText(text);
032: if (icon != null)
033: setIcon(icon);
034: if (link != null)
035: setLink(link);
036: }
037:
038: /**
039: * Creates a <code>JLabel</code> instance with the specified
040: * text and image.
041: */
042: public SLabel(SIcon icon, String text) {
043: this (icon, text, null);
044: }
045:
046: /**
047: * Creates a <code>JLabel</code> instance with the specified text
048: * and link.
049: */
050: public SLabel(String text, SLink link) {
051: this (null, text, link);
052: }
053:
054: /**
055: * Creates a <code>JLabel</code> instance with the specified text.
056: */
057: public SLabel(String text) {
058: this (null, text, null);
059:
060: }
061:
062: /**
063: * Creates a <code>JLabel</code> instance with the specified image.
064: */
065: public SLabel(SIcon icon) {
066: this (icon, null, null);
067: }
068:
069: /**
070: * Creates a <code>JLabel</code> instance with the specified image
071: * and link.
072: */
073: public SLabel(SIcon icon, SLink link) {
074: this (icon, null, link);
075: }
076:
077: /**
078: * Creates a <code>JLabel</code> instance with
079: * no image and with an empty string for the title.
080: */
081: public SLabel() {
082: this (null, "", null);
083: }
084:
085: /**
086: * Returns the name of the L&F class that renders this component.
087: */
088: public Class getUIClass() {
089: return SLabel.class;
090: }
091:
092: /**
093: * Returns the text string that the label displays.
094: */
095: public String getText() {
096: return text;
097: }
098:
099: /**
100: * Defines the single line of text this component will display.
101: */
102: public SLabel setText(String text) {
103: firePropertyChange("text", this .text, this .text = text);
104: return this ;
105: }
106:
107: /**
108: * Returns the achor
109: */
110: public String getAnchor() {
111: return anchor;
112: }
113:
114: /**
115: * Defines the single line of text this component will display.
116: */
117: public SLabel setAnchor(String anchor) {
118: firePropertyChange("anchor", this .anchor, this .anchor = anchor);
119: return this ;
120: }
121:
122: /**
123: * Returns the icon that this label displays.
124: */
125: public SIcon getIcon() {
126: return icon;
127: }
128:
129: /**
130: * Defines the icon this component will display.
131: */
132: public SLabel setIcon(SIcon icon) {
133: firePropertyChange("icon", this .icon, this .icon = icon);
134: return this ;
135: }
136:
137: /**
138: * Set the Hyper Link.
139: */
140: public SLabel setLink(SLink link) {
141: firePropertyChange("link", this .link, this .link = link);
142: return this ;
143: }
144:
145: /**
146: * Returns the alignment of the text relative to the icon.
147: */
148: public int getTextAlignment() {
149: return textAlignment;
150: }
151:
152: /**
153: * Sets the alignment of the text relative to the icon.
154: * One of SConstants LEFT, RIGHT
155: */
156: public SComponent setTextAlignment(int textAlignment) {
157: firePropertyChange("textAlignment", this .textAlignment,
158: this .textAlignment = textAlignment);
159: return this ;
160: }
161:
162: /**
163: * Get the Hyper Link.
164: */
165: public SLink getLink() {
166: return link;
167: }
168:
169: /**
170: * Processes events occurring on this component.
171: */
172: protected void processEvent(AWTEvent event) {
173: if (event instanceof FormEvent) {
174: processActionEvent(new ActionEvent(this ,
175: ActionEvent.ACTION_PERFORMED, null));
176: } else {
177: super .processEvent(event);
178: }
179: }
180:
181: // PRIVATE ////////////////////////////////////////////////////
182:
183: protected String text;
184: protected String anchor;
185: protected SIcon icon;
186: protected SLink link;
187: protected int textAlignment = SConstants.RIGHT;
188:
189: }
|