home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / Button.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  21.7 KB  |  1,180 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. import netscape.util.InconsistencyException;
  9. import netscape.util.Vector;
  10.  
  11. public class Button extends View implements Target, DrawingSequenceOwner, FormElement {
  12.    Font _titleFont;
  13.    Color _titleColor;
  14.    Color _disabledTitleColor;
  15.    Color _raisedColor;
  16.    Color _loweredColor;
  17.    Image _image;
  18.    Image _altImage;
  19.    Border _raisedBorder;
  20.    Border _loweredBorder;
  21.    Sound _downSound;
  22.    Sound _upSound;
  23.    Timer _actionTimer;
  24.    Target _target;
  25.    String _title;
  26.    String _command;
  27.    String _altTitle;
  28.    int _type;
  29.    int _imagePosition;
  30.    int _repeatDelay;
  31.    boolean _state;
  32.    boolean _enabled;
  33.    boolean _bordered;
  34.    boolean _highlighted;
  35.    boolean _oldState;
  36.    boolean transparent;
  37.    private int _clickCount;
  38.    private boolean _performingAction;
  39.    static Vector _fieldDescription;
  40.    public static final int PUSH_TYPE = 0;
  41.    public static final int TOGGLE_TYPE = 1;
  42.    public static final int RADIO_TYPE = 2;
  43.    public static final int CONTINUOUS_TYPE = 3;
  44.    public static final int IMAGE_ON_LEFT = 0;
  45.    public static final int IMAGE_ON_RIGHT = 1;
  46.    public static final int IMAGE_ABOVE = 2;
  47.    public static final int IMAGE_BELOW = 3;
  48.    public static final int IMAGE_BENEATH = 4;
  49.    public static final String SEND_COMMAND = "sendCommand";
  50.    public static final String CLICK = "click";
  51.    public static final String SELECT_NEXT_RADIO_BUTTON = "selectNextRadioButton";
  52.    public static final String SELECT_PREVIOUS_RADIO_BUTTON = "selectPreviousRadioButton";
  53.    static final String TITLE_KEY = "title";
  54.    static final String ALT_TITLE_KEY = "altTitle";
  55.    static final String TITLE_FONT_KEY = "titleFont";
  56.    static final String TITLE_COLOR_KEY = "titleColor";
  57.    static final String DISABLED_TITLE_COLOR_KEY = "disabledTitleColor";
  58.    static final String RAISED_COLOR_KEY = "raisedColor";
  59.    static final String LOWERED_COLOR_KEY = "loweredColor";
  60.    static final String IMAGE_KEY = "image";
  61.    static final String ALT_IMAGE_KEY = "altImage";
  62.    static final String DOWN_SOUND_KEY = "downSound";
  63.    static final String UP_SOUND_KEY = "upSound";
  64.    static final String TARGET_KEY = "target";
  65.    static final String COMMAND_KEY = "command";
  66.    static final String TYPE_KEY = "type";
  67.    static final String IMAGE_POSITION_KEY = "imagePosition";
  68.    static final String REPEAT_DELAY_KEY = "repeatDelay";
  69.    static final String STATE_KEY = "state";
  70.    static final String ENABLED_KEY = "enabled";
  71.    static final String BORDERED_KEY = "bordered";
  72.    static final String TRANSPARENT_KEY = "transparent";
  73.    static final String RAISED_BORDER_KEY = "raisedBorder";
  74.    static final String LOWERED_BORDER_KEY = "loweredBorder";
  75.  
  76.    public static Button createPushButton(int var0, int var1, int var2, int var3) {
  77.       Button var4 = new Button(var0, var1, var2, var3);
  78.       var4.setType(0);
  79.       return var4;
  80.    }
  81.  
  82.    public static Button createCheckButton(int var0, int var1, int var2, int var3) {
  83.       Button var4 = new Button(var0, var1, var2, var3);
  84.       var4.setType(1);
  85.       var4.setTransparent(true);
  86.       var4.setImage(new CheckButtonImage(false));
  87.       var4.setAltImage(new CheckButtonImage(true));
  88.       var4.setImagePosition(0);
  89.       return var4;
  90.    }
  91.  
  92.    public static Button createRadioButton(int var0, int var1, int var2, int var3) {
  93.       Button var4 = new Button(var0, var1, var2, var3);
  94.       var4.setType(2);
  95.       var4.setImage(Bitmap.bitmapNamed("netscape/application/RadioButtonOff.gif"));
  96.       var4.setAltImage(Bitmap.bitmapNamed("netscape/application/RadioButtonOn.gif"));
  97.       var4.setImagePosition(0);
  98.       var4.setTransparent(true);
  99.       return var4;
  100.    }
  101.  
  102.    public Button() {
  103.       this(0, 0, 0, 0);
  104.    }
  105.  
  106.    public Button(Rect var1) {
  107.       this(var1.x, var1.y, var1.width, var1.height);
  108.    }
  109.  
  110.    public Button(int var1, int var2, int var3, int var4) {
  111.       super(var1, var2, var3, var4);
  112.       this._title = "";
  113.       this._altTitle = "";
  114.       this._repeatDelay = 75;
  115.       this._enabled = true;
  116.       this._bordered = true;
  117.       this.transparent = false;
  118.       this._titleColor = Color.black;
  119.       this._disabledTitleColor = Color.gray;
  120.       this._titleFont = Font.defaultFont();
  121.       this._raisedBorder = BezelBorder.raisedButtonBezel();
  122.       this._loweredBorder = BezelBorder.loweredButtonBezel();
  123.       this._raisedColor = Color.lightGray;
  124.       this._loweredColor = Color.lightGray;
  125.       this._setupKeyboard();
  126.    }
  127.  
  128.    public void setTitle(String var1) {
  129.       if (var1 == null) {
  130.          this._title = "";
  131.       } else {
  132.          this._title = var1;
  133.       }
  134.  
  135.       ((View)this).draw();
  136.    }
  137.  
  138.    public String title() {
  139.       return this._title;
  140.    }
  141.  
  142.    public void setAltTitle(String var1) {
  143.       if (var1 == null) {
  144.          this._altTitle = "";
  145.       } else {
  146.          this._altTitle = var1;
  147.       }
  148.  
  149.       ((View)this).setDirty(true);
  150.    }
  151.  
  152.    public String altTitle() {
  153.       return this._altTitle;
  154.    }
  155.  
  156.    public void setEnabled(boolean var1) {
  157.       if (var1 != this._enabled) {
  158.          this._enabled = var1;
  159.          ((View)this).setDirty(true);
  160.       }
  161.  
  162.    }
  163.  
  164.    public boolean isEnabled() {
  165.       return this._enabled;
  166.    }
  167.  
  168.    void _setState(boolean var1) {
  169.       if (var1 != this._state) {
  170.          this._state = var1;
  171.          ((View)this).draw();
  172.       }
  173.  
  174.    }
  175.  
  176.    void selectNextRadioButton(boolean var1) {
  177.       View var2 = ((View)this).superview();
  178.       if (var2 != null) {
  179.          Vector var4 = var2.subviews();
  180.          int var5 = var4.indexOfIdentical(this);
  181.          int var6 = var4.count();
  182.  
  183.          View var3;
  184.          do {
  185.             if (var1) {
  186.                ++var5;
  187.                if (var5 == var6) {
  188.                   var5 = 0;
  189.                }
  190.             } else {
  191.                --var5;
  192.                if (var5 < 0) {
  193.                   var5 = var6 - 1;
  194.                }
  195.             }
  196.  
  197.             var3 = (View)var4.elementAt(var5);
  198.             if (var3 instanceof Button && ((Button)var3).type() == 2) {
  199.                ((Button)var3).setState(true);
  200.                ((View)this).rootView().selectView(var3, true);
  201.                return;
  202.             }
  203.          } while(var3 != this);
  204.       }
  205.  
  206.    }
  207.  
  208.    Button _otherActive() {
  209.       if (((View)this).superview() == null) {
  210.          return null;
  211.       } else {
  212.          Vector var3 = ((View)this).superview().peersForSubview(this);
  213.          int var4 = var3.count();
  214.  
  215.          while(var4-- > 0) {
  216.             View var2 = (View)var3.elementAt(var4);
  217.             if (var2 instanceof Button && var2 != this) {
  218.                Button var1 = (Button)var2;
  219.                if (var1.type() == 2 && var1.isEnabled() && var1.state()) {
  220.                   return var1;
  221.                }
  222.             }
  223.          }
  224.  
  225.          return null;
  226.       }
  227.    }
  228.  
  229.    public void setState(boolean var1) {
  230.       ((View)this).rootView();
  231.       if (this._type == 2) {
  232.          if (var1 == this.state()) {
  233.             return;
  234.          }
  235.  
  236.          if (var1) {
  237.             Button var2 = this._otherActive();
  238.             if (var2 != null) {
  239.                var2._setState(false);
  240.             }
  241.          }
  242.       }
  243.  
  244.       this._setState(var1);
  245.    }
  246.  
  247.    public boolean state() {
  248.       return this._state;
  249.    }
  250.  
  251.    public void setTarget(Target var1) {
  252.       this._target = var1;
  253.    }
  254.  
  255.    public Target target() {
  256.       return this._target;
  257.    }
  258.  
  259.    public void setCommand(String var1) {
  260.       this._command = var1;
  261.    }
  262.  
  263.    public String command() {
  264.       return this._command;
  265.    }
  266.  
  267.    public Size imageAreaSize() {
  268.       Size var1;
  269.       if (this._image != null) {
  270.          var1 = new Size(this._image.width(), this._image.height());
  271.       } else {
  272.          var1 = new Size();
  273.       }
  274.  
  275.       if (this._altImage != null) {
  276.          if (this._altImage.width() > var1.width) {
  277.             var1.width = this._altImage.width();
  278.          }
  279.  
  280.          if (this._altImage.height() > var1.height) {
  281.             var1.height = this._altImage.height();
  282.          }
  283.       }
  284.  
  285.       return var1;
  286.    }
  287.  
  288.    Size minStringSize(String var1) {
  289.       int var5 = var1.indexOf(10);
  290.       if (var5 == -1) {
  291.          return this._titleFont.fontMetrics().stringSize(var1);
  292.       } else {
  293.          Size var2 = new Size(0, this._titleFont.fontMetrics().stringHeight());
  294.          int var4 = 1;
  295.  
  296.          String var3;
  297.          for(var3 = var1; var5 != -1; var5 = var3.indexOf(10)) {
  298.             int var6 = this._titleFont.fontMetrics().stringWidth(var3.substring(0, var5));
  299.             if (var6 > var2.width) {
  300.                var2.width = var6;
  301.             }
  302.  
  303.             ++var4;
  304.             var3 = var3.substring(var5 + 1);
  305.          }
  306.  
  307.          int var7 = this._titleFont.fontMetrics().stringWidth(var3);
  308.          if (var7 > var2.width) {
  309.             var2.width = var7;
  310.          }
  311.  
  312.          var2.height *= var4;
  313.          return var2;
  314.       }
  315.    }
  316.  
  317.    public Size minSize() {
  318.       Size var1 = null;
  319.       Size var2 = null;
  320.       boolean var4 = false;
  321.       if (super._minSize != null) {
  322.          return new Size(super._minSize);
  323.       } else {
  324.          if (this._title != null && this._title.length() > 0) {
  325.             var1 = this.minStringSize(this._title);
  326.             var4 = true;
  327.          }
  328.  
  329.          if (this._altTitle != null && this._altTitle.length() > 0) {
  330.             var2 = this.minStringSize(this._altTitle);
  331.             var4 = true;
  332.          }
  333.  
  334.          if (var1 == null) {
  335.             var1 = var2;
  336.          } else if (var2 != null) {
  337.             if (var1.width < var2.width) {
  338.                var1.width = var2.width;
  339.             }
  340.  
  341.             if (var1.height < var2.height) {
  342.                var1.height = var2.height;
  343.             }
  344.          }
  345.  
  346.          if (var1 != null) {
  347.             if (var1.width > 0) {
  348.                var1.sizeBy(3, 0);
  349.             }
  350.          } else {
  351.             var1 = new Size();
  352.          }
  353.  
  354.          Size var3 = this.imageAreaSize();
  355.          boolean var5 = var3.width > 0 || var3.height > 0;
  356.          if (var5) {
  357.             if (this._imagePosition != 2 && this._imagePosition != 3) {
  358.                if (var4 && this._imagePosition != 4) {
  359.                   var1.sizeBy(var3.width + 2, 0);
  360.                   if (var3.height > var1.height) {
  361.                      var1.height = var3.height;
  362.                   }
  363.                } else {
  364.                   if (var3.width > var1.width) {
  365.                      var1.width = var3.width;
  366.                   }
  367.  
  368.                   if (var3.height > var1.height) {
  369.                      var1.height = var3.height;
  370.                   }
  371.                }
  372.             } else {
  373.                if (var1.width < var3.width) {
  374.                   var1.width = var3.width;
  375.                }
  376.  
  377.                var1.height += var3.height + 2;
  378.             }
  379.          }
  380.  
  381.          if (this._bordered) {
  382.             var1.sizeBy(3, 3);
  383.          }
  384.  
  385.          return var1;
  386.       }
  387.    }
  388.  
  389.    public void setFont(Font var1) {
  390.       if (var1 == null) {
  391.          this._titleFont = Font.defaultFont();
  392.       } else {
  393.          this._titleFont = var1;
  394.       }
  395.    }
  396.  
  397.    public Font font() {
  398.       return this._titleFont;
  399.    }
  400.  
  401.    public void setTitleColor(Color var1) {
  402.       if (var1 == null) {
  403.          this._titleColor = Color.black;
  404.       } else {
  405.          this._titleColor = var1;
  406.       }
  407.    }
  408.  
  409.    public Color titleColor() {
  410.       return this._titleColor;
  411.    }
  412.  
  413.    public void setDisabledTitleColor(Color var1) {
  414.       if (var1 == null) {
  415.          this._disabledTitleColor = Color.gray;
  416.       } else {
  417.          this._disabledTitleColor = var1;
  418.       }
  419.    }
  420.  
  421.    public Color disabledTitleColor() {
  422.       return this._disabledTitleColor;
  423.    }
  424.  
  425.    public void setRaisedColor(Color var1) {
  426.       if (var1 == null) {
  427.          this._raisedColor = Color.lightGray;
  428.       } else {
  429.          this._raisedColor = var1;
  430.       }
  431.    }
  432.  
  433.    public Color raisedColor() {
  434.       return this._raisedColor;
  435.    }
  436.  
  437.    public void setLoweredColor(Color var1) {
  438.       if (var1 == null) {
  439.          this._loweredColor = Color.lightGray;
  440.       } else {
  441.          this._loweredColor = var1;
  442.       }
  443.    }
  444.  
  445.    public Color loweredColor() {
  446.       return this._loweredColor;
  447.    }
  448.  
  449.    public void setImage(Image var1) {
  450.       this._image = var1;
  451.       if (var1 instanceof DrawingSequence) {
  452.          DrawingSequence var2 = (DrawingSequence)var1;
  453.          var2.setOwner(this);
  454.       }
  455.  
  456.    }
  457.  
  458.    public Image image() {
  459.       return this._image;
  460.    }
  461.  
  462.    public void setAltImage(Image var1) {
  463.       this._altImage = var1;
  464.       if (var1 instanceof DrawingSequence) {
  465.          DrawingSequence var2 = (DrawingSequence)var1;
  466.          var2.setOwner(this);
  467.       }
  468.  
  469.    }
  470.  
  471.    public Image altImage() {
  472.       return this._altImage;
  473.    }
  474.  
  475.    public void setRaisedBorder(Border var1) {
  476.       this._raisedBorder = var1;
  477.    }
  478.  
  479.    public Border raisedBorder() {
  480.       return this._raisedBorder;
  481.    }
  482.  
  483.    public void setLoweredBorder(Border var1) {
  484.       this._loweredBorder = var1;
  485.    }
  486.  
  487.    public Border loweredBorder() {
  488.       return this._loweredBorder;
  489.    }
  490.  
  491.    public void setMouseDownSound(Sound var1) {
  492.       this._downSound = var1;
  493.       if (this._type == 3 && this._downSound != null) {
  494.          this._downSound.setLoops(true);
  495.       }
  496.  
  497.    }
  498.  
  499.    public Sound mouseDownSound() {
  500.       return this._downSound;
  501.    }
  502.  
  503.    public void setMouseUpSound(Sound var1) {
  504.       this._upSound = var1;
  505.    }
  506.  
  507.    public Sound mouseUpSound() {
  508.       return this._upSound;
  509.    }
  510.  
  511.    public void setBordered(boolean var1) {
  512.       this._bordered = var1;
  513.       if (this._bordered) {
  514.          this.setTransparent(false);
  515.       }
  516.  
  517.    }
  518.  
  519.    public boolean isBordered() {
  520.       return this._bordered;
  521.    }
  522.  
  523.    public void setType(int var1) {
  524.       if (var1 >= 0 && var1 <= 3) {
  525.          this._type = var1;
  526.          this.setState(false);
  527.          if (this._type == 3) {
  528.             if (this._downSound != null) {
  529.                this._downSound.setLoops(true);
  530.             }
  531.          } else if (this._downSound != null) {
  532.             this._downSound.setLoops(false);
  533.          }
  534.  
  535.          this._setupKeyboard();
  536.       } else {
  537.          throw new InconsistencyException("Invalid Button type: " + var1);
  538.       }
  539.    }
  540.  
  541.    public int type() {
  542.       return this._type;
  543.    }
  544.  
  545.    public void setRepeatDelay(int var1) {
  546.       if (var1 > 0) {
  547.          this._repeatDelay = var1;
  548.          if (this._actionTimer != null) {
  549.             this._actionTimer.setDelay(this._repeatDelay);
  550.          }
  551.       }
  552.  
  553.    }
  554.  
  555.    public int repeatDelay() {
  556.       return this._repeatDelay;
  557.    }
  558.  
  559.    public void setImagePosition(int var1) {
  560.       if (var1 >= 0 && var1 <= 4) {
  561.          this._imagePosition = var1;
  562.       }
  563.    }
  564.  
  565.    public int imagePosition() {
  566.       return this._imagePosition;
  567.    }
  568.  
  569.    public void setTransparent(boolean var1) {
  570.       this.transparent = var1;
  571.       if (this.transparent) {
  572.          this._bordered = false;
  573.       }
  574.  
  575.    }
  576.  
  577.    public boolean isTransparent() {
  578.       return this.transparent;
  579.    }
  580.  
  581.    protected void ancestorWasAddedToViewHierarchy(View var1) {
  582.       super.ancestorWasAddedToViewHierarchy(var1);
  583.       if (this._type == 2 && this._state) {
  584.          this._state = false;
  585.          this.setState(true);
  586.       }
  587.  
  588.    }
  589.  
  590.    public void drawViewTitleInRect(Graphics var1, String var2, Font var3, Rect var4, int var5) {
  591.       if (var2 != null && var2.length() != 0) {
  592.          if (this._enabled) {
  593.             var1.setColor(this._titleColor);
  594.          } else {
  595.             var1.setColor(this._disabledTitleColor);
  596.          }
  597.  
  598.          var1.setFont(var3);
  599.          int var8 = var2.indexOf(10);
  600.          if (var8 == -1) {
  601.             var1.drawStringInRect(var2, var4, var5);
  602.          } else {
  603.             Rect var6 = new Rect(var4);
  604.             var6.height = this._titleFont.fontMetrics().stringHeight();
  605.  
  606.             String var7;
  607.             for(var7 = var2; var8 != -1; var8 = var7.indexOf(10)) {
  608.                var1.drawStringInRect(var7.substring(0, var8), var6, var5);
  609.                var6.y += var6.height;
  610.                var7 = var7.substring(var8 + 1);
  611.             }
  612.  
  613.             var1.drawStringInRect(var7, var6, var5);
  614.          }
  615.       }
  616.    }
  617.  
  618.    public void drawViewInterior(Graphics var1, String var2, Image var3, Rect var4) {
  619.       Size var5 = this.imageAreaSize();
  620.       if (this._imagePosition == 0) {
  621.          int var9;
  622.          if (var2 != null && var2.length() != 0) {
  623.             var9 = var4.x + 1;
  624.          } else {
  625.             var9 = var4.x + 1 + (var4.width - var5.width - 2) / 2;
  626.          }
  627.  
  628.          if (var3 != null) {
  629.             var3.drawAt(var1, var9, var4.y + (var4.height - var5.height) / 2);
  630.          }
  631.  
  632.          byte var10;
  633.          if (var5.width > 0) {
  634.             var4.moveBy(var5.width + 3, 0);
  635.             var4.sizeBy(-(var5.width + 4), 0);
  636.             var10 = 0;
  637.          } else {
  638.             var4.moveBy(1, 0);
  639.             var4.sizeBy(-2, 0);
  640.             var10 = 1;
  641.          }
  642.  
  643.          this.drawViewTitleInRect(var1, var2, this._titleFont, var4, var10);
  644.       } else if (this._imagePosition == 2) {
  645.          if (var3 != null) {
  646.             var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.y + 2);
  647.          }
  648.  
  649.          int var7 = this._titleFont.fontMetrics().charHeight();
  650.          var4.setBounds(var4.x + 1, var4.maxY() - var7 - 1, var4.width - 2, var7);
  651.          this.drawViewTitleInRect(var1, var2, this._titleFont, var4, 1);
  652.       } else if (this._imagePosition == 3) {
  653.          if (var3 != null) {
  654.             var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.maxY() - var5.height - 2);
  655.          }
  656.  
  657.          var4.setBounds(var4.x + 1, var4.y + 1, var4.width - 2, this._titleFont.fontMetrics().charHeight());
  658.          this.drawViewTitleInRect(var1, var2, this._titleFont, var4, 1);
  659.       } else {
  660.          byte var8;
  661.          if (var3 != null && this._imagePosition == 4) {
  662.             var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.y + (var4.height - var5.height) / 2);
  663.             var8 = 1;
  664.          } else if (var5.width == 0) {
  665.             var4.moveBy(2, 0);
  666.             var8 = 1;
  667.          } else {
  668.             var8 = 0;
  669.          }
  670.  
  671.          int var6;
  672.          if (var2 != null && var2.length() != 0) {
  673.             var6 = var4.maxX() - var5.width - 1;
  674.          } else {
  675.             var6 = var4.x + 1 + (var4.width - var5.width - 2) / 2;
  676.          }
  677.  
  678.          if (var3 != null && this._imagePosition == 1) {
  679.             var3.drawAt(var1, var6, var4.y + (var4.height - var5.height) / 2);
  680.          }
  681.  
  682.          this.drawViewTitleInRect(var1, var2, this._titleFont, var4, var8);
  683.       }
  684.    }
  685.  
  686.    public void drawViewBackground(Graphics var1, Rect var2, boolean var3) {
  687.       if (this._bordered) {
  688.          var2.sizeBy(-3, -3);
  689.          if (var3) {
  690.             this._loweredBorder.drawInRect(var1, 0, 0, super.bounds.width, super.bounds.height);
  691.             var1.setColor(this._loweredColor);
  692.             var1.fillRect(this._loweredBorder.leftMargin(), this._loweredBorder.topMargin(), super.bounds.width - this._loweredBorder.widthMargin(), super.bounds.height - this._loweredBorder.heightMargin());
  693.             var2.moveBy(2, 2);
  694.          } else {
  695.             this._raisedBorder.drawInRect(var1, 0, 0, super.bounds.width, super.bounds.height);
  696.             var1.setColor(this._raisedColor);
  697.             var1.fillRect(this._raisedBorder.leftMargin(), this._raisedBorder.topMargin(), super.bounds.width - this._raisedBorder.widthMargin(), super.bounds.height - this._raisedBorder.heightMargin());
  698.             var2.moveBy(1, 1);
  699.          }
  700.       } else {
  701.          if (!this.isTransparent()) {
  702.             if (var3) {
  703.                var1.setColor(this._loweredColor);
  704.             } else {
  705.                var1.setColor(this._raisedColor);
  706.             }
  707.  
  708.             var1.fillRect(0, 0, super.bounds.width, super.bounds.height);
  709.          }
  710.  
  711.       }
  712.    }
  713.  
  714.    public void drawView(Graphics var1) {
  715.       Image var2 = null;
  716.       boolean var6 = this._highlighted ? !this._state : this._state;
  717.       Rect var5 = Rect.newRect(0, 0, super.bounds.width, super.bounds.height);
  718.       this.drawViewBackground(var1, var5, var6);
  719.       if (this._image instanceof DrawingSequence) {
  720.          DrawingSequence var3 = (DrawingSequence)this._image;
  721.          if (var3.isAnimating()) {
  722.             var2 = this._image;
  723.          } else if (this._altImage instanceof DrawingSequence) {
  724.             var2 = this._altImage;
  725.          }
  726.       } else if (this._altImage instanceof DrawingSequence) {
  727.          DrawingSequence var7 = (DrawingSequence)this._altImage;
  728.          if (var7.isAnimating()) {
  729.             var2 = this._altImage;
  730.          }
  731.       }
  732.  
  733.       if (var2 == null) {
  734.          var2 = this._image;
  735.          if (var6 && this._altImage != null) {
  736.             var2 = this._altImage;
  737.          }
  738.       }
  739.  
  740.       String var4;
  741.       if (var6 && this._altTitle != null && this._altTitle.length() != 0) {
  742.          var4 = this._altTitle;
  743.       } else {
  744.          var4 = this._title;
  745.       }
  746.  
  747.       if (var2 != null || var4 != null && var4.length() != 0) {
  748.          this.drawViewInterior(var1, var4, var2, var5);
  749.          Rect.returnRect(var5);
  750.       } else {
  751.          Rect.returnRect(var5);
  752.       }
  753.    }
  754.  
  755.    Button _activeForPoint(int var1, int var2) {
  756.       if (((View)this).superview() == null) {
  757.          return null;
  758.       } else {
  759.          Vector var6 = ((View)this).superview().peersForSubview(this);
  760.          Point var5 = Point.newPoint();
  761.          int var7 = var6.count();
  762.  
  763.          while(var7-- > 0) {
  764.             View var4 = (View)var6.elementAt(var7);
  765.             if (var4 instanceof Button && var4 != this) {
  766.                Button var3 = (Button)var4;
  767.                if (var3.type() == 2) {
  768.                   ((View)this).convertToView(var4, var1, var2, var5);
  769.                   if (((View)var3).containsPoint(var5.x, var5.y)) {
  770.                      Point.returnPoint(var5);
  771.                      return var3;
  772.                   }
  773.                }
  774.             }
  775.          }
  776.  
  777.          Point.returnPoint(var5);
  778.          return null;
  779.       }
  780.    }
  781.  
  782.    public boolean mouseDown(MouseEvent var1) {
  783.       if (!this._enabled) {
  784.          return false;
  785.       } else if (!((View)this).containsPoint(var1.x, var1.y)) {
  786.          return false;
  787.       } else {
  788.          if (this._type == 2) {
  789.             Button var2 = this._otherActive();
  790.             if (var2 != null) {
  791.                var2._setState(false);
  792.             }
  793.  
  794.             this._oldState = this._state;
  795.             this._state = false;
  796.          }
  797.  
  798.          this._clickCount = var1.clickCount;
  799.          if (this._type != 1 && this._type != 2) {
  800.             this.setState(true);
  801.          } else {
  802.             this.setHighlighted(true);
  803.          }
  804.  
  805.          if (this._downSound != null) {
  806.             this._downSound.play();
  807.          }
  808.  
  809.          if (this._altImage instanceof DrawingSequence) {
  810.             DrawingSequence var3 = (DrawingSequence)this._altImage;
  811.             var3.start();
  812.          }
  813.  
  814.          if (this._type == 3 && this._actionTimer == null) {
  815.             this.sendCommand();
  816.             this._actionTimer = new Timer(this, "sendCommand", this._repeatDelay);
  817.             this._actionTimer.setInitialDelay(300);
  818.             this._actionTimer.start();
  819.          }
  820.  
  821.          return true;
  822.       }
  823.    }
  824.  
  825.    void _buttonDown() {
  826.       if (this._image instanceof DrawingSequence) {
  827.          DrawingSequence var1 = (DrawingSequence)this._image;
  828.          if (var1.doesLoop()) {
  829.             var1.stop();
  830.          } else {
  831.             while(var1.isAnimating()) {
  832.                var1.stop();
  833.             }
  834.          }
  835.       }
  836.  
  837.       if (this._altImage instanceof DrawingSequence) {
  838.          DrawingSequence var2 = (DrawingSequence)this._altImage;
  839.          var2.start();
  840.       }
  841.  
  842.       if (this._type == 3 && this._upSound != null) {
  843.          this._upSound.stop();
  844.       }
  845.  
  846.       if (this._downSound != null) {
  847.          this._downSound.play();
  848.       }
  849.  
  850.    }
  851.  
  852.    void _buttonUp() {
  853.       if (this._altImage instanceof DrawingSequence) {
  854.          DrawingSequence var1 = (DrawingSequence)this._altImage;
  855.          if (var1.doesLoop()) {
  856.             var1.stop();
  857.          } else {
  858.             while(var1.isAnimating()) {
  859.                var1.stop();
  860.             }
  861.          }
  862.       }
  863.  
  864.       if (this._image instanceof DrawingSequence) {
  865.          DrawingSequence var2 = (DrawingSequence)this._image;
  866.          var2.start();
  867.       }
  868.  
  869.       if (this._type == 3 && this._downSound != null) {
  870.          this._downSound.stop();
  871.       }
  872.  
  873.       if (this._upSound != null) {
  874.          this._upSound.play();
  875.       }
  876.  
  877.    }
  878.  
  879.    public void mouseDragged(MouseEvent var1) {
  880.       if (this._enabled) {
  881.          if (this._type == 2 && !((View)this).containsPoint(var1.x, var1.y)) {
  882.             Button var2 = this._activeForPoint(var1.x, var1.y);
  883.             if (var2 != null) {
  884.                this.setHighlighted(false);
  885.                var2.setHighlighted(true);
  886.                ((View)this).rootView().setMouseView(var2);
  887.             }
  888.  
  889.          } else {
  890.             if (((View)this).containsPoint(var1.x, var1.y)) {
  891.                if (!this._state && !this._highlighted) {
  892.                   this._buttonDown();
  893.                   if (this._type != 1 && this._type != 2) {
  894.                      this.setState(true);
  895.                   } else {
  896.                      this.setHighlighted(true);
  897.                   }
  898.  
  899.                   if (this._type == 3) {
  900.                      this.sendCommand();
  901.                      this._actionTimer = new Timer(this, "sendCommand", 100);
  902.                      this._actionTimer.start();
  903.                      return;
  904.                   }
  905.                }
  906.             } else if (this._state || this._highlighted) {
  907.                this._buttonUp();
  908.                if (this._type == 3 && this._actionTimer != null) {
  909.                   this._actionTimer.stop();
  910.                   this._actionTimer = null;
  911.                }
  912.  
  913.                if (this._type == 1 || this._type == 2) {
  914.                   this.setHighlighted(false);
  915.                   return;
  916.                }
  917.  
  918.                this.setState(false);
  919.             }
  920.  
  921.          }
  922.       }
  923.    }
  924.  
  925.    public void mouseUp(MouseEvent var1) {
  926.       if (this._enabled) {
  927.          if (this._type == 2) {
  928.             if (this._highlighted) {
  929.                this._highlighted = false;
  930.                this.setState(true);
  931.             }
  932.  
  933.             if (this._state != this._oldState) {
  934.                this.sendCommand();
  935.             }
  936.  
  937.             this._oldState = false;
  938.             if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
  939.                ((View)this).rootView().selectView(this, true);
  940.             }
  941.  
  942.          } else {
  943.             if (this._actionTimer != null) {
  944.                this._actionTimer.stop();
  945.                this._actionTimer = null;
  946.             }
  947.  
  948.             boolean var2 = ((View)this).containsPoint(var1.x, var1.y);
  949.             if (var2) {
  950.                this._buttonUp();
  951.             }
  952.  
  953.             if (this._type == 3) {
  954.                this._state = false;
  955.                if (var2) {
  956.                   ((View)this).setDirty(true);
  957.                }
  958.  
  959.                if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
  960.                   ((View)this).rootView().selectView(this, true);
  961.                }
  962.  
  963.             } else {
  964.                if (this._type == 1) {
  965.                   if (var2) {
  966.                      this._highlighted = false;
  967.                      this._state = !this._state;
  968.                   } else {
  969.                      this._highlighted = false;
  970.                   }
  971.  
  972.                   if (var2) {
  973.                      ((View)this).setDirty(true);
  974.                   }
  975.  
  976.                   if (var2) {
  977.                      this.sendCommand();
  978.                   }
  979.                } else {
  980.                   if (this._type != 3 && var2) {
  981.                      this.sendCommand();
  982.                   }
  983.  
  984.                   this._state = false;
  985.                   if (var2) {
  986.                      ((View)this).setDirty(true);
  987.                   }
  988.                }
  989.  
  990.                if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
  991.                   ((View)this).rootView().selectView(this, true);
  992.                }
  993.  
  994.             }
  995.          }
  996.       }
  997.    }
  998.  
  999.    public int clickCount() {
  1000.       return this._performingAction ? this._clickCount : 0;
  1001.    }
  1002.  
  1003.    public void click() {
  1004.       if (this._enabled) {
  1005.          if (this._type != 2 || !this._state) {
  1006.             if (this._type != 1 && this._type != 2) {
  1007.                this.setState(true);
  1008.                ((View)this).application().syncGraphics();
  1009.  
  1010.                try {
  1011.                   Thread.sleep(200L);
  1012.                } catch (InterruptedException var1) {
  1013.                }
  1014.  
  1015.                this._clickCount = 1;
  1016.                this.sendCommand();
  1017.                this.setState(false);
  1018.             } else {
  1019.                this.setState(!this._state);
  1020.                ((View)this).application().syncGraphics();
  1021.                this.sendCommand();
  1022.             }
  1023.          }
  1024.       }
  1025.    }
  1026.  
  1027.    public void performCommand(String var1, Object var2) {
  1028.       int var3 = this.type();
  1029.       if ("sendCommand".equals(var1)) {
  1030.          this.sendCommand();
  1031.       } else if ("click".equals(var1)) {
  1032.          this.click();
  1033.       } else if (var3 == 2 && "selectPreviousRadioButton".equals(var1)) {
  1034.          this.selectNextRadioButton(false);
  1035.       } else if (var3 == 2 && "selectNextRadioButton".equals(var1)) {
  1036.          this.selectNextRadioButton(true);
  1037.       } else {
  1038.          throw new NoSuchMethodError("unknown command: " + var1);
  1039.       }
  1040.    }
  1041.  
  1042.    public void drawingSequenceFrameChanged(DrawingSequence var1) {
  1043.       ((View)this).setDirty(true);
  1044.    }
  1045.  
  1046.    public void drawingSequenceCompleted(DrawingSequence var1) {
  1047.    }
  1048.  
  1049.    public void sendCommand() {
  1050.       this._performingAction = true;
  1051.       if (this._target != null) {
  1052.          this._target.performCommand(this._command, this);
  1053.       }
  1054.  
  1055.       this._performingAction = false;
  1056.    }
  1057.  
  1058.    protected void setHighlighted(boolean var1) {
  1059.       if (this._highlighted != var1) {
  1060.          this._highlighted = var1;
  1061.          ((View)this).setDirty(true);
  1062.       }
  1063.  
  1064.    }
  1065.  
  1066.    protected boolean isHighlighted() {
  1067.       return this._highlighted;
  1068.    }
  1069.  
  1070.    public boolean canBecomeSelectedView() {
  1071.       if (this.isEnabled() && ((View)this).hasKeyboardBindings()) {
  1072.          if (this.type() == 2) {
  1073.             return this.state();
  1074.          } else {
  1075.             return true;
  1076.          }
  1077.       } else {
  1078.          return false;
  1079.       }
  1080.    }
  1081.  
  1082.    public void describeClassInfo(ClassInfo var1) {
  1083.       super.describeClassInfo(var1);
  1084.       var1.addClass("netscape.application.Button", 2);
  1085.       var1.addField("title", (byte)16);
  1086.       var1.addField("altTitle", (byte)16);
  1087.       var1.addField("titleFont", (byte)18);
  1088.       var1.addField("titleColor", (byte)18);
  1089.       var1.addField("disabledTitleColor", (byte)18);
  1090.       var1.addField("raisedColor", (byte)18);
  1091.       var1.addField("loweredColor", (byte)18);
  1092.       var1.addField("image", (byte)18);
  1093.       var1.addField("altImage", (byte)18);
  1094.       var1.addField("downSound", (byte)18);
  1095.       var1.addField("upSound", (byte)18);
  1096.       var1.addField("target", (byte)18);
  1097.       var1.addField("command", (byte)16);
  1098.       var1.addField("type", (byte)8);
  1099.       var1.addField("imagePosition", (byte)8);
  1100.       var1.addField("repeatDelay", (byte)8);
  1101.       var1.addField("state", (byte)0);
  1102.       var1.addField("enabled", (byte)0);
  1103.       var1.addField("bordered", (byte)0);
  1104.       var1.addField("transparent", (byte)0);
  1105.       var1.addField("raisedBorder", (byte)18);
  1106.       var1.addField("loweredBorder", (byte)18);
  1107.    }
  1108.  
  1109.    public void encode(Encoder var1) throws CodingException {
  1110.       super.encode(var1);
  1111.       var1.encodeString("title", this._title);
  1112.       var1.encodeString("altTitle", this._altTitle);
  1113.       var1.encodeObject("titleFont", this._titleFont);
  1114.       var1.encodeObject("titleColor", this._titleColor);
  1115.       var1.encodeObject("disabledTitleColor", this._disabledTitleColor);
  1116.       var1.encodeObject("raisedColor", this._raisedColor);
  1117.       var1.encodeObject("loweredColor", this._loweredColor);
  1118.       var1.encodeObject("image", this._image);
  1119.       var1.encodeObject("altImage", this._altImage);
  1120.       var1.encodeObject("target", (Codable)this._target);
  1121.       var1.encodeString("command", this._command);
  1122.       var1.encodeInt("type", this._type);
  1123.       var1.encodeInt("imagePosition", this._imagePosition);
  1124.       var1.encodeInt("repeatDelay", this._repeatDelay);
  1125.       var1.encodeBoolean("state", this._state);
  1126.       var1.encodeBoolean("enabled", this._enabled);
  1127.       var1.encodeBoolean("bordered", this._bordered);
  1128.       var1.encodeBoolean("transparent", this.transparent);
  1129.       var1.encodeObject("raisedBorder", this._raisedBorder);
  1130.       var1.encodeObject("loweredBorder", this._loweredBorder);
  1131.    }
  1132.  
  1133.    public void decode(Decoder var1) throws CodingException {
  1134.       super.decode(var1);
  1135.       this._title = var1.decodeString("title");
  1136.       this._altTitle = var1.decodeString("altTitle");
  1137.       this._titleFont = (Font)var1.decodeObject("titleFont");
  1138.       this._titleColor = (Color)var1.decodeObject("titleColor");
  1139.       this._disabledTitleColor = (Color)var1.decodeObject("disabledTitleColor");
  1140.       this._raisedColor = (Color)var1.decodeObject("raisedColor");
  1141.       this._loweredColor = (Color)var1.decodeObject("loweredColor");
  1142.       this._image = (Image)var1.decodeObject("image");
  1143.       this._altImage = (Image)var1.decodeObject("altImage");
  1144.       this._target = (Target)var1.decodeObject("target");
  1145.       this._command = var1.decodeString("command");
  1146.       this._type = var1.decodeInt("type");
  1147.       this._imagePosition = var1.decodeInt("imagePosition");
  1148.       this._repeatDelay = var1.decodeInt("repeatDelay");
  1149.       this._state = var1.decodeBoolean("state");
  1150.       this._enabled = var1.decodeBoolean("enabled");
  1151.       this._bordered = var1.decodeBoolean("bordered");
  1152.       this.transparent = var1.decodeBoolean("transparent");
  1153.       if (var1.versionForClassName("netscape.application.Button") > 1) {
  1154.          this._raisedBorder = (Border)var1.decodeObject("raisedBorder");
  1155.          this._loweredBorder = (Border)var1.decodeObject("loweredBorder");
  1156.       }
  1157.  
  1158.    }
  1159.  
  1160.    void _setupKeyboard() {
  1161.       ((View)this).removeAllCommandsForKeys();
  1162.       if (this.type() == 2) {
  1163.          ((View)this).setCommandForKey("selectNextRadioButton", 1007, 0);
  1164.          ((View)this).setCommandForKey("selectNextRadioButton", 1005, 0);
  1165.          ((View)this).setCommandForKey("selectPreviousRadioButton", 1006, 0);
  1166.          ((View)this).setCommandForKey("selectPreviousRadioButton", 1004, 0);
  1167.       } else {
  1168.          ((View)this).setCommandForKey("click", 10, 0);
  1169.       }
  1170.    }
  1171.  
  1172.    public String formElementText() {
  1173.       if (this._type == 1) {
  1174.          return this._state ? "true" : "false";
  1175.       } else {
  1176.          return this.title();
  1177.       }
  1178.    }
  1179. }
  1180.