Deprecated MultilineLabel.setAntiAliased(), made Label honor
SwingUtil.getDefaultTextAntiAliased(), tidied up some bits related to SwingUtil.restoreAntiAliasing(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@2512 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -49,6 +49,8 @@ import com.samskivert.util.RunAnywhere;
|
|||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
import com.samskivert.util.Tuple;
|
import com.samskivert.util.Tuple;
|
||||||
|
|
||||||
|
import com.samskivert.swing.util.SwingUtil;
|
||||||
|
|
||||||
import static com.samskivert.Log.log;
|
import static com.samskivert.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -377,6 +379,10 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
FontRenderContext frc = gfx.getFontRenderContext();
|
FontRenderContext frc = gfx.getFontRenderContext();
|
||||||
List<Tuple<TextLayout,Rectangle2D>> layouts = null;
|
List<Tuple<TextLayout,Rectangle2D>> layouts = null;
|
||||||
|
|
||||||
|
// if text antialiasing is enabled by default, honor that setting
|
||||||
|
Object oalias = SwingUtil.getDefaultTextAntialiasing() ?
|
||||||
|
SwingUtil.activateAntiAliasing(gfx) : null;
|
||||||
|
|
||||||
// if we have a target height, do some processing and convert that into a target width
|
// if we have a target height, do some processing and convert that into a target width
|
||||||
if (_constraints.height > 0 || _constraints.width == -1) {
|
if (_constraints.height > 0 || _constraints.width == -1) {
|
||||||
int targetHeight = _constraints.height;
|
int targetHeight = _constraints.height;
|
||||||
@@ -458,6 +464,9 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
_leaders[ii] = (float)-_lbounds[ii].getX();
|
_leaders[ii] = (float)-_lbounds[ii].getX();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// finally restore our antialiasing state
|
||||||
|
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,13 +72,10 @@ public abstract class LabelSausage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lay out our label
|
// lay out our label
|
||||||
if (SwingUtil.getDefaultTextAntialiasing()) {
|
Object oalias = SwingUtil.getDefaultTextAntialiasing() ?
|
||||||
Object oalias = SwingUtil.activateAntiAliasing(gfx);
|
SwingUtil.activateAntiAliasing(gfx) : null;
|
||||||
_label.layout(gfx);
|
_label.layout(gfx);
|
||||||
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
||||||
} else {
|
|
||||||
_label.layout(gfx);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dimension lsize = _label.getSize();
|
Dimension lsize = _label.getSize();
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.RenderingHints;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
@@ -88,13 +87,12 @@ public class MultiLineLabel extends JComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether this label's text should be rendered with anti-aliasing.
|
* @deprecated see {@link SwingUtil#getDefaultAntiAliasing} on how to control text
|
||||||
|
* antialiasing.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setAntiAliased (boolean antialiased)
|
public void setAntiAliased (boolean antialiased)
|
||||||
{
|
{
|
||||||
_antialiased = antialiased;
|
|
||||||
_dirty = true;
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,14 +243,7 @@ public class MultiLineLabel extends JComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draw the label
|
// draw the label
|
||||||
Object oalias = null;
|
|
||||||
if (_antialiased) {
|
|
||||||
oalias = SwingUtil.activateAntiAliasing(gfx);
|
|
||||||
}
|
|
||||||
_label.render(gfx, dx, dy);
|
_label.render(gfx, dx, dy);
|
||||||
if (_antialiased) {
|
|
||||||
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -323,9 +314,6 @@ public class MultiLineLabel extends JComponent
|
|||||||
Graphics2D gfx = (Graphics2D)getGraphics();
|
Graphics2D gfx = (Graphics2D)getGraphics();
|
||||||
if (gfx != null) {
|
if (gfx != null) {
|
||||||
// re-layout the label
|
// re-layout the label
|
||||||
gfx.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, (_antialiased) ?
|
|
||||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
|
|
||||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
|
||||||
_label.layout(gfx);
|
_label.layout(gfx);
|
||||||
gfx.dispose();
|
gfx.dispose();
|
||||||
|
|
||||||
@@ -385,9 +373,6 @@ public class MultiLineLabel extends JComponent
|
|||||||
/** 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;
|
protected int _constrainedSize;
|
||||||
|
|
||||||
/** Whether to render the label with anti-aliasing. */
|
|
||||||
protected boolean _antialiased = SwingUtil.getDefaultTextAntialiasing();
|
|
||||||
|
|
||||||
/** Whether this label is dirty and should be re-layed out. */
|
/** Whether this label is dirty and should be re-layed out. */
|
||||||
protected boolean _dirty = true;
|
protected boolean _dirty = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,11 +432,15 @@ public class SwingUtil
|
|||||||
/**
|
/**
|
||||||
* Restores anti-aliasing in the supplied graphics context to its original setting.
|
* Restores anti-aliasing in the supplied graphics context to its original setting.
|
||||||
*
|
*
|
||||||
* @param rock the results of a previous call to {@link #activateAntiAliasing}.
|
* @param rock the results of a previous call to {@link #activateAntiAliasing} or null, in
|
||||||
|
* which case this method will NOOP. This alleviates every caller having to conditionally avoid
|
||||||
|
* calling restore if they chose not to activate earlier.
|
||||||
*/
|
*/
|
||||||
public static void restoreAntiAliasing (Graphics2D gfx, Object rock)
|
public static void restoreAntiAliasing (Graphics2D gfx, Object rock)
|
||||||
{
|
{
|
||||||
gfx.setRenderingHints((RenderingHints)rock);
|
if (rock != null) {
|
||||||
|
gfx.setRenderingHints((RenderingHints)rock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user