annotate geotemco/lib/slider/js/range.js @ 26:9f67e8afa1cc default tip

add new file for new LGService UI project
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 28 Sep 2017 23:58:34 +0200
parents 57bde4830927
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 /*----------------------------------------------------------------------------\
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
2 | Range Class |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 | Created by Erik Arvidsson |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 | (http://webfx.eae.net/contact.html#erik) |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 | For WebFX (http://webfx.eae.net/) |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 | Used to model the data used when working with sliders, scrollbars and |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9 | progress bars. Based on the ideas of the javax.swing.BoundedRangeModel |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 | interface defined by Sun for Java; http://java.sun.com/products/jfc/ |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 | swingdoc-api-1.0.3/com/sun/java/swing/BoundedRangeModel.html |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 | Copyright (c) 2002, 2005, 2006 Erik Arvidsson |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 | use this file except in compliance with the License. You may obtain a copy |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 | of the License at http://www.apache.org/licenses/LICENSE-2.0 |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 | Unless required by applicable law or agreed to in writing, software |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 | License for the specific language governing permissions and limitations |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 | under the License. |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 | 2002-10-14 | Original version released |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 | 2005-10-27 | Use Math.round instead of Math.floor |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 | 2006-05-28 | Changed license to Apache Software License 2.0. |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 |-----------------------------------------------------------------------------|
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 | Created 2002-10-14 | All changes are in the log above. | Updated 2006-05-28 |
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 \----------------------------------------------------------------------------*/
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 function Range() {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 this._value = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 this._minimum = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 this._maximum = 100;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 this._extent = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
38
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
39 this._isChanging = false;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 Range.prototype.setValue = function (value) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 value = Math.round(parseFloat(value));
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 if (isNaN(value)) return;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 if (this._value != value) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 if (value + this._extent > this._maximum)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 this._value = this._maximum - this._extent;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 else if (value < this._minimum)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 this._value = this._minimum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 else
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 this._value = value;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 if (!this._isChanging && typeof this.onchange == "function")
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 this.onchange();
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
56
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 Range.prototype.getValue = function () {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 return this._value;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 Range.prototype.setExtent = function (extent) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 if (this._extent != extent) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 if (extent < 0)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 this._extent = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 else if (this._value + extent > this._maximum)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 this._extent = this._maximum - this._value;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 else
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
68 this._extent = extent;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69 if (!this._isChanging && typeof this.onchange == "function")
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 this.onchange();
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
73
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 Range.prototype.getExtent = function () {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 return this._extent;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
77
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 Range.prototype.setMinimum = function (minimum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 if (this._minimum != minimum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 var oldIsChanging = this._isChanging;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 this._isChanging = true;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
82
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 this._minimum = minimum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
84
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 if (minimum > this._value)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 this.setValue(minimum);
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 if (minimum > this._maximum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 this._extent = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 this.setMaximum(minimum);
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 this.setValue(minimum)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 if (minimum + this._extent > this._maximum)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 this._extent = this._maximum - this._minimum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
94
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 this._isChanging = oldIsChanging;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
96 if (!this._isChanging && typeof this.onchange == "function")
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 this.onchange();
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
98 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
99 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
100
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 Range.prototype.getMinimum = function () {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
102 return this._minimum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
104
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 Range.prototype.setMaximum = function (maximum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
106 if (this._maximum != maximum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 var oldIsChanging = this._isChanging;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
108 this._isChanging = true;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
109
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 this._maximum = maximum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
111
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 if (maximum < this._value)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 this.setValue(maximum - this._extent);
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 if (maximum < this._minimum) {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 this._extent = 0;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
116 this.setMinimum(maximum);
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 this.setValue(this._maximum);
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
119 if (maximum < this._minimum + this._extent)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
120 this._extent = this._maximum - this._minimum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 if (maximum < this._value + this._extent)
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 this._extent = this._maximum - this._value;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
123
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 this._isChanging = oldIsChanging;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 if (!this._isChanging && typeof this.onchange == "function")
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 this.onchange();
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
127 }
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 };
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
129
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
130 Range.prototype.getMaximum = function () {
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
131 return this._maximum;
57bde4830927 first commit
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
132 };