001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.ui.render.displayAdapter;
010:
011: import java.awt.Point;
012:
013: import org.eclipse.swt.SWT;
014:
015: import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
016:
017: /**
018: * Encapsulates a mouse event. MapMouseListeners receive MapMouse events.
019: *
020: * @author jeichar
021: */
022: public class MapMouseEvent {
023:
024: /** Indicates no modifiers or no buttons. */
025: public static final int NONE = 0;
026: /** Indicates that the alt key is down */
027: public static final int ALT_DOWN_MASK = SWT.ALT;
028:
029: /** Indicates that the ctrl key is down */
030: public static final int CTRL_DOWN_MASK = SWT.CTRL;
031:
032: /** Indicates that the shift key is down */
033: public static final int SHIFT_DOWN_MASK = SWT.SHIFT;
034:
035: /** Indicates that the mod1 key is down */
036: public static final int MOD1_DOWN_MASK = SWT.MOD1;
037:
038: /** Indicates that the mod2 key is down */
039: public static final int MOD2_DOWN_MASK = SWT.MOD2;
040:
041: /** Indicates that the mod3 key is down */
042: public static final int MOD3_DOWN_MASK = SWT.MOD3;
043:
044: /** Indicates that the mod3 key is down */
045: public static final int MOD4_DOWN_MASK = SWT.MOD4;
046:
047: /** Indicates that the 1st mouse button, the left button on right handed mouses */
048: public static final int BUTTON1 = 1 << 3;
049:
050: /** Indicates that the 2nd mouse button. */
051: public static final int BUTTON2 = 1 << 4;
052:
053: /** Indicates that the 3rd mouse button. */
054: public static final int BUTTON3 = 1 << 5;
055:
056: /** The Viewport pane that raised the event. */
057: public final IMapDisplay source;
058:
059: /**
060: * The state consists buttons|modifiers
061: * @deprecated user modifiers and buttons
062: */
063: public final int state;
064:
065: /**
066: * All the buttons that are currently down ORed together
067: */
068: public final int buttons;
069:
070: /**
071: * All the key modifiers ORed together
072: */
073: public final int modifiers;
074:
075: /** indicates the button that last changed */
076: public final int button;
077:
078: /** indicates the x position of the event */
079: public final int x;
080:
081: /** indicates the y position of the event */
082: public final int y;
083:
084: /** the time the event occurred */
085: public final long timestamp;
086:
087: /**
088: * Construct <code>MapMouseEvent</code>.
089: *
090: * @param source The object that raised the event
091: * @param x the x position of the event
092: * @param y the y position of the event
093: * @param modifiers indicates what modifiers are down. Modifiers are ORed together
094: * @param buttons indicates the buttons that are down. button ids are ORed together.
095: * @param button the button that last changed
096: */
097: public MapMouseEvent(IMapDisplay source, int x, int y,
098: int modifiers, int buttons, int button) {
099: this .source = source;
100: this .state = modifiers | buttons;
101: this .x = x;
102: this .y = y;
103: this .button = button;
104: this .buttons = buttons;
105: this .modifiers = modifiers;
106: timestamp = System.currentTimeMillis();
107: }
108:
109: /**
110: * Returns the location of the event.
111: *
112: * @return the location of the event.
113: * @see Point
114: */
115: public Point getPoint() {
116: return new Point(x, y);
117: }
118:
119: /**
120: * Returns true if shift key is down.
121: *
122: * @return true if shift key is down.
123: */
124: public boolean isShiftDown() {
125: return isModifierDown(SHIFT_DOWN_MASK);
126: }
127:
128: /**
129: * Returns true if control key is down.
130: *
131: * @return true if control key is down.
132: */
133: public boolean isControlDown() {
134: return isModifierDown(CTRL_DOWN_MASK);
135: }
136:
137: /**
138: * Returns true if alt key is down.
139: *
140: * @return true if alt key is down.
141: */
142: public boolean isAltDown() {
143: return isModifierDown(ALT_DOWN_MASK);
144: }
145:
146: /**
147: * Returns true if the modifier is down
148: *
149: * @see #CTRL_DOWN_MASK
150: * @see #ALT_DOWN_MASK
151: * @see #SHIFT_DOWN_MASK
152: * @see #MOD1_DOWN_MASK
153: * @see #MOD2_DOWN_MASK
154: * @see #MOD3_DOWN_MASK
155: * @see #MOD4_DOWN_MASK
156: *
157: * @param mask the modifier to test for.
158: * @return true if modifier is down.
159: */
160: public boolean isModifierDown(int mask) {
161: return (modifiers & mask) != 0;
162: }
163:
164: /**
165: * @return Returns true if a keyboard modifier is down.
166: */
167: public boolean modifiersDown() {
168: return isModifierDown(MOD1_DOWN_MASK)
169: || isModifierDown(MOD2_DOWN_MASK)
170: || isModifierDown(MOD3_DOWN_MASK)
171: || isModifierDown(MOD4_DOWN_MASK)
172: || isModifierDown(ALT_DOWN_MASK)
173: || isModifierDown(CTRL_DOWN_MASK)
174: || isModifierDown(SHIFT_DOWN_MASK);
175: }
176:
177: /**
178: * @return Returns true if a button is down.
179: */
180: public boolean buttonsDown() {
181: return buttons != 0;
182: }
183:
184: }
|