⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guicomponents.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
            case BiKeyboardEvent.ALT:            case BiKeyboardEvent.ESC:            case BiKeyboardEvent.DELETE:            case BiKeyboardEvent.BACKSPACE:            case BiKeyboardEvent.INSERT:            case BiKeyboardEvent.HOME:            case BiKeyboardEvent.END:            case BiKeyboardEvent.PAGE_UP:            case BiKeyboardEvent.PAGE_DOWN:            case BiKeyboardEvent.NUM_LOCK:                preventDefault = false;        }        if (kc >= 48 && kc <= 57)            preventDefault = false;        if (preventDefault)            e.preventDefault();    }};_p._onkeydown = function(e){    var kc = e.getKeyCode();    if (this._tickIncrease == null && (kc == BiKeyboardEvent.UP || kc == BiKeyboardEvent.DOWN))    {        this._tickIncrease = kc == BiKeyboardEvent.UP;        this._resetIncrements();        this._increment();        this._timer.setInterval(this._firstInterval);        this._timer.start();    }};_p._onkeyup = function(e){    var kc = e.getKeyCode();    if (this._tickIncrease != null && (kc == BiKeyboardEvent.UP || kc == BiKeyboardEvent.DOWN))    {        this._timer.stop();        this._tickIncrease = null;    }};_p._onmousedown = function(e){    if (e.getButton() != BiMouseEvent.LEFT)        return;    this._ensureValidValue();    var b = e.getTarget();    b.addEventListener("mouseup", this._onmouseup, this);    b.addEventListener("mouseout", this._onmouseup, this);    this._tickIncrease = b == this._upButton;    this._resetIncrements();    this._increment();    this._textField.selectAll();    this._timer.setInterval(this._firstInterval);    this._timer.start();};_p._onmouseup = function(e){    var b = e.getTarget();    b.removeEventListener("mouseup", this._onmouseup, this);    b.removeEventListener("mouseout", this._onmouseup, this);    this._textField.selectAll();    this._textField.setFocused(true);    this._timer.stop();    this._tickIncrease = null;};_p._onchange = function(e){    this._textField.setMaxLength(Math.ceil(Math.log(this.getMaximum() + 1) / Math.LN10));    this._textField.setText(String(this._rangeModel.getValue()));    this.dispatchEvent(new BiEvent("change"));};_p._onblur = function(e){    this._ensureValidValue();} ;_p._ontick = function(e){    this._timer.stop();    this._interval = Math.max(20, this._interval - 2);    if (this._interval == 20)        this._incrementAmount = 1.01 * this._incrementAmount;    this._increment();    this._timer.setInterval(this._interval);    this._timer.start();};_p._ontextfieldfocuschanged = function(e){    this.dispatchEvent(new BiEvent(e.getType()));} ;_p._ensureValidValue = function(){    var v = parseInt(this._textField.getText());    if (!isNaN(v))    {        this._rangeModel.setValue(v);    }    v = this._rangeModel.getValue();    if (String(v) != this._textField.getText())        this._textField.setText(String(v));};_p._increment = function(){    this._rangeModel.setValue(this._rangeModel.getValue() + (this._tickIncrease ? 1 : -1) * this._incrementAmount);} ;_p._resetIncrements = function(){    this._incrementAmount = BiSpinner.prototype._incrementAmount;    this._interval = BiSpinner.prototype._interval;};function BiList(){    BiComponent.call(this);    this.setCssClassName("bi-list");    this.setTabIndex(1);    this.setHideFocus(true);    this._selectionModel = new BiListSelectionModel(this);    this.addEventListener("mousedown", this._onmousevent);    this.addEventListener("mouseup", this._onmousevent);    this.addEventListener("click", this._onmousevent);    this.addEventListener("dblclick", this._onmousevent);    this.addEventListener("keydown", this._onkeydown);    this.addEventListener("keypress", this._onKeyPress);    this.addEventListener("focus", this._onfocuschange);    this.addEventListener("blur", this._onfocuschange);    this._selectionModel.addEventListener("change", function(e)    {        this.dispatchEvent(new BiEvent("change"));        if (this._command)            this._command.setUserValue(this.getUserValue());    }, this);}var _p = BiList.prototype = new BiComponent;_p._className = "BiList";_p._lastKeyPress = 0;_p._accumulatedKeys = "";_p.getSelectedItem = function(){    return this.getSelectedItems()[0];} ;_p.getSelectedItems = function(){    return this._selectionModel.getSelectedItems();} ;_p.getValue = _p.getUserValue = function(){    var si = this.getSelectedItem();    if (si)        return si.getUserValue();    return null;};_p.getValues = _p.getUserValues = function(){    var sis = this.getSelectedItems();    var l = sis.length;    var res = new Array(l);    for (var i = 0; i < l; i++)        res[i] = sis[i].getUserValue();    return res;};_p.setValue = _p.setUserValue = function(v){    var item = this.findUserValueExact(v);    if (item)    {        this._selectionModel._deselectAll();        item.setSelected(true);        this._selectionModel.setAnchorItem(item);        this._selectionModel.setLeadItem(item);    }};BiList.prototype.getSelectionModel = function(){    return this._selectionModel;} ;BiList.prototype.setSelectionModel = function(v){    this._selectionModel = v;} ;_p.add = function(oChild, oBefore){    BiComponent.prototype.add.call(this, oChild, oBefore);    if (oChild.getSelected())        this._selectionModel.setItemSelected(oChild, true);};_p.remove = function(oChild){    var b = oChild.getSelected();    var sm = this._selectionModel;    var next;    if (sm._leadItem == oChild || sm._anchorItem == oChild)        next = oChild.getNextSibling() || oChild.getPreviousSibling();    BiComponent.prototype.remove.call(this, oChild);    if (b)    {        sm.setItemSelected(oChild, false);        oChild.setSelected(true);    }    if (sm._leadItem == oChild)        sm._leadItem = next;    if (sm._anchorItem == oChild)        sm._anchorItem = next;};_p.removeAll = function(){    var sm = this.getSelectionModel();    sm.deselectAll();    sm.setAnchorItem(null);    sm.setLeadItem(null);    var cs = this.getChildren();    var l = cs.length;    for (var i = 0; i < l; i++)    {        BiComponent.prototype.remove.call(this, cs[i]);        cs[i].dispose();    }};_p.setMultipleSelection = function(b){    this._selectionModel.setMultipleSelection(b);} ;_p.getMultipleSelection = function(){    return this._selectionModel.getMultipleSelection();} ;_p.findString = function(sText, nStartIndex){    return this._findItem(sText, nStartIndex || 0, "String");} ;_p.findStringExact = function(sText, nStartIndex){    return this._findItem(sText, nStartIndex || 0, "StringExact");} ;_p._findItem = function(oUserValue, nStartIndex, sType){    var i;    var items = this.getChildren();    if (nStartIndex == null)    {        var si = this.getSelectedItem();        nStartIndex = items.indexOf(si);        if (nStartIndex == -1)            nStartIndex = 0;    }    var methodName = "matches" + sType;    for (i = nStartIndex; i < items.length; i++)    {        if (items[i][methodName](oUserValue))            return items[i];    }    for (i = 0; i < nStartIndex; i++)    {        if (items[i][methodName](oUserValue))            return items[i];    }    return null;};_p.findValueExact = _p.findUserValueExact = function(oUserValue, nStartIndex){    var items = this.getChildren();    if (isNaN(nStartIndex))        nStartIndex = 0;    for (var i = nStartIndex; i < items.length; i++)    {        if (items[i].getUserValue() == oUserValue)            return items[i];    }    return null;};_p._onmousevent = function(e){    var item = e.getTarget();    while (item != null && item.getParent() != this)        item = item.getParent();    if (item != null)    {        switch (e.getType())        {            case "mousedown":            this._selectionModel.handleMouseDown(item, e);            break;            case "mouseup":            this._selectionModel.handleMouseUp(item, e);            break;            case "click":            this._selectionModel.handleClick(item, e);            break;            case "dblclick":            this._selectionModel.handleDblClick(item, e);            break;        }    }};_p._onfocuschange = function(e){    var items = this.getSelectedItems();    for (var i = 0; i < items.length; i++)        items[i]._updateClassName();    if (this._selectionModel._leadItem)        this._selectionModel._leadItem._updateClassName();};_p._onkeydown = function(e){    var kc = e.getKeyCode();    if (kc == BiKeyboardEvent.ENTER && !e.getAltKey())    {        var items = this.getSelectedItems();        for (var i = 0; i < items.length; i++)            items[i]._dispatchAction();    }    else        this._selectionModel.handleKeyDown(e);};_p._onKeyPress = function(e){    if (new Date - this._lastKeyPress > 1000)    {        this._accumulatedKeys = "";    }    this._accumulatedKeys += String.fromCharCode(e.getKeyCode());    var item = this._findItem(this._accumulatedKeys, null, "String");    if (item)    {        var oldVal = this._selectionModel._getChangeValue();        var oldFireChange = this._selectionModel._fireChange;        this._selectionModel._fireChange = false;        this._selectionModel._deselectAll();        this._selectionModel.setItemSelected(item, true);        this._selectionModel.setAnchorItem(item);        this._selectionModel.setLeadItem(item);        item.scrollIntoView();        this._selectionModel._fireChange = oldFireChange;        if (this._selectionModel._fireChange && this._selectionModel._hasChanged(oldVal))            this._selectionModel._dispatchChange();    }    this._lastKeyPress = ( new Date).valueOf();    e.preventDefault();};_p.dispose = function(){    if (this._disposed)        return;    BiComponent.prototype.dispose.call(this);    this._selectionModel.dispose();    this._selectionModel = null;    if (this._dataSource)    {        this._dataSource.dispose();        this._dataSource = null;    }};_p._syncWithCommmand = function(){    if (this._command)    {        this.setEnabled(this._command.getEnabled());        this.setUserValue(this._command.getUserValue());    }};function BiListItem(sText, oUserValue){    BiLabel.call(this, sText);    if (oUserValue != null)        this._userValue = oUserValue;    this.setCssClassName("bi-list-item");    this.addEventListener("dblclick", this._onDblClick);}_p = BiListItem.prototype = new BiLabel;_p._className = "BiListItem";_p._selected = false;_p._anchor = false;_p._lead = false;_p._userValue = null;_p.setSelected = function(bSelected){    if (this._selected != bSelected)    {        var p;        if ((p = this.getParent()) != null)        {            p._selectionModel.setItemSelected(this, bSelected);        }        this._setSelected(bSelected);    }};BiListItem.prototype.getSelected = function(){    return this._selected;} ;BiListItem.prototype.getUserValue = function(){    return this._userValue;} ;_p.setUserValue = function(v){    if (this._userValue != v)    {        this._userValue = v;        if (this._command)            this._command.setUserValue(v);    }};_p.getValue = _p.getUserValue;_p.setValue = _p.setUserValue;_p._setSelected = function(bSelected){    this._selected = bSelected;    this._updateClassName();};_p._setAnchor = function(bAnchor){    this._anchor = bAnchor;    this._updateClassName();};_p._setLead = function(bLead){    this._lead = bLead;    this._updateClassName();};_p._updateClassName = function(){    var f = this._parent && this._parent.getFocused();    this.setCssClassName("bi-list-item" + (this._selected && f ? " selected-focused" : "") + (this._selected && !f ? " selected" : "") + (this._lead && f ? " lead-focused" : "") + (this._lead && !f ? " lead" : "") + (this._anchor ? " anchor" : ""));};_p.getIndex = function(){    var p;    if ((p = this.getParent()) != null)        return p.getChildren().indexOf(this);    return -1;};_p.matchesString = function(sText){    return sText != "" && this.getText().toLowerCase().indexOf(sText.toLowerCase()) == 0;} ;_p.matchesStringExact = function(sText){    return sText != "" && this.getText().toLowerCase() == String(sText).toLowerCase();} ;_p._onDblClick = function(e){    var p = this.getParent();    if (p && p.getIsEnabled())        this._dispatchAction()};_p._dispatchAction = function(){    if (this.getIsEnabled())    {        this.dispatchEvent(new BiEvent("action"));        if (this._command)            this._command.execute();    }};_p.dispose = function(){    if (this._disposed)        return;    BiLabel.prototype.dispose.call(this);    this._userValue = null;};_p._syncWithCommmand = function(){    if (this._command)    {        this.setEnabled(this._command.getEnabled());        this.setUserValue(this._command.getUserValue());    }};function BiListSelectionModel(oList){    BiEventTarget.call(this);    this._list = oList;    this._selectedItems = {    };}var _p = BiListSelectionModel.prototype = new BiEven

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -