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;
- import netscape.util.InconsistencyException;
- import netscape.util.Vector;
-
- public class Button extends View implements Target, DrawingSequenceOwner, FormElement {
- Font _titleFont;
- Color _titleColor;
- Color _disabledTitleColor;
- Color _raisedColor;
- Color _loweredColor;
- Image _image;
- Image _altImage;
- Border _raisedBorder;
- Border _loweredBorder;
- Sound _downSound;
- Sound _upSound;
- Timer _actionTimer;
- Target _target;
- String _title;
- String _command;
- String _altTitle;
- int _type;
- int _imagePosition;
- int _repeatDelay;
- boolean _state;
- boolean _enabled;
- boolean _bordered;
- boolean _highlighted;
- boolean _oldState;
- boolean transparent;
- private int _clickCount;
- private boolean _performingAction;
- static Vector _fieldDescription;
- public static final int PUSH_TYPE = 0;
- public static final int TOGGLE_TYPE = 1;
- public static final int RADIO_TYPE = 2;
- public static final int CONTINUOUS_TYPE = 3;
- public static final int IMAGE_ON_LEFT = 0;
- public static final int IMAGE_ON_RIGHT = 1;
- public static final int IMAGE_ABOVE = 2;
- public static final int IMAGE_BELOW = 3;
- public static final int IMAGE_BENEATH = 4;
- public static final String SEND_COMMAND = "sendCommand";
- public static final String CLICK = "click";
- public static final String SELECT_NEXT_RADIO_BUTTON = "selectNextRadioButton";
- public static final String SELECT_PREVIOUS_RADIO_BUTTON = "selectPreviousRadioButton";
- static final String TITLE_KEY = "title";
- static final String ALT_TITLE_KEY = "altTitle";
- static final String TITLE_FONT_KEY = "titleFont";
- static final String TITLE_COLOR_KEY = "titleColor";
- static final String DISABLED_TITLE_COLOR_KEY = "disabledTitleColor";
- static final String RAISED_COLOR_KEY = "raisedColor";
- static final String LOWERED_COLOR_KEY = "loweredColor";
- static final String IMAGE_KEY = "image";
- static final String ALT_IMAGE_KEY = "altImage";
- static final String DOWN_SOUND_KEY = "downSound";
- static final String UP_SOUND_KEY = "upSound";
- static final String TARGET_KEY = "target";
- static final String COMMAND_KEY = "command";
- static final String TYPE_KEY = "type";
- static final String IMAGE_POSITION_KEY = "imagePosition";
- static final String REPEAT_DELAY_KEY = "repeatDelay";
- static final String STATE_KEY = "state";
- static final String ENABLED_KEY = "enabled";
- static final String BORDERED_KEY = "bordered";
- static final String TRANSPARENT_KEY = "transparent";
- static final String RAISED_BORDER_KEY = "raisedBorder";
- static final String LOWERED_BORDER_KEY = "loweredBorder";
-
- public static Button createPushButton(int var0, int var1, int var2, int var3) {
- Button var4 = new Button(var0, var1, var2, var3);
- var4.setType(0);
- return var4;
- }
-
- public static Button createCheckButton(int var0, int var1, int var2, int var3) {
- Button var4 = new Button(var0, var1, var2, var3);
- var4.setType(1);
- var4.setTransparent(true);
- var4.setImage(new CheckButtonImage(false));
- var4.setAltImage(new CheckButtonImage(true));
- var4.setImagePosition(0);
- return var4;
- }
-
- public static Button createRadioButton(int var0, int var1, int var2, int var3) {
- Button var4 = new Button(var0, var1, var2, var3);
- var4.setType(2);
- var4.setImage(Bitmap.bitmapNamed("netscape/application/RadioButtonOff.gif"));
- var4.setAltImage(Bitmap.bitmapNamed("netscape/application/RadioButtonOn.gif"));
- var4.setImagePosition(0);
- var4.setTransparent(true);
- return var4;
- }
-
- public Button() {
- this(0, 0, 0, 0);
- }
-
- public Button(Rect var1) {
- this(var1.x, var1.y, var1.width, var1.height);
- }
-
- public Button(int var1, int var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this._title = "";
- this._altTitle = "";
- this._repeatDelay = 75;
- this._enabled = true;
- this._bordered = true;
- this.transparent = false;
- this._titleColor = Color.black;
- this._disabledTitleColor = Color.gray;
- this._titleFont = Font.defaultFont();
- this._raisedBorder = BezelBorder.raisedButtonBezel();
- this._loweredBorder = BezelBorder.loweredButtonBezel();
- this._raisedColor = Color.lightGray;
- this._loweredColor = Color.lightGray;
- this._setupKeyboard();
- }
-
- public void setTitle(String var1) {
- if (var1 == null) {
- this._title = "";
- } else {
- this._title = var1;
- }
-
- ((View)this).draw();
- }
-
- public String title() {
- return this._title;
- }
-
- public void setAltTitle(String var1) {
- if (var1 == null) {
- this._altTitle = "";
- } else {
- this._altTitle = var1;
- }
-
- ((View)this).setDirty(true);
- }
-
- public String altTitle() {
- return this._altTitle;
- }
-
- public void setEnabled(boolean var1) {
- if (var1 != this._enabled) {
- this._enabled = var1;
- ((View)this).setDirty(true);
- }
-
- }
-
- public boolean isEnabled() {
- return this._enabled;
- }
-
- void _setState(boolean var1) {
- if (var1 != this._state) {
- this._state = var1;
- ((View)this).draw();
- }
-
- }
-
- void selectNextRadioButton(boolean var1) {
- View var2 = ((View)this).superview();
- if (var2 != null) {
- Vector var4 = var2.subviews();
- int var5 = var4.indexOfIdentical(this);
- int var6 = var4.count();
-
- View var3;
- do {
- if (var1) {
- ++var5;
- if (var5 == var6) {
- var5 = 0;
- }
- } else {
- --var5;
- if (var5 < 0) {
- var5 = var6 - 1;
- }
- }
-
- var3 = (View)var4.elementAt(var5);
- if (var3 instanceof Button && ((Button)var3).type() == 2) {
- ((Button)var3).setState(true);
- ((View)this).rootView().selectView(var3, true);
- return;
- }
- } while(var3 != this);
- }
-
- }
-
- Button _otherActive() {
- if (((View)this).superview() == null) {
- return null;
- } else {
- Vector var3 = ((View)this).superview().peersForSubview(this);
- int var4 = var3.count();
-
- while(var4-- > 0) {
- View var2 = (View)var3.elementAt(var4);
- if (var2 instanceof Button && var2 != this) {
- Button var1 = (Button)var2;
- if (var1.type() == 2 && var1.isEnabled() && var1.state()) {
- return var1;
- }
- }
- }
-
- return null;
- }
- }
-
- public void setState(boolean var1) {
- ((View)this).rootView();
- if (this._type == 2) {
- if (var1 == this.state()) {
- return;
- }
-
- if (var1) {
- Button var2 = this._otherActive();
- if (var2 != null) {
- var2._setState(false);
- }
- }
- }
-
- this._setState(var1);
- }
-
- public boolean state() {
- return this._state;
- }
-
- 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 Size imageAreaSize() {
- Size var1;
- if (this._image != null) {
- var1 = new Size(this._image.width(), this._image.height());
- } else {
- var1 = new Size();
- }
-
- if (this._altImage != null) {
- if (this._altImage.width() > var1.width) {
- var1.width = this._altImage.width();
- }
-
- if (this._altImage.height() > var1.height) {
- var1.height = this._altImage.height();
- }
- }
-
- return var1;
- }
-
- Size minStringSize(String var1) {
- int var5 = var1.indexOf(10);
- if (var5 == -1) {
- return this._titleFont.fontMetrics().stringSize(var1);
- } else {
- Size var2 = new Size(0, this._titleFont.fontMetrics().stringHeight());
- int var4 = 1;
-
- String var3;
- for(var3 = var1; var5 != -1; var5 = var3.indexOf(10)) {
- int var6 = this._titleFont.fontMetrics().stringWidth(var3.substring(0, var5));
- if (var6 > var2.width) {
- var2.width = var6;
- }
-
- ++var4;
- var3 = var3.substring(var5 + 1);
- }
-
- int var7 = this._titleFont.fontMetrics().stringWidth(var3);
- if (var7 > var2.width) {
- var2.width = var7;
- }
-
- var2.height *= var4;
- return var2;
- }
- }
-
- public Size minSize() {
- Size var1 = null;
- Size var2 = null;
- boolean var4 = false;
- if (super._minSize != null) {
- return new Size(super._minSize);
- } else {
- if (this._title != null && this._title.length() > 0) {
- var1 = this.minStringSize(this._title);
- var4 = true;
- }
-
- if (this._altTitle != null && this._altTitle.length() > 0) {
- var2 = this.minStringSize(this._altTitle);
- var4 = true;
- }
-
- if (var1 == null) {
- var1 = var2;
- } else if (var2 != null) {
- if (var1.width < var2.width) {
- var1.width = var2.width;
- }
-
- if (var1.height < var2.height) {
- var1.height = var2.height;
- }
- }
-
- if (var1 != null) {
- if (var1.width > 0) {
- var1.sizeBy(3, 0);
- }
- } else {
- var1 = new Size();
- }
-
- Size var3 = this.imageAreaSize();
- boolean var5 = var3.width > 0 || var3.height > 0;
- if (var5) {
- if (this._imagePosition != 2 && this._imagePosition != 3) {
- if (var4 && this._imagePosition != 4) {
- var1.sizeBy(var3.width + 2, 0);
- if (var3.height > var1.height) {
- var1.height = var3.height;
- }
- } else {
- if (var3.width > var1.width) {
- var1.width = var3.width;
- }
-
- if (var3.height > var1.height) {
- var1.height = var3.height;
- }
- }
- } else {
- if (var1.width < var3.width) {
- var1.width = var3.width;
- }
-
- var1.height += var3.height + 2;
- }
- }
-
- if (this._bordered) {
- var1.sizeBy(3, 3);
- }
-
- return var1;
- }
- }
-
- public void setFont(Font var1) {
- if (var1 == null) {
- this._titleFont = Font.defaultFont();
- } else {
- this._titleFont = var1;
- }
- }
-
- public Font font() {
- return this._titleFont;
- }
-
- public void setTitleColor(Color var1) {
- if (var1 == null) {
- this._titleColor = Color.black;
- } else {
- this._titleColor = var1;
- }
- }
-
- public Color titleColor() {
- return this._titleColor;
- }
-
- public void setDisabledTitleColor(Color var1) {
- if (var1 == null) {
- this._disabledTitleColor = Color.gray;
- } else {
- this._disabledTitleColor = var1;
- }
- }
-
- public Color disabledTitleColor() {
- return this._disabledTitleColor;
- }
-
- public void setRaisedColor(Color var1) {
- if (var1 == null) {
- this._raisedColor = Color.lightGray;
- } else {
- this._raisedColor = var1;
- }
- }
-
- public Color raisedColor() {
- return this._raisedColor;
- }
-
- public void setLoweredColor(Color var1) {
- if (var1 == null) {
- this._loweredColor = Color.lightGray;
- } else {
- this._loweredColor = var1;
- }
- }
-
- public Color loweredColor() {
- return this._loweredColor;
- }
-
- public void setImage(Image var1) {
- this._image = var1;
- if (var1 instanceof DrawingSequence) {
- DrawingSequence var2 = (DrawingSequence)var1;
- var2.setOwner(this);
- }
-
- }
-
- public Image image() {
- return this._image;
- }
-
- public void setAltImage(Image var1) {
- this._altImage = var1;
- if (var1 instanceof DrawingSequence) {
- DrawingSequence var2 = (DrawingSequence)var1;
- var2.setOwner(this);
- }
-
- }
-
- public Image altImage() {
- return this._altImage;
- }
-
- public void setRaisedBorder(Border var1) {
- this._raisedBorder = var1;
- }
-
- public Border raisedBorder() {
- return this._raisedBorder;
- }
-
- public void setLoweredBorder(Border var1) {
- this._loweredBorder = var1;
- }
-
- public Border loweredBorder() {
- return this._loweredBorder;
- }
-
- public void setMouseDownSound(Sound var1) {
- this._downSound = var1;
- if (this._type == 3 && this._downSound != null) {
- this._downSound.setLoops(true);
- }
-
- }
-
- public Sound mouseDownSound() {
- return this._downSound;
- }
-
- public void setMouseUpSound(Sound var1) {
- this._upSound = var1;
- }
-
- public Sound mouseUpSound() {
- return this._upSound;
- }
-
- public void setBordered(boolean var1) {
- this._bordered = var1;
- if (this._bordered) {
- this.setTransparent(false);
- }
-
- }
-
- public boolean isBordered() {
- return this._bordered;
- }
-
- public void setType(int var1) {
- if (var1 >= 0 && var1 <= 3) {
- this._type = var1;
- this.setState(false);
- if (this._type == 3) {
- if (this._downSound != null) {
- this._downSound.setLoops(true);
- }
- } else if (this._downSound != null) {
- this._downSound.setLoops(false);
- }
-
- this._setupKeyboard();
- } else {
- throw new InconsistencyException("Invalid Button type: " + var1);
- }
- }
-
- public int type() {
- return this._type;
- }
-
- public void setRepeatDelay(int var1) {
- if (var1 > 0) {
- this._repeatDelay = var1;
- if (this._actionTimer != null) {
- this._actionTimer.setDelay(this._repeatDelay);
- }
- }
-
- }
-
- public int repeatDelay() {
- return this._repeatDelay;
- }
-
- public void setImagePosition(int var1) {
- if (var1 >= 0 && var1 <= 4) {
- this._imagePosition = var1;
- }
- }
-
- public int imagePosition() {
- return this._imagePosition;
- }
-
- public void setTransparent(boolean var1) {
- this.transparent = var1;
- if (this.transparent) {
- this._bordered = false;
- }
-
- }
-
- public boolean isTransparent() {
- return this.transparent;
- }
-
- protected void ancestorWasAddedToViewHierarchy(View var1) {
- super.ancestorWasAddedToViewHierarchy(var1);
- if (this._type == 2 && this._state) {
- this._state = false;
- this.setState(true);
- }
-
- }
-
- public void drawViewTitleInRect(Graphics var1, String var2, Font var3, Rect var4, int var5) {
- if (var2 != null && var2.length() != 0) {
- if (this._enabled) {
- var1.setColor(this._titleColor);
- } else {
- var1.setColor(this._disabledTitleColor);
- }
-
- var1.setFont(var3);
- int var8 = var2.indexOf(10);
- if (var8 == -1) {
- var1.drawStringInRect(var2, var4, var5);
- } else {
- Rect var6 = new Rect(var4);
- var6.height = this._titleFont.fontMetrics().stringHeight();
-
- String var7;
- for(var7 = var2; var8 != -1; var8 = var7.indexOf(10)) {
- var1.drawStringInRect(var7.substring(0, var8), var6, var5);
- var6.y += var6.height;
- var7 = var7.substring(var8 + 1);
- }
-
- var1.drawStringInRect(var7, var6, var5);
- }
- }
- }
-
- public void drawViewInterior(Graphics var1, String var2, Image var3, Rect var4) {
- Size var5 = this.imageAreaSize();
- if (this._imagePosition == 0) {
- int var9;
- if (var2 != null && var2.length() != 0) {
- var9 = var4.x + 1;
- } else {
- var9 = var4.x + 1 + (var4.width - var5.width - 2) / 2;
- }
-
- if (var3 != null) {
- var3.drawAt(var1, var9, var4.y + (var4.height - var5.height) / 2);
- }
-
- byte var10;
- if (var5.width > 0) {
- var4.moveBy(var5.width + 3, 0);
- var4.sizeBy(-(var5.width + 4), 0);
- var10 = 0;
- } else {
- var4.moveBy(1, 0);
- var4.sizeBy(-2, 0);
- var10 = 1;
- }
-
- this.drawViewTitleInRect(var1, var2, this._titleFont, var4, var10);
- } else if (this._imagePosition == 2) {
- if (var3 != null) {
- var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.y + 2);
- }
-
- int var7 = this._titleFont.fontMetrics().charHeight();
- var4.setBounds(var4.x + 1, var4.maxY() - var7 - 1, var4.width - 2, var7);
- this.drawViewTitleInRect(var1, var2, this._titleFont, var4, 1);
- } else if (this._imagePosition == 3) {
- if (var3 != null) {
- var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.maxY() - var5.height - 2);
- }
-
- var4.setBounds(var4.x + 1, var4.y + 1, var4.width - 2, this._titleFont.fontMetrics().charHeight());
- this.drawViewTitleInRect(var1, var2, this._titleFont, var4, 1);
- } else {
- byte var8;
- if (var3 != null && this._imagePosition == 4) {
- var3.drawAt(var1, var4.x + (var4.width - var5.width) / 2, var4.y + (var4.height - var5.height) / 2);
- var8 = 1;
- } else if (var5.width == 0) {
- var4.moveBy(2, 0);
- var8 = 1;
- } else {
- var8 = 0;
- }
-
- int var6;
- if (var2 != null && var2.length() != 0) {
- var6 = var4.maxX() - var5.width - 1;
- } else {
- var6 = var4.x + 1 + (var4.width - var5.width - 2) / 2;
- }
-
- if (var3 != null && this._imagePosition == 1) {
- var3.drawAt(var1, var6, var4.y + (var4.height - var5.height) / 2);
- }
-
- this.drawViewTitleInRect(var1, var2, this._titleFont, var4, var8);
- }
- }
-
- public void drawViewBackground(Graphics var1, Rect var2, boolean var3) {
- if (this._bordered) {
- var2.sizeBy(-3, -3);
- if (var3) {
- this._loweredBorder.drawInRect(var1, 0, 0, super.bounds.width, super.bounds.height);
- var1.setColor(this._loweredColor);
- var1.fillRect(this._loweredBorder.leftMargin(), this._loweredBorder.topMargin(), super.bounds.width - this._loweredBorder.widthMargin(), super.bounds.height - this._loweredBorder.heightMargin());
- var2.moveBy(2, 2);
- } else {
- this._raisedBorder.drawInRect(var1, 0, 0, super.bounds.width, super.bounds.height);
- var1.setColor(this._raisedColor);
- var1.fillRect(this._raisedBorder.leftMargin(), this._raisedBorder.topMargin(), super.bounds.width - this._raisedBorder.widthMargin(), super.bounds.height - this._raisedBorder.heightMargin());
- var2.moveBy(1, 1);
- }
- } else {
- if (!this.isTransparent()) {
- if (var3) {
- var1.setColor(this._loweredColor);
- } else {
- var1.setColor(this._raisedColor);
- }
-
- var1.fillRect(0, 0, super.bounds.width, super.bounds.height);
- }
-
- }
- }
-
- public void drawView(Graphics var1) {
- Image var2 = null;
- boolean var6 = this._highlighted ? !this._state : this._state;
- Rect var5 = Rect.newRect(0, 0, super.bounds.width, super.bounds.height);
- this.drawViewBackground(var1, var5, var6);
- if (this._image instanceof DrawingSequence) {
- DrawingSequence var3 = (DrawingSequence)this._image;
- if (var3.isAnimating()) {
- var2 = this._image;
- } else if (this._altImage instanceof DrawingSequence) {
- var2 = this._altImage;
- }
- } else if (this._altImage instanceof DrawingSequence) {
- DrawingSequence var7 = (DrawingSequence)this._altImage;
- if (var7.isAnimating()) {
- var2 = this._altImage;
- }
- }
-
- if (var2 == null) {
- var2 = this._image;
- if (var6 && this._altImage != null) {
- var2 = this._altImage;
- }
- }
-
- String var4;
- if (var6 && this._altTitle != null && this._altTitle.length() != 0) {
- var4 = this._altTitle;
- } else {
- var4 = this._title;
- }
-
- if (var2 != null || var4 != null && var4.length() != 0) {
- this.drawViewInterior(var1, var4, var2, var5);
- Rect.returnRect(var5);
- } else {
- Rect.returnRect(var5);
- }
- }
-
- Button _activeForPoint(int var1, int var2) {
- if (((View)this).superview() == null) {
- return null;
- } else {
- Vector var6 = ((View)this).superview().peersForSubview(this);
- Point var5 = Point.newPoint();
- int var7 = var6.count();
-
- while(var7-- > 0) {
- View var4 = (View)var6.elementAt(var7);
- if (var4 instanceof Button && var4 != this) {
- Button var3 = (Button)var4;
- if (var3.type() == 2) {
- ((View)this).convertToView(var4, var1, var2, var5);
- if (((View)var3).containsPoint(var5.x, var5.y)) {
- Point.returnPoint(var5);
- return var3;
- }
- }
- }
- }
-
- Point.returnPoint(var5);
- return null;
- }
- }
-
- public boolean mouseDown(MouseEvent var1) {
- if (!this._enabled) {
- return false;
- } else if (!((View)this).containsPoint(var1.x, var1.y)) {
- return false;
- } else {
- if (this._type == 2) {
- Button var2 = this._otherActive();
- if (var2 != null) {
- var2._setState(false);
- }
-
- this._oldState = this._state;
- this._state = false;
- }
-
- this._clickCount = var1.clickCount;
- if (this._type != 1 && this._type != 2) {
- this.setState(true);
- } else {
- this.setHighlighted(true);
- }
-
- if (this._downSound != null) {
- this._downSound.play();
- }
-
- if (this._altImage instanceof DrawingSequence) {
- DrawingSequence var3 = (DrawingSequence)this._altImage;
- var3.start();
- }
-
- if (this._type == 3 && this._actionTimer == null) {
- this.sendCommand();
- this._actionTimer = new Timer(this, "sendCommand", this._repeatDelay);
- this._actionTimer.setInitialDelay(300);
- this._actionTimer.start();
- }
-
- return true;
- }
- }
-
- void _buttonDown() {
- if (this._image instanceof DrawingSequence) {
- DrawingSequence var1 = (DrawingSequence)this._image;
- if (var1.doesLoop()) {
- var1.stop();
- } else {
- while(var1.isAnimating()) {
- var1.stop();
- }
- }
- }
-
- if (this._altImage instanceof DrawingSequence) {
- DrawingSequence var2 = (DrawingSequence)this._altImage;
- var2.start();
- }
-
- if (this._type == 3 && this._upSound != null) {
- this._upSound.stop();
- }
-
- if (this._downSound != null) {
- this._downSound.play();
- }
-
- }
-
- void _buttonUp() {
- if (this._altImage instanceof DrawingSequence) {
- DrawingSequence var1 = (DrawingSequence)this._altImage;
- if (var1.doesLoop()) {
- var1.stop();
- } else {
- while(var1.isAnimating()) {
- var1.stop();
- }
- }
- }
-
- if (this._image instanceof DrawingSequence) {
- DrawingSequence var2 = (DrawingSequence)this._image;
- var2.start();
- }
-
- if (this._type == 3 && this._downSound != null) {
- this._downSound.stop();
- }
-
- if (this._upSound != null) {
- this._upSound.play();
- }
-
- }
-
- public void mouseDragged(MouseEvent var1) {
- if (this._enabled) {
- if (this._type == 2 && !((View)this).containsPoint(var1.x, var1.y)) {
- Button var2 = this._activeForPoint(var1.x, var1.y);
- if (var2 != null) {
- this.setHighlighted(false);
- var2.setHighlighted(true);
- ((View)this).rootView().setMouseView(var2);
- }
-
- } else {
- if (((View)this).containsPoint(var1.x, var1.y)) {
- if (!this._state && !this._highlighted) {
- this._buttonDown();
- if (this._type != 1 && this._type != 2) {
- this.setState(true);
- } else {
- this.setHighlighted(true);
- }
-
- if (this._type == 3) {
- this.sendCommand();
- this._actionTimer = new Timer(this, "sendCommand", 100);
- this._actionTimer.start();
- return;
- }
- }
- } else if (this._state || this._highlighted) {
- this._buttonUp();
- if (this._type == 3 && this._actionTimer != null) {
- this._actionTimer.stop();
- this._actionTimer = null;
- }
-
- if (this._type == 1 || this._type == 2) {
- this.setHighlighted(false);
- return;
- }
-
- this.setState(false);
- }
-
- }
- }
- }
-
- public void mouseUp(MouseEvent var1) {
- if (this._enabled) {
- if (this._type == 2) {
- if (this._highlighted) {
- this._highlighted = false;
- this.setState(true);
- }
-
- if (this._state != this._oldState) {
- this.sendCommand();
- }
-
- this._oldState = false;
- if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
- ((View)this).rootView().selectView(this, true);
- }
-
- } else {
- if (this._actionTimer != null) {
- this._actionTimer.stop();
- this._actionTimer = null;
- }
-
- boolean var2 = ((View)this).containsPoint(var1.x, var1.y);
- if (var2) {
- this._buttonUp();
- }
-
- if (this._type == 3) {
- this._state = false;
- if (var2) {
- ((View)this).setDirty(true);
- }
-
- if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
- ((View)this).rootView().selectView(this, true);
- }
-
- } else {
- if (this._type == 1) {
- if (var2) {
- this._highlighted = false;
- this._state = !this._state;
- } else {
- this._highlighted = false;
- }
-
- if (var2) {
- ((View)this).setDirty(true);
- }
-
- if (var2) {
- this.sendCommand();
- }
- } else {
- if (this._type != 3 && var2) {
- this.sendCommand();
- }
-
- this._state = false;
- if (var2) {
- ((View)this).setDirty(true);
- }
- }
-
- if (this.canBecomeSelectedView() && ((View)this).rootView() != null) {
- ((View)this).rootView().selectView(this, true);
- }
-
- }
- }
- }
- }
-
- public int clickCount() {
- return this._performingAction ? this._clickCount : 0;
- }
-
- public void click() {
- if (this._enabled) {
- if (this._type != 2 || !this._state) {
- if (this._type != 1 && this._type != 2) {
- this.setState(true);
- ((View)this).application().syncGraphics();
-
- try {
- Thread.sleep(200L);
- } catch (InterruptedException var1) {
- }
-
- this._clickCount = 1;
- this.sendCommand();
- this.setState(false);
- } else {
- this.setState(!this._state);
- ((View)this).application().syncGraphics();
- this.sendCommand();
- }
- }
- }
- }
-
- public void performCommand(String var1, Object var2) {
- int var3 = this.type();
- if ("sendCommand".equals(var1)) {
- this.sendCommand();
- } else if ("click".equals(var1)) {
- this.click();
- } else if (var3 == 2 && "selectPreviousRadioButton".equals(var1)) {
- this.selectNextRadioButton(false);
- } else if (var3 == 2 && "selectNextRadioButton".equals(var1)) {
- this.selectNextRadioButton(true);
- } else {
- throw new NoSuchMethodError("unknown command: " + var1);
- }
- }
-
- public void drawingSequenceFrameChanged(DrawingSequence var1) {
- ((View)this).setDirty(true);
- }
-
- public void drawingSequenceCompleted(DrawingSequence var1) {
- }
-
- public void sendCommand() {
- this._performingAction = true;
- if (this._target != null) {
- this._target.performCommand(this._command, this);
- }
-
- this._performingAction = false;
- }
-
- protected void setHighlighted(boolean var1) {
- if (this._highlighted != var1) {
- this._highlighted = var1;
- ((View)this).setDirty(true);
- }
-
- }
-
- protected boolean isHighlighted() {
- return this._highlighted;
- }
-
- public boolean canBecomeSelectedView() {
- if (this.isEnabled() && ((View)this).hasKeyboardBindings()) {
- if (this.type() == 2) {
- return this.state();
- } else {
- return true;
- }
- } else {
- return false;
- }
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.Button", 2);
- var1.addField("title", (byte)16);
- var1.addField("altTitle", (byte)16);
- var1.addField("titleFont", (byte)18);
- var1.addField("titleColor", (byte)18);
- var1.addField("disabledTitleColor", (byte)18);
- var1.addField("raisedColor", (byte)18);
- var1.addField("loweredColor", (byte)18);
- var1.addField("image", (byte)18);
- var1.addField("altImage", (byte)18);
- var1.addField("downSound", (byte)18);
- var1.addField("upSound", (byte)18);
- var1.addField("target", (byte)18);
- var1.addField("command", (byte)16);
- var1.addField("type", (byte)8);
- var1.addField("imagePosition", (byte)8);
- var1.addField("repeatDelay", (byte)8);
- var1.addField("state", (byte)0);
- var1.addField("enabled", (byte)0);
- var1.addField("bordered", (byte)0);
- var1.addField("transparent", (byte)0);
- var1.addField("raisedBorder", (byte)18);
- var1.addField("loweredBorder", (byte)18);
- }
-
- public void encode(Encoder var1) throws CodingException {
- super.encode(var1);
- var1.encodeString("title", this._title);
- var1.encodeString("altTitle", this._altTitle);
- var1.encodeObject("titleFont", this._titleFont);
- var1.encodeObject("titleColor", this._titleColor);
- var1.encodeObject("disabledTitleColor", this._disabledTitleColor);
- var1.encodeObject("raisedColor", this._raisedColor);
- var1.encodeObject("loweredColor", this._loweredColor);
- var1.encodeObject("image", this._image);
- var1.encodeObject("altImage", this._altImage);
- var1.encodeObject("target", (Codable)this._target);
- var1.encodeString("command", this._command);
- var1.encodeInt("type", this._type);
- var1.encodeInt("imagePosition", this._imagePosition);
- var1.encodeInt("repeatDelay", this._repeatDelay);
- var1.encodeBoolean("state", this._state);
- var1.encodeBoolean("enabled", this._enabled);
- var1.encodeBoolean("bordered", this._bordered);
- var1.encodeBoolean("transparent", this.transparent);
- var1.encodeObject("raisedBorder", this._raisedBorder);
- var1.encodeObject("loweredBorder", this._loweredBorder);
- }
-
- public void decode(Decoder var1) throws CodingException {
- super.decode(var1);
- this._title = var1.decodeString("title");
- this._altTitle = var1.decodeString("altTitle");
- this._titleFont = (Font)var1.decodeObject("titleFont");
- this._titleColor = (Color)var1.decodeObject("titleColor");
- this._disabledTitleColor = (Color)var1.decodeObject("disabledTitleColor");
- this._raisedColor = (Color)var1.decodeObject("raisedColor");
- this._loweredColor = (Color)var1.decodeObject("loweredColor");
- this._image = (Image)var1.decodeObject("image");
- this._altImage = (Image)var1.decodeObject("altImage");
- this._target = (Target)var1.decodeObject("target");
- this._command = var1.decodeString("command");
- this._type = var1.decodeInt("type");
- this._imagePosition = var1.decodeInt("imagePosition");
- this._repeatDelay = var1.decodeInt("repeatDelay");
- this._state = var1.decodeBoolean("state");
- this._enabled = var1.decodeBoolean("enabled");
- this._bordered = var1.decodeBoolean("bordered");
- this.transparent = var1.decodeBoolean("transparent");
- if (var1.versionForClassName("netscape.application.Button") > 1) {
- this._raisedBorder = (Border)var1.decodeObject("raisedBorder");
- this._loweredBorder = (Border)var1.decodeObject("loweredBorder");
- }
-
- }
-
- void _setupKeyboard() {
- ((View)this).removeAllCommandsForKeys();
- if (this.type() == 2) {
- ((View)this).setCommandForKey("selectNextRadioButton", 1007, 0);
- ((View)this).setCommandForKey("selectNextRadioButton", 1005, 0);
- ((View)this).setCommandForKey("selectPreviousRadioButton", 1006, 0);
- ((View)this).setCommandForKey("selectPreviousRadioButton", 1004, 0);
- } else {
- ((View)this).setCommandForKey("click", 10, 0);
- }
- }
-
- public String formElementText() {
- if (this._type == 1) {
- return this._state ? "true" : "false";
- } else {
- return this.title();
- }
- }
- }
-