Ejemplo n.º 1
0
    /** This is where the ghost image is drawn */
    public void dragOver(final DropTargetDragEvent e) {
      if ((e == null)
          || (_raGhost == null)
          || (_ptLast == null)
          || (_ptOffset == null)
          || (_imgGhost == null)
          || (_raCueLine == null)) return;
      // Even if the mouse is not moving, this method is still invoked 10 times per second
      final Point pt = e.getLocation();
      if (pt == null) return;
      if (pt.equals(_ptLast)) return;

      // Try to determine whether the user is flicking the cursor right or left
      final int nDeltaLeftRight = pt.x - _ptLast.x;
      if (((_nLeftRight > 0) && (nDeltaLeftRight < 0))
          || ((_nLeftRight < 0) && (nDeltaLeftRight > 0))) _nLeftRight = 0;
      _nLeftRight += nDeltaLeftRight;
      _ptLast = pt;
      final Graphics2D g2 = (Graphics2D) getGraphics();
      if (g2 == null) return;

      // If a drag image is not supported by the platform, then draw my own drag image
      if (!DragSource.isDragImageSupported()) {
        JDragTree.this.paintImmediately(
            _raGhost.getBounds()); // Rub out the last ghost image and cue line
        // And remember where we are about to draw the new ghost image
        _raGhost.setRect(
            pt.x - _ptOffset.x, pt.y - _ptOffset.y, _imgGhost.getWidth(), _imgGhost.getHeight());
        g2.drawImage(
            _imgGhost,
            AffineTransform.getTranslateInstance(_raGhost.getX(), _raGhost.getY()),
            null);
      } else // Just rub out the last cue line
      JDragTree.this.paintImmediately(_raCueLine.getBounds());

      final TreePath path = getClosestPathForLocation(pt.x, pt.y);
      if (!(path == _pathLast)) {
        _nLeftRight = 0; // We've moved up or down, so reset left/right movement trend
        _pathLast = path;
        _timerHover.restart();
      }

      // In any case draw (over the ghost image if necessary) a cue line indicating where a drop
      // will occur
      final Rectangle raPath = getPathBounds(path);
      _raCueLine.setRect(0, raPath.y + (int) raPath.getHeight(), getWidth(), 2);

      g2.setColor(_colorCueLine);
      g2.fill(_raCueLine);

      // And include the cue line in the area to be rubbed out next time
      _raGhost = _raGhost.createUnion(_raCueLine);

      // Do this if you want to prohibit dropping onto the drag source
      if (path.equals(_pathSource)) e.rejectDrag();
      else e.acceptDrag(e.getDropAction());
    }
Ejemplo n.º 2
0
 public Rectangle2D getBoundingBox() {
   if (worldGeometry != null) return (Rectangle2D) worldGeometry.clone();
   Rectangle2D bbox = null;
   for (Surface child : children) {
     if (bbox == null) bbox = child.getBoundingBox();
     else bbox = bbox.createUnion(child.getBoundingBox());
   }
   return bbox;
 }
Ejemplo n.º 3
0
  /**
   * Receives notification of a change to a GraphicsNode.
   *
   * @param gnce The event object describing the GraphicsNode change.
   */
  public void changeStarted(GraphicsNodeChangeEvent gnce) {
    // System.out.println("A node has changed for: " + this);
    GraphicsNode gn = gnce.getGraphicsNode();
    WeakReference gnWRef = gn.getWeakReference();

    boolean doPut = false;
    if (dirtyNodes == null) {
      dirtyNodes = new HashMap();
      doPut = true;
    } else if (!dirtyNodes.containsKey(gnWRef)) doPut = true;

    if (doPut) {
      AffineTransform at = gn.getTransform();
      if (at != null) at = (AffineTransform) at.clone();
      else at = new AffineTransform();
      dirtyNodes.put(gnWRef, at);
    }

    GraphicsNode chngSrc = gnce.getChangeSrc();
    Rectangle2D rgn = null;
    if (chngSrc != null) {
      // A child node is moving in the tree so assign it's dirty
      // regions to this node before it moves.
      Rectangle2D drgn = getNodeDirtyRegion(chngSrc);
      if (drgn != null) rgn = new ChngSrcRect(drgn);
    } else {
      // Otherwise just use gn's current region.
      rgn = gn.getBounds();
    }
    // Add this dirty region to any existing dirty region.
    Rectangle2D r2d = (Rectangle2D) fromBounds.remove(gnWRef);
    if (rgn != null) {
      if ((r2d != null) && (r2d != NULL_RECT)) {
        // System.err.println("GN: " + gn);
        // System.err.println("R2d: " + r2d);
        // System.err.println("Rgn: " + rgn);
        r2d = r2d.createUnion(rgn);
        // System.err.println("Union: " + r2d);
      } else r2d = rgn;
    }

    // if ((gn instanceof CompositeGraphicsNode) &&
    //     (r2d.getWidth() > 200)) {
    //     new Exception("Adding Large: " + gn).printStackTrace();
    // }

    // Store the bounds for the future.
    if (r2d == null) r2d = NULL_RECT;
    fromBounds.put(gnWRef, r2d);
  }
