01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: @Override
46: public boolean equals(Object o) {
47: if (o instanceof MouseWheelVelocity) {
48: MouseWheelVelocity v = (MouseWheelVelocity) o;
49: return getDeltaY() == v.getDeltaY();
50: }
51:
52: return false;
53: }
54:
55: /**
56: * @return the change in the mouse wheel position along the Y-axis; positive
57: * if the mouse wheel is moving north (toward the top of the screen)
58: * or negative if the mouse wheel is moving south (toward the bottom
59: * of the screen)
60: */
61: public int getDeltaY() {
62: return vY;
63: }
64:
65: @Override
66: public int hashCode() {
67: return getDeltaY();
68: }
69:
70: /**
71: * Convenience method that returns <code>true</code> if {@link #getDeltaY()}
72: * is a negative value.
73: *
74: * @return <code>true</code> if the velocity includes a component directed
75: * toword the top of the screen
76: */
77: public boolean isNorth() {
78: return getDeltaY() < 0;
79: }
80:
81: /**
82: * Convenience method that returns <code>true</code> if {@link #getDeltaY()}
83: * is a positive value.
84: *
85: * @return <code>true</code> if the velocity includes a component directed
86: * toword the bottom of the screen
87: */
88: public boolean isSouth() {
89: return getDeltaY() > 0;
90: }
91:
92: @Override
93: public String toString() {
94: return "<" + getDeltaY() + ">";
95: }
96: }
|