📄 plotlayer.java
字号:
* could return the delegate from this method instead. * * @return The object to receive <code>MapMouseEvent</code> s or * null if this layer isn't interested in * <code>MapMouseEvent</code> s */ public MapMouseListener getMapMouseListener() { return this; } public Component getGUI() { if (pal == null) { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { int index = Integer.parseInt(e.getActionCommand(), 10); switch (index) { case 0: if (show_plot_) hidePlot(); else showPlot(); break; default: throw new RuntimeException("argh!"); } } }; pal = PaletteHelper.createCheckbox("Plot Control", new String[] { "Show Temperature Plot" }, new boolean[] { show_plot_ }, al); } return pal; } //---------------------------------------------------------------------- // MapMouseListener interface implementation //---------------------------------------------------------------------- /** * Indicates which mouse modes should send events to this * <code>Layer</code>. * * @return String[] of mouse mode names * * @see com.bbn.openmap.event.MapMouseListener * @see com.bbn.openmap.MouseDelegator */ public String[] getMouseModeServiceList() { return new String[] { SelectMouseMode.modeID }; } //graphic position variables when moving the plot graphic private int prevX, prevY; private boolean grabbed_plot_graphics_ = false; /** * Called whenever the mouse is pressed by the user and one of the * requested mouse modes is active. * * @param e the press event * @return true if event was consumed (handled), false otherwise * @see #getMouseModeServiceList */ public boolean mousePressed(MouseEvent e) { if (show_plot_ && graph != null) { int x = e.getX(); int y = e.getY(); if ((x >= plotX) && (x <= plotX + plotWidth) && (y >= plotY) && (y <= plotY + plotWidth)) { grabbed_plot_graphics_ = true; // grab the location prevX = x; prevY = y; } } return false; } /** * Called whenever the mouse is released by the user and one of * the requested mouse modes is active. * * @param e the release event * @return true if event was consumed (handled), false otherwise * @see #getMouseModeServiceList */ public boolean mouseReleased(MouseEvent e) { grabbed_plot_graphics_ = false; return false; } /** * Called whenever the mouse is clicked by the user and one of the * requested mouse modes is active. * * @param e the click event * @return true if event was consumed (handled), false otherwise * @see #getMouseModeServiceList */ public boolean mouseClicked(MouseEvent e) { // System.out.println("XY: " + e.getX() + " " + e.getY() ); if (selectedGraphic != null && !show_plot_) { switch (e.getClickCount()) { case 1: /** * One click adds the site to our list of sites to * plot. */ addSelectionToPlotList(); generatePlot(); repaint(); break; case 2: /** * Double click means generate the plot. */ // System.out.println("Saw DoubleClick!"); repaint(); break; default: break; } return true; } else { return false; } } /** * Called whenever the mouse enters this layer and one of the * requested mouse modes is active. * * @param e the enter event * @see #getMouseModeServiceList */ public void mouseEntered(MouseEvent e) {} /** * Called whenever the mouse exits this layer and one of the * requested mouse modes is active. * * @param e the exit event * @see #getMouseModeServiceList */ public void mouseExited(MouseEvent e) {} /** * Called whenever the mouse is dragged on this layer and one of * the requested mouse modes is active. * * @param e the drag event * @return true if event was consumed (handled), false otherwise * @see #getMouseModeServiceList */ public boolean mouseDragged(MouseEvent e) { if (grabbed_plot_graphics_) { int x = e.getX(); int y = e.getY(); int dx = x - prevX; int dy = y - prevY; plotX += dx; plotY += dy; prevX = x; prevY = y; graph.resize(plotX, plotY, plotWidth, plotHeight); OMGraphicList plotGraphics = graph.getPlotGraphics(); //regenerate the plot graphics plotGraphics.generate(getProjection(), true); repaint(); } return false; } /** * Called whenever the mouse is moved on this layer and one of the * requested mouse modes is active. * <p> * Tries to locate a graphic near the mouse, and if it is found, * it is highlighted and the Layer is repainted to show the * highlighting. * * @param e the move event * @return true if event was consumed (handled), false otherwise * @see #getMouseModeServiceList */ public boolean mouseMoved(MouseEvent e) { OMGraphic newSelectedGraphic; if (show_plot_ && graph != null) { newSelectedGraphic = graph.selectPoint(e.getX(), e.getY(), 4.0f); if (newSelectedGraphic != null) { String infostring = (String) (newSelectedGraphic.getAppObject()); if (infostring != null) { fireRequestInfoLine(infostring); } } else { fireRequestInfoLine(""); } } else { newSelectedGraphic = getList().selectClosest(e.getX(), e.getY(), 4.0f); if (newSelectedGraphic != null && (selectedGraphic == null || newSelectedGraphic != selectedGraphic)) { Debug.message("basic", "Making selection..."); selectedGraphic = newSelectedGraphic; //selectedGraphic.setLineColor(Color.yellow); selectedGraphic.regenerate(getProjection()); // display site info on map GLOBESite site = (GLOBESite) (newSelectedGraphic.getAppObject()); if (site != null) { fireRequestInfoLine(site.getInfo()); } repaint(); } else if (selectedGraphic != null && newSelectedGraphic == null) { // revert color of un-moused object. Debug.message("basic", "Clearing selection..."); //selectedGraphic.setLineColor(Color.red); selectedGraphic.regenerate(getProjection()); fireRequestInfoLine(""); selectedGraphic = null; repaint(); } } return true; } /** * Called whenever the mouse is moved on this layer and one of the * requested mouse modes is active, and the gesture is consumed by * another active layer. We need to deselect anything that may be * selected. * * @see #getMouseModeServiceList */ public void mouseMoved() { getList().deselectAll(); repaint(); } /** * Initializes this layer from the given properties. * * @param props the <code>Properties</code> holding settings for * this layer */ public void setProperties(String prefix, Properties props) { super.setProperties(prefix, props); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -