From: <svn...@os...> - 2012-04-20 10:03:44
|
Author: moovida Date: 2012-04-20 03:03:30 -0700 (Fri, 20 Apr 2012) New Revision: 38680 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java Log: applying patch GEOT-4112 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -97,6 +97,18 @@ } /** + * The button that was pressed or released; 1 for the + * first button, 2 for the second button, and 3 for the + * third button, etc. + * + * @return the button that was pressed or released + * @see MouseEvent#button + */ + public int getMouseButton() { + return event.button; + } + + /** * Get the position, in map (world) coordinates of this mouse event * * @return a new DirectPosition2D object for the world coordinates Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -38,11 +38,22 @@ protected double zoom; /** - * Constructor + * Constructs a new abstract zoom tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public AbstractZoomTool() { - setZoom(DEFAULT_ZOOM_FACTOR); - } + public AbstractZoomTool(int triggeringMouseButton) { + super(triggeringMouseButton); + setZoom(DEFAULT_ZOOM_FACTOR); + } + + /** + * Constructs a new abstract zoom tool which is triggered by any mouse button. + */ + public AbstractZoomTool() { + this(CursorTool.ANY_BUTTON); + } + /** * Get the current areal zoom increment. Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -20,6 +20,7 @@ import org.eclipse.swt.graphics.Cursor; import org.geotools.swt.SwtMapPane; import org.geotools.swt.event.MapMouseAdapter; +import org.geotools.swt.event.MapMouseEvent; import org.geotools.swt.utils.CursorManager; import org.geotools.swt.utils.Messages; @@ -36,9 +37,33 @@ */ public abstract class CursorTool extends MapMouseAdapter { + /** + * Flag indicating that the tool should be triggered whenever any mouse button + * is used. + */ + public static final int ANY_BUTTON = -1; + private SwtMapPane mapPane; + private int triggeringMouseButton; + /** + * Constructs a new cursor tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button + */ + public CursorTool(int triggeringMouseButton) { + this.triggeringMouseButton = triggeringMouseButton; + } + + /** + * Constructs a new cursor tool which is triggered by any mouse button. + */ + public CursorTool() { + this(ANY_BUTTON); + } + + /** * Set the map pane that this cursor tool is associated with * @param pane the map pane * @throws IllegalArgumentException if mapPane is null @@ -83,4 +108,14 @@ * @return <code>true</code> if the tool can move the map while dragging. */ public abstract boolean canMove(); + + /** + * Checks if the tool should be triggered by the event. + * @param event event to be checked + * @return <code>true</code> if the tool is triggered by the event + */ + protected boolean isTriggerMouseButton(MapMouseEvent event) + { + return triggeringMouseButton == ANY_BUTTON || triggeringMouseButton == event.getMouseButton(); + } } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -84,16 +84,28 @@ private WeakHashMap<Layer, InfoToolHelper<?>> helperTable; /** - * Constructor + * Constructs a new info tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public InfoTool() { + public InfoTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getInfoCursor(); helperTable = new WeakHashMap<Layer, InfoToolHelper<?>>(); } /** + * Constructs a new info tool which is triggered by any mouse button. + */ + public InfoTool() { + this(CursorTool.ANY_BUTTON); + } + + + /** * Respond to a mouse click by querying each of the {@code MapLayers}. The * details of features lying within the threshold distance of the mouse * position are reported on screen using a {@code JTextReporter} dialog. @@ -111,6 +123,11 @@ */ @Override public void onMouseClicked( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + DirectPosition2D pos = ev.getMapPosition(); report(pos); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -50,21 +50,37 @@ boolean panning; /** - * Constructor + * Constructs a new pan tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public PanTool() { + public PanTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getPanCursor(); panning = false; } /** + * Constructs a new pan tool which is triggered by any mouse button. + */ + public PanTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Respond to a mouse button press event from the map mapPane. This may * signal the start of a mouse drag. Records the event's window position. * @param ev the mouse event */ @Override public void onMousePressed( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + panePos = ev.getPoint(); panning = true; } @@ -91,8 +107,10 @@ */ @Override public void onMouseReleased( MapMouseEvent ev ) { - panning = false; - getMapPane().redraw(); + if (panning) { + panning = false; + getMapPane().redraw(); + } } /** Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -62,9 +62,13 @@ private boolean dragged; /** - * Constructor + * Constructs a new zoom in tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomInTool() { + public ZoomInTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getZoominCursor(); startDragPos = new DirectPosition2D(); @@ -72,6 +76,13 @@ } /** + * Constructs a new zoom in tool which is triggered by any mouse button. + */ + public ZoomInTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Zoom in by the currently set increment, with the map * centred at the location (in world coords) of the mouse * click @@ -80,6 +91,11 @@ */ @Override public void onMouseClicked( MapMouseEvent e ) { + + if ( ! isTriggerMouseButton(e)) { + return; + } + startDragPos = new DirectPosition2D(); startDragPos.setLocation(e.getMapPosition()); } @@ -101,6 +117,11 @@ */ @Override public void onMouseDragged( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + dragged = true; } @@ -114,6 +135,11 @@ */ @Override public void onMouseReleased( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + if (dragged) { Envelope2D env = new Envelope2D(); env.setFrameFromDiagonal(startDragPos, ev.getMapPosition()); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -52,13 +52,23 @@ private Cursor cursor; /** - * Constructor + * Constructs a new zoom out tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomOutTool() { + public ZoomOutTool(int triggeringMouseButton) { + super(triggeringMouseButton); cursor = CursorManager.getInstance().getZoomoutCursor(); } /** + * Constructs a new zoom out tool which is triggered by any mouse button. + */ + public ZoomOutTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Zoom out by the currently set increment, with the map * centred at the location (in world coords) of the mouse * click @@ -67,6 +77,11 @@ */ @Override public void onMouseClicked( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + Rectangle paneArea = getMapPane().getBounds(); DirectPosition2D mapPos = ev.getMapPosition(); |