/**
  * Draws the block within the specified area.
  *
  * @param g2 the graphics device.
  * @param area the area.
  * @param params ignored (<code>null</code> permitted).
  * @return An {@link org.jfree.chart.block.EntityBlockResult} or <code>null</code>.
  */
 public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
   Rectangle2D target = (Rectangle2D) area.clone();
   Rectangle2D hotspot = (Rectangle2D) area.clone();
   StandardEntityCollection sec = null;
   if (params instanceof EntityBlockParams && ((EntityBlockParams) params).getGenerateEntities()) {
     sec = new StandardEntityCollection();
     sec.add(new TitleEntity(hotspot, this));
   }
   target = trimMargin(target);
   if (this.backgroundPaint != null) {
     g2.setPaint(this.backgroundPaint);
     g2.fill(target);
   }
   BlockFrame border = getFrame();
   border.draw(g2, target);
   border.getInsets().trim(target);
   BlockContainer container = this.wrapper;
   if (container == null) {
     container = this.items;
   }
   target = trimPadding(target);
   Object val = container.draw(g2, target, params);
   if (val instanceof BlockResult) {
     EntityCollection ec = ((BlockResult) val).getEntityCollection();
     if (ec != null && sec != null) {
       sec.addAll(ec);
       ((BlockResult) val).setEntityCollection(sec);
     }
   }
   return val;
 }
 protected void invalidate() {
   // Retrieve current bounds and set local vars
   Rectangle2D tmp = graph.getCellBounds(vertex.getCell());
   if (tmp != null) {
     tmp = (Rectangle2D) tmp.clone();
     graph.toScreen(tmp);
     int handlesize = graph.getHandleSize();
     int s2 = 2 * handlesize;
     double left = tmp.getX() - handlesize;
     double top = tmp.getY() - handlesize;
     double w2 = tmp.getX() + (tmp.getWidth() / 2) - handlesize;
     double h2 = tmp.getY() + (tmp.getHeight() / 2) - handlesize;
     double right = tmp.getX() + tmp.getWidth() - handlesize;
     double bottom = tmp.getY() + tmp.getHeight() - handlesize;
     // Update control point positions
     r[0].setFrame(left, top, s2, s2);
     r[1].setFrame(w2, top, s2, s2);
     r[2].setFrame(right, top, s2, s2);
     r[3].setFrame(left, h2, s2, s2);
     r[4].setFrame(right, h2, s2, s2);
     r[5].setFrame(left, bottom, s2, s2);
     r[6].setFrame(w2, bottom, s2, s2);
     r[7].setFrame(right, bottom, s2, s2);
   }
 }
 public void overlay(Graphics g) {
   if (!firstOverlayInvocation) {
     if (cachedBounds != null) {
       g.setColor(Color.black);
       Rectangle2D tmp = graph.toScreen((Rectangle2D) cachedBounds.clone());
       g.drawRect(
           (int) tmp.getX(),
           (int) tmp.getY(),
           (int) tmp.getWidth() - 2,
           (int) tmp.getHeight() - 2);
     } else if (!initialBounds.equals(vertex.getBounds())) {
       Graphics2D g2 = (Graphics2D) g;
       AffineTransform oldTransform = g2.getTransform();
       g2.scale(graph.getScale(), graph.getScale());
       graph.getUI().paintCell(g, vertex, vertex.getBounds(), true);
       if (contextViews != null) {
         for (int i = 0; i < contextViews.length; i++) {
           graph.getUI().paintCell(g, contextViews[i], contextViews[i].getBounds(), true);
         }
       }
       if (!graph.isPortsScaled()) g2.setTransform(oldTransform);
       if (portViews != null && graph.isPortsVisible()) graph.getUI().paintPorts(g, portViews);
       g2.setTransform(oldTransform);
     }
   }
   firstOverlayInvocation = false;
 }
  /**
   * Draws the graphic item within the specified area.
   *
   * @param g2 the graphics device.
   * @param area the area.
   */
  public void draw(Graphics2D g2, Rectangle2D area) {
    area = (Rectangle2D) area.clone();
    area = trimMargin(area);
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (this.lineVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);
      Shape aLine =
          ShapeUtilities.createTranslatedShape(
              getLine(), this.shapeAnchor, location.getX(), location.getY());
      g2.setPaint(this.linePaint);
      g2.setStroke(this.lineStroke);
      g2.draw(aLine);
    }

    if (this.shapeVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);

      Shape s =
          ShapeUtilities.createTranslatedShape(
              this.shape, this.shapeAnchor, location.getX(), location.getY());
      if (this.shapeFilled) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
      }
      if (this.shapeOutlineVisible) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(s);
      }
    }
  }
 /**
  * Draws a the title vertically within the specified area. This method will be called from the
  * {@link #draw(Graphics2D, Rectangle2D) draw} method.
  *
  * @param g2 the graphics device.
  * @param area the area for the title.
  */
 protected void drawVertical(Graphics2D g2, Rectangle2D area) {
   Rectangle2D titleArea = (Rectangle2D) area.clone();
   g2.setFont(this.font);
   g2.setPaint(this.paint);
   TextBlockAnchor anchor = null;
   float y = 0.0f;
   VerticalAlignment verticalAlignment = getVerticalAlignment();
   if (verticalAlignment == VerticalAlignment.TOP) {
     y = (float) titleArea.getY();
     anchor = TextBlockAnchor.TOP_RIGHT;
   } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
     y = (float) titleArea.getMaxY();
     anchor = TextBlockAnchor.TOP_LEFT;
   } else if (verticalAlignment == VerticalAlignment.CENTER) {
     y = (float) titleArea.getCenterY();
     anchor = TextBlockAnchor.TOP_CENTER;
   }
   float x = 0.0f;
   RectangleEdge position = getPosition();
   if (position == RectangleEdge.LEFT) {
     x = (float) titleArea.getX();
   } else if (position == RectangleEdge.RIGHT) {
     x = (float) titleArea.getMaxX();
     if (verticalAlignment == VerticalAlignment.TOP) {
       anchor = TextBlockAnchor.BOTTOM_RIGHT;
     } else if (verticalAlignment == VerticalAlignment.CENTER) {
       anchor = TextBlockAnchor.BOTTOM_CENTER;
     } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
       anchor = TextBlockAnchor.BOTTOM_LEFT;
     }
   }
   this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
 }
