本文整理匯總了Java中java.awt.geom.QuadCurve2D.setCurve方法的典型用法代碼示例。如果您正苦於以下問題:Java QuadCurve2D.setCurve方法的具體用法?Java QuadCurve2D.setCurve怎麽用?Java QuadCurve2D.setCurve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.geom.QuadCurve2D
的用法示例。
在下文中一共展示了QuadCurve2D.setCurve方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCoulombIcon
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
private static ImageIcon createCoulombIcon( Color color ) {
final int w = 20;
final int h = 20;
BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
QuadCurve2D curve1 = new QuadCurve2D.Double();
QuadCurve2D curve2 = new QuadCurve2D.Double();
curve1.setCurve( 0, 4, 8, 5, 7, 16 );
curve2.setCurve( 10, 16, 11, 5, 17, 4 );
g2.setStroke( ICON_STROKE );
g2.setPaint( color );
g2.draw( curve1 );
g2.draw( curve2 );
return new ImageIcon( bi );
}
示例2: createHarmonicOscillatorIcon
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
private static ImageIcon createHarmonicOscillatorIcon( Color color ) {
final int w = 17;
final int h = 20;
BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
QuadCurve2D curve = new QuadCurve2D.Double();
curve.setCurve( 0, 3, w/2, 30, w, 3 );
g2.setStroke( ICON_STROKE );
g2.setPaint( color );
g2.draw( curve );
return new ImageIcon( bi );
}
示例3: curveOverlap
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
public SortedSet<Shape> curveOverlap(double x) {
QuadCurve2D tcurve = new QuadCurve2D.Double();
tcurve.setCurve(x, 0, x, 0, x, 0);
SortedSet overlap = new TreeSet(arcsByStart.headSet(tcurve, true));
overlap.retainAll(arcsByEnd.tailSet(tcurve, true));
return overlap;
}
示例4: decorateAttributedString
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
public void decorateAttributedString(Graphics2D g2, AttributedString attributedWord, ChangeableAttributedString newAttrString) {
Color oldColor = g2.getColor();
Composite oldComp = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(alphaCompositeType));
for (int j = 0; j < attributedWord.getIterator().getEndIndex(); j++) {
g2.setColor(linesColorGenerator.getNextColor());
Rectangle2D bounds = newAttrString.getBounds(j).getFrame();
for (int i = 0; i < numberOfLinesPerGlyph.intValue(); i++) {
// double circleSize = circleMaxSize * (1 + myRandom.nextDouble()) / 2;
double circlex = bounds.getMinX() + bounds.getWidth() * 0.7 * myRandom.nextDouble();
double circley = bounds.getMinY() - bounds.getHeight() * 0.5
* myRandom.nextDouble();
//width
double width = 5 + myRandom.nextInt(25);
//length
double length = 5 + myRandom.nextInt(25);
//get an angle between 0 and PI
double angle = Math.PI * myRandom.nextDouble();
//rotation and translation where the character is
AffineTransform transformation = new AffineTransform(Math.cos(angle), -Math
.sin(angle), Math.sin(angle), Math.cos(angle), circlex, circley);
QuadCurve2D q = new QuadCurve2D.Double();
// start poitn , control point, finhsi point
q.setCurve(0, 0, (length / 2.0) + 15.0 * myRandom.nextDouble()
* (myRandom.nextBoolean() ? -1 : 1), (width / 2.0) + 15.0
* myRandom.nextDouble() * (myRandom.nextBoolean() ? -1 : 1), length, width);
g2.setStroke(new BasicStroke(2 + myRandom.nextInt(4)));
g2.draw(transformation.createTransformedShape(q));
}
}
g2.setComposite(oldComp);
g2.setColor(oldColor);
}
示例5: getNormalEdgeShape
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
private Shape getNormalEdgeShape()
{
Line line = getConnectionPoints();
QuadCurve2D curve = new QuadCurve2D.Float();
curve.setCurve(Conversions.toPoint2D(line.getPoint1()), getControlPoint(),
Conversions.toPoint2D(line.getPoint2()));
return curve;
}
示例6: evaluate
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
public QuadCurve2D evaluate(QuadCurve2D v0, QuadCurve2D v1,
float fraction)
{
double x1 = v0.getX1() + ((v1.getX1() - v0.getX1()) * fraction);
double y1 = v0.getY1() + ((v1.getY1() - v0.getY1()) * fraction);
double x2 = v0.getX2() + ((v1.getX2() - v0.getX2()) * fraction);
double y2 = v0.getY2() + ((v1.getY2() - v0.getY2()) * fraction);
double ctrlx = v0.getCtrlX() +
((v1.getCtrlX() - v0.getCtrlX()) * fraction);
double ctrly = v0.getCtrlY() +
((v1.getCtrlY() - v0.getCtrlY()) * fraction);
QuadCurve2D value = (QuadCurve2D)v0.clone();
value.setCurve(x1, y1, ctrlx, ctrly, x2, y2);
return value;
}
示例7: evaluate
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
@RegionEffects("reads All")
public QuadCurve2D evaluate(QuadCurve2D v0, QuadCurve2D v1, double fraction) {
double x1 = v0.getX1() + ((v1.getX1() - v0.getX1()) * fraction);
double y1 = v0.getY1() + ((v1.getY1() - v0.getY1()) * fraction);
double x2 = v0.getX2() + ((v1.getX2() - v0.getX2()) * fraction);
double y2 = v0.getY2() + ((v1.getY2() - v0.getY2()) * fraction);
double ctrlx = v0.getCtrlX() + ((v1.getCtrlX() - v0.getCtrlX()) * fraction);
double ctrly = v0.getCtrlY() + ((v1.getCtrlY() - v0.getCtrlY()) * fraction);
QuadCurve2D value = (QuadCurve2D) v0.clone();
value.setCurve(x1, y1, ctrlx, ctrly, x2, y2);
return value;
}
示例8: addLengthLines
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
private void addLengthLines(int startSpace, int endSpace, boolean horseOffset) {
// If there is no jump to show, don't bother computing a jump.
if (startSpace == endSpace) {
return;
}
// Get end points of the curve
int [] p1coords = getHorsePoint(startSpace, horseOffset);
int [] p2coords = getHorsePoint(endSpace, horseOffset);
Point p1 = new Point (p1coords[0], p1coords[1]);
Point p2 = new Point (p2coords[0], p2coords[1]);
// Compute control point location for the curve
int dx = (p2coords[0] - p1coords[0]) / 2;
int dy = (p2coords[1] - p1coords[1]) / 2;
Point cp = new Point (p1coords[0] + dx, p1coords[1] + dy);
double ratio = (HORSE_VERT_OFFSET / Math.sqrt((dx * dx) + (dy * dy)));
if (dx > 0) {
cp.translate((int) (dy * ratio), (int) (-dx * ratio));
} else {
cp.translate((int) (-dy * ratio), (int) (dx * ratio));
}
// Create the curve
QuadCurve2D q = new QuadCurve2D.Float();
q.setCurve(p1, cp, p2);
// Add it to the lines
lines.add(new JumpingTrackOrnament(q));
// Add a dot at the end.
lines.add(new JumpingTrackOrnament(p2coords));
}
示例9: drawLeftLabel
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Draws a section label on the left side of the pie chart.
*
* @param g2 the graphics device.
* @param state the state.
* @param record the label record.
*/
protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
PieLabelRecord record) {
double anchorX = state.getLinkArea().getMinX();
double targetX = anchorX - record.getGap();
double targetY = record.getAllocatedY();
if (this.labelLinksVisible) {
double theta = record.getAngle();
double linkX = state.getPieCenterX() + Math.cos(theta)
* state.getPieWRadius() * record.getLinkPercent();
double linkY = state.getPieCenterY() - Math.sin(theta)
* state.getPieHRadius() * record.getLinkPercent();
double elbowX = state.getPieCenterX() + Math.cos(theta)
* state.getLinkArea().getWidth() / 2.0;
double elbowY = state.getPieCenterY() - Math.sin(theta)
* state.getLinkArea().getHeight() / 2.0;
double anchorY = elbowY;
g2.setPaint(this.labelLinkPaint);
g2.setStroke(this.labelLinkStroke);
PieLabelLinkStyle style = getLabelLinkStyle();
if (style.equals(PieLabelLinkStyle.STANDARD)) {
g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
}
else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
QuadCurve2D q = new QuadCurve2D.Float();
q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
g2.draw(q);
g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
}
else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
CubicCurve2D c = new CubicCurve2D .Float();
c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
linkX, linkY);
g2.draw(c);
}
}
TextBox tb = record.getLabel();
tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT);
}
示例10: drawRightLabel
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Draws a section label on the right side of the pie chart.
*
* @param g2 the graphics device.
* @param state the state.
* @param record the label record.
*/
protected void drawRightLabel(Graphics2D g2, PiePlotState state,
PieLabelRecord record) {
double anchorX = state.getLinkArea().getMaxX();
double targetX = anchorX + record.getGap();
double targetY = record.getAllocatedY();
if (this.labelLinksVisible) {
double theta = record.getAngle();
double linkX = state.getPieCenterX() + Math.cos(theta)
* state.getPieWRadius() * record.getLinkPercent();
double linkY = state.getPieCenterY() - Math.sin(theta)
* state.getPieHRadius() * record.getLinkPercent();
double elbowX = state.getPieCenterX() + Math.cos(theta)
* state.getLinkArea().getWidth() / 2.0;
double elbowY = state.getPieCenterY() - Math.sin(theta)
* state.getLinkArea().getHeight() / 2.0;
double anchorY = elbowY;
g2.setPaint(this.labelLinkPaint);
g2.setStroke(this.labelLinkStroke);
PieLabelLinkStyle style = getLabelLinkStyle();
if (style.equals(PieLabelLinkStyle.STANDARD)) {
g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
}
else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
QuadCurve2D q = new QuadCurve2D.Float();
q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
g2.draw(q);
g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
}
else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
CubicCurve2D c = new CubicCurve2D .Float();
c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
linkX, linkY);
g2.draw(c);
}
}
TextBox tb = record.getLabel();
tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);
}
示例11: pasteText
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Pastes the attributed string on the backround image and return the final image. Implementation must take into
* account the fact that the text must be readable by human and non by programs
*
* @return the final image
*
* @throws CaptchaException if any exception accurs during paste routine.
*/
public BufferedImage pasteText(BufferedImage background, AttributedString attributedWord)
throws CaptchaException {
BufferedImage out = copyBackground(background);
Graphics2D g2 = pasteBackgroundAndSetTextColor(out, background);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// this attribute doesn't do anything in JDK 1.4, but maybe it will in JDK 1.5
// attributedString.addAttribute(TextAttribute.WIDTH, TextAttribute.WIDTH_EXTENDED);
// convert string into a series of glyphs we can work with
ChangeableAttributedString newAttrString = new ChangeableAttributedString(g2,
attributedWord, kerning);
// space out the glyphs with a little kerning
newAttrString.useMinimumSpacing(kerning);
// shift string to a random spot in the output imge
newAttrString.moveToRandomSpot(background);
// now draw each glyph at the appropriate spot on th eimage.
if (isManageColorPerGlyph())
newAttrString.drawString(g2, getColorGenerator());
else
newAttrString.drawString(g2);
g2.setColor(linesColorGenerator.getNextColor());
for (int j = 0; j < attributedWord.getIterator().getEndIndex(); j++) {
Rectangle2D bounds = newAttrString.getBounds(j).getFrame();
for (int i = 0; i < numberOfLinesPerGlyph.intValue(); i++) {
double circlex = bounds.getMinX() + bounds.getWidth() * 0.7 * myRandom.nextDouble();
double circley = bounds.getMinY() - bounds.getHeight() * 0.5
* myRandom.nextDouble();
//width
double width = 5 + myRandom.nextInt(25);
//length
double length = 5 + myRandom.nextInt(25);
//get an angle between 0 and PI
double angle = Math.PI * myRandom.nextDouble();
//rotation and translation where the character is
AffineTransform transformation = new AffineTransform(Math.cos(angle), -Math
.sin(angle), Math.sin(angle), Math.cos(angle), circlex, circley);
QuadCurve2D q = new QuadCurve2D.Double();
// start poitn , control point, finhsi point
q.setCurve(0, 0, (length / 2.0) + 15.0 * myRandom.nextDouble()
* (myRandom.nextBoolean() ? -1 : 1), (width / 2.0) + 15.0
* myRandom.nextDouble() * (myRandom.nextBoolean() ? -1 : 1), length, width);
g2.setStroke(new BasicStroke(2 + myRandom.nextInt(4)));
g2.draw(transformation.createTransformedShape(q));
}
}
g2.dispose();
return out;
}
示例12: drawCurve
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Link the two points with the given curve, by subdividing, until the length
* of each segment is lower or equal to AWTShape.LINE_FLATNESS. The last curve
* painted is returned in the last argument, <code>curve</code>. It can
* be used to know the real endpoint, ad the edge of the second curve.
*
* @param gl GL object to draw
* @param center1 start point
* @param center2 end point
* @param curve curve to follow
* @param shape1 shape at starting point
* @param shape2 shape at end point
* @param last last curve painted.
* @return
*/
public boolean drawCurve(GL2 gl, Point2D center1, Point2D center2,
QuadCurve2D curve, GLEntity shape1, GLEntity shape2, QuadCurve2D last) {
double p1X = curve.getP1().getX();
double p1Y = curve.getP1().getY();
double p2X = curve.getP2().getX();
double p2Y = curve.getP2().getY();
// different cases to handle are represented visually with the following
// convertion: [ ] represent a shape, and --- a segment.
// [ ---]--- is a segment with starting point inside a shape, end endpoint
// outside...
if (shape1.contains(p2X, p2Y)) {
// [ -- ] [ ]
// first shape contains end point. don't do anything.
return false;
}
if (shape2.contains(p1X, p1Y)) {
// [ ] [ -- ]
// second shape contains starting point. don't do anything
return false;
}
if (shape1.contains(p1X, p1Y)) {
if (shape2.contains(p2X, p2Y)) {
// [ ---]----[--- ]
// subdivide to conquer...
return divideAndDraw(gl, center1, center2, curve, shape1, shape2,
last);
} else {
// [ ---]-- [ ]
if (new Vec2(curve.getP2()).minus(new Vec2(curve.getP1())).length()
< AWTShape.lineFlatness) {
// segment small enough
AWTShape.draw(gl, curve);
return false;
} else {
// segment to large. divide it.
divideAndDraw(gl, center1, center2, curve, shape1, shape2, last);
return false;
}
}
} else if (shape2.contains(p2X, p2Y)) {
// [ ] --[--- ]
if (new Vec2(curve.getP2()).minus(new Vec2(curve.getP1())).length()
< AWTShape.lineFlatness) {
// segment small enough
last.setCurve(curve);
AWTShape.draw(gl, curve);
return true;
} else {
// segment to large. divide it.
return divideAndDraw(gl, center1, center2, curve, shape1, shape2,
last);
}
} else {
// [ ] -- [ ]
AWTShape.draw(gl, curve);
}
return false;
}
示例13: drawLink
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Draw a link between 2 notes
*
* @see #getLinkPoints(TwoNotesLink) calculates the best link curve
*/
protected void drawLink(Graphics2D g2, TwoNotesLink slurDef) {
Point2D[] points = null;
try {
points = getLinkPoints(slurDef);
} catch (Exception e) {
System.err.println("Exception in drawLink : "+e.getMessage());
e.printStackTrace();
}
if ((points == null) || (points.length != 3))
return;
//TODO move this in JSlurOrTie.render(g2);
JSlurOrTie jSlurDef = getJSlurOrTie(slurDef);
if (jSlurDef.isTuplet()) {
//we consider tuplet are always above notes
if (jSlurDef.getTupletControlPoint() == null) {
jSlurDef.setTupletControlPoint(new Point2D.Double(
points[START].getX()+(points[END].getX()-points[START].getX())/2,
points[START].getY()-getMetrics().getSlurAnchorYOffset()*5
));
}
points[CONTROL].setLocation(
jSlurDef.getTupletControlPoint()
);
}
// System.out.println("drawLink "+slurDef);
// System.out.println(" - start = "+points[START]);
// System.out.println(" - end = "+points[END]);
Color previousColor = g2.getColor();
boolean isAboveNotes = false;
if (points[CONTROL].getY() < points[START].getY()
&& (points[CONTROL].getY() < points[END].getY()))
isAboveNotes = true;
else if (points[CONTROL].getY() > points[START].getY()
&& (points[CONTROL].getY() > points[END].getY()))
isAboveNotes = false;
else {//problem, mark it red
g2.setColor(Color.RED);
}
GeneralPath path = new GeneralPath();
path.moveTo((float)points[START].getX(), (float)points[START].getY());
QuadCurve2D q = new QuadCurve2D.Float();
q.setCurve(
points[START],
newControl(points[START], points[CONTROL], points[END]),
points[END]);
path.append(q, true);
q = new QuadCurve2D.Float();
double slurThickness = Math.max(1.0,
getTemplate().getAttributeSize(
ScoreAttribute.SLUR_THICKNESS));
if (!isAboveNotes) {
points[CONTROL].setLocation(points[CONTROL].getX(),
points[CONTROL].getY()+slurThickness);
} else {
points[CONTROL].setLocation(points[CONTROL].getX(),
points[CONTROL].getY()-slurThickness);
}
q.setCurve(
points[END],
newControl(points[START], points[CONTROL], points[END]),
points[START]);
path.append(q, true);
g2.fill(path);
g2.draw(path);
g2.setColor(previousColor);
}
示例14: setHighlightMove
import java.awt.geom.QuadCurve2D; //導入方法依賴的package包/類
/**
* Set the highlighted move to the given one.
*
* @param move The move to make the highlighted one.
* @param playerId The player whose move is being shown. This is used
* to set the color of the line.
*/
public void setHighlightMove(Vector move, int playerId) {
highlightedMoveCurves = new Vector();
highlightedMoveColor = playerColors[playerId];
if (move != null) {
// Make the Quad Curves for the move
ListIterator iter = move.listIterator();
Point p2 = (Point) iter.next();
while (iter.hasNext()) {
// Get the logical end points of the move
Point p1 = p2;
p2 = (Point) iter.next();
// Convert them to screen points
Point sp1 = getScreenCenterFor(p1);
Point sp2 = getScreenCenterFor(p2);
// Compute the control point location for this curve.
int dx = (sp2.x - sp1.x) / 2;
int dy = (sp2.y - sp1.y) / 2;
Point cp = new Point (sp1.x + dx, sp1.y + dy);
double halfLength = Math.sqrt((dx * dx) + (dy * dy));
double ratio = (HEXAGON_SIZE / halfLength);
if (dx > 0) {
cp.translate((int) (dy * ratio), (int) (- dx * ratio));
} else {
cp.translate((int) (- dy * ratio), (int) (dx * ratio));
}
// Generate the Quad curve connecting those points
QuadCurve2D q = new QuadCurve2D.Float();
q.setCurve(sp1, cp, sp2);
// Add the curve to the vectors of curves
highlightedMoveCurves.add(q);
}
}
}