java.awt.Shape#intersects ( )源码实例Demo

下面列出了java.awt.Shape#intersects ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openstock   文件: FXGraphics2D.java
/**
 * Clips to the intersection of the current clipping region and the
 * specified shape. 
 * 
 * According to the Oracle API specification, this method will accept a 
 * {@code null} argument, but there is an open bug report (since 2004) 
 * that suggests this is wrong:
 * <p>
 * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189">
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189</a>
 * 
 * In this implementation, a {@code null} argument is not permitted.
 * 
 * @param s  the clip shape ({@code null} not permitted). 
 */
@Override
public void clip(Shape s) {
    if (this.clip == null) {
        setClip(s);
        return;
    }
    Shape ts = this.transform.createTransformedShape(s);
    Shape clipNew;
    if (!ts.intersects(this.clip.getBounds2D())) {
        clipNew = new Rectangle2D.Double();
    } else {
        Area a1 = new Area(ts);
        Area a2 = new Area(this.clip);
        a1.intersect(a2);
        clipNew = new Path2D.Double(a1);
    }
    this.clip = clipNew;
    if (!this.clippingDisabled) {
        this.gc.save();
        this.saveCount++;
        shapeToPath(this.clip);
        this.gc.clip();
    }
}
 
源代码2 项目: pumpernickel   文件: CompositePaintable.java
private void paint(Graphics2D g, double dx, double dy) {
	if (bounds == null)
		refreshBounds();

	for (int a = 0; a < paintables.size(); a++) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.translate(dx, dy);
		g2.transform(transforms.get(a));
		Paintable paintable = paintables.get(a);
		Shape clip = g2.getClip();
		if (clip == null
				|| clip.intersects(0, 0, paintable.getWidth(),
						paintable.getHeight())) {
			// g2.setColor(new Color( Color.HSBtoRGB( (float)(a)/.7f, .2f,
			// 1f) ));
			// g2.fillRect(0, 0, paintables.get(a).getWidth(),
			// paintables.get(a).getHeight() );
			paintable.paint(g2);
		}
		g2.dispose();
	}
}
 
源代码3 项目: rcrs-server   文件: ScreenTransform.java
/**
   Find out if a shape is inside the current view bounds.
   @param s The shape to test.
   @return True if any part of the shape is inside the current view bounds, false otherwise.
*/
public boolean isInView(Shape s) {
    if (s == null) {
        return false;
    }
    return s.intersects(viewBounds);
}
 
源代码4 项目: rcrs-server   文件: Layer.java
public Object[] getObjectsInArea(Rectangle2D r) {
	Collection result = new ArrayList();
	for (Iterator it = objects.iterator();it.hasNext();) {
		Object next = it.next();
		Shape s = (Shape)shapes.get(next);
		if (s!=null && s.intersects(r)) {
			result.add(next);
		}
	}
	return result.toArray();
}
 
源代码5 项目: ontopia   文件: TMAbstractEdge.java
@Override
public double distFromPoint(double x, double y) {
  Shape shape = getDisplayShape();
  if (shape == null)
    return super.distFromPoint(x, y);
  
  // Bit of a hack, but just because TG does something rather
  // stupid here anyway.
  if (shape.intersects(x -2, y-2, 4, 4))
    return 0;
  return 1000;
}
 
源代码6 项目: openstock   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
源代码7 项目: openstock   文件: XYShapeRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
源代码8 项目: opensim-gui   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method 
 * draws the shapes which mark the item positions. If <code>entities</code> 
 * is not <code>null</code> it will be populated with entity information.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the data is being drawn.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
                                 XYDataset dataset,
                                 int pass, int series, int item,
                                 ValueAxis domainAxis, 
                                 Rectangle2D dataArea,
                                 ValueAxis rangeAxis, 
                                 CrosshairState crosshairState,
                                 EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, 
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, 
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        double xx = transX1;
        double yy = transY1;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY1;
            yy = transX1;
        }          
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, 
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, 
            rangeAxisIndex, transX1, transY1, plot.getOrientation());

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, entityArea, dataset, series, item, transX1, 
                transY1);
    }
}
 
源代码9 项目: ramus   文件: HTMLPrintable.java
private boolean printView(final Graphics2D graphics2D,
                          final Shape allocation, final View view) {
    boolean pageExists = false;
    final Rectangle clipRectangle = new Rectangle(0, 0, (int) (pageFormat
            .getImageableWidth() / SCALE), (int) clientHeight);
    Shape childAllocation;
    View childView;

    if (view.getViewCount() > 0) {
        for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i, allocation);
            if (childAllocation != null) {
                childView = view.getView(i);
                if (printView(graphics2D, childAllocation, childView)) {
                    pageExists = true;
                }
            }
        }
    } else {
        if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {

            if (allocation.getBounds().getHeight() > clipRectangle
                    .getHeight()
                    && allocation.intersects(clipRectangle)) {
                paintView(graphics2D, view, allocation);
                pageExists = true;
            } else {
                if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                    if (allocation.getBounds().getMaxY() <= clipRectangle
                            .getMaxY()) {
                        paintView(graphics2D, view, allocation);
                        pageExists = true;

                    } else {
                        if (allocation.getBounds().getY() < pageEndY) {
                            pageEndY = allocation.getBounds().getY();
                        }
                    }
                }
            }
        }
    }
    return pageExists;
}
 
源代码10 项目: Spark   文件: ChatPrinter.java
private boolean printView(Graphics2D graphics2D, Shape allocation,
                              View view) {
        boolean pageExists = false;
        Rectangle clipRectangle = graphics2D.getClipBounds();
        Shape childAllocation;
        View childView;

        if (view.getViewCount() > 0) {
            for (int i = 0; i < view.getViewCount(); i++) {
                childAllocation = view.getChildAllocation(i, allocation);
                if (childAllocation != null) {
                    childView = view.getView(i);
                    if (printView(graphics2D, childAllocation, childView)) {
                        pageExists = true;
                    }
                }
            }
        }
        else {
//  I
            if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
                pageExists = true;
//  II
                if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
                        (allocation.intersects(clipRectangle))) {
                    view.paint(graphics2D, allocation);
                }
                else {
//  III
                    if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                        if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
                            view.paint(graphics2D, allocation);
                        }
                        else {
//  IV
                            if (allocation.getBounds().getY() < pageEndY) {
                                pageEndY = allocation.getBounds().getY();
                            }
                        }
                    }
                }
            }
        }
        return pageExists;
    }
 
源代码11 项目: ccu-historian   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
源代码12 项目: ccu-historian   文件: XYShapeRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
源代码13 项目: astor   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param selected  is the data item selected?
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawShape2(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, int pass, int series, int item,
        boolean selected, ValueAxis domainAxis, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item, selected);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item, selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item,
                            selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.setStroke(getItemOutlineStroke(series, item, selected));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item, selected)) {
        drawItemLabel(g2, orientation, dataset, series, item, selected, 
                xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null 
            && ShapeUtilities.isPointInRect(xx, yy, dataArea)) {
        addEntity(entities, entityArea, dataset, series, item, selected,
                xx, yy);
    }
}
 
源代码14 项目: buffer_bci   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
源代码15 项目: ECG-Viewer   文件: XYShapeRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
源代码16 项目: SIMVA-SoS   文件: XYShapeRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
/**
 * Draws the block representing the specified item.
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the state.
 * @param dataArea
 *            the data area.
 * @param info
 *            the plot rendering info.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the x-axis.
 * @param rangeAxis
 *            the y-axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index.
 * @param item
 *            the item index.
 * @param crosshairState
 *            the crosshair state.
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
		XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
		CrosshairState crosshairState, int pass) {

	Shape hotspot = null;
	EntityCollection entities = null;
	if (info != null) {
		entities = info.getOwner().getEntityCollection();
	}

	double x = dataset.getXValue(series, item);
	double y = dataset.getYValue(series, item);
	double colorValue = ((XYZDataset) dataset).getZValue(series, item);
	double normalized = (colorValue - minColor) / (maxColor - minColor);

	if (Double.isNaN(x) || Double.isNaN(y)) {
		// can't draw anything
		return;
	}

	double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
	double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());

	PlotOrientation orientation = plot.getOrientation();

	Shape shape = getItemShape(series, item);
	if (orientation == PlotOrientation.HORIZONTAL) {
		shape = ShapeUtilities.createTranslatedShape(shape, transY, transX);
	} else if (orientation == PlotOrientation.VERTICAL) {
		shape = ShapeUtilities.createTranslatedShape(shape, transX, transY);
	}
	hotspot = shape;
	if (shape.intersects(dataArea)) {
		g2.setPaint(colorProvider.getPointColor(normalized));
		g2.fill(shape);
		if (getDrawOutlines()) {
			if (getUseOutlinePaint()) {
				g2.setPaint(getItemOutlinePaint(series, item));
			} else {
				g2.setPaint(getItemPaint(series, item));
			}
			g2.setStroke(getItemOutlineStroke(series, item));
			g2.draw(shape);
		}
	}

	// add an entity for the item...
	if (entities != null) {
		addEntity(entities, hotspot, dataset, series, item, transX, transY);
	}
}
 
源代码18 项目: buffer_bci   文件: XYLineAndShapeRenderer.java
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
源代码19 项目: lams   文件: SLGraphics.java
/**
 * Checks whether or not the specified <code>Shape</code> intersects
 * the specified {@link Rectangle}, which is in device
 * space. If <code>onStroke</code> is false, this method checks
 * whether or not the interior of the specified <code>Shape</code>
 * intersects the specified <code>Rectangle</code>.  If
 * <code>onStroke</code> is <code>true</code>, this method checks
 * whether or not the <code>Stroke</code> of the specified
 * <code>Shape</code> outline intersects the specified
 * <code>Rectangle</code>.
 * The rendering attributes taken into account include the
 * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
 * attributes.
 * @param rect the area in device space to check for a hit
 * @param s the <code>Shape</code> to check for a hit
 * @param onStroke flag used to choose between testing the
 * stroked or the filled shape.  If the flag is <code>true</code>, the
 * <code>Stroke</code> oultine is tested.  If the flag is
 * <code>false</code>, the filled <code>Shape</code> is tested.
 * @return <code>true</code> if there is a hit; <code>false</code>
 * otherwise.
 * @see #setStroke
 * @see #fill(Shape)
 * @see #draw(Shape)
 * @see #_transform
 * @see #setTransform
 * @see #clip
 * @see #setClip(Shape)
 */
public boolean hit(Rectangle rect,
                   Shape s,
                   boolean onStroke){
    if (onStroke) {
        s = getStroke().createStrokedShape(s);
    }

    s = getTransform().createTransformedShape(s);

    return s.intersects(rect);
}
 
源代码20 项目: osp   文件: EpsGraphics2D.java
/**
 * Checks whether or not the specified Shape intersects the specified
 * Rectangle, which is in device space.
 */
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
  return s.intersects(rect);
}