X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fswingjs%2Fj2s%2Fjavax%2Fswing%2Fborder%2FTitledBorder.js;fp=site%2Fswingjs%2Fj2s%2Fjavax%2Fswing%2Fborder%2FTitledBorder.js;h=5e7f4c6e1423e21f8fbf8c15f1269af1ffe1a533;hp=e9a97666c7b9f09525bc27be4e308734a0977d58;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/swingjs/j2s/javax/swing/border/TitledBorder.js b/site/swingjs/j2s/javax/swing/border/TitledBorder.js index e9a9766..5e7f4c6 100644 --- a/site/swingjs/j2s/javax/swing/border/TitledBorder.js +++ b/site/swingjs/j2s/javax/swing/border/TitledBorder.js @@ -1,430 +1,430 @@ -Clazz.declarePackage ("javax.swing.border"); -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 () { -c$ = Clazz.decorateAsClass (function () { -this.title = null; -this.border = null; -this.titlePosition = 0; -this.titleJustification = 0; -this.titleFont = null; -this.titleColor = null; -this.textLoc = null; -Clazz.instantialize (this, arguments); -}, javax.swing.border, "TitledBorder", javax.swing.border.AbstractBorder); -Clazz.prepareFields (c$, function () { -this.textLoc = new java.awt.Point (); -}); -Clazz.makeConstructor (c$, -function (title) { -this.construct (null, title, 4, 0, null, null); -}, "~S"); -Clazz.makeConstructor (c$, -function (border) { -this.construct (border, "", 4, 0, null, null); -}, "javax.swing.border.Border"); -Clazz.makeConstructor (c$, -function (border, title) { -this.construct (border, title, 4, 0, null, null); -}, "javax.swing.border.Border,~S"); -Clazz.makeConstructor (c$, -function (border, title, titleJustification, titlePosition) { -this.construct (border, title, titleJustification, titlePosition, null, null); -}, "javax.swing.border.Border,~S,~N,~N"); -Clazz.makeConstructor (c$, -function (border, title, titleJustification, titlePosition, titleFont) { -this.construct (border, title, titleJustification, titlePosition, titleFont, null); -}, "javax.swing.border.Border,~S,~N,~N,java.awt.Font"); -Clazz.makeConstructor (c$, -function (border, title, titleJustification, titlePosition, titleFont, titleColor) { -Clazz.superConstructor (this, javax.swing.border.TitledBorder, []); -this.title = title; -this.border = border; -this.titleFont = titleFont; -this.titleColor = titleColor; -this.setTitleJustification (titleJustification); -this.setTitlePosition (titlePosition); -}, "javax.swing.border.Border,~S,~N,~N,java.awt.Font,java.awt.Color"); -Clazz.overrideMethod (c$, "paintBorder", -function (c, g, x, y, width, height) { -var border = this.getBorder (); -if (this.getTitle () == null || this.getTitle ().equals ("")) { -if (border != null) { -border.paintBorder (c, g, x, y, width, height); -}return; -}var grooveRect = new java.awt.Rectangle (x + 2, y + 2, width - (4), height - (4)); -var font = g.getFont (); -var color = g.getColor (); -g.setFont (this.getFont (c)); -var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null; -var fm = jssun.swing.SwingUtilities2.getFontMetrics (jc, g); -var fontHeight = fm.getHeight (); -var descent = fm.getDescent (); -var ascent = fm.getAscent (); -var diff; -var stringWidth = jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()); -var insets; -if (border != null) { -insets = border.getBorderInsets (c); -} else { -insets = new java.awt.Insets (0, 0, 0, 0); -}var titlePos = this.getTitlePosition (); -switch (titlePos) { -case 1: -diff = ascent + descent + (Math.max (2, 4) - 2); -grooveRect.y += diff; -grooveRect.height -= diff; -this.textLoc.y = grooveRect.y - (descent + 2); -break; -case 2: -case 0: -diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2); -grooveRect.y += diff; -grooveRect.height -= diff; -this.textLoc.y = (grooveRect.y - descent) + Clazz.doubleToInt ((insets.top + ascent + descent) / 2); -break; -case 3: -this.textLoc.y = grooveRect.y + insets.top + ascent + 2; -break; -case 4: -this.textLoc.y = (grooveRect.y + grooveRect.height) - (insets.bottom + descent + 2); -break; -case 5: -grooveRect.height -= Clazz.doubleToInt (fontHeight / 2); -this.textLoc.y = ((grooveRect.y + grooveRect.height) - descent) + Clazz.doubleToInt (((ascent + descent) - insets.bottom) / 2); -break; -case 6: -grooveRect.height -= fontHeight; -this.textLoc.y = grooveRect.y + grooveRect.height + ascent + 2; -break; -} -var justification = this.getTitleJustification (); -if (javax.swing.border.AbstractBorder.isLeftToRight (c)) { -if (justification == 4 || justification == 0) { -justification = 1; -} else if (justification == 5) { -justification = 3; -}} else { -if (justification == 4 || justification == 0) { -justification = 3; -} else if (justification == 5) { -justification = 1; -}}switch (justification) { -case 1: -this.textLoc.x = grooveRect.x + 5 + insets.left; -break; -case 3: -this.textLoc.x = (grooveRect.x + grooveRect.width) - (stringWidth + 5 + insets.right); -break; -case 2: -this.textLoc.x = grooveRect.x + (Clazz.doubleToInt ((grooveRect.width - stringWidth) / 2)); -break; -} -if (border != null) { -if (((titlePos == 2 || titlePos == 0) && (grooveRect.y > this.textLoc.y - ascent)) || (titlePos == 5 && (grooveRect.y + grooveRect.height < this.textLoc.y + descent))) { -var clipRect = new java.awt.Rectangle (); -var saveClip = g.getClipBounds (); -clipRect.setBounds (saveClip); -if (javax.swing.border.TitledBorder.computeIntersection (clipRect, x, y, this.textLoc.x - 1 - x, height)) { -g.setClip (clipRect); -border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); -}clipRect.setBounds (saveClip); -if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x + stringWidth + 1, y, x + width - (this.textLoc.x + stringWidth + 1), height)) { -g.setClip (clipRect); -border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); -}if (titlePos == 2 || titlePos == 0) { -clipRect.setBounds (saveClip); -if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, this.textLoc.y + descent, stringWidth + 2, y + height - this.textLoc.y - descent)) { -g.setClip (clipRect); -border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); -}} else { -clipRect.setBounds (saveClip); -if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, y, stringWidth + 2, this.textLoc.y - ascent - y)) { -g.setClip (clipRect); -border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); -}}g.setClip (saveClip); -} else { -border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); -}}g.setColor (this.getTitleColor ()); -jssun.swing.SwingUtilities2.drawString (jc, g, this.getTitle (), this.textLoc.x, this.textLoc.y); -g.setFont (font); -g.setColor (color); -}, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N"); -Clazz.defineMethod (c$, "getBorderInsets", -function (c) { -return this.getBorderInsets (c, new java.awt.Insets (0, 0, 0, 0)); -}, "java.awt.Component"); -Clazz.defineMethod (c$, "getBorderInsets", -function (c, insets) { -var fm; -var descent = 0; -var ascent = 16; -var height = 16; -var border = this.getBorder (); -if (border != null) { -if (Clazz.instanceOf (border, javax.swing.border.AbstractBorder)) { -(border).getBorderInsets (c, insets); -} else { -var i = border.getBorderInsets (c); -insets.top = i.top; -insets.right = i.right; -insets.bottom = i.bottom; -insets.left = i.left; -}} else { -insets.left = insets.top = insets.right = insets.bottom = 0; -}insets.left += 4; -insets.right += 4; -insets.top += 4; -insets.bottom += 4; -if (c == null || this.getTitle () == null || this.getTitle ().equals ("")) { -return insets; -}var font = this.getFont (c); -fm = c.getFontMetrics (font); -if (fm != null) { -descent = fm.getDescent (); -ascent = fm.getAscent (); -height = fm.getHeight (); -}switch (this.getTitlePosition ()) { -case 1: -insets.top += ascent + descent + (Math.max (2, 4) - 2); -break; -case 2: -case 0: -insets.top += ascent + descent; -break; -case 3: -insets.top += ascent + descent + 2; -break; -case 4: -insets.bottom += ascent + descent + 2; -break; -case 5: -insets.bottom += ascent + descent; -break; -case 6: -insets.bottom += height; -break; -} -return insets; -}, "java.awt.Component,java.awt.Insets"); -Clazz.overrideMethod (c$, "isBorderOpaque", -function () { -return false; -}); -Clazz.defineMethod (c$, "getTitle", -function () { -return this.title; -}); -Clazz.defineMethod (c$, "getBorder", -function () { -var b = this.border; -if (b == null) b = javax.swing.UIManager.getBorder ("TitledBorder.border"); -return b; -}); -Clazz.defineMethod (c$, "getTitlePosition", -function () { -if (this.titlePosition == 0) { -var value = javax.swing.UIManager.get ("TitledBorder.position"); -if (Clazz.instanceOf (value, String)) { -var s = value; -if ("ABOVE_TOP".equalsIgnoreCase (s)) { -return 1; -} else if ("TOP".equalsIgnoreCase (s)) { -return 2; -} else if ("BELOW_TOP".equalsIgnoreCase (s)) { -return 3; -} else if ("ABOVE_BOTTOM".equalsIgnoreCase (s)) { -return 4; -} else if ("BOTTOM".equalsIgnoreCase (s)) { -return 5; -} else if ("BELOW_BOTTOM".equalsIgnoreCase (s)) { -return 6; -}} else if (Clazz.instanceOf (value, Integer)) { -var i = (value).intValue (); -if (i >= 0 && i <= 6) { -return i; -}}}return this.titlePosition; -}); -Clazz.defineMethod (c$, "getTitleJustification", -function () { -return this.titleJustification; -}); -Clazz.defineMethod (c$, "getTitleFont", -function () { -var f = this.titleFont; -if (f == null) f = javax.swing.UIManager.getFont ("TitledBorder.font"); -return f; -}); -Clazz.defineMethod (c$, "getTitleColor", -function () { -var c = this.titleColor; -if (c == null) c = javax.swing.UIManager.getColor ("TitledBorder.titleColor"); -return c; -}); -Clazz.defineMethod (c$, "setTitle", -function (title) { -this.title = title; -}, "~S"); -Clazz.defineMethod (c$, "setBorder", -function (border) { -this.border = border; -}, "javax.swing.border.Border"); -Clazz.defineMethod (c$, "setTitlePosition", -function (titlePosition) { -switch (titlePosition) { -case 1: -case 2: -case 3: -case 4: -case 5: -case 6: -case 0: -this.titlePosition = titlePosition; -break; -default: -throw new IllegalArgumentException (titlePosition + " is not a valid title position."); -} -}, "~N"); -Clazz.defineMethod (c$, "setTitleJustification", -function (titleJustification) { -switch (titleJustification) { -case 0: -case 1: -case 2: -case 3: -case 4: -case 5: -this.titleJustification = titleJustification; -break; -default: -throw new IllegalArgumentException (titleJustification + " is not a valid title justification."); -} -}, "~N"); -Clazz.defineMethod (c$, "setTitleFont", -function (titleFont) { -this.titleFont = titleFont; -}, "java.awt.Font"); -Clazz.defineMethod (c$, "setTitleColor", -function (titleColor) { -this.titleColor = titleColor; -}, "java.awt.Color"); -Clazz.defineMethod (c$, "getMinimumSize", -function (c) { -var insets = this.getBorderInsets (c); -var minSize = new java.awt.Dimension (insets.right + insets.left, insets.top + insets.bottom); -var font = this.getFont (c); -var fm = c.getFontMetrics (font); -var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null; -switch (this.getTitlePosition ()) { -case 1: -case 6: -minSize.width = Math.max (jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()), minSize.width); -break; -case 3: -case 4: -case 2: -case 5: -case 0: -default: -minSize.width += jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()); -} -return minSize; -}, "java.awt.Component"); -Clazz.overrideMethod (c$, "getBaseline", -function (c, width, height) { -if (c == null) { -throw new NullPointerException ("Must supply non-null component"); -}if (height < 0) { -throw new IllegalArgumentException ("Height must be >= 0"); -}var title = this.getTitle (); -if (title != null && !"".equals (title)) { -var font = this.getFont (c); -var border2 = this.getBorder (); -var borderInsets; -if (border2 != null) { -borderInsets = border2.getBorderInsets (c); -} else { -borderInsets = new java.awt.Insets (0, 0, 0, 0); -}var fm = c.getFontMetrics (font); -var fontHeight = fm.getHeight (); -var descent = fm.getDescent (); -var ascent = fm.getAscent (); -var y = 2; -var h = height - 4; -var diff; -switch (this.getTitlePosition ()) { -case 1: -diff = ascent + descent + (Math.max (2, 4) - 2); -return y + diff - (descent + 2); -case 2: -case 0: -diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2); -return (y + diff - descent) + Clazz.doubleToInt ((borderInsets.top + ascent + descent) / 2); -case 3: -return y + borderInsets.top + ascent + 2; -case 4: -return (y + h) - (borderInsets.bottom + descent + 2); -case 5: -h -= Clazz.doubleToInt (fontHeight / 2); -return ((y + h) - descent) + Clazz.doubleToInt (((ascent + descent) - borderInsets.bottom) / 2); -case 6: -h -= fontHeight; -return y + h + ascent + 2; -} -}return -1; -}, "java.awt.Component,~N,~N"); -Clazz.defineMethod (c$, "getBaselineResizeBehavior", -function (c) { -Clazz.superCall (this, javax.swing.border.TitledBorder, "getBaselineResizeBehavior", [c]); -switch (this.getTitlePosition ()) { -case 1: -case 2: -case 0: -case 3: -return java.awt.Component.BaselineResizeBehavior.CONSTANT_ASCENT; -case 4: -case 5: -case 6: -return java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT; -} -return java.awt.Component.BaselineResizeBehavior.OTHER; -}, "java.awt.Component"); -Clazz.defineMethod (c$, "getFont", -function (c) { -var font; -if ((font = this.getTitleFont ()) != null) { -return font; -} else if (c != null && (font = c.getFont ()) != null) { -return font; -}return new java.awt.Font ("Dialog", 0, 12); -}, "java.awt.Component"); -c$.computeIntersection = Clazz.defineMethod (c$, "computeIntersection", - function (dest, rx, ry, rw, rh) { -var x1 = Math.max (rx, dest.x); -var x2 = Math.min (rx + rw, dest.x + dest.width); -var y1 = Math.max (ry, dest.y); -var y2 = Math.min (ry + rh, dest.y + dest.height); -dest.x = x1; -dest.y = y1; -dest.width = x2 - x1; -dest.height = y2 - y1; -if (dest.width <= 0 || dest.height <= 0) { -return false; -}return true; -}, "java.awt.Rectangle,~N,~N,~N,~N"); -Clazz.defineStatics (c$, -"DEFAULT_POSITION", 0, -"ABOVE_TOP", 1, -"TOP", 2, -"BELOW_TOP", 3, -"ABOVE_BOTTOM", 4, -"BOTTOM", 5, -"BELOW_BOTTOM", 6, -"DEFAULT_JUSTIFICATION", 0, -"LEFT", 1, -"CENTER", 2, -"RIGHT", 3, -"LEADING", 4, -"TRAILING", 5, -"EDGE_SPACING", 2, -"TEXT_SPACING", 2, -"TEXT_INSET_H", 5); -}); +Clazz.declarePackage ("javax.swing.border"); +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 () { +c$ = Clazz.decorateAsClass (function () { +this.title = null; +this.border = null; +this.titlePosition = 0; +this.titleJustification = 0; +this.titleFont = null; +this.titleColor = null; +this.textLoc = null; +Clazz.instantialize (this, arguments); +}, javax.swing.border, "TitledBorder", javax.swing.border.AbstractBorder); +Clazz.prepareFields (c$, function () { +this.textLoc = new java.awt.Point (); +}); +Clazz.makeConstructor (c$, +function (title) { +this.construct (null, title, 4, 0, null, null); +}, "~S"); +Clazz.makeConstructor (c$, +function (border) { +this.construct (border, "", 4, 0, null, null); +}, "javax.swing.border.Border"); +Clazz.makeConstructor (c$, +function (border, title) { +this.construct (border, title, 4, 0, null, null); +}, "javax.swing.border.Border,~S"); +Clazz.makeConstructor (c$, +function (border, title, titleJustification, titlePosition) { +this.construct (border, title, titleJustification, titlePosition, null, null); +}, "javax.swing.border.Border,~S,~N,~N"); +Clazz.makeConstructor (c$, +function (border, title, titleJustification, titlePosition, titleFont) { +this.construct (border, title, titleJustification, titlePosition, titleFont, null); +}, "javax.swing.border.Border,~S,~N,~N,java.awt.Font"); +Clazz.makeConstructor (c$, +function (border, title, titleJustification, titlePosition, titleFont, titleColor) { +Clazz.superConstructor (this, javax.swing.border.TitledBorder, []); +this.title = title; +this.border = border; +this.titleFont = titleFont; +this.titleColor = titleColor; +this.setTitleJustification (titleJustification); +this.setTitlePosition (titlePosition); +}, "javax.swing.border.Border,~S,~N,~N,java.awt.Font,java.awt.Color"); +Clazz.overrideMethod (c$, "paintBorder", +function (c, g, x, y, width, height) { +var border = this.getBorder (); +if (this.getTitle () == null || this.getTitle ().equals ("")) { +if (border != null) { +border.paintBorder (c, g, x, y, width, height); +}return; +}var grooveRect = new java.awt.Rectangle (x + 2, y + 2, width - (4), height - (4)); +var font = g.getFont (); +var color = g.getColor (); +g.setFont (this.getFont (c)); +var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null; +var fm = jssun.swing.SwingUtilities2.getFontMetrics (jc, g); +var fontHeight = fm.getHeight (); +var descent = fm.getDescent (); +var ascent = fm.getAscent (); +var diff; +var stringWidth = jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()); +var insets; +if (border != null) { +insets = border.getBorderInsets (c); +} else { +insets = new java.awt.Insets (0, 0, 0, 0); +}var titlePos = this.getTitlePosition (); +switch (titlePos) { +case 1: +diff = ascent + descent + (Math.max (2, 4) - 2); +grooveRect.y += diff; +grooveRect.height -= diff; +this.textLoc.y = grooveRect.y - (descent + 2); +break; +case 2: +case 0: +diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2); +grooveRect.y += diff; +grooveRect.height -= diff; +this.textLoc.y = (grooveRect.y - descent) + Clazz.doubleToInt ((insets.top + ascent + descent) / 2); +break; +case 3: +this.textLoc.y = grooveRect.y + insets.top + ascent + 2; +break; +case 4: +this.textLoc.y = (grooveRect.y + grooveRect.height) - (insets.bottom + descent + 2); +break; +case 5: +grooveRect.height -= Clazz.doubleToInt (fontHeight / 2); +this.textLoc.y = ((grooveRect.y + grooveRect.height) - descent) + Clazz.doubleToInt (((ascent + descent) - insets.bottom) / 2); +break; +case 6: +grooveRect.height -= fontHeight; +this.textLoc.y = grooveRect.y + grooveRect.height + ascent + 2; +break; +} +var justification = this.getTitleJustification (); +if (javax.swing.border.AbstractBorder.isLeftToRight (c)) { +if (justification == 4 || justification == 0) { +justification = 1; +} else if (justification == 5) { +justification = 3; +}} else { +if (justification == 4 || justification == 0) { +justification = 3; +} else if (justification == 5) { +justification = 1; +}}switch (justification) { +case 1: +this.textLoc.x = grooveRect.x + 5 + insets.left; +break; +case 3: +this.textLoc.x = (grooveRect.x + grooveRect.width) - (stringWidth + 5 + insets.right); +break; +case 2: +this.textLoc.x = grooveRect.x + (Clazz.doubleToInt ((grooveRect.width - stringWidth) / 2)); +break; +} +if (border != null) { +if (((titlePos == 2 || titlePos == 0) && (grooveRect.y > this.textLoc.y - ascent)) || (titlePos == 5 && (grooveRect.y + grooveRect.height < this.textLoc.y + descent))) { +var clipRect = new java.awt.Rectangle (); +var saveClip = g.getClipBounds (); +clipRect.setBounds (saveClip); +if (javax.swing.border.TitledBorder.computeIntersection (clipRect, x, y, this.textLoc.x - 1 - x, height)) { +g.setClip (clipRect); +border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); +}clipRect.setBounds (saveClip); +if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x + stringWidth + 1, y, x + width - (this.textLoc.x + stringWidth + 1), height)) { +g.setClip (clipRect); +border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); +}if (titlePos == 2 || titlePos == 0) { +clipRect.setBounds (saveClip); +if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, this.textLoc.y + descent, stringWidth + 2, y + height - this.textLoc.y - descent)) { +g.setClip (clipRect); +border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); +}} else { +clipRect.setBounds (saveClip); +if (javax.swing.border.TitledBorder.computeIntersection (clipRect, this.textLoc.x - 1, y, stringWidth + 2, this.textLoc.y - ascent - y)) { +g.setClip (clipRect); +border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); +}}g.setClip (saveClip); +} else { +border.paintBorder (c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height); +}}g.setColor (this.getTitleColor ()); +jssun.swing.SwingUtilities2.drawString (jc, g, this.getTitle (), this.textLoc.x, this.textLoc.y); +g.setFont (font); +g.setColor (color); +}, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N"); +Clazz.defineMethod (c$, "getBorderInsets", +function (c) { +return this.getBorderInsets (c, new java.awt.Insets (0, 0, 0, 0)); +}, "java.awt.Component"); +Clazz.defineMethod (c$, "getBorderInsets", +function (c, insets) { +var fm; +var descent = 0; +var ascent = 16; +var height = 16; +var border = this.getBorder (); +if (border != null) { +if (Clazz.instanceOf (border, javax.swing.border.AbstractBorder)) { +(border).getBorderInsets (c, insets); +} else { +var i = border.getBorderInsets (c); +insets.top = i.top; +insets.right = i.right; +insets.bottom = i.bottom; +insets.left = i.left; +}} else { +insets.left = insets.top = insets.right = insets.bottom = 0; +}insets.left += 4; +insets.right += 4; +insets.top += 4; +insets.bottom += 4; +if (c == null || this.getTitle () == null || this.getTitle ().equals ("")) { +return insets; +}var font = this.getFont (c); +fm = c.getFontMetrics (font); +if (fm != null) { +descent = fm.getDescent (); +ascent = fm.getAscent (); +height = fm.getHeight (); +}switch (this.getTitlePosition ()) { +case 1: +insets.top += ascent + descent + (Math.max (2, 4) - 2); +break; +case 2: +case 0: +insets.top += ascent + descent; +break; +case 3: +insets.top += ascent + descent + 2; +break; +case 4: +insets.bottom += ascent + descent + 2; +break; +case 5: +insets.bottom += ascent + descent; +break; +case 6: +insets.bottom += height; +break; +} +return insets; +}, "java.awt.Component,java.awt.Insets"); +Clazz.overrideMethod (c$, "isBorderOpaque", +function () { +return false; +}); +Clazz.defineMethod (c$, "getTitle", +function () { +return this.title; +}); +Clazz.defineMethod (c$, "getBorder", +function () { +var b = this.border; +if (b == null) b = javax.swing.UIManager.getBorder ("TitledBorder.border"); +return b; +}); +Clazz.defineMethod (c$, "getTitlePosition", +function () { +if (this.titlePosition == 0) { +var value = javax.swing.UIManager.get ("TitledBorder.position"); +if (Clazz.instanceOf (value, String)) { +var s = value; +if ("ABOVE_TOP".equalsIgnoreCase (s)) { +return 1; +} else if ("TOP".equalsIgnoreCase (s)) { +return 2; +} else if ("BELOW_TOP".equalsIgnoreCase (s)) { +return 3; +} else if ("ABOVE_BOTTOM".equalsIgnoreCase (s)) { +return 4; +} else if ("BOTTOM".equalsIgnoreCase (s)) { +return 5; +} else if ("BELOW_BOTTOM".equalsIgnoreCase (s)) { +return 6; +}} else if (Clazz.instanceOf (value, Integer)) { +var i = (value).intValue (); +if (i >= 0 && i <= 6) { +return i; +}}}return this.titlePosition; +}); +Clazz.defineMethod (c$, "getTitleJustification", +function () { +return this.titleJustification; +}); +Clazz.defineMethod (c$, "getTitleFont", +function () { +var f = this.titleFont; +if (f == null) f = javax.swing.UIManager.getFont ("TitledBorder.font"); +return f; +}); +Clazz.defineMethod (c$, "getTitleColor", +function () { +var c = this.titleColor; +if (c == null) c = javax.swing.UIManager.getColor ("TitledBorder.titleColor"); +return c; +}); +Clazz.defineMethod (c$, "setTitle", +function (title) { +this.title = title; +}, "~S"); +Clazz.defineMethod (c$, "setBorder", +function (border) { +this.border = border; +}, "javax.swing.border.Border"); +Clazz.defineMethod (c$, "setTitlePosition", +function (titlePosition) { +switch (titlePosition) { +case 1: +case 2: +case 3: +case 4: +case 5: +case 6: +case 0: +this.titlePosition = titlePosition; +break; +default: +throw new IllegalArgumentException (titlePosition + " is not a valid title position."); +} +}, "~N"); +Clazz.defineMethod (c$, "setTitleJustification", +function (titleJustification) { +switch (titleJustification) { +case 0: +case 1: +case 2: +case 3: +case 4: +case 5: +this.titleJustification = titleJustification; +break; +default: +throw new IllegalArgumentException (titleJustification + " is not a valid title justification."); +} +}, "~N"); +Clazz.defineMethod (c$, "setTitleFont", +function (titleFont) { +this.titleFont = titleFont; +}, "java.awt.Font"); +Clazz.defineMethod (c$, "setTitleColor", +function (titleColor) { +this.titleColor = titleColor; +}, "java.awt.Color"); +Clazz.defineMethod (c$, "getMinimumSize", +function (c) { +var insets = this.getBorderInsets (c); +var minSize = new java.awt.Dimension (insets.right + insets.left, insets.top + insets.bottom); +var font = this.getFont (c); +var fm = c.getFontMetrics (font); +var jc = (Clazz.instanceOf (c, javax.swing.JComponent)) ? c : null; +switch (this.getTitlePosition ()) { +case 1: +case 6: +minSize.width = Math.max (jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()), minSize.width); +break; +case 3: +case 4: +case 2: +case 5: +case 0: +default: +minSize.width += jssun.swing.SwingUtilities2.stringWidth (jc, fm, this.getTitle ()); +} +return minSize; +}, "java.awt.Component"); +Clazz.overrideMethod (c$, "getBaseline", +function (c, width, height) { +if (c == null) { +throw new NullPointerException ("Must supply non-null component"); +}if (height < 0) { +throw new IllegalArgumentException ("Height must be >= 0"); +}var title = this.getTitle (); +if (title != null && !"".equals (title)) { +var font = this.getFont (c); +var border2 = this.getBorder (); +var borderInsets; +if (border2 != null) { +borderInsets = border2.getBorderInsets (c); +} else { +borderInsets = new java.awt.Insets (0, 0, 0, 0); +}var fm = c.getFontMetrics (font); +var fontHeight = fm.getHeight (); +var descent = fm.getDescent (); +var ascent = fm.getAscent (); +var y = 2; +var h = height - 4; +var diff; +switch (this.getTitlePosition ()) { +case 1: +diff = ascent + descent + (Math.max (2, 4) - 2); +return y + diff - (descent + 2); +case 2: +case 0: +diff = Math.max (0, ((Clazz.doubleToInt (ascent / 2)) + 2) - 2); +return (y + diff - descent) + Clazz.doubleToInt ((borderInsets.top + ascent + descent) / 2); +case 3: +return y + borderInsets.top + ascent + 2; +case 4: +return (y + h) - (borderInsets.bottom + descent + 2); +case 5: +h -= Clazz.doubleToInt (fontHeight / 2); +return ((y + h) - descent) + Clazz.doubleToInt (((ascent + descent) - borderInsets.bottom) / 2); +case 6: +h -= fontHeight; +return y + h + ascent + 2; +} +}return -1; +}, "java.awt.Component,~N,~N"); +Clazz.defineMethod (c$, "getBaselineResizeBehavior", +function (c) { +Clazz.superCall (this, javax.swing.border.TitledBorder, "getBaselineResizeBehavior", [c]); +switch (this.getTitlePosition ()) { +case 1: +case 2: +case 0: +case 3: +return java.awt.Component.BaselineResizeBehavior.CONSTANT_ASCENT; +case 4: +case 5: +case 6: +return java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT; +} +return java.awt.Component.BaselineResizeBehavior.OTHER; +}, "java.awt.Component"); +Clazz.defineMethod (c$, "getFont", +function (c) { +var font; +if ((font = this.getTitleFont ()) != null) { +return font; +} else if (c != null && (font = c.getFont ()) != null) { +return font; +}return new java.awt.Font ("Dialog", 0, 12); +}, "java.awt.Component"); +c$.computeIntersection = Clazz.defineMethod (c$, "computeIntersection", + function (dest, rx, ry, rw, rh) { +var x1 = Math.max (rx, dest.x); +var x2 = Math.min (rx + rw, dest.x + dest.width); +var y1 = Math.max (ry, dest.y); +var y2 = Math.min (ry + rh, dest.y + dest.height); +dest.x = x1; +dest.y = y1; +dest.width = x2 - x1; +dest.height = y2 - y1; +if (dest.width <= 0 || dest.height <= 0) { +return false; +}return true; +}, "java.awt.Rectangle,~N,~N,~N,~N"); +Clazz.defineStatics (c$, +"DEFAULT_POSITION", 0, +"ABOVE_TOP", 1, +"TOP", 2, +"BELOW_TOP", 3, +"ABOVE_BOTTOM", 4, +"BOTTOM", 5, +"BELOW_BOTTOM", 6, +"DEFAULT_JUSTIFICATION", 0, +"LEFT", 1, +"CENTER", 2, +"RIGHT", 3, +"LEADING", 4, +"TRAILING", 5, +"EDGE_SPACING", 2, +"TEXT_SPACING", 2, +"TEXT_INSET_H", 5); +});