本文整理汇总了Java中java.awt.Graphics2D.draw方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.draw方法的具体用法?Java Graphics2D.draw怎么用?Java Graphics2D.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: plotXY
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void plotXY( Graphics2D g,
Rectangle2D bounds,
double xScale, double yScale,
int k) {
GeneralPath path = new GeneralPath();
boolean start = true;
for( int i=0 ; i<rows.size() ; i++) {
if( !plot[k][i] )continue;
double[] row = (double[])rows.get(i);
float x = (float)((row[k+1]-bounds.getX())*xScale);
float y = (float)((row[0]-bounds.getY())*yScale);
if( start ) {
path.moveTo(x,y);
start = false;
} else path.lineTo(x,y);
}
g.setColor( Color.white );
g.setStroke( new BasicStroke(3f) );
g.draw(path);
g.setColor( Color.black );
g.setStroke( new BasicStroke(1f) );
g.draw(path);
}
示例2: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the frame. This method is called by the {@link DialPlot} class,
* you shouldn't need to call it directly.
*
* @param g2 the graphics target (<code>null</code> not permitted).
* @param plot the plot (<code>null</code> not permitted).
* @param frame the frame (<code>null</code> not permitted).
* @param view the view (<code>null</code> not permitted).
*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
Shape window = getWindow(frame);
Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02,
this.radius + 0.02);
Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(),
f.getHeight());
Area area = new Area(e);
Area area2 = new Area(window);
area.subtract(area2);
g2.setPaint(this.backgroundPaint);
g2.fill(area);
g2.setStroke(this.stroke);
g2.setPaint(this.foregroundPaint);
g2.draw(window);
g2.draw(e);
}
示例3: drawArc
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws an arc.
*
* @param g2 the graphics device.
* @param area the plot area.
* @param minValue the minimum value.
* @param maxValue the maximum value.
* @param paint the paint.
* @param stroke the stroke.
*/
protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue,
double maxValue, Paint paint, Stroke stroke) {
double startAngle = valueToAngle(maxValue);
double endAngle = valueToAngle(minValue);
double extent = endAngle - startAngle;
double x = area.getX();
double y = area.getY();
double w = area.getWidth();
double h = area.getHeight();
g2.setPaint(paint);
g2.setStroke(stroke);
if (paint != null && stroke != null) {
Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle,
extent, Arc2D.OPEN);
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(arc);
}
}
示例4: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
g2d.setStroke(new BasicStroke(2f));
// clear edges, otherwise they will be in the color of the component background
if (drawRoundFrame && !c.getBackground().equals(c.getParent().getBackground())) {
Shape frame = new Rectangle2D.Float(x + 2, y + 2, width - 4, height - 4);
g2d.setPaint(c.getParent().getBackground());
g2d.draw(frame);
}
g2d.setPaint(paint);
g2d.setFont(new Font("Dialog", Font.BOLD, 21));
if (drawRoundFrame) {
Shape roundFrame = new RoundRectangle2D.Float(x + 2, y + 2, width - 4, height - 4, 10, 10);
g2d.draw(roundFrame);
}
if (number > 0) {
Shape circle = new Ellipse2D.Float(20, 20, 34, 34);
g2d.fill(circle);
g2d.setPaint(Color.WHITE);
g2d.drawString(String.valueOf(number), 29, 44);
}
if (key != null) {
g2d.setPaint(paint);
g2d.drawString(key, 60, 44);
}
g2d.dispose();
}
示例5: drawNumericalLegend
import java.awt.Graphics2D; //导入方法依赖的package包/类
/** This method can be used to draw a legend on the given graphics context. */
public void drawNumericalLegend(Graphics graphics, int width, String minColorString, String maxColorString,
String legendColumnName, int alpha) {
Graphics2D g = (Graphics2D) graphics.create();
// painting label name
g.drawString(legendColumnName, MARGIN, 15);
Rectangle2D legendNameBounds = LABEL_FONT.getStringBounds(legendColumnName, g.getFontRenderContext());
g.translate(legendNameBounds.getWidth(), 0);
// painting legend
Rectangle2D minStringBounds = LABEL_FONT.getStringBounds(minColorString, g.getFontRenderContext());
Rectangle2D maxStringBounds = LABEL_FONT.getStringBounds(maxColorString, g.getFontRenderContext());
int legendWidth = (int) (minStringBounds.getWidth() + 114 + maxStringBounds.getWidth());
int keyX = MARGIN + width / 2 - legendWidth / 2;
int keyY = (int) (MARGIN + 2 - minStringBounds.getHeight() / 2);
g.setColor(Color.black);
g.drawString(minColorString, keyX, keyY);
keyX += minStringBounds.getWidth() + 10;
for (int i = 0; i < 100; i++) {
double scaledColor = i / 100.0d;
Color lineColor = getColorProvider().getPointColor(scaledColor, alpha);
g.setColor(lineColor);
g.drawLine(keyX, keyY, keyX, keyY - 10);
keyX++;
}
g.setColor(Color.black);
Rectangle2D frame = new Rectangle2D.Double(keyX - 101, keyY - 11, 101, 11);
g.draw(frame);
keyX += 4;
g.drawString(maxColorString, keyX, keyY);
}
示例6: insertImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void insertImage(BufferedImage source, String imgPath,
boolean needCompress) throws Exception {
File file = new File(imgPath);
if (!file.exists()) {
System.err.println(""+imgPath+" 该文件不存在!");
return;
}
Image src = ImageIO.read(new File(imgPath));
int width = src.getWidth(null);
int height = src.getHeight(null);
if (needCompress) {// 压缩LOGO
if (width > WIDTH) {
width = WIDTH;
}
if (height > HEIGHT) {
height = HEIGHT;
}
Image image = src.getScaledInstance(width, height,
Image.SCALE_SMOOTH);
BufferedImage tag = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(image, 0, 0, null); // 绘制缩小后的图
g.dispose();
src = image;
}
// 插入LOGO
Graphics2D graph = source.createGraphics();
int x = (QRCODE_SIZE - width) / 2;
int y = (QRCODE_SIZE - height) / 2;
graph.drawImage(src, x, y, width, height, null);
Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
graph.setStroke(new BasicStroke(3f));
graph.draw(shape);
graph.dispose();
}
示例7: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the axis.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param cursor the cursor position.
* @param plotArea the plot area (<code>null</code> not permitted).
* @param dataArea the data area (<code>null</code> not permitted).
* @param edge the edge (<code>null</code> not permitted).
* @param plotState collects information about the plot (<code>null</code> permitted).
*
* @return the axis state (never <code>null</code>).
*/
public AxisState draw(Graphics2D g2,
double cursor,
Rectangle2D plotArea,
Rectangle2D dataArea,
RectangleEdge edge,
PlotRenderingInfo plotState) {
AxisState ret = super.draw(g2, cursor, plotArea, dataArea, edge, plotState);
if (isAdvanceLineVisible()) {
double xx = valueToJava2D(getRange().getUpperBound(), dataArea, edge);
Line2D mark = null;
g2.setStroke(getAdvanceLineStroke());
g2.setPaint(getAdvanceLinePaint());
if (edge == RectangleEdge.LEFT) {
mark = new Line2D.Double(cursor, xx, cursor + dataArea.getWidth(), xx);
}
else if (edge == RectangleEdge.RIGHT) {
mark = new Line2D.Double(cursor - dataArea.getWidth(), xx, cursor, xx);
}
else if (edge == RectangleEdge.TOP) {
mark = new Line2D.Double(xx, cursor + dataArea.getHeight(), xx, cursor);
}
else if (edge == RectangleEdge.BOTTOM) {
mark = new Line2D.Double(xx, cursor, xx, cursor - dataArea.getHeight());
}
g2.draw(mark);
}
return ret;
}
示例8: drawVerticalTic
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawVerticalTic(Graphics2D g, int ticNumber, DecimalFormat format, double dx, double dy, double sx,
double sy) {
double x = ticNumber * xTicSize + minX;
g.setColor(GRID_COLOR);
g.draw(new Line2D.Double((x + dx) * sx, (minY + dy) * sy, (x + dx) * sx, (maxY + dy) * sy));
g.setColor(Color.black);
}
示例9: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(GamePiece p, Graphics g, int x, int y,
Component obs, double zoom) {
if (thickness > 0) {
if (c != null) {
// Find the border by outsetting the bounding box, and then scaling
// the shape to fill the outset.
final Shape s = p.getShape();
final Rectangle br = s.getBounds();
// Don't bother if the shape is empty.
if (!br.isEmpty()) {
final double xzoom = (br.getWidth()+1) / br.getWidth();
final double yzoom = (br.getHeight()+1) / br.getHeight();
final AffineTransform t = AffineTransform.getTranslateInstance(x,y);
t.scale(xzoom*zoom, yzoom*zoom);
final Graphics2D g2d = (Graphics2D) g;
final Stroke str = g2d.getStroke();
g2d.setStroke(
new BasicStroke(Math.max(1, Math.round(zoom*thickness))));
g2d.setColor(c);
g2d.draw(t.createTransformedShape(s));
g2d.setStroke(str);
}
}
else {
highlightSelectionBounds(p, g, x, y, obs, zoom);
}
}
// Draw any additional highlighters
for (Highlighter h : highlighters) {
h.draw(p, g, x, y, obs, zoom);
}
}
示例10: finish
import java.awt.Graphics2D; //导入方法依赖的package包/类
void finish(MouseEvent e) {
double wrap = map.getWrap();
if (p0==null) {
return;
}
drawLine();
Graphics2D g = map.getGraphics2D();
g.setStroke( new BasicStroke(4f/(float)map.getZoom()) );
g.setColor( Color.white );
//g.setXORMode(Color.white);
g.draw( currentPath );
if( wrap>0.) {
g.translate(wrap,0.);
g.draw( currentPath );
}
Point p1 = e.getPoint();
if( p0.x==p1.x && p0.y==p1.y ) {
if( line!=null ) {
line=null;
if(dialog!=null)dialog.setVisible(false);
map.repaint();
}
p0=null;
return;
}
Point2D pA = map.getScaledPoint( p0 );
Point2D pB = map.getScaledPoint( e.getPoint());
Point2D latLonA = map.getProjection().getRefXY(pA);
Point2D latLonB = map.getProjection().getRefXY(pB);
startLonTF.setText(df.format(latLonA.getX()));
startLatTF.setText(df.format(latLonA.getY()));
endLonTF.setText(df.format(latLonB.getX()));
endLatTF.setText(df.format(latLonB.getY()));
currentLine = null;
currentPath = null;
p0=null;
}
示例11: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics2D g) {
g.setColor(function.getBackground());
final Rectangle2D rect = movingArea.getBounds(getBounds());
Ellipse2D ellipse = new Ellipse2D.Double(rect.getX(), rect.getY(),
rect.getWidth(), rect.getHeight());
g.fill(ellipse);
g.setFont(function.getFont());
paintText(g);
paintBorder(g);
final Stroke tmp = g.getStroke();
g.draw(ellipse);
if (!function.isHaveChilds()) {
FRectangle fr = new FRectangle(rect);
double y1 = rect.getY() + rect.getHeight() / 2.5;
double x1 = getX(rect.getY() + rect.getHeight() / 2.5, true, fr);
double x2 = rect.getX() + rect.getWidth() / 2.5;
double y2 = getY(x2, true, fr);
g.draw(new Line2D.Double(x1, y1, x2, y2));
}
g.setStroke(new BasicStroke(2));
final String string = Integer.toString(function.getId());
g.setFont(function.getFont());
double h = MovingArea.getWidth(0)
+ MovingArea.getWidth((int) function.getFont()
.getStringBounds(string, g.getFontRenderContext())
.getHeight());
h = h * 0.7;
paintTringle(g);
g.setStroke(tmp);
movingArea.paintText(g, string, new FRectangle(getBounds().getX(),
getBounds().getBottom() - h, getBounds().getWidth(), h),
com.ramussoft.pb.print.old.Line.RIGHT_ALIGN, 1, true);
}
示例12: main
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(String[] args) {
Locale.setDefault(Locale.US);
// initialize j.u.l Looger:
final Logger log = Logger.getLogger("sun.java2d.marlin");
log.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
Throwable th = record.getThrown();
// detect any Throwable:
if (th != null) {
System.out.println("Test failed:\n" + record.getMessage());
th.printStackTrace(System.out);
throw new RuntimeException("Test failed: ", th);
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
});
log.info("TextClipErrorTest: start");
// enable Marlin logging & internal checks:
System.setProperty("sun.java2d.renderer.log", "true");
System.setProperty("sun.java2d.renderer.useLogger", "true");
System.setProperty("sun.java2d.renderer.doChecks", "true");
BufferedImage image = new BufferedImage(256, 256,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.red);
try {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font font = g2d.getFont();
FontRenderContext frc = new FontRenderContext(
new AffineTransform(), true, true);
g2d.setStroke(new BasicStroke(4.0f,
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
final Shape badShape;
if (SERIALIZE) {
final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
final Shape textShape = gv1.getOutline();
final AffineTransform at1 = AffineTransform.getTranslateInstance(
-2091202.554154681, 5548.601436981691);
badShape = at1.createTransformedShape(textShape);
serializeShape(badShape);
} else {
badShape = deserializeShape();
}
g2d.draw(badShape);
// Draw anything within bounds and it fails:
g2d.draw(new Line2D.Double(10, 20, 30, 40));
if (SAVE_IMAGE) {
final File file = new File("TextClipErrorTest.png");
System.out.println("Writing file: " + file.getAbsolutePath());
ImageIO.write(image, "PNG", file);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
g2d.dispose();
log.info("TextClipErrorTest: end");
}
}
示例13: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void draw(Graphics2D graphics) {
float radius = Base.BASE_RADIUS;
float diameter = Base.BASE_RADIUS * 2;
// change the base's transparency based upon the energy level
int alpha = (int) (((float) base.getEnergy() / base.getMaxEnergy()) * 255.0);
Color energyColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue(), alpha);
graphics.setColor(energyColor);
graphics.fillOval((int)(drawLocation.getX() - radius), (int)(drawLocation.getY() - radius),
(int)diameter, (int)diameter);
// draw an outline around the base (in case its healing energy goes to 0)
final Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
drawLocation.getY() - radius, diameter, diameter);
graphics.setStroke(JSpaceSettlersComponent.STROKE);
Color outlineColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue());
graphics.setColor(outlineColor);
graphics.draw(shape);
// if the base is shielded, put a white circle around the outside
if (base.isShielded()) {
double shieldRadius = radius + 8;
final Ellipse2D.Double shieldShape = new Ellipse2D.Double(drawLocation.getX() - shieldRadius,
drawLocation.getY() - shieldRadius, 2 * shieldRadius, 2 * shieldRadius);
graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
graphics.setColor(BASE_SHIELD_COLOR);
graphics.draw(shieldShape);
}
// show the healing energy level of the base
final Font font = new Font("Arial", Font.BOLD, 12);
graphics.setFont(font);
String number = Integer.toString(base.getHealingEnergy());
graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() + 12);
// show the resourcesAvailable collected by the team at this base
//number = Integer.toString(base.getMoney());
//graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
//graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() - 12);
// if it is a home base, put a H inside it
if (base.isHomeBase()) {
graphics.setPaint(Color.BLACK);
graphics.drawString("H", (int) drawLocation.getX()-4, (int) drawLocation.getY() + 4);
}
}
示例14: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws the annotation. This method is usually called by the
* {@link XYPlot} class, you shouldn't need to call it directly.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param rendererIndex the renderer index.
* @param info the plot rendering info.
*/
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
ValueAxis domainAxis, ValueAxis rangeAxis,
int rendererIndex, PlotRenderingInfo info) {
// if we don't have at least 2 (x, y) coordinates, just return
if (this.polygon.length < 4) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
plot.getRangeAxisLocation(), orientation);
GeneralPath area = new GeneralPath();
double x = domainAxis.valueToJava2D(this.polygon[0], dataArea,
domainEdge);
double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea,
rangeEdge);
if (orientation == PlotOrientation.HORIZONTAL) {
area.moveTo((float) y, (float) x);
for (int i = 2; i < this.polygon.length; i += 2) {
x = domainAxis.valueToJava2D(this.polygon[i], dataArea,
domainEdge);
y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea,
rangeEdge);
area.lineTo((float) y, (float) x);
}
area.closePath();
}
else if (orientation == PlotOrientation.VERTICAL) {
area.moveTo((float) x, (float) y);
for (int i = 2; i < this.polygon.length; i += 2) {
x = domainAxis.valueToJava2D(this.polygon[i], dataArea,
domainEdge);
y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea,
rangeEdge);
area.lineTo((float) x, (float) y);
}
area.closePath();
}
if (this.fillPaint != null) {
g2.setPaint(this.fillPaint);
g2.fill(area);
}
if (this.stroke != null && this.outlinePaint != null) {
g2.setPaint(this.outlinePaint);
g2.setStroke(this.stroke);
g2.draw(area);
}
addEntity(info, area, rendererIndex, getToolTipText(), getURL());
}
示例15: paintIcon
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JMenuItem b = (JMenuItem) c;
ButtonModel bm = b.getModel();
g.translate(x, y);
boolean isSelected = bm.isSelected();
boolean isEnabled = bm.isEnabled();
boolean isPressed = bm.isPressed();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// drawing background section
if (!isEnabled) {
g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
} else {
if (isPressed) {
g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
} else {
g2.setColor(Colors.RADIOBUTTON_BORDER);
}
}
g2.setStroke(RADIO_STROKE);
Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
g2.draw(circle);
// drawing sphere
if (isSelected) {
if (isEnabled) {
g2.setColor(Colors.RADIOBUTTON_CHECKED);
} else {
g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
}
circle = new Ellipse2D.Double(3, 3, 4, 4);
g2.fill(circle);
}
g.translate(-x, -y);
}