bdaae50c974871f9f9e84a3b9672f3757156820e
[jalviewjs.git] / site / j2s / javax / swing / DefaultBoundedRangeModel.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.BoundedRangeModel", "javax.swing.event.EventListenerList"], "javax.swing.DefaultBoundedRangeModel", ["java.lang.IllegalArgumentException", "javax.swing.event.ChangeEvent", "$.ChangeListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.changeEvent = null;
5 this.listenerList = null;
6 this.value = 0;
7 this.extent = 0;
8 this.min = 0;
9 this.max = 100;
10 this.isAdjusting = false;
11 Clazz.instantialize (this, arguments);
12 }, javax.swing, "DefaultBoundedRangeModel", null, javax.swing.BoundedRangeModel);
13 Clazz.prepareFields (c$, function () {
14 this.listenerList =  new javax.swing.event.EventListenerList ();
15 });
16 Clazz.makeConstructor (c$, 
17 function () {
18 });
19 Clazz.makeConstructor (c$, 
20 function (value, extent, min, max) {
21 if ((max >= min) && (value >= min) && ((value + extent) >= value) && ((value + extent) <= max)) {
22 this.value = value;
23 this.extent = extent;
24 this.min = min;
25 this.max = max;
26 } else {
27 throw  new IllegalArgumentException ("invalid range properties");
28 }}, "~N,~N,~N,~N");
29 Clazz.overrideMethod (c$, "getValue", 
30 function () {
31 return this.value;
32 });
33 Clazz.overrideMethod (c$, "getExtent", 
34 function () {
35 return this.extent;
36 });
37 Clazz.overrideMethod (c$, "getMinimum", 
38 function () {
39 return this.min;
40 });
41 Clazz.overrideMethod (c$, "getMaximum", 
42 function () {
43 return this.max;
44 });
45 Clazz.overrideMethod (c$, "setValue", 
46 function (n) {
47 n = Math.min (n, 2147483647 - this.extent);
48 var newValue = Math.max (n, this.min);
49 if (newValue + this.extent > this.max) {
50 newValue = this.max - this.extent;
51 }this.setRangeProperties (newValue, this.extent, this.min, this.max, this.isAdjusting);
52 }, "~N");
53 Clazz.overrideMethod (c$, "setExtent", 
54 function (n) {
55 var newExtent = Math.max (0, n);
56 if (this.value + newExtent > this.max) {
57 newExtent = this.max - this.value;
58 }this.setRangeProperties (this.value, newExtent, this.min, this.max, this.isAdjusting);
59 }, "~N");
60 Clazz.overrideMethod (c$, "setMinimum", 
61 function (n) {
62 var newMax = Math.max (n, this.max);
63 var newValue = Math.max (n, this.value);
64 var newExtent = Math.min (newMax - newValue, this.extent);
65 this.setRangeProperties (newValue, newExtent, n, newMax, this.isAdjusting);
66 }, "~N");
67 Clazz.overrideMethod (c$, "setMaximum", 
68 function (n) {
69 var newMin = Math.min (n, this.min);
70 var newExtent = Math.min (n - newMin, this.extent);
71 var newValue = Math.min (n - newExtent, this.value);
72 this.setRangeProperties (newValue, newExtent, newMin, n, this.isAdjusting);
73 }, "~N");
74 Clazz.overrideMethod (c$, "setValueIsAdjusting", 
75 function (b) {
76 this.setRangeProperties (this.value, this.extent, this.min, this.max, b);
77 }, "~B");
78 Clazz.overrideMethod (c$, "getValueIsAdjusting", 
79 function () {
80 return this.isAdjusting;
81 });
82 Clazz.overrideMethod (c$, "setRangeProperties", 
83 function (newValue, newExtent, newMin, newMax, adjusting) {
84 if (newMin > newMax) {
85 newMin = newMax;
86 }if (newValue > newMax) {
87 newMax = newValue;
88 }if (newValue < newMin) {
89 newMin = newValue;
90 }if ((newExtent + newValue) > newMax) {
91 newExtent = newMax - newValue;
92 }if (newExtent < 0) {
93 newExtent = 0;
94 }var isChange = (newValue != this.value) || (newExtent != this.extent) || (newMin != this.min) || (newMax != this.max) || (adjusting != this.isAdjusting);
95 if (isChange) {
96 this.value = newValue;
97 this.extent = newExtent;
98 this.min = newMin;
99 this.max = newMax;
100 this.isAdjusting = adjusting;
101 this.fireStateChanged ();
102 }}, "~N,~N,~N,~N,~B");
103 Clazz.overrideMethod (c$, "addChangeListener", 
104 function (l) {
105 this.listenerList.add (javax.swing.event.ChangeListener, l);
106 }, "javax.swing.event.ChangeListener");
107 Clazz.overrideMethod (c$, "removeChangeListener", 
108 function (l) {
109 this.listenerList.remove (javax.swing.event.ChangeListener, l);
110 }, "javax.swing.event.ChangeListener");
111 Clazz.defineMethod (c$, "getChangeListeners", 
112 function () {
113 return this.listenerList.getListeners (javax.swing.event.ChangeListener);
114 });
115 Clazz.defineMethod (c$, "fireStateChanged", 
116 function () {
117 var listeners = this.listenerList.getListenerList ();
118 for (var i = listeners.length - 2; i >= 0; i -= 2) {
119 if (listeners[i] === javax.swing.event.ChangeListener) {
120 if (this.changeEvent == null) {
121 this.changeEvent =  new javax.swing.event.ChangeEvent (this);
122 }(listeners[i + 1]).stateChanged (this.changeEvent);
123 }}
124 });
125 Clazz.overrideMethod (c$, "toString", 
126 function () {
127 var modelString = "value=" + this.getValue () + ", " + "extent=" + this.getExtent () + ", " + "min=" + this.getMinimum () + ", " + "max=" + this.getMaximum () + ", " + "adj=" + this.getValueIsAdjusting ();
128 return this.getClass ().getName () + "[" + modelString + "]";
129 });
130 Clazz.defineMethod (c$, "getListeners", 
131 function (listenerType) {
132 return this.listenerList.getListeners (listenerType);
133 }, "Class");
134 });