Ejemplo n.º 4
0
 /**
  * Performs the layout with no constraint, so the content size is determined by the bounds of the
  * shape and/or line drawn to represent the series.
  *
  * @param g2 the graphics device.
  * @return The content size.
  */
 protected ArrangeResult arrangeNN(Graphics2D g2, ArrangeParams params) {
   Rectangle2D contentSize = new Rectangle2D.Double();
   if (this.line != null) {
     contentSize.setRect(this.line.getBounds2D());
   }
   if (this.shape != null) {
     contentSize = contentSize.createUnion(this.shape.getBounds2D());
   }
   ArrangeResult result = params.getRecyclableResult();
   if (result != null) {
     result.setSize(contentSize.getWidth(), contentSize.getHeight());
   } else {
     result = new ArrangeResult(contentSize.getWidth(), contentSize.getHeight(), null);
   }
   return result;
 }
Ejemplo n.º 5
0
  /** Synchronizes bounding box with the model ; */
  protected void syncBounds() {
    PicText te = (PicText) element;
    // [pending] Il faut tenir compte de la rotation !

    Rectangle2D latexBB =
        null; // BB relative to latex dimensions (including rotation) (without frame)
    Rectangle2D textLayoutBB =
        null; // BB relative to textLayout dimensions (including rotation) (without frame)
    Rectangle2D textBB = null; // BB of the text (including rotation), without frame

    if (areDimensionsComputed) { // compute latexBB
      Rectangle2D nonRotated =
          new Rectangle2D.Double(
              te.getLeftX(), te.getBottomY(), te.getWidth(), te.getHeight() + te.getDepth());
      AffineTransform tr =
          new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
      tr.setToIdentity(); // reset
      PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
      tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
      latexBB = tr.createTransformedShape(nonRotated).getBounds2D();
    }

    if (image == null) { // compute textLayoutBB
      Rectangle2D nonRotated = textLayout.getBounds();
      textLayoutBB = text2ModelTr.createTransformedShape(nonRotated).getBounds2D();
    }

    // use textLayoutBB or latexBB or their union
    if (image != null) textBB = latexBB;
    else {
      if (!areDimensionsComputed) textBB = textLayoutBB;
      else {
        textBB = latexBB.createUnion(textLayoutBB);
      }
    }

    // union with frame BB
    if (te.isFramed()) {
      super.syncBounds(); // update bounds of the frame if necessary
      Rectangle2D.union(super.bounds, textBB, this.bounds);
    } else this.bounds = textBB;
  }
Ejemplo n.º 6
0
  protected ArrangeResult arrangeFF(
      Graphics2D g2, double fixedWidth, double fixedHeight, ArrangeParams params) {

    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
      contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
      contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    // TODO: compare the contentSize to the required fixed size
    // and possibly log the problems
    ArrangeResult result = params.getRecyclableResult();
    if (result != null) {
      result.setSize(fixedWidth, fixedHeight);
    } else {
      result = new ArrangeResult(fixedWidth, fixedHeight, null);
    }
    return result;
  }
Ejemplo n.º 7
0
  /**
   * This returns the dirty region for gn in the coordinate system given by <code>at</code>.
   *
   * @param gn Node tree to return dirty region for.
   * @param at Affine transform to coordinate space to accumulate dirty regions in.
   */
  public Rectangle2D getNodeDirtyRegion(GraphicsNode gn, AffineTransform at) {
    WeakReference gnWRef = gn.getWeakReference();
    AffineTransform nat = (AffineTransform) dirtyNodes.get(gnWRef);
    if (nat == null) nat = gn.getTransform();
    if (nat != null) {
      at = new AffineTransform(at);
      at.concatenate(nat);
    }

    Filter f = gn.getFilter();
    Rectangle2D ret = null;
    if (gn instanceof CompositeGraphicsNode) {
      CompositeGraphicsNode cgn = (CompositeGraphicsNode) gn;
      Iterator iter = cgn.iterator();

      while (iter.hasNext()) {
        GraphicsNode childGN = (GraphicsNode) iter.next();
        Rectangle2D r2d = getNodeDirtyRegion(childGN, at);
        if (r2d != null) {
          if (f != null) {
            // If we have a filter and a change region
            // Update our full filter extents.
            Shape s = at.createTransformedShape(f.getBounds2D());
            ret = s.getBounds2D();
            break;
          }
          if ((ret == null) || (ret == NULL_RECT)) ret = r2d;
          else ret = ret.createUnion(r2d);
        }
      }
    } else {
      ret = (Rectangle2D) fromBounds.remove(gnWRef);
      if (ret == null) {
        if (f != null) ret = f.getBounds2D();
        else ret = gn.getBounds();
      } else if (ret == NULL_RECT) ret = null;
      if (ret != null) ret = at.createTransformedShape(ret).getBounds2D();
    }
    return ret;
  }
Ejemplo n.º 8
0
 private Rectangle2D addClipAreas(Rectangle2D c1, Rectangle2D c2) {
   if (c1 == null) return c2;
   if (c2 == null) return c1;
   return c1.createUnion(c2);
 }