[cp-patches] FYI: Swing text fixes
This solves some problems in javax.swing.text: - Sometimes the layout got borked and was very slow. This was caused by a thinko in FlowView.FlowStrategy. - Line breaking was not working really well. This is improved now. BeanShell and jIRCii should now work again as expected. 2006-11-02 Roman Kennke <[EMAIL PROTECTED]> PR 29644 * javax/swing/text/FlowView.java (FlowStrategy.changedUpdate): Reversed condition. This caused wrong layout and bad performance. (FlowStrategy.insertUpdate): Reversed condition. This caused wrong layout and bad performance. (FlowStrategy.removeUpdate): Reversed condition. This caused wrong layout and bad performance. (LogicalView): Changed to be a subclass of CompositeView. (LogicalView()): Only take one Element argument. (LogicalView.childAllocation): New method for implementing the abstract CompositeView method. (LogicalView.forwardUpdateToView): Overridden for correct reparenting. (getMinimumSpan): Overridden to handle line breaking correctly. (getPreferredSpan): Implemented to handle line breaking correctly. (getViewAtPoint): New method for implementing the abstract CompositeView method. (getViewIndexAtPosition): Overridden to handle leaf elements correctly. (isAfter): New method for implementing the abstract CompositeView method. (isBefore): New method for implementing the abstract CompositeView method. (loadChildren): Overridden to handle leaf elements correctly. (paint): New method for implementing the abstract CompositeView method. (calculateMinorAxisRequirements): Use preferredSpan in calculation. (loadChildren): Initialize flow layout by sending a synthetic insertUpdate() to the layout strategy. * javax/swing/text/GlyphView.java (DefaultGlyphPainter.getBoundedPosition): Fall back to Toolkit's font metrics if component is not available. Add initial offset to result. (breakView): Be more clever when breaking the view. (getBreakLocation): New helper method to determine a good break location. (getBreakWeight): Be more clever when breaking the view. (getTabbedSpan): Make sure we have a painter. Use view's start and end offset rather than the element's. * javax/swing/text/Utilities.java (drawTabbedText): Avoid useless add and sub with the y offset. /Roman Index: javax/swing/text/FlowView.java === RCS file: /cvsroot/classpath/classpath/javax/swing/text/FlowView.java,v retrieving revision 1.17 diff -u -1 -5 -r1.17 FlowView.java --- javax/swing/text/FlowView.java 12 Oct 2006 15:12:56 - 1.17 +++ javax/swing/text/FlowView.java 2 Nov 2006 11:19:28 - @@ -27,30 +27,31 @@ permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package javax.swing.text; import java.awt.Component; +import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; import javax.swing.SizeRequirements; import javax.swing.event.DocumentEvent; /** * A View that can flows it's children into it's layout space. * * The FlowView manages a set of logical views (that are * the children of the [EMAIL PROTECTED] #layoutPool} field). These are translated * at layout time into a set of physical views. These are the views that * are managed as the real child views. Each of these child views represents * a row and are laid out within a box using the superclasses behaviour. * The concrete implementation of the rows must be provided by subclasses. @@ -74,92 +75,92 @@ } /** * Receives notification from a FlowView that some content * has been inserted into the document at a location that the * FlowView is responsible for. * * The default implementation simply calls [EMAIL PROTECTED] #layout}. * * @param fv the flow view that sends the notification * @param e the document event describing the change * @param alloc the current allocation of the flow view */ public void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) { - if (alloc != null) + if (alloc == null) { fv
[cp-patches] FYI: Swing text fixes
This fixes a couple of issues in the Swing text code for better stability. Also this removes the scrollRectToVisible() that causes the view to scroll around when activating a link. 2006-12-06 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/JEditorPane.java (getStream): Buffer the stream for efficiency. (setPage): Don't scroll the view at this point. * javax/swing/plaf/basic/BasicTextUI.java (RootView.paint): Call RootView's setSize to get synchronization. (RootView.setSize): Synchronize to prevent race in layout code. * javax/swing/text/AbstractDocument.java (notifyListeners): New field. (fireChangedUpdate): Track notifyListener field. (fireRemoveUpdate): Track notifyListener field. (fireIndertUpdate): Track notifyListener field. (writeLock): Check notifyListener and throw IllegalStateException. * javax/swing/text/View.java (preferenceChanged): Create local var for better thread safety and more efficiency. /Roman Index: javax/swing/JEditorPane.java === RCS file: /cvsroot/classpath/classpath/javax/swing/JEditorPane.java,v retrieving revision 1.41 diff -u -1 -5 -r1.41 JEditorPane.java --- javax/swing/JEditorPane.java 3 Dec 2006 16:41:55 - 1.41 +++ javax/swing/JEditorPane.java 6 Dec 2006 20:18:15 - @@ -28,31 +28,31 @@ executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package javax.swing; import java.awt.Container; import java.awt.Dimension; -import java.awt.Rectangle; +import java.io.BufferedInputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.HashMap; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleHyperlink; import javax.accessibility.AccessibleHypertext; import javax.accessibility.AccessibleStateSet; @@ -886,31 +886,31 @@ public URL getPage() { return loader != null ? loader.page : null; } protected InputStream getStream(URL page) throws IOException { URLConnection conn = page.openConnection(); // Try to detect the content type of the stream data. String type = conn.getContentType(); if (type != null) setContentType(type); InputStream stream = conn.getInputStream(); -return stream; +return new BufferedInputStream(stream); } public String getText() { return super.getText(); } public String getUIClassID() { return "EditorPaneUI"; } public boolean isFocusCycleRoot() { return focus_root; @@ -1049,34 +1049,30 @@ */ public void setPage(String url) throws IOException { setPage(new URL(url)); } /** * Sets the current URL being displayed. */ public void setPage(URL page) throws IOException { if (page == null) throw new IOException("invalid url"); URL old = getPage(); -// Reset scrollbar when URL actually changes. -if (! page.equals(old) && page.getRef() == null) - scrollRectToVisible(new Rectangle(0, 0, 1, 1)); - // Only reload if the URL doesn't point to the same file. // This is not the same as equals because there might be different // URLs on the same file with different anchors. if (old == null || ! old.sameFile(page)) { InputStream in = getStream(page); if (editorKit != null) { Document doc = editorKit.createDefaultDocument(); doc.putProperty(Document.StreamDescriptionProperty, page); if (loader != null) loader.cancel(); loader = new PageLoader(doc, in, old, page); Index: javax/swing/plaf/basic/BasicTextUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v retrieving revision 1.96 diff -u -1 -5 -r1.96 BasicTextUI.java --- javax/swing/plaf/basic/BasicTextUI.java 20 Nov 2006 10:38:09 - 1.96 +++ javax/swing/plaf/basic/BasicTextUI.java 6 Dec 2006 20:18:16 - @@ -350,48 +350,53 @@ count = 1; return count; } /** * Returns the Container that contains th