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 () {
10 this.lowerRight = null;
11 this.upperLeft = null;
12 this.upperRight = null;
15 Clazz.instantialize (this, arguments);
16 }, javax.swing, "ScrollPaneLayout", null, [java.awt.LayoutManager, javax.swing.ScrollPaneConstants]);
17 Clazz.defineMethod (c$, "syncWithScrollPane",
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);
36 }, "java.awt.Component,java.awt.Component");
37 Clazz.overrideMethod (c$, "addLayoutComponent",
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);
58 throw new IllegalArgumentException ("invalid layout key " + s);
59 }}, "~S,java.awt.Component");
60 Clazz.overrideMethod (c$, "removeLayoutComponent",
62 if (c === this.viewport) {
64 } else if (c === this.vsb) {
66 } else if (c === this.hsb) {
68 } else if (c === this.rowHead) {
70 } else if (c === this.colHead) {
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",
83 return this.vsbPolicy;
85 Clazz.defineMethod (c$, "setVerticalScrollBarPolicy",
94 throw new IllegalArgumentException ("invalid verticalScrollBarPolicy");
97 Clazz.defineMethod (c$, "getHorizontalScrollBarPolicy",
99 return this.hsbPolicy;
101 Clazz.defineMethod (c$, "setHorizontalScrollBarPolicy",
110 throw new IllegalArgumentException ("invalid horizontalScrollBarPolicy");
113 Clazz.defineMethod (c$, "getViewport",
115 return this.viewport;
117 Clazz.defineMethod (c$, "getHorizontalScrollBar",
121 Clazz.defineMethod (c$, "getVerticalScrollBar",
125 Clazz.defineMethod (c$, "getRowHeader",
129 Clazz.defineMethod (c$, "getColumnHeader",
133 Clazz.defineMethod (c$, "getCorner",
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;
146 Clazz.overrideMethod (c$, "preferredLayoutSize",
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;
157 if (this.viewport != null) {
158 extentSize = this.viewport.getPreferredSize ();
159 view = this.viewport.getView ();
161 viewSize = view.getPreferredSize ();
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",
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",
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;
256 rowHeadR.x = availR.x;
257 availR.x += rowHeadWidth;
259 rowHeadR.x = availR.x + availR.width;
260 }}var viewportBorder = scrollPane.getViewportBorder ();
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;
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);
277 if (!isEmpty && Clazz.instanceOf (view, javax.swing.Scrollable)) {
279 viewTracksViewportWidth = sv.getScrollableTracksViewportWidth ();
280 viewTracksViewportHeight = sv.getScrollableTracksViewportHeight ();
283 }var vsbR = new java.awt.Rectangle (0, availR.y - vpbInsets.top, 0, 0);
287 } else if (this.vsbPolicy == 22) {
289 } else if (this.vsbPolicy == 21) {
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);
300 } else if (this.hsbPolicy == 32) {
302 } else if (this.hsbPolicy == 31) {
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;
312 this.adjustForVSB (true, availR, vsbR, vpbInsets, leftToRight);
313 }}}if (this.viewport != null) {
314 this.viewport.setBounds (availR);
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;
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) {
351 if (this.colHead != null && javax.swing.UIManager.getBoolean ("ScrollPane.fillUpperCorner")) {
352 if ((leftToRight && this.upperRight == null) || (!leftToRight && this.upperLeft == null)) {
354 vsbR.height += colHeadR.height;
355 }}this.vsb.setVisible (true);
356 this.vsb.setBounds (vsbR);
358 this.vsb.setVisible (false);
359 }}if (this.hsb != null) {
361 if (this.rowHead != null && javax.swing.UIManager.getBoolean ("ScrollPane.fillLowerCorner")) {
362 if ((leftToRight && this.lowerLeft == null) || (!leftToRight && this.lowerRight == null)) {
365 }hsbR.width += rowHeadR.width;
366 }}this.hsb.setVisible (true);
367 this.hsb.setBounds (hsbR);
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;
383 var vsbWidth = Math.max (0, Math.min (this.vsb.getPreferredSize ().width, available.width));
384 available.width -= vsbWidth;
385 vsbR.width = vsbWidth;
387 vsbR.x = available.x + available.width + vpbInsets.right;
389 vsbR.x = available.x - vpbInsets.left;
390 available.x += vsbWidth;
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;
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;
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");
410 c$ = Clazz.declareType (javax.swing.ScrollPaneLayout, "UIResource", javax.swing.ScrollPaneLayout, javax.swing.plaf.UIResource);