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