Пример #1
0
  /**
   * Register an object that wishes to receive {@code MapPaneEvent}s
   *
   * @param listener an object that implements {@code MapPaneListener}
   * @see MapPaneListener
   */
  public void addMapPaneListener(MapPaneListener listener) {
    if (listener == null) {
      throw new IllegalArgumentException(Messages.getString("arg_null_error")); // $NON-NLS-1$
    }

    listeners.add(listener);
  }
Пример #2
0
  /**
   * Register a {@linkplain MapLayerComposite} object to be receive layer change events from this
   * map pane and to control layer ordering, visibility and selection.
   *
   * @param layerTable an instance of MapLayerTable
   * @throws IllegalArgumentException if layerTable is null
   */
  public void setMapLayerTable(MapLayerComposite layerTable) {
    if (layerTable == null) {
      throw new IllegalArgumentException(Messages.getString("arg_null_error")); // $NON-NLS-1$
    }

    this.layerTable = layerTable;
  }
Пример #3
0
  /**
   * Unregister the {@code MapMouseListener} object.
   *
   * @param listener the listener to remove
   * @throws IllegalArgumentException if listener is null
   */
  public void removeMouseListener(MapMouseListener listener) {
    if (listener == null) {
      throw new IllegalArgumentException(Messages.getString("arg_null_error")); // $NON-NLS-1$
    }

    toolManager.removeMouseListener(listener);
  }
Пример #4
0
/**
 * A zoom-out tool for JMapPane.
 *
 * <p>For mouse clicks, the display will be zoomed-out such that the map centre is the position of
 * the mouse click and the map width and height are calculated as:
 *
 * <pre>   {@code len = len.old * z} </pre>
 *
 * where {@code z} is the linear zoom increment (>= 1.0)
 *
 * @author Michael Bedward
 * @author Andrea Antonello (www.hydrologis.com)
 * @since 2.6
 * @source $URL$
 */
public class ZoomOutTool extends AbstractZoomTool {

  /** Tool name */
  public static final String TOOL_NAME = Messages.getString("tool_name_zoom_out");
  /** Tool tip text */
  public static final String TOOL_TIP = Messages.getString("tool_tip_zoom_out");

  private Cursor cursor;

  /**
   * Constructs a new zoom out tool. To activate the tool only on certain mouse events provide a
   * single mask, e.g. {@link SWT#BUTTON1}, or a combination of multiple SWT-masks.
   *
   * @param triggerButtonMask Mouse button which triggers the tool's activation or {@value
   *     #ANY_BUTTON} if the tool is to be triggered by any button
   */
  public ZoomOutTool(int triggerButtonMask) {
    super(triggerButtonMask);
    cursor = CursorManager.getInstance().getZoomoutCursor();
  }

  /** Constructs a new zoom out tool which is triggered by any mouse button. */
  public ZoomOutTool() {
    this(CursorTool.ANY_BUTTON);
  }

  /**
   * Zoom out by the currently set increment, with the map centred at the location (in world coords)
   * of the mouse click
   *
   * @param ev the mouse event
   */
  @Override
  public void onMouseClicked(MapMouseEvent ev) {

    if (!isTriggerMouseButton(ev)) {
      return;
    }

    Rectangle paneArea = getMapPane().getBounds();
    DirectPosition2D mapPos = ev.getMapPosition();

    double scale = getMapPane().getWorldToScreenTransform().getScaleX();
    double newScale = scale / zoom;

    DirectPosition2D corner =
        new DirectPosition2D(
            mapPos.getX() - 0.5d * paneArea.width / newScale,
            mapPos.getY() + 0.5d * paneArea.height / newScale);

    Envelope2D newMapArea = new Envelope2D();
    newMapArea.setFrameFromCenter(mapPos, corner);
    getMapPane().setDisplayArea(newMapArea);
  }

  /** Get the mouse cursor for this tool */
  @Override
  public Cursor getCursor() {
    return cursor;
  }

  public boolean canDraw() {
    return false;
  }

  public boolean canMove() {
    return false;
  }
}