📄 guicomponents.js
字号:
else if(mouseY>t+h&&this._tickIncrease!=true){this.setValue(this.getValue()-this.getBlockIncrement());this._tickIncrease=false;}}};_p._onchange=function(e){this._layoutThumb();this.dispatchEvent(new BiEvent("change"));};_p.dispose=function(){BiComponent.prototype.dispose.call(this);this._line=null;this._thumb=null;};function BiSpinner(){BiComponent.call(this);this.setCssClassName("bi-spinner");this.setSize(50,22);this._rangeModel=new BiRangeModel();var f=new BiFont(1);this._upButton=new BiButton;this._upButton.setCssClassName("bi-button bi-spinner-up-button");this._upButton.setFont(f);this._upButton.setIcon(new BiImage(BiSpinner.UP_BUTTON_IMAGE,3,2));this._upButton.setTabIndex(-1);this.add(this._upButton,null,true);this._downButton=new BiButton;this._downButton.setCssClassName("bi-button bi-spinner-down-button");this._downButton.setFont(f);this._downButton.setIcon(new BiImage(BiSpinner.DOWN_BUTTON_IMAGE,3,2));this._downButton.setTabIndex(-1);this.add(this._downButton,null,true);this._textField=new BiTextField;this._textField.setMaxLength(3);this._textField.setText("0");this.add(this._textField,null,true);this._upButton.setWidth(16);this._upButton.setTop(0);this._downButton.setWidth(16);this._downButton.setBottom(0);this._textField.setTop(0);this._textField.setBottom(0);this._positionComponents();this._timer=new BiTimer
this._timer.setInterval(this._interval);this.setTabIndex(1);this._textField.addEventListener("keypress",this._onkeypress,this);this._textField.addEventListener("keydown",this._onkeydown,this);this._textField.addEventListener("keyup",this._onkeyup,this);this._textField.addEventListener("blur",this._onblur,this);this._upButton.addEventListener("mousedown",this._onmousedown,this);this._downButton.addEventListener("mousedown",this._onmousedown,this);this._rangeModel.addEventListener("change",this._onchange,this);this._timer.addEventListener("tick",this._ontick,this);}
BiSpinner.UP_BUTTON_IMAGE=application.getPath()+"images/arrow.up.tiny.gif";BiSpinner.DOWN_BUTTON_IMAGE=application.getPath()+"images/arrow.down.tiny.gif";var _p=BiSpinner.prototype=new BiComponent;_p._className="BiSpinner";_p._tickIncrease=null;_p._incrementAmount=1;_p._interval=100;_p._firstInterval=500;_p.setValue=function(nValue){this._rangeModel.setValue(nValue);};_p.getValue=function(){this._ensureValidValue();return this._rangeModel.getValue();};_p.setMaximum=function(nMaximum){this._rangeModel.setMaximum(nMaximum);};_p.getMaximum=function(){return this._rangeModel.getMaximum();};_p.setMinimum=function(nMinimum){this._rangeModel.setMinimum(nMinimum);};_p.getMinimum=function(){return this._rangeModel.getMinimum();};_p.layoutAllChildren=function(){BiComponent.prototype.layoutAllChildren.call(this);this._layoutSpinnerButtons();};_p.layoutAllChildrenY=function(){BiComponent.prototype.layoutAllChildrenY.call(this);this._layoutSpinnerButtons();};_p._layoutSpinnerButtons=function(){var h=this.getClientHeight();this._upButton.setHeight(Math.ceil(h/2));this._downButton.setHeight(Math.floor(h/2));};_p.getPreferredWidth=function(){var pw=Math.max(this._textField.getPreferredWidth(),this._textField.getMaxLength()*9);var labelW=this._textField.getLeft()+pw-(this.getRightToLeft()?16:0);return labelW+5+16;};_p.getPreferredHeight=function(){return this._textField.getPreferredHeight()+5;};_p.setFont=function(oFont){this._textField.setFont(oFont);};_p.getFont=function(){return this._textField.getFont();};_p.setAlign=function(sAlign){this._textField.setAlign(sAlign);};_p.getAlign=function(){return this._textField.getAlign();};_p.setTabIndex=function(nTabIndex){BiComponent.prototype.setTabIndex.call(this,-1);this._textField.setTabIndex(nTabIndex);};_p.getTabIndex=function(){return this._textField.getTabIndex();};_p.setFocused=function(bFocused){if(this.getCanFocus())
this._textField.setFocused(bFocused);};_p.setEnabled=function(b){BiComponent.prototype.setEnabled.call(this,b);this._upButton.setEnabled(b);this._downButton.setEnabled(b);this._textField.setEnabled(b);};_p._selectOnTabFocus=function(){this._textField.selectAll();};_p.setRightToLeft=function(b){BiComponent.prototype.setRightToLeft.call(this,b);this._positionComponents();this._textField.setAlign(this.getRightToLeft()?"left":"right");};_p._positionComponents=function(){if(this.getRightToLeft()){this._upButton.setRight(null);this._upButton.setLeft(0);this._downButton.setRight(null);this._downButton.setLeft(0);this._textField.setRight(0);this._textField.setLeft(16);}
else{this._upButton.setLeft(null);this._upButton.setRight(0);this._downButton.setLeft(null);this._downButton.setRight(0);this._textField.setLeft(0);this._textField.setRight(16);}};_p._onkeypress=function(e){var kc=e.getKeyCode();if(kc==BiKeyboardEvent.ENTER&&!e.getAltKey()){this._ensureValidValue();this._textField.selectAll();this.dispatchEvent(new BiEvent("action"));if(this._command)
this._command.execute();}
else {var preventDefault=true;switch(kc)
{case BiKeyboardEvent.UP:case BiKeyboardEvent.DOWN:case BiKeyboardEvent.LEFT:case BiKeyboardEvent.RIGHT:case BiKeyboardEvent.SHIFT:case BiKeyboardEvent.CTRL: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 BiSelectionModel(oOwner)
{BiEventTarget.call(this);this._owner=oOwner;this._selectedItems={};}
var _p=BiSelectionModel.prototype=new BiEventTarget;_p._className="BiSelectionModel";_p._multipleSelection=true;_p._fireChange=true;_p._anchorItem=null;_p._leadItem=null;BiSelectionModel.prototype.getOwner=function(){return this._owner;};BiSelectionModel.prototype.setOwner=function(v){this._owner=v;};BiSelectionModel.prototype.getMultipleSelection=function(){return this._multipleSelection;};BiSelectionModel.prototype.setMultipleSelection=function(v){this._multipleSelection=v;};_p.getFirst=function()
{return this._owner.getFirstChild();};_p.getLast=function()
{return this._owner.getLastChild();};_p.getItems=function()
{return this._owner.getChildren();};_p.getNext=function(oItem)
{if(oItem)
return oItem.getNextSibling();return null;};_p.getPrevious=function(oItem)
{if(oItem)
return oItem.getPreviousSibling();return null;};_p.isBefore=function(oItem1,oItem2)
{var cs=this.getItems();return cs.indexOf(oItem1)<cs.indexOf(oItem2);};_p.isEqual=function(oItem1,oItem2)
{return oItem1==oItem2;};_p.getItemHashCode=function(oItem)
{return oItem.toHashCode();};_p.getItemSelected=function(oItem)
{return this.getItemHashCode(oItem)in this._selectedItems;};_p.updateItemSelectionState=function(oItem,bSelected)
{};_p.updateItemAnchorState=function(oItem,bAnchor)
{};_p.updateItemLeadState=function(oItem,bLead)
{};_p.scrollItemIntoView=function(oItem)
{oItem.scrollIntoView();};_p.getItemLeft=function(oItem)
{return oItem.getLeft();};_p.getItemTop=function(oItem)
{return oItem.getTop();};_p.getItemWidth=function(oItem)
{return oItem.getWidth();};_p.getItemHeight=function(oItem)
{return oItem.getHeight();};_p.setItemSelected=function(oItem,bSelected)
{var hc=this.getItemHashCode(oItem);if(!this._multipleSelection)
{var item0=this.getSelectedItems()[0];if(bSelected)
{var old=item0;if(this.isEqual(oItem,old))
return;if(old!=null)
this.updateItemSelectionState(old,false);this.updateItemSelectionState(oItem,true);this._selectedItems={};this._selectedItems[hc]=oItem;this._dispatchChange();}
else {if(this.isEqual(item0,oItem))
{this.updateItemSelectionState(oItem,false);this._selectedItems={};this._dispatchChange();}}}
else{if(this.getItemSelected(oItem)==bSelected)
return;this.updateItemSelectionState(oItem,bSelected);if(bSelected)
this._selectedItems[hc]=oItem;else delete this._selectedItems[hc]
this._dispatchChange();}};_p.setAnchorItem=function(oItem)
{if(this._anchorItem!=oItem&&this._anchorItem!=null)
this.updateItemAnchorState(this._anchorItem,false)
this._anchorItem=oItem;if(oItem!=null)
this.updateItemAnchorState(oItem,true)};BiSelectionModel.prototype.getAnchorItem=function(){return this._anchorItem;};_p.setLeadItem=function(oItem)
{if(this._leadItem!=oItem&&this._leadItem!=null)
this.updateItemLeadState(this._leadItem,false)
this._leadItem=oItem;if(oItem!=null)
this.updateItemLeadState(oItem,true)};BiSelectionModel.prototype.getLeadItem=function(){return this._leadItem;};_p.getSelectedItems=function()
{var res=[];for(var hc in this._selectedItems)
res.push(this._selectedItems[hc]);return res;};_p.setSelectedItems=function(oItems)
{var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;this._deselectAll();var item;for(var i=0;i<oItems.length;i++)
{item=oItems[i];this._selectedItems[this.getItemHashCode(item)]=item;this.updateItemSelectionState(item,true);}
this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
this._dispatchChange();};_p.selectAll=function(){var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;this._selectAll();this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
this._dispatchChange();};_p._selectAll=function(){if(!this._multipleSelection)return;var items=this.getItems();this._selectedItems={};for(var i=0;i<items.length;i++){this.updateItemSelectionState(items[i],true);this._selectedItems[this.getItemHashCode(items[i])]=items[i];}};_p.deselectAll=function(){var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;this._deselectAll();this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
this._dispatchChange();};_p._deselectAll=function(){for(var hc in this._selectedItems){this.updateItemSelectionState(this._selectedItems[hc],false);delete this._selectedItems[hc];}};_p.selectItemRange=function(oItem1,oItem2){var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;this._selectItemRange(oItem1,oItem2,true);this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
this._dispatchChange();};_p._selectItemRange=function(item1,item2,bDeselect)
{if(this.isBefore(item2,item1))
{this._selectItemRange(item2,item1,bDeselect);return;}
if(bDeselect)
this._deselectAll();var item=item1;while(item!=null)
{this._selectedItems[this.getItemHashCode(item)]=item;this.updateItemSelectionState(item,true);if(this.isEqual(item,item2))
break;item=this.getNext(item);}};_p.handleMouseDown=function(oItem,e)
{if(e.getButton()!=BiMouseEvent.LEFT&&e.getButton()!=BiMouseEvent.RIGHT)
return;if(e.getShiftKey()||(!this.getItemSelected(oItem)&&!e.getCtrlKey()))
this._onmouseevent(oItem,e);else this.setLeadItem(oItem);};_p.handleMouseUp=function(oItem,e)
{if(e.getButton()!=BiMouseEvent.LEFT)
return;if(e.getCtrlKey()||this.getItemSelected(oItem))
this._onmouseevent(oItem,e);};_p.handleClick=function(oItem,e){};_p.handleDblClick=function(oItem,e){};_p._onmouseevent=function(oItem,e){var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;var selectedItems=this.getSelectedItems();var selectedCount=selectedItems.length;var el=oItem
this.setLeadItem(oItem);var rItem=el;var aItem=this._anchorItem;if(selectedCount==0||(e.getCtrlKey()&&!e.getShiftKey()&&this._multipleSelection)){this.setAnchorItem(aItem);aItem=rItem;}
if(!e.getCtrlKey()&&!e.getShiftKey()||!this._multipleSelection){this._deselectAll();this.setAnchorItem(rItem);if(!this.getItemSelected(el))
this.updateItemSelectionState(el,true);this._selectedItems={};this._selectedItems[this.getItemHashCode(el)]=el;}
else if(this._multipleSelection&&e.getCtrlKey()&&!e.getShiftKey()){this.setItemSelected(el,!this.getItemSelected(el));this.setAnchorItem(rItem);}
else if(this._multipleSelection&&e.getCtrlKey()&&e.getShiftKey()){this._selectItemRange(aItem,rItem,false);}
else if(this._multipleSelection&&!e.getCtrlKey()&&e.getShiftKey()){this._selectItemRange(aItem,rItem,true);}
this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
this._dispatchChange();};_p.handleKeyDown=function(e){var oldVal=this._getChangeValue();var oldFireChange=this._fireChange;this._fireChange=false;if(e.getKeyCode()==65&&e.getCtrlKey()){if(this._multipleSelection){this._selectAll();this.setLeadItem(this.getFirst());}}
else{var aIndex=this._anchorItem;var itemToSelect=this.getItemToSelect(e);if(itemToSelect){this.setLeadItem(itemToSelect);this.scrollItemIntoView(itemToSelect);e.preventDefault();if(e.getShiftKey()&&this._multipleSelection){if(aIndex==null)
this.setAnchorItem(itemToSelect);this._selectItemRange(this._anchorItem,itemToSelect,true);}
else if(!e.getCtrlKey()){this._deselectAll();this.updateItemSelectionState(itemToSelect,true);this._selectedItems[this.getItemHashCode(itemToSelect)]=itemToSelect;this.setAnchorItem(itemToSelect);}}}
this._fireChange=oldFireChange;if(this._fireChange&&this._hasChanged(oldVal))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -