This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: ScrollPane fix
- To: Java Patch List <java-patches at sourceware dot cygnus dot com>
- Subject: Patch: ScrollPane fix
- From: Tom Tromey <tromey at redhat dot com>
- Date: 03 Jan 2001 13:53:36 -0700
- Reply-To: tromey at redhat dot com
This is what I came up with to finish ScrollPane.
2001-01-03 Tom Tromey <tromey@redhat.com>
* java/awt/ScrollPane.java (setBlockIncrement): Throw error.
(getViewportSize): Insets include scrollbar size.
(doLayout): Finished.
(getScrollPosition): Wrote.
* java/awt/peer/ScrollPanePeer.java (setBlockIncrement): Removed.
Tom
Index: java/awt/ScrollPane.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/ScrollPane.java,v
retrieving revision 1.2
diff -u -r1.2 ScrollPane.java
--- ScrollPane.java 2001/01/03 00:07:13 1.2
+++ ScrollPane.java 2001/01/03 20:33:19
@@ -15,9 +15,6 @@
* scrollbars as well as a single child which is scrolled by them.
* @author Tom Tromey <tromey@redhat.com>
* @date December 31, 2000
- * Status: Unfinished. The Adjustables are probably wrong (there
- * isn't a mechanism for scrollbar events to affect them), and also
- * doLayout() is not finished.
*/
public class ScrollPane extends Container
{
@@ -90,7 +87,8 @@
Dimension c = component[0].getPreferredSize ();
component[0].setSize (c.width, c.height);
spp.childResized (c.width, c.height);
- // FIXME
+ // Update the scrollbar position to the closest valid value.
+ setScrollPosition (hscroll.getValue (), vscroll.getValue ());
}
/** Returns an Adjustable representing the horizontal scrollbar.
@@ -121,8 +119,7 @@
/** Returns the viewport's scroll position. */
public Point getScrollPosition ()
{
- // FIXME
- return null;
+ return new Point (hscroll.getValue (), vscroll.getValue ());
}
/** Returns an Adjustable representing the vertical scrollbar.
@@ -138,6 +135,9 @@
/** Returns the size of the viewport. */
public Dimension getViewportSize ()
{
+ // Note: according to the online docs, the Insets are
+ // automatically updated by the peer to include the scrollbar
+ // sizes.
Insets ins = getInsets ();
int myw = width - ins.left - ins.right;
int myh = height - ins.top - ins.bottom;
@@ -148,14 +148,6 @@
else
cs = new Dimension (myw, myh);
- if (policy == SCROLLBARS_ALWAYS
- || (policy == SCROLLBARS_AS_NEEDED && myw < cs.width))
- myw -= getVScrollbarWidth ();
-
- if (policy == SCROLLBARS_ALWAYS
- || (policy == SCROLLBARS_AS_NEEDED && myh < cs.height))
- myh -= getHScrollbarHeight ();
-
// A little optimization -- reuse the Dimension.
cs.setSize (myw, myh);
return cs;
@@ -228,6 +220,12 @@
setScrollPosition (p.x, p.y);
}
+ // This implements the Adjustable for each scrollbar. The
+ // expectation is that the peer will look at these objects directly
+ // and modify the values in them when the user manipulates the
+ // scrollbars. This has to be done from CNI to bypass Java
+ // protection rules. The peer should also take care of calling the
+ // adjustment listeners.
class ScrollPaneAdjustable implements Adjustable
{
AdjustmentListener listeners;
@@ -295,12 +293,7 @@
public void setBlockIncrement (int b)
{
- block = b;
- if (peer != null)
- {
- ScrollPanePeer spp = (ScrollPanePeer) peer;
- spp.setBlockIncrement (this, b);
- }
+ throw new AWTError ("can't use setBlockIncrement on this Adjustable");
}
public void setMaximum (int max)
Index: java/awt/peer/ScrollPanePeer.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/peer/ScrollPanePeer.java,v
retrieving revision 1.2
diff -u -r1.2 ScrollPanePeer.java
--- ScrollPanePeer.java 2001/01/03 00:07:13 1.2
+++ ScrollPanePeer.java 2001/01/03 20:33:19
@@ -17,6 +17,5 @@
int getVScrollbarWidth();
void setScrollPosition(int x, int y);
void setUnitIncrement(Adjustable adj, int increment);
- void setBlockIncrement(Adjustable adj, int increment);
void setValue(Adjustable adj, int value);
}