home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / Label.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  5.8 KB  |  202 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8.  
  9. public class Label extends View implements Target {
  10.    TextField label;
  11.    Target target;
  12.    String command;
  13.    Rect underlineRect;
  14.    int key;
  15.    static final String LABEL_KEY = "label";
  16.    static final String TARGET_KEY = "target";
  17.    static final String COMMAND_KEY = "command";
  18.    static final String KEY_KEY = "labelKey";
  19.    final int UNDERLINE_SIZE;
  20.    final String SEND_COMMAND;
  21.  
  22.    public Label() {
  23.       this("", (Font)null);
  24.    }
  25.  
  26.    public Label(String var1, Font var2) {
  27.       this.SEND_COMMAND = "sendCommand";
  28.       this.label = new TextField(0, 0, 0, 0);
  29.       this.label.setBorder((Border)null);
  30.       this.label.setStringValue(var1);
  31.       this.label.setFont(var2);
  32.       this.label.setTransparent(true);
  33.       this.label.setEditable(false);
  34.       this.label.setSelectable(false);
  35.       this.label.setJustification(2);
  36.       ((View)this).addSubview(this.label);
  37.       ((View)this).sizeToMinSize();
  38.    }
  39.  
  40.    public void setJustification(int var1) {
  41.       this.label.setJustification(var1);
  42.    }
  43.  
  44.    public int justification() {
  45.       return this.label.justification();
  46.    }
  47.  
  48.    public void setTitle(String var1) {
  49.       this.label.setStringValue(var1);
  50.       this.invalidateUnderlineRect();
  51.    }
  52.  
  53.    public String title() {
  54.       return this.label.stringValue();
  55.    }
  56.  
  57.    public void setFont(Font var1) {
  58.       this.label.setFont(var1);
  59.       this.invalidateUnderlineRect();
  60.    }
  61.  
  62.    public Font font() {
  63.       return this.label.font();
  64.    }
  65.  
  66.    public Size minSize() {
  67.       Font var1 = this.label.font();
  68.       FontMetrics var2 = var1.fontMetrics();
  69.       int var3 = var2.stringWidth(this.label.stringValue());
  70.       int var4 = var2.stringHeight();
  71.       return new Size(var3, var4);
  72.    }
  73.  
  74.    public void didSizeBy(int var1, int var2) {
  75.       super.didSizeBy(var1, var2);
  76.       this.invalidateUnderlineRect();
  77.       this.label.setBounds(0, 0, ((View)this).width(), ((View)this).height());
  78.    }
  79.  
  80.    public void setColor(Color var1) {
  81.       this.label.setTextColor(var1);
  82.    }
  83.  
  84.    public Color color() {
  85.       return this.label.textColor();
  86.    }
  87.  
  88.    public void setTarget(Target var1) {
  89.       this.target = var1;
  90.    }
  91.  
  92.    public Target target() {
  93.       return this.target;
  94.    }
  95.  
  96.    public void setCommand(String var1) {
  97.       this.command = var1;
  98.    }
  99.  
  100.    public String command() {
  101.       return this.command;
  102.    }
  103.  
  104.    public void setCommandKey(int var1) {
  105.       this.key = var1;
  106.       this.invalidateUnderlineRect();
  107.       ((View)this).removeAllCommandsForKeys();
  108.       ((View)this).setCommandForKey("sendCommand", (Object)null, var1, 0, 1);
  109.       ((View)this).setCommandForKey("sendCommand", (Object)null, var1, 2, 1);
  110.       ((View)this).setDirty(true);
  111.    }
  112.  
  113.    public int commandKey() {
  114.       return this.key;
  115.    }
  116.  
  117.    public boolean isTransparent() {
  118.       return true;
  119.    }
  120.  
  121.    public void performCommand(String var1, Object var2) {
  122.       if ("sendCommand".equals(var1)) {
  123.          this.sendCommand();
  124.       }
  125.  
  126.    }
  127.  
  128.    void invalidateUnderlineRect() {
  129.       this.underlineRect = null;
  130.    }
  131.  
  132.    public Rect underlineRect() {
  133.       if (this.underlineRect == null) {
  134.          if (this.key != 0) {
  135.             String var2 = this.label.stringValue();
  136.             int var1 = var2.indexOf(this.key);
  137.             if (var1 == -1) {
  138.                var1 = var2.toUpperCase().indexOf(this.key);
  139.                if (var1 == -1) {
  140.                   var1 = var2.toLowerCase().indexOf(this.key);
  141.                }
  142.             }
  143.  
  144.             if (var1 != -1) {
  145.                Rect var3 = this.label.rectForRange(var1, var1 + 1);
  146.                this.underlineRect = new Rect();
  147.                this.label.convertRectToView(this, var3, this.underlineRect);
  148.                this.underlineRect.y = this.underlineRect.y + this.underlineRect.height - 1;
  149.                this.underlineRect.height = 1;
  150.             }
  151.          }
  152.  
  153.          if (this.underlineRect == null) {
  154.             this.underlineRect = new Rect(0, 0, 0, 0);
  155.          }
  156.       }
  157.  
  158.       return this.underlineRect;
  159.    }
  160.  
  161.    public void drawView(Graphics var1) {
  162.       Rect var2 = this.underlineRect();
  163.       if (var2 != null && var2.intersects(var1.clipRect())) {
  164.          var1.setColor(this.label.textColor());
  165.          var1.fillRect(this.underlineRect());
  166.       }
  167.  
  168.    }
  169.  
  170.    void sendCommand() {
  171.       if (this.target != null && this.command != null) {
  172.          this.target.performCommand(this.command, this);
  173.       }
  174.  
  175.    }
  176.  
  177.    public void describeClassInfo(ClassInfo var1) {
  178.       super.describeClassInfo(var1);
  179.       var1.addClass("netscape.application.Label", 1);
  180.       var1.addField("label", (byte)18);
  181.       var1.addField("target", (byte)18);
  182.       var1.addField("command", (byte)16);
  183.       var1.addField("labelKey", (byte)8);
  184.    }
  185.  
  186.    public void encode(Encoder var1) throws CodingException {
  187.       super.encode(var1);
  188.       var1.encodeObject("label", this.label);
  189.       var1.encodeObject("target", (Codable)this.target);
  190.       var1.encodeString("command", this.command);
  191.       var1.encodeInt("labelKey", this.key);
  192.    }
  193.  
  194.    public void decode(Decoder var1) throws CodingException {
  195.       super.decode(var1);
  196.       this.label = (TextField)var1.decodeObject("label");
  197.       this.target = (Target)var1.decodeObject("target");
  198.       this.command = var1.decodeString("command");
  199.       this.key = var1.decodeInt("labelKey");
  200.    }
  201. }
  202.