home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
-
- public class Label extends View implements Target {
- TextField label;
- Target target;
- String command;
- Rect underlineRect;
- int key;
- static final String LABEL_KEY = "label";
- static final String TARGET_KEY = "target";
- static final String COMMAND_KEY = "command";
- static final String KEY_KEY = "labelKey";
- final int UNDERLINE_SIZE;
- final String SEND_COMMAND;
-
- public Label() {
- this("", (Font)null);
- }
-
- public Label(String var1, Font var2) {
- this.SEND_COMMAND = "sendCommand";
- this.label = new TextField(0, 0, 0, 0);
- this.label.setBorder((Border)null);
- this.label.setStringValue(var1);
- this.label.setFont(var2);
- this.label.setTransparent(true);
- this.label.setEditable(false);
- this.label.setSelectable(false);
- this.label.setJustification(2);
- ((View)this).addSubview(this.label);
- ((View)this).sizeToMinSize();
- }
-
- public void setJustification(int var1) {
- this.label.setJustification(var1);
- }
-
- public int justification() {
- return this.label.justification();
- }
-
- public void setTitle(String var1) {
- this.label.setStringValue(var1);
- this.invalidateUnderlineRect();
- }
-
- public String title() {
- return this.label.stringValue();
- }
-
- public void setFont(Font var1) {
- this.label.setFont(var1);
- this.invalidateUnderlineRect();
- }
-
- public Font font() {
- return this.label.font();
- }
-
- public Size minSize() {
- Font var1 = this.label.font();
- FontMetrics var2 = var1.fontMetrics();
- int var3 = var2.stringWidth(this.label.stringValue());
- int var4 = var2.stringHeight();
- return new Size(var3, var4);
- }
-
- public void didSizeBy(int var1, int var2) {
- super.didSizeBy(var1, var2);
- this.invalidateUnderlineRect();
- this.label.setBounds(0, 0, ((View)this).width(), ((View)this).height());
- }
-
- public void setColor(Color var1) {
- this.label.setTextColor(var1);
- }
-
- public Color color() {
- return this.label.textColor();
- }
-
- public void setTarget(Target var1) {
- this.target = var1;
- }
-
- public Target target() {
- return this.target;
- }
-
- public void setCommand(String var1) {
- this.command = var1;
- }
-
- public String command() {
- return this.command;
- }
-
- public void setCommandKey(int var1) {
- this.key = var1;
- this.invalidateUnderlineRect();
- ((View)this).removeAllCommandsForKeys();
- ((View)this).setCommandForKey("sendCommand", (Object)null, var1, 0, 1);
- ((View)this).setCommandForKey("sendCommand", (Object)null, var1, 2, 1);
- ((View)this).setDirty(true);
- }
-
- public int commandKey() {
- return this.key;
- }
-
- public boolean isTransparent() {
- return true;
- }
-
- public void performCommand(String var1, Object var2) {
- if ("sendCommand".equals(var1)) {
- this.sendCommand();
- }
-
- }
-
- void invalidateUnderlineRect() {
- this.underlineRect = null;
- }
-
- public Rect underlineRect() {
- if (this.underlineRect == null) {
- if (this.key != 0) {
- String var2 = this.label.stringValue();
- int var1 = var2.indexOf(this.key);
- if (var1 == -1) {
- var1 = var2.toUpperCase().indexOf(this.key);
- if (var1 == -1) {
- var1 = var2.toLowerCase().indexOf(this.key);
- }
- }
-
- if (var1 != -1) {
- Rect var3 = this.label.rectForRange(var1, var1 + 1);
- this.underlineRect = new Rect();
- this.label.convertRectToView(this, var3, this.underlineRect);
- this.underlineRect.y = this.underlineRect.y + this.underlineRect.height - 1;
- this.underlineRect.height = 1;
- }
- }
-
- if (this.underlineRect == null) {
- this.underlineRect = new Rect(0, 0, 0, 0);
- }
- }
-
- return this.underlineRect;
- }
-
- public void drawView(Graphics var1) {
- Rect var2 = this.underlineRect();
- if (var2 != null && var2.intersects(var1.clipRect())) {
- var1.setColor(this.label.textColor());
- var1.fillRect(this.underlineRect());
- }
-
- }
-
- void sendCommand() {
- if (this.target != null && this.command != null) {
- this.target.performCommand(this.command, this);
- }
-
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.Label", 1);
- var1.addField("label", (byte)18);
- var1.addField("target", (byte)18);
- var1.addField("command", (byte)16);
- var1.addField("labelKey", (byte)8);
- }
-
- public void encode(Encoder var1) throws CodingException {
- super.encode(var1);
- var1.encodeObject("label", this.label);
- var1.encodeObject("target", (Codable)this.target);
- var1.encodeString("command", this.command);
- var1.encodeInt("labelKey", this.key);
- }
-
- public void decode(Decoder var1) throws CodingException {
- super.decode(var1);
- this.label = (TextField)var1.decodeObject("label");
- this.target = (Target)var1.decodeObject("target");
- this.command = var1.decodeString("command");
- this.key = var1.decodeInt("labelKey");
- }
- }
-