37c0a8f12fac88a48dd450eddfbca5bfdd3b1b04
[jalviewjs.git] / site / swingjs / j2s / javax / swing / JSpinner.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.awt.LayoutManager", "java.beans.PropertyChangeListener", "javax.swing.Action", "$.JComponent", "$.JFormattedTextField", "$.JPanel", "javax.swing.event.ChangeListener", "javax.swing.text.DocumentFilter", "$.NumberFormatter"], "javax.swing.JSpinner", ["java.lang.IllegalArgumentException", "java.awt.Dimension", "java.text.DecimalFormat", "javax.swing.SpinnerListModel", "$.SpinnerNumberModel", "$.UIManager", "javax.swing.event.ChangeEvent", "javax.swing.text.DefaultFormatterFactory"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.model = null;
5 this.editor = null;
6 this.modelListener = null;
7 this.changeEvent = null;
8 this.editorExplicitlySet = false;
9 if (!Clazz.isClassDefined ("javax.swing.JSpinner.ModelListener")) {
10 javax.swing.JSpinner.$JSpinner$ModelListener$ ();
11 }
12 Clazz.instantialize (this, arguments);
13 }, javax.swing, "JSpinner", javax.swing.JComponent);
14 Clazz.makeConstructor (c$, 
15 function (model) {
16 Clazz.superConstructor (this, javax.swing.JSpinner, []);
17 this.model = model;
18 this.editor = this.createEditor (model);
19 this.setUIProperty ("opaque", new Boolean (true));
20 this.updateUI ();
21 }, "javax.swing.SpinnerModel");
22 Clazz.makeConstructor (c$, 
23 function () {
24 this.construct ( new javax.swing.SpinnerNumberModel ());
25 });
26 Clazz.overrideMethod (c$, "getUI", 
27 function () {
28 return this.ui;
29 });
30 Clazz.overrideMethod (c$, "getUIClassID", 
31 function () {
32 return "SpinnerUI";
33 });
34 Clazz.overrideMethod (c$, "updateUI", 
35 function () {
36 this.setUI (javax.swing.UIManager.getUI (this));
37 this.invalidate ();
38 });
39 Clazz.defineMethod (c$, "createEditor", 
40 function (model) {
41 if (Clazz.instanceOf (model, javax.swing.SpinnerListModel)) {
42 return  new javax.swing.JSpinner.ListEditor (this);
43 } else if (Clazz.instanceOf (model, javax.swing.SpinnerNumberModel)) {
44 return  new javax.swing.JSpinner.NumberEditor (this);
45 } else {
46 return  new javax.swing.JSpinner.DefaultEditor (this);
47 }}, "javax.swing.SpinnerModel");
48 Clazz.defineMethod (c$, "setModel", 
49 function (model) {
50 if (model == null) {
51 throw  new IllegalArgumentException ("null model");
52 }if (!model.equals (this.model)) {
53 var oldModel = this.model;
54 this.model = model;
55 if (this.modelListener != null) {
56 oldModel.removeChangeListener (this.modelListener);
57 this.model.addChangeListener (this.modelListener);
58 }this.firePropertyChangeObject ("model", oldModel, model);
59 if (!this.editorExplicitlySet) {
60 this.setEditor (this.createEditor (model));
61 this.editorExplicitlySet = false;
62 }this.repaint ();
63 this.revalidate ();
64 }}, "javax.swing.SpinnerModel");
65 Clazz.defineMethod (c$, "getModel", 
66 function () {
67 return this.model;
68 });
69 Clazz.defineMethod (c$, "getValue", 
70 function () {
71 return this.getModel ().getValue ();
72 });
73 Clazz.defineMethod (c$, "setValue", 
74 function (value) {
75 this.getModel ().setValue (value);
76 }, "~O");
77 Clazz.defineMethod (c$, "getNextValue", 
78 function () {
79 return this.getModel ().getNextValue ();
80 });
81 Clazz.defineMethod (c$, "addChangeListener", 
82 function (listener) {
83 if (this.modelListener == null) {
84 this.modelListener = Clazz.innerTypeInstance (javax.swing.JSpinner.ModelListener, this, null);
85 this.getModel ().addChangeListener (this.modelListener);
86 }this.listenerList.add (javax.swing.event.ChangeListener, listener);
87 }, "javax.swing.event.ChangeListener");
88 Clazz.defineMethod (c$, "removeChangeListener", 
89 function (listener) {
90 this.listenerList.remove (javax.swing.event.ChangeListener, listener);
91 }, "javax.swing.event.ChangeListener");
92 Clazz.defineMethod (c$, "getChangeListeners", 
93 function () {
94 return this.listenerList.getListeners (javax.swing.event.ChangeListener);
95 });
96 Clazz.defineMethod (c$, "fireStateChanged", 
97 function () {
98 var listeners = this.listenerList.getListenerList ();
99 for (var i = listeners.length - 2; i >= 0; i -= 2) {
100 if (listeners[i] === javax.swing.event.ChangeListener) {
101 if (this.changeEvent == null) {
102 this.changeEvent =  new javax.swing.event.ChangeEvent (this);
103 }(listeners[i + 1]).stateChanged (this.changeEvent);
104 }}
105 });
106 Clazz.defineMethod (c$, "getPreviousValue", 
107 function () {
108 return this.getModel ().getPreviousValue ();
109 });
110 Clazz.defineMethod (c$, "setEditor", 
111 function (editor) {
112 if (editor == null) {
113 throw  new IllegalArgumentException ("null editor");
114 }if (!editor.equals (this.editor)) {
115 var oldEditor = this.editor;
116 this.editor = editor;
117 if (Clazz.instanceOf (oldEditor, javax.swing.JSpinner.DefaultEditor)) {
118 (oldEditor).dismiss (this);
119 }this.editorExplicitlySet = true;
120 this.firePropertyChangeObject ("editor", oldEditor, editor);
121 this.revalidate ();
122 this.repaint ();
123 }}, "javax.swing.JComponent");
124 Clazz.defineMethod (c$, "getEditor", 
125 function () {
126 return this.editor;
127 });
128 Clazz.defineMethod (c$, "commitEdit", 
129 function () {
130 var editor = this.getEditor ();
131 if (Clazz.instanceOf (editor, javax.swing.JSpinner.DefaultEditor)) {
132 (editor).commitEdit ();
133 }});
134 c$.$JSpinner$ModelListener$ = function () {
135 Clazz.pu$h(self.c$);
136 c$ = Clazz.decorateAsClass (function () {
137 Clazz.prepareCallback (this, arguments);
138 Clazz.instantialize (this, arguments);
139 }, javax.swing.JSpinner, "ModelListener", null, javax.swing.event.ChangeListener);
140 Clazz.overrideMethod (c$, "stateChanged", 
141 function (a) {
142 this.b$["javax.swing.JSpinner"].fireStateChanged ();
143 }, "javax.swing.event.ChangeEvent");
144 c$ = Clazz.p0p ();
145 };
146 Clazz.pu$h(self.c$);
147 c$ = Clazz.declareType (javax.swing.JSpinner, "DefaultEditor", javax.swing.JPanel, [javax.swing.event.ChangeListener, java.beans.PropertyChangeListener, java.awt.LayoutManager]);
148 Clazz.makeConstructor (c$, 
149 function (a) {
150 Clazz.superConstructor (this, javax.swing.JSpinner.DefaultEditor, [null]);
151 var b =  new javax.swing.JFormattedTextField ();
152 b.setName ("Spinner.formattedTextField");
153 b.setValue (a.getValue ());
154 b.addPropertyChangeListener (this);
155 b.setEditable (false);
156 b.setInheritsPopupMenu (true);
157 var c = a.getToolTipText ();
158 if (c != null) {
159 b.setToolTipText (c);
160 }this.add (b);
161 this.setLayout (this);
162 a.addChangeListener (this);
163 var d = b.getActionMap ();
164 if (d != null) {
165 d.put ("increment", javax.swing.JSpinner.DISABLED_ACTION);
166 d.put ("decrement", javax.swing.JSpinner.DISABLED_ACTION);
167 }}, "javax.swing.JSpinner");
168 Clazz.defineMethod (c$, "dismiss", 
169 function (a) {
170 a.removeChangeListener (this);
171 }, "javax.swing.JSpinner");
172 Clazz.defineMethod (c$, "getSpinner", 
173 function () {
174 for (var a = this; a != null; a = a.getParent ()) {
175 if (Clazz.instanceOf (a, javax.swing.JSpinner)) {
176 return a;
177 }}
178 return null;
179 });
180 Clazz.defineMethod (c$, "getTextField", 
181 function () {
182 return this.getComponent (0);
183 });
184 Clazz.overrideMethod (c$, "stateChanged", 
185 function (a) {
186 var b = (a.getSource ());
187 this.getTextField ().setValue (b.getValue ());
188 }, "javax.swing.event.ChangeEvent");
189 Clazz.overrideMethod (c$, "propertyChange", 
190 function (a) {
191 var b = this.getSpinner ();
192 if (b == null) {
193 return;
194 }var c = a.getSource ();
195 var d = a.getPropertyName ();
196 if ((Clazz.instanceOf (c, javax.swing.JFormattedTextField)) && "value".equals (d)) {
197 var e = b.getValue ();
198 try {
199 b.setValue (this.getTextField ().getValue ());
200 } catch (iae) {
201 if (Clazz.exceptionOf (iae, IllegalArgumentException)) {
202 try {
203 (c).setValue (e);
204 } catch (iae2) {
205 if (Clazz.exceptionOf (iae2, IllegalArgumentException)) {
206 } else {
207 throw iae2;
208 }
209 }
210 } else {
211 throw iae;
212 }
213 }
214 }}, "java.beans.PropertyChangeEvent");
215 Clazz.overrideMethod (c$, "addLayoutComponent", 
216 function (a, b) {
217 }, "~S,java.awt.Component");
218 Clazz.overrideMethod (c$, "removeLayoutComponent", 
219 function (a) {
220 }, "java.awt.Component");
221 Clazz.defineMethod (c$, "insetSize", 
222  function (a) {
223 var b = a.getInsets ();
224 var c = b.left + b.right;
225 var d = b.top + b.bottom;
226 return  new java.awt.Dimension (c, d);
227 }, "java.awt.Container");
228 Clazz.overrideMethod (c$, "preferredLayoutSize", 
229 function (a) {
230 var b = this.insetSize (a);
231 if (a.getComponentCount () > 0) {
232 var c = this.getComponent (0).getPreferredSize ();
233 b.width += c.width;
234 b.height += c.height;
235 }return b;
236 }, "java.awt.Container");
237 Clazz.overrideMethod (c$, "minimumLayoutSize", 
238 function (a) {
239 var b = this.insetSize (a);
240 if (a.getComponentCount () > 0) {
241 var c = this.getComponent (0).getMinimumSize ();
242 b.width += c.width;
243 b.height += c.height;
244 }return b;
245 }, "java.awt.Container");
246 Clazz.overrideMethod (c$, "layoutContainer", 
247 function (a) {
248 if (a.getComponentCount () > 0) {
249 var b = a.getInsets ();
250 var c = a.getWidth () - (b.left + b.right);
251 var d = a.getHeight () - (b.top + b.bottom);
252 this.getComponent (0).setBounds (b.left, b.top, c, d);
253 }}, "java.awt.Container");
254 Clazz.defineMethod (c$, "commitEdit", 
255 function () {
256 });
257 Clazz.defineMethod (c$, "getBaseline", 
258 function (a, b) {
259 Clazz.superCall (this, javax.swing.JSpinner.DefaultEditor, "getBaseline", [a, b]);
260 var c = this.getInsets ();
261 a = a - c.left - c.right;
262 b = b - c.top - c.bottom;
263 var d = this.getComponent (0).getBaseline (a, b);
264 if (d >= 0) {
265 return d + c.top;
266 }return -1;
267 }, "~N,~N");
268 Clazz.overrideMethod (c$, "getBaselineResizeBehavior", 
269 function () {
270 return this.getComponent (0).getBaselineResizeBehavior ();
271 });
272 c$ = Clazz.p0p ();
273 Clazz.pu$h(self.c$);
274 c$ = Clazz.decorateAsClass (function () {
275 this.model = null;
276 Clazz.instantialize (this, arguments);
277 }, javax.swing.JSpinner, "NumberEditorFormatter", javax.swing.text.NumberFormatter);
278 Clazz.makeConstructor (c$, 
279 function (a, b) {
280 Clazz.superConstructor (this, javax.swing.JSpinner.NumberEditorFormatter, [b]);
281 this.model = a;
282 this.setValueClass (a.getValue ().getClass ());
283 }, "javax.swing.SpinnerNumberModel,java.text.NumberFormat");
284 Clazz.overrideMethod (c$, "setMinimum", 
285 function (a) {
286 this.model.setMinimum (a);
287 }, "Comparable");
288 Clazz.overrideMethod (c$, "getMinimum", 
289 function () {
290 return this.model.getMinimum ();
291 });
292 Clazz.overrideMethod (c$, "setMaximum", 
293 function (a) {
294 this.model.setMaximum (a);
295 }, "Comparable");
296 Clazz.overrideMethod (c$, "getMaximum", 
297 function () {
298 return this.model.getMaximum ();
299 });
300 c$ = Clazz.p0p ();
301 Clazz.pu$h(self.c$);
302 c$ = Clazz.declareType (javax.swing.JSpinner, "NumberEditor", javax.swing.JSpinner.DefaultEditor);
303 c$.getDefaultPattern = Clazz.defineMethod (c$, "getDefaultPattern", 
304  function (a) {
305 return null;
306 }, "java.util.Locale");
307 Clazz.makeConstructor (c$, 
308 function (a) {
309 this.construct (a, javax.swing.JSpinner.NumberEditor.getDefaultPattern (a.getLocale ()));
310 }, "javax.swing.JSpinner");
311 Clazz.makeConstructor (c$, 
312 function (a, b) {
313 this.construct (a,  new java.text.DecimalFormat (b));
314 }, "javax.swing.JSpinner,~S");
315 Clazz.makeConstructor (c$, 
316  function (a, b) {
317 Clazz.superConstructor (this, javax.swing.JSpinner.NumberEditor, [a]);
318 if (!(Clazz.instanceOf (a.getModel (), javax.swing.SpinnerNumberModel))) {
319 throw  new IllegalArgumentException ("model not a SpinnerNumberModel");
320 }var c = a.getModel ();
321 var d =  new javax.swing.JSpinner.NumberEditorFormatter (c, b);
322 var e =  new javax.swing.text.DefaultFormatterFactory (d);
323 var f = this.getTextField ();
324 f.setEditable (true);
325 f.setFormatterFactory (e);
326 f.setHorizontalAlignment (4);
327 try {
328 var g = d.valueToString (c.getMinimum ());
329 var h = d.valueToString (c.getMaximum ());
330 f.setColumns (Math.max (g.length, h.length));
331 } catch (e) {
332 if (Clazz.exceptionOf (e, java.text.ParseException)) {
333 } else {
334 throw e;
335 }
336 }
337 }, "javax.swing.JSpinner,java.text.DecimalFormat");
338 Clazz.defineMethod (c$, "getFormat", 
339 function () {
340 return ((this.getTextField ().getFormatter ())).getFormat ();
341 });
342 Clazz.defineMethod (c$, "getModel", 
343 function () {
344 return (this.getSpinner ().getModel ());
345 });
346 c$ = Clazz.p0p ();
347 Clazz.pu$h(self.c$);
348 c$ = Clazz.decorateAsClass (function () {
349 if (!Clazz.isClassDefined ("javax.swing.JSpinner.ListEditor.ListFormatter")) {
350 javax.swing.JSpinner.ListEditor.$JSpinner$ListEditor$ListFormatter$ ();
351 }
352 Clazz.instantialize (this, arguments);
353 }, javax.swing.JSpinner, "ListEditor", javax.swing.JSpinner.DefaultEditor);
354 Clazz.makeConstructor (c$, 
355 function (a) {
356 Clazz.superConstructor (this, javax.swing.JSpinner.ListEditor, [a]);
357 if (!(Clazz.instanceOf (a.getModel (), javax.swing.SpinnerListModel))) {
358 throw  new IllegalArgumentException ("model not a SpinnerListModel");
359 }this.getTextField ().setEditable (true);
360 this.getTextField ().setFormatterFactory ( new javax.swing.text.DefaultFormatterFactory (Clazz.innerTypeInstance (javax.swing.JSpinner.ListEditor.ListFormatter, this, null)));
361 }, "javax.swing.JSpinner");
362 Clazz.defineMethod (c$, "getModel", 
363 function () {
364 return (this.getSpinner ().getModel ());
365 });
366 c$.$JSpinner$ListEditor$ListFormatter$ = function () {
367 Clazz.pu$h(self.c$);
368 c$ = Clazz.decorateAsClass (function () {
369 Clazz.prepareCallback (this, arguments);
370 this.filter = null;
371 if (!Clazz.isClassDefined ("javax.swing.JSpinner.ListEditor.ListFormatter.Filter")) {
372 javax.swing.JSpinner.ListEditor.ListFormatter.$JSpinner$ListEditor$ListFormatter$Filter$ ();
373 }
374 Clazz.instantialize (this, arguments);
375 }, javax.swing.JSpinner.ListEditor, "ListFormatter", javax.swing.JFormattedTextField.AbstractFormatter);
376 Clazz.overrideMethod (c$, "valueToString", 
377 function (a) {
378 if (a == null) {
379 return "";
380 }return a.toString ();
381 }, "~O");
382 Clazz.overrideMethod (c$, "stringToValue", 
383 function (a) {
384 return a;
385 }, "~S");
386 Clazz.overrideMethod (c$, "getDocumentFilter", 
387 function () {
388 if (this.filter == null) {
389 this.filter = Clazz.innerTypeInstance (javax.swing.JSpinner.ListEditor.ListFormatter.Filter, this, null);
390 }return this.filter;
391 });
392 c$.$JSpinner$ListEditor$ListFormatter$Filter$ = function () {
393 Clazz.pu$h(self.c$);
394 c$ = Clazz.decorateAsClass (function () {
395 Clazz.prepareCallback (this, arguments);
396 Clazz.instantialize (this, arguments);
397 }, javax.swing.JSpinner.ListEditor.ListFormatter, "Filter", javax.swing.text.DocumentFilter);
398 Clazz.defineMethod (c$, "replace", 
399 function (a, b, c, d, e) {
400 if (d != null && (b + c) == a.getDocument ().getLength ()) {
401 var f = this.b$["javax.swing.JSpinner.ListEditor"].getModel ().findNextMatch (a.getDocument ().getText (0, b) + d);
402 var g = (f != null) ? f.toString () : null;
403 if (g != null) {
404 a.remove (0, b + c);
405 a.insertString (0, g, null);
406 this.b$["javax.swing.JSpinner.ListEditor.ListFormatter"].getFormattedTextField ().select (b + d.length, g.length);
407 return;
408 }}Clazz.superCall (this, javax.swing.JSpinner.ListEditor.ListFormatter.Filter, "replace", [a, b, c, d, e]);
409 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
410 Clazz.overrideMethod (c$, "insertString", 
411 function (a, b, c, d) {
412 this.replace (a, b, 0, c, d);
413 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~S,javax.swing.text.AttributeSet");
414 c$ = Clazz.p0p ();
415 };
416 c$ = Clazz.p0p ();
417 };
418 c$ = Clazz.p0p ();
419 Clazz.pu$h(self.c$);
420 c$ = Clazz.declareType (javax.swing.JSpinner, "DisabledAction", null, javax.swing.Action);
421 Clazz.overrideMethod (c$, "getValue", 
422 function (a) {
423 return null;
424 }, "~S");
425 Clazz.overrideMethod (c$, "putValue", 
426 function (a, b) {
427 }, "~S,~O");
428 Clazz.overrideMethod (c$, "setEnabled", 
429 function (a) {
430 }, "~B");
431 Clazz.overrideMethod (c$, "isEnabled", 
432 function () {
433 return false;
434 });
435 Clazz.overrideMethod (c$, "addPropertyChangeListener", 
436 function (a) {
437 }, "java.beans.PropertyChangeListener");
438 Clazz.overrideMethod (c$, "removePropertyChangeListener", 
439 function (a) {
440 }, "java.beans.PropertyChangeListener");
441 Clazz.overrideMethod (c$, "actionPerformed", 
442 function (a) {
443 }, "java.awt.event.ActionEvent");
444 c$ = Clazz.p0p ();
445 Clazz.defineStatics (c$,
446 "$uiClassID", "SpinnerUI");
447 c$.DISABLED_ACTION = c$.prototype.DISABLED_ACTION =  new javax.swing.JSpinner.DisabledAction ();
448 });