本文整理汇总了Java中java.awt.Graphics2D.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.getColor方法的具体用法?Java Graphics2D.getColor怎么用?Java Graphics2D.getColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.getColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintState
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintState(Graphics2D g2, ASVConfig s) {
if (s == null) {
return;
}
Path2D.Float path = new Path2D.Float();
List<Point2D> points = s.getASVPositions();
Point2D p = points.get(0);
path.moveTo(p.getX(), p.getY());
for (int i = 1; i < points.size(); i++) {
p = points.get(i);
path.lineTo(p.getX(), p.getY());
}
path.transform(transform);
g2.draw(path);
if (animating || !displayingSolution) {
p = transform.transform(points.get(0), null);
Color color = g2.getColor();
Stroke stroke = g2.getStroke();
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(1));
g2.draw(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8));
g2.setColor(color);
g2.setStroke(stroke);
}
}
示例2: drawJobs
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawJobs(Graphics2D g2d) {
double x = getProcessorXY().x + 2 * PROC_RAD, y = getProcessorXY().y + PROC_RAD * 2 + 4 * ELEMS_GAP;
Color tmp = g2d.getColor();
// System.out.println(nCpu);
if (nCpu == 1) {
txtBounds = drawCenteredText("executing cust.:" + donejobs + ", residual time:" + remainingTime[0] + "ms", Color.BLACK, Color.WHITE, x,
y, g2d, true, false);
drawCenteredText("executing cust.:" + donejobs + ", residual time:" + remainingTime[0] + "ms", Color.BLACK, Color.WHITE, x
- txtBounds.getWidth() / 2.0, y, g2d, true, true);
}
// else if(nCpu==2){
// txtBounds = drawCenteredText("executing cust.:" +
// donejobs + ", residual time(1):" + remainingTime[0] + "ms"+ ", residual time(2):" + remainingTime[1] + "ms", Color.BLACK, Color.WHITE, x, y, g2d, true, false);
// drawCenteredText("executing cust.:" +
// donejobs + ", residual time(1):" + remainingTime[0] + "ms"+ ", residual time(2):" + remainingTime[1] + "ms", Color.BLACK, Color.WHITE, x - txtBounds.getWidth() / 2.0, y, g2d, true, true);
//
// }
// else
// {
// txtBounds = drawCenteredText("executing cust.:" + donejobs , Color.BLACK, Color.WHITE, x, y, g2d, true, false);
// drawCenteredText("executing cust.:" + donejobs , Color.BLACK, Color.WHITE, x - txtBounds.getWidth() / 2.0, y, g2d, true, true);
// }
// draw box around text
g2d.setColor(tmp);
}
示例3: drawCenteredText
import java.awt.Graphics2D; //导入方法依赖的package包/类
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean draw) {
Rectangle2D txtBounds;
double x, y;
double gap = dCst.getElementsGap();
g2d.setFont(dCst.getFont());
txtBounds = dCst.getFont().getStringBounds(s, g2d.getFontRenderContext());
x = centerX - txtBounds.getWidth() / 2.0;
y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
txtBounds.setRect(x - gap, y - txtBounds.getHeight() / 2.0 - gap, txtBounds.getWidth() + 2 * gap, txtBounds.getHeight() + 2 * gap);
Color ctmp = g2d.getColor();
g2d.setColor(c);
if (draw) {
g2d.drawString(s, (float) x, (float) y);
}
g2d.setColor(ctmp);
return txtBounds;
}
示例4: drawCenteredText
import java.awt.Graphics2D; //导入方法依赖的package包/类
private Rectangle2D drawCenteredText(String s, Color c, double centerX, double centerY, Graphics2D g2d, boolean drawBorder) {
double x, y;
g2d.setFont(f);
txtBounds = f.getStringBounds(s, g2d.getFontRenderContext());
x = centerX - txtBounds.getWidth() / 2.0;
y = centerY - txtBounds.getY() - txtBounds.getHeight() / 2;
txtBounds.setRect(x - ELEMS_GAP, y - txtBounds.getHeight() / 2.0 - ELEMS_GAP, txtBounds.getWidth() + 2 * ELEMS_GAP, txtBounds.getHeight() + 2
* ELEMS_GAP);
if (drawBorder) {
g2d.setColor(invertedColor(c));
g2d.fill(txtBounds);
g2d.setColor(c);
g2d.draw(txtBounds);
}
Color ctmp = g2d.getColor();
g2d.setColor(c);
g2d.drawString(s, (float) x, (float) y);
g2d.setColor(ctmp);
return txtBounds;
}
示例5: drawTextWithShadow
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* PERFORMANCE HINT: The larger the text is, the more time it needs to render
* especially with antialiasing turned on.
*
* @param g
* @param text
* @param x
* @param y
* @param shadow
*/
public static void drawTextWithShadow(final Graphics2D g, final String text, final double x, final double y, final Color shadow) {
if (text == null || text.isEmpty()) {
return;
}
final Color old = g.getColor();
g.setColor(shadow);
g.drawString(text, (float) x + 1, (float) y + 1);
g.drawString(text, (float) x + 1, (float) y - 1);
g.drawString(text, (float) x - 1, (float) y - 1);
g.drawString(text, (float) x - 1, (float) y + 1);
g.setColor(old);
g.drawString(text, (float) x, (float) y);
}
示例6: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
if (selected) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
Color oldColor = g2d.getColor();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(oldComposite);
g2d.setColor(oldColor);
}
super.paint(g);
}
示例7: paintIcon
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y)
{
Rectangle r = new Rectangle(x, y, WIDTH - 1, HEIGHT - 1);
Graphics2D g2 = (Graphics2D) g;
Color oldColor = g2.getColor();
g2.setColor(color);
g2.fill(r);
g2.setColor(Color.BLACK);
g2.draw(r);
g2.setColor(oldColor);
}
示例8: drawViewButton
import java.awt.Graphics2D; //导入方法依赖的package包/类
private RoundRectangle2D drawViewButton(double x, double y, Graphics2D g2d, boolean draw, boolean clicked) {
Rectangle2D dvR;
RoundRectangle2D dvRR;
Color tmp;
Color fg = Color.BLACK;
Color bg = Color.LIGHT_GRAY;
if (clicked) {
tmp = fg;
fg = bg;
bg = tmp;
}
if (nCpu > 2) {
fg = Color.DARK_GRAY.brighter().brighter();
bg = Color.LIGHT_GRAY;
}
dvR = drawCenteredText("change view", fg, bg, x, y, g2d, false, false);
dvRR = new RoundRectangle2D.Double(x, y, dvR.getWidth(), dvR.getHeight(), 5.0, 5.0);
if (draw) {
tmp = g2d.getColor();
g2d.setColor(bg);
g2d.fill(dvRR);
g2d.setColor(fg);
g2d.draw(dvRR);
drawCenteredText("change view", fg, bg, x + dvR.getWidth() / 2.0, y + dvR.getHeight() / 2.0, g2d, false, true);
g2d.setColor(tmp);
}
return dvRR;
}
示例9: drawViewButton
import java.awt.Graphics2D; //导入方法依赖的package包/类
private RoundRectangle2D drawViewButton(double x, double y, Graphics2D g2d, boolean draw, boolean clicked) {
Rectangle2D dvR;
RoundRectangle2D dvRR;
Color tmp;
Color fg = Color.BLACK;
Color bg = Color.LIGHT_GRAY;
if (clicked) {
tmp = fg;
fg = bg;
bg = tmp;
}
if (nCpu > 2) {
fg = Color.darkGray.brighter().brighter();
bg = Color.LIGHT_GRAY;
}
dvR = drawCenteredText("change view", fg, bg, x, y, g2d, false, false);
dvRR = new RoundRectangle2D.Double(x, y, dvR.getWidth(), dvR.getHeight(), 5.0, 5.0);
if (draw) {
tmp = g2d.getColor();
g2d.setColor(bg);
g2d.fill(dvRR);
g2d.setColor(fg);
g2d.draw(dvRR);
drawCenteredText("change view", fg, bg, x + dvR.getWidth() / 2.0, y + dvR.getHeight() / 2.0, g2d, false, true);
g2d.setColor(tmp);
}
return dvRR;
}
示例10: paintButtonPressed
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintButtonPressed(Graphics g, AbstractButton c) {
if (c.isContentAreaFilled()) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = c.getSize();
Composite oldComposite = g2d.getComposite();
Color oldColor = g2d.getColor();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
g2d.setComposite(oldComposite);
g2d.setColor(oldColor);
}
}
示例11: drawMoreStatus
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawMoreStatus(Graphics2D g2d) {
double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLength() - 2) + START_GAP;
Color ctmp = g2d.getColor();
g2d.setPaint(Color.BLACK);
drawCenteredText(" . . . ", Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
g2d.setColor(ctmp);
}
示例12: paintLayer
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
super.paintLayer(g2, layer);
if (this.mainTraceInfo.getPoint() == null) {
return;
}
final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
final Color oldColor = g2.getColor();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(COLOR_BLUE);
final int BALL_RADIUS = 8;
g2.fillOval((int)(this.mainTraceInfo.getPoint().getX() - (BALL_RADIUS >> 1) + 0.5), (int)(this.mainTraceInfo.getPoint().getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);
for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) {
final Point2D point = indicatorTraceInfo.getPoint();
if (null == point) {
continue;
}
g2.fillOval((int)(point.getX() - (BALL_RADIUS >> 1) + 0.5), (int)(point.getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);
}
g2.setColor(oldColor);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
this.drawInformationBox(g2, layer);
}
示例13: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(final Graphics2D g, final double x, final double y,
final boolean fill, int partNumber, int hPageCount) {
if (!function.isHaveChilds())
return;
final ArrowPainter painter = new ArrowPainter(movingArea);
final int y1 = movingArea.getIntOrdinate(movingArea.TOP_PART_A);
final int y2 = movingArea.getIntOrdinate(movingArea.CLIENT_HEIGHT);
final int height = movingArea.getIntOrdinate(movingArea.BOTTOM_PART_A);
final int x0 = (int) x + 1;
final int y0 = (int) y + 1;
if (fill) {
final Color c = g.getColor();
g.setColor(IDEFPanel.DEFAULT_BACKGROUND);
g.fillRect(x0, y0,
movingArea.getIntOrdinate(movingArea.MOVING_AREA_WIDTH), y1
+ y2 + height);
g.setColor(c);
}
g.setStroke(ArrowPainter.THIN_STROKE);
g.translate(x0, y0);
g.setColor(Color.BLACK);
painter.paintTop(
g// (Graphics2D)g.create(x0,y0,size.width,y1)
, movingArea.getIntOrdinate(movingArea.TOP_PART_A), movingArea,
partNumber, hPageCount);
g.translate(0, y1);
movingArea.paint(g);// g.create(x0,y0+y1,size.width,y2));
g.setStroke(ArrowPainter.THIN_STROKE);
g.translate(0, y2);
g.setColor(Color.BLACK);
painter.paintBottom(g, height, movingArea, partNumber, hPageCount);
}
示例14: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
if (allocBounds.intersects(clipBounds)) {
Font origFont = g.getFont();
Color origColor = g.getColor();
Color origBkColor = g.getBackground();
Shape origClip = g.getClip();
try {
// Leave component font
g.setBackground(getBackgroundColor());
int xInt = (int) allocBounds.getX();
int yInt = (int) allocBounds.getY();
int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
g.setColor(getBorderColor());
g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
g.setColor(getForegroundColor());
g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
g.clip(alloc);
TextLayout textLayout = getTextLayout();
if (textLayout != null) {
EditorView.Parent parent = (EditorView.Parent) getParent();
float ascent = parent.getViewRenderContext().getDefaultAscent();
String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
float y = (float) allocBounds.getY();
if (desc.length() > 0) {
textLayout.draw(g, x, y + ascent);
}
}
} finally {
g.setClip(origClip);
g.setBackground(origBkColor);
g.setColor(origColor);
g.setFont(origFont);
}
}
}
示例15: drawInstance
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawInstance(InstancePainter painter, boolean isGhost) {
Bounds bds = painter.getBounds();
Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
Direction facing = painter.getAttributeValue(StdAttr.FACING);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
if (flip)
degrees += 180;
double radians = Math.toRadians((degrees + 360) % 360);
Graphics2D g = (Graphics2D) painter.getGraphics().create();
g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
g.translate(bds.getX(), bds.getY());
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
Color gate0 = g.getColor();
Color gate1 = gate0;
Color input = gate0;
Color output = gate0;
Color platform = gate0;
if (!isGhost && painter.getShowState()) {
gate0 = painter.getPort(GATE0).getColor();
gate1 = painter.getPort(GATE0).getColor();
input = painter.getPort(INPUT).getColor();
output = painter.getPort(OUTPUT).getColor();
platform = computeOutput(painter).getColor();
}
g.setColor(flip ? input : output);
g.drawLine(0, 20, 11, 20);
g.drawLine(11, 13, 11, 27);
g.setColor(flip ? output : input);
g.drawLine(29, 20, 40, 20);
g.drawLine(29, 13, 29, 27);
g.setColor(gate0);
g.drawLine(20, 35, 20, 40);
GraphicsUtil.switchToWidth(g, 1);
g.drawOval(18, 30, 4, 4);
g.drawLine(10, 30, 30, 30);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.setColor(gate1);
g.drawLine(20, 9, 20, 0);
GraphicsUtil.switchToWidth(g, 1);
g.drawLine(10, 10, 30, 10);
g.setColor(platform);
g.drawLine(9, 12, 31, 12);
g.drawLine(9, 28, 31, 28);
if (flip) { // arrow
g.drawLine(18, 17, 21, 20);
g.drawLine(18, 23, 21, 20);
} else {
g.drawLine(22, 17, 19, 20);
g.drawLine(22, 23, 19, 20);
}
g.dispose();
}