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

Print this page




 144      * Called from Windows in response to WM_VSCROLL/WM_HSCROLL message
 145      */
 146     private void postScrollEvent(int orient, int type,
 147                                  int pos, boolean isAdjusting)
 148     {
 149         Runnable adjustor = new Adjustor(orient, type, pos, isAdjusting);
 150         WToolkit.executeOnEventHandlerThread(new ScrollEvent(target, adjustor));
 151     }
 152 
 153     /*
 154      * Event that executes on the Java dispatch thread to move the
 155      * scroll bar thumbs and paint the exposed area in one synchronous
 156      * operation.
 157      */
 158     class ScrollEvent extends PeerEvent {
 159         ScrollEvent(Object source, Runnable runnable) {
 160             super(source, runnable, 0L);
 161         }
 162 
 163         public PeerEvent coalesceEvents(PeerEvent newEvent) {
 164             if (log.isLoggable(PlatformLogger.FINEST)) {
 165                 log.finest("ScrollEvent coalesced: " + newEvent);
 166             }
 167             if (newEvent instanceof ScrollEvent) {
 168                 return newEvent;
 169             }
 170             return null;
 171         }
 172     }
 173 
 174     /*
 175      * Runnable for the ScrollEvent that performs the adjustment.
 176      */
 177     class Adjustor implements Runnable {
 178         int orient;             // selects scrollbar
 179         int type;               // adjustment type
 180         int pos;                // new position (only used for absolute)
 181         boolean isAdjusting;    // isAdjusting status
 182 
 183         Adjustor(int orient, int type, int pos, boolean isAdjusting) {
 184             this.orient = orient;


 187             this.isAdjusting = isAdjusting;
 188         }
 189 
 190         public void run() {
 191             if (getScrollChild() == null) {
 192                 return;
 193             }
 194             ScrollPane sp = (ScrollPane)WScrollPanePeer.this.target;
 195             ScrollPaneAdjustable adj = null;
 196 
 197             // ScrollPaneAdjustable made public in 1.4, but
 198             // get[HV]Adjustable can't be declared to return
 199             // ScrollPaneAdjustable because it would break backward
 200             // compatibility -- hence the cast
 201 
 202             if (orient == Adjustable.VERTICAL) {
 203                 adj = (ScrollPaneAdjustable)sp.getVAdjustable();
 204             } else if (orient == Adjustable.HORIZONTAL) {
 205                 adj = (ScrollPaneAdjustable)sp.getHAdjustable();
 206             } else {
 207                 if (log.isLoggable(PlatformLogger.FINE)) {
 208                     log.fine("Assertion failed: unknown orient");
 209                 }
 210             }
 211 
 212             if (adj == null) {
 213                 return;
 214             }
 215 
 216             int newpos = adj.getValue();
 217             switch (type) {
 218               case AdjustmentEvent.UNIT_DECREMENT:
 219                   newpos -= adj.getUnitIncrement();
 220                   break;
 221               case AdjustmentEvent.UNIT_INCREMENT:
 222                   newpos += adj.getUnitIncrement();
 223                   break;
 224               case AdjustmentEvent.BLOCK_DECREMENT:
 225                   newpos -= adj.getBlockIncrement();
 226                   break;
 227               case AdjustmentEvent.BLOCK_INCREMENT:
 228                   newpos += adj.getBlockIncrement();
 229                   break;
 230               case AdjustmentEvent.TRACK:
 231                   newpos = this.pos;
 232                   break;
 233               default:
 234                   if (log.isLoggable(PlatformLogger.FINE)) {
 235                       log.fine("Assertion failed: unknown type");
 236                   }
 237                   return;
 238             }
 239 
 240             // keep scroll position in acceptable range
 241             newpos = Math.max(adj.getMinimum(), newpos);
 242             newpos = Math.min(adj.getMaximum(), newpos);
 243 
 244             // set value, this will synchronously fire an AdjustmentEvent
 245             adj.setValueIsAdjusting(isAdjusting);
 246 
 247             // Fix for 4075484 - consider type information when creating AdjustmentEvent
 248             // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
 249             // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
 250             AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj,
 251                                                                         newpos,
 252                                                                         type);
 253 
 254             // Paint the exposed area right away.  To do this - find
 255             // the heavyweight ancestor of the scroll child.
 256             Component hwAncestor = getScrollChild();
 257             while (hwAncestor != null
 258                    && !(hwAncestor.getPeer() instanceof WComponentPeer))
 259             {
 260                 hwAncestor = hwAncestor.getParent();
 261             }
 262             if (log.isLoggable(PlatformLogger.FINE)) {
 263                 if (hwAncestor == null) {
 264                     log.fine("Assertion (hwAncestor != null) failed, " +
 265                              "couldn't find heavyweight ancestor of scroll pane child");
 266                 }
 267             }
 268             WComponentPeer hwPeer = (WComponentPeer)hwAncestor.getPeer();
 269             hwPeer.paintDamagedAreaImmediately();
 270         }
 271     }
 272 
 273 }


 144      * Called from Windows in response to WM_VSCROLL/WM_HSCROLL message
 145      */
 146     private void postScrollEvent(int orient, int type,
 147                                  int pos, boolean isAdjusting)
 148     {
 149         Runnable adjustor = new Adjustor(orient, type, pos, isAdjusting);
 150         WToolkit.executeOnEventHandlerThread(new ScrollEvent(target, adjustor));
 151     }
 152 
 153     /*
 154      * Event that executes on the Java dispatch thread to move the
 155      * scroll bar thumbs and paint the exposed area in one synchronous
 156      * operation.
 157      */
 158     class ScrollEvent extends PeerEvent {
 159         ScrollEvent(Object source, Runnable runnable) {
 160             super(source, runnable, 0L);
 161         }
 162 
 163         public PeerEvent coalesceEvents(PeerEvent newEvent) {
 164             if (log.isLoggable(PlatformLogger.Level.FINEST)) {
 165                 log.finest("ScrollEvent coalesced: " + newEvent);
 166             }
 167             if (newEvent instanceof ScrollEvent) {
 168                 return newEvent;
 169             }
 170             return null;
 171         }
 172     }
 173 
 174     /*
 175      * Runnable for the ScrollEvent that performs the adjustment.
 176      */
 177     class Adjustor implements Runnable {
 178         int orient;             // selects scrollbar
 179         int type;               // adjustment type
 180         int pos;                // new position (only used for absolute)
 181         boolean isAdjusting;    // isAdjusting status
 182 
 183         Adjustor(int orient, int type, int pos, boolean isAdjusting) {
 184             this.orient = orient;


 187             this.isAdjusting = isAdjusting;
 188         }
 189 
 190         public void run() {
 191             if (getScrollChild() == null) {
 192                 return;
 193             }
 194             ScrollPane sp = (ScrollPane)WScrollPanePeer.this.target;
 195             ScrollPaneAdjustable adj = null;
 196 
 197             // ScrollPaneAdjustable made public in 1.4, but
 198             // get[HV]Adjustable can't be declared to return
 199             // ScrollPaneAdjustable because it would break backward
 200             // compatibility -- hence the cast
 201 
 202             if (orient == Adjustable.VERTICAL) {
 203                 adj = (ScrollPaneAdjustable)sp.getVAdjustable();
 204             } else if (orient == Adjustable.HORIZONTAL) {
 205                 adj = (ScrollPaneAdjustable)sp.getHAdjustable();
 206             } else {
 207                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 208                     log.fine("Assertion failed: unknown orient");
 209                 }
 210             }
 211 
 212             if (adj == null) {
 213                 return;
 214             }
 215 
 216             int newpos = adj.getValue();
 217             switch (type) {
 218               case AdjustmentEvent.UNIT_DECREMENT:
 219                   newpos -= adj.getUnitIncrement();
 220                   break;
 221               case AdjustmentEvent.UNIT_INCREMENT:
 222                   newpos += adj.getUnitIncrement();
 223                   break;
 224               case AdjustmentEvent.BLOCK_DECREMENT:
 225                   newpos -= adj.getBlockIncrement();
 226                   break;
 227               case AdjustmentEvent.BLOCK_INCREMENT:
 228                   newpos += adj.getBlockIncrement();
 229                   break;
 230               case AdjustmentEvent.TRACK:
 231                   newpos = this.pos;
 232                   break;
 233               default:
 234                   if (log.isLoggable(PlatformLogger.Level.FINE)) {
 235                       log.fine("Assertion failed: unknown type");
 236                   }
 237                   return;
 238             }
 239 
 240             // keep scroll position in acceptable range
 241             newpos = Math.max(adj.getMinimum(), newpos);
 242             newpos = Math.min(adj.getMaximum(), newpos);
 243 
 244             // set value, this will synchronously fire an AdjustmentEvent
 245             adj.setValueIsAdjusting(isAdjusting);
 246 
 247             // Fix for 4075484 - consider type information when creating AdjustmentEvent
 248             // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
 249             // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
 250             AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj,
 251                                                                         newpos,
 252                                                                         type);
 253 
 254             // Paint the exposed area right away.  To do this - find
 255             // the heavyweight ancestor of the scroll child.
 256             Component hwAncestor = getScrollChild();
 257             while (hwAncestor != null
 258                    && !(hwAncestor.getPeer() instanceof WComponentPeer))
 259             {
 260                 hwAncestor = hwAncestor.getParent();
 261             }
 262             if (log.isLoggable(PlatformLogger.Level.FINE)) {
 263                 if (hwAncestor == null) {
 264                     log.fine("Assertion (hwAncestor != null) failed, " +
 265                              "couldn't find heavyweight ancestor of scroll pane child");
 266                 }
 267             }
 268             WComponentPeer hwPeer = (WComponentPeer)hwAncestor.getPeer();
 269             hwPeer.paintDamagedAreaImmediately();
 270         }
 271     }
 272 
 273 }