Exemple #6
0
  private Rectangle2D getContentsBoundingBox() {
    Rectangle2D bb = null;

    for (VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) {
      bb = BoundingBoxHelper.union(bb, a.getLabelBoundingBox());
    }
    if (bb == null) bb = contentsBB;
    else {
      bb.setRect(
          bb.getMinX() - frameDepth,
          bb.getMinY() - frameDepth,
          bb.getWidth() + 2.0 * frameDepth,
          bb.getHeight() + 2.0 * frameDepth);
    }

    if (bb == null) bb = new Rectangle2D.Double(0, 0, 1, 1);

    contentsBB = (Rectangle2D) bb.clone();

    return bb;
  }
Exemple #7
0
 public Rectangle2D evaluate(Rectangle2D v0, Rectangle2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   Rectangle2D value = (Rectangle2D) v0.clone();
   value.setRect(x, y, w, h);
   return value;
 }
Exemple #8
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;
 }
 /** Process mouse pressed event. */
 public void mousePressed(MouseEvent event) {
   if (!graph.isSizeable()) return;
   for (int i = 0; i < r.length; i++) {
     if (r[i].contains(event.getPoint()) && cursors[i] != 0) {
       Set set = new HashSet();
       set.add(vertex.getCell());
       contextViews = context.createTemporaryContextViews(set);
       Object[] all = AbstractCellView.getDescendantViews(new CellView[] {vertex});
       if (all.length >= org.jgraph.plaf.basic.BasicGraphUI.MAXHANDLES)
         cachedBounds = (Rectangle2D) initialBounds.clone();
       event.consume();
       index = i;
       return;
     }
   }
 }
Exemple #10
0
  /**
   * Constructs a new <code>PatternPaint</code>.
   *
   * @param node Used to generate the paint pixel pattern
   * @param patternRegion Region to which this paint is constrained
   * @param overflow controls whether or not the node can overflow the patternRegion.
   * @param patternTransform additional transform added on top of the user space to device space
   *     transform.
   */
  public PatternPaint(
      GraphicsNode node,
      Rectangle2D patternRegion,
      boolean overflow,
      AffineTransform patternTransform) {

    if (node == null) {
      throw new IllegalArgumentException();
    }

    if (patternRegion == null) {
      throw new IllegalArgumentException();
    }

    this.node = node;
    this.patternRegion = patternRegion;
    this.overflow = overflow;
    this.patternTransform = patternTransform;

    // Wrap the input node so that the primitivePaint
    // in GraphicsNodeRable takes the filter, clip....
    // into account.
    CompositeGraphicsNode comp = new CompositeGraphicsNode();
    comp.getChildren().add(node);
    Filter gnr = comp.getGraphicsNodeRable(true);

    Rectangle2D padBounds = (Rectangle2D) patternRegion.clone();

    // When there is overflow, make sure we take the full node bounds into
    // account.
    if (overflow) {
      Rectangle2D nodeBounds = comp.getBounds();
      // System.out.println("Comp Bounds    : " + nodeBounds);
      // System.out.println("Node Bounds    : " + node.getBounds(gnrc));
      padBounds.add(nodeBounds);
    }

    // System.out.println("Pattern region : " + patternRegion);
    // System.out.println("Node txf       : " + node.getTransform());
    tile = new PadRable8Bit(gnr, padBounds, PadMode.ZERO_PAD);
  }
 /**
  * Draws the block within the specified area.
  *
  * @param g2  the graphics device.
  * @param area  the area.
  * @param params  passed on to blocks within the container
  *                (<code>null</code> permitted).
  *
  * @return An instance of {@link EntityBlockResult}, or <code>null</code>.
  */
 public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
     // draw the block without collecting entities
     super.draw(g2, area, null);
     EntityBlockParams ebp = null;
     BlockResult r = new BlockResult();
     if (params instanceof EntityBlockParams) {
         ebp = (EntityBlockParams) params;
         if (ebp.getGenerateEntities()) {
             EntityCollection ec = new StandardEntityCollection();
             LegendItemEntity entity = new LegendItemEntity(
                     (Shape) area.clone());
             entity.setSeriesIndex(this.series);
             entity.setSeriesKey(this.seriesKey);
             entity.setDataset(this.dataset);
             entity.setToolTipText(getToolTipText());
             entity.setURLText(getURLText());
             ec.add(entity);
             r.setEntityCollection(ec);
         }
     }
     return r;
 }
  /**
   * Draws the legend within the specified area.
   *
   * @param g2 the graphics target (<code>null</code> not permitted).
   * @param area the drawing area (<code>null</code> not permitted).
   * @param params drawing parameters (ignored here).
   * @return <code>null</code>.
   */
  public Object draw(Graphics2D g2, Rectangle2D area, Object params) {

    Rectangle2D target = (Rectangle2D) area.clone();
    target = trimMargin(target);
    if (this.backgroundPaint != null) {
      g2.setPaint(this.backgroundPaint);
      g2.fill(target);
    }
    getFrame().draw(g2, target);
    getFrame().getInsets().trim(target);
    target = trimPadding(target);
    double base = this.axis.getLowerBound();
    double increment = this.axis.getRange().getLength() / this.subdivisions;
    Rectangle2D r = new Rectangle2D.Double();

    if (RectangleEdge.isTopOrBottom(getPosition())) {
      RectangleEdge axisEdge =
          Plot.resolveRangeAxisLocation(this.axisLocation, PlotOrientation.HORIZONTAL);
      if (axisEdge == RectangleEdge.TOP) {
        for (int i = 0; i < this.subdivisions; i++) {
          double v = base + (i * increment);
          Paint p = this.scale.getPaint(v);
          double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.TOP);
          double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.TOP);
          double ww = Math.abs(vv1 - vv0) + 1.0;
          r.setRect(Math.min(vv0, vv1), target.getMaxY() - this.stripWidth, ww, this.stripWidth);
          g2.setPaint(p);
          g2.fill(r);
        }
        if (isStripOutlineVisible()) {
          g2.setPaint(this.stripOutlinePaint);
          g2.setStroke(this.stripOutlineStroke);
          g2.draw(
              new Rectangle2D.Double(
                  target.getMinX(),
                  target.getMaxY() - this.stripWidth,
                  target.getWidth(),
                  this.stripWidth));
        }
        this.axis.draw(
            g2,
            target.getMaxY() - this.stripWidth - this.axisOffset,
            target,
            target,
            RectangleEdge.TOP,
            null);
      } else if (axisEdge == RectangleEdge.BOTTOM) {
        for (int i = 0; i < this.subdivisions; i++) {
          double v = base + (i * increment);
          Paint p = this.scale.getPaint(v);
          double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.BOTTOM);
          double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.BOTTOM);
          double ww = Math.abs(vv1 - vv0) + 1.0;
          r.setRect(Math.min(vv0, vv1), target.getMinY(), ww, this.stripWidth);
          g2.setPaint(p);
          g2.fill(r);
        }
        if (isStripOutlineVisible()) {
          g2.setPaint(this.stripOutlinePaint);
          g2.setStroke(this.stripOutlineStroke);
          g2.draw(
              new Rectangle2D.Double(
                  target.getMinX(), target.getMinY(), target.getWidth(), this.stripWidth));
        }
        this.axis.draw(
            g2,
            target.getMinY() + this.stripWidth + this.axisOffset,
            target,
            target,
            RectangleEdge.BOTTOM,
            null);
      }
    } else {
      RectangleEdge axisEdge =
          Plot.resolveRangeAxisLocation(this.axisLocation, PlotOrientation.VERTICAL);
      if (axisEdge == RectangleEdge.LEFT) {
        for (int i = 0; i < this.subdivisions; i++) {
          double v = base + (i * increment);
          Paint p = this.scale.getPaint(v);
          double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.LEFT);
          double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.LEFT);
          double hh = Math.abs(vv1 - vv0) + 1.0;
          r.setRect(target.getMaxX() - this.stripWidth, Math.min(vv0, vv1), this.stripWidth, hh);
          g2.setPaint(p);
          g2.fill(r);
        }
        if (isStripOutlineVisible()) {
          g2.setPaint(this.stripOutlinePaint);
          g2.setStroke(this.stripOutlineStroke);
          g2.draw(
              new Rectangle2D.Double(
                  target.getMaxX() - this.stripWidth,
                  target.getMinY(),
                  this.stripWidth,
                  target.getHeight()));
        }
        this.axis.draw(
            g2,
            target.getMaxX() - this.stripWidth - this.axisOffset,
            target,
            target,
            RectangleEdge.LEFT,
            null);
      } else if (axisEdge == RectangleEdge.RIGHT) {
        for (int i = 0; i < this.subdivisions; i++) {
          double v = base + (i * increment);
          Paint p = this.scale.getPaint(v);
          double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.LEFT);
          double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.LEFT);
          double hh = Math.abs(vv1 - vv0) + 1.0;
          r.setRect(target.getMinX(), Math.min(vv0, vv1), this.stripWidth, hh);
          g2.setPaint(p);
          g2.fill(r);
        }
        if (isStripOutlineVisible()) {
          g2.setPaint(this.stripOutlinePaint);
          g2.setStroke(this.stripOutlineStroke);
          g2.draw(
              new Rectangle2D.Double(
                  target.getMinX(), target.getMinY(), this.stripWidth, target.getHeight()));
        }
        this.axis.draw(
            g2,
            target.getMinX() + this.stripWidth + this.axisOffset,
            target,
            target,
            RectangleEdge.RIGHT,
            null);
      }
    }
    return null;
  }
Exemple #13
0
 /** Returns the pattern region. */
 public Rectangle2D getPatternRect() {
   return (Rectangle2D) patternRegion.clone();
 }
Exemple #14
0
 /** The region to which this mask applies */
 public Rectangle2D getFilterRegion() {
   return (Rectangle2D) filterRegion.clone();
 }
Exemple #15
0
 /** Pass-through: returns the source's bounds */
 public Rectangle2D getBounds2D() {
   return (Rectangle2D) filterRegion.clone();
 }
 /**
  * Returns the high precision bounding box of the {@link Shape}.
  *
  * @return a {@link Rectangle2D} that precisely bounds the <code>Shape</code>.
  */
 @Override
 public Rectangle2D getBounds2D() {
   return (Rectangle2D) bounds.clone();
 }