Esempio n. 1
0
  /**
   * Cuando soltamos el botón del ratón desplazamos la imagen a la posición de destino calculando el
   * extent nuevamente.
   */
  public void mouseReleased(MouseEvent e) throws BehaviorException {
    if (!isActiveTool()) return;
    if (e.getButton() == MouseEvent.BUTTON1 && isMoveable) {
      FLyrRasterSE lyr = grBehavior.getLayer();
      if (lyr == null) return;

      ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
      ptoFin = vp.toMapPoint(e.getPoint());

      // Asignamos la nueva matriz de transformación a la capa
      AffineTransform atOld = lyr.getAffineTransform();
      AffineTransform atNew = null;

      double distX = ptoFin.getX() - ptoIni.getX();
      double distY = ptoFin.getY() - ptoIni.getY();

      // La nueva matriz de transformación es la vieja más la distancia desplazada
      atNew =
          new AffineTransform(
              atOld.getScaleX(),
              atOld.getShearY(),
              atOld.getShearX(),
              atOld.getScaleY(),
              atOld.getTranslateX() + distX,
              atOld.getTranslateY() + distY);
      lyr.setAffineTransform(atNew);

      grBehavior.getMapControl().getMapContext().invalidate();
      isMoveable = false;
      super.mouseReleased(e);
    }
  }
Esempio n. 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.gvsig.fmap.tools.Listeners.PointListener#point(org.gvsig.fmap.tools
   * .Events.PointEvent) The PointEvent method bring you a point in pixel
   * coordinates. You need to transform it to world coordinates. The class to
   * do conversions is ViewPort, obtained thru the MapContext of mapCtrl.
   */
  public void point(PointEvent event) throws BehaviorException {
    com.iver.cit.gvsig.fmap.ViewPort vp = mapCtrl.getViewPort();
    Point2D pReal = vp.toMapPoint(event.getPoint());

    SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
    while (it.hasNext()) {
      FLayer aux = it.next();
      if (!aux.isActive()) continue;
      Network net = (Network) aux.getProperty("network");

      if (net != null) {

        double realTol = vp.toMapDistance(pixelTolerance);
        Point2D pReal2 =
            vp.toMapPoint(
                (int) event.getPoint().getX() + pixelTolerance,
                (int) event.getPoint().getY() + pixelTolerance);

        // if ((vp.getProjection() != null) &&
        // !(vp.getProjection().isProjected())) {
        // realTol = vp.distanceWorld(pReal, pReal2);
        // }

        GvFlag flag;
        try {
          if (mode == TO_ARC) flag = net.addFlag(pReal.getX(), pReal.getY(), realTol);
          else flag = net.addFlagToNode(pReal.getX(), pReal.getY(), realTol);
          if (flag == null) {
            JOptionPane.showMessageDialog(
                null, PluginServices.getText(this, "point_not_on_the_network"));
            return;
          }
          NetworkUtils.addGraphicFlag(mapCtrl, flag);
          mapCtrl.drawGraphics();
          PluginServices.getMainFrame().enableControls();
        } catch (GraphException e) {
          e.printStackTrace();
          NotificationManager.addError(e);
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * Esta función repinta el canvas si se está arrasrtando la imagen para poder ver el marco de
   * arrastre.
   */
  public void mouseDragged(MouseEvent e) throws BehaviorException {
    if (!isActiveTool()) return;
    if (isMoveable) {
      ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
      ptoFin = vp.toMapPoint(e.getPoint());

      // Asignación de las coordenadas temporales al dialogo
      assignTransformToDialog();

      grBehavior.getMapControl().repaint();
    }
  }
Esempio n. 4
0
  /**
   * Si no está activo el cursor por defecto capturamos el punto seleccionado en coordenadas del
   * mundo real.
   */
  public void mousePressed(MouseEvent e) throws BehaviorException {
    if (e.getButton() == MouseEvent.BUTTON1 && !defaultCursorActive) {
      setActiveTool(true);
      lyr = grBehavior.getLayer();

      if (lyr == null) return;

      ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
      ptoIni = vp.toMapPoint(e.getPoint());

      isMoveable = true;
    }
  }
Esempio n. 5
0
  /** Coloca el cursor del ratón con el icono adecuado cuando entra dentro de la imagen. */
  public boolean mouseMoved(MouseEvent e) throws BehaviorException {

    ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();

    try {
      lyr = grBehavior.getLayer();
      if (lyr == null) {
        setActiveTool(false);
        return false;
      }

      Point2D pto = vp.toMapPoint(e.getX(), e.getY());

      try {
        if (lyr.isInside(pto)) {
          grBehavior
              .getMapControl()
              .setCursor(
                  Toolkit.getDefaultToolkit()
                      .createCustomCursor(handCursor, new Point(16, 16), ""));
          defaultCursorActive = false;
          setActiveTool(true);
          return true;
        } else {
          if (!defaultCursorActive) {
            grBehavior.getMapControl().setCursor(defaultCursor);
            defaultCursorActive = true;
            setActiveTool(false);
            return false;
          }
        }
      } catch (HeadlessException e1) {
        e1.printStackTrace();
      } catch (IndexOutOfBoundsException e1) {
        e1.printStackTrace();
      }
    } catch (ClassCastException exc) {
      RasterToolsUtil.messageBoxError("error_capa_puntos", this, exc);
    }
    setActiveTool(false);
    return false;
  }