KickJava   Java API By Example, From Geeks To Geeks.

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


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 mouse movement in a lateral (vertical or horizontal) direction.
22  * This event represents a high level event that does not have a direct
23  * InputEvent associated with it. This class maintains a magnitude parameter.
24  * Two LateralMouseMoveEvents are equal if their magnitude has the same
25  * direction (positive/negative), but the actual magnitude does not matter.
26  *
27  * @author Dusty Phillips [dusty@buchuki.com]
28  */

29 public class LateralMouseMoveEvent extends EnsmerMouseEvent implements Measurable {
30
31     /**
32      * Create a LateralMouseMoveEvent with a reference to its magnitude.
33      *
34      * @param magnitude the amount of movement that occured. A negative movement
35      * indicates leftward or downward action, while a positive movement
36      * indicates rightward or upward action.
37      */

38     public LateralMouseMoveEvent(int magnitude) {
39         this.magnitude = magnitude;
40     }
41
42     /**
43      * Determine if this object is equal to another object. Two objects are equal
44      * if they are instances of the same class and the magnitude has the same sign
45      * (ie: both are positive or both are negative).
46      *
47      * @param obj the object to compare to
48      * @return true if the two objects are equal
49      */

50     @Override JavaDoc
51     public boolean equals(Object JavaDoc obj) {
52         if (!getClass().equals(obj.getClass())) {
53             return false;
54         }
55         int newmag = (int) ((LateralMouseMoveEvent) obj).getMagnitude();
56         if (newmag < 0 && magnitude < 0) {
57             return true;
58         }
59         else if (newmag > 0 && magnitude > 0) {
60             return true;
61         }
62         else if (newmag == 0 && magnitude == 0) {
63             return true;
64         }
65         else {
66             return false;
67         }
68     }
69
70     /**
71      * Get the hashcode for this class. Events are not likely to be hashed, but
72      * this method maintains the equals contract
73      *
74      * @return The hashcode for this object
75      */

76     @Override JavaDoc
77     public int hashCode() {
78         int classcode = getClass().hashCode();
79         if (magnitude < 1) {
80             return classcode - 1;
81         }
82         else if (magnitude > 1) {
83             return classcode + 1;
84         }
85         else {
86             return classcode;
87         }
88     }
89
90     /**
91      * Returns the magnitude of the movement for this Lateral Movement
92      *
93      * @return The magnitude of the movement
94      */

95     public float getMagnitude() {
96         return magnitude;
97     }
98
99     /**
100      * The magnitude of the movement for this Lateral movement
101      */

102     private int magnitude;
103 }
104
105
Popular Tags