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