[cp-patches] FYI: BasicScrollBarUI fixlet
The BasicScrollBarUI should scroll by -block or -unit (fetched from the Scrollable impl) when the direction is not positive, and +unit or +block otherwise. So far we expected the Scrollable impl to return a negative value for up-scrolling and a positive value for down scrolling. Which is wrong (== not what the JDK does). This means that scrolling is now probably broken for a couple of components (those which implement the Scrollable interface wrong). This needs fixing up. JTextComponent scrolling works now correctly. 2006-08-13 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicScrollBarUI.java (scrollByUnit): Scroll by -unit when direction is not positive and +unit otherwise. (scrollByBlock): Scroll by -unit when direction is not positive and +unit otherwise. /Roman Index: javax/swing/text/PlainView.java === RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v retrieving revision 1.46 diff -u -1 -2 -r1.46 PlainView.java --- javax/swing/text/PlainView.java 11 Aug 2006 12:06:59 - 1.46 +++ javax/swing/text/PlainView.java 13 Aug 2006 15:15:48 - @@ -271,37 +271,45 @@ selectedColor = textComponent.getSelectedTextColor(); unselectedColor = textComponent.getForeground(); disabledColor = textComponent.getDisabledTextColor(); selectionStart = textComponent.getSelectionStart(); selectionEnd = textComponent.getSelectionEnd(); Rectangle rect = s instanceof Rectangle ? (Rectangle) s : s.getBounds(); tabBase = rect.x; // FIXME: Text may be scrolled. Document document = textComponent.getDocument(); Element root = getElement(); -int y = rect.y + metrics.getAscent(); int height = metrics.getHeight(); // For layered highlighters we need to paint the layered highlights // before painting any text. LayeredHighlighter hl = null; Highlighter h = textComponent.getHighlighter(); if (h instanceof LayeredHighlighter) hl = (LayeredHighlighter) h; int count = root.getElementCount(); -for (int i = 0; i < count; i++) +// Determine first and last line inside the clip. +Rectangle clip = g.getClipBounds(); +//SwingUtilities.computeIntersection(rect.x, rect.y, rect.width, rect.height, +// clip); +int line0 = (clip.y - rect.y) / height; +line0 = Math.max(0, Math.min(line0, count - 1)); +int line1 = (clip.y + clip.height - rect.y) / height; +line1 = Math.max(0, Math.min(line1, count - 1)); +int y = rect.y + metrics.getAscent() + height * line0; +for (int i = line0; i <= line1; i++) { if (hl != null) { Element lineEl = root.getElement(i); // Exclude the trailing newline from beeing highlighted. if (i == count) hl.paintLayeredHighlights(g, lineEl.getStartOffset(), lineEl.getEndOffset(), s, textComponent, this); else hl.paintLayeredHighlights(g, lineEl.getStartOffset(), lineEl.getEndOffset() - 1, s,
[cp-patches] FYI: BasicScrollBarUI fixlet
This removes a repaint call in BasicScrollBarUI.PropertyChangeHandler. For all Swing hackers: As a general rule, do not put repaint and revalidate calls in event handlers. When a property change must trigger a repaint and/or revalidate, then this should happen in the corresponding setter method. This makes the code more clear and avoids ugly eventqueue loops. 2005-10-18 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicScrollBarUI.java (PropertyChangeHandler.propertyChange): Removed repaint call. /Roman Index: javax/swing/plaf/basic/BasicScrollBarUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java,v retrieving revision 1.26 diff -u -r1.26 BasicScrollBarUI.java --- javax/swing/plaf/basic/BasicScrollBarUI.java 12 Oct 2005 12:10:00 - 1.26 +++ javax/swing/plaf/basic/BasicScrollBarUI.java 18 Oct 2005 14:00:58 - @@ -149,31 +149,30 @@ { if (e.getPropertyName().equals("model")) { - ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener); - scrollbar.getModel().addChangeListener(modelListener); - getThumbBounds(); + ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener); + scrollbar.getModel().addChangeListener(modelListener); + getThumbBounds(); } else if (e.getPropertyName().equals("orientation")) { - incrButton.removeMouseListener(buttonListener); - decrButton.removeMouseListener(buttonListener); + incrButton.removeMouseListener(buttonListener); + decrButton.removeMouseListener(buttonListener); int orientation = scrollbar.getOrientation(); switch (orientation) -{ -case (JScrollBar.HORIZONTAL): - incrButton = createIncreaseButton(EAST); - decrButton = createDecreaseButton(WEST); - break; -default: - incrButton = createIncreaseButton(SOUTH); - decrButton = createDecreaseButton(NORTH); - break; -} - incrButton.addMouseListener(buttonListener); - decrButton.addMouseListener(buttonListener); - calculatePreferredSize(); + { + case (JScrollBar.HORIZONTAL): +incrButton = createIncreaseButton(EAST); + decrButton = createDecreaseButton(WEST); + break; + default: +incrButton = createIncreaseButton(SOUTH); + decrButton = createDecreaseButton(NORTH); + break; + } + incrButton.addMouseListener(buttonListener); + decrButton.addMouseListener(buttonListener); + calculatePreferredSize(); } - scrollbar.repaint(); } } ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] FYI: BasicScrollBarUI fixlet
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Roman, > For all Swing hackers: As a general rule, do not put repaint and > revalidate calls in event handlers. When a property change must trigger > a repaint and/or revalidate, then this should happen in the > corresponding setter method. This makes the code more clear and avoids > ugly eventqueue loops. Would you mind putting such findings in the Wiki[0]? Maybe you could open a new page and just put all hints and infos in it. I will come to clean it up later. That way I think we could preserve such useful information for future hackers in a better way. cu Robert [0] - developer.classpath.org/mediation -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFDVUxaG9cfwmwwEtoRAv0bAJ9/2Iy9ko8Tqs6AB3fK0iNwrZgMwwCbB1a4 1WPiNw80xwCIWfJrVJdQyzs= =gLhP -END PGP SIGNATURE- ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches