[Schmitzm-commits] r1010 - branches/2.2.x/src/schmitzm/geotools/gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 17 00:00:02 CEST 2010


Author: mojays
Date: 2010-09-17 00:00:02 +0200 (Fri, 17 Sep 2010)
New Revision: 1010

Added:
   branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java
Modified:
   branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java
   branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java
Log:
new XMapPaneActionDraggingAdapter to centralize the dragging envelope drawing

Modified: branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java	2010-09-16 21:58:52 UTC (rev 1009)
+++ branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java	2010-09-16 22:00:02 UTC (rev 1010)
@@ -84,5 +84,16 @@
   public void performWheel(XMapPane mapPane, MouseWheelEvent ev,
       DirectPosition coord) {
   }
+  
+  /**
+   * Checks whether a mouse drag is too small, so it should be
+   * handled as a click.
+   */
+  public static boolean dragWasClick(XMapPane mapPane, MouseEvent ev,
+      Point dragStartPos, Point dragLastPos,
+      DirectPosition startCoord, DirectPosition endCoord) {
+    return (Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
+        .getPoint().y - dragStartPos.y)) < 160;
+  }
 
 }

Added: branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java	2010-09-16 21:58:52 UTC (rev 1009)
+++ branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java	2010-09-16 22:00:02 UTC (rev 1010)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+
+package schmitzm.geotools.gui;
+
+import java.awt.Color;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+
+import org.opengis.geometry.DirectPosition;
+
+
+
+/**
+ * Almost empty implementation of {@link XMapPaneAction}. Only
+ * {@link #performDragging(XMapPane, MouseEvent, Point, Point, DirectPosition, DirectPosition)}
+ * is implemented to show a dragging window. Furthermore the
+ * {@link #performDragged(XMapPane, MouseEvent, Point, Point, DirectPosition, DirectPosition)}
+ * implements the "delete" of the dragging window. So a
+ * super-call is recommended when overwriting this method
+ * for the "real" dragged action.
+ * does anything.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ */
+public class XMapPaneActionDraggingAdapter extends XMapPaneActionAdapter {
+  /** Color of the dragging envelope. */
+  protected Color rectColor = Color.WHITE;
+  /** Flag whether the dragging envelope is filled. */
+  protected boolean rectFill = false;
+  
+  /**
+   * Default constructor. Simply calls {@link #init()}.
+   */
+  public XMapPaneActionDraggingAdapter() {
+    init();
+  }
+  
+  /**
+   * Can be overwritten to change the color and fill
+   * behavior.
+   */
+  protected void init() {
+  }
+  
+  /**
+   * Implements the action AFTER a mouse drag has ended. Does nothing.
+   */
+  @Override
+  public void performDragged(XMapPane mapPane, MouseEvent ev,
+      Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
+      DirectPosition endCoord) {
+    // Remove the last dragging window
+    if (dragLastPos != null)
+      mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+              dragLastPos, rectColor, rectFill);
+  }
+
+  /**
+   * Implements the action DURING a mouse drag. Does nothing.
+   */
+  @Override
+  public void performDragging(XMapPane mapPane, MouseEvent ev,
+      Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
+      DirectPosition endCoord) {
+    // Remove the last dragging window
+    if (dragLastPos != null)
+      mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+              dragLastPos, rectColor, rectFill);
+    // Create the new dragging window
+    mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+        ev.getPoint(), rectColor, rectFill);
+   }
+}

Modified: branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java	2010-09-16 21:58:52 UTC (rev 1009)
+++ branches/2.2.x/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java	2010-09-16 22:00:02 UTC (rev 1010)
@@ -12,23 +12,10 @@
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 
-public abstract class XMapPaneAction_Zoom implements XMapPaneAction {
+public abstract class XMapPaneAction_Zoom extends XMapPaneActionDraggingAdapter {
 
-	@Override
-	public void performDragging(XMapPane mapPane, MouseEvent ev,
-			Point dragStartPos, Point dragLastPos,
-			DirectPosition startCoord, DirectPosition endCoord) {
+  public static class In extends XMapPaneAction_Zoom {
 
-		if (dragLastPos != null)
-			mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
-					dragLastPos);
-
-		mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
-				.getPoint());
-	}
-
-	public static class In extends XMapPaneAction_Zoom {
-
 		@Override
 		public void performClick(XMapPane mapPane, MouseEvent ev,
 				DirectPosition coord) {
@@ -72,15 +59,10 @@
 		public void performDragged(XMapPane mapPane, MouseEvent ev,
 				Point dragStartPos, Point dragLastPos,
 				DirectPosition startCoord, DirectPosition endCoord) {
+		    super.performDragged(mapPane, ev, dragStartPos, dragLastPos, startCoord, endCoord);
 
-			if (dragLastPos != null)
-				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
-						dragLastPos);
-
 			// If this is similar to a click, let mouseClicked handle it!
-			if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
-					.getPoint().y
-					- dragStartPos.y)) < 160) {
+			if ( dragWasClick(mapPane,ev,dragStartPos,dragLastPos,startCoord,endCoord) ) {
 				// performClick(mapPane, ev, coord)
 				return;
 			}
@@ -183,15 +165,14 @@
 		public void performDragged(XMapPane mapPane, MouseEvent ev,
 				Point dragStartPos, Point dragLastPos,
 				DirectPosition startCoord, DirectPosition endCoord) {
+          super.performDragged(mapPane, ev, dragStartPos, dragLastPos, startCoord, endCoord);
 
-			if (dragLastPos != null)
-				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
-						dragLastPos);
+//			if (dragLastPos != null)
+//				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+//						dragLastPos);
 
 			// If this is similar to a click, let mouseClicked handle it!
-			if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
-					.getPoint().y
-					- dragStartPos.y)) < 160) {
+			if ( dragWasClick(mapPane,ev,dragStartPos,dragLastPos,startCoord,endCoord) ) {
 				// performClick(mapPane, ev, coord)
 				return;
 			}



More information about the Schmitzm-commits mailing list