diff options
author | Roman Kennke <roman@kennke.org> | 2006-11-20 10:38:09 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-11-20 10:38:09 +0000 |
commit | 3a4839a94c71038660a7a2c5450b40a7e40e654f (patch) | |
tree | deed72642672cb3a2eb55531bc295cbc21b8fc98 /javax | |
parent | ec3880456fce8eee43bbb10fdc073326aae69f48 (diff) | |
download | classpath-3a4839a94c71038660a7a2c5450b40a7e40e654f.tar.gz |
2006-11-20 Roman Kennke <kennke@aicas.com>
* javax/swing/plaf/basic/BasicTextUI.java
(RootView.paint): Avoid allocation.
(cachedInsets): New field. Caches an Insets instance.
(getNextVisualPositionFrom): Read-lock the document to avoid
thread nastiness. Push allocation.
(getPreferredSize): Push fake allocation when not yet laid out.
(getVisibleEditorRect): Use cached insets.
(viewToModel): Read-lock the document to avoid
thread nastiness. Push allocation.
Diffstat (limited to 'javax')
-rw-r--r-- | javax/swing/plaf/basic/BasicTextUI.java | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java index dc30347f5..d4e43c60e 100644 --- a/javax/swing/plaf/basic/BasicTextUI.java +++ b/javax/swing/plaf/basic/BasicTextUI.java @@ -378,7 +378,7 @@ public abstract class BasicTextUI extends TextUI { if (view != null) { - Rectangle b = s.getBounds(); + Rectangle b = s instanceof Rectangle ? (Rectangle) s : s.getBounds(); view.setSize(b.width, b.height); view.paint(g, s); } @@ -997,6 +997,11 @@ public abstract class BasicTextUI extends TextUI rootView.setSize(d.width - i.left - i.right, d.height - i.top - i.bottom); } + else + { + // Not laid out yet. Force some pseudo size. + rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); + } w = rootView.getPreferredSpan(View.X_AXIS); h = rootView.getPreferredSpan(View.Y_AXIS); } @@ -1092,7 +1097,6 @@ public abstract class BasicTextUI extends TextUI AbstractDocument aDoc = (AbstractDocument) doc; aDoc.readLock(); } - paintSafely(g); } finally @@ -1273,12 +1277,26 @@ public abstract class BasicTextUI extends TextUI Position.Bias[] biasRet) throws BadLocationException { - // A comment in the spec of NavigationFilter.getNextVisualPositionFrom() - // suggests that this method should be implemented by forwarding the call - // the root view. - return rootView.getNextVisualPositionFrom(pos, b, - getVisibleEditorRect(), - direction, biasRet); + int offset = -1; + Document doc = textComponent.getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + Rectangle alloc = getVisibleEditorRect(); + if (alloc != null) + { + rootView.setSize(alloc.width, alloc.height); + offset = rootView.getNextVisualPositionFrom(pos, b, alloc, + direction, biasRet); + } + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + return offset; } /** @@ -1388,7 +1406,25 @@ public abstract class BasicTextUI extends TextUI */ public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn) { - return rootView.viewToModel(pt.x, pt.y, getVisibleEditorRect(), biasReturn); + int offset = -1; + Document doc = textComponent.getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + Rectangle alloc = getVisibleEditorRect(); + if (alloc != null) + { + rootView.setSize(alloc.width, alloc.height); + offset = rootView.viewToModel(pt.x, pt.y, alloc, biasReturn); + } + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + return offset; } /** @@ -1420,6 +1456,11 @@ public abstract class BasicTextUI extends TextUI } /** + * A cached Insets instance to be reused below. + */ + private Insets cachedInsets; + + /** * Returns the allocation to give the root view. * * @return the allocation to give the root view @@ -1437,7 +1478,7 @@ public abstract class BasicTextUI extends TextUI if (width <= 0 || height <= 0) return null; - Insets insets = textComponent.getInsets(); + Insets insets = textComponent.getInsets(cachedInsets); return new Rectangle(insets.left, insets.top, width - insets.left - insets.right, height - insets.top - insets.bottom); @@ -1488,4 +1529,5 @@ public abstract class BasicTextUI extends TextUI { // The default implementation does nothing. } + } |