1 Clazz.declarePackage ("javax.swing.border");
\r
2 Clazz.load (["javax.swing.border.AbstractBorder", "java.awt.Point"], "javax.swing.border.TitledBorder", ["java.lang.IllegalArgumentException", "$.NullPointerException", "java.awt.Component", "$.Dimension", "$.Font", "$.Insets", "$.Rectangle", "javax.swing.JComponent", "$.UIManager", "jssun.swing.SwingUtilities2"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
6 this.titlePosition = 0;
\r
7 this.titleJustification = 0;
\r
8 this.titleFont = null;
\r
9 this.titleColor = null;
\r
10 this.textLoc = null;
\r
11 Clazz.instantialize (this, arguments);
\r
12 }, javax.swing.border, "TitledBorder", javax.swing.border.AbstractBorder);
\r
13 Clazz.prepareFields (c$, function () {
\r
14 this.textLoc = new java.awt.Point ();
\r
16 Clazz.makeConstructor (c$,
\r
18 this.construct (null, title, 4, 0, null, null);
\r
20 Clazz.makeConstructor (c$,
\r
22 this.construct (border, "", 4, 0, null, null);
\r
23 }, "javax.swing.border.Border");
\r
24 Clazz.makeConstructor (c$,
\r
25 function (border, title) {
\r
26 this.construct (border, title, 4, 0, null, null);
\r
27 }, "javax.swing.border.Border,~S");
\r
28 Clazz.makeConstructor (c$,
\r
29 function (border, title, titleJustification, titlePosition) {
\r
30 this.construct (border, title, titleJustification, titlePosition, null, null);
\r
31 }, "javax.swing.border.Border,~S,~N,~N");
\r
32 Clazz.makeConstructor (c$,
\r
33 function (border, title, titleJustification, titlePosition, titleFont) {
\r
34 this.construct (border, title, titleJustification, titlePosition, titleFont, null);
\r
35 }, "javax.swing.border.Border,~S,~N,~N,java.awt.Font");
\r
36 Clazz.makeConstructor (c$,
\r
37 function (border, title, titleJustification, titlePosition, titleFont, titleColor) {
\r
38 Clazz.superConstructor (this, javax.swing.border.TitledBorder, []);
\r
40 this.border = border;
\r
41 this.titleFont = titleFont;
\r
42 this.titleColor = titleColor;
\r
43 this.setTitleJustification (titleJustification);
\r
44 this.setTitlePosition (titlePosition);
\r
45 }, "javax.swing.border.Border,~S,~N,~N,java.awt.Font,java.awt.Color");
\r
46 Clazz.overrideMethod (c$, "paintBorder",
\r
47 function (c, g, x, y, width, height) {
\r
48 var border = this.getBorder ();
\r
49 if (this.getTitle () == null || this.getTitle ().equals ("")) {
\r
50 if (border != null) {
\r
51 border.paintBorder (c, g, x, y, width, height);
\r
53 }var grooveRect = new java.awt.Rectangle (x + 2, y + 2, width - (4), height - (4));
\r
54 var font = g.getFont ();
\r
55 var color = g.getColor ();
\r
56 g.setFont (this.getFont (c));
\r
57 var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null;
\r
58 var fm = jssun.swing.SwingUtilities2.getFontMetrics (jc, g);
\r
59 var fontHeight = fm.getHeight ();
\r
60 var descent = fm.getDescent ();
\r
61 var ascent = fm.getAscent ();
\r
63 var stringWidth = jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ());
\r
65 if (border != null) {
\r
66 insets = border.getBorderInsets (c);
\r
68 insets = new java.awt.Insets (0, 0, 0, 0);
\r
69 }var titlePos = this.getTitlePosition ();
\r
72 diff = ascent + descent + (Math.max (2, 4) - 2);
\r
73 grooveRect.y += diff;
\r
74 grooveRect.height -= diff;
\r
75 this.textLoc.y = grooveRect.y - (descent + 2);
\r
79 diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2);
\r
80 grooveRect.y += diff;
\r
81 grooveRect.height -= diff;
\r
82 this.textLoc.y = (grooveRect.y - descent) + Clazz.doubleToInt ((insets.top + ascent + descent) / 2);
\r
85 this.textLoc.y = grooveRect.y + insets.top + ascent + 2;
\r
88 this.textLoc.y = (grooveRect.y + grooveRect.height) - (insets.bottom + descent + 2);
\r
91 grooveRect.height -= Clazz.doubleToInt (fontHeight / 2);
\r
92 this.textLoc.y = ((grooveRect.y + grooveRect.height) - descent) + Clazz.doubleToInt (((ascent + descent) - insets.bottom) / 2);
\r
95 grooveRect.height -= fontHeight;
\r
96 this.textLoc.y = grooveRect.y + grooveRect.height + ascent + 2;
\r
99 var justification = this.getTitleJustification ();
\r
100 if (javax.swing.border.AbstractBorder.isLeftToRight (c)) {
\r
101 if (justification == 4 || justification == 0) {
\r
103 } else if (justification == 5) {
\r
106 if (justification == 4 || justification == 0) {
\r
108 } else if (justification == 5) {
\r
110 }}switch (justification) {
\r
112 this.textLoc.x = grooveRect.x + 5 + insets.left;
\r
115 this.textLoc.x = (grooveRect.x + grooveRect.width) - (stringWidth + 5 + insets.right);
\r
118 this.textLoc.x = grooveRect.x + (Clazz.doubleToInt ((grooveRect.width - stringWidth) / 2));
\r
121 if (border != null) {
\r
122 if (((titlePos == 2 || titlePos == 0) && (grooveRect.y > this.textLoc.y - ascent)) || (titlePos == 5 && (grooveRect.y + grooveRect.height < this.textLoc.y + descent))) {
\r
123 var clipRect = new java.awt.Rectangle ();
\r
124 var saveClip = g.getClipBounds ();
\r
125 clipRect.setBounds (saveClip);
\r
126 if (javax.swing.border.TitledBorder.computeIntersection (clipRect, x, y, this.textLoc.x - 1 - x, height)) {
\r
127 g.setClip (clipRect);
\r
128 border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
\r
129 }clipRect.setBounds (saveClip);
\r
130 if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x + stringWidth + 1, y, x + width - (this.textLoc.x + stringWidth + 1), height)) {
\r
131 g.setClip (clipRect);
\r
132 border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
\r
133 }if (titlePos == 2 || titlePos == 0) {
\r
134 clipRect.setBounds (saveClip);
\r
135 if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, this.textLoc.y + descent, stringWidth + 2, y + height - this.textLoc.y - descent)) {
\r
136 g.setClip (clipRect);
\r
137 border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
\r
139 clipRect.setBounds (saveClip);
\r
140 if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, y, stringWidth + 2, this.textLoc.y - ascent - y)) {
\r
141 g.setClip (clipRect);
\r
142 border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
\r
143 }}g.setClip (saveClip);
\r
145 border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
\r
146 }}g.setColor (this.getTitleColor ());
\r
147 jssun.swing.SwingUtilities2.drawString (jc, g, this.getTitle (), this.textLoc.x, this.textLoc.y);
\r
149 g.setColor (color);
\r
150 }, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N");
\r
151 Clazz.defineMethod (c$, "getBorderInsets",
\r
153 return this.getBorderInsets (c, new java.awt.Insets (0, 0, 0, 0));
\r
154 }, "java.awt.Component");
\r
155 Clazz.defineMethod (c$, "getBorderInsets",
\r
156 function (c, insets) {
\r
161 var border = this.getBorder ();
\r
162 if (border != null) {
\r
163 if (Clazz.instanceOf (border, javax.swing.border.AbstractBorder)) {
\r
164 (border).getBorderInsets (c, insets);
\r
166 var i = border.getBorderInsets (c);
\r
167 insets.top = i.top;
\r
168 insets.right = i.right;
\r
169 insets.bottom = i.bottom;
\r
170 insets.left = i.left;
\r
172 insets.left = insets.top = insets.right = insets.bottom = 0;
\r
176 insets.bottom += 4;
\r
177 if (c == null || this.getTitle () == null || this.getTitle ().equals ("")) {
\r
179 }var font = this.getFont (c);
\r
180 fm = c.getFontMetrics (font);
\r
182 descent = fm.getDescent ();
\r
183 ascent = fm.getAscent ();
\r
184 height = fm.getHeight ();
\r
185 }switch (this.getTitlePosition ()) {
\r
187 insets.top += ascent + descent + (Math.max (2, 4) - 2);
\r
191 insets.top += ascent + descent;
\r
194 insets.top += ascent + descent + 2;
\r
197 insets.bottom += ascent + descent + 2;
\r
200 insets.bottom += ascent + descent;
\r
203 insets.bottom += height;
\r
207 }, "java.awt.Component,java.awt.Insets");
\r
208 Clazz.overrideMethod (c$, "isBorderOpaque",
\r
212 Clazz.defineMethod (c$, "getTitle",
\r
216 Clazz.defineMethod (c$, "getBorder",
\r
218 var b = this.border;
\r
219 if (b == null) b = javax.swing.UIManager.getBorder ("TitledBorder.border");
\r
222 Clazz.defineMethod (c$, "getTitlePosition",
\r
224 if (this.titlePosition == 0) {
\r
225 var value = javax.swing.UIManager.get ("TitledBorder.position");
\r
226 if (Clazz.instanceOf (value, String)) {
\r
228 if ("ABOVE_TOP".equalsIgnoreCase (s)) {
\r
230 } else if ("TOP".equalsIgnoreCase (s)) {
\r
232 } else if ("BELOW_TOP".equalsIgnoreCase (s)) {
\r
234 } else if ("ABOVE_BOTTOM".equalsIgnoreCase (s)) {
\r
236 } else if ("BOTTOM".equalsIgnoreCase (s)) {
\r
238 } else if ("BELOW_BOTTOM".equalsIgnoreCase (s)) {
\r
240 }} else if (Clazz.instanceOf (value, Integer)) {
\r
241 var i = (value).intValue ();
\r
242 if (i >= 0 && i <= 6) {
\r
244 }}}return this.titlePosition;
\r
246 Clazz.defineMethod (c$, "getTitleJustification",
\r
248 return this.titleJustification;
\r
250 Clazz.defineMethod (c$, "getTitleFont",
\r
252 var f = this.titleFont;
\r
253 if (f == null) f = javax.swing.UIManager.getFont ("TitledBorder.font");
\r
256 Clazz.defineMethod (c$, "getTitleColor",
\r
258 var c = this.titleColor;
\r
259 if (c == null) c = javax.swing.UIManager.getColor ("TitledBorder.titleColor");
\r
262 Clazz.defineMethod (c$, "setTitle",
\r
264 this.title = title;
\r
266 Clazz.defineMethod (c$, "setBorder",
\r
267 function (border) {
\r
268 this.border = border;
\r
269 }, "javax.swing.border.Border");
\r
270 Clazz.defineMethod (c$, "setTitlePosition",
\r
271 function (titlePosition) {
\r
272 switch (titlePosition) {
\r
280 this.titlePosition = titlePosition;
\r
283 throw new IllegalArgumentException (titlePosition + " is not a valid title position.");
\r
286 Clazz.defineMethod (c$, "setTitleJustification",
\r
287 function (titleJustification) {
\r
288 switch (titleJustification) {
\r
295 this.titleJustification = titleJustification;
\r
298 throw new IllegalArgumentException (titleJustification + " is not a valid title justification.");
\r
301 Clazz.defineMethod (c$, "setTitleFont",
\r
302 function (titleFont) {
\r
303 this.titleFont = titleFont;
\r
304 }, "java.awt.Font");
\r
305 Clazz.defineMethod (c$, "setTitleColor",
\r
306 function (titleColor) {
\r
307 this.titleColor = titleColor;
\r
308 }, "java.awt.Color");
\r
309 Clazz.defineMethod (c$, "getMinimumSize",
\r
311 var insets = this.getBorderInsets (c);
\r
312 var minSize = new java.awt.Dimension (insets.right + insets.left, insets.top + insets.bottom);
\r
313 var font = this.getFont (c);
\r
314 var fm = c.getFontMetrics (font);
\r
315 var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null;
\r
316 switch (this.getTitlePosition ()) {
\r
319 minSize.width = Math.max (jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()), minSize.width);
\r
327 minSize.width += jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ());
\r
330 }, "java.awt.Component");
\r
331 Clazz.overrideMethod (c$, "getBaseline",
\r
332 function (c, width, height) {
\r
334 throw new NullPointerException ("Must supply non-null component");
\r
336 throw new IllegalArgumentException ("Height must be >= 0");
\r
337 }var title = this.getTitle ();
\r
338 if (title != null && !"".equals (title)) {
\r
339 var font = this.getFont (c);
\r
340 var border2 = this.getBorder ();
\r
342 if (border2 != null) {
\r
343 borderInsets = border2.getBorderInsets (c);
\r
345 borderInsets = new java.awt.Insets (0, 0, 0, 0);
\r
346 }var fm = c.getFontMetrics (font);
\r
347 var fontHeight = fm.getHeight ();
\r
348 var descent = fm.getDescent ();
\r
349 var ascent = fm.getAscent ();
\r
351 var h = height - 4;
\r
353 switch (this.getTitlePosition ()) {
\r
355 diff = ascent + descent + (Math.max (2, 4) - 2);
\r
356 return y + diff - (descent + 2);
\r
359 diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2);
\r
360 return (y + diff - descent) + Clazz.doubleToInt ((borderInsets.top + ascent + descent) / 2);
\r
362 return y + borderInsets.top + ascent + 2;
\r
364 return (y + h) - (borderInsets.bottom + descent + 2);
\r
366 h -= Clazz.doubleToInt (fontHeight / 2);
\r
367 return ((y + h) - descent) + Clazz.doubleToInt (((ascent + descent) - borderInsets.bottom) / 2);
\r
370 return y + h + ascent + 2;
\r
373 }, "java.awt.Component,~N,~N");
\r
374 Clazz.defineMethod (c$, "getBaselineResizeBehavior",
\r
376 Clazz.superCall (this, javax.swing.border.TitledBorder, "getBaselineResizeBehavior", [c]);
\r
377 switch (this.getTitlePosition ()) {
\r
382 return java.awt.Component.BaselineResizeBehavior.CONSTANT_ASCENT;
\r
386 return java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT;
\r
388 return java.awt.Component.BaselineResizeBehavior.OTHER;
\r
389 }, "java.awt.Component");
\r
390 Clazz.defineMethod (c$, "getFont",
\r
393 if ((font = this.getTitleFont ()) != null) {
\r
395 } else if (c != null && (font = c.getFont ()) != null) {
\r
397 }return new java.awt.Font ("Dialog", 0, 12);
\r
398 }, "java.awt.Component");
\r
399 c$.computeIntersection = Clazz.defineMethod (c$, "computeIntersection",
\r
400 function (dest, rx, ry, rw, rh) {
\r
401 var x1 = Math.max (rx, dest.x);
\r
402 var x2 = Math.min (rx + rw, dest.x + dest.width);
\r
403 var y1 = Math.max (ry, dest.y);
\r
404 var y2 = Math.min (ry + rh, dest.y + dest.height);
\r
407 dest.width = x2 - x1;
\r
408 dest.height = y2 - y1;
\r
409 if (dest.width <= 0 || dest.height <= 0) {
\r
412 }, "java.awt.Rectangle,~N,~N,~N,~N");
\r
413 Clazz.defineStatics (c$,
\r
414 "DEFAULT_POSITION", 0,
\r
421 "DEFAULT_JUSTIFICATION", 0,
\r
429 "TEXT_INSET_H", 5);
\r