use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.
the class Path2DGrow method testGeneralPath.
static void testGeneralPath() {
echo("\n - Test(GeneralPath) ---");
test(() -> new GeneralPath());
}
use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.
the class Path2DCopyConstructor method testGeneralPath.
static void testGeneralPath() {
log("\n - Test(GeneralPath) ---");
test(() -> new GeneralPath());
}
use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.
the class TextLayout method getBlackBoxBounds.
/**
* Returns the black box bounds of the characters in the specified range.
* The black box bounds is an area consisting of the union of the bounding
* boxes of all the glyphs corresponding to the characters between start
* and limit. This area can be disjoint.
* @param firstEndpoint one end of the character range
* @param secondEndpoint the other end of the character range. Can be
* less than <code>firstEndpoint</code>.
* @return a <code>Shape</code> enclosing the black box bounds. This is
* in standard coordinates.
*/
public Shape getBlackBoxBounds(int firstEndpoint, int secondEndpoint) {
ensureCache();
if (firstEndpoint > secondEndpoint) {
int t = firstEndpoint;
firstEndpoint = secondEndpoint;
secondEndpoint = t;
}
if (firstEndpoint < 0 || secondEndpoint > characterCount) {
throw new IllegalArgumentException("Invalid range passed to TextLayout.getBlackBoxBounds()");
}
/*
* return an area that consists of the bounding boxes of all the
* characters from firstEndpoint to limit
*/
GeneralPath result = new GeneralPath(GeneralPath.WIND_NON_ZERO);
if (firstEndpoint < characterCount) {
for (int logIndex = firstEndpoint; logIndex < secondEndpoint; logIndex++) {
Rectangle2D r = textLine.getCharBounds(logIndex);
if (!r.isEmpty()) {
result.append(r, false);
}
}
}
if (dx != 0 || dy != 0) {
AffineTransform tx = AffineTransform.getTranslateInstance(dx, dy);
result = (GeneralPath) tx.createTransformedShape(result);
}
LayoutPathImpl lp = textLine.getLayoutPath();
if (lp != null) {
result = (GeneralPath) lp.mapShape(result);
}
//return new Highlight(result, false);
return result;
}
use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.
the class TextLayout method pathToShape.
private static GeneralPath pathToShape(double[] path, boolean close, LayoutPathImpl lp) {
GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD, path.length);
result.moveTo((float) path[0], (float) path[1]);
for (int i = 2; i < path.length; i += 2) {
result.lineTo((float) path[i], (float) path[i + 1]);
}
if (close) {
result.closePath();
}
if (lp != null) {
result = (GeneralPath) lp.mapShape(result);
}
return result;
}
use of java.awt.geom.GeneralPath in project JMRI by JMRI.
the class PositionablePolygon method doHandleMove.
@Override
protected boolean doHandleMove(MouseEvent event) {
if (_hitIndex >= 0 && _editor.isEditable()) {
if (_editing) {
Point pt = new Point(event.getX() - _lastX, event.getY() - _lastY);
Rectangle rect = _vertexHandles.get(_hitIndex);
rect.x += pt.x;
rect.y += pt.y;
if (_editFrame != null) {
if (event.getX() - getX() < 0) {
_editor.moveItem(this, event.getX() - getX(), 0);
} else if (isLeftMost(rect.x)) {
_editor.moveItem(this, event.getX() - _lastX, 0);
}
if (event.getY() - getY() < 0) {
_editor.moveItem(this, 0, event.getY() - getY());
} else if (isTopMost(rect.y)) {
_editor.moveItem(this, 0, event.getY() - _lastY);
}
((DrawPolygon) _editFrame).doHandleMove(_hitIndex, pt);
}
_lastX = event.getX();
_lastY = event.getY();
} else {
float deltaX = event.getX() - _lastX;
float deltaY = event.getY() - _lastY;
float width = _width;
float height = _height;
if (_height < SIZE || _width < SIZE) {
log.error("Bad size _width= " + _width + ", _height= " + _height);
}
GeneralPath path = null;
switch(_hitIndex) {
case TOP:
if (height - deltaY > SIZE) {
path = scale(1, (height - deltaY) / height);
_editor.moveItem(this, 0, (int) deltaY);
} else {
path = scale(1, SIZE / height);
_editor.moveItem(this, 0, _height - SIZE);
}
break;
case RIGHT:
path = scale(Math.max(SIZE / width, (width + deltaX) / width), 1);
break;
case BOTTOM:
path = scale(1, Math.max(SIZE / height, (height + deltaY) / height));
break;
case LEFT:
if (_width - deltaX > SIZE) {
path = scale((width - deltaX) / width, 1);
_editor.moveItem(this, (int) deltaX, 0);
} else {
path = scale(SIZE / width, 1);
_editor.moveItem(this, _width - SIZE, 0);
}
break;
default:
log.warn("Unhandled direction code: {}", _hitIndex);
}
if (path != null) {
setShape(path);
}
}
drawHandles();
repaint();
updateSize();
_lastX = event.getX();
_lastY = event.getY();
return true;
}
return false;
}
Aggregations