📄 window.js
字号:
BiDesktopPane.prototype.getWindowManager = function(){ return this._windowManager;} ;_p.add = function(oChild, oBefore){ BiComponent.prototype.add.call(this, oChild, oBefore); if (oChild instanceof BiWindow) this._windowManager.add(oChild);};_p.remove = function(oChild){ BiComponent.prototype.remove.call(this, oChild); if (oChild instanceof BiWindow) this._windowManager.remove(oChild); return oChild;};_p.getWindows = function(){ return this._windowManager.getWindows();} ;_p.dispose = function(){ if (this._disposed) return; BiComponent.prototype.dispose.call(this); this._windowManager.dispose(); this._windowManager = null;};function BiOptionPane(oMessage, sMessageType, sOptionType, oImage, oOptions, oInitialValue){ BiComponent.call(this); this.setSize(250, 100); this._message = oMessage; this._messageComponent = BiOptionPane.getComponentFromObject(this._message); this._messageType = sMessageType || "plain"; this._optionType = sOptionType || "default"; this._image = oImage || BiOptionPane.getImageFromOptionType(this._messageType); this._options = oOptions; this._optionComponents = this._getOptionComponents(); this.setInitialValue(oInitialValue); this._addComponents(); this._fixedLayout();}var _p = BiOptionPane.prototype = new BiComponent;_p._className = "BiOptionPane";BiOptionPane.BUTTONS_GAP = 6;BiOptionPane.IMAGE_MESSAGE_GAP = 18;BiOptionPane.MESSAGE_INPUT_GAP = 10;BiOptionPane.MESSAGE_BUTTONS_GAP = 18;BiOptionPane.PADDING_LEFT = 11;BiOptionPane.PADDING_RIGHT = 11;BiOptionPane.PADDING_TOP = 11;BiOptionPane.PADDING_BOTTOM = 11;BiOptionPane.ERROR_IMAGE = application.getPath() + "images/stopmark.32.png";BiOptionPane.INFORMATION_IMAGE = application.getPath() + "images/infomark.32.png";BiOptionPane.WARNING_IMAGE = application.getPath() + "images/exclamation.32.png";BiOptionPane.QUESTION_IMAGE = application.getPath() + "images/questionmark.32.png";_p._message = null;_p._messageType = "plain";_p._optionType = "default";_p._options = null;_p._inputComponent = null;_p._acceptButton = null;_p._cancelButton = null;_p._dialog = null;_p._value = null;BiOptionPane.getComponentFromObject = function(o){ if (o instanceof BiComponent) return o; var l = new BiLabel(String(o)); l.setWrap(true); return l;};BiOptionPane.getImageFromOptionType = function(sOptionType){ if (sOptionType == "plain") return null; var uri; switch (sOptionType) { case "error": uri = BiOptionPane.ERROR_IMAGE; break; case "information": uri = BiOptionPane.INFORMATION_IMAGE; break; case "warning": uri = BiOptionPane.WARNING_IMAGE; break; case "question": uri = BiOptionPane.QUESTION_IMAGE; break; } var img = new BiImage(uri, 32, 32); return img;};BiOptionPane.prototype.getMessage = function(){ return this._message;} ;BiOptionPane.prototype.getMessageType = function(){ return this._messageType;} ;BiOptionPane.prototype.getOptions = function(){ return this._options;} ;BiOptionPane.prototype.getOptionType = function(){ return this._optionType;} ;BiOptionPane.prototype.getImage = function(){ return this._image;} ;BiOptionPane.prototype.getInitialValue = function(){ return this._initialValue;} ;BiOptionPane.prototype.getAcceptButton = function(){ return this._acceptButton;} ;BiOptionPane.prototype.setAcceptButton = function(v){ this._acceptButton = v;} ;BiOptionPane.prototype.getCancelButton = function(){ return this._cancelButton;} ;BiOptionPane.prototype.setCancelButton = function(v){ this._cancelButton = v;} ;BiOptionPane.prototype.getDialog = function(){ return this._dialog;} ;BiOptionPane.prototype.getValue = function(){ return this._value;} ;BiOptionPane.prototype.setValue = function(v){ this._value = v;} ;BiOptionPane.prototype.getInputComponent = function(){ return this._inputComponent;} ;_p.setInitialValue = function(oInitialValue){ this._initialValue = oInitialValue; if (oInitialValue != null) { var idx = this._options.indexOf(this._initialValue); this._acceptButton = this._optionComponents[idx]; } this._value = oInitialValue;};_p._getOptionComponents = function(){ var res = []; if (this._options != null) { for (var i = 0; i < this._options.length; i++) res[i] = this._getOptionButton(this._options[i], this._options[i]) } else { if (this._optionType == "default" || this._optionType == "okcancel") res.push(this._getOptionButton("OK", "ok")); if (this._optionType == "yesno" || this._optionType == "yesnocancel") { res.push(this._getOptionButton("Yes", "yes")); res.push(this._getOptionButton("No", "no")); } if (this._optionType == "okcancel" || this._optionType == "yesnocancel") res.push(this._getOptionButton("Cancel", "cancel")); } for (var i = 0; i < res.length; i++) res[i].setWidth(75); return res;};_p._getOptionButton = function(oText, oDialogResult){ var b; if (oText instanceof BiComponent) b = oText; else b = new BiButton(String(oText)); b.addEventListener("action", function(e) { this._onOptionAction(e, oDialogResult); } , this); return b;};_p.setInputComponent = function(oComponent){ if (this._inputComponent != oComponent) { if (this._inputComponent) this.remove(this._inputComponent); this._inputComponent = oComponent; if (this._inputComponent) this.add(this._inputComponent, this._optionComponents[0]); this._fixedLayout(); if (this.getCreated()) this._layoutInputComponentY(); }};_p._addComponents = function(){ if (this._image) this.add(this._image); this.add(this._messageComponent); if (this._inputComponent) this.add(this._inputComponent); for (var i = 0; i < this._optionComponents.length; i++) this.add(this._optionComponents[i]);};_p.layoutAllChildren = function(){ BiComponent.prototype.layoutAllChildren.call(this); this._layoutOptionComponentsX(); this._layoutOptionComponentsY(); this._layoutInputComponentY();};_p.layoutAllChildrenX = function(){ BiComponent.prototype.layoutAllChildrenX.call(this); this._layoutOptionComponentsX();};_p.layoutAllChildrenY = function(){ BiComponent.prototype.layoutAllChildrenY.call(this); this._layoutOptionComponentsY(); this._layoutInputComponentY();};_p._fixedLayout = function(){ var messageLeft; if (this._image) { this._image.setLocation(BiOptionPane.PADDING_LEFT, BiOptionPane.PADDING_TOP); messageLeft = BiOptionPane.PADDING_LEFT + this._image.getWidth() + BiOptionPane.IMAGE_MESSAGE_GAP; } else { messageLeft = BiOptionPane.PADDING_LEFT; } this._messageComponent.setLocation(messageLeft, BiOptionPane.PADDING_TOP); this._messageComponent.setRight(BiOptionPane.PADDING_RIGHT); if (this._inputComponent) { this._inputComponent.setLeft(messageLeft); this._inputComponent.setRight(BiOptionPane.PADDING_RIGHT); }};_p._getOptionComponentsWidth = function(){ var w = 0; for (var i = 0; i < this._optionComponents.length; i++) w += this._optionComponents[i].getWidth() + BiOptionPane.BUTTONS_GAP; w -= BiOptionPane.BUTTONS_GAP; return w;};_p._getOptionComponentsHeight = function(){ var h = 0; for (var i = 0; i < this._optionComponents.length; i++) h = Math.max(h, this._optionComponents[i].getHeight()); return h;};_p._layoutOptionComponentsX = function(){ var cw = this.getClientWidth() - BiOptionPane.PADDING_LEFT - BiOptionPane.PADDING_RIGHT; var bw = this._getOptionComponentsWidth(); var x = BiOptionPane.PADDING_LEFT + (cw - bw) / 2; for (var i = 0; i < this._optionComponents.length; i++) { this._optionComponents[i].setLeft(x); x += this._optionComponents[i].getWidth() + BiOptionPane.BUTTONS_GAP; }};_p._layoutOptionComponentsY = function(){ var maxHeight = this._getOptionComponentsHeight(); for (var i = 0; i < this._optionComponents.length; i++) { this._optionComponents[i].setBottom( BiOptionPane.PADDING_BOTTOM + (maxHeight - this._optionComponents[i].getHeight()) / 2); }};_p._layoutInputComponentY = function(){ if (this._inputComponent) { this._inputComponent.setTop( BiOptionPane.PADDING_TOP + this._messageComponent.getHeight() + BiOptionPane.MESSAGE_INPUT_GAP); }};_p.getPreferredWidth = function(){ var w = (this._image ? this._image.getWidth() + BiOptionPane.IMAGE_MESSAGE_GAP : 0) + Math.max(this._messageComponent.getPreferredWidth(), (this._inputComponent ? this._inputComponent.getPreferredWidth() : 0)); return BiOptionPane.PADDING_LEFT + BiOptionPane.PADDING_RIGHT + Math.max(w, this._getOptionComponentsWidth());};_p.getPreferredHeight = function(){ var h = Math.max(this._image ? this._image.getHeight() : 0, this._messageComponent.getPreferredHeight() + (this._inputComponent ? this._inputComponent.getPreferredHeight() + BiOptionPane.MESSAGE_INPUT_GAP : 0)); return BiOptionPane.PADDING_TOP + h + BiOptionPane.MESSAGE_BUTTONS_GAP + this._getOptionComponentsHeight() + BiOptionPane.PADDING_BOTTOM;};_p.createDialog = function(sCaption){ var d = new BiDialog(sCaption); d.setResizable(true); d.setMinimumWidth(250); d.setMinimumHeight(123); var cp = d.getContentPane(); d.setContentPane(this); cp.dispose(); var aw = application.getWindow(); aw.add(d); this.layoutAllChildren(); var pw = Math.max(d.getPreferredWidth(), d.getMinimumWidth()); var ph = Math.max(d.getPreferredHeight(), d.getMinimumHeight()); pw = Math.min(aw.getClientWidth(), pw); d.setSize(pw, ph); d.setResizable(false); if (!this._acceptButton && !this._options) this._acceptButton = this._optionComponents[0]; if (!this._cancelButton && !this._options) this._cancelButton = this._optionComponents[this._optionComponents.length - 1]; d.setAcceptButton(this._acceptButton); d.setCancelButton(this._cancelButton); this._dialog = d; return d;};_p._onOptionAction = function(e, oDialogResult){ if (this._inputComponent) { if (oDialogResult == "cancel") this.setValue(null); else if (typeof this._inputComponent.getValue == "function") this.setValue(this._inputComponent.getValue()); else if (typeof this._inputComponent.getText == "function") this.setValue(this._inputComponent.getText()); else this.setValue(String(this._inputComponent)); } else this.setValue(oDialogResult); if (this._dialog) { this._dialog.setDialogResult(this.getValue()); this._dialog.close(); }};BiOptionPane.createMessageDialog = function(oMessage, sCaption, sMessageType, oImage){ var op = new BiOptionPane(oMessage, sMessageType || "information", "default", oImage); return op.createDialog(sCaption || "Message");};BiOptionPane.createOptionDialog = function(oMessage, sCaption, sMessageType, sOptionType, oImage, oOptions, oInitialValue){ var op = new BiOptionPane(oMessage, sMessageType, sOptionType, oImage, oOptions, oInitialValue); return op.createDialog(sCaption);};BiOptionPane.createConfirmDialog = function(oMessage, sCaption, sMessageType, sOptionType, oImage){ var op = new BiOptionPane(oMessage, sMessageType || "question", sOptionType || "yesnocancel", oImage); return op.createDialog(sCaption || "Select an Option");};BiOptionPane.createInputDialog = function(oMessage, sCaption, sMessageType, oImage, sDefaultValue){ var op = new BiOptionPane(oMessage, sMessageType || "question", "okcancel", oImage); op.setInputComponent(new BiTextField(sDefaultValue)); var d = op.createDialog(sCaption || "Input"); d.setDefaultFocusedComponent(op.getInputComponent()); return d;};function BiDialog(sCaption){ BiWindow.call(this, sCaption); this.setSize(200, 100); this.setShowMinimize(false); this.setShowMaximize(false); this.setShowIcon(false); this.setShowClose(false); this.setResizable(false); this.setCanMinimize(false); BiWindow.prototype.setVisible.call(this, false);}_p = BiDialog.prototype = new BiWindow;_p._className = "BiDialog";_p._dialogResult = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -