[Schmitzm-commits] r1008 - trunk/src/schmitzm/geotools/gui
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Sep 16 23:56:35 CEST 2010
Author: mojays
Date: 2010-09-16 23:56:35 +0200 (Thu, 16 Sep 2010)
New Revision: 1008
Added:
trunk/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java
Modified:
trunk/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java
trunk/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java
Log:
new XMapPaneActionDraggingAdapter to centralize the dragging envelope drawing
Modified: trunk/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java 2010-09-14 21:00:47 UTC (rev 1007)
+++ trunk/src/schmitzm/geotools/gui/XMapPaneActionAdapter.java 2010-09-16 21:56:35 UTC (rev 1008)
@@ -85,4 +85,15 @@
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: trunk/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java 2010-09-14 21:00:47 UTC (rev 1007)
+++ trunk/src/schmitzm/geotools/gui/XMapPaneActionDraggingAdapter.java 2010-09-16 21:56:35 UTC (rev 1008)
@@ -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: trunk/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java 2010-09-14 21:00:47 UTC (rev 1007)
+++ trunk/src/schmitzm/geotools/gui/XMapPaneAction_Zoom.java 2010-09-16 21:56:35 UTC (rev 1008)
@@ -12,21 +12,8 @@
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) {
-
- if (dragLastPos != null)
- mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
- dragLastPos);
-
- mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
- .getPoint());
- }
-
public static class In extends XMapPaneAction_Zoom {
@Override
@@ -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;
}
@@ -184,14 +166,10 @@
Point dragStartPos, Point dragLastPos,
DirectPosition startCoord, DirectPosition endCoord) {
- if (dragLastPos != null)
- mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
- dragLastPos);
+ super.performDragged(mapPane, ev, dragStartPos, dragLastPos, startCoord, endCoord);
// 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