Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / CardLayout.js
1 Clazz.declarePackage ("java.awt");
2 Clazz.load (["java.awt.LayoutManager2", "java.io.ObjectStreamField", "java.util.Hashtable", "$.Vector"], "java.awt.CardLayout", ["java.lang.IllegalArgumentException", "java.awt.Dimension"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.vector = null;
5 if (!Clazz.isClassDefined ("java.awt.CardLayout.Card")) {
6 java.awt.CardLayout.$CardLayout$Card$ ();
7 }
8 this.currentCard = 0;
9 this.hgap = 0;
10 this.vgap = 0;
11 Clazz.instantialize (this, arguments);
12 }, java.awt, "CardLayout", null, [java.awt.LayoutManager2, java.io.Serializable]);
13 Clazz.prepareFields (c$, function () {
14 this.vector =  new java.util.Vector ();
15 });
16 Clazz.makeConstructor (c$, 
17 function () {
18 this.construct (0, 0);
19 });
20 Clazz.makeConstructor (c$, 
21 function (hgap, vgap) {
22 this.hgap = hgap;
23 this.vgap = vgap;
24 }, "~N,~N");
25 Clazz.defineMethod (c$, "getHgap", 
26 function () {
27 return this.hgap;
28 });
29 Clazz.defineMethod (c$, "setHgap", 
30 function (hgap) {
31 this.hgap = hgap;
32 }, "~N");
33 Clazz.defineMethod (c$, "getVgap", 
34 function () {
35 return this.vgap;
36 });
37 Clazz.defineMethod (c$, "setVgap", 
38 function (vgap) {
39 this.vgap = vgap;
40 }, "~N");
41 Clazz.defineMethod (c$, "addLayoutComponent", 
42 function (comp, constraints) {
43 {
44 if (constraints == null) {
45 constraints = "";
46 }if (Clazz.instanceOf (constraints, String)) {
47 this.addLayoutComponent (constraints, comp);
48 } else {
49 throw  new IllegalArgumentException ("cannot add to layout: constraint must be a string");
50 }}}, "java.awt.Component,~O");
51 Clazz.defineMethod (c$, "addLayoutComponent", 
52 function (name, comp) {
53 {
54 if (!this.vector.isEmpty ()) {
55 comp.setVisible (false);
56 }for (var i = 0; i < this.vector.size (); i++) {
57 if ((this.vector.get (i)).name.equals (name)) {
58 (this.vector.get (i)).comp = comp;
59 return;
60 }}
61 this.vector.add (Clazz.innerTypeInstance (java.awt.CardLayout.Card, this, null, name, comp));
62 }}, "~S,java.awt.Component");
63 Clazz.overrideMethod (c$, "removeLayoutComponent", 
64 function (comp) {
65 {
66 for (var i = 0; i < this.vector.size (); i++) {
67 if ((this.vector.get (i)).comp === comp) {
68 if (comp.isVisible () && (comp.getParent () != null)) {
69 this.next (comp.getParent ());
70 }this.vector.remove (i);
71 if (this.currentCard > i) {
72 this.currentCard--;
73 }break;
74 }}
75 }}, "java.awt.Component");
76 Clazz.overrideMethod (c$, "preferredLayoutSize", 
77 function (parent) {
78 {
79 var insets = parent.getInsets ();
80 var ncomponents = parent.getComponentCount ();
81 var w = 0;
82 var h = 0;
83 for (var i = 0; i < ncomponents; i++) {
84 var comp = parent.getComponent (i);
85 var d = comp.getPreferredSize ();
86 if (d.width > w) {
87 w = d.width;
88 }if (d.height > h) {
89 h = d.height;
90 }}
91 return  new java.awt.Dimension (insets.left + insets.right + w + this.hgap * 2, insets.top + insets.bottom + h + this.vgap * 2);
92 }}, "java.awt.Container");
93 Clazz.overrideMethod (c$, "minimumLayoutSize", 
94 function (parent) {
95 {
96 var insets = parent.getInsets ();
97 var ncomponents = parent.getComponentCount ();
98 var w = 0;
99 var h = 0;
100 for (var i = 0; i < ncomponents; i++) {
101 var comp = parent.getComponent (i);
102 var d = comp.getMinimumSize ();
103 if (d.width > w) {
104 w = d.width;
105 }if (d.height > h) {
106 h = d.height;
107 }}
108 return  new java.awt.Dimension (insets.left + insets.right + w + this.hgap * 2, insets.top + insets.bottom + h + this.vgap * 2);
109 }}, "java.awt.Container");
110 Clazz.overrideMethod (c$, "maximumLayoutSize", 
111 function (target) {
112 return  new java.awt.Dimension (2147483647, 2147483647);
113 }, "java.awt.Container");
114 Clazz.overrideMethod (c$, "getLayoutAlignmentX", 
115 function (parent) {
116 return 0.5;
117 }, "java.awt.Container");
118 Clazz.overrideMethod (c$, "getLayoutAlignmentY", 
119 function (parent) {
120 return 0.5;
121 }, "java.awt.Container");
122 Clazz.overrideMethod (c$, "invalidateLayout", 
123 function (target) {
124 }, "java.awt.Container");
125 Clazz.overrideMethod (c$, "layoutContainer", 
126 function (parent) {
127 {
128 var insets = parent.getInsets ();
129 var ncomponents = parent.getComponentCount ();
130 var comp = null;
131 var currentFound = false;
132 for (var i = 0; i < ncomponents; i++) {
133 comp = parent.getComponent (i);
134 comp.setBounds (this.hgap + insets.left, this.vgap + insets.top, parent.width - (this.hgap * 2 + insets.left + insets.right), parent.height - (this.vgap * 2 + insets.top + insets.bottom));
135 if (comp.isVisible ()) {
136 currentFound = true;
137 }}
138 if (!currentFound && ncomponents > 0) {
139 parent.getComponent (0).setVisible (true);
140 }}}, "java.awt.Container");
141 Clazz.defineMethod (c$, "checkLayout", 
142 function (parent) {
143 if (parent.getLayout () !== this) {
144 throw  new IllegalArgumentException ("wrong parent for CardLayout");
145 }}, "java.awt.Container");
146 Clazz.defineMethod (c$, "first", 
147 function (parent) {
148 {
149 this.checkLayout (parent);
150 var ncomponents = parent.getComponentCount ();
151 for (var i = 0; i < ncomponents; i++) {
152 var comp = parent.getComponent (i);
153 if (comp.isVisible ()) {
154 comp.setVisible (false);
155 break;
156 }}
157 if (ncomponents > 0) {
158 this.currentCard = 0;
159 parent.getComponent (0).setVisible (true);
160 parent.validate ();
161 }}}, "java.awt.Container");
162 Clazz.defineMethod (c$, "next", 
163 function (parent) {
164 {
165 this.checkLayout (parent);
166 var ncomponents = parent.getComponentCount ();
167 for (var i = 0; i < ncomponents; i++) {
168 var comp = parent.getComponent (i);
169 if (comp.isVisible ()) {
170 comp.setVisible (false);
171 this.currentCard = (i + 1) % ncomponents;
172 comp = parent.getComponent (this.currentCard);
173 comp.setVisible (true);
174 parent.validate ();
175 return;
176 }}
177 this.showDefaultComponent (parent);
178 }}, "java.awt.Container");
179 Clazz.defineMethod (c$, "previous", 
180 function (parent) {
181 {
182 this.checkLayout (parent);
183 var ncomponents = parent.getComponentCount ();
184 for (var i = 0; i < ncomponents; i++) {
185 var comp = parent.getComponent (i);
186 if (comp.isVisible ()) {
187 comp.setVisible (false);
188 this.currentCard = ((i > 0) ? i - 1 : ncomponents - 1);
189 comp = parent.getComponent (this.currentCard);
190 comp.setVisible (true);
191 parent.validate ();
192 return;
193 }}
194 this.showDefaultComponent (parent);
195 }}, "java.awt.Container");
196 Clazz.defineMethod (c$, "showDefaultComponent", 
197 function (parent) {
198 if (parent.getComponentCount () > 0) {
199 this.currentCard = 0;
200 parent.getComponent (0).setVisible (true);
201 parent.validate ();
202 }}, "java.awt.Container");
203 Clazz.defineMethod (c$, "last", 
204 function (parent) {
205 {
206 this.checkLayout (parent);
207 var ncomponents = parent.getComponentCount ();
208 for (var i = 0; i < ncomponents; i++) {
209 var comp = parent.getComponent (i);
210 if (comp.isVisible ()) {
211 comp.setVisible (false);
212 break;
213 }}
214 if (ncomponents > 0) {
215 this.currentCard = ncomponents - 1;
216 parent.getComponent (this.currentCard).setVisible (true);
217 parent.validate ();
218 }}}, "java.awt.Container");
219 Clazz.defineMethod (c$, "show", 
220 function (parent, name) {
221 {
222 this.checkLayout (parent);
223 var next = null;
224 var ncomponents = this.vector.size ();
225 for (var i = 0; i < ncomponents; i++) {
226 var card = this.vector.get (i);
227 if (card.name.equals (name)) {
228 next = card.comp;
229 this.currentCard = i;
230 break;
231 }}
232 if ((next != null) && !next.isVisible ()) {
233 ncomponents = parent.getComponentCount ();
234 for (var i = 0; i < ncomponents; i++) {
235 var comp = parent.getComponent (i);
236 if (comp.isVisible ()) {
237 comp.setVisible (false);
238 break;
239 }}
240 next.setVisible (true);
241 parent.validate ();
242 }}}, "java.awt.Container,~S");
243 Clazz.overrideMethod (c$, "toString", 
244 function () {
245 return this.getClass ().getName () + "[hgap=" + this.hgap + ",vgap=" + this.vgap + "]";
246 });
247 c$.$CardLayout$Card$ = function () {
248 Clazz.pu$h(self.c$);
249 c$ = Clazz.decorateAsClass (function () {
250 Clazz.prepareCallback (this, arguments);
251 this.name = null;
252 this.comp = null;
253 Clazz.instantialize (this, arguments);
254 }, java.awt.CardLayout, "Card", null, java.io.Serializable);
255 Clazz.makeConstructor (c$, 
256 function (a, b) {
257 this.name = a;
258 this.comp = b;
259 }, "~S,java.awt.Component");
260 c$ = Clazz.p0p ();
261 };
262 c$.serialPersistentFields = c$.prototype.serialPersistentFields =  Clazz.newArray (-1, [ new java.io.ObjectStreamField ("tab", java.util.Hashtable),  new java.io.ObjectStreamField ("hgap", Integer.TYPE),  new java.io.ObjectStreamField ("vgap", Integer.TYPE),  new java.io.ObjectStreamField ("vector", java.util.Vector),  new java.io.ObjectStreamField ("currentCard", Integer.TYPE)]);
263 });