6c772818b2627077ff412d00a8f888b5b88d377f
[jalviewjs.git] / site / j2s / javax / swing / SpinnerListModel.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.AbstractSpinnerModel"], "javax.swing.SpinnerListModel", ["java.lang.IllegalArgumentException", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.list = null;
5 this.index = 0;
6 Clazz.instantialize (this, arguments);
7 }, javax.swing, "SpinnerListModel", javax.swing.AbstractSpinnerModel);
8 Clazz.makeConstructor (c$, 
9 function (values) {
10 Clazz.superConstructor (this, javax.swing.SpinnerListModel, []);
11 if (values == null || values.size () == 0) {
12 throw  new IllegalArgumentException ("SpinnerListModel(List) expects non-null non-empty List");
13 }this.list = values;
14 this.index = 0;
15 }, "java.util.List");
16 Clazz.makeConstructor (c$, 
17 function (values) {
18 Clazz.superConstructor (this, javax.swing.SpinnerListModel, []);
19 if (values == null || values.length == 0) {
20 throw  new IllegalArgumentException ("SpinnerListModel(Object[]) expects non-null non-empty Object[]");
21 }this.list = java.util.Arrays.asList (values);
22 this.index = 0;
23 }, "~A");
24 Clazz.makeConstructor (c$, 
25 function () {
26 this.construct ( Clazz.newArray (-1, ["empty"]));
27 });
28 Clazz.defineMethod (c$, "getList", 
29 function () {
30 return this.list;
31 });
32 Clazz.defineMethod (c$, "setList", 
33 function (list) {
34 if ((list == null) || (list.size () == 0)) {
35 throw  new IllegalArgumentException ("invalid list");
36 }if (!list.equals (this.list)) {
37 this.list = list;
38 this.index = 0;
39 this.fireStateChanged ();
40 }}, "java.util.List");
41 Clazz.overrideMethod (c$, "getValue", 
42 function () {
43 return this.list.get (this.index);
44 });
45 Clazz.overrideMethod (c$, "setValue", 
46 function (elt) {
47 var index = this.list.indexOf (elt);
48 if (index == -1) {
49 throw  new IllegalArgumentException ("invalid sequence element");
50 } else if (index != this.index) {
51 this.index = index;
52 this.fireStateChanged ();
53 }}, "~O");
54 Clazz.overrideMethod (c$, "getNextValue", 
55 function () {
56 return (this.index >= (this.list.size () - 1)) ? null : this.list.get (this.index + 1);
57 });
58 Clazz.overrideMethod (c$, "getPreviousValue", 
59 function () {
60 return (this.index <= 0) ? null : this.list.get (this.index - 1);
61 });
62 Clazz.defineMethod (c$, "findNextMatch", 
63 function (substring) {
64 var max = this.list.size ();
65 if (max == 0) {
66 return null;
67 }var counter = this.index;
68 do {
69 var value = this.list.get (counter);
70 var string = value.toString ();
71 if (string != null && string.startsWith (substring)) {
72 return value;
73 }counter = (counter + 1) % max;
74 } while (counter != this.index);
75 return null;
76 }, "~S");
77 });