1 /*----------------------------------------------------------------------------\
\r
3 |-----------------------------------------------------------------------------|
\r
4 | Created by Erik Arvidsson |
\r
5 | (http://webfx.eae.net/contact.html#erik) |
\r
6 | For WebFX (http://webfx.eae.net/) |
\r
7 |-----------------------------------------------------------------------------|
\r
8 | Used to model the data used when working with sliders, scrollbars and |
\r
9 | progress bars. Based on the ideas of the javax.swing.BoundedRangeModel |
\r
10 | interface defined by Sun for Java; http://java.sun.com/products/jfc/ |
\r
11 | swingdoc-api-1.0.3/com/sun/java/swing/BoundedRangeModel.html |
\r
12 |-----------------------------------------------------------------------------|
\r
13 | Copyright (c) 2002, 2005, 2006 Erik Arvidsson |
\r
14 |-----------------------------------------------------------------------------|
\r
15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
\r
16 | use this file except in compliance with the License. You may obtain a copy |
\r
17 | of the License at http://www.apache.org/licenses/LICENSE-2.0 |
\r
18 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
\r
19 | Unless required by applicable law or agreed to in writing, software |
\r
20 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
\r
21 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
\r
22 | License for the specific language governing permissions and limitations |
\r
23 | under the License. |
\r
24 |-----------------------------------------------------------------------------|
\r
25 | 2002-10-14 | Original version released |
\r
26 | 2005-10-27 | Use Math.round instead of Math.floor |
\r
27 | 2006-05-28 | Changed license to Apache Software License 2.0. |
\r
28 |-----------------------------------------------------------------------------|
\r
29 | Created 2002-10-14 | All changes are in the log above. | Updated 2006-05-28 |
\r
30 \----------------------------------------------------------------------------*/
\r
36 this._maximum = 100;
\r
39 this._isChanging = false;
\r
42 Range.prototype.setValue = function (value) {
\r
43 value = Math.round(parseFloat(value));
\r
44 if (isNaN(value)) return;
\r
45 if (this._value != value) {
\r
46 if (value + this._extent > this._maximum)
\r
47 this._value = this._maximum - this._extent;
\r
48 else if (value < this._minimum)
\r
49 this._value = this._minimum;
\r
51 this._value = value;
\r
52 if (!this._isChanging && typeof this.onchange == "function")
\r
57 Range.prototype.getValue = function () {
\r
61 Range.prototype.setExtent = function (extent) {
\r
62 if (this._extent != extent) {
\r
65 else if (this._value + extent > this._maximum)
\r
66 this._extent = this._maximum - this._value;
\r
68 this._extent = extent;
\r
69 if (!this._isChanging && typeof this.onchange == "function")
\r
74 Range.prototype.getExtent = function () {
\r
75 return this._extent;
\r
78 Range.prototype.setMinimum = function (minimum) {
\r
79 if (this._minimum != minimum) {
\r
80 var oldIsChanging = this._isChanging;
\r
81 this._isChanging = true;
\r
83 this._minimum = minimum;
\r
85 if (minimum > this._value)
\r
86 this.setValue(minimum);
\r
87 if (minimum > this._maximum) {
\r
89 this.setMaximum(minimum);
\r
90 this.setValue(minimum)
\r
92 if (minimum + this._extent > this._maximum)
\r
93 this._extent = this._maximum - this._minimum;
\r
95 this._isChanging = oldIsChanging;
\r
96 if (!this._isChanging && typeof this.onchange == "function")
\r
101 Range.prototype.getMinimum = function () {
\r
102 return this._minimum;
\r
105 Range.prototype.setMaximum = function (maximum) {
\r
106 if (this._maximum != maximum) {
\r
107 var oldIsChanging = this._isChanging;
\r
108 this._isChanging = true;
\r
110 this._maximum = maximum;
\r
112 if (maximum < this._value)
\r
113 this.setValue(maximum - this._extent);
\r
114 if (maximum < this._minimum) {
\r
116 this.setMinimum(maximum);
\r
117 this.setValue(this._maximum);
\r
119 if (maximum < this._minimum + this._extent)
\r
120 this._extent = this._maximum - this._minimum;
\r
121 if (maximum < this._value + this._extent)
\r
122 this._extent = this._maximum - this._value;
\r
124 this._isChanging = oldIsChanging;
\r
125 if (!this._isChanging && typeof this.onchange == "function")
\r
130 Range.prototype.getMaximum = function () {
\r
131 return this._maximum;
\r