提交 b819df42 编写于 作者: M mlapshin

6727829: BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM

Summary: Several private static variables made local
Reviewed-by: alexp
上级 bd5a8fca
...@@ -65,6 +65,9 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener ...@@ -65,6 +65,9 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
protected static BasicLabelUI labelUI = new BasicLabelUI(); protected static BasicLabelUI labelUI = new BasicLabelUI();
private final static BasicLabelUI SAFE_BASIC_LABEL_UI = new BasicLabelUI(); private final static BasicLabelUI SAFE_BASIC_LABEL_UI = new BasicLabelUI();
private Rectangle paintIconR = new Rectangle();
private Rectangle paintTextR = new Rectangle();
static void loadActionMap(LazyActionMap map) { static void loadActionMap(LazyActionMap map) {
map.put(new Actions(Actions.PRESS)); map.put(new Actions(Actions.PRESS));
map.put(new Actions(Actions.RELEASE)); map.put(new Actions(Actions.RELEASE));
...@@ -135,17 +138,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener ...@@ -135,17 +138,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
textX, textY); textX, textY);
} }
/* These rectangles/insets are allocated once for this shared LabelUI
* implementation. Re-using rectangles rather than allocating
* them in each paint call halved the time it took paint to run.
*/
private static Rectangle paintIconR = new Rectangle();
private static Rectangle paintTextR = new Rectangle();
private static Rectangle paintViewR = new Rectangle();
private static Insets paintViewInsets = new Insets(0, 0, 0, 0);
/** /**
* Paint the label text in the foreground color, if the label * Paint the label text in the foreground color, if the label
* is opaque then paint the entire background with the background * is opaque then paint the entire background with the background
...@@ -194,10 +186,11 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener ...@@ -194,10 +186,11 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
private String layout(JLabel label, FontMetrics fm, private String layout(JLabel label, FontMetrics fm,
int width, int height) { int width, int height) {
Insets insets = label.getInsets(paintViewInsets); Insets insets = label.getInsets(null);
String text = label.getText(); String text = label.getText();
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
label.getDisabledIcon(); label.getDisabledIcon();
Rectangle paintViewR = new Rectangle();
paintViewR.x = insets.left; paintViewR.x = insets.left;
paintViewR.y = insets.top; paintViewR.y = insets.top;
paintViewR.width = width - (insets.left + insets.right); paintViewR.width = width - (insets.left + insets.right);
...@@ -208,24 +201,13 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener ...@@ -208,24 +201,13 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
paintTextR); paintTextR);
} }
/* These rectangles/insets are allocated once for this shared LabelUI
* implementation. Re-using rectangles rather than allocating
* them in each getPreferredSize call sped up the method substantially.
*/
private static Rectangle iconR = new Rectangle();
private static Rectangle textR = new Rectangle();
private static Rectangle viewR = new Rectangle();
private static Insets viewInsets = new Insets(0, 0, 0, 0);
public Dimension getPreferredSize(JComponent c) public Dimension getPreferredSize(JComponent c)
{ {
JLabel label = (JLabel)c; JLabel label = (JLabel)c;
String text = label.getText(); String text = label.getText();
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
label.getDisabledIcon(); label.getDisabledIcon();
Insets insets = label.getInsets(viewInsets); Insets insets = label.getInsets(null);
Font font = label.getFont(); Font font = label.getFont();
int dx = insets.left + insets.right; int dx = insets.left + insets.right;
...@@ -242,6 +224,9 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener ...@@ -242,6 +224,9 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
} }
else { else {
FontMetrics fm = label.getFontMetrics(font); FontMetrics fm = label.getFontMetrics(font);
Rectangle iconR = new Rectangle();
Rectangle textR = new Rectangle();
Rectangle viewR = new Rectangle();
iconR.x = iconR.y = iconR.width = iconR.height = 0; iconR.x = iconR.y = iconR.width = iconR.height = 0;
textR.x = textR.y = textR.width = textR.height = 0; textR.x = textR.y = textR.width = textR.height = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册