summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gilbert <david.gilbert@object-refinery.com>2005-10-10 08:28:44 +0000
committerDavid Gilbert <david.gilbert@object-refinery.com>2005-10-10 08:28:44 +0000
commit4f1cf3f49f40f2c385b0c5c299680d0a372de31d (patch)
treee9a7f560945350ca4486f82643e3925b3138b5d1
parent83229e190630176784aa2aa417975e4074e4ce7d (diff)
downloadclasspath-4f1cf3f49f40f2c385b0c5c299680d0a372de31d.tar.gz
2005-10-10 David Gilbert <david.gilbert@object-refinery.com>
* javax/swing/border/TitledBorder.java (TitledBorder(String)): Changed default justification and position, (TitledBorder(Border)): Likewise, (TitledBorder(Border, String)): Likewise, (BorderPainter.paint(Graphics)): Use full width and height, (BorderPainter.paintExcept): Fixed bounds for region 3, (paintBorder): indented left justified title further, adjusted ABOVE_TOP text position, adjusted bounds for call to paintExcept(), updated for renamed fields in Measurements class, (getMeasurements): added special handling for null text, increased outer spacing, adjusted spacing for TOP, BOTTOM and BELOW_BOTTOM title positions, (Measurements.borderSpacing): renamed outerSpacing, (Measurements.edgeSpacing): renamed innerSpacing, (Measurements.getContentInsets): updated for renamed fields, (Measurements.getMinimumSize): wrap at 80 columns. ----------------------------------------------------------------------
-rw-r--r--ChangeLog19
-rw-r--r--javax/swing/border/TitledBorder.java110
2 files changed, 81 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index fd9f81b86..8017a57f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2005-10-10 David Gilbert <david.gilbert@object-refinery.com>
+
+ * javax/swing/border/TitledBorder.java
+ (TitledBorder(String)): Changed default justification and position,
+ (TitledBorder(Border)): Likewise,
+ (TitledBorder(Border, String)): Likewise,
+ (BorderPainter.paint(Graphics)): Use full width and height,
+ (BorderPainter.paintExcept): Fixed bounds for region 3,
+ (paintBorder): indented left justified title further, adjusted
+ ABOVE_TOP text position, adjusted bounds for call to paintExcept(),
+ updated for renamed fields in Measurements class,
+ (getMeasurements): added special handling for null text, increased
+ outer spacing, adjusted spacing for TOP, BOTTOM and BELOW_BOTTOM title
+ positions,
+ (Measurements.borderSpacing): renamed outerSpacing,
+ (Measurements.edgeSpacing): renamed innerSpacing,
+ (Measurements.getContentInsets): updated for renamed fields,
+ (Measurements.getMinimumSize): wrap at 80 columns.
+
2005-10-09 Mark Wielaard <mark@klomp.org>
Fixes bug #24006
diff --git a/javax/swing/border/TitledBorder.java b/javax/swing/border/TitledBorder.java
index 3ed60815a..1c7068d02 100644
--- a/javax/swing/border/TitledBorder.java
+++ b/javax/swing/border/TitledBorder.java
@@ -1,5 +1,5 @@
/* TitledBorder.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -304,7 +304,7 @@ public class TitledBorder
public TitledBorder(String title)
{
this(/* border */ null,
- title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION,
+ title, LEADING, TOP,
/* titleFont */ null, /* titleColor */ null);
}
@@ -317,7 +317,7 @@ public class TitledBorder
*/
public TitledBorder(Border border)
{
- this(border, /* title */ "", DEFAULT_JUSTIFICATION, DEFAULT_POSITION,
+ this(border, /* title */ "", LEADING, TOP,
/* titleFont */ null, /* titleColor */ null);
}
@@ -333,7 +333,7 @@ public class TitledBorder
*/
public TitledBorder(Border border, String title)
{
- this(border, title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION,
+ this(border, title, LEADING, TOP,
/* titleFont */ null, /* titleColor */ null);
}
@@ -507,7 +507,7 @@ public class TitledBorder
public void paint(Graphics g)
{
if (b != null)
- b.paintBorder(c, g, x, y, width - 1, height - 1);
+ b.paintBorder(c, g, x, y, width, height);
}
@@ -565,7 +565,7 @@ public class TitledBorder
if (stripeHeight > 0)
{
paint(g, x, holeY, holeX - x, stripeHeight); // patches #2 and #3
- paint(g, holeX + holeWidth, holeY, width - (holeX + holeWidth), stripeHeight);
+ paint(g, holeX + holeWidth, holeY, x + width - (holeX + holeWidth), stripeHeight);
}
stripeHeight = height - (holeY - y + holeHeight);
@@ -577,16 +577,16 @@ public class TitledBorder
BorderPainter bp;
int textX, textY, borderWidth, borderHeight;
- borderWidth = width - (mes.borderSpacing.left + mes.borderSpacing.right);
- borderHeight = height - (mes.borderSpacing.top + mes.borderSpacing.bottom);
+ borderWidth = width - (mes.outerSpacing.left + mes.outerSpacing.right);
+ borderHeight = height - (mes.outerSpacing.top + mes.outerSpacing.bottom);
bp = new BorderPainter(c, getBorder(),
- x + mes.borderSpacing.left, y + mes.borderSpacing.top,
+ x + mes.outerSpacing.left, y + mes.outerSpacing.top,
borderWidth, borderHeight);
switch (getRealTitleJustification(c))
{
case LEFT:
- textX = x + TEXT_INSET_H;
+ textX = x + EDGE_SPACING + TEXT_INSET_H;
break;
case CENTER:
@@ -604,22 +604,22 @@ public class TitledBorder
switch (titlePosition)
{
case ABOVE_TOP:
- textY = y;
+ textY = y + EDGE_SPACING;
break;
case TOP:
case DEFAULT_POSITION:
default:
- textY = y + mes.borderSpacing.top + mes.borderInsets.top - mes.textAscent
+ textY = y + mes.outerSpacing.top + mes.borderInsets.top - mes.textAscent
+ mes.lineHeight;
break;
case BELOW_TOP:
- textY = y + mes.borderSpacing.top + mes.borderInsets.top + TEXT_SPACING;
+ textY = y + mes.outerSpacing.top + mes.borderInsets.top + TEXT_SPACING;
break;
case ABOVE_BOTTOM:
- textY = y + height - mes.borderSpacing.bottom - mes.borderInsets.bottom
+ textY = y + height - mes.outerSpacing.bottom - mes.borderInsets.bottom
- TEXT_SPACING - (mes.textAscent + mes.textDescent);
break;
@@ -644,8 +644,8 @@ public class TitledBorder
g.setFont(oldFont);
g.setColor(oldColor);
}
- bp.paintExcept(g, textX - 2, textY,
- mes.textWidth + 2, mes.textAscent + mes.textDescent);
+ bp.paintExcept(g, textX, textY,
+ mes.textWidth, mes.textAscent + mes.textDescent);
}
}
@@ -1002,49 +1002,63 @@ public class TitledBorder
m.trimmedText = null;
}
- m.textAscent = fmet.getAscent();
- m.textDescent = fmet.getDescent();
-
- FontRenderContext frc = new FontRenderContext(new AffineTransform(), false,
- false);
- LineMetrics lmet = m.font.getLineMetrics(m.trimmedText, 0,
- m.trimmedText.length(), frc);
- m.lineHeight = (int) lmet.getStrikethroughOffset();
- // Fallback in case that LineMetrics is not available/working.
- if (m.lineHeight == 0)
- m.lineHeight = (int) (0.3333 * (double) m.textAscent);
-
if (m.trimmedText != null)
- m.textWidth = fmet.stringWidth(m.trimmedText) + 3;
+ {
+ m.textAscent = fmet.getAscent();
+ m.textDescent = fmet.getDescent() + fmet.getLeading();
+
+ FontRenderContext frc = new FontRenderContext(new AffineTransform(),
+ false, false);
+ LineMetrics lmet = m.font.getLineMetrics(m.trimmedText, 0,
+ m.trimmedText.length(), frc);
+ m.lineHeight = (int) lmet.getStrikethroughOffset();
+
+ // Fallback in case that LineMetrics is not available/working.
+ if (m.lineHeight == 0)
+ m.lineHeight = (int) (0.3333 * (double) m.textAscent);
+ m.textWidth = fmet.stringWidth(m.trimmedText) + 3;
+ }
+ else
+ {
+ m.textAscent = 0;
+ m.textDescent = 0;
+ }
- m.edgeSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING, EDGE_SPACING);
- m.borderSpacing = new Insets(0, 0, 0, 0);
+ m.innerSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING,
+ EDGE_SPACING);
+ m.outerSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING,
+ EDGE_SPACING);
switch (titlePosition)
{
case ABOVE_TOP:
- m.borderSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
+ m.outerSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
break;
+ case TOP:
+ m.outerSpacing.top += m.textDescent + m.lineHeight;
+ m.innerSpacing.top += m.textAscent - m.lineHeight;
+ break;
+
case BELOW_TOP:
- m.edgeSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
+ m.innerSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
break;
case ABOVE_BOTTOM:
- m.edgeSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;
+ m.innerSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;
break;
case BOTTOM:
- m.edgeSpacing.bottom += Math.max(m.textAscent - m.borderInsets.bottom, 0);
- m.borderSpacing.bottom += m.textDescent;
+ m.innerSpacing.bottom += Math.max(m.textAscent - m.lineHeight, 0);
+ m.outerSpacing.bottom += m.textDescent + m.lineHeight;
break;
case BELOW_BOTTOM:
- m.borderSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;
+ m.outerSpacing.bottom += m.textAscent + m.textDescent;
break;
default:
- m.borderSpacing.top += m.textAscent;
+ m.outerSpacing.top += m.textAscent;
}
return m;
@@ -1067,7 +1081,7 @@ public class TitledBorder
* which means that the font is to be retrieved from the current
* LookAndFeel. In this case, this <code>font</code> field will
* contain the result of the retrieval. Therefore, it is safe
- * to assume that his <code>font</code> field will never have
+ * to assume that this <code>font</code> field will never have
* a <code>null</code> value.
*/
Font font;
@@ -1107,7 +1121,7 @@ public class TitledBorder
/**
- * The border that constitues the interior border
+ * The border that constitutes the interior border
* underneath the title text.
*/
Border border;
@@ -1116,8 +1130,7 @@ public class TitledBorder
/**
* The distance between the TitledBorder and the interior border.
*/
- Insets borderSpacing;
-
+ Insets outerSpacing;
/**
* The width of the interior border, as returned by
@@ -1130,7 +1143,7 @@ public class TitledBorder
* The distance between the interior border and the nested
* Component for which this TitledBorder is a border.
*/
- Insets edgeSpacing;
+ Insets innerSpacing;
/**
@@ -1149,10 +1162,10 @@ public class TitledBorder
{
if (i == null)
i = new Insets(0, 0, 0, 0);
- i.left = borderSpacing.left + borderInsets.left + edgeSpacing.left;
- i.right = borderSpacing.right + borderInsets.right + edgeSpacing.right;
- i.top = borderSpacing.top + borderInsets.top + edgeSpacing.top;
- i.bottom = borderSpacing.bottom + borderInsets.bottom + edgeSpacing.bottom;
+ i.left = outerSpacing.left + borderInsets.left + innerSpacing.left;
+ i.right = outerSpacing.right + borderInsets.right + innerSpacing.right;
+ i.top = outerSpacing.top + borderInsets.top + innerSpacing.top;
+ i.bottom = outerSpacing.bottom + borderInsets.bottom + innerSpacing.bottom;
return i;
}
@@ -1167,7 +1180,8 @@ public class TitledBorder
Insets insets;
insets = getContentInsets(null);
- width = Math.max(insets.left + insets.right, textWidth + 2 * TEXT_INSET_H);
+ width = Math.max(insets.left + insets.right, textWidth + 2
+ * TEXT_INSET_H);
return new Dimension(width, insets.top + insets.bottom);
}
}