001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.tool;
018:
019: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
020: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseWheelEvent;
021: import net.refractions.udig.project.ui.render.displayAdapter.ViewportPane;
022:
023: /**
024: * An abstract class for all tools that wish to be "selection" tools. A selection tool is
025: * distinquished from other tools as it opens a context menu with the normal context menu mouse
026: * button.
027: *
028: * @author jeichar
029: * @since 0.9.0
030: */
031: public class SimpleTool extends AbstractModalTool {
032:
033: /**
034: * By default SimpleTool will simply respond to MOUSE.
035: * <p>
036: * To respond to additional stimulus please override your constuctor
037: * to call SimpleTool( targets ):<pre><code>
038: * public class MyTool extends SimpleTool {
039: * public MyTool(){ // default consturctor called by extention point
040: * super( MOUSE | WHEEL );
041: * }
042: * ...
043: * }
044: * </code></pre>
045: */
046: public SimpleTool() {
047: super (MOUSE);
048: }
049:
050: /**
051: * @see AbstractModalTool#AbstractModalTool(int)
052: */
053: public SimpleTool(int targets) {
054: super (targets);
055: }
056:
057: /**
058: * Called when a double clicked event occurs. It will never be a context-menu request
059: *
060: * @param e the mouse event
061: */
062: protected void onMouseDoubleClicked(MapMouseEvent e) {
063: // do nothing
064: }
065:
066: /**
067: * Called when a mouse pressed event occurs. It will never be a context-menu request
068: *
069: * @param e the mouse event
070: */
071: protected void onMousePressed(MapMouseEvent e) {
072: // do nothing
073: }
074:
075: /**
076: * Called when a mouse released event occurs. It will never be a context-menu request
077: *
078: * @param e the mouse event
079: */
080: protected void onMouseReleased(MapMouseEvent e) {
081: // do nothing
082: }
083:
084: /**
085: * Called when a entered event occurs. It will never be a context-menu request
086: *
087: * @param e the mouse event
088: */
089: protected void onMouseEntered(MapMouseEvent e) {
090: // do nothing
091: }
092:
093: /**
094: * Called when a moved event occurs. It will never be a context-menu request
095: *
096: * @param e the mouse event
097: */
098: protected void onMouseMoved(MapMouseEvent e) {
099: // do nothing
100: }
101:
102: /**
103: * Called when a hovered event occurs. It will never be a context-menu request
104: *
105: * @param e the mouse event
106: */
107: protected void onMouseHovered(MapMouseEvent e) {
108: // do nothing
109: }
110:
111: /**
112: * Called when a exited event occurs. It will never be a context-menu request
113: *
114: * @param e the mouse event
115: */
116: protected void onMouseExited(MapMouseEvent e) {
117: // do nothing
118: }
119:
120: /**
121: * Called when a mouse wheel moved event occurs. It will never be a context-menu request
122: *
123: * @param e the mouse event
124: */
125: protected void onMouseWheelMoved(MapMouseWheelEvent e) {
126: // do nothing
127: }
128:
129: /**
130: * Called when a mouse dragged event occurs. It will never be a context-menu request
131: *
132: * @param e the mouse event
133: */
134: protected void onMouseDragged(MapMouseEvent e) {
135: // do nothing
136: }
137:
138: /**
139: * Opens the context menu if the second mouse button is pressed and calls
140: * noContextMouseReleased().
141: *
142: * @see AbstractTool#mousePressed(MapMouseEvent)
143: * @param e the mouse event
144: * @see MapMouseEvent
145: */
146: public final void mousePressed(MapMouseEvent e) {
147: if (e.button == MapMouseEvent.BUTTON3)
148: ((ViewportPane) e.source).getMapEditor().openContextMenu();
149: else
150: onMousePressed(e);
151: }
152:
153: /**
154: * Consumes the event if the second mouse button is released and calls noContextMousePressed().
155: *
156: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseReleased(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
157: * @see MapMouseEvent
158: */
159: public final void mouseReleased(MapMouseEvent e) {
160: if (e.button != MapMouseEvent.BUTTON3)
161: onMouseReleased(e);
162: }
163:
164: /**
165: * Consumes the event if the second mouse button is doubleclicked and calls
166: * noContextMouseDoubleClicked().
167: *
168: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseDoubleClicked(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
169: * @see MapMouseEvent
170: */
171: public final void mouseDoubleClicked(MapMouseEvent e) {
172: if (e.button != MapMouseEvent.BUTTON3)
173: onMouseDoubleClicked(e);
174: }
175:
176: /**
177: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseDragged(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
178: * @see MapMouseEvent
179: */
180: public final void mouseDragged(MapMouseEvent e) {
181: if (e.button != MapMouseEvent.BUTTON3)
182: onMouseDragged(e);
183: }
184:
185: /**
186: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseEntered(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
187: * @see MapMouseEvent
188: */
189: public final void mouseEntered(MapMouseEvent e) {
190: if (e.button != MapMouseEvent.BUTTON3)
191: onMouseEntered(e);
192: }
193:
194: /**
195: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseMoved(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
196: * @see MapMouseEvent
197: */
198: public final void mouseMoved(MapMouseEvent e) {
199: if (e.button != MapMouseEvent.BUTTON3)
200: onMouseMoved(e);
201: }
202:
203: /**
204: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseMoved(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
205: * @see MapMouseEvent
206: */
207: public final void mouseHovered(MapMouseEvent e) {
208: if (e.button != MapMouseEvent.BUTTON3)
209: onMouseHovered(e);
210: }
211:
212: /**
213: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseExited(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
214: */
215: public final void mouseExited(MapMouseEvent e) {
216: if (e.button != MapMouseEvent.BUTTON3)
217: onMouseExited(e);
218: }
219:
220: /**
221: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseWheelMoved(net.refractions.udig.project.render.displayAdapter.MapMouseWheelEvent)
222: * @see MapMouseEvent
223: */
224: public final void mouseWheelMoved(MapMouseWheelEvent e) {
225: if (e.button != MapMouseEvent.BUTTON3)
226: onMouseWheelMoved(e);
227: }
228:
229: }
|