From: <svn...@os...> - 2012-04-20 15:10:30
|
Author: moovida Date: 2012-04-20 08:10:20 -0700 (Fri, 20 Apr 2012) New Revision: 38681 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java 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: enhancements to mouse when dragging + tools bbox style config by Michael Gruebsch Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -152,6 +152,10 @@ private Color white; private Color yellow; + private Color cursorToolColor; + private int cursorToolLineWidth; + private int cursorToolLineStyle; + /** * Constructor - creates an instance of JMapPane with no map * context or renderer initially @@ -216,6 +220,9 @@ } }); + cursorToolColor = getDisplay().getSystemColor(SWT.COLOR_YELLOW); + cursorToolLineWidth = 2; + cursorToolLineStyle = SWT.LINE_SOLID; } /** @@ -1123,7 +1130,7 @@ * draw a boundingbox while dragging, we draw the box * keeping the current drawn image */ - if (toolCanDraw && isDragging) { + if (toolCanDraw && toolManager.getCursorTool().isDrawing() && isDragging) { // System.out.println("draw box: " + startX + "/" + startY + "/" + endX + // "/" + endY); if (swtImage != null) { @@ -1132,8 +1139,9 @@ gc.setXORMode(true); org.eclipse.swt.graphics.Color fC = gc.getForeground(); - gc.setLineWidth(2); - gc.setForeground(yellow); + gc.setLineStyle(cursorToolLineStyle); + gc.setLineWidth(cursorToolLineWidth); + gc.setForeground(cursorToolColor); gc.drawRectangle(startX, startY, endX - startX, endY - startY); gc.setForeground(fC); @@ -1181,7 +1189,7 @@ swtImage.dispose(); swtImage = null; } - System.out.println("READRAWBASEIMAGE"); + // System.out.println("READRAWBASEIMAGE"); swtImage = new Image(getDisplay(), awtToSwt(baseImage, curPaintArea.width + 1, curPaintArea.height + 1)); } @@ -1290,4 +1298,72 @@ public void layerPreDispose( MapLayerListEvent event ) { } + + /** + * Returns the colour which is used to draw the bounding box + * of the currently active cursor tool. The bounding box is + * drawn in xor mode. + * + * @return the colour used for the tool's bounding box + */ + public Color getCursorToolColor() { + return cursorToolColor; + } + + /** + * Sets the colour which is used to draw the bounding box + * of the currently active cursor tool. The bounding box is + * drawn in xor mode. + * + * @param color the colour used for the tool's bounding box + */ + public void setCursorToolColor( Color color ) { + this.cursorToolColor = color; + } + + /** + * Returns the line width of the bounding box of the currently + * active cursor tool. + * + * @return line width + */ + public int getCursorToolLineWidth() { + return cursorToolLineWidth; + } + + /** + * Sets the line width of the bounding box of the currently + * active cursor tool. + * + * @param lineWidth line width + */ + public void setCursorToolLineWidth( int lineWidth ) { + this.cursorToolLineWidth = lineWidth; + } + + /** + * Returns the line style of the bounding box of the currently + * active cursor tool. + * + * @return line style + */ + public int getCursorToolLineStyle() { + return cursorToolLineStyle; + } + + /** + * Sets the line style of the bounding box of the currently + * active cursor tool. + * + * @param lineStyle line style + * @see SWT#LINE_SOLID + * @see SWT#LINE_DASH + * @see SWT#LINE_DOT + * @see SWT#LINE_DASHDOT + * @see SWT#LINE_DASHDOTDOT + */ + public void setCursorToolLineStyle( int lineStyle ) { + this.cursorToolLineStyle = lineStyle; + } + } 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -99,7 +99,8 @@ /** * The button that was pressed or released; 1 for the * first button, 2 for the second button, and 3 for the - * third button, etc. + * third button, etc. On mouse dragging this function may + * return 0. * * @return the button that was pressed or released * @see MouseEvent#button @@ -109,6 +110,15 @@ } /** + * Returns the state mask of the mouse event. + * @return the state mask + * @see MouseEvent#stateMask + */ + public int getStateMask() { + return event.stateMask; + } + + /** * 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,7 +17,9 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; + /** * Abstract base class for the zoom-in and zoom-out tools. Provides getter / setter * methods for the zoom increment. @@ -38,12 +40,15 @@ protected double zoom; /** - * Constructs a new abstract zoom tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new abstract zoom tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public AbstractZoomTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public AbstractZoomTool(int triggerButtonMask) { + super(triggerButtonMask); setZoom(DEFAULT_ZOOM_FACTOR); } 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.geotools.swt.SwtMapPane; import org.geotools.swt.event.MapMouseAdapter; @@ -41,19 +42,22 @@ * Flag indicating that the tool should be triggered whenever any mouse button * is used. */ - public static final int ANY_BUTTON = -1; + public static final int ANY_BUTTON = SWT.BUTTON_MASK; private SwtMapPane mapPane; - private int triggeringMouseButton; + private int triggerButtonMask; /** - * Constructs a new cursor tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new cursor tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask 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; + public CursorTool(int triggerButtonMask) { + this.triggerButtonMask = triggerButtonMask; } /** @@ -110,12 +114,37 @@ public abstract boolean canMove(); /** + * Returns <code>true</code> for any tool which is drawing + * while dragging. For tools which are triggered only by a certain + * mouse event it might be the case that {@link #canDraw()} is + * <code>true</code> while they are actually not active. + * + * @return <code>true</code> if the tool is drawing while dragging + */ + public boolean isDrawing() + { + return canDraw(); + } + + /** * 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(); + return + triggerButtonMask == ANY_BUTTON + || // on mouse move or mouse drag the mouse button field is 0 but the state mask is set + 0 != (triggerButtonMask & event.getStateMask()) + || // on mouse click the state mask is 0, but the mouse button field is set + ( event.getStateMask() == 0 + && ( ((triggerButtonMask & SWT.BUTTON1) != 0 && event.getMouseButton() == 1) + || ((triggerButtonMask & SWT.BUTTON2) != 0 && event.getMouseButton() == 2) + || ((triggerButtonMask & SWT.BUTTON3) != 0 && event.getMouseButton() == 3) + || ((triggerButtonMask & SWT.BUTTON4) != 0 && event.getMouseButton() == 4) + || ((triggerButtonMask & SWT.BUTTON5) != 0 && event.getMouseButton() == 5) + ) + ); } } 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -84,13 +84,16 @@ private WeakHashMap<Layer, InfoToolHelper<?>> helperTable; /** - * Constructs a new info tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new info tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public InfoTool(int triggeringMouseButton) { + public InfoTool(int triggerButtonMask) { - super(triggeringMouseButton); + super(triggerButtonMask); cursor = CursorManager.getInstance().getInfoCursor(); 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Point; import org.geotools.swt.SwtMapPane; @@ -50,12 +51,15 @@ boolean panning; /** - * Constructs a new pan tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new pan tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public PanTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public PanTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getPanCursor(); 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -22,6 +22,7 @@ import java.awt.geom.Point2D; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Rectangle; import org.geotools.geometry.DirectPosition2D; @@ -62,12 +63,15 @@ private boolean dragged; /** - * Constructs a new zoom in tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new zoom in tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomInTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public ZoomInTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getZoominCursor(); @@ -177,7 +181,12 @@ return false; } - public static double pythagoras( double d1, double d2 ) { + @Override + public boolean isDrawing() { + return dragged; + } + + public static double pythagoras( double d1, double d2 ) { return sqrt(pow(d1, 2.0) + pow(d2, 2.0)); } } 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 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Rectangle; import org.geotools.geometry.DirectPosition2D; @@ -52,12 +53,15 @@ private Cursor cursor; /** - * Constructs a new zoom out tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new zoom out tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomOutTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public ZoomOutTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getZoomoutCursor(); } @@ -105,7 +109,7 @@ } public boolean canDraw() { - return true; + return false; } public boolean canMove() { |