Exemplo 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);
    }
  }
Exemplo n.º 2
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();
    }
  }
Exemplo n.º 3
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;
    }
  }
Exemplo n.º 4
0
  /**
   * Función de pintado del canvas. Pintamos un marco a la imagen para saber donde la movemos.
   *
   * <p>Para dibujar el marco alrededor del raster hacemos lo mismo que para pintar el raster
   * rotado. En realidad dibujamos un cuadrado y luego le aplicamos las transformaciones necesarias
   * para que se vea con la misma forma del raster al que representa.
   */
  public void paintComponent(Graphics g) {
    if (isMoveable && lyr != null && ptoFin != null && ptoIni != null) {
      try {
        ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
        AffineTransform at = (AffineTransform) lyr.getAffineTransform().clone();
        at.preConcatenate(vp.getAffineTransform());
        Extent ext = lyr.getFullRasterExtent();

        Point2D pt = new Point2D.Double(ext.getULX(), ext.getULY());
        vp.getAffineTransform().transform(pt, pt);
        at.inverseTransform(pt, pt);

        Point2D size = new Point2D.Double(ext.getLRX(), ext.getLRY());
        vp.getAffineTransform().transform(size, size);
        at.inverseTransform(size, size);

        double distX = ptoFin.getX() - ptoIni.getX();
        double distY = ptoFin.getY() - ptoIni.getY();
        Point2D d = new Point2D.Double(ext.getULX() + distX, ext.getULY() + distY);
        vp.getAffineTransform().transform(d, d);
        at.inverseTransform(d, d);

        // Giramos el graphics se dibuja y se vuelve a dejar como estaba
        ((Graphics2D) g).transform(at);
        g.setColor(rectangleColor);
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
        ((Graphics2D) g).setComposite(alpha);
        g.fillRect(
            (int) pt.getX() + (int) d.getX(),
            (int) pt.getY() + (int) d.getY(),
            (int) size.getX(),
            (int) size.getY());
        ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        g.drawRect(
            (int) pt.getX() + (int) d.getX(),
            (int) pt.getY() + (int) d.getY(),
            (int) size.getX(),
            (int) size.getY());
        ((Graphics2D) g).transform(at.createInverse());
      } catch (NoninvertibleTransformException e1) {
        RasterToolsUtil.messageBoxError("error_transformacion1", this, e1);
      }
    }
  }
Exemplo 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;
  }
Exemplo n.º 6
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);
        }
      }
    }
  }
Exemplo n.º 7
0
  public ViewPort getTileViewPort(ViewPort viewPort, int tileNr)
      throws NoninvertibleTransformException {
    /*
     * if(viewPortList == null) this.calcViewPort(viewPort); return
     * viewPortList[tileNr];
     */

    if (tile.length == 1) return viewPort;

    double[] dstPts = new double[8];
    double[] srcPts = getTilePts(tileNr);
    Rectangle tile = getTile(tileNr);
    // Rectangle newRect = new Rectangle((int)srcPts[0], (int)srcPts[1],
    // tileSz[0], tileSz[1]);

    mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
    double x = dstPts[0], w = dstPts[2] - dstPts[0];
    double y = dstPts[1], h = dstPts[5] - dstPts[3];
    if (w < 0) {
      x = dstPts[2];
      w = dstPts[0] - dstPts[2];
    }
    if (h < 0) {
      y = dstPts[5];
      h = dstPts[3] - dstPts[5];
    }
    Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(x, y, w, h);
    // Extent extent = new Extent(rectCuadricula);

    ViewPort vp = viewPort.cloneViewPort();
    vp.setImageSize(tile.getSize());
    // vp.setOffset(tile.getLocation());
    vp.setExtent(rectCuadricula);
    vp.setAffineTransform(mat);

    if (debug)
      System.out.println(
          "Tiling.print(): tile "
              + tileNr
              + " de "
              + getNumTiles()
              + "\n, Extent = "
              + vp.getAdjustedExtent()
              + " tile: "
              + tile);

    return vp;
  }
Exemplo n.º 8
0
  private void calcViewPort(ViewPort viewPort) throws NoninvertibleTransformException {
    viewPortList = new ViewPort[numCols * numRows];

    /*
     * if(viewPort.getImageWidth() < width && viewPort.getImageHeight() <
     * height){ viewPortList[0] = viewPort; return; }
     */

    int vpCnt = 0;

    double imgPxX = viewPort.getImageWidth();
    double dWcX = viewPort.getAdjustedExtent().getWidth();
    double tileWcW = (getTile(vpCnt).getSize().getWidth() * dWcX) / imgPxX;

    double imgPxY = viewPort.getImageHeight();
    double dWcY = viewPort.getAdjustedExtent().getHeight();
    double tileWcH = (getTile(vpCnt).getSize().getHeight() * dWcY) / imgPxY;

    viewPortList[0] = viewPort.cloneViewPort();
    viewPortList[0].setImageSize(getTile(vpCnt).getSize());
    viewPortList[0].setExtent(
        new Rectangle2D.Double(
            viewPort.getAdjustedExtent().getMinX(),
            viewPort.getAdjustedExtent().getMaxY() - tileWcH,
            tileWcW,
            tileWcH));
    viewPortList[0].setAffineTransform(mat);

    double wt = tileWcW;
    double ht = tileWcH;
    double xt = viewPort.getAdjustedExtent().getMinX();
    double yt = viewPort.getAdjustedExtent().getMaxY() - tileWcH;

    for (int stepY = 0; stepY < numRows; stepY++) {
      wt = tileWcW;
      xt = viewPort.getAdjustedExtent().getMinX();
      for (int stepX = 0; stepX < numCols; stepX++) {
        vpCnt = stepY * numCols + stepX;
        if (vpCnt > 0) {
          if (stepX > 0) xt += wt;
          if ((xt + wt) > viewPort.getAdjustedExtent().getMaxX())
            wt = Math.abs(viewPort.getAdjustedExtent().getMaxX() - xt);

          viewPortList[vpCnt] = viewPort.cloneViewPort();
          viewPortList[vpCnt].setImageSize(getTile(vpCnt).getSize());
          viewPortList[vpCnt].setExtent(new Rectangle2D.Double(xt, yt, wt, ht));
          viewPortList[vpCnt].setAffineTransform(mat);
        }
        // System.out.println("ViewPort: "+vpCnt+" "+viewPortList[vpCnt].getAdjustedExtent()+"
        // "+getTile(vpCnt).getSize());
      }
      if ((yt - ht) < viewPort.getAdjustedExtent().getMinY()) {
        ht = Math.abs(yt - viewPort.getAdjustedExtent().getMinY());
        yt = viewPort.getAdjustedExtent().getMinY();
      } else yt -= ht;
    }
  }