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