Button.js
上传用户:ahit0551
上传日期:2009-04-15
资源大小:2345k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /**
  2.  * <p>Title: </p>
  3.  * <p>Description: </p>
  4.  * <p>Copyright: Copyright (c) xio.name 2006</p>
  5.  * @author xio
  6.  */
  7. function Button(image, text) {
  8.     this.base = Component;
  9.     this.base(Toolkit.newTable());
  10.     //
  11.     this.ui.cellPadding = 0;
  12.     this.ui.cellSpacing = 0;
  13.     this.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON");
  14.     //
  15.     var row = this.ui.insertRow(-1);
  16.     //
  17.     if (image) {
  18.         var imageIcon = Toolkit.newImage();
  19.         imageIcon.src = image;
  20.         imageIcon.className = "NAME_XIO_UI_BUTTON_IMGCELL";
  21.         this.imgCell = row.insertCell(-1);
  22.         this.imgCell.appendChild(imageIcon);
  23.         this.imgCell.valign = "middle";
  24.         this.imgCell.align = "center";
  25.     } else {
  26.         this.imgCell = null;
  27.         if (!text) {
  28.             text = "&nbsp;";
  29.         }
  30.     }
  31.     //
  32.     if (text) {
  33.         this.txtCell = row.insertCell(-1);
  34.         this.txtCell.innerHTML = text;
  35.         this.txtCell.valign = "middle";
  36.         this.txtCell.align = "center";
  37.         this.txtCell.className = "NAME_XIO_UI_BUTTON_TXTCELL";
  38.         if (!image) {
  39.             this.txtCell.style.paddingLeft = "5px";
  40.             this.txtCell.style.paddingRight = "5px";
  41.         }
  42.     } else {
  43.         this.txtCell = null;
  44.     }
  45.     //
  46.     this.addMouseListener(new ButtonMouseListener(this));
  47.     //
  48.     this.setModel(new ButtonModel());
  49.     //
  50.     this.actionListeners = new Array();
  51. }
  52. Button.prototype = new Component();
  53. Button.prototype.toString = function () {
  54.     return "[Component,Button]";
  55. };
  56. Button.prototype.setModel = function (model) {
  57.     if (!model) {
  58.         return;
  59.     }
  60.     this.model = model;
  61.     this.model.addObserver(this);
  62. };
  63. Button.prototype.getModel = function () {
  64.     return this.model;
  65. };
  66. Button.prototype.getText = function () {
  67.     if (this.txtCell) {
  68.         return this.txtCell.innerHTML;
  69.     } else {
  70.         return null;
  71.     }
  72. };
  73. Button.prototype.setText = function (text) {
  74.     if (this.txtCell) {
  75.         this.txtCell.innerHTML = text;
  76.     }
  77. };
  78. Button.prototype.doClick = function () {
  79.     this.model.setPressed(true);
  80.     for (var i = 0; i < this.actionListeners.size(); i++) {
  81.         this.actionListeners.get(i).actionPerformed(this);
  82.     }
  83.     this.model.setPressed(false);
  84. };
  85. //
  86. Button.prototype.addActionListener = function (actionListener) {
  87.     this.actionListeners.add(actionListener);
  88. };
  89. Button.prototype.removeActionListener = function (actionListener) {
  90.     this.actionListeners.remove(actionListener);
  91. };
  92. Button.prototype.clearActionListeners = function (actionListener) {
  93.     this.actionListeners.clear();
  94. };
  95. Button.prototype.getActionListeners = function () {
  96.     return this.actionListeners;
  97. };
  98. //
  99. Button.prototype.update = function (observable, arg) {
  100.     this._update();
  101. };
  102. Button.prototype._update = function () {
  103.     if (this.model.isPressed()) {
  104.         if (this.model.isEnabled()) {
  105.             this.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON NAME_XIO_UI_BUTTON_PRESSED");
  106.         } else {
  107.             this.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON NAME_XIO_UI_BUTTON_PRESSED NAME_XIO_UI_DISENABLED");
  108.         }
  109.     } else {
  110.         if (this.model.isEnabled()) {
  111.             this.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON");
  112.         } else {
  113.             this.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON NAME_XIO_UI_DISENABLED");
  114.         }
  115.     }
  116. };
  117. //
  118. /**
  119.  *
  120.  */
  121. function ButtonMouseListener(button) {
  122.     this.button = button;
  123. }
  124. ButtonMouseListener.prototype = new MouseListener();
  125. ButtonMouseListener.prototype.onClick = function () {
  126.     if (!this.button.getModel().isEnabled()) {
  127.         return;
  128.     }
  129.     this.button.doClick();
  130. };
  131. ButtonMouseListener.prototype.onMouseOver = function () {
  132.     if (!this.button.getModel().isEnabled()) {
  133.         return;
  134.     }
  135.     this.button.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON NAME_XIO_UI_BUTTON_OVER");
  136. };
  137. ButtonMouseListener.prototype.onMouseDown = function () {
  138.     if (!this.button.getModel().isEnabled()) {
  139.         return;
  140.     }
  141.     this.button.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON NAME_XIO_UI_BUTTON_PRESSED");
  142. };
  143. ButtonMouseListener.prototype.onMouseOut = function () {
  144.     if (!this.button.getModel().isEnabled()) {
  145.         return;
  146.     }
  147.     this.button.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON");
  148. };
  149. ButtonMouseListener.prototype.onMouseUp = function () {
  150.     if (!this.button.getModel().isEnabled()) {
  151.         return;
  152.     }
  153.     this.button.setClassName("NAME_XIO_UI_FONT NAME_XIO_UI_BUTTON");
  154. };