src/macosx/classes/sun/lwawt/LWScrollPanePeer.java

Print this page

        

@@ -27,10 +27,11 @@
 
 import javax.swing.*;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.ChangeEvent;
 import java.awt.*;
+import java.awt.event.MouseWheelEvent;
 import java.awt.peer.ScrollPanePeer;
 import java.util.List;
 
 final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
         implements ScrollPanePeer, ChangeListener {

@@ -108,24 +109,71 @@
             }
         }
     }
 
     @Override
+    public void handleEvent(AWTEvent e) {
+        if (e instanceof MouseWheelEvent
+                && !getTarget().isWheelScrollingEnabled()) {
+            return;
+        }
+        super.handleEvent(e);
+    }
+
+    @Override
+    public boolean handlesWheelScrolling() {
+        return isVerticalBarVisible() || isHorizontalBarVisible();
+    }
+
+    
+    private boolean isVerticalBarVisible() {
+        synchronized (getDelegateLock()) {
+            JScrollBar verticalScrollBar = getDelegate().getVerticalScrollBar();
+            return verticalScrollBar != null && verticalScrollBar.isVisible();
+        }
+    }
+
+    private boolean isHorizontalBarVisible() {
+        synchronized (getDelegateLock()) {
+            JScrollBar horizontalScrollBar = getDelegate().getHorizontalScrollBar();
+            return horizontalScrollBar != null && horizontalScrollBar.isVisible();
+        }
+    }
+    
+    @Override
+    public Insets getInsets() {
+        if (getViewPeer() != null) {
+            synchronized (getDelegateLock()) {
+                int right = isVerticalBarVisible() ? getVScrollbarWidth() : 0;
+                int bottom = isHorizontalBarVisible() ? getHScrollbarHeight() : 0;
+                return new Insets(0, 0, bottom, right);
+            }
+        }
+        return new Insets(0, 0, 0, 0);
+    }
+
+
+    @Override
     public void setScrollPosition(int x, int y) {
+        synchronized (getDelegateLock()) {
+            getDelegate().getViewport().setViewPosition(new Point(x, y));
+        }
     }
 
     @Override
     public int getHScrollbarHeight() {
         synchronized (getDelegateLock()) {
-            return getDelegate().getHorizontalScrollBar().getHeight();
+            JScrollBar horizontalScrollBar = getDelegate().getHorizontalScrollBar();
+            return horizontalScrollBar != null ? horizontalScrollBar.getHeight() : 0;
         }
     }
 
     @Override
     public int getVScrollbarWidth() {
         synchronized (getDelegateLock()) {
-            return getDelegate().getVerticalScrollBar().getWidth();
+            JScrollBar verticalScrollBar = getDelegate().getVerticalScrollBar();
+            return verticalScrollBar != null ? verticalScrollBar.getWidth() : 0;
         }
     }
 
     @Override
     public void childResized(int w, int h) {

@@ -139,10 +187,23 @@
     public void setUnitIncrement(Adjustable adj, int u) {
     }
 
     @Override
     public void setValue(Adjustable adj, int v) {
+        LWComponentPeer c = getViewPeer();
+        if (c == null) {
+            return;
+        }
+        Point p = c.getTarget().getLocation();
+        switch (adj.getOrientation()) {
+            case Adjustable.VERTICAL:
+                setScrollPosition(-(p.x), v);
+                break;
+            case Adjustable.HORIZONTAL:
+                setScrollPosition(v, (-p.y));
+                break;
+        }
     }
 
     private static int convertHPolicy(final int policy) {
         switch (policy) {
             case ScrollPane.SCROLLBARS_NEVER: