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

📄 window.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
_p._defaultFocusedComponent = null;BiDialog.prototype.getDialogResult = function(){    return this._dialogResult;} ;BiDialog.prototype.setDialogResult = function(v){    this._dialogResult = v;} ;BiDialog.prototype.getDefaultFocusedComponent = function(){    return this._defaultFocusedComponent;} ;BiDialog.prototype.setDefaultFocusedComponent = function(v){    this._defaultFocusedComponent = v;} ;_p.centerDialog = function(){    var p = this.getParent();    if (!p)        return;    var cw = p.getClientWidth();    var ch = p.getClientHeight();    var w = this.getWidth();    var h = this.getHeight();    this.setLocation((cw - w) / 2, (ch - h) / 2);};_p.setVisible = function(b){    if (this._visible != b)    {        if (b && this._parent == null)            application.getWindow().add(this);        if (b)            this.centerDialog();        BiWindow.prototype.setVisible.call(this, b);        if (b)            this.setActive(b);        application.getWindow().updateGlassPane(this, b);        var dfc = this.getDefaultFocusedComponent();        if (b && dfc)        {            dfc.setFocused(true);            if (dfc instanceof BiTextField)                dfc.selectAll();        }        else if (b && this.getAcceptButton() && this.getAcceptButton().getCanFocus())            this.getAcceptButton().setFocused(true);        if (!b)            this.dispatchEvent(new BiEvent("dialogresult"));    }};_p.close = function(){    this.setVisible(false);    BiWindow.prototype.close.call(this);};BiDialog.createMessageDialog = BiOptionPane.createMessageDialog;BiDialog.createOptionDialog = BiOptionPane.createOptionDialog;BiDialog.createConfirmDialog = BiOptionPane.createConfirmDialog;BiDialog.createInputDialog = BiOptionPane.createInputDialog;function BiColorPicker(){    BiDialog.call(this, "Color");    var cp = this.getContentPane();    var l = this._colors.length;    this._items = new Array(l);    var item, i = 0;    for (var y = 0; y < 6; y++)    {        for (var x = 0; x < 8; x++)        {            item = new BiComponent;            item.setBackColor(this._colors[i]);            item.setBorder(this._insetBorder);            item.setBounds(5 + x * (this._itemWidth + this._itemGap), 5 + y * (this._itemHeight + this._itemGap),                           this._itemWidth,                           this._itemHeight);            cp.add(item);            this._items[i] = item;            i++;        }    }    this._colorBox = new BiComponent;    this._colorBox.setBounds(150, 230, 50, 25);    this._colorBox.setBackColor("red");    this._colorBox.setBorder(this._insetBorder);    cp.add(this._colorBox);    this._colorLabel = new BiLabel("Selected color:");    this._colorLabel.setAlign("right");    this._colorLabel.setBounds(5, 235, 140, 15);    cp.add(this._colorLabel);    this.setSize(518, 322);    var gridWidth = 8 * (this._itemWidth + this._itemGap) - 5;    this._hueBack = new BiComponent;    this._hueBack.setBorder(this._insetBorder);    this._hueBack.setBackColor("#000");    this._hueBack.setSize(250, 250);    this._hueBack.setLocation(gridWidth + 15, 5);    cp.add(this._hueBack);    this._hueImage = new BiImage(BiColorPicker.HUE_SATURATION_IMAGE_URI, 246, 246);    this._hueImage.setLocation(gridWidth + 15 + 2, 5 + 2);    cp.add(this._hueImage);    this._hueHandle = new BiImage(BiColorPicker.HUE_SATURATION_HANDLE_IMAGE_URI, 11, 11);    this._hueHandle.setLocation(gridWidth + 15 + 2 - 6, 5 + 2 - 6);    cp.add(this._hueHandle);    this._brightnessImage = new BiImage(BiColorPicker.BRIGHTNESS_IMAGE_URI, 19, 246);    this._brightnessImage.setBorder(this._insetBorder);    this._brightnessImage.setLocation(gridWidth + 280, 5);    cp.add(this._brightnessImage);    this._brightnessHandle = new BiImage(BiColorPicker.BRIGHTNESS_HANDLE_IMAGE_URI, 35, 11);    this._brightnessHandle.setLocation(gridWidth + 274, 0);    cp.add(this._brightnessHandle);    this.addEventListener("mouseup", this._onClick);    this._hueImage.addEventListener("mousedown", this._onHueDown, this);    this._hueHandle.addEventListener("mousedown", this._onHueDown, this);    this._brightnessImage.addEventListener("mousedown", this._onBrightnessDown, this);    this._brightnessHandle.addEventListener("mousedown", this._onBrightnessDown, this);    this._hueLabel = new BiLabel("Hue:");    this._satLabel = new BiLabel("Sat:");    this._lumLabel = new BiLabel("Lum:");    this._redLabel = new BiLabel("Red:");    this._greenLabel = new BiLabel("Green:");    this._blueLabel = new BiLabel("Blue:");    this._hueField = new BiSpinner;    this._satField = new BiSpinner;    this._lumField = new BiSpinner;    this._redField = new BiSpinner;    this._greenField = new BiSpinner;    this._blueField = new BiSpinner;    var tmp = ["hue", "sat", "lum", "red", "green", "blue"];    var f, l;    for (var i = 0; i < tmp.length; i++)    {        f = this["_" + tmp[i] + "Field"];        l = this["_" + tmp[i] + "Label"];        f.setMinimum(0);        f.setMaximum(255);        f.setWidth(50);        f.setTabIndex(i + 1);        l.setWidth(40);        l.setLabelFor(f);        l.setAlign("right");        cp.add(l);        cp.add(f);    }    this._hueField.setMaximum(360);    this._satField.setMaximum(100);    this._lumField.setMaximum(100);    for (var i = 0; i < tmp.length; i++)    {        f = this["_" + tmp[i] + "Field"];        f.addEventListener("change", this._onSpinnerChange, this);    }    var y = 145;    for (var i = 0; i < 3; i++)    {        f = this["_" + tmp[i] + "Field"];        l = this["_" + tmp[i] + "Label"];        l.setLocation(5, y + 2);        f.setLocation(50, y);        y += 25;    }    y = 145;    for (var i = 3; i < 6; i++)    {        f = this["_" + tmp[i] + "Field"];        l = this["_" + tmp[i] + "Label"];        l.setLocation(105, y + 2);        f.setLocation(150, y);        y += 25;    }    this._colorOkButton = new BiButton("OK");    this._colorCancelButton = new BiButton("Cancel");    this.setAcceptButton(this._colorOkButton);    this.setCancelButton(this._colorCancelButton);    cp.add(this._colorOkButton);    cp.add(this._colorCancelButton);    this._colorOkButton.setWidth(75);    this._cancelButton.setWidth(75);    this._colorCancelButton.setRight(5);    this._colorCancelButton.setBottom(5);    this._colorOkButton.setRight(85);    this._colorOkButton.setBottom(5);    this._colorOkButton.addEventListener("action", function(e)    {        this.setDialogResult(this.getRgbString());        this.close();    },                                   this);    this._colorCancelButton.addEventListener("action", function(e)    {        this.setDialogResult(null);        this.close();    },                                       this);    this._hsl = {        h: 0, s: 0, l: 1    };    this._rgb = {        r: 0, g: 0, b: 0    };    this.setRgb({        r: 255, g: 0, b: 0    });}var _p = BiColorPicker.prototype = new BiDialog;_p._className = "BiColorPicker";BiColorPicker.HUE_SATURATION_IMAGE_URI = application.getPath() + "images/huesaturation.jpg";BiColorPicker.HUE_SATURATION_HANDLE_IMAGE_URI = application.getPath() + "images/huesaturationhandle.gif";BiColorPicker.BRIGHTNESS_IMAGE_URI = application.getPath() + "images/brightness.jpg";BiColorPicker.BRIGHTNESS_HANDLE_IMAGE_URI = application.getPath() + "images/brightnesshandle.gif";_p._colors = ["rgb(255,128,128)", "rgb(255,255,128)", "rgb(128,255,128)", "rgb(0,155,128)",   "rgb(128,255,255)",              "rgb(0,128,255)",   "rgb(255,128,192)", "rgb(255,128,255)", "rgb(255,0,0)",     "rgb(255,255,0)",              "rgb(128,255,0)",   "rgb(0,255,64)",    "rgb(0,255,255)",   "rgb(0,128,192)",   "rgb(128,128,192)",              "rgb(255,0,255)",   "rgb(128,64,64)",   "rgb(255,128,64)",  "rgb(0,255,0)",     "rgb(0,128,128)",              "rgb(0,64,128)",    "rgb(128,128,255)", "rgb(128,0,64)",    "rgb(255,0,128)",   "rgb(128,0,0)",              "rgb(255,128,0)",   "rgb(0,128,0)",     "rgb(0,128,64)",    "rgb(0,0,255)",     "rgb(0,160,160)",              "rgb(128,0,128)",   "rgb(128,0,255)",   "rgb(64,0,0)",      "rgb(128,64,0)",    "rgb(0,64,0)",              "rgb(0,64,64)",     "rgb(0,0,128)",     "rgb(0,0,64)",      "rgb(64,0,64)",     "rgb(64,0,128)",              "rgb(0,0,0)",       "rgb(128,128,0)",   "rgb(128,128,64)",  "rgb(128,128,128)", "rgb(64,128,128)",              "rgb(192,192,192)", "rgb(32,0,32)",     "rgb(255,255,255)"];_p._insetBorder = new BiBorder(2, "inset");_p._itemWidth = 20;_p._itemHeight = 17;_p._itemGap = 5;_p._rgbString = "rgb(255,0,0)";_p._fireChange = true;BiColorPicker.hslToRgb = function(hsl){    var rgb = {    };    var h = hsl.h;    var s = hsl.s;    var l = hsl.l * 255;    if (s == 0)    {        rgb.r = rgb.g = rgb.b = l;        return rgb;    }    h = h / 60 % 6;    var i = Math.floor(h);    var f = h - i;    var p = l * (1 - s);    var q = l * (1 - s * f);    var t = l * (1 - s * (1 - f));    switch (i)    {        case 0:        rgb.r = l;        rgb.g = t;        rgb.b = p;        break;        case 1:        rgb.r = q;        rgb.g = l;        rgb.b = p;        break;        case 2:        rgb.r = p;        rgb.g = l;        rgb.b = t;        break;        case 3:        rgb.r = p;        rgb.g = q;        rgb.b = l;        break;        case 4:        rgb.r = t;        rgb.g = p;        rgb.b = l;        break;        default:        rgb.r = l;        rgb.g = p;        rgb.b = q;        break;    }    return rgb;};BiColorPicker.rgbToHsl = function(rgb){    var hsl = {    };    var min = Math.min(rgb.r, rgb.g, rgb.b);    var max = Math.max(rgb.r, rgb.g, rgb.b);    hsl.l = max;    var delta = max - min;    if (max != 0)        hsl.s = delta / max;    else    {        hsl.s = 0;        hsl.h = 0;        return hsl;    }    if (rgb.r == max)        hsl.h = (rgb.g - rgb.b) / delta;    else if (rgb.g == max)        hsl.h = 2 + (rgb.b - rgb.r) / delta;    else        hsl.h = 4 + (rgb.r - rgb.g) / delta;    hsl.h *= 60;    if (hsl.h < 0)        hsl.h += 360;    hsl.l = hsl.l / 255;    return hsl;};BiColorPicker.getRgbFromRgbString = function(s){    var re = /^rgb\s*\(\s*(\d+)\s*\,\s*(\d+)\s*\,\s*(\d+)\s*\)$/i;    var a = re.exec(s);    return {        r: Number(RegExp.$1), g: Number(RegExp.$2), b: Number(RegExp.$3)    };};BiColorPicker.getRgbStringFromRgb = function(rgb){    return "rgb(" + Math.floor(rgb.r) + "," + Math.floor(rgb.g) + "," + Math.floor(rgb.b) + ")";} ;_p.setRgbString = function(sValue){    this.setRgb(BiColorPicker.getRgbFromRgbString(sValue));} ;_p.getRgbString = function(){    return this._rgbString;} ;_p._onClick = function(e){    var t = e.getTarget();    if (this._items.contains(t))    {        this.setRgbString(t.getBackColor());    }};_p._onHueDown = function(e){    this._hueImage.addEventListener("mousemove", this._onHueMove, this);    this._hueImage.addEventListener("mouseup", this._onHueUp, this);    this._hueImage.addEventListener("losecapture", this._onHueUp, this);    this._hueImage.setCapture(true);    this._onHueMove(e);    e.preventDefault();};_p._onHueMove = function(e){    var width = this._hueImage.getWidth();    var height = this._hueImage.getHeight();    var left = Math.min(this._hueImage.getWidth(), Math.max(0, e.getScreenX() - this._hueImage.getScreenLeft()));    var top = Math.min(this._hueImage.getHeight(), Math.max(0, e.getScreenY() - this._hueImage.getScreenTop()));    var s = (1 - top / height);    var h = Math.max(0, Math.min(360, (360 * (left / width))));    this.setHsl({        h: h, s: s, l: this._hsl.l    });};_p._onHueUp = function(e){    this._hueImage.removeEventListener("mousemove", this._onHueMove, this);    this._hueImage.removeEventListener("mouseup", this._onHueUp, this);    this._hueImage.removeEventListener("losecapture", this._onHueUp, this);    this._hueImage.setCapture(false);};_p._onBrightnessDown = function(e){    this._brightnessImage.addEventListener("mousemove", this._onBrightnessMove, this);    this._brightnessImage.addEventListener("mouseup", this._onBrightnessUp, this);    this._brightnessImage.addEventListener("losecapture", this._onBrightnessUp, this);    this._brightnessImage.setCapture(true);    this._onBrightnessMove(e);    e.preventDefault();};_p._onBrightnessMove = function(e){    var height = this._brightnessImage.getHeight();    var top = Math.min(height, Math.max(0, e.getScreenY() - this._brightnessImage.getScreenTop()));    var l = (1 - top / height);    this.setHsl({        h: this._hsl.h, s: this._hsl.s, l: l    });};_p._onBrightnessUp = function(e){    this._brightnessImage.removeEventListener("mousemove", this._onBrightnessMove, this);    this._brightnessImage.removeEventListener("mouseup", this._onBrightnessUp, this);    this._brightnessImage.removeEventListener("losecapture", this._onBrightnessUp, this);    this._brightnessImage.setCapture(false);};_p._syncHandles = function(){    if (this._dontSync)        return;    var brightnessHeight = this._brightnessImage.getHeight();    var width = this._hueImage.getWidth();    var height = this._hueImage.getHeight();    this._hueHandle.setLeft(        this._hueImage.getLeft() - Math.floor(this._hueHandle.getWidth() / 2) + this._hsl.h / 360 * width);    this._hueHandle.setTop(        this._hueImage.getTop() - Math.floor(this._hueHandle.getHeight() / 2) + height - this._hsl.s * height);    this._brightnessHandle.setTop(brightnessHeight - this._hsl.l * brightnessHeight);    this._hueImage.setOpacity(this._hsl.l);};_p.setRgb = function(rgb){    this.setHsl(BiColorPicker.rgbToHsl(rgb));} ;_p.getRgb = function(){    return{        r: this._rgb.r, g: this._rgb.g, b: this._rgb.b    };} ;_p.setHsl = function(hsl){    if (this._hsl.h != hsl.h || this._hsl.s != hsl.s || this._hsl.l != hsl.l)    {        var oldFireChange = this._fireChange;        this._fireChange = false;        if (hsl.h == -1 || isNaN(hsl.h))            hsl = {                h: this._hsl.h, s: hsl.s, l: hsl.l            };        this._hsl = hsl;        this._rgb = BiColorPicker.hslToRgb(hsl);        this._hueField.setValue(Math.round(this._hsl.h));        this._satField.setValue(Math.round(100 * this._hsl.s));        this._lumFie

⌨️ 快捷键说明

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