src/java.desktop/windows/classes/sun/awt/windows/WScrollPanePeer.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.awt.windows;
  26 
  27 import java.awt.*;
  28 import java.awt.event.AdjustmentEvent;
  29 import java.awt.peer.ScrollPanePeer;
  30 
  31 import sun.awt.AWTAccessor;

  32 import sun.awt.PeerEvent;
  33 
  34 import sun.util.logging.PlatformLogger;
  35 
  36 final class WScrollPanePeer extends WPanelPeer implements ScrollPanePeer {
  37 
  38     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WScrollPanePeer");
  39 
  40     int scrollbarWidth;
  41     int scrollbarHeight;
  42     int prevx;
  43     int prevy;
  44 
  45     static {
  46         initIDs();
  47     }
  48 
  49     static native void initIDs();
  50     @Override
  51     native void create(WComponentPeer parent);


 182         }
 183     }
 184 
 185     /*
 186      * Runnable for the ScrollEvent that performs the adjustment.
 187      */
 188     class Adjustor implements Runnable {
 189         int orient;             // selects scrollbar
 190         int type;               // adjustment type
 191         int pos;                // new position (only used for absolute)
 192         boolean isAdjusting;    // isAdjusting status
 193 
 194         Adjustor(int orient, int type, int pos, boolean isAdjusting) {
 195             this.orient = orient;
 196             this.type = type;
 197             this.pos = pos;
 198             this.isAdjusting = isAdjusting;
 199         }
 200 
 201         @Override
 202         @SuppressWarnings("deprecation")
 203         public void run() {
 204             if (getScrollChild() == null) {
 205                 return;
 206             }
 207             ScrollPane sp = (ScrollPane)WScrollPanePeer.this.target;
 208             ScrollPaneAdjustable adj = null;
 209 
 210             // ScrollPaneAdjustable made public in 1.4, but
 211             // get[HV]Adjustable can't be declared to return
 212             // ScrollPaneAdjustable because it would break backward
 213             // compatibility -- hence the cast
 214 
 215             if (orient == Adjustable.VERTICAL) {
 216                 adj = (ScrollPaneAdjustable)sp.getVAdjustable();
 217             } else if (orient == Adjustable.HORIZONTAL) {
 218                 adj = (ScrollPaneAdjustable)sp.getHAdjustable();
 219             } else {
 220                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 221                     log.fine("Assertion failed: unknown orient");
 222                 }


 250                   return;
 251             }
 252 
 253             // keep scroll position in acceptable range
 254             newpos = Math.max(adj.getMinimum(), newpos);
 255             newpos = Math.min(adj.getMaximum(), newpos);
 256 
 257             // set value, this will synchronously fire an AdjustmentEvent
 258             adj.setValueIsAdjusting(isAdjusting);
 259 
 260             // Fix for 4075484 - consider type information when creating AdjustmentEvent
 261             // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
 262             // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
 263             AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj,
 264                                                                         newpos,
 265                                                                         type);
 266 
 267             // Paint the exposed area right away.  To do this - find
 268             // the heavyweight ancestor of the scroll child.
 269             Component hwAncestor = getScrollChild();

 270             while (hwAncestor != null
 271                    && !(hwAncestor.getPeer() instanceof WComponentPeer))
 272             {
 273                 hwAncestor = hwAncestor.getParent();
 274             }
 275             if (log.isLoggable(PlatformLogger.Level.FINE)) {
 276                 if (hwAncestor == null) {
 277                     log.fine("Assertion (hwAncestor != null) failed, " +
 278                              "couldn't find heavyweight ancestor of scroll pane child");
 279                 }
 280             }
 281             WComponentPeer hwPeer = (WComponentPeer)hwAncestor.getPeer();
 282             hwPeer.paintDamagedAreaImmediately();
 283         }
 284     }
 285 
 286 }
   1 /*
   2  * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.awt.windows;
  26 
  27 import java.awt.*;
  28 import java.awt.event.AdjustmentEvent;
  29 import java.awt.peer.ScrollPanePeer;
  30 
  31 import sun.awt.AWTAccessor;
  32 import sun.awt.AWTAccessor.ComponentAccessor;
  33 import sun.awt.PeerEvent;
  34 
  35 import sun.util.logging.PlatformLogger;
  36 
  37 final class WScrollPanePeer extends WPanelPeer implements ScrollPanePeer {
  38 
  39     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WScrollPanePeer");
  40 
  41     int scrollbarWidth;
  42     int scrollbarHeight;
  43     int prevx;
  44     int prevy;
  45 
  46     static {
  47         initIDs();
  48     }
  49 
  50     static native void initIDs();
  51     @Override
  52     native void create(WComponentPeer parent);


 183         }
 184     }
 185 
 186     /*
 187      * Runnable for the ScrollEvent that performs the adjustment.
 188      */
 189     class Adjustor implements Runnable {
 190         int orient;             // selects scrollbar
 191         int type;               // adjustment type
 192         int pos;                // new position (only used for absolute)
 193         boolean isAdjusting;    // isAdjusting status
 194 
 195         Adjustor(int orient, int type, int pos, boolean isAdjusting) {
 196             this.orient = orient;
 197             this.type = type;
 198             this.pos = pos;
 199             this.isAdjusting = isAdjusting;
 200         }
 201 
 202         @Override

 203         public void run() {
 204             if (getScrollChild() == null) {
 205                 return;
 206             }
 207             ScrollPane sp = (ScrollPane)WScrollPanePeer.this.target;
 208             ScrollPaneAdjustable adj = null;
 209 
 210             // ScrollPaneAdjustable made public in 1.4, but
 211             // get[HV]Adjustable can't be declared to return
 212             // ScrollPaneAdjustable because it would break backward
 213             // compatibility -- hence the cast
 214 
 215             if (orient == Adjustable.VERTICAL) {
 216                 adj = (ScrollPaneAdjustable)sp.getVAdjustable();
 217             } else if (orient == Adjustable.HORIZONTAL) {
 218                 adj = (ScrollPaneAdjustable)sp.getHAdjustable();
 219             } else {
 220                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 221                     log.fine("Assertion failed: unknown orient");
 222                 }


 250                   return;
 251             }
 252 
 253             // keep scroll position in acceptable range
 254             newpos = Math.max(adj.getMinimum(), newpos);
 255             newpos = Math.min(adj.getMaximum(), newpos);
 256 
 257             // set value, this will synchronously fire an AdjustmentEvent
 258             adj.setValueIsAdjusting(isAdjusting);
 259 
 260             // Fix for 4075484 - consider type information when creating AdjustmentEvent
 261             // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
 262             // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
 263             AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj,
 264                                                                         newpos,
 265                                                                         type);
 266 
 267             // Paint the exposed area right away.  To do this - find
 268             // the heavyweight ancestor of the scroll child.
 269             Component hwAncestor = getScrollChild();
 270             final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
 271             while (hwAncestor != null
 272                    && !(acc.getPeer(hwAncestor) instanceof WComponentPeer))
 273             {
 274                 hwAncestor = hwAncestor.getParent();
 275             }
 276             if (log.isLoggable(PlatformLogger.Level.FINE)) {
 277                 if (hwAncestor == null) {
 278                     log.fine("Assertion (hwAncestor != null) failed, " +
 279                              "couldn't find heavyweight ancestor of scroll pane child");
 280                 }
 281             }
 282             WComponentPeer hwPeer = acc.getPeer(hwAncestor);
 283             hwPeer.paintDamagedAreaImmediately();
 284         }
 285     }
 286 
 287 }