Ejemplo n.º 1
0
 /**
  * Register itself at the given event source.
  *
  * @param eventSource The emitter of the mouse events.
  * @param lassoMode {@code true} to enable lasso mode, {@code false} to disable it.
  */
 public void register(NavigatableComponent eventSource, boolean lassoMode) {
   this.lassoMode = lassoMode;
   eventSource.addMouseListener(this);
   eventSource.addMouseMotionListener(this);
   selectionEndedListener.addPropertyChangeListener(this);
   eventSource.addPropertyChangeListener(
       "scale",
       new PropertyChangeListener() {
         @Override
         public void propertyChange(PropertyChangeEvent evt) {
           if (mousePosStart != null) {
             paintRect();
             mousePos = mousePosStart = null;
           }
         }
       });
 }
Ejemplo n.º 2
0
  /** Check the state of the keys and buttons and set the selection accordingly. */
  @Override
  public void mouseReleased(MouseEvent e) {
    if (e.getButton() != MouseEvent.BUTTON1) return;
    if (mousePos == null || mousePosStart == null) return; // injected release from outside
    // disable the selection rect
    Rectangle r;
    if (!lassoMode) {
      nc.requestClearRect();
      r = getSelectionRectangle();

      lasso = rectToPolygon(r);
    } else {
      nc.requestClearPoly();
      lasso.addPoint(mousePos.x, mousePos.y);
      r = lasso.getBounds();
    }
    mousePosStart = null;
    mousePos = null;

    if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == 0) {
      selectionEndedListener.selectionEnded(r, e);
    }
  }
Ejemplo n.º 3
0
 /**
  * Unregister itself from the given event source. If a selection rectangle is shown, hide it
  * first.
  *
  * @param eventSource The emitter of the mouse events.
  */
 public void unregister(Component eventSource) {
   eventSource.removeMouseListener(this);
   eventSource.removeMouseMotionListener(this);
   selectionEndedListener.removePropertyChangeListener(this);
 }