下面列出了java.awt.Graphics2D#drawOval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates a new instance of EmptyTileFactory using the specified info.
*
* @param info TileFactoryInfo
*/
public EmptyTileFactory(TileFactoryInfo info) {
super(info);
int tileSize = info.getTileSize(info.getMinimumZoomLevel());
emptyTile = new BufferedImage(tileSize, tileSize,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = emptyTile.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.GRAY);
g.fillRect(0, 0, tileSize, tileSize);
g.setColor(Color.WHITE);
g.drawOval(10, 10, tileSize - 20, tileSize - 20);
g.fillOval(70, 50, 20, 20);
g.fillOval(tileSize - 90, 50, 20, 20);
g.fillOval(tileSize / 2 - 10, tileSize / 2 - 10, 20, 20);
g.dispose();
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setBackground(Color.WHITE);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2f));
g2d.clearRect(0, 0, 208, 212);
SalesmanRoute salesmanRoute = (SalesmanRoute) individual.getPhenotype();
for (int i = 0; i < salesmanRoute.size(); i++) {
final int j = (i + 1) % salesmanRoute.size();
City one = salesmanRoute.get(i);
City two = salesmanRoute.get(j);
int x1 = (int) (one.getX() * 2) + 4;
int y1 = (int) (one.getY() * 2) + 4;
int x2 = (int) (two.getX() * 2) + 4;
int y2 = (int) (two.getY() * 2) + 4;
g2d.drawLine(x1, y1, x2, y2);
g2d.drawOval(x1 - 2, y1 - 2, 4, 4);
}
}
/**
* 画随机码图
*
* @param fontcolor
* 随机字体颜色
* @param strs
* 字符数组
* @param flag
* 透明度使用
* @return BufferedImage
*/
private BufferedImage graphicsImage(Color[] fontcolor, char[] strs, int flag) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 或得图形上下文
// Graphics2D g2d=image.createGraphics();
Graphics2D g2d = (Graphics2D) image.getGraphics();
// 利用指定颜色填充背景
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);
AlphaComposite ac3;
int h = height - ((height - font.getSize()) >> 1);
int w = width / len;
g2d.setFont(font);
for (int i = 0; i < len; i++) {
ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i));
g2d.setComposite(ac3);
g2d.setColor(fontcolor[i]);
g2d.drawOval(num(width), num(height), 5 + num(10), 5 + num(10));
g2d.drawString(strs[i] + "", (width - (len - i) * w) + (w - font.getSize()) + 1, h - 4);
}
g2d.dispose();
return image;
}
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
cfImageData im = getImage( _session, argStruct );
int x = getNamedIntParam(argStruct, "x", Integer.MIN_VALUE );
int y = getNamedIntParam(argStruct, "y", Integer.MIN_VALUE );
int w = getNamedIntParam(argStruct, "width", Integer.MIN_VALUE );
int h = getNamedIntParam(argStruct, "height", Integer.MIN_VALUE );
boolean bFilled = getNamedBooleanParam(argStruct, "filled", false );
//Check boundaries
if ( x == Integer.MIN_VALUE )
throwException(_session, "x not specifed" );
if ( y == Integer.MIN_VALUE )
throwException(_session, "y not specifed" );
if ( w == Integer.MIN_VALUE )
throwException(_session, "width not specifed" );
if ( h == Integer.MIN_VALUE )
throwException(_session, "height not specifed" );
Graphics2D g2 = im.createGraphics();
if ( bFilled ){
g2.fillOval(x, y, w, h );
}else{
g2.drawOval(x, y, w, h );
}
im.dispose(g2);
return cfBooleanData.TRUE;
}
private void paintBar(Graphics2D g) {
List<String> list = getPaintingModel().getPositions();
int barStartY = getBarStartY();
g.setColor(BAR_COLOR);
g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);
int circleCenterY = barStartY + BAR_HEIGHT / 2;
for (int i = 0; i < list.size(); i++) {
int curX = getXPosition(i);
g.setColor(getPaintingModel().getColors().get(i));
g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
g.setColor(Color.black);
g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
String curS = list.get(i);
if (curS != null && curS.length() > 0) {
int startX = getStartXPosition(i);
int endX = getEndXPosition(i);
FontMetrics metrics = g.getFontMetrics();
Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
if (bounds.width < endX - startX && bounds.height < barStartY) {
g.setColor(Color.black);
g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
}
}
}
}
@Override
public void paint(Graphics g) {
try {
Border border = getBorder();
Insets insets = new Insets(0, 0, 0, 0);
if (border != null) {
insets = border.getBorderInsets(this);
}
int diameter = Math.min(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom)) - 4;
VolatileImage img = createVolatileImage(getBounds().width - (insets.left + insets.right), getBounds().height - (insets.top + insets.bottom), new ImageCapabilities(true));
Graphics2D gr = img.createGraphics();
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gr.drawOval(insets.left, insets.top, diameter, diameter);
TextLayout textTl = new TextLayout("fERRARI", getFont(), gr.getFontRenderContext());
AffineTransform at = new AffineTransform();
at.translate(0, (float)getBounds().getHeight() - (insets.top + insets.bottom) - (float)textTl.getBounds().getHeight());
at.scale(2d, 2d);
// at.shear(1.3d, 0.8d);
Shape textShape = textTl.getOutline(at);
gr.fill(textShape);
// GlyphVector gv = getFont().createGlyphVector(gr.getFontRenderContext(), "fERRARI");
// Rectangle bounds = gv.getPixelBounds(gr.getFontRenderContext(), 0, 0);
// double scale = (double)(getBounds().width - (insets.left + insets.right)) / (double)bounds.width;
// for(int i=0;i<gv.getNumGlyphs();i++) {
// gv.setGlyphTransform(i, AffineTransform.getScaleInstance(scale, 1d));
// gv.
// }
// gr.drawGlyphVector(gv, insets.left + 2, getBounds().height - (insets.top + insets.bottom) - 2 - bounds.height);
int lineLenght = diameter / 2 - 10;
gr.drawLine(diameter / 2, diameter / 2, diameter / 2 - getXOnArc(lineLenght, getAngle()), diameter / 2 - getYOnArc(lineLenght, getAngle()));
gr.dispose();
g.drawImage(img, insets.left, insets.top, this);
if (border != null) {
border.paintBorder(this, g, 0, 0, getBounds().width, getBounds().height);
}
} catch (AWTException e) {}
}
private void paintBar(Graphics2D g) {
List<String> list = getPaintingModel().getPositions();
int barStartY = getBarStartY();
g.setColor(BAR_COLOR);
g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);
int circleCenterY = barStartY + BAR_HEIGHT / 2;
for (int i = 0; i < list.size(); i++) {
int curX = getXPosition(i);
g.setColor(getPaintingModel().getColors().get(i));
g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
g.setColor(Color.black);
g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
String curS = list.get(i);
if (curS != null && curS.length() > 0) {
int startX = getStartXPosition(i);
int endX = getEndXPosition(i);
FontMetrics metrics = g.getFontMetrics();
Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
if (bounds.width < endX - startX && bounds.height < barStartY) {
g.setColor(Color.black);
g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
}
}
}
}
private void renderRows(RenderSettings pSettings, Graphics2D pG2D) {
//iterate through entire rows
List<KnownVillage> watchtowerVillages = KnownVillageManager.getSingleton().getWatchtowerVillages();
Color cb = pG2D.getColor();
Composite com = pG2D.getComposite();
Stroke st = pG2D.getStroke();
for (KnownVillage village : watchtowerVillages) {
Point villAbs = MapPanel.getSingleton().virtualPosToSceenPos(village.getVillage().getX(), village.getVillage().getY());
int w = (int) (village.getWatchtowerRange() * pSettings.getFieldWidth() * 2);
int h = (int) (village.getWatchtowerRange() * pSettings.getFieldHeight() * 2);
int x = (int) (villAbs.x + (pSettings.getFieldWidth() - w) / 2.0);
int y = (int) (villAbs.y + (pSettings.getFieldHeight()- h) / 2.0);
pG2D.setColor(village.getRangeColor());
pG2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
pG2D.setStroke(new BasicStroke(13.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND,
0.0f, new float[] {15, 15}, 0.0f));
pG2D.drawOval(x, y, w, h);
pG2D.setComposite(com);
pG2D.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
0.0f, new float[] {15, 15}, 0.0f));
pG2D.drawOval(x, y, w, h);
}
pG2D.setComposite(com);
pG2D.setColor(cb);
pG2D.setStroke(st);
}
@Override
public void draw(Graphics2D g2) {
AffineTransform at = g2.getTransform();
if (valign == VerticalAlignment.BOTTOM) {
g2.translate(0, height - size);
} else
if (valign == VerticalAlignment.MIDDLE) {
g2.translate(0, (height - size) / 2);
}
if (backgroundColor != 0) {
g2.setColor(new Color(backgroundColor, true));
g2.fillRect(-5, -5, width + 10, height + 10);
}
g2.setColor(enabled ? Color.WHITE : new Color(disabledColor));
Stroke sp = g2.getStroke();
g2.setStroke(new BasicStroke(2));
g2.drawOval(0, 0, size - 1, size - 1);
g2.setStroke(sp);
if (selected) {
g2.fillOval(3, 3, size - 7, size - 7);
}
tr.paintTo(g2, size + 6, 0, size, enabled() ? color : disabledColor, text);
g2.setTransform(at);
}
protected void drawOval(Graphics2D g2d, int x, int y, boolean isFocus)
{
if(isFocus)
{
g2d.setColor(Color.WHITE);
}
else
{
g2d.setColor(UIManager.getColor(LuckToggleButtonUIBundle.RADIO_FOCUS_COLOR));
}
g2d.drawOval(x, y, getIconWidth() - 3, getIconHeight() - 3);
}
/**
*
* @param g2d
* @param x
* @param y
*/
protected void drawOvalShadow(Graphics2D g2d, int x, int y)
{
g2d.setColor(UIManager.getColor(LuckToggleButtonUIBundle.RADIO_SHADOW_COLOR));
g2d.drawOval(x + 1 + getLeftInset(), y + 1 + getTopInset(),
getIconWidth() - 5, getIconHeight() - 5);
}
/**
*
* @param g
* @param width
* @param height
*/
public void draw(Graphics g, int width, int height, PaintMode paintMode) {
Graphics2D g2d = (Graphics2D)g;
if (Math.abs(projectedCoords[0][0]) > 0.5 ||
Math.abs(projectedCoords[0][1]) > 0.5 ||
this.hidden == true) {
return;
}
g2d.setColor(color);
deviceCoords[0][0] = (int)((projectedCoords[0][0] + 0.5) * width);
deviceCoords[0][1] = (int)((projectedCoords[0][1] + 0.5) * height);
double screenRadius = 0.5;
if (effectiveRadius * width > 0.5) {
screenRadius = effectiveRadius * width;
}
int x = deviceCoords[0][0]-(int)screenRadius;
int y = deviceCoords[0][1]-(int)screenRadius;
int w = (int)(screenRadius*2);
int h = (int)(screenRadius*2);
if(paintMode == CoordinateArea.PaintMode.RECT){
g2d.setPaint(color);
g2d.fillRect(x, y, w, h);
} else {
paintBall(x, y, w, h, color, g2d);
}
if (selected == true) {
g2d.setPaint(Color.gray);
g2d.drawOval(x-2, y-2, w+4, h+4);
}
}
public void drawPoint(DataPoint point){
layerPointCanvas.setVisible(pointsVisible);
layerPoints.setVisible(false);
if(!pointsVisible)
return;
Graphics2D imageGraphics = (Graphics2D) pointCanvas.createGraphics();
if (ANTIALIAS) {
imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
int size = Math.min(getWidth(), getHeight());
int x = (int) Math.round(point.value(getActiveXDim()) * size);
int y = (int) Math.round(point.value(getActiveYDim()) * size);
Color c = PointPanel.getPointColorbyClass(point, 10);
imageGraphics.setColor(c);
int psize = PointPanel.POINTSIZE;
int poffset = 2;
imageGraphics.drawOval(x - poffset, y - poffset, psize, psize);
imageGraphics.fillOval(x - poffset, y - poffset, psize, psize);
layerPointCanvas.repaint();
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, w, h);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
antialiasHint);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
renderHint);
g2d.transform(transform);
g2d.setPaint(paint);
switch (shapeType) {
default:
case RECT:
g2d.fillRect(0, 0, w, h);
break;
case ELLIPSE:
g2d.fillOval(0, 0, w, h);
break;
case MULTIPLE:
g2d.fillRect(0, 0, w/2, h/2);
g2d.fillOval(w/2, 0, w/2, h/2);
g2d.drawOval(0, h/2, w/2, h/2);
g2d.drawLine(0, h/2, w/2, h);
g2d.drawLine(0, h, w/2, h/2);
Polygon p = new Polygon();
p.addPoint(w/2, h);
p.addPoint(w, h);
p.addPoint(3*w/4, h/2);
g2d.fillPolygon(p);
break;
}
switch (paintType) {
default:
case BASIC:
case LINEAR:
g2d.setColor(Color.white);
g2d.fillRect(startX-1, startY-1, 2, 2);
g2d.drawString("1", startX, startY + 12);
g2d.fillRect(endX-1, endY-1, 2, 2);
g2d.drawString("2", endX, endY + 12);
break;
case RADIAL:
g2d.setColor(Color.white);
g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
g2d.drawString("C", ctrX, ctrY + 12);
g2d.fillRect(focusX-1, focusY-1, 2, 2);
g2d.drawString("F", focusX, focusY + 12);
break;
}
g2d.dispose();
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, w, h);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
antialiasHint);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
renderHint);
g2d.transform(transform);
g2d.setPaint(paint);
switch (shapeType) {
default:
case RECT:
g2d.fillRect(0, 0, w, h);
break;
case ELLIPSE:
g2d.fillOval(0, 0, w, h);
break;
case MULTIPLE:
g2d.fillRect(0, 0, w/2, h/2);
g2d.fillOval(w/2, 0, w/2, h/2);
g2d.drawOval(0, h/2, w/2, h/2);
g2d.drawLine(0, h/2, w/2, h);
g2d.drawLine(0, h, w/2, h/2);
Polygon p = new Polygon();
p.addPoint(w/2, h);
p.addPoint(w, h);
p.addPoint(3*w/4, h/2);
g2d.fillPolygon(p);
break;
}
switch (paintType) {
default:
case BASIC:
case LINEAR:
g2d.setColor(Color.white);
g2d.fillRect(startX-1, startY-1, 2, 2);
g2d.drawString("1", startX, startY + 12);
g2d.fillRect(endX-1, endY-1, 2, 2);
g2d.drawString("2", endX, endY + 12);
break;
case RADIAL:
g2d.setColor(Color.white);
g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
g2d.drawString("C", ctrX, ctrY + 12);
g2d.fillRect(focusX-1, focusY-1, 2, 2);
g2d.drawString("F", focusX, focusY + 12);
break;
}
g2d.dispose();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if (getRenderer() != null) {
//Antialiasing ON
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ArrayList<BivariateColorPoint> points = getRenderer().getPoints();
for (BivariateColorPoint point : points) {
int px = attr1ToPixelX(point.getAttribute1());
int py = attr2ToPixelY(point.getAttribute2());
g2d.setColor(point.getColor());
if (point.isLonLatDefined()) {
g2d.fillOval(px - RECT_DIM / 2, py - RECT_DIM / 2, RECT_DIM, RECT_DIM);
} else {
g2d.fillRect(px - RECT_DIM / 2, py - RECT_DIM / 2, RECT_DIM, RECT_DIM);
}
if (point == selectedPoint) {
if (ColorUtils.difference(Color.RED, point.getColor()) > 100) {
g2d.setColor(Color.RED);
} else {
g2d.setColor(Color.CYAN);
}
} else {
if (ColorUtils.getBrightness(point.getColor()) > 100) {
g2d.setColor(Color.BLACK);
} else {
g2d.setColor(Color.WHITE);
}
}
if (point.isLonLatDefined()) {
g2d.drawOval(px - RECT_DIM / 2, py - RECT_DIM / 2, RECT_DIM, RECT_DIM);
} else {
g2d.drawRect(px - RECT_DIM / 2, py - RECT_DIM / 2, RECT_DIM, RECT_DIM);
}
}
int D = 3;
g2d.setColor(Color.BLACK);
if (crossXPerc >= 0 && crossYPerc >= 0) {
int x = (int) Math.round(crossXPerc * getWidth() / 100d);
int y = (int) Math.round(crossYPerc * getHeight() / 100d);
g2d.drawLine(x - D, y, x + D, y);
g2d.drawLine(x, y - D, x, y + D);
}
}
paintWarningString(g2d);
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, w, h);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
antialiasHint);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
renderHint);
g2d.transform(transform);
g2d.setPaint(paint);
switch (shapeType) {
default:
case RECT:
g2d.fillRect(0, 0, w, h);
break;
case ELLIPSE:
g2d.fillOval(0, 0, w, h);
break;
case MULTIPLE:
g2d.fillRect(0, 0, w/2, h/2);
g2d.fillOval(w/2, 0, w/2, h/2);
g2d.drawOval(0, h/2, w/2, h/2);
g2d.drawLine(0, h/2, w/2, h);
g2d.drawLine(0, h, w/2, h/2);
Polygon p = new Polygon();
p.addPoint(w/2, h);
p.addPoint(w, h);
p.addPoint(3*w/4, h/2);
g2d.fillPolygon(p);
break;
}
switch (paintType) {
default:
case BASIC:
case LINEAR:
g2d.setColor(Color.white);
g2d.fillRect(startX-1, startY-1, 2, 2);
g2d.drawString("1", startX, startY + 12);
g2d.fillRect(endX-1, endY-1, 2, 2);
g2d.drawString("2", endX, endY + 12);
break;
case RADIAL:
g2d.setColor(Color.white);
g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
g2d.drawString("C", ctrX, ctrY + 12);
g2d.fillRect(focusX-1, focusY-1, 2, 2);
g2d.drawString("F", focusX, focusY + 12);
break;
}
g2d.dispose();
}
/** Draws the outline of a circle centered at (centerX, centerY) with radius $radius$ */
private void drawCircle(Graphics2D g, int centerX, int centerY, int radius) {
g.drawOval(centerX - radius, centerY - radius, 2 * radius + 1, 2 * radius + 1);
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, w, h);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
antialiasHint);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
renderHint);
g2d.transform(transform);
g2d.setPaint(paint);
switch (shapeType) {
default:
case RECT:
g2d.fillRect(0, 0, w, h);
break;
case ELLIPSE:
g2d.fillOval(0, 0, w, h);
break;
case MULTIPLE:
g2d.fillRect(0, 0, w/2, h/2);
g2d.fillOval(w/2, 0, w/2, h/2);
g2d.drawOval(0, h/2, w/2, h/2);
g2d.drawLine(0, h/2, w/2, h);
g2d.drawLine(0, h, w/2, h/2);
Polygon p = new Polygon();
p.addPoint(w/2, h);
p.addPoint(w, h);
p.addPoint(3*w/4, h/2);
g2d.fillPolygon(p);
break;
}
switch (paintType) {
default:
case BASIC:
case LINEAR:
g2d.setColor(Color.white);
g2d.fillRect(startX-1, startY-1, 2, 2);
g2d.drawString("1", startX, startY + 12);
g2d.fillRect(endX-1, endY-1, 2, 2);
g2d.drawString("2", endX, endY + 12);
break;
case RADIAL:
g2d.setColor(Color.white);
g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
g2d.drawString("C", ctrX, ctrY + 12);
g2d.fillRect(focusX-1, focusY-1, 2, 2);
g2d.drawString("F", focusX, focusY + 12);
break;
}
g2d.dispose();
}
@Override
public void paint( final Graphics g ) {
final Graphics2D g2 = (Graphics2D) g;
g2.setBackground( Color.BLACK );
g2.clearRect( 0, 0, Consts.WIDTH, Consts.HEIGHT );
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
model = model_;
if ( model == null ) {
paintInfo( g2 );
}
else {
// Clone the model so we can concurrently paint it and have the controller modify it
model = model_.clone();
final boolean colorBind = Settings.getBoolean( Settings.KEY_MOUSE_PRACTICE_COLOR_BLIND );
// Draw objects of the model
for ( final Disc disc : model.discList ) {
if ( rules.paintMaxDiscOutline ) {
g2.setColor( Color.GRAY );
g2.drawOval( (int) ( disc.x - rules.maxDiscRadius ), (int) ( disc.y - rules.maxDiscRadius ), ( rules.maxDiscRadius << 1 ) + 1, ( rules.maxDiscRadius << 1 ) + 1 );
}
g2.setColor( disc.friendly ? PlayerColor.GREEN.color : PlayerColor.RED.color );
if ( disc.friendly || !colorBind )
g2.fillOval( (int) ( disc.x - disc.radius ), (int) ( disc.y - disc.radius ), (int) ( disc.radius*2 ) + 1, (int) ( disc.radius*2 ) + 1 );
else {
final Stroke storedStroke = g2.getStroke();
g2.setStroke( DOUBLE_STROKE );
g2.drawOval( (int) ( disc.x - disc.radius ), (int) ( disc.y - disc.radius ), (int) ( disc.radius*2 ) + 1, (int) ( disc.radius*2 ) + 1 );
g2.setStroke( storedStroke );
}
if ( rules.paintDiscCenterCross && disc.radius > 1 ) {
g2.setColor( Color.WHITE );
g2.drawLine( (int) ( disc.x - disc.radius/2 ), (int) disc.y, (int) ( disc.x + disc.radius/2 ), (int) disc.y );
g2.drawLine( (int) disc.x, (int) ( disc.y - disc.radius/2 ), (int) disc.x, (int) ( disc.y + disc.radius/2 ) );
}
}
final FontMetrics fontMetrics = g2.getFontMetrics();
final int shiftY = fontMetrics.getAscent() >> 1;
for ( final FloatingText floatingText : model.floatingTextList ) {
g2.setColor( floatingText.color );
g2.drawString( floatingText.text, floatingText.x - ( fontMetrics.stringWidth( floatingText.text ) >> 1 ), floatingText.y + shiftY );
}
// Draw texts
paintTexts( g2 );
}
}