ae6808042a08ea037e594fbf7ca8d4a041eac016
[jalviewjs.git] / site / j2s / javax / swing / ScrollPaneLayout.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.awt.LayoutManager", "javax.swing.ScrollPaneConstants", "javax.swing.plaf.UIResource"], "javax.swing.ScrollPaneLayout", ["java.lang.IllegalArgumentException", "java.awt.Dimension", "$.Insets", "$.Rectangle", "javax.swing.Scrollable", "$.SwingUtilities", "$.UIManager"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.viewport = null;
5 this.vsb = null;
6 this.hsb = null;
7 this.rowHead = null;
8 this.colHead = null;
9 this.lowerLeft = null;
10 this.lowerRight = null;
11 this.upperLeft = null;
12 this.upperRight = null;
13 this.vsbPolicy = 20;
14 this.hsbPolicy = 30;
15 Clazz.instantialize (this, arguments);
16 }, javax.swing, "ScrollPaneLayout", null, [java.awt.LayoutManager, javax.swing.ScrollPaneConstants]);
17 Clazz.defineMethod (c$, "syncWithScrollPane", 
18 function (sp) {
19 this.viewport = sp.getViewport ();
20 this.vsb = sp.getVerticalScrollBar ();
21 this.hsb = sp.getHorizontalScrollBar ();
22 this.rowHead = sp.getRowHeader ();
23 this.colHead = sp.getColumnHeader ();
24 this.lowerLeft = sp.getCorner ("LOWER_LEFT_CORNER");
25 this.lowerRight = sp.getCorner ("LOWER_RIGHT_CORNER");
26 this.upperLeft = sp.getCorner ("UPPER_LEFT_CORNER");
27 this.upperRight = sp.getCorner ("UPPER_RIGHT_CORNER");
28 this.vsbPolicy = sp.getVerticalScrollBarPolicy ();
29 this.hsbPolicy = sp.getHorizontalScrollBarPolicy ();
30 }, "javax.swing.JScrollPane");
31 Clazz.defineMethod (c$, "addSingletonComponent", 
32 function (oldC, newC) {
33 if ((oldC != null) && (oldC !== newC)) {
34 oldC.getParent ().remove (oldC);
35 }return newC;
36 }, "java.awt.Component,java.awt.Component");
37 Clazz.overrideMethod (c$, "addLayoutComponent", 
38 function (s, c) {
39 if (s.equals ("VIEWPORT")) {
40 this.viewport = this.addSingletonComponent (this.viewport, c);
41 } else if (s.equals ("VERTICAL_SCROLLBAR")) {
42 this.vsb = this.addSingletonComponent (this.vsb, c);
43 } else if (s.equals ("HORIZONTAL_SCROLLBAR")) {
44 this.hsb = this.addSingletonComponent (this.hsb, c);
45 } else if (s.equals ("ROW_HEADER")) {
46 this.rowHead = this.addSingletonComponent (this.rowHead, c);
47 } else if (s.equals ("COLUMN_HEADER")) {
48 this.colHead = this.addSingletonComponent (this.colHead, c);
49 } else if (s.equals ("LOWER_LEFT_CORNER")) {
50 this.lowerLeft = this.addSingletonComponent (this.lowerLeft, c);
51 } else if (s.equals ("LOWER_RIGHT_CORNER")) {
52 this.lowerRight = this.addSingletonComponent (this.lowerRight, c);
53 } else if (s.equals ("UPPER_LEFT_CORNER")) {
54 this.upperLeft = this.addSingletonComponent (this.upperLeft, c);
55 } else if (s.equals ("UPPER_RIGHT_CORNER")) {
56 this.upperRight = this.addSingletonComponent (this.upperRight, c);
57 } else {
58 throw  new IllegalArgumentException ("invalid layout key " + s);
59 }}, "~S,java.awt.Component");
60 Clazz.overrideMethod (c$, "removeLayoutComponent", 
61 function (c) {
62 if (c === this.viewport) {
63 this.viewport = null;
64 } else if (c === this.vsb) {
65 this.vsb = null;
66 } else if (c === this.hsb) {
67 this.hsb = null;
68 } else if (c === this.rowHead) {
69 this.rowHead = null;
70 } else if (c === this.colHead) {
71 this.colHead = null;
72 } else if (c === this.lowerLeft) {
73 this.lowerLeft = null;
74 } else if (c === this.lowerRight) {
75 this.lowerRight = null;
76 } else if (c === this.upperLeft) {
77 this.upperLeft = null;
78 } else if (c === this.upperRight) {
79 this.upperRight = null;
80 }}, "java.awt.Component");
81 Clazz.defineMethod (c$, "getVerticalScrollBarPolicy", 
82 function () {
83 return this.vsbPolicy;
84 });
85 Clazz.defineMethod (c$, "setVerticalScrollBarPolicy", 
86 function (x) {
87 switch (x) {
88 case 20:
89 case 21:
90 case 22:
91 this.vsbPolicy = x;
92 break;
93 default:
94 throw  new IllegalArgumentException ("invalid verticalScrollBarPolicy");
95 }
96 }, "~N");
97 Clazz.defineMethod (c$, "getHorizontalScrollBarPolicy", 
98 function () {
99 return this.hsbPolicy;
100 });
101 Clazz.defineMethod (c$, "setHorizontalScrollBarPolicy", 
102 function (x) {
103 switch (x) {
104 case 30:
105 case 31:
106 case 32:
107 this.hsbPolicy = x;
108 break;
109 default:
110 throw  new IllegalArgumentException ("invalid horizontalScrollBarPolicy");
111 }
112 }, "~N");
113 Clazz.defineMethod (c$, "getViewport", 
114 function () {
115 return this.viewport;
116 });
117 Clazz.defineMethod (c$, "getHorizontalScrollBar", 
118 function () {
119 return this.hsb;
120 });
121 Clazz.defineMethod (c$, "getVerticalScrollBar", 
122 function () {
123 return this.vsb;
124 });
125 Clazz.defineMethod (c$, "getRowHeader", 
126 function () {
127 return this.rowHead;
128 });
129 Clazz.defineMethod (c$, "getColumnHeader", 
130 function () {
131 return this.colHead;
132 });
133 Clazz.defineMethod (c$, "getCorner", 
134 function (key) {
135 if (key.equals ("LOWER_LEFT_CORNER")) {
136 return this.lowerLeft;
137 } else if (key.equals ("LOWER_RIGHT_CORNER")) {
138 return this.lowerRight;
139 } else if (key.equals ("UPPER_LEFT_CORNER")) {
140 return this.upperLeft;
141 } else if (key.equals ("UPPER_RIGHT_CORNER")) {
142 return this.upperRight;
143 } else {
144 return null;
145 }}, "~S");
146 Clazz.overrideMethod (c$, "preferredLayoutSize", 
147 function (parent) {
148 var scrollPane = parent;
149 this.vsbPolicy = scrollPane.getVerticalScrollBarPolicy ();
150 this.hsbPolicy = scrollPane.getHorizontalScrollBarPolicy ();
151 var insets = parent.getInsets ();
152 var prefWidth = insets.left + insets.right;
153 var prefHeight = insets.top + insets.bottom;
154 var extentSize = null;
155 var viewSize = null;
156 var view = null;
157 if (this.viewport != null) {
158 extentSize = this.viewport.getPreferredSize ();
159 view = this.viewport.getView ();
160 if (view != null) {
161 viewSize = view.getPreferredSize ();
162 } else {
163 viewSize =  new java.awt.Dimension (0, 0);
164 }}if (extentSize != null) {
165 prefWidth += extentSize.width;
166 prefHeight += extentSize.height;
167 }var viewportBorder = scrollPane.getViewportBorder ();
168 if (viewportBorder != null) {
169 var vpbInsets = viewportBorder.getBorderInsets (parent);
170 prefWidth += vpbInsets.left + vpbInsets.right;
171 prefHeight += vpbInsets.top + vpbInsets.bottom;
172 }if ((this.rowHead != null) && this.rowHead.isVisible ()) {
173 prefWidth += this.rowHead.getPreferredSize ().width;
174 }if ((this.colHead != null) && this.colHead.isVisible ()) {
175 prefHeight += this.colHead.getPreferredSize ().height;
176 }if ((this.vsb != null) && (this.vsbPolicy != 21)) {
177 if (this.vsbPolicy == 22) {
178 prefWidth += this.vsb.getPreferredSize ().width;
179 } else if ((viewSize != null) && (extentSize != null)) {
180 var canScroll = true;
181 if (Clazz.instanceOf (view, javax.swing.Scrollable)) {
182 canScroll = !(view).getScrollableTracksViewportHeight ();
183 }if (canScroll && (viewSize.height > extentSize.height)) {
184 prefWidth += this.vsb.getPreferredSize ().width;
185 }}}if ((this.hsb != null) && (this.hsbPolicy != 31)) {
186 if (this.hsbPolicy == 32) {
187 prefHeight += this.hsb.getPreferredSize ().height;
188 } else if ((viewSize != null) && (extentSize != null)) {
189 var canScroll = true;
190 if (Clazz.instanceOf (view, javax.swing.Scrollable)) {
191 canScroll = !(view).getScrollableTracksViewportWidth ();
192 }if (canScroll && (viewSize.width > extentSize.width)) {
193 prefHeight += this.hsb.getPreferredSize ().height;
194 }}}return  new java.awt.Dimension (prefWidth, prefHeight);
195 }, "java.awt.Container");
196 Clazz.overrideMethod (c$, "minimumLayoutSize", 
197 function (parent) {
198 var scrollPane = parent;
199 this.vsbPolicy = scrollPane.getVerticalScrollBarPolicy ();
200 this.hsbPolicy = scrollPane.getHorizontalScrollBarPolicy ();
201 var insets = parent.getInsets ();
202 var minWidth = insets.left + insets.right;
203 var minHeight = insets.top + insets.bottom;
204 if (this.viewport != null) {
205 var size = this.viewport.getMinimumSize ();
206 minWidth += size.width;
207 minHeight += size.height;
208 }var viewportBorder = scrollPane.getViewportBorder ();
209 if (viewportBorder != null) {
210 var vpbInsets = viewportBorder.getBorderInsets (parent);
211 minWidth += vpbInsets.left + vpbInsets.right;
212 minHeight += vpbInsets.top + vpbInsets.bottom;
213 }if ((this.rowHead != null) && this.rowHead.isVisible ()) {
214 var size = this.rowHead.getMinimumSize ();
215 minWidth += size.width;
216 minHeight = Math.max (minHeight, size.height);
217 }if ((this.colHead != null) && this.colHead.isVisible ()) {
218 var size = this.colHead.getMinimumSize ();
219 minWidth = Math.max (minWidth, size.width);
220 minHeight += size.height;
221 }if ((this.vsb != null) && (this.vsbPolicy != 21)) {
222 var size = this.vsb.getMinimumSize ();
223 minWidth += size.width;
224 minHeight = Math.max (minHeight, size.height);
225 }if ((this.hsb != null) && (this.hsbPolicy != 31)) {
226 var size = this.hsb.getMinimumSize ();
227 minWidth = Math.max (minWidth, size.width);
228 minHeight += size.height;
229 }return  new java.awt.Dimension (minWidth, minHeight);
230 }, "java.awt.Container");
231 Clazz.overrideMethod (c$, "layoutContainer", 
232 function (parent) {
233 var scrollPane = parent;
234 this.vsbPolicy = scrollPane.getVerticalScrollBarPolicy ();
235 this.hsbPolicy = scrollPane.getHorizontalScrollBarPolicy ();
236 var availR = scrollPane.getBounds ();
237 availR.x = availR.y = 0;
238 var insets = parent.getInsets ();
239 availR.x = insets.left;
240 availR.y = insets.top;
241 availR.width -= insets.left + insets.right;
242 availR.height -= insets.top + insets.bottom;
243 var leftToRight = javax.swing.SwingUtilities.isLeftToRight (scrollPane);
244 var colHeadR =  new java.awt.Rectangle (0, availR.y, 0, 0);
245 if ((this.colHead != null) && (this.colHead.isVisible ())) {
246 var colHeadHeight = Math.min (availR.height, this.colHead.getPreferredSize ().height);
247 colHeadR.height = colHeadHeight;
248 availR.y += colHeadHeight;
249 availR.height -= colHeadHeight;
250 }var rowHeadR =  new java.awt.Rectangle (0, 0, 0, 0);
251 if ((this.rowHead != null) && (this.rowHead.isVisible ())) {
252 var rowHeadWidth = Math.min (availR.width, this.rowHead.getPreferredSize ().width);
253 rowHeadR.width = rowHeadWidth;
254 availR.width -= rowHeadWidth;
255 if (leftToRight) {
256 rowHeadR.x = availR.x;
257 availR.x += rowHeadWidth;
258 } else {
259 rowHeadR.x = availR.x + availR.width;
260 }}var viewportBorder = scrollPane.getViewportBorder ();
261 var vpbInsets;
262 if (viewportBorder != null) {
263 vpbInsets = viewportBorder.getBorderInsets (parent);
264 availR.x += vpbInsets.left;
265 availR.y += vpbInsets.top;
266 availR.width -= vpbInsets.left + vpbInsets.right;
267 availR.height -= vpbInsets.top + vpbInsets.bottom;
268 } else {
269 vpbInsets =  new java.awt.Insets (0, 0, 0, 0);
270 }var view = (this.viewport != null) ? this.viewport.getView () : null;
271 var viewPrefSize = (view != null) ? view.getPreferredSize () :  new java.awt.Dimension (0, 0);
272 var extentSize = (this.viewport != null) ? this.viewport.toViewCoordinates (availR.getSize ()) :  new java.awt.Dimension (0, 0);
273 var viewTracksViewportWidth = false;
274 var viewTracksViewportHeight = false;
275 var isEmpty = (availR.width < 0 || availR.height < 0);
276 var sv;
277 if (!isEmpty && Clazz.instanceOf (view, javax.swing.Scrollable)) {
278 sv = view;
279 viewTracksViewportWidth = sv.getScrollableTracksViewportWidth ();
280 viewTracksViewportHeight = sv.getScrollableTracksViewportHeight ();
281 } else {
282 sv = null;
283 }var vsbR =  new java.awt.Rectangle (0, availR.y - vpbInsets.top, 0, 0);
284 var vsbNeeded;
285 if (isEmpty) {
286 vsbNeeded = false;
287 } else if (this.vsbPolicy == 22) {
288 vsbNeeded = true;
289 } else if (this.vsbPolicy == 21) {
290 vsbNeeded = false;
291 } else {
292 vsbNeeded = !viewTracksViewportHeight && (viewPrefSize.height > extentSize.height);
293 }if ((this.vsb != null) && vsbNeeded) {
294 this.adjustForVSB (true, availR, vsbR, vpbInsets, leftToRight);
295 extentSize = this.viewport.toViewCoordinates (availR.getSize ());
296 }var hsbR =  new java.awt.Rectangle (availR.x - vpbInsets.left, 0, 0, 0);
297 var hsbNeeded;
298 if (isEmpty) {
299 hsbNeeded = false;
300 } else if (this.hsbPolicy == 32) {
301 hsbNeeded = true;
302 } else if (this.hsbPolicy == 31) {
303 hsbNeeded = false;
304 } else {
305 hsbNeeded = !viewTracksViewportWidth && (viewPrefSize.width > extentSize.width);
306 }if ((this.hsb != null) && hsbNeeded) {
307 this.adjustForHSB (true, availR, hsbR, vpbInsets);
308 if ((this.vsb != null) && !vsbNeeded && (this.vsbPolicy != 21)) {
309 extentSize = this.viewport.toViewCoordinates (availR.getSize ());
310 vsbNeeded = viewPrefSize.height > extentSize.height;
311 if (vsbNeeded) {
312 this.adjustForVSB (true, availR, vsbR, vpbInsets, leftToRight);
313 }}}if (this.viewport != null) {
314 this.viewport.setBounds (availR);
315 if (sv != null) {
316 extentSize = this.viewport.toViewCoordinates (availR.getSize ());
317 var oldHSBNeeded = hsbNeeded;
318 var oldVSBNeeded = vsbNeeded;
319 viewTracksViewportWidth = sv.getScrollableTracksViewportWidth ();
320 viewTracksViewportHeight = sv.getScrollableTracksViewportHeight ();
321 if (this.vsb != null && this.vsbPolicy == 20) {
322 var newVSBNeeded = !viewTracksViewportHeight && (viewPrefSize.height > extentSize.height);
323 if (newVSBNeeded != vsbNeeded) {
324 vsbNeeded = newVSBNeeded;
325 this.adjustForVSB (vsbNeeded, availR, vsbR, vpbInsets, leftToRight);
326 extentSize = this.viewport.toViewCoordinates (availR.getSize ());
327 }}if (this.hsb != null && this.hsbPolicy == 30) {
328 var newHSBbNeeded = !viewTracksViewportWidth && (viewPrefSize.width > extentSize.width);
329 if (newHSBbNeeded != hsbNeeded) {
330 hsbNeeded = newHSBbNeeded;
331 this.adjustForHSB (hsbNeeded, availR, hsbR, vpbInsets);
332 if ((this.vsb != null) && !vsbNeeded && (this.vsbPolicy != 21)) {
333 extentSize = this.viewport.toViewCoordinates (availR.getSize ());
334 vsbNeeded = viewPrefSize.height > extentSize.height;
335 if (vsbNeeded) {
336 this.adjustForVSB (true, availR, vsbR, vpbInsets, leftToRight);
337 }}}}if (oldHSBNeeded != hsbNeeded || oldVSBNeeded != vsbNeeded) {
338 this.viewport.setBounds (availR);
339 }}}vsbR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
340 hsbR.width = availR.width + vpbInsets.left + vpbInsets.right;
341 rowHeadR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
342 rowHeadR.y = availR.y - vpbInsets.top;
343 colHeadR.width = availR.width + vpbInsets.left + vpbInsets.right;
344 colHeadR.x = availR.x - vpbInsets.left;
345 if (this.rowHead != null) {
346 this.rowHead.setBounds (rowHeadR);
347 }if (this.colHead != null) {
348 this.colHead.setBounds (colHeadR);
349 }if (this.vsb != null) {
350 if (vsbNeeded) {
351 if (this.colHead != null && javax.swing.UIManager.getBoolean ("ScrollPane.fillUpperCorner")) {
352 if ((leftToRight && this.upperRight == null) || (!leftToRight && this.upperLeft == null)) {
353 vsbR.y = colHeadR.y;
354 vsbR.height += colHeadR.height;
355 }}this.vsb.setVisible (true);
356 this.vsb.setBounds (vsbR);
357 } else {
358 this.vsb.setVisible (false);
359 }}if (this.hsb != null) {
360 if (hsbNeeded) {
361 if (this.rowHead != null && javax.swing.UIManager.getBoolean ("ScrollPane.fillLowerCorner")) {
362 if ((leftToRight && this.lowerLeft == null) || (!leftToRight && this.lowerRight == null)) {
363 if (leftToRight) {
364 hsbR.x = rowHeadR.x;
365 }hsbR.width += rowHeadR.width;
366 }}this.hsb.setVisible (true);
367 this.hsb.setBounds (hsbR);
368 } else {
369 this.hsb.setVisible (false);
370 }}if (this.lowerLeft != null) {
371 this.lowerLeft.setBounds (leftToRight ? rowHeadR.x : vsbR.x, hsbR.y, leftToRight ? rowHeadR.width : vsbR.width, hsbR.height);
372 }if (this.lowerRight != null) {
373 this.lowerRight.setBounds (leftToRight ? vsbR.x : rowHeadR.x, hsbR.y, leftToRight ? vsbR.width : rowHeadR.width, hsbR.height);
374 }if (this.upperLeft != null) {
375 this.upperLeft.setBounds (leftToRight ? rowHeadR.x : vsbR.x, colHeadR.y, leftToRight ? rowHeadR.width : vsbR.width, colHeadR.height);
376 }if (this.upperRight != null) {
377 this.upperRight.setBounds (leftToRight ? vsbR.x : rowHeadR.x, colHeadR.y, leftToRight ? vsbR.width : rowHeadR.width, colHeadR.height);
378 }}, "java.awt.Container");
379 Clazz.defineMethod (c$, "adjustForVSB", 
380  function (wantsVSB, available, vsbR, vpbInsets, leftToRight) {
381 var oldWidth = vsbR.width;
382 if (wantsVSB) {
383 var vsbWidth = Math.max (0, Math.min (this.vsb.getPreferredSize ().width, available.width));
384 available.width -= vsbWidth;
385 vsbR.width = vsbWidth;
386 if (leftToRight) {
387 vsbR.x = available.x + available.width + vpbInsets.right;
388 } else {
389 vsbR.x = available.x - vpbInsets.left;
390 available.x += vsbWidth;
391 }} else {
392 available.width += oldWidth;
393 }}, "~B,java.awt.Rectangle,java.awt.Rectangle,java.awt.Insets,~B");
394 Clazz.defineMethod (c$, "adjustForHSB", 
395  function (wantsHSB, available, hsbR, vpbInsets) {
396 var oldHeight = hsbR.height;
397 if (wantsHSB) {
398 var hsbHeight = Math.max (0, Math.min (available.height, this.hsb.getPreferredSize ().height));
399 available.height -= hsbHeight;
400 hsbR.y = available.y + available.height + vpbInsets.bottom;
401 hsbR.height = hsbHeight;
402 } else {
403 available.height += oldHeight;
404 }}, "~B,java.awt.Rectangle,java.awt.Rectangle,java.awt.Insets");
405 Clazz.defineMethod (c$, "getViewportBorderBounds", 
406 function (scrollpane) {
407 return scrollpane.getViewportBorderBounds ();
408 }, "javax.swing.JScrollPane");
409 Clazz.pu$h(self.c$);
410 c$ = Clazz.declareType (javax.swing.ScrollPaneLayout, "UIResource", javax.swing.ScrollPaneLayout, javax.swing.plaf.UIResource);
411 c$ = Clazz.p0p ();
412 });