summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTania Bento <tbento@redhat.com>2006-12-08 16:49:35 +0000
committerTania Bento <tbento@redhat.com>2006-12-08 16:49:35 +0000
commit24bb46e990e91b4cc22795c39990862c7a6aa3b6 (patch)
tree3e35242e290907afcfce9994ab1c271e0a81206c
parenta4ef9620e22209ba431ca8bb3aaf0e73b4742426 (diff)
downloadclasspath-24bb46e990e91b4cc22795c39990862c7a6aa3b6.tar.gz
2006-12-08 Tania Bento <tbento@redhat.com>
* java/awt/ScrollPane.java (getScrollPosition): Throw NullPointerException if scrollpane does have a child. (setScrollPosition(int, int)): Throw NullPointerException if scrollpane does have a child. Check that both ints are within the allowed bounds; If they are not, scroll to the closest allowed bound.
-rw-r--r--ChangeLog10
-rw-r--r--java/awt/ScrollPane.java24
2 files changed, 32 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index c132a3264..cd2768362 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-12-08 Tania Bento <tbento@redhat.com>
+
+ * java/awt/ScrollPane.java
+ (getScrollPosition): Throw NullPointerException if scrollpane
+ does have a child.
+ (setScrollPosition(int, int)): Throw NullPointerException if
+ scrollpane does have a child. Check that both ints are within
+ the allowed bounds; If they are not, scroll to the closest allowed
+ bound.
+
2006-12-07 Roman Kennke <kennke@aicas.com>
* javax/swing/JEditorPane.java
diff --git a/java/awt/ScrollPane.java b/java/awt/ScrollPane.java
index 35a81300d..100a17b6a 100644
--- a/java/awt/ScrollPane.java
+++ b/java/awt/ScrollPane.java
@@ -338,10 +338,15 @@ getVScrollbarWidth()
* Returns the current scroll position of the viewport.
*
* @return The current scroll position of the viewport.
+ *
+ * @throws NullPointerException if the scrollpane does have a child.
*/
public Point
getScrollPosition()
{
+ if (getComponentCount() == 0)
+ throw new NullPointerException();
+
int x = 0;
int y = 0;
@@ -380,20 +385,35 @@ setScrollPosition(Point scrollPosition) throws IllegalArgumentException
* @param x The new X coordinate of the scroll position.
* @param y The new Y coordinate of the scroll position.
*
+ * @throws NullPointerException if scrollpane does not have a child.
+ *
* @exception IllegalArgumentException If the specified value is outside
* the legal scrolling range.
*/
public void
setScrollPosition(int x, int y)
{
+ if (getComponentCount() == 0)
+ throw new NullPointerException("child is null");
+
+ if (x > (int) (getComponent(0).getWidth() - getViewportSize().getWidth()))
+ x = (int) (getComponent(0).getWidth() - getViewportSize().getWidth());
+ if (y > (int) (getComponent(0).getHeight() - getViewportSize().getHeight()))
+ y = (int) (getComponent(0).getHeight() - getViewportSize().getHeight());
+
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+
Adjustable h = getHAdjustable();
Adjustable v = getVAdjustable();
-
+
if (h != null)
h.setValue(x);
if (v != null)
v.setValue(y);
-
+
ScrollPanePeer spp = (ScrollPanePeer)getPeer();
if (spp != null)
spp.setScrollPosition(x, y);