本文整理汇总了Java中java.awt.Shape.intersects方法的典型用法代码示例。如果您正苦于以下问题:Java Shape.intersects方法的具体用法?Java Shape.intersects怎么用?Java Shape.intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Shape
的用法示例。
在下文中一共展示了Shape.intersects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsPoint
import java.awt.Shape; //导入方法依赖的package包/类
public static boolean containsPoint(Edge edge, Point2D p, double scaleFactor) {
Shape edgeShape = null;
if (edge.getShape().equalsIgnoreCase(Constants.LINE_STRAIGHT)) {
edgeShape = new Line2D.Double(edge.getSource().getPosition(), edge
.getTarget().getPosition());
} else if (edge.getShape().equalsIgnoreCase(Constants.LINE_CURVED)) {
Point2D from = edge.getSource().getPosition();
Point2D to = edge.getTarget().getPosition();
double fx = from.getX();
double fy = from.getY();
double tx = to.getX();
double ty = to.getY();
double a = Utilities.calculateAngle(from, to);
double h = EdgeRenderer.QUADCURVE_CTRL_POINT.getY() / scaleFactor;
// Calculate Control Point
double cx = (fx + tx) / 2 - h * Math.sin(a);
double cy = (fy + ty) / 2 + h * Math.cos(a);
edgeShape = new QuadCurve2D.Double(fx, fy, cx, cy, tx, ty);
} else if (edge.getShape().equalsIgnoreCase(Constants.LINE_LOOP)) {
// TODO: Calculate shape for loop to enable picking of loop edges
}
// Create a small rectangular area around point, and use it
// to check for intersection with the line of the edge
double pickRadius = 1;
double px = p.getX();
double py = p.getY();
Rectangle2D pickArea = new Rectangle2D.Double(px - pickRadius, py
- pickRadius, 2 * pickRadius, 2 * pickRadius);
return edgeShape.intersects(pickArea);
}
示例2: drawItem
import java.awt.Shape; //导入方法依赖的package包/类
/**
* 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);
}
}
示例3: printView
import java.awt.Shape; //导入方法依赖的package包/类
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;
}
示例4: select
import java.awt.Shape; //导入方法依赖的package包/类
public boolean select( Shape shape, Rectangle2D shapeBounds ) {
if( shapeBounds.intersects(getBounds()) )return shape.intersects(getBounds());
return false;
}