jdk/src/share/classes/java/awt/event/MouseWheelEvent.java
changeset 121 c43b2dfab9ac
parent 2 90ce3da70b43
child 440 a3dac373f62d
equal deleted inserted replaced
120:98296a9fc072 121:c43b2dfab9ac
     1 /*
     1 /*
     2  * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     7  * published by the Free Software Foundation.  Sun designates this
    72  * (commonly lines of text in a text-based component) or an entire "block"
    72  * (commonly lines of text in a text-based component) or an entire "block"
    73  * (similar to page-up/page-down).  The MouseWheelEvent offers
    73  * (similar to page-up/page-down).  The MouseWheelEvent offers
    74  * methods for conforming to the underlying platform settings.  These
    74  * methods for conforming to the underlying platform settings.  These
    75  * platform settings can be changed at any time by the user.  MouseWheelEvents
    75  * platform settings can be changed at any time by the user.  MouseWheelEvents
    76  * reflect the most recent settings.
    76  * reflect the most recent settings.
       
    77  * <P>
       
    78  * The <code>MouseWheelEvent</code> class includes methods for
       
    79  * getting the number of "clicks" by which the mouse wheel is rotated.
       
    80  * The {@link #getWheelRotation} method returns the integer number
       
    81  * of "clicks" corresponding to the number of notches by which the wheel was
       
    82  * rotated. In addition to this method, the <code>MouseWheelEvent</code>
       
    83  * class provides the {@link #getPreciseWheelRotation} method which returns
       
    84  * a double number of "clicks" in case a partial rotation occurred.
       
    85  * The {@link #getPreciseWheelRotation} method is useful if a mouse supports
       
    86  * a high-resolution wheel, such as a freely rotating wheel with no
       
    87  * notches. Applications can benefit by using this method to process
       
    88  * mouse wheel events more precisely, and thus, making visual perception
       
    89  * smoother.
    77  *
    90  *
    78  * @author Brent Christian
    91  * @author Brent Christian
    79  * @see MouseWheelListener
    92  * @see MouseWheelListener
    80  * @see java.awt.ScrollPane
    93  * @see java.awt.ScrollPane
    81  * @see java.awt.ScrollPane#setWheelScrollingEnabled(boolean)
    94  * @see java.awt.ScrollPane#setWheelScrollingEnabled(boolean)
   128      * Indicates how far the mouse wheel was rotated.
   141      * Indicates how far the mouse wheel was rotated.
   129      *
   142      *
   130      * @see #getWheelRotation
   143      * @see #getWheelRotation
   131      */
   144      */
   132     int wheelRotation;
   145     int wheelRotation;
       
   146 
       
   147     /**
       
   148      * Indicates how far the mouse wheel was rotated.
       
   149      *
       
   150      * @see #getPreciseWheelRotation
       
   151      */
       
   152     double preciseWheelRotation;
   133 
   153 
   134     /*
   154     /*
   135      * serialVersionUID
   155      * serialVersionUID
   136      */
   156      */
   137 
   157 
   163      *                       response to this event;  valid values are
   183      *                       response to this event;  valid values are
   164      *                       <code>WHEEL_UNIT_SCROLL</code> and
   184      *                       <code>WHEEL_UNIT_SCROLL</code> and
   165      *                       <code>WHEEL_BLOCK_SCROLL</code>
   185      *                       <code>WHEEL_BLOCK_SCROLL</code>
   166      * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
   186      * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
   167      *                       the number of units to be scrolled
   187      *                       the number of units to be scrolled
   168      * @param wheelRotation  the amount that the mouse wheel was rotated (the
   188      * @param wheelRotation  the integer number of "clicks" by which the mouse
   169      *                       number of "clicks")
   189      *                       wheel was rotated
   170      *
   190      *
   171      * @throws IllegalArgumentException if <code>source</code> is null
   191      * @throws IllegalArgumentException if <code>source</code> is null
   172      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
   192      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
   173      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
   193      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
   174      */
   194      */
   209      *                       response to this event;  valid values are
   229      *                       response to this event;  valid values are
   210      *                       <code>WHEEL_UNIT_SCROLL</code> and
   230      *                       <code>WHEEL_UNIT_SCROLL</code> and
   211      *                       <code>WHEEL_BLOCK_SCROLL</code>
   231      *                       <code>WHEEL_BLOCK_SCROLL</code>
   212      * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
   232      * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
   213      *                       the number of units to be scrolled
   233      *                       the number of units to be scrolled
   214      * @param wheelRotation  the amount that the mouse wheel was rotated (the
   234      * @param wheelRotation  the integer number of "clicks" by which the mouse
   215      *                       number of "clicks")
   235      *                       wheel was rotated
   216      *
   236      *
   217      * @throws IllegalArgumentException if <code>source</code> is null
   237      * @throws IllegalArgumentException if <code>source</code> is null
   218      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
   238      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
   219      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
   239      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
   220      * @since 1.6
   240      * @since 1.6
   221      */
   241      */
   222     public MouseWheelEvent (Component source, int id, long when, int modifiers,
   242     public MouseWheelEvent (Component source, int id, long when, int modifiers,
   223                             int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
   243                             int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
   224                             int scrollType, int scrollAmount, int wheelRotation) {
   244                             int scrollType, int scrollAmount, int wheelRotation) {
   225 
   245 
       
   246         this(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger,
       
   247              scrollType, scrollAmount, wheelRotation, wheelRotation);
       
   248 
       
   249     }
       
   250 
       
   251 
       
   252     /**
       
   253      * Constructs a <code>MouseWheelEvent</code> object with the specified
       
   254      * source component, type, modifiers, coordinates, absolute coordinates,
       
   255      * scroll type, scroll amount, and wheel rotation.
       
   256      * <p>Note that passing in an invalid <code>id</code> parameter results
       
   257      * in unspecified behavior. This method throws an
       
   258      * <code>IllegalArgumentException</code> if <code>source</code> equals
       
   259      * <code>null</code>.
       
   260      * <p>Even if inconsistent values for relative and absolute coordinates
       
   261      * are passed to the constructor, a <code>MouseWheelEvent</code> instance
       
   262      * is still created and no exception is thrown.
       
   263      *
       
   264      * @param source         the <code>Component</code> that originated the event
       
   265      * @param id             the integer value that identifies the event
       
   266      * @param when           a long value that gives the time when the event occurred
       
   267      * @param modifiers      the modifier keys down during event
       
   268      *                       (shift, ctrl, alt, meta)
       
   269      * @param x              the horizontal <code>x</code> coordinate for the
       
   270      *                       mouse location
       
   271      * @param y              the vertical <code>y</code> coordinate for the
       
   272      *                       mouse location
       
   273      * @param xAbs           the absolute horizontal <code>x</code> coordinate for
       
   274      *                       the mouse location
       
   275      * @param yAbs           the absolute vertical <code>y</code> coordinate for
       
   276      *                       the mouse location
       
   277      * @param clickCount     the number of mouse clicks associated with the event
       
   278      * @param popupTrigger   a boolean value, <code>true</code> if this event is a trigger
       
   279      *                       for a popup-menu
       
   280      * @param scrollType     the type of scrolling which should take place in
       
   281      *                       response to this event;  valid values are
       
   282      *                       <code>WHEEL_UNIT_SCROLL</code> and
       
   283      *                       <code>WHEEL_BLOCK_SCROLL</code>
       
   284      * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
       
   285      *                       the number of units to be scrolled
       
   286      * @param wheelRotation  the integer number of "clicks" by which the mouse wheel
       
   287      *                       was rotated
       
   288      * @param preciseWheelRotation the double number of "clicks" by which the mouse wheel
       
   289      *                       was rotated
       
   290      *
       
   291      * @throws IllegalArgumentException if <code>source</code> is null
       
   292      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
       
   293      * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
       
   294      * @since 1.7
       
   295      */
       
   296     public MouseWheelEvent (Component source, int id, long when, int modifiers,
       
   297                             int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
       
   298                             int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation) {
       
   299 
   226         super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
   300         super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
   227               popupTrigger, MouseEvent.NOBUTTON);
   301               popupTrigger, MouseEvent.NOBUTTON);
   228 
   302 
   229         this.scrollType = scrollType;
   303         this.scrollType = scrollType;
   230         this.scrollAmount = scrollAmount;
   304         this.scrollAmount = scrollAmount;
   231         this.wheelRotation = wheelRotation;
   305         this.wheelRotation = wheelRotation;
       
   306         this.preciseWheelRotation = preciseWheelRotation;
       
   307 
   232     }
   308     }
   233 
   309 
   234     /**
   310     /**
   235      * Returns the type of scrolling that should take place in response to this
   311      * Returns the type of scrolling that should take place in response to this
   236      * event.  This is determined by the native platform.  Legal values are:
   312      * event.  This is determined by the native platform.  Legal values are:
   265     public int getScrollAmount() {
   341     public int getScrollAmount() {
   266         return scrollAmount;
   342         return scrollAmount;
   267     }
   343     }
   268 
   344 
   269     /**
   345     /**
   270      * Returns the number of "clicks" the mouse wheel was rotated.
   346      * Returns the number of "clicks" the mouse wheel was rotated, as an integer.
       
   347      * A partial rotation may occur if the mouse supports a high-resolution wheel.
       
   348      * In this case, the method returns zero until a full "click" has been accumulated.
   271      *
   349      *
   272      * @return negative values if the mouse wheel was rotated up/away from
   350      * @return negative values if the mouse wheel was rotated up/away from
   273      * the user, and positive values if the mouse wheel was rotated down/
   351      * the user, and positive values if the mouse wheel was rotated down/
   274      * towards the user
   352      * towards the user
       
   353      * @see #getPreciseWheelRotation
   275      */
   354      */
   276     public int getWheelRotation() {
   355     public int getWheelRotation() {
   277         return wheelRotation;
   356         return wheelRotation;
       
   357     }
       
   358 
       
   359     /**
       
   360      * Returns the number of "clicks" the mouse wheel was rotated, as a double.
       
   361      * A partial rotation may occur if the mouse supports a high-resolution wheel.
       
   362      * In this case, the return value will include a fractional "click".
       
   363      *
       
   364      * @return negative values if the mouse wheel was rotated up or away from
       
   365      * the user, and positive values if the mouse wheel was rotated down or
       
   366      * towards the user
       
   367      * @see #getWheelRotation
       
   368      * @since 1.7
       
   369      */
       
   370     public double getPreciseWheelRotation() {
       
   371         return preciseWheelRotation;
   278     }
   372     }
   279 
   373 
   280     /**
   374     /**
   281      * This is a convenience method to aid in the implementation of
   375      * This is a convenience method to aid in the implementation of
   282      * the common-case MouseWheelListener - to scroll a ScrollPane or
   376      * the common-case MouseWheelListener - to scroll a ScrollPane or
   346         else {
   440         else {
   347             scrollTypeStr = "unknown scroll type";
   441             scrollTypeStr = "unknown scroll type";
   348         }
   442         }
   349         return super.paramString()+",scrollType="+scrollTypeStr+
   443         return super.paramString()+",scrollType="+scrollTypeStr+
   350          ",scrollAmount="+getScrollAmount()+",wheelRotation="+
   444          ",scrollAmount="+getScrollAmount()+",wheelRotation="+
   351          getWheelRotation();
   445          getWheelRotation()+",preciseWheelRotation="+getPreciseWheelRotation();
   352     }
   446     }
   353 }
   447 }