📄 omgraphichandlerlayer.java
字号:
public synchronized void setMouseEventInterpreter(MapMouseInterpreter mmi) { if (mmi instanceof StandardMapMouseInterpreter) { String[] modeList = getMouseModeIDsForEvents(); ((StandardMapMouseInterpreter) mmi).setMouseModeServiceList(modeList); ((StandardMapMouseInterpreter) mmi).setConsumeEvents(getConsumeEvents()); } if (mouseEventInterpreter != null) { // Remove handle mouseEventInterpreter.setGRP(null); } mmi.setGRP(this); mouseEventInterpreter = mmi; } /** * Get the interpreter used to field and interpret MouseEvents, * thereby calling GestureResponsePolicy methods on this layer. * This method checks to see if any mouse modes ids have been set * via the getMouseModeIDsForEvents() method, and if there were * and the interpreter hasn't been set, it will create a * StandardMapMouseInterpreter. Otherwise, it returns whatever has * been set as the interpreter, which could be null. */ public synchronized MapMouseInterpreter getMouseEventInterpreter() { if (getMouseModeIDsForEvents() != null && mouseEventInterpreter == null) { setMouseEventInterpreter(new StandardMapMouseInterpreter(this)); } return mouseEventInterpreter; } /** * Query asked from the MouseDelegator for interest in receiving * MapMouseEvents. This returns a MapMouseInterpreter that has * been told to listen for events from the MapMouseModes in * setMouseModeIDsForEvents(). */ public MapMouseListener getMapMouseListener() { MapMouseListener mml = getMouseEventInterpreter(); if (mml != null) { if (Debug.debugging("layer")) { String[] modes = mml.getMouseModeServiceList(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < modes.length; i++) { sb.append(modes[i] + ", "); } Debug.output("Layer " + getName() + " returning " + mml.getClass().getName() + " as map mouse listener that listens to: " + sb.toString()); } } return mml; } /** * A flag to tell the layer to be selfish about consuming * MouseEvents it receives. If set to true, it will consume events * so that other layers will not receive the events. If false, * lower layers will also receive events, which will let them * react too. Intended to let other layers provide information * about what the mouse is over when editing is occuring. */ public void setConsumeEvents(boolean consume) { consumeEvents = consume; if (mouseEventInterpreter instanceof StandardMapMouseInterpreter) { ((StandardMapMouseInterpreter) mouseEventInterpreter).setConsumeEvents(getConsumeEvents()); } } public boolean getConsumeEvents() { return consumeEvents; } /** * This is the important method call that determines what * MapMouseModes the interpreter for this layer responds to. The * MapMouseInterpreter calls this so it can respond to * MouseDelegator queries. You can programmatically call * setMouseModeIDsForEvents with the mode IDs to set these values, * or set the mouseModes property for this layer set to a * space-separated list of mode IDs. */ public String[] getMouseModeIDsForEvents() { return mouseModeIDs; } /** * Use this method to set which mouse modes this layer responds * to. The array should contain the mouse mode IDs. */ public void setMouseModeIDsForEvents(String[] mm) { if (Debug.debugging("layer")) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < mm.length; i++) { sb.append(mm[i] + " "); } Debug.output("For layer " + getName() + ", setting mouse modes to " + sb.toString()); } mouseModeIDs = mm; if (mouseEventInterpreter instanceof StandardMapMouseInterpreter) { ((StandardMapMouseInterpreter) mouseEventInterpreter).setMouseModeServiceList(mm); } } /** * Query asking if OMGraphic is highlightable, which means that * something in the GUI should change when the mouse is moved or * dragged over the given OMGraphic. Highlighting shows that * something could happen, or provides cursory information about * the OMGraphic. Responding true to this method may cause * getInfoText() and getToolTipTextFor() methods to be called * (depends on the MapMouseInterpetor). */ public boolean isHighlightable(OMGraphic omg) { return true; } /** * Query asking if an OMGraphic is selectable, or able to be * moved, deleted or otherwise modified. Responding true to this * method may cause select() to be called (depends on the * MapMouseInterpertor) so the meaning depends on what the layer * does in select. */ public boolean isSelectable(OMGraphic omg) { return false; } /** * A current list of select OMGraphics. */ protected OMGraphicList selectedList; /** * Retrieve the list of currently selected OMGraphics. */ public OMGraphicList getSelected() { return selectedList; } // //// Reactions /** * Fleeting change of appearance for mouse movements over an * OMGraphic. */ public void highlight(OMGraphic omg) { omg.select(); omg.generate(getProjection()); repaint(); } /** * Notification to set OMGraphic to normal appearance. */ public void unhighlight(OMGraphic omg) { omg.deselect(); omg.generate(getProjection()); repaint(); } /** * Designate a list of OMGraphics as selected. */ public void select(OMGraphicList list) { if (list != null) { Iterator it = list.iterator(); while (it.hasNext()) { if (selectedList == null) { selectedList = new OMGraphicList(); } OMGraphic omg = (OMGraphic) it.next(); if (omg instanceof OMGraphicList && !((OMGraphicList) omg).isVague()) { select((OMGraphicList) omg); } else { selectedList.add(omg); } } } } /** * Designate a list of OMGraphics as deselected. */ public void deselect(OMGraphicList list) { if (list != null) { Iterator it = list.iterator(); while (it.hasNext() && selectedList != null) { OMGraphic omg = (OMGraphic) it.next(); if (omg instanceof OMGraphicList && !((OMGraphicList) omg).isVague()) { deselect((OMGraphicList) omg); } else { selectedList.remove(omg); } } } } /** * Remove OMGraphics from the layer. */ public OMGraphicList cut(OMGraphicList omgl) { OMGraphicList list = getList(); if (list != null && omgl != null) { Iterator it = omgl.iterator(); while (it.hasNext()) { list.remove((OMGraphic) it.next()); } } return omgl; } /***************************************************************** * Return a copy of an OMGraphic. Not implemented yet. */ public OMGraphicList copy(OMGraphicList omgl) { return null; } /** * Add OMGraphics to the Layer. */ public void paste(OMGraphicList omgl) { OMGraphicList list = getList(); if (list != null && omgl != null) { Iterator it = omgl.iterator(); while (it.hasNext()) { list.add((OMGraphic) it.next()); } } } /** * If applicable, should return a short, informational string * about the OMGraphic to be displayed in the * InformationDelegator. Return null if nothing should be * displayed. */ public String getInfoText(OMGraphic omg) { return null; } /** * If applicable, should return a tool tip for the OMGraphic. * Return null if nothing should be shown. */ public String getToolTipTextFor(OMGraphic omg) { return null; } /** * Return a JMenu with contents applicable to a popup menu for a * location over the map. The popup doesn't concern any * OMGraphics, and should be presented for a click on the map * background. * * @param mme a MapMouseEvent describing the location over where * the menu items should apply, in case different options * are appropriate for different places. * @return a JMenu for the map. Return null or empty List if no * input required. */ public List getItemsForMapMenu(MapMouseEvent mme) { return null; } /** * Return a java.util.List containing input for a JMenu with * contents applicable to a popup menu for a location over an * OMGraphic. * * @return a List containing options for the given OMGraphic. * Return null or empty list if there are no options. */ public List getItemsForOMGraphicMenu(OMGraphic omg) { return null; } /** * A query from the MapMouseInterpreter wondering if the * GestureResponsePolicy wants events pertaining to mouse * movements over the map that are not over an OMGraphic. If the * GestureResponsePolicy responds true, then the mouseOver and * leftClick methods will be called on the GestureResponsePolicy * by the interpreter. There is no rightClick method that is * called, because a right click will always cause a * getItemsForMapMenu() method to be called. */ public boolean receivesMapEvents() { return false; } /** * A notification that the mouse cursor has been moved over the * map, not over any of the OMGraphics on the * GestureResponsePolicy. This only gets called if the response to * receiveMapEvents is true. * * @param mme MapMouseEvent describing the location of the mouse. * @return true of this information is to be considered consumed * and should not be passed to anybody else. */ public boolean mouseOver(MapMouseEvent mme) { return false; } /** * A notification that the mouse has been clicked with the left * mouse button on the map, and not on any of the OMGraphics. This * only gets called if the response to receiveMapEvents is true. * Right clicks on the map are always reported to the * getItemsForMapMenu method. * * @param mme MapMouseEvent describing the location of the mouse. * @return true of this information is to be considered consumed * and should not be passed to anybody else. */ public boolean leftClick(MapMouseEvent mme) { return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -