本文整理匯總了Java中java.awt.geom.Line2D.setLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Line2D.setLine方法的具體用法?Java Line2D.setLine怎麽用?Java Line2D.setLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.geom.Line2D
的用法示例。
在下文中一共展示了Line2D.setLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkLineBounds
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Check the bounds of given line with the bounds of this pane. Optionally
* calculate the new bounds in current pane's boundary.
* @param line a line for check
* @return a line with bounds inside the pane's boundary */
private Line2D checkLineBounds(Line2D line) {
Rectangle bounds = getBounds();
double startPointX;
double startPointY;
double endPointX;
double endPointY;
// check start point
startPointX = Math.max(line.getX1(), bounds.x + MIN_X);
startPointY = Math.max(line.getY1(), bounds.y + MIN_Y);
// check end point
endPointX = Math.min(line.getX2(), (bounds.x + bounds.width) - MIN_WIDTH);
endPointY = Math.min(line.getY2(), (bounds.y + bounds.height) - MIN_HEIGTH);
// set new bounds
line.setLine(startPointX, startPointY, endPointX, endPointY);
return line;
}
示例2: checkLineBounds
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Check the bounds of given line with the bounds of this pane. Optionally
* calculate the new bounds in current pane's boundary.
* @param line a line for check
* @return a line with bounds inside the pane's boundary */
private Line2D checkLineBounds(Line2D line) {
Rectangle bounds = getBounds();
double startPointX;
double startPointY;
double endPointX;
double endPointY;
// check start point
startPointX = Math.max(line.getX1(), bounds.x + MIN_X);
startPointY = Math.max(line.getY1(), bounds.y + MIN_Y);
// check end point
endPointX = Math.min(line.getX2(), (bounds.x + bounds.width));// - MIN_WIDTH);
endPointY = Math.min(line.getY2(), (bounds.y + bounds.height) - MIN_HEIGTH);
// set new bounds
line.setLine(startPointX, startPointY, endPointX, endPointY);
return line;
}
示例3: paintComponent
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the sample.
*
* @param g the graphics device.
*/
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
Dimension size = getSize();
Insets insets = getInsets();
double ww = size.getWidth() - insets.left - insets.right;
double hh = size.getHeight() - insets.top - insets.bottom;
g2.setStroke(new BasicStroke(1.0f));
double y1 = insets.top;
double y2 = y1 + hh;
double xx = insets.left;
Line2D line = new Line2D.Double();
int count = 0;
while (xx <= insets.left + ww) {
count++;
line.setLine(xx, y1, xx, y2);
g2.setPaint(this.palette.getColor(count));
g2.draw(line);
xx += 1;
}
}
示例4: drawNeedle
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
Point2D rotate, double angle) {
Line2D shape = new Line2D.Double();
double x = plotArea.getMinX() + (plotArea.getWidth() / 2);
shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY());
Shape s = shape;
if ((rotate != null) && (angle != 0)) {
/// we have rotation
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
s = getTransform().createTransformedShape(s);
}
defaultDisplay(g2, s);
}
示例5: convertBoundsAndSetDropLine
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
* is over this root pane. After covert a given line is set to drop glass pane.
* @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
int x1 = (int) line.getX1();
int x2 = (int) line.getX2();
int y1 = (int) line.getY1();
int y2 = (int) line.getY2();
Point p1 = SwingUtilities.convertPoint(tree, x1, y1, tree.getRootPane());
Point p2 = SwingUtilities.convertPoint(tree, x2, y2, tree.getRootPane());
line.setLine(p1, p2);
if( null != dropPane )
dropPane.setDropLine(line);
}
示例6: convertBoundsAndSetDropLine
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
* is over this root pane. After covert a given line is set to drop glass pane.
* @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
int x1 = (int) line.getX1();
int x2 = (int) line.getX2();
int y1 = (int) line.getY1();
int y2 = (int) line.getY2();
Point p1 = SwingUtilities.convertPoint(table, x1, y1, table.getRootPane());
Point p2 = SwingUtilities.convertPoint(table, x2, y2, table.getRootPane());
line.setLine(p1, p2);
dropPane.setDropLine(line);
}
示例7: draw
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the border by filling in the reserved space (in black).
*
* @param g2 the graphics device.
* @param area the area.
*/
public void draw(Graphics2D g2, Rectangle2D area) {
double w = area.getWidth();
double h = area.getHeight();
double t = this.insets.calculateTopInset(h);
double b = this.insets.calculateBottomInset(h);
double l = this.insets.calculateLeftInset(w);
double r = this.insets.calculateRightInset(w);
double x = area.getX();
double y = area.getY();
double x0 = x + l / 2.0;
double x1 = x + w - r / 2.0;
double y0 = y + h - b / 2.0;
double y1 = y + t / 2.0;
g2.setPaint(getPaint());
g2.setStroke(getStroke());
Line2D line = new Line2D.Double();
if (t > 0.0) {
line.setLine(x0, y1, x1, y1);
g2.draw(line);
}
if (b > 0.0) {
line.setLine(x0, y0, x1, y0);
g2.draw(line);
}
if (l > 0.0) {
line.setLine(x0, y0, x0, y1);
g2.draw(line);
}
if (r > 0.0) {
line.setLine(x1, y0, x1, y1);
g2.draw(line);
}
}
示例8: paintComponent
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the sample.
*
* @param g the graphics device.
*/
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF
);
Dimension size = getSize();
Insets insets = getInsets();
double ww = size.getWidth() - insets.left - insets.right;
double hh = size.getHeight() - insets.top - insets.bottom;
g2.setStroke(new BasicStroke(1.0f));
double y1 = insets.top;
double y2 = y1 + hh;
double xx = insets.left;
Line2D line = new Line2D.Double();
int count = 0;
while (xx <= insets.left + ww) {
count++;
line.setLine(xx, y1, xx, y2);
g2.setPaint(this.palette.getColor(count));
g2.draw(line);
xx += 1;
}
}
示例9: drawBackground
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the background for the plot.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the area inside the axes.
*/
public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {
float x0 = (float) dataArea.getX();
float x1 = x0 + (float) Math.abs(this.xOffset);
float x3 = (float) dataArea.getMaxX();
float x2 = x3 - (float) Math.abs(this.xOffset);
float y0 = (float) dataArea.getMaxY();
float y1 = y0 - (float) Math.abs(this.yOffset);
float y3 = (float) dataArea.getMinY();
float y2 = y3 + (float) Math.abs(this.yOffset);
GeneralPath clip = new GeneralPath();
clip.moveTo(x0, y0);
clip.lineTo(x0, y2);
clip.lineTo(x1, y3);
clip.lineTo(x3, y3);
clip.lineTo(x3, y1);
clip.lineTo(x2, y0);
clip.closePath();
// fill background...
Paint backgroundPaint = plot.getBackgroundPaint();
if (backgroundPaint != null) {
g2.setPaint(backgroundPaint);
g2.fill(clip);
}
GeneralPath leftWall = new GeneralPath();
leftWall.moveTo(x0, y0);
leftWall.lineTo(x0, y2);
leftWall.lineTo(x1, y3);
leftWall.lineTo(x1, y1);
leftWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(leftWall);
GeneralPath bottomWall = new GeneralPath();
bottomWall.moveTo(x0, y0);
bottomWall.lineTo(x1, y1);
bottomWall.lineTo(x3, y1);
bottomWall.lineTo(x2, y0);
bottomWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(bottomWall);
// higlight the background corners...
g2.setPaint(Color.lightGray);
Line2D corner = new Line2D.Double(x0, y0, x1, y1);
g2.draw(corner);
corner.setLine(x1, y1, x1, y3);
g2.draw(corner);
corner.setLine(x1, y1, x3, y1);
g2.draw(corner);
// draw background image, if there is one...
Image backgroundImage = plot.getBackgroundImage();
if (backgroundImage != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC,
plot.getBackgroundAlpha()));
g2.drawImage(backgroundImage,
(int) x1, (int) y3,
(int) (x3 - x1 + 1), (int) (y1 - y3 + 1),
null);
g2.setComposite(originalComposite);
}
}
示例10: drawNeedle
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
Line2D shape = new Line2D.Float();
Shape d = null;
float x = (float) (plotArea.getMinX() + (plotArea.getWidth() / 2));
float minY = (float) plotArea.getMinY();
float maxY = (float) plotArea.getMaxY();
shape.setLine(x, minY, x, maxY);
GeneralPath shape1 = new GeneralPath();
if (this.isArrowAtTop) {
shape1.moveTo(x, minY);
minY += 4 * getSize();
}
else {
shape1.moveTo(x, maxY);
minY = maxY - 4 * getSize();
}
shape1.lineTo(x + getSize(), minY);
shape1.lineTo(x - getSize(), minY);
shape1.closePath();
if ((rotate != null) && (angle != 0)) {
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
d = getTransform().createTransformedShape(shape);
}
else {
d = shape;
}
defaultDisplay(g2, d);
if ((rotate != null) && (angle != 0)) {
d = getTransform().createTransformedShape(shape1);
}
else {
d = shape1;
}
defaultDisplay(g2, d);
}
示例11: drawNeedle
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
Line2D shape = new Line2D.Double();
double x = plotArea.getMinX() + (plotArea.getWidth() / 2);
shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY());
Shape s = shape;
if ((rotate != null) && (angle != 0)) {
/// we have rotation
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
s = getTransform().createTransformedShape(s);
}
defaultDisplay(g2, s);
}
示例12: draw
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the pointer.
*
* @param g2 the graphics target.
* @param plot the plot.
* @param frame the dial's reference frame.
* @param view the dial's view.
*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
g2.setPaint(Color.blue);
g2.setStroke(new BasicStroke(1.0f));
Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame,
this.radius, this.radius);
Rectangle2D widthRect = DialPlot.rectangleByRadius(frame,
this.widthRadius, this.widthRadius);
double value = plot.getValue(this.datasetIndex);
DialScale scale = plot.getScaleForDataset(this.datasetIndex);
double angle = scale.valueToAngle(value);
Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
Point2D pt1 = arc1.getEndPoint();
Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0,
Arc2D.OPEN);
Point2D pt2 = arc2.getStartPoint();
Point2D pt3 = arc2.getEndPoint();
Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0,
Arc2D.OPEN);
Point2D pt4 = arc3.getStartPoint();
GeneralPath gp = new GeneralPath();
gp.moveTo((float) pt1.getX(), (float) pt1.getY());
gp.lineTo((float) pt2.getX(), (float) pt2.getY());
gp.lineTo((float) pt4.getX(), (float) pt4.getY());
gp.lineTo((float) pt3.getX(), (float) pt3.getY());
gp.closePath();
g2.setPaint(Color.gray);
g2.fill(gp);
g2.setPaint(Color.black);
Line2D line = new Line2D.Double(frame.getCenterX(),
frame.getCenterY(), pt1.getX(), pt1.getY());
g2.draw(line);
line.setLine(pt2, pt3);
g2.draw(line);
line.setLine(pt3, pt1);
g2.draw(line);
line.setLine(pt2, pt1);
g2.draw(line);
line.setLine(pt2, pt4);
g2.draw(line);
line.setLine(pt3, pt4);
g2.draw(line);
}
示例13: drawBackground
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the background for the plot.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the area inside the axes.
*/
public void drawBackground(Graphics2D g2, CategoryPlot plot,
Rectangle2D dataArea) {
float x0 = (float) dataArea.getX();
float x1 = x0 + (float) Math.abs(this.xOffset);
float x3 = (float) dataArea.getMaxX();
float x2 = x3 - (float) Math.abs(this.xOffset);
float y0 = (float) dataArea.getMaxY();
float y1 = y0 - (float) Math.abs(this.yOffset);
float y3 = (float) dataArea.getMinY();
float y2 = y3 + (float) Math.abs(this.yOffset);
GeneralPath clip = new GeneralPath();
clip.moveTo(x0, y0);
clip.lineTo(x0, y2);
clip.lineTo(x1, y3);
clip.lineTo(x3, y3);
clip.lineTo(x3, y1);
clip.lineTo(x2, y0);
clip.closePath();
// fill background...
Paint backgroundPaint = plot.getBackgroundPaint();
if (backgroundPaint != null) {
g2.setPaint(backgroundPaint);
g2.fill(clip);
}
GeneralPath leftWall = new GeneralPath();
leftWall.moveTo(x0, y0);
leftWall.lineTo(x0, y2);
leftWall.lineTo(x1, y3);
leftWall.lineTo(x1, y1);
leftWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(leftWall);
GeneralPath bottomWall = new GeneralPath();
bottomWall.moveTo(x0, y0);
bottomWall.lineTo(x1, y1);
bottomWall.lineTo(x3, y1);
bottomWall.lineTo(x2, y0);
bottomWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(bottomWall);
// higlight the background corners...
g2.setPaint(Color.lightGray);
Line2D corner = new Line2D.Double(x0, y0, x1, y1);
g2.draw(corner);
corner.setLine(x1, y1, x1, y3);
g2.draw(corner);
corner.setLine(x1, y1, x3, y1);
g2.draw(corner);
// draw background image, if there is one...
Image backgroundImage = plot.getBackgroundImage();
if (backgroundImage != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC, plot.getBackgroundAlpha()));
g2.drawImage(backgroundImage, (int) x1, (int) y3,
(int) (x3 - x1 + 1), (int) (y1 - y3 + 1), null);
g2.setComposite(originalComposite);
}
}
示例14: drawBackground
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the background for the plot.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the area inside the axes.
*/
public void drawBackground(Graphics2D g2, CategoryPlot plot,
Rectangle2D dataArea) {
float x0 = (float) dataArea.getX();
float x1 = x0 + (float) Math.abs(this.xOffset);
float x3 = (float) dataArea.getMaxX();
float x2 = x3 - (float) Math.abs(this.xOffset);
float y0 = (float) dataArea.getMaxY();
float y1 = y0 - (float) Math.abs(this.yOffset);
float y3 = (float) dataArea.getMinY();
float y2 = y3 + (float) Math.abs(this.yOffset);
GeneralPath clip = new GeneralPath();
clip.moveTo(x0, y0);
clip.lineTo(x0, y2);
clip.lineTo(x1, y3);
clip.lineTo(x3, y3);
clip.lineTo(x3, y1);
clip.lineTo(x2, y0);
clip.closePath();
// fill background...
Paint backgroundPaint = plot.getBackgroundPaint();
if (backgroundPaint != null) {
g2.setPaint(backgroundPaint);
g2.fill(clip);
}
GeneralPath leftWall = new GeneralPath();
leftWall.moveTo(x0, y0);
leftWall.lineTo(x0, y2);
leftWall.lineTo(x1, y3);
leftWall.lineTo(x1, y1);
leftWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(leftWall);
GeneralPath bottomWall = new GeneralPath();
bottomWall.moveTo(x0, y0);
bottomWall.lineTo(x1, y1);
bottomWall.lineTo(x3, y1);
bottomWall.lineTo(x2, y0);
bottomWall.closePath();
g2.setPaint(getWallPaint());
g2.fill(bottomWall);
// higlight the background corners...
g2.setPaint(Color.lightGray);
Line2D corner = new Line2D.Double(x0, y0, x1, y1);
g2.draw(corner);
corner.setLine(x1, y1, x1, y3);
g2.draw(corner);
corner.setLine(x1, y1, x3, y1);
g2.draw(corner);
// draw background image, if there is one...
Image backgroundImage = plot.getBackgroundImage();
if (backgroundImage != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC,
plot.getBackgroundAlpha()));
g2.drawImage(backgroundImage, (int) x1, (int) y3,
(int) (x3 - x1 + 1), (int) (y1 - y3 + 1), null);
g2.setComposite(originalComposite);
}
}
示例15: drawNeedle
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
* Draws the needle.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param rotate the rotation point.
* @param angle the angle.
*/
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
Point2D rotate, double angle) {
Line2D shape = new Line2D.Float();
Shape d = null;
float x = (float) (plotArea.getMinX() + (plotArea.getWidth() / 2));
float minY = (float) plotArea.getMinY();
float maxY = (float) plotArea.getMaxY();
shape.setLine(x, minY, x, maxY);
GeneralPath shape1 = new GeneralPath();
if (this.isArrowAtTop) {
shape1.moveTo(x, minY);
minY += 4 * getSize();
}
else {
shape1.moveTo(x, maxY);
minY = maxY - 4 * getSize();
}
shape1.lineTo(x + getSize(), minY);
shape1.lineTo(x - getSize(), minY);
shape1.closePath();
if ((rotate != null) && (angle != 0)) {
getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
d = getTransform().createTransformedShape(shape);
}
else {
d = shape;
}
defaultDisplay(g2, d);
if ((rotate != null) && (angle != 0)) {
d = getTransform().createTransformedShape(shape1);
}
else {
d = shape1;
}
defaultDisplay(g2, d);
}