📄 standardmapmouseinterpreter.java
字号:
} /** * Invoked when the mouse exits a component. * * @param e MouseEvent */ public void mouseExited(MouseEvent e) { setCurrentMouseEvent(e); } // Mouse Motion Listener events /////////////////////////////// /** * Invoked when a mouse button has been pressed and is moving. * Resets the click geometry of interest to null. * * @param e MouseEvent * @return the result from mouseMoved (also called from this * method) combined with the consumeEvents setting. */ public boolean mouseDragged(MouseEvent e) { setCurrentMouseEvent(e); GeometryOfInterest goi = getClickInterest(); if (goi != null) { setClickInterest(null); } return mouseMoved(e) && consumeEvents; } /** * Invoked when the mouse has been moved. Sets the movement * geometry of interest and updates the movement timer. * * @param e MouseEvent * @return the result of updateMouseMoved() if the timer isn't * being used, or false. */ public boolean mouseMoved(MouseEvent e) { setCurrentMouseEvent(e); if ((noTimerOverOMGraphic && getMovementInterest() != null) || mouseTimerInterval <= 0) { return updateMouseMoved(e); } else { if (mouseTimer == null) { mouseTimer = new Timer(mouseTimerInterval, mouseTimerListener); mouseTimer.setRepeats(false); } mouseTimerListener.setEvent(e); mouseTimer.restart(); return false; } } protected boolean noTimerOverOMGraphic = true; /** * Set whether to ignore the timer when movement is occuring over * an OMGraphic. Sometimes unhighlight can be inappropriately * delayed when timer is enabled. */ public void setNoTimerOverOMGraphic(boolean val) { noTimerOverOMGraphic = val; } /** * Get whether the timer should be ignored when movement is * occuring over an OMGraphic. */ public boolean getNoTimerOverOMGraphic() { return noTimerOverOMGraphic; } /** * The wait interval before a mouse over event gets triggered. */ protected int mouseTimerInterval = 150; /** * Set the time interval that the mouse timer waits before calling * upateMouseMoved. A negative number or zero will disable the * timer. */ public void setMouseTimerInterval(int interval) { mouseTimerInterval = interval; } public int getMouseTimerInterval() { return mouseTimerInterval; } /** * The timer used to track the wait interval. */ protected Timer mouseTimer = null; /** * The timer listener that calls updateMouseMoved. */ protected MouseTimerListener mouseTimerListener = new MouseTimerListener(); /** * The definition of the listener that calls updateMouseMoved when * the timer goes off. */ protected class MouseTimerListener implements ActionListener { private MouseEvent event; public synchronized void setEvent(MouseEvent e) { event = e; } public synchronized void actionPerformed(ActionEvent ae) { if (event != null) { updateMouseMoved(event); } } } /** * The real mouseMoved call, called when mouseMoved is called and, * if there is a mouse timer interval set, that interval time has * passed. * * @return the consumeEvents setting of the mouse event concerns * an OMGraphic, false if it didn't. */ protected boolean updateMouseMoved(MouseEvent e) { boolean ret = false; OMGraphic omg = getGeometryUnder(e); GeometryOfInterest goi = getMovementInterest(); if (omg != null && grp != null) { // This gets called if the goi is new or if the goi // refers to a different OMGraphic as previously noted. if (goi == null || !goi.appliesTo(omg)) { if (goi != null) { mouseNotOver(goi.getGeometry()); } goi = new GeometryOfInterest(omg, e); setMovementInterest(goi); setNoTimerOverOMGraphic(!omg.shouldRenderFill()); ret = mouseOver(omg, e); } } else { if (goi != null) { mouseNotOver(goi.getGeometry()); setMovementInterest(null); } ret = mouseOver(e); } return ret && consumeEvents; } /** * Handle notification that another layer consumed a mouse moved * event. Sets movement interest to null. */ public void mouseMoved() { GeometryOfInterest goi = getMovementInterest(); if (goi != null) { mouseNotOver(goi.getGeometry()); setMovementInterest(null); } } /** * Handle a left-click on the map. Does nothing by default. * * @return false */ public boolean leftClick(MouseEvent me) { if (DEBUG) { Debug.output("leftClick(MAP) at " + me.getX() + ", " + me.getY()); } if (grp != null && grp.receivesMapEvents() && me instanceof MapMouseEvent) { return grp.leftClick((MapMouseEvent) me); } return false; } /** * Handle a left-click on an OMGraphic. Does nothing by default. * * @return true */ public boolean leftClick(OMGraphic omg, MouseEvent me) { if (DEBUG) { Debug.output("leftClick(" + omg.getClass().getName() + ") at " + me.getX() + ", " + me.getY()); } return false; } /** * Notification that the user clicked on something else other than * the provided OMGraphic that was previously left-clicked on. * Calls deselect(omg). * * @return false */ public boolean leftClickOff(OMGraphic omg, MouseEvent me) { if (DEBUG) { Debug.output("leftClickOff(" + omg.getClass().getName() + ") at " + me.getX() + ", " + me.getY()); } deselect(omg); return false; } /** * Notification that the map was right-clicked on. * * @return false */ public boolean rightClick(MouseEvent me) { if (DEBUG) { Debug.output("rightClick(MAP) at " + me.getX() + ", " + me.getY()); } if (me instanceof MapMouseEvent) { return displayPopup(grp.getItemsForMapMenu((MapMouseEvent) me), me); } return false; } /** * Notification that an OMGraphic was right-clicked on. * * @return true */ public boolean rightClick(OMGraphic omg, MouseEvent me) { if (DEBUG) { Debug.output("rightClick(" + omg.getClass().getName() + ") at " + me.getX() + ", " + me.getY()); } return displayPopup(grp.getItemsForOMGraphicMenu(omg), me); } /** * Create a popup menu from GRP requests, over the mouse event * location. * * @return true if popup was presented, false if not. */ protected boolean displayPopup(List contents, MouseEvent me) { if (DEBUG) { Debug.output("displayPopup(" + contents + ") " + me); } if (contents != null && contents.size() > 0) { JPopupMenu jpm = new JPopupMenu(); Iterator it = contents.iterator(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof java.awt.Component) { jpm.add((java.awt.Component) obj); } } jpm.show((java.awt.Component) me.getSource(), me.getX(), me.getY()); return true; } return false; } /** * Notification that the user clicked on something else other than * the provided OMGraphic that was previously right-clicked on. * * @return false */ public boolean rightClickOff(OMGraphic omg, MouseEvent me) { if (DEBUG) { Debug.output("rightClickOff(" + omg.getClass().getName() + ") at " + me.getX() + ", " + me.getY()); } return false; } /** * Notification that the mouse is not over an OMGraphic, but over * the map at some location. * * @return false */ public boolean mouseOver(MouseEvent me) { if (DEBUG) { Debug.output("mouseOver(MAP) at " + me.getX() + ", " + me.getY()); } if (grp != null && grp.receivesMapEvents() && me instanceof MapMouseEvent) { return grp.mouseOver((MapMouseEvent) me); } return false; } /** * Notification that the mouse is over an OMGraphic. Makes all the * highlight calls. * * @return true */ public boolean mouseOver(OMGraphic omg, MouseEvent me) { if (DEBUG) { Debug.output("mouseOver(" + omg.getClass().getName() + ") at " + me.getX() + ", " + me.getY()); } if (grp != null) { handleToolTip(grp.getToolTipTextFor(omg)); handleInfoLine(grp.getInfoText(omg)); if (grp.isHighlightable(omg)) { grp.highlight(omg); } } return true; } /** * Given a tool tip String, use the layer to get it displayed. */ protected void handleToolTip(String tip) { if (lastToolTip == tip) { return; } lastToolTip = tip; if (layer != null) { if (lastToolTip != null) { layer.fireRequestToolTip(lastToolTip); } else { layer.fireHideToolTip(); } } } /** * Given an information line, use the layer to get it displayed on * the InformationDelegator. */ protected void handleInfoLine(String line) { if (layer != null) { layer.fireRequestInfoLine((line == null) ? "" : line); } } /** * Notification that the mouse has moved off of an OMGraphic. */ public boolean mouseNotOver(OMGraphic omg) { if (DEBUG) { Debug.output("mouseNotOver(" + omg.getClass().getName() + ")"); } if (grp != null) { grp.unhighlight(omg); } handleToolTip(null); handleInfoLine(null); return false; } /** * Notify the GRP that the OMGraphic has been selected. Wraps the * OMGraphic in an OMGraphicList. */ public void select(OMGraphic omg) { if (grp != null && grp.isSelectable(omg)) { OMGraphicList omgl = new OMGraphicList(); omgl.add(omg); grp.select(omgl); } } /** * Notify the GRP that the OMGraphic has been deselected. Wraps * the OMGraphic in an OMGraphicList. */ public void deselect(OMGraphic omg) { if (grp != null && grp.isSelectable(omg)) { OMGraphicList omgl = new OMGraphicList(); omgl.add(omg); grp.deselect(omgl); } } /** * The last MouseEvent received, for later reference. */ protected MouseEvent currentMouseEvent; /** * Set the last MouseEvent received. */ protected void setCurrentMouseEvent(MouseEvent me) { currentMouseEvent = me; } /** * Get the last MouseEvent received. */ public MouseEvent getCurrentMouseEvent() { return currentMouseEvent; } /** * Set the GestureResponsePolicy to notify of the mouse actions * over the layer's OMGraphicList. */ public void setGRP(GestureResponsePolicy grp) { this.grp = grp; } /** * Get the GestureResponsePolicy that is being notified of the * mouse actions over the layer's OMGraphicList. */ public GestureResponsePolicy getGRP() { return grp; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -