本文整理汇总了Java中java.awt.Graphics2D.setStroke方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setStroke方法的具体用法?Java Graphics2D.setStroke怎么用?Java Graphics2D.setStroke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.setStroke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawStatus
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
double y = panelH / 2.0 - STATUS_RAD;
double pie = probability * 360;
Color ctmp = g2d.getColor();
if (bold) {
g2d.setStroke(strokeB);
}
statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
g2d.setPaint(sc);
g2d.fill(statusE[status]);
g2d.setPaint(pc);
g2d.fill(statusP[status]);
g2d.setPaint(borderC);
g2d.draw(statusE[status]);
drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
g2d.setColor(ctmp);
g2d.setStroke(stroke);
}
示例2: paintEastArrow
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void paintEastArrow(Graphics2D g2, int w, int h, boolean isPressed, boolean isRollover) {
g2.setColor(Colors.SCROLLBAR_ARROW_BORDER);
g2.drawLine(0, 0, w - 1, 0);
if (isPressed) {
g2.setColor(Colors.SCROLLBAR_ARROW_PRESSED);
} else if (isRollover) {
g2.setColor(Colors.SCROLLBAR_ARROW_ROLLOVER);
} else {
g2.setColor(Colors.SCROLLBAR_ARROW);
}
g2.setStroke(ARROW_STROKE);
g2.drawLine(6, OFFSET, w - 6, h / 2);
g2.drawLine(w - 6, h / 2, 6, h - OFFSET);
}
示例3: createPattern
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* @param g2d
*/
private void createPattern(final Graphics2D g2d) {
g2d.setColor(Color.WHITE);
g2d.setStroke(new BasicStroke(1));
int variant = 5;
// horizontal line
for (int ii = 0; ii < END_Y; ii++) {
g2d.drawLine(0, ii, END_X, ii);
ii += variant;
}
// vertical line
for (int ii = 0; ii < END_X; ii++) {
g2d.drawLine(ii, 0, ii, END_Y);
ii += variant;
}
}
示例4: drawCrossing
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawCrossing(Graphics2D g2d){
g2d.setColor(new Color(0, 100, 100)); // teal
g2d.setStroke(new BasicStroke(6));
for (int i = 0; i < blocks.size(); i++){
if (blocks.get(i).getCrossing() != null){
double[] x_coords = blocks.get(i).getXCoordinates();
double[] y_coords = blocks.get(i).getYCoordinates();
for (int j = 3; j < x_coords.length-2; j+=3){
int x0 = (int)x_coords[j-3];
int y0 = (int)y_coords[j-3];
int x1 = (int)x_coords[j];
int y1 = (int)y_coords[j];
g2d.drawLine(x0, y0, x1, y1);
}
}
}
}
示例5: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g) {
float radius = Beacon.BEACON_RADIUS;
float diameter = Beacon.BEACON_RADIUS * 2;
Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
drawLocation.getY() - radius, diameter, diameter);
g.setColor(BEACON_COLOR);
g.fill(shape);
g.setStroke(JSpaceSettlersComponent.THICK_STROKE);
g.setColor(BEACON_LINE_COLOR);
g.draw(shape);
// add an E to make it clear it is an energy beacon
g.setPaint(Color.BLACK);
g.drawString("E", (int) drawLocation.getX()-3, (int) drawLocation.getY() + 4);
}
示例6: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw( Graphics2D g ) {
if( !visible || path==null ) return;
g.setColor( color );
g.setStroke( new BasicStroke(
lineWidth/(float)map.getZoom(),
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND) );
g.draw( path );
}
示例7: 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();
}
示例8: render
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void render(final Graphics2D g) {
super.render(g);
if (this.selectedComponent != null) {
final Stroke oldStroke = g.getStroke();
g.setStroke(new BasicStroke(2));
final Rectangle2D border = new Rectangle2D.Double(this.selectedComponent.getX() - 1, this.selectedComponent.getY() - 1, this.selectedComponent.getWidth() + 2, this.selectedComponent.getHeight() + 2);
g.setColor(Color.WHITE);
g.draw(border);
g.setStroke(oldStroke);
}
}
示例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: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paintBorder(Graphics graphics) {
Graphics2D g = (Graphics2D)graphics.create();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(this.colorBorder);
g.setStroke(new BasicStroke(2.0F));
g.drawRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 10, 10);
}
示例11: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* This handles the toroidal space wrapping internally. It probably shouldn't.
*
* TODO: Fix it so it does the wrapping externally like the other graphics (but it is harder here)
*/
public void draw(Graphics2D graphics) {
graphics.setColor(lineColor);
graphics.setStroke(new BasicStroke(strokeWidth));
graphics.drawLine((int)startPoint.getX(), (int)startPoint.getY(),
(int)endPoint.getX(), (int)endPoint.getY());
}
示例12: drawSelection
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawSelection(Graphics2D g2d) {
selection.setFrameFromDiagonal(start, end);
Rectangle select = this.selection.getBounds();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.setStroke(new BasicStroke(1.8f));
g2d.setColor(Color.RED);
g2d.drawRect(select.x, select.y, select.width, select.height);
}
示例13: drawSelectLine
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draw the selected line of the convex hull
* and the information about it
* @param g Graphic object
* @param p1 The first point of the line
* @param p2 The second point of the line
* @param s3d Information aboute the classes
* @param classNames The name of the classes
*/
public void drawSelectLine(Graphics2D g, DPoint p1, DPoint p2, Vector<Object> s3d, String[] classNames) {
if ((p1 != null) && (p2 != null)) {
//Draw the selected line
Stroke oldStro = g.getStroke();
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
g.setStroke(stroke);
g.setColor(Color.BLACK);
g.drawLine((int) (p1.getX() * scale) + tran_x, tran_y - (int) (p1.getY() * scale), (int) (p2.getX() * scale) + tran_x, tran_y
- (int) (p2.getY() * scale));
g.setStroke(oldStro);
//Set the middle point
int x = (int) p2.getX() + (int) ((p1.getX() - p2.getX()) / 2);
int y = (int) p2.getY() + (int) ((p1.getY() - p2.getY()) / 2);
x = (int) (x * scale) + tran_x + (pointSize + 3);
y = tran_y - (int) (y * scale) - (pointSize + 1);
Font label = new Font("Arial", Font.PLAIN, 7 + pointSize);
g.setFont(label);
//Draw the label
for (int i = 0; i < s3d.size(); i++) {
// Current sector
FinalSect2D sect = (FinalSect2D) s3d.get(i);
String pb11 = format2Dec.format(sect.getBeta11() * 100);
String pb12 = format2Dec.format(sect.getBeta1() * 100);
String pb21 = format2Dec.format(sect.getBeta22() * 100);
String pb22 = format2Dec.format(sect.getBeta2() * 100);
if (sect.countStation() < 2) {
continue;
}
Station2D d1 = (sect.getstation()).get(0);
Station2D d2 = (sect.getstation()).get(1);
int d1x = (int) (d1.getVert()).getX();
int d1y = (int) (d1.getVert()).getY();
int d2x = (int) (d2.getVert()).getX();
int d2y = (int) (d2.getVert()).getY();
int p1x = (int) (p1.getX() * 100);
int p1y = (int) (p1.getY() * 100);
int p2x = (int) (p2.getX() * 100);
int p2y = (int) (p2.getY() * 100);
double t1 = ((p1.getY() - p2.getY()) / ((p2.getX() * p1.getY()) - (p1.getX() * p2.getY())));
double t2 = ((p2.getX() - p1.getX()) / ((p2.getX() * p1.getY()) - (p1.getX() * p2.getY())));
if (((d1x == p1x) && (d1y == p1y) && (d2x == p2x) && (d2y == p2y)) || ((d1x == p2x) && (d1y == p2y) && (d2x == p1x) && (d2y == p1y))) {
g.drawString(classNames[0] + "=" + format4Dec.format(t1) + " job/sec", x, y - (8 + pointSize));
g.drawString(classNames[1] + "=" + format4Dec.format(t2) + " job/sec", x, y);
g.drawString(classNames[1] + "% [" + pb22 + "," + pb12 + "]", x, y - 2 * (8 + pointSize));
g.drawString(classNames[0] + "% [" + pb21 + "," + pb11 + "]", x, y - 3 * (8 + pointSize));
break;
}
}
}
}
示例14: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g) {
if( !loaded ) return;
if(display.data != null)display.data.currentPoint = null;
Stroke stroke = g.getStroke();
if( types==0 ) {
g.setStroke( new BasicStroke( 1f/(float)map.getZoom() ));
if(enabled && display.data != null) display.data.draw(g);
g.setStroke(stroke);
return;
}
g.setStroke( new BasicStroke( 1f/(float)map.getZoom() ));
Rectangle2D rect = map.getClipRect2D();
int temp = selectedIndex;
model.clearTracks();
selectedIndex = temp;
if(enabled) {
g.setColor(Color.black);
} else {
g.setColor(Color.darkGray);
}
for( int i=0 ; i<size ; i++) {
// if( (types & tracks[i].getTypes()) ==0)continue;
if( (types & tracks[i].getTypes()) ==0)continue;
if( !tracks[i].intersects(rect) && !tracks[i].getName().equals(IMPORT_TRACK_LINE.getName())) continue;
if( i==dataIndex && display.data != null) display.data.draw(g);
else tracks[i].draw(g);
model.addTrack(tracks[i], i);
}
if(enabled && display.data != null) display.data.draw(g);
if((selectedIndex>=0) && (selectedIndex<size)) {
if(enabled) {
g.setColor(Color.white);
} else {
g.setColor(Color.lightGray);
}
if( selectedIndex==dataIndex && display.data != null) display.data.draw(g);
else tracks[selectedIndex].draw(g);
}
model.updateList();
selectedIndex = temp;
g.setStroke(stroke);
if( enabled && selectedIndex!=-1 ) {
int index = model.indexOf(tracks[selectedIndex]);
synchronized( map.getTreeLock() ) {
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
// list.setSelectedValue( tracks[selectedIndex], true );
}
}
示例15: drawTick
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws a tick on the dial.
*
* @param g2 the graphics device.
* @param meterArea the meter area.
* @param value the tick value.
* @param label a flag that controls whether or not a value label is drawn.
*/
protected void drawTick(Graphics2D g2, Rectangle2D meterArea,
double value, boolean label) {
double valueAngle = valueToAngle(value);
double meterMiddleX = meterArea.getCenterX();
double meterMiddleY = meterArea.getCenterY();
g2.setPaint(this.tickPaint);
g2.setStroke(new BasicStroke(2.0f));
double valueP2X = 0;
double valueP2Y = 0;
double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
double radius1 = radius - 15;
double valueP1X = meterMiddleX
+ (radius * Math.cos(Math.PI * (valueAngle / 180)));
double valueP1Y = meterMiddleY
- (radius * Math.sin(Math.PI * (valueAngle / 180)));
valueP2X = meterMiddleX
+ (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
valueP2Y = meterMiddleY
- (radius1 * Math.sin(Math.PI * (valueAngle / 180)));
Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X,
valueP2Y);
g2.draw(line);
if (this.tickLabelsVisible && label) {
String tickLabel = this.tickLabelFormat.format(value);
g2.setFont(this.tickLabelFont);
g2.setPaint(this.tickLabelPaint);
FontMetrics fm = g2.getFontMetrics();
Rectangle2D tickLabelBounds
= TextUtilities.getTextBounds(tickLabel, g2, fm);
double x = valueP2X;
double y = valueP2Y;
if (valueAngle == 90 || valueAngle == 270) {
x = x - tickLabelBounds.getWidth() / 2;
}
else if (valueAngle < 90 || valueAngle > 270) {
x = x - tickLabelBounds.getWidth();
}
if ((valueAngle > 135 && valueAngle < 225)
|| valueAngle > 315 || valueAngle < 45) {
y = y - tickLabelBounds.getHeight() / 2;
}
else {
y = y + tickLabelBounds.getHeight() / 2;
}
g2.drawString(tickLabel, (float) x, (float) y);
}
}