KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > buchuki > ensmer > input > event > MouseWheelEvent


1 /*
2  * Copyright 2004 Dusty Phillips
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.buchuki.ensmer.input.event;
17
18 import java.awt.event.*;
19
20 /**
21  * Represents a MouseWheel in any direction. It can model an event that
22  * has occured or an event that can occur. If no actual event is represented,
23  * getInputEvent() will return null;
24  *
25  * @author Dusty Phillips [dusty@buchuki.com]
26  */

27 public class MouseWheelEvent extends EnsmerMouseEvent implements Measurable {
28
29     /**
30      * Create a MouseWheelEvent.
31      */

32     public MouseWheelEvent() {
33         super();
34     }
35
36     /**
37      * Create a MouseWheelEvent with a reference to the actual MouseWheelEvent
38      * that occured. This constructor is used when an actual InputEvent has
39      * been generated. The button is retrieved from the event itself.
40      *
41      * @param event an InputEvent that was generated
42      */

43     public MouseWheelEvent(java.awt.event.MouseWheelEvent JavaDoc event) {
44         super(event);
45     }
46     
47     /**
48      * Get the magnitude of the wheel rotation. This method call is only valid
49      * if the event was instantiated with a genuine MouseWheelEvent, otherwise
50      * an IllegalStateException is thrown
51      *
52      * @return the magnitude of the wheelmovement
53      * @throws IllegalStateException if this doesn't represent an actual
54      * InputEvent
55      */

56     public float getMagnitude() {
57         java.awt.event.MouseWheelEvent JavaDoc evt = (java.awt.event.MouseWheelEvent JavaDoc) getInputEvent();
58         if (evt == null) {
59             throw new IllegalStateException JavaDoc("No MouseWheelEvent to retrieve magnitude from");
60         }
61         return evt.getWheelRotation();
62     }
63
64     /**
65      * Determine if this event is equal to another object. Two events are
66      * equal if they have the same class in this case.
67      *
68      * @param obj the object to compare to
69      * @return true if the object is equal to this object
70      */

71     @Override JavaDoc
72     public boolean equals(Object JavaDoc obj) {
73         return getClass().equals(obj.getClass());
74     }
75
76     /**
77      * Determine the hashcode for this event. Events will not likely be
78      * hashed, but this keeps the equals() contract.
79      *
80      * @return the hashCode for this object
81      */

82      @Override JavaDoc
83     public int hashCode() {
84         return getClass().hashCode();
85     }
86
87 }
88
Popular Tags