[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: corrected javax.swing.text.PlainView
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: corrected javax.swing.text.PlainView |
Date: |
Fri, 06 May 2005 12:32:57 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
I have corrected the calculation of the preferredSpan property in
javax.swing.text.PlainView.
2005-05-06 Roman Kennke <address@hidden>
* javax/swing/text/PlainView.java
(getPreferredSpan): Corrected the calculation of the span of
the view.
/Roman
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.6
diff -u -r1.6 PlainView.java
--- javax/swing/text/PlainView.java 4 May 2005 15:11:31 -0000 1.6
+++ javax/swing/text/PlainView.java 6 May 2005 10:30:35 -0000
@@ -200,7 +200,42 @@
if (axis != X_AXIS && axis != Y_AXIS)
throw new IllegalArgumentException();
- return 10;
+ // make sure we have the metrics
+ updateMetrics();
+
+ float span = 0;
+ Element el = getElement();
+ Document doc = el.getDocument();
+ Segment seg = new Segment();
+
+ switch (axis)
+ {
+ case X_AXIS:
+ // calculate the maximum of the line's widths
+ for (int i = 0; i < el.getElementCount(); i++)
+ {
+ Element child = el.getElement(i);
+ int start = child.getStartOffset();
+ int end = child.getEndOffset();
+ try {
+ doc.getText(start, start + end, seg);
+ }
+ catch (BadLocationException ex)
+ {
+ // throw new ClasspathAssertionError
+ // ("no BadLocationException should be thrown here");
+ }
+ int width = metrics.charsWidth(seg.array, seg.offset, seg.count);
+ span = Math.max(span, width);
+ }
+ break;
+ case Y_AXIS:
+ default:
+ span = metrics.getHeight() * el.getElementCount();
+ break;
+ }
+
+ return span;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: corrected javax.swing.text.PlainView,
Roman Kennke <=