JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / javax / swing / SpinnerDateModel.js
1 Clazz.declarePackage ("javax.swing");\r
2 Clazz.load (["javax.swing.AbstractSpinnerModel"], "javax.swing.SpinnerDateModel", ["java.lang.IllegalArgumentException", "java.util.Calendar", "$.Date"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.start = null;\r
5 this.end = null;\r
6 this.value = null;\r
7 this.calendarField = 0;\r
8 Clazz.instantialize (this, arguments);\r
9 }, javax.swing, "SpinnerDateModel", javax.swing.AbstractSpinnerModel);\r
10 Clazz.defineMethod (c$, "calendarFieldOK", \r
11  function (calendarField) {\r
12 switch (calendarField) {\r
13 case 0:\r
14 case 1:\r
15 case 2:\r
16 case 3:\r
17 case 4:\r
18 case 5:\r
19 case 6:\r
20 case 7:\r
21 case 8:\r
22 case 9:\r
23 case 10:\r
24 case 11:\r
25 case 12:\r
26 case 13:\r
27 case 14:\r
28 return true;\r
29 default:\r
30 return false;\r
31 }\r
32 }, "~N");\r
33 Clazz.makeConstructor (c$, \r
34 function (value, start, end, calendarField) {\r
35 Clazz.superConstructor (this, javax.swing.SpinnerDateModel, []);\r
36 if (value == null) {\r
37 throw  new IllegalArgumentException ("value is null");\r
38 }if (!this.calendarFieldOK (calendarField)) {\r
39 throw  new IllegalArgumentException ("invalid calendarField");\r
40 }if (!(((start == null) || (start.compareTo (value) <= 0)) && ((end == null) || (end.compareTo (value) >= 0)))) {\r
41 throw  new IllegalArgumentException ("(start <= value <= end) is false");\r
42 }this.value = java.util.Calendar.getInstance ();\r
43 this.start = start;\r
44 this.end = end;\r
45 this.calendarField = calendarField;\r
46 this.value.setTime (value);\r
47 }, "java.util.Date,Comparable,Comparable,~N");\r
48 Clazz.makeConstructor (c$, \r
49 function () {\r
50 this.construct ( new java.util.Date (), null, null, 5);\r
51 });\r
52 Clazz.defineMethod (c$, "setStart", \r
53 function (start) {\r
54 if ((start == null) ? (this.start != null) : !start.equals (this.start)) {\r
55 this.start = start;\r
56 this.fireStateChanged ();\r
57 }}, "Comparable");\r
58 Clazz.defineMethod (c$, "getStart", \r
59 function () {\r
60 return this.start;\r
61 });\r
62 Clazz.defineMethod (c$, "setEnd", \r
63 function (end) {\r
64 if ((end == null) ? (this.end != null) : !end.equals (this.end)) {\r
65 this.end = end;\r
66 this.fireStateChanged ();\r
67 }}, "Comparable");\r
68 Clazz.defineMethod (c$, "getEnd", \r
69 function () {\r
70 return this.end;\r
71 });\r
72 Clazz.defineMethod (c$, "setCalendarField", \r
73 function (calendarField) {\r
74 if (!this.calendarFieldOK (calendarField)) {\r
75 throw  new IllegalArgumentException ("invalid calendarField");\r
76 }if (calendarField != this.calendarField) {\r
77 this.calendarField = calendarField;\r
78 this.fireStateChanged ();\r
79 }}, "~N");\r
80 Clazz.defineMethod (c$, "getCalendarField", \r
81 function () {\r
82 return this.calendarField;\r
83 });\r
84 Clazz.overrideMethod (c$, "getNextValue", \r
85 function () {\r
86 var cal = java.util.Calendar.getInstance ();\r
87 cal.setTime (this.value.getTime ());\r
88 cal.add (this.calendarField, 1);\r
89 var next = cal.getTime ();\r
90 return ((this.end == null) || (this.end.compareTo (next) >= 0)) ? next : null;\r
91 });\r
92 Clazz.overrideMethod (c$, "getPreviousValue", \r
93 function () {\r
94 var cal = java.util.Calendar.getInstance ();\r
95 cal.setTime (this.value.getTime ());\r
96 cal.add (this.calendarField, -1);\r
97 var prev = cal.getTime ();\r
98 return ((this.start == null) || (this.start.compareTo (prev) <= 0)) ? prev : null;\r
99 });\r
100 Clazz.defineMethod (c$, "getDate", \r
101 function () {\r
102 return this.value.getTime ();\r
103 });\r
104 Clazz.overrideMethod (c$, "getValue", \r
105 function () {\r
106 return this.value.getTime ();\r
107 });\r
108 Clazz.overrideMethod (c$, "setValue", \r
109 function (value) {\r
110 if ((value == null) || !(Clazz.instanceOf (value, java.util.Date))) {\r
111 throw  new IllegalArgumentException ("illegal value");\r
112 }if (!value.equals (this.value.getTime ())) {\r
113 this.value.setTime (value);\r
114 this.fireStateChanged ();\r
115 }}, "~O");\r
116 });\r