< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java

Print this page




 248                 c = text.charAt(index);
 249                 eventNotifier.notifyKeyEvent(KeyEvent.KEY_TYPED,
 250                         System.currentTimeMillis(),
 251                         0, KeyEvent.VK_UNDEFINED, c,
 252                         KeyEvent.KEY_LOCATION_UNKNOWN);
 253                 index++;
 254             }
 255             eventNotifier.notifyKeyEvent(KeyEvent.KEY_RELEASED,
 256                     System.currentTimeMillis(),
 257                     0, lastKeyPressCode, c,
 258                     KeyEvent.KEY_LOCATION_UNKNOWN);
 259         }
 260     }
 261 
 262     void handleWindowFocusEvent(boolean gained, LWWindowPeer opposite) {
 263         eventNotifier.notifyActivation(gained, opposite);
 264     }
 265 
 266     static class DeltaAccumulator {
 267 
 268         static final double MIN_THRESHOLD = 0.1;
 269         static final double MAX_THRESHOLD = 0.5;
 270         double accumulatedDelta;

 271 
 272         int getRoundedDelta(double delta, int scrollPhase) {
 273 
 274             int roundDelta = (int) Math.round(delta);
 275 
 276             if (scrollPhase == NSEvent.SCROLL_PHASE_UNSUPPORTED) { // mouse wheel
 277                 if (roundDelta == 0 && delta != 0) {
 278                     roundDelta = delta > 0 ? 1 : -1;
 279                 }
 280             } else { // trackpad
 281                 boolean begin = scrollPhase == NSEvent.SCROLL_PHASE_BEGAN;
 282                 boolean end = scrollPhase == NSEvent.SCROLL_MASK_PHASE_ENDED
 283                         || scrollPhase == NSEvent.SCROLL_MASK_PHASE_CANCELLED;
 284 
 285                 if (begin) {
 286                     accumulatedDelta = 0;




 287                 }

 288 
 289                 accumulatedDelta += delta;
 290 
 291                 double absAccumulatedDelta = Math.abs(accumulatedDelta);
 292                 if (absAccumulatedDelta > MAX_THRESHOLD) {
 293                     roundDelta = (int) Math.round(accumulatedDelta);

 294                     accumulatedDelta -= roundDelta;
 295                 }
 296 
 297                 if (end) {
 298                     if (roundDelta == 0 && absAccumulatedDelta > MIN_THRESHOLD) {
 299                         roundDelta = accumulatedDelta > 0 ? 1 : -1;
 300                     }
 301                 }
 302             }
 303 
 304             return roundDelta;
 305         }
 306     }
 307 }


 248                 c = text.charAt(index);
 249                 eventNotifier.notifyKeyEvent(KeyEvent.KEY_TYPED,
 250                         System.currentTimeMillis(),
 251                         0, KeyEvent.VK_UNDEFINED, c,
 252                         KeyEvent.KEY_LOCATION_UNKNOWN);
 253                 index++;
 254             }
 255             eventNotifier.notifyKeyEvent(KeyEvent.KEY_RELEASED,
 256                     System.currentTimeMillis(),
 257                     0, lastKeyPressCode, c,
 258                     KeyEvent.KEY_LOCATION_UNKNOWN);
 259         }
 260     }
 261 
 262     void handleWindowFocusEvent(boolean gained, LWWindowPeer opposite) {
 263         eventNotifier.notifyActivation(gained, opposite);
 264     }
 265 
 266     static class DeltaAccumulator {
 267 


 268         double accumulatedDelta;
 269         boolean accumulate;
 270 
 271         int getRoundedDelta(double delta, int scrollPhase) {
 272 
 273             int roundDelta = (int) Math.round(delta);
 274 
 275             if (scrollPhase == NSEvent.SCROLL_PHASE_UNSUPPORTED) { // mouse wheel
 276                 if (roundDelta == 0 && delta != 0) {
 277                     roundDelta = delta > 0 ? 1 : -1;
 278                 }
 279             } else { // trackpad
 280                 if (scrollPhase == NSEvent.SCROLL_PHASE_BEGAN) {




 281                     accumulatedDelta = 0;
 282                     accumulate = true;
 283                 }
 284                 else if (scrollPhase == NSEvent.SCROLL_PHASE_MOMENTUM_BEGAN) {
 285                     accumulate = true;
 286                 }
 287                 if (accumulate) {
 288 
 289                     accumulatedDelta += delta;
 290 


 291                     roundDelta = (int) Math.round(accumulatedDelta);
 292 
 293                     accumulatedDelta -= roundDelta;

 294 
 295                     if (scrollPhase == NSEvent.SCROLL_PHASE_ENDED) {
 296                         accumulate = false;

 297                     }
 298                 }
 299             }
 300 
 301             return roundDelta;
 302         }
 303     }
 304 }
< prev index next >