[Schmitzm-commits] r636 - branches/2.0-RC2/src/skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 28 16:33:22 CET 2010
Author: alfonx
Date: 2010-01-28 16:33:22 +0100 (Thu, 28 Jan 2010)
New Revision: 636
Modified:
branches/2.0-RC2/src/skrueger/geotools/XMapPaneMouseListener.java
Log:
Schrittweise umstellen...
Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPaneMouseListener.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPaneMouseListener.java 2010-01-28 15:27:27 UTC (rev 635)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPaneMouseListener.java 2010-01-28 15:33:22 UTC (rev 636)
@@ -1,10 +1,166 @@
package skrueger.geotools;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.geotools.geometry.DirectPosition2D;
+
+import schmitzm.geotools.JTSUtil;
+import schmitzm.swing.event.MouseInputType;
import schmitzm.swing.event.SelectiveMouseAdapter;
+import schmitzm.swing.event.MouseInputType.*;
public class XMapPaneMouseListener extends SelectiveMouseAdapter {
+ /**
+ * Holds the configuration of which {@link XMapPaneAction} is associated
+ * with which {@link MouseInputType}
+ **/
+ Map<MouseInputType, XMapPaneAction> actions = new HashMap<MouseInputType, XMapPaneAction>(
+ MouseInputType.values().length);
+
+ /**
+ * A reference to the {@link XMapPane} that the {@link XMapPaneAction}s will
+ * be performed on.
+ */
+ private final XMapPane xMapPane;
+
public XMapPaneMouseListener(XMapPane xMapPane) {
+ this.xMapPane = xMapPane;
}
+ @Override
+ public void performMouseClicked(MouseEvent mEv) {
+
+ MouseInputType key = null;
+
+ switch (mEv.getButton()) {
+ case MouseEvent.BUTTON1:
+ key = MouseInputType.LClick;
+ break;
+ case MouseEvent.BUTTON3:
+ key = MouseInputType.RClick;
+ break;
+ default:
+ return;
+ }
+
+ XMapPaneAction action = actions.get(key);
+
+ if (action == null) {
+ // No action has been defined for this - no problem
+ return;
+ }
+
+ // Calculate the coordinates in the map's CRS
+ DirectPosition2D coord = XMapPane.getMapCoordinatesFromEvent(mEv);
+
+ /** Call the XMapPaneAction */
+ if (coord != null)
+ action.performClick(xMapPane, mEv, coord);
+ }
+
+ @Override
+ public void performMouseDragged(MouseEvent mEv) {
+
+ MouseInputType key = null;
+
+ switch (mEv.getButton()) {
+ case MouseEvent.BUTTON1:
+ key = MouseInputType.LDrag;
+ break;
+ case MouseEvent.BUTTON3:
+ key = MouseInputType.RDrag;
+ break;
+ default:
+ return;
+ }
+
+ XMapPaneAction action = actions.get(key);
+
+ if (action == null) {
+ // No action has been defined for this - no problem
+ return;
+ }
+
+ // Calculate the coordinates in the map's CRS
+ DirectPosition2D endCoord = XMapPane.getMapCoordinatesFromEvent(mEv);
+
+ DirectPosition2D startCoord = getDragStartCoord();
+
+ /** Call the XMapPaneAction */
+ if (startCoord != null && endCoord != null)
+ action.performDragging(xMapPane, mEv, dragStartPos, startCoord,
+ endCoord);
+ }
+
+ @Override
+ public void performMouseWheelMoved(MouseWheelEvent mEv) {
+
+ XMapPaneAction action = actions.get(MouseInputType.Wheel);
+
+ if (action == null)
+ return;
+
+ // Calculate the coordinates in the map's CRS
+ DirectPosition2D coord = XMapPane.getMapCoordinatesFromEvent(mEv);
+
+ /** Call the XMapPaneAction */
+ if (coord != null)
+ action.performWheel(xMapPane, mEv, coord);
+ }
+
+ public void performMouseReleased(MouseEvent mEv) {
+
+ if (mEv.getPoint().equals(dragStartPos))
+ performMouseClicked(mEv);
+
+ MouseInputType key;
+ switch (mEv.getButton()) {
+ case MouseEvent.BUTTON1:
+ key = MouseInputType.LWin;
+ break;
+ case MouseEvent.BUTTON3:
+ key = MouseInputType.RWin;
+ break;
+ default:
+ return;
+ }
+
+ XMapPaneAction action = actions.get(key);
+
+ if (action == null)
+ return;
+
+ // Transform window coordinates to MapContext coordinates
+
+ // Calculate the coordinates in the map's CRS
+ DirectPosition2D endCoord = XMapPane.getMapCoordinatesFromEvent(mEv);
+ if (endCoord == null)
+ return;
+
+ action.performWindow(xMapPane, mEv, dragStartPos, getDragStartCoord(),
+ endCoord);
+ }
+
+ /**
+ * Returns the drag position in map CRS
+ */
+ public DirectPosition2D getDragStartCoord() {
+
+ final AffineTransform at = xMapPane.getScreenToWorld();
+ if (at == null)
+ return null;
+
+ Point2D transformed = at.transform(dragStartPos, null);
+ DirectPosition2D startCoord = new DirectPosition2D(xMapPane
+ .getMapContext().getCoordinateReferenceSystem(), transformed
+ .getX(), transformed.getY());
+ return startCoord;
+ }
+
}
More information about the Schmitzm-commits
mailing list