source: trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/MouseButtonInteraction.java @ 2252

Last change on this file since 2252 was 945, checked in by pharms, 12 years ago
  • added support for mouse click coordinates
  • Property svn:executable set to *
File size: 3.3 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.eventcore.gui;
16
17/**
18 * <p>
19 * Base class for all mouse interaction event types.
20 * </p>
21 *
22 * @version 1.0
23 * @author Patrick Harms
24 */
25public abstract class MouseButtonInteraction extends MouseInteraction {
26
27    /**
28     * <p>
29     * Id for object serialization.
30     * </p>
31     */
32    private static final long serialVersionUID = 1L;
33
34    /**
35     * <p>
36     * Describes the pressed mouse button.
37     * </p>
38     *
39     * @version 1.0
40     * @author Patrick Harms
41     */
42    public static enum Button {
43        LEFT, MIDDLE, RIGHT, X;
44    }
45
46    /**
47     * <p>
48     * The button used for mouse interaction
49     * </p>
50     */
51    private Button button;
52
53    /**
54     * <p>
55     * The x coordinate, where the mouse interaction took place
56     * </p>
57     */
58    private int x;
59
60    /**
61     * <p>
62     * The y coordinate, where the mouse interaction took place
63     * </p>
64     */
65    private int y;
66
67    /**
68     * <p>
69     * Constructor. Creates a new {@link MouseButtonInteraction}
70     * </p>
71     *
72     * @param button
73     *            the button associated with the interaction
74     * @param x
75     *            the x coordinate of where the interaction took place on the target
76     * @param y
77     *            the y coordinate of where the interaction took place on the target
78     */
79    public MouseButtonInteraction(Button button, int x, int y) {
80        this.button = button;
81        this.x = x;
82        this.y = y;
83    }
84
85    /**
86     * <p>
87     * Returns the button associated with the interaction.
88     * </p>
89     *
90     * @return the button
91     */
92    public Button getButton() {
93        return button;
94    }
95
96    /**
97     * <p>
98     * Returns the x coordinate of where the interaction took place on the target.
99     * </p>
100     *
101     * @return the x coordinate
102     */
103    public int getX() {
104        return x;
105    }
106
107    /**
108     * <p>
109     * Returns the y coordinate of where the interaction took place on the target.
110     * </p>
111     *
112     * @return the y coordinate
113     */
114    public int getY() {
115        return y;
116    }
117
118    /*
119     * (non-Javadoc)
120     *
121     * @see java.lang.Object#equals(java.lang.Object)
122     */
123    @Override
124    public boolean equals(Object obj) {
125        if (obj instanceof MouseButtonInteraction) {
126            return getButton().equals(((MouseButtonInteraction) obj).getButton());
127        }
128        return false;
129    }
130
131    /*
132     * (non-Javadoc)
133     *
134     * @see java.lang.Object#hashCode()
135     */
136    @Override
137    public int hashCode() {
138        return getButton().hashCode();
139    }
140}
Note: See TracBrowser for help on using the repository browser.