下面列出了java.awt.Stroke#createStrokedShape ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Return a Selection for a shape. This takes into account
* <code>getStroke(scp, shapeIndex)</code> and should be consulted after
* possible matches for handles have been ruled out.
*
* @param mouseLoc
* an un-transformed mouse location (that is: this comes directly
* from a MouseEvent and is relative to the ShapeCreationPanel's
* coordinates).
*/
protected Selection getSelectedShape(ShapeCreationPanel scp,
Point2D mouseLoc) {
Shape[] shapes = scp.getDataModel().getShapes();
for (int shapeIndex = shapes.length - 1; shapeIndex >= 0; shapeIndex--) {
Stroke stroke = getStroke(scp, shapeIndex);
GeneralPath transformedShape = new GeneralPath();
transformedShape.append(shapes[shapeIndex], false);
transformedShape.transform(scp.getTransform());
// If we invoke stroke.createStrokedShape on an invalid
// shape the JVM might crash. The data model already put safeguards
// in to help prevent this condition, but since this involves
// crashing let's be doubly safe:
if (!ShapeUtils.isValid(transformedShape)) {
continue;
}
Shape strokedShape = stroke.createStrokedShape(transformedShape);
if (strokedShape.intersects(mouseLoc.getX() - .5,
mouseLoc.getY() - .5, 1, 1)) {
return new Selection(shapeIndex, -1, null);
}
}
return new Selection();
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
/**
* This paints an individual shape. Subclasses may override this to control
* the color/stroke of shapes.
* <p>
* The default implementation here paints a 2-pixel focus ring around a
* shape if it is the currently selected shape.
*
* @see #getStroke(ShapeCreationPanel, int)
*/
protected void paintShape(Graphics2D g, ShapeCreationPanel panel,
int shapeIndex, Shape transformedShape) {
Selection selection = panel.getSelectionModel().getSelection();
Stroke stroke = getStroke(panel, shapeIndex);
if (selection.getShapeIndex() == shapeIndex && panel.hasFocus()) {
Shape strokedShape = stroke.createStrokedShape(transformedShape);
PlafPaintUtils.paintFocus(g, strokedShape, 2);
}
g.setStroke(stroke);
g.setColor(Color.black);
g.draw(transformedShape);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
Shape getUnderlineShape(float thickness,
float x1,
float x2,
float y) {
Stroke ulStroke = getStroke(thickness);
Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
return ulStroke.createStrokedShape(line);
}
public void draw(DrawingPanel panel, Graphics g) {
if (!PerspectiveFilter.super.isEnabled()) return;
VideoPanel vidPanel = (VideoPanel)panel;
Corner[] corners = PerspectiveFilter.this.isEnabled()? outCorners: inCorners;
for (int i=0; i<4; i++) {
screenPts[i] = corners[i].getScreenPosition(vidPanel);
transform.setToTranslation(screenPts[i].getX(), screenPts[i].getY());
Shape s = corners[i]==selectedCorner? selectionShape: cornerShape;
Stroke sk = corners[i]==selectedCorner? stroke: cornerStroke;
hitShapes[i] = transform.createTransformedShape(s);
drawShapes[i] = sk.createStrokedShape(hitShapes[i]);
}
path.reset();
path.moveTo((float)screenPts[0].getX(), (float)screenPts[0].getY());
path.lineTo((float)screenPts[1].getX(), (float)screenPts[1].getY());
path.lineTo((float)screenPts[2].getX(), (float)screenPts[2].getY());
path.lineTo((float)screenPts[3].getX(), (float)screenPts[3].getY());
path.closePath();
drawShapes[4] = stroke.createStrokedShape(path);
Graphics2D g2 = (Graphics2D)g;
Color gcolor = g2.getColor();
g2.setColor(color);
Font gfont = g.getFont();
g2.setFont(font);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
for (int i=0; i< drawShapes.length; i++) {
g2.fill(drawShapes[i]);
}
for (int i=0; i<textLayouts.length; i++) {
p.setLocation(screenPts[i].getX()-4-font.getSize(), screenPts[i].getY()-6);
textLayouts[i].draw(g2, p.x, p.y);
}
g2.setFont(gfont);
g2.setColor(gcolor);
}
private static void testStrokedShapes() {
final Stroke stroke = new BasicStroke();
final Path2D.Double path = new Path2D.Double();
Shape s;
// Check filtering NaN values:
path.reset();
path.moveTo(100, NaN);
path.lineTo(NaN, 100);
path.lineTo(NaN, NaN);
path.quadTo(NaN, 100, NaN, 100);
path.quadTo(100, NaN, 100, NaN);
path.quadTo(NaN, NaN, NaN, NaN);
path.curveTo(NaN, 100, NaN, 100, NaN, 100);
path.curveTo(100, NaN, 100, NaN, 100, NaN);
path.curveTo(NaN, NaN, NaN, NaN, NaN, NaN);
path.closePath();
s = stroke.createStrokedShape(path);
checkEmptyPath(s);
// Check filtering +Infinity values:
path.reset();
path.moveTo(100, POSITIVE_INFINITY);
path.lineTo(POSITIVE_INFINITY, 100);
path.lineTo(POSITIVE_INFINITY, POSITIVE_INFINITY);
path.quadTo(POSITIVE_INFINITY, 100,
POSITIVE_INFINITY, 100);
path.quadTo(100, POSITIVE_INFINITY,
100, POSITIVE_INFINITY);
path.quadTo(POSITIVE_INFINITY, POSITIVE_INFINITY,
POSITIVE_INFINITY, POSITIVE_INFINITY);
path.curveTo(POSITIVE_INFINITY, 100,
POSITIVE_INFINITY, 100,
POSITIVE_INFINITY, 100);
path.curveTo(100, POSITIVE_INFINITY,
100, POSITIVE_INFINITY,
100, POSITIVE_INFINITY);
path.curveTo(POSITIVE_INFINITY, POSITIVE_INFINITY,
POSITIVE_INFINITY, POSITIVE_INFINITY,
POSITIVE_INFINITY, POSITIVE_INFINITY);
path.closePath();
s = stroke.createStrokedShape(path);
checkEmptyPath(s);
// Check filtering -Infinity values:
path.reset();
path.moveTo(100, NEGATIVE_INFINITY);
path.lineTo(NEGATIVE_INFINITY, 100);
path.lineTo(NEGATIVE_INFINITY, NEGATIVE_INFINITY);
path.quadTo(NEGATIVE_INFINITY, 100,
NEGATIVE_INFINITY, 100);
path.quadTo(100, NEGATIVE_INFINITY,
100, NEGATIVE_INFINITY);
path.quadTo(NEGATIVE_INFINITY, NEGATIVE_INFINITY,
NEGATIVE_INFINITY, NEGATIVE_INFINITY);
path.curveTo(NEGATIVE_INFINITY, 100,
NEGATIVE_INFINITY, 100,
NEGATIVE_INFINITY, 100);
path.curveTo(100, NEGATIVE_INFINITY,
100, NEGATIVE_INFINITY,
100, NEGATIVE_INFINITY);
path.curveTo(NEGATIVE_INFINITY, NEGATIVE_INFINITY,
NEGATIVE_INFINITY, NEGATIVE_INFINITY,
NEGATIVE_INFINITY, NEGATIVE_INFINITY);
path.closePath();
s = stroke.createStrokedShape(path);
checkEmptyPath(s);
}
/**
* 給定筆劃加寬度,取得物件活字外框
*
* @param rectangularArea
* 物件活字
* @param strokeWidth
* 筆劃加寬度
* @return 物件活字外框
*/
protected PlaneGeometry getBoldSurface(PlaneGeometry rectangularArea, double strokeWidth)
{
if (strokeWidth < getPrecision())
return new PlaneGeometry();
Stroke stroke = chineseCharacterTypeBolder.getStroke(strokeWidth);
return new PlaneGeometry(stroke.createStrokedShape(rectangularArea));
}