[Schmitzm-commits] r633 - branches/2.0-RC2/src/schmitzm/swing/event

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 28 16:03:32 CET 2010


Author: mojays
Date: 2010-01-28 16:03:31 +0100 (Thu, 28 Jan 2010)
New Revision: 633

Modified:
   branches/2.0-RC2/src/schmitzm/swing/event/SelectiveMouseAdapter.java
Log:


Modified: branches/2.0-RC2/src/schmitzm/swing/event/SelectiveMouseAdapter.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/swing/event/SelectiveMouseAdapter.java	2010-01-28 14:35:45 UTC (rev 632)
+++ branches/2.0-RC2/src/schmitzm/swing/event/SelectiveMouseAdapter.java	2010-01-28 15:03:31 UTC (rev 633)
@@ -32,13 +32,148 @@
 
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.geom.Point2D;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  *
  */
 public class SelectiveMouseAdapter extends MouseAdapter {
+  /** Holds the activation of the several {@link MouseInputType MouseInputTypes}. */
+  protected Map<MouseInputType, Boolean> activationMap = new HashMap<MouseInputType, Boolean>();
+  /** Holds the window position a drag is started on. */
+  protected Point2D dragStartPos = null;
   
+  /**
+   * Sets whether a specific input action of the mouse adapter is
+   * enabled.
+   * @param type mouse input type 
+   * @param enabled {@code true} to enable the action
+   */
+  public void setEnabled(MouseInputType type, boolean enabled) {
+    activationMap.put(type, enabled);
+  }
+
+  /**
+   * Returns whether a specific input action of the mouse adapter is
+   * enabled.
+   * @param type mouse input type 
+   */
+  public boolean isEnabled(MouseInputType type) {
+    Boolean enabled = activationMap.get(type);  
+    return enabled != null && enabled;
+  }
+  
+  /**
+   * Returns the start point of a drag or window selection.
+   */
+  public Point2D getDragStartPoint() {
+    return dragStartPos;
+  }
+
+  /**
+   * Calls {@link #performMouseClicked(MouseEvent)} if the mouse
+   * action is enabled for the click.<br>
+   * For actions which can not be specified by {@link MouseInputType} (e.g. 3rd
+   * mouse button) the perform-method is called generally.<br>
+   * In any case the drag start position is initialized with {@code null}
+   * at the end of this method.
+   */
+  @Override
+  public final void mouseClicked(MouseEvent e) {
+    switch ( e.getButton() ) {
+      case 1: if ( isEnabled(MouseInputType.LClick) )
+                performMouseClicked(e);
+              break;
+      case 3: if ( isEnabled(MouseInputType.RClick) )
+                performMouseClicked(e);
+              break;
+      default: performMouseClicked(e);
+               break;
+    }
+    dragStartPos = null;
+  }
+
+  /**
+   * Calls {@link #performMouseDragged(MouseEvent)} if the mouse
+   * action is enabled for the drag.<br>
+   * For actions which can not be specified by {@link MouseInputType} (e.g. 3rd
+   * mouse button) the perform-method is called generally.
+   */
+  @Override
+  public final void mouseDragged(MouseEvent e) {
+    switch ( e.getButton() ) {
+      case 1: if ( isEnabled(MouseInputType.LDrag) )
+                performMouseDragged(e);
+              break;
+      case 3: if ( isEnabled(MouseInputType.RDrag) )
+                performMouseDragged(e);
+              break;
+      default: performMouseDragged(e);
+               break;
+    }
+  }
+  
+  /**
+   * Calls {@link #performMouseDragged(MouseEvent)} in any case, because
+   * enter, exit and move can not be specified by {@link MouseInputType}.
+   */
+  @Override
+  public final void mouseEntered(MouseEvent e) {
+    performMouseEntered(e);
+  }
+  
+  /**
+   * Calls {@link #performMouseExited(MouseEvent)} in any case, because
+   * enter, exit and move can not be specified by {@link MouseInputType}.
+   */
+  @Override
+  public final void mouseExited(MouseEvent e) {
+    performMouseExited(e);
+  }
+
+  /**
+   * Calls {@link #performMouseExited(MouseEvent)} in any case, because
+   * enter, exit and move can not be specified by {@link MouseInputType}.
+   */
+  @Override
+  public final void mouseMoved(MouseEvent e) {
+    performMouseMoved(e);
+  }
+
+  
+  /**
+   * Stored the current mouse location in {@link #dragStartPos}.
+   */
+  @Override
+  public final void mousePressed(MouseEvent e) {
+    dragStartPos = e.getPoint();
+    
+  }
+
+  @Override
+  public final void mouseReleased(MouseEvent e) {
+    Point2D dragEndPos = e.getPoint();
+    
+    dragStartPos = null;
+  }
+
+  @Override
+  public final void mouseWheelMoved(MouseWheelEvent e) {
+  }
+
+  
+  
+  
+  
+  
+  
+  
+  
+  
   public void performMouseClicked(MouseEvent e) {
   }
 



More information about the Schmitzm-commits mailing list