From c1f89f922790ef95917bb120cc3c82e7362f0baa Mon Sep 17 00:00:00 2001 From: samskivert Date: Thu, 18 Dec 2008 01:20:31 +0000 Subject: [PATCH] Widening, and switch to KEY_TEXT_ANTIALIASING when laying out instead of KEY_ANTIALIASING, since labels are all about text. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2506 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/MultiLineLabel.java | 84 ++++++++----------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/src/java/com/samskivert/swing/MultiLineLabel.java b/src/java/com/samskivert/swing/MultiLineLabel.java index 4a0c3db9..422f3bc8 100644 --- a/src/java/com/samskivert/swing/MultiLineLabel.java +++ b/src/java/com/samskivert/swing/MultiLineLabel.java @@ -53,8 +53,8 @@ public class MultiLineLabel extends JComponent } /** - * Constructs a multi line label that displays the supplied text with - * center-alignment. The default layout is all on one line. + * Constructs a multi line label that displays the supplied text with center-alignment. The + * default layout is all on one line. * * @see #setLayout */ @@ -64,8 +64,8 @@ public class MultiLineLabel extends JComponent } /** - * Constructs a multi line label that displays the supplied text with - * the specified alignment. The default layout is all on one line. + * Constructs a multi line label that displays the supplied text with the specified + * alignment. The default layout is all on one line. * * @see #setLayout */ @@ -75,8 +75,8 @@ public class MultiLineLabel extends JComponent } /** - * Constructs a multi line label that displays the supplied text with - * the specified alignment. The default layout is all on one line. + * Constructs a multi line label that displays the supplied text with the specified + * alignment. The default layout is all on one line. * * @see #setLayout */ @@ -88,8 +88,7 @@ public class MultiLineLabel extends JComponent } /** - * Sets whether this label's text should be rendered with - * anti-aliasing. + * Sets whether this label's text should be rendered with anti-aliasing. */ public void setAntiAliased (boolean antialiased) { @@ -101,16 +100,13 @@ public class MultiLineLabel extends JComponent /** * Sets the constraints to be used when laying out the label. * - * @param constrain {@link #HORIZONTAL} or {@link #VERTICAL} or {@link - * #GOLDEN} if the label should be laid out in a rectangle whose - * bounds approximate the golden ratio. - * @param size the width or height respectively to be targeted by the - * label or 0 if the label should react the first time it is laid out - * and use the dimension available at that point. Note: this - * requires that the label invalidate itself during its first - * validation which will cause it to change size visibly in the user - * interface. This argument is ignored if constrain is - * {@link #GOLDEN}. + * @param constrain {@link #HORIZONTAL} or {@link #VERTICAL} or {@link #GOLDEN} if the label + * should be laid out in a rectangle whose bounds approximate the golden ratio. + * @param size the width or height respectively to be targeted by the label or 0 if the label + * should react the first time it is laid out and use the dimension available at that + * point. Note: this requires that the label invalidate itself during its first + * validation which will cause it to change size visibly in the user interface. This argument + * is ignored if constrain is {@link #GOLDEN}. */ public void setLayout (int constrain, int size) { @@ -148,8 +144,7 @@ public class MultiLineLabel extends JComponent break; default: - throw new IllegalArgumentException( - "Invalid constraint orientation " + constrain); + throw new IllegalArgumentException("Invalid constraint orientation " + constrain); } } @@ -265,15 +260,15 @@ public class MultiLineLabel extends JComponent { super.doLayout(); - // if we have been configured to relay ourselves out once we know - // our constrained width or height, take care of that here + // if we have been configured to relay ourselves out once we know our constrained width or + // height, take care of that here int size; boolean delayedRevalidate = false; switch (_constrain) { case HORIZONTAL: size = getWidth(); - // sanity check; sometimes labels are laid out with completely - // invalid dimensions, so we just quietly play along + // sanity check; sometimes labels are laid out with completely invalid dimensions, so + // we just quietly play along if (size > 0 && size != _constrainedSize) { _constrainedSize = size; _label.setTargetWidth(size); @@ -291,16 +286,13 @@ public class MultiLineLabel extends JComponent break; } - // we can't just call revalidate() because we're in the middle of - // a validation traversal; our parent will, when we return from - // this method, declare itself to be valid; if we call - // revalidate() it will mark us and all of our parents as invalid, - // but then those of our parents that are involved in the first - // validation traversal will mark themselves as valid and in the - // validation pass that results from our call to revalidate() we - // will be skipped over; dooh! instead we delay a call to - // revalidate so that the current validation traversal will be - // completed before we mark ourselves and our parents as invalid + // we can't just call revalidate() because we're in the middle of a validation traversal; + // our parent will, when we return from this method, declare itself to be valid; if we call + // revalidate() it will mark us and all of our parents as invalid, but then those of our + // parents that are involved in the first validation traversal will mark themselves as + // valid and in the validation pass that results from our call to revalidate() we will be + // skipped over; dooh! instead we delay a call to revalidate so that the current validation + // traversal will be completed before we mark ourselves and our parents as invalid if (delayedRevalidate) { Runnable callRevalidate = new Runnable() { public void run() { @@ -310,8 +302,7 @@ public class MultiLineLabel extends JComponent SwingUtilities.invokeLater(callRevalidate); } - // go ahead and lay out the label in all cases so that we assume - // some sort of size + // go ahead and lay out the label in all cases so that we assume some sort of size layoutLabel(); } @@ -324,19 +315,17 @@ public class MultiLineLabel extends JComponent } /** - * Called when the label has changed in some meaningful way and we'd - * accordingly like to re-layout the label, update our component's - * size, and repaint everything to suit. + * Called when the label has changed in some meaningful way and we'd accordingly like to + * re-layout the label, update our component's size, and repaint everything to suit. */ protected void layoutLabel () { Graphics2D gfx = (Graphics2D)getGraphics(); if (gfx != null) { // re-layout the label - gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - (_antialiased) ? - RenderingHints.VALUE_ANTIALIAS_ON : - RenderingHints.VALUE_ANTIALIAS_OFF); + gfx.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, (_antialiased) ? + RenderingHints.VALUE_TEXT_ANTIALIAS_ON : + RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); _label.layout(gfx); gfx.dispose(); @@ -353,15 +342,13 @@ public class MultiLineLabel extends JComponent } if (_dirty) { - // attempt to lay out the label before obtaining its preferred - // dimensions + // attempt to lay out the label before obtaining its preferred dimensions layoutLabel(); } Dimension size = _label.getSize(); if (size != null) { - // never let our preferred size shrink in our constrained - // direction + // never let our preferred size shrink in our constrained direction switch (_constrain) { case HORIZONTAL: _prefd.width = Math.max(_prefd.width, size.width); @@ -395,8 +382,7 @@ public class MultiLineLabel extends JComponent /** Pending constraint adjustments. */ protected int _constrain = NONE; - /** The size to which we constrained ourselves when most recently laid - * out. */ + /** The size to which we constrained ourselves when most recently laid out. */ protected int _constrainedSize; /** Whether to render the label with anti-aliasing. */