KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > MouseWheelVelocity


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui;
17
18 import com.google.gwt.user.client.DOM;
19 import com.google.gwt.user.client.Event;
20
21 /**
22  * Encapsulates the direction and velocity of mouse wheel events. Not all
23  * combinations of browser and user input devices can generate all combinations
24  * of direction or range of velocity information.
25  *
26  * @see com.google.gwt.user.client.DOM#eventGetMouseWheelVelocityY An
27  * explanation of the units used for mouse wheel velocity.
28  */

29 public class MouseWheelVelocity {
30
31   /**
32    * Stores the Y-axis velocity.
33    */

34   protected final int vY;
35
36   /**
37    * Construct the higher-level view of the original ONMOUSEWHEEL Event.
38    *
39    * @param e the event
40    */

41   public MouseWheelVelocity(Event e) {
42     vY = DOM.eventGetMouseWheelVelocityY(e);
43   }
44
45   public boolean equals(Object JavaDoc o) {
46     if (o instanceof MouseWheelVelocity) {
47       MouseWheelVelocity v = (MouseWheelVelocity) o;
48       return getDeltaY() == v.getDeltaY();
49     }
50
51     return false;
52   }
53
54   /**
55    * @return the change in the mouse wheel position along the Y-axis; positive
56    * if the mouse wheel is moving north (toward the top of the screen)
57    * or negative if the mouse wheel is moving south (toward the bottom
58    * of the screen)
59    */

60   public int getDeltaY() {
61     return vY;
62   }
63
64   public int hashCode() {
65     return getDeltaY();
66   }
67
68   /**
69    * Convenience method that returns <code>true</code> if {@link #getDeltaY()}
70    * is a negative value.
71    *
72    * @return <code>true</code> if the velocity includes a component directed
73    * toword the top of the screen
74    */

75   public boolean isNorth() {
76     return getDeltaY() < 0;
77   }
78
79   /**
80    * Convenience method that returns <code>true</code> if {@link #getDeltaY()}
81    * is a positive value.
82    *
83    * @return <code>true</code> if the velocity includes a component directed
84    * toword the bottom of the screen
85    */

86   public boolean isSouth() {
87     return getDeltaY() > 0;
88   }
89
90   public String JavaDoc toString() {
91     return "<" + getDeltaY() + ">";
92   }
93 }
94
Popular Tags