+
+
+ /**
+ * Respond to mouse click events
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
+ public void mouseClicked(MouseEvent inE)
+ {
+ if (_track != null && _track.getNumPoints() > 0)
+ {
+ // select point if it's a left-click
+ if (!inE.isMetaDown())
+ {
+ if (inE.getClickCount() == 1)
+ {
+ // single click
+ if (_drawMode == MODE_DEFAULT)
+ {
+ int pointIndex = _track.getNearestPointIndex(
+ _mapPosition.getXFromPixels(inE.getX(), getWidth()),
+ _mapPosition.getYFromPixels(inE.getY(), getHeight()),
+ _mapPosition.getBoundsFromPixels(CLICK_SENSITIVITY), false);
+ // Extend selection for shift-click
+ if (inE.isShiftDown()) {
+ _trackInfo.extendSelection(pointIndex);
+ }
+ else {
+ _trackInfo.selectPoint(pointIndex);
+ }
+ }
+ else if (_drawMode == MODE_DRAW_POINTS_START)
+ {
+ _app.createPoint(createPointFromClick(inE.getX(), inE.getY()));
+ _dragToX = inE.getX();
+ _dragToY = inE.getY();
+ _drawMode = MODE_DRAW_POINTS_CONT;
+ }
+ else if (_drawMode == MODE_DRAW_POINTS_CONT)
+ {
+ DataPoint point = createPointFromClick(inE.getX(), inE.getY());
+ _app.createPoint(point);
+ point.setSegmentStart(false);
+ }
+ }
+ else if (inE.getClickCount() == 2)
+ {
+ // double click
+ if (_drawMode == MODE_DEFAULT) {
+ panMap(inE.getX() - getWidth()/2, inE.getY() - getHeight()/2);
+ zoomIn();
+ }
+ else if (_drawMode == MODE_DRAW_POINTS_START || _drawMode == MODE_DRAW_POINTS_CONT) {
+ _drawMode = MODE_DEFAULT;
+ }
+ }
+ }
+ else
+ {
+ // show the popup menu for right-clicks
+ _popupMenuX = inE.getX();
+ _popupMenuY = inE.getY();
+ _popup.show(this, _popupMenuX, _popupMenuY);
+ }
+ }
+ }
+
+ /**
+ * Ignore mouse enter events
+ * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
+ */
+ public void mouseEntered(MouseEvent inE)
+ {
+ // ignore
+ }
+
+ /**
+ * Ignore mouse exited events
+ * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
+ */
+ public void mouseExited(MouseEvent inE)
+ {
+ // ignore
+ }
+
+ /**
+ * Ignore mouse pressed events
+ * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
+ */
+ public void mousePressed(MouseEvent inE)
+ {
+ // ignore
+ }
+
+ /**
+ * Respond to mouse released events
+ * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
+ */
+ public void mouseReleased(MouseEvent inE)
+ {
+ _recalculate = true;
+ if (_drawMode == MODE_ZOOM_RECT && Math.abs(_dragToX - _dragFromX) > 20
+ && Math.abs(_dragToY - _dragFromY) > 20)
+ {
+ _mapPosition.zoomToPixels(_dragFromX, _dragToX, _dragFromY, _dragToY, getWidth(), getHeight());
+ }
+ if (_drawMode == MODE_ZOOM_RECT) {
+ _drawMode = MODE_DEFAULT;
+ }
+ _dragFromX = _dragFromY = -1;
+ repaint();
+ }
+
+ /**
+ * Respond to mouse drag events
+ * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
+ */
+ public void mouseDragged(MouseEvent inE)
+ {
+ if (!inE.isMetaDown())
+ {
+ // Left mouse drag - pan map by appropriate amount
+ if (_dragFromX != -1)
+ {
+ panMap(_dragFromX - inE.getX(), _dragFromY - inE.getY());
+ _recalculate = true;
+ repaint();
+ }
+ _dragFromX = _dragToX = inE.getX();
+ _dragFromY = _dragToY = inE.getY();
+ }
+ else
+ {
+ // Right-click and drag - draw rectangle and control zoom
+ _drawMode = MODE_ZOOM_RECT;
+ if (_dragFromX == -1) {
+ _dragFromX = inE.getX();
+ _dragFromY = inE.getY();
+ }
+ _dragToX = inE.getX();
+ _dragToY = inE.getY();
+ repaint();
+ }
+ }
+
+ /**
+ * Respond to mouse move events without button pressed
+ * @param inEvent ignored
+ */
+ public void mouseMoved(MouseEvent inEvent)
+ {
+ // Ignore unless we're drawing points
+ if (_drawMode == MODE_DRAW_POINTS_CONT)
+ {
+ _dragToX = inEvent.getX();
+ _dragToY = inEvent.getY();
+ repaint();
+ }
+ }
+
+ /**
+ * Respond to status bar message from broker
+ * @param inMessage message, ignored
+ */
+ public void actionCompleted(String inMessage)
+ {
+ // ignore
+ }
+
+ /**
+ * Respond to data updated message from broker
+ * @param inUpdateType type of update
+ */
+ public void dataUpdated(byte inUpdateType)
+ {
+ _recalculate = true;
+ if ((inUpdateType & DataSubscriber.DATA_ADDED_OR_REMOVED) > 0) {
+ _checkBounds = true;
+ }
+ if ((inUpdateType & DataSubscriber.MAPSERVER_CHANGED) > 0) {
+ _tileManager.resetConfig();
+ }
+ repaint();
+ // enable or disable components
+ boolean hasData = _track.getNumPoints() > 0;
+ _topPanel.setVisible(hasData);
+ _sidePanel.setVisible(hasData);
+ // grab focus for the key presses
+ this.requestFocus();
+ }
+
+ /**
+ * Respond to key presses on the map canvas
+ * @param inE key event
+ */
+ public void keyPressed(KeyEvent inE)
+ {
+ int code = inE.getKeyCode();
+ int currPointIndex = _selection.getCurrentPointIndex();
+ // Check for Ctrl key (for Linux/Win) or meta key (Clover key for Mac)
+ if (inE.isControlDown() || inE.isMetaDown())
+ {
+ // Shift as well makes things faster
+ final int pointIncrement = inE.isShiftDown()?3:1;
+ // Check for arrow keys to zoom in and out
+ if (code == KeyEvent.VK_UP)
+ zoomIn();
+ else if (code == KeyEvent.VK_DOWN)
+ zoomOut();
+ // Key nav for next/prev point
+ else if (code == KeyEvent.VK_LEFT && currPointIndex > 0)
+ _trackInfo.incrementPointIndex(-pointIncrement);
+ else if (code == KeyEvent.VK_RIGHT)
+ _trackInfo.incrementPointIndex(pointIncrement);
+ else if (code == KeyEvent.VK_PAGE_UP)
+ _trackInfo.selectPoint(Checker.getPreviousSegmentStart(
+ _trackInfo.getTrack(), _trackInfo.getSelection().getCurrentPointIndex()));
+ else if (code == KeyEvent.VK_PAGE_DOWN)
+ _trackInfo.selectPoint(Checker.getNextSegmentStart(
+ _trackInfo.getTrack(), _trackInfo.getSelection().getCurrentPointIndex()));
+ // Check for home and end
+ else if (code == KeyEvent.VK_HOME)
+ _trackInfo.selectPoint(0);
+ else if (code == KeyEvent.VK_END)
+ _trackInfo.selectPoint(_trackInfo.getTrack().getNumPoints()-1);
+ }
+ else
+ {
+ // Check for arrow keys to pan
+ int upwardsPan = 0;
+ if (code == KeyEvent.VK_UP)
+ upwardsPan = -PAN_DISTANCE;
+ else if (code == KeyEvent.VK_DOWN)
+ upwardsPan = PAN_DISTANCE;
+ int rightwardsPan = 0;
+ if (code == KeyEvent.VK_RIGHT)
+ rightwardsPan = PAN_DISTANCE;
+ else if (code == KeyEvent.VK_LEFT)
+ rightwardsPan = -PAN_DISTANCE;
+ panMap(rightwardsPan, upwardsPan);
+ // Check for escape
+ if (code == KeyEvent.VK_ESCAPE)
+ _drawMode = MODE_DEFAULT;
+ // Check for backspace key to delete current point (delete key already handled by menu)
+ else if (code == KeyEvent.VK_BACK_SPACE && currPointIndex >= 0) {
+ _app.deleteCurrentPoint();
+ }
+ }
+ }
+
+ /**
+ * @param inE key released event, ignored
+ */
+ public void keyReleased(KeyEvent e)
+ {
+ // ignore
+ }
+
+ /**
+ * @param inE key typed event, ignored
+ */
+ public void keyTyped(KeyEvent inE)
+ {
+ // ignore
+ }
+
+ /**
+ * @param inE mouse wheel event indicating scroll direction
+ */
+ public void mouseWheelMoved(MouseWheelEvent inE)
+ {
+ int clicks = inE.getWheelRotation();
+ if (clicks < 0) {
+ panMap((inE.getX() - getWidth()/2)/2, (inE.getY() - getHeight()/2)/2);
+ zoomIn();
+ }
+ else if (clicks > 0) {
+ panMap(-(inE.getX() - getWidth()/2), -(inE.getY() - getHeight()/2));
+ zoomOut();
+ }
+ }
+
+ /**
+ * @return current map position
+ */
+ public MapPosition getMapPosition()
+ {
+ return _mapPosition;
+ }