?? mapmousesupport.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/event/MapMouseSupport.java,v $// $RCSfile: MapMouseSupport.java,v $// $Revision: 1.7.2.1 $// $Date: 2004/10/14 18:26:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.event;import java.awt.event.MouseEvent;import java.util.Iterator;import com.bbn.openmap.util.Debug;/** * This is a utility class that can be used by beans that need support * for handling MapMouseListeners and firing MapMouseEvents. You can * use an instance of this class as a member field of your bean and * delegate work to it. * <p> * You can set the behavior of how MouseEvents are propagated by * setting whether to "consume" events. If the MouseMode is consuming * events, then the event is not propagated further than the first * listener to successfully process it. Otherwise the event is * propagated to all listeners. The default is to consume events. */public class MapMouseSupport extends ListenerSupport { /** * The flag that dictates whether the events should be passed to * all the listeners or just limited to the first listener that * can deal with it. The default value is set to true, which means * the event will be consumed by the first layer that can handle * it. */ protected boolean consumeEvents = true; /** * The priority MapMouseListener will be guaranteed to receive * events that go hand in hand (pressed - released, etc.). */ protected MapMouseListener priorityListener = null; /** * Used to determine whether a release should reset the * priorityListener on a mouse release. */ protected boolean clickHappened = false; /** * A MapMouseMode that may be using the parent of this support * object as a proxy. */ protected transient MapMouseMode proxy = null; protected transient int proxyDistributionMask = 0; public final static int PROXY_DISTRIB_MOUSE_PRESSED = 1 << 0; public final static int PROXY_ACK_CONSUMED_MOUSE_PRESSED = 1 << 1; public final static int PROXY_DISTRIB_MOUSE_RELEASED = 1 << 2; public final static int PROXY_ACK_CONSUMED_MOUSE_RELEASED = 1 << 3; public final static int PROXY_DISTRIB_MOUSE_CLICKED = 1 << 4; public final static int PROXY_ACK_CONSUMED_MOUSE_CLICKED = 1 << 5; public final static int PROXY_DISTRIB_MOUSE_MOVED = 1 << 6; public final static int PROXY_ACK_CONSUMED_MOUSE_MOVED = 1 << 7; public final static int PROXY_DISTRIB_MOUSE_DRAGGED = 1 << 8; public final static int PROXY_ACK_CONSUMED_MOUSE_DRAGGED = 1 << 9; public final static int PROXY_DISTRIB_MOUSE_ENTERED = 1 << 10; public final static int PROXY_DISTRIB_MOUSE_EXITED = 1 << 11; protected boolean DEBUG = false; protected boolean DEBUG_DETAIL = false; /** * Construct a default MapMouseSupport. The default value of * consumeEvents is set to true. */ public MapMouseSupport() { this(null, true); } /** * Construct a default MapMouseSupport. The default value of * consumeEvents is set to true. * * @param mode the parent MapMouseMode to use with creating the * MapMouseEvent. */ public MapMouseSupport(MapMouseMode mode) { this(mode, true); } /** * Construct a MapMouseSupport. * * @param shouldConsumeEvents if true, events are propagated to * the first MapMouseListener that successfully processes * the event, if false, events are propagated to all * MapMouseListeners */ public MapMouseSupport(boolean shouldConsumeEvents) { this(null, shouldConsumeEvents); } /** * Construct a MapMouseSupport. * * @param mode the parent MapMouseMode to use with creating the * MapMouseEvent. * @param shouldConsumeEvents if true, events are propagated to * the first MapMouseListener that successfully processes * the event, if false, events are propagated to all * MapMouseListeners */ public MapMouseSupport(MapMouseMode mode, boolean shouldConsumeEvents) { super(mode); consumeEvents = shouldConsumeEvents; DEBUG = Debug.debugging("mousemode"); DEBUG_DETAIL = Debug.debugging("mousemodedetail"); } /** * Set the parent MapMouseMode to use in constructing * MapMouseEvents. */ public void setParentMode(MapMouseMode mode) { setSource(mode); } public MapMouseMode getParentMode() { return (MapMouseMode) getSource(); } /** * Sets how the mouse support passes out events. If the value * passed in is true, the mouse support will only pass the event * to the first listener that can respond to the event. If false, * the mouse support will pass the event on to all its listeners. * * @param shouldConsumeEvents true for limited distribution. */ public void setConsumeEvents(boolean shouldConsumeEvents) { consumeEvents = shouldConsumeEvents; } /** * Returns how the mouse support is set up to distribute events. * * @return true if only one listner gets to act on an event. */ public boolean isConsumeEvents() { return consumeEvents; } /** * Add a MapMouseListener to the listener list. * * @param listener The MapMouseListener to be added */ public void addMapMouseListener(MapMouseListener listener) { addListener(listener); } /** * Remove a MapMouseListener from the listener list. * * @param listener The MapMouseListener to be removed */ public void removeMapMouseListener(MapMouseListener listener) { removeListener(listener); } /** * Remove all MapMouseListeners from the listener list. */ public void removeAllMapMouseListeners() { removeAll(); } /** * Handle a mousePressed MouseListener event. * * @param evt MouseEvent to be handled */ public boolean fireMapMousePressed(MouseEvent evt) { if (DEBUG) { System.out.println("MapMouseSupport.fireMapMousePressed()"); } boolean consumed = false; if (DEBUG) { Debug.output(" -- has proxy (" + (proxy != null) + ") -- shift used (" + evt.isShiftDown() + ")"); } if (proxy == null || evt.isShiftDown() || (proxyDistributionMask & PROXY_DISTRIB_MOUSE_PRESSED) > 0) { evt = new MapMouseEvent(getParentMode(), evt); if (DEBUG && proxy != null && evt.isShiftDown()) { Debug.output("MMS.fireMapMousePressed(): proxy enabled, but side stepping to send event to primary listeners"); } Iterator it = iterator(); while (it.hasNext() && !consumed) { MapMouseListener target = (MapMouseListener) it.next(); consumed = target.mousePressed(evt) && consumeEvents; if (consumed) { priorityListener = target; } } } boolean ignoreConsumed = !consumed || (consumed && ((proxyDistributionMask & PROXY_ACK_CONSUMED_MOUSE_PRESSED) == 0)); if (proxy != null && ignoreConsumed && !evt.isShiftDown()) { proxy.mousePressed(evt); consumed = true; } else { if (DEBUG && evt.isShiftDown()) { Debug.output("MMS.fireMapMousePressed(): side-stepped proxy"); } } return consumed; } /** * Handle a mouseReleased MouseListener event. Checks to see if * there is a priorityListener, and will direct the event to that * listener. The priorityListener variable will be reset to null. * If there is not a priorityListener, the event is passed through * the listeners, subject to the consumeEvents mode. * * @param evt MouseEvent to be handled. */ public boolean fireMapMouseReleased(MouseEvent evt) { if (DEBUG) { Debug.output("MapMouseSupport: fireMapMouseReleased"); } boolean consumed = false; evt = new MapMouseEvent(getParentMode(), evt); if (priorityListener != null) { priorityListener.mouseReleased(evt); if (!clickHappened) { priorityListener = null; } consumed = true; } if (proxy == null || evt.isShiftDown() || (proxyDistributionMask & PROXY_DISTRIB_MOUSE_RELEASED) > 0) { Iterator it = iterator(); while (it.hasNext() && !consumed) { consumed = ((MapMouseListener) it.next()).mouseReleased(evt) && consumeEvents;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -