/[colormatch]/trunk/range.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/range.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Sat Oct 2 23:24:01 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 6075 byte(s)
imported original ColorMatch

1 dpavlin 1 /*----------------------------------------------------------------------------\
2     | Range Class |
3     |-----------------------------------------------------------------------------|
4     | Created by Erik Arvidsson |
5     | (http://webfx.eae.net/contact.html#erik) |
6     | For WebFX (http://webfx.eae.net/) |
7     |-----------------------------------------------------------------------------|
8     | Used to model the data used when working with sliders, scrollbars and |
9     | progress bars. Based on the ideas of the javax.swing.BoundedRangeModel |
10     | interface defined by Sun for Java. http://java.sun.com/products/jfc/ |
11     | swingdoc-api-1.0.3/com/sun/java/swing/BoundedRangeModel.html | |
12     |-----------------------------------------------------------------------------|
13     | Copyright (c) 1999 - 2002 Erik Arvidsson |
14     |-----------------------------------------------------------------------------|
15     | This software is provided "as is", without warranty of any kind, express or |
16     | implied, including but not limited to the warranties of merchantability, |
17     | fitness for a particular purpose and noninfringement. In no event shall the |
18     | authors or copyright holders be liable for any claim, damages or other |
19     | liability, whether in an action of contract, tort or otherwise, arising |
20     | from, out of or in connection with the software or the use or other |
21     | dealings in the software. |
22     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
23     | This software is available under the three different licenses mentioned |
24     | below. To use this software you must chose, and qualify, for one of those. |
25     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
26     | The WebFX Non-Commercial License http://webfx.eae.net/license.html |
27     | Permits anyone the right to use the software in a non-commercial context |
28     | free of charge. |
29     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
30     | The WebFX Commercial license http://webfx.eae.net/commercial.html |
31     | Permits the license holder the right to use the software in a commercial |
32     | context. Such license must be specifically obtained, however it's valid for |
33     | any number of implementations of the licensed software. |
34     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
35     | GPL - The GNU General Public License http://www.gnu.org/licenses/gpl.txt |
36     | Permits anyone the right to use and modify the software without limitations |
37     | as long as proper credits are given and the original and modified source |
38     | code are included. Requires that the final product, software derivate from |
39     | the original source or any software utilizing a GPL component, such as |
40     | this, is also licensed under the GPL license. |
41     |-----------------------------------------------------------------------------|
42     | 2002-10-14 | Original version released |
43     |-----------------------------------------------------------------------------|
44     | Created 2002-10-14 | All changes are in the log above. | Updated 2002-10-14 |
45     \----------------------------------------------------------------------------*/
46    
47    
48     function Range() {
49     this._value = 0;
50     this._minimum = 0;
51     this._maximum = 100;
52     this._extent = 0;
53    
54     this._isChanging = false;
55     }
56    
57     Range.prototype.setValue = function (value) {
58     value = parseInt(value);
59     if (isNaN(value)) return;
60     if (this._value != value) {
61     if (value + this._extent > this._maximum)
62     this._value = this._maximum - this._extent;
63     else if (value < this._minimum)
64     this._value = this._minimum;
65     else
66     this._value = value;
67     if (!this._isChanging && typeof this.onchange == "function")
68     this.onchange();
69     }
70     };
71    
72     Range.prototype.getValue = function () {
73     return this._value;
74     };
75    
76     Range.prototype.setExtent = function (extent) {
77     if (this._extent != extent) {
78     if (extent < 0)
79     this._extent = 0;
80     else if (this._value + extent > this._maximum)
81     this._extent = this._maximum - this._value;
82     else
83     this._extent = extent;
84     if (!this._isChanging && typeof this.onchange == "function")
85     this.onchange();
86     }
87     };
88    
89     Range.prototype.getExtent = function () {
90     return this._extent;
91     };
92    
93     Range.prototype.setMinimum = function (minimum) {
94     if (this._minimum != minimum) {
95     var oldIsChanging = this._isChanging;
96     this._isChanging = true;
97    
98     this._minimum = minimum;
99    
100     if (minimum > this._value)
101     this.setValue(minimum);
102     if (minimum > this._maximum) {
103     this._extent = 0;
104     this.setMaximum(minimum);
105     this.setValue(minimum)
106     }
107     if (minimum + this._extent > this._maximum)
108     this._extent = this._maximum - this._minimum;
109    
110     this._isChanging = oldIsChanging;
111     if (!this._isChanging && typeof this.onchange == "function")
112     this.onchange();
113     }
114     };
115    
116     Range.prototype.getMinimum = function () {
117     return this._minimum;
118     };
119    
120     Range.prototype.setMaximum = function (maximum) {
121     if (this._maximum != maximum) {
122     var oldIsChanging = this._isChanging;
123     this._isChanging = true;
124    
125     this._maximum = maximum;
126    
127     if (maximum < this._value)
128     this.setValue(maximum - this._extent);
129     if (maximum < this._minimum) {
130     this._extent = 0;
131     this.setMinimum(maximum);
132     this.setValue(this._maximum);
133     }
134     if (maximum < this._minimum + this._extent)
135     this._extent = this._maximum - this._minimum;
136     if (maximum < this._value + this._extent)
137     this._extent = this._maximum - this._value;
138    
139     this._isChanging = oldIsChanging;
140     if (!this._isChanging && typeof this.onchange == "function")
141     this.onchange();
142     }
143     };
144    
145     Range.prototype.getMaximum = function () {
146     return this._maximum;
147     };

  ViewVC Help
Powered by ViewVC 1.1.26