KickJava   Java API By Example, From Geeks To Geeks.

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


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 MouseButtonEvent for a specific button. It can model an event
22  * that has occured or an event that can occur. If no actual event is
23  * represented, getInputEvent() will return null. This class acts as an
24  * abstract class for the MousePressEvent and MouseReleaseEvents that share a
25  * lot of functionality.
26  *
27  * @author Dusty Phillips [dusty@buchuki.com]
28  */

29 public class EnsmerMouseButtonEvent extends EnsmerMouseEvent {
30
31     /**
32      * Create an EnsmerMouseButtonEvent with a reference to the button it should
33      * model. This constructor is used when no actual InputEvent was generated.
34      *
35      * @param button One of the java.awt.event.MouseEvent.ButtonX constants.
36      */

37     public EnsmerMouseButtonEvent(int button) {
38         this.button = button;
39     }
40
41     /**
42      * Create an EnsmerMouseButtonEvent with a reference to the actual MouseEvent
43      * that occured. This constructor is used when an actual InputEvent has been
44      * generated. The button is retrieved from the event itself.
45      *
46      * @param event an InputEvent that was generated
47      */

48     public EnsmerMouseButtonEvent(MouseEvent event) {
49         super(event);
50         this.button = event.getButton();
51     }
52
53     /**
54      * Compare this EnsmerMouseButtonEvent to another object to determine if they
55      * are equal. Objects are equal if they are the same class and have the same
56      * button.
57      *
58      * @param obj the object to compare to
59      * @return Description of the Return Value
60      */

61     @Override JavaDoc
62     public boolean equals(Object JavaDoc obj) {
63         return getClass().equals(obj.getClass()) && ((EnsmerMouseButtonEvent) obj).getButton() == button;
64     }
65
66     /**
67      * Retrieve the hashcode for this object. Events are not likely to be hashed,
68      * but this keeps the equals() contract.
69      *
70      * @return the hashcode for this object
71      */

72     @Override JavaDoc
73     public int hashCode() {
74         return button + getClass().hashCode();
75     }
76
77     /**
78      * Get access to the button for this object
79      *
80      * @return an integer (from java.awt.event.MouseEvent) representing which
81      * button was activated
82      */

83     public int getButton() {
84         return button;
85     }
86
87     /**
88      * The keycode for the key that was pressed
89      */

90     private int button;
91 }
92
93
Popular Tags