use of java.awt.BasicStroke in project JMRI by JMRI.
the class LayoutSlip method drawSlipState.
private void drawSlipState(Graphics2D g2, int state) {
int ctrX = 20;
int ctrY = 20;
Point2D ldispA = new Point2D.Double(-20.0, 0.0);
Point2D ldispB = new Point2D.Double(-14.0, 14.0);
g2.setColor(Color.black);
Point2D A = new Point2D.Double(ctrX + ldispA.getX(), ctrY + ldispA.getY());
Point2D B = new Point2D.Double(ctrX + ldispB.getX(), ctrY + ldispB.getY());
Point2D C = new Point2D.Double(ctrX - ldispA.getX(), ctrY - ldispA.getY());
Point2D D = new Point2D.Double(ctrX - ldispB.getX(), ctrY - ldispB.getY());
g2.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, C)));
g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, A)));
if (state == STATE_AC || state == STATE_BD || state == UNKNOWN) {
g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
if (getSlipType() == DOUBLE_SLIP) {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
}
} else {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
}
if (getSlipType() == DOUBLE_SLIP) {
if (state == STATE_AC) {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
g2.setColor(Color.red);
g2.draw(new Line2D.Double(A, C));
} else if (state == STATE_BD) {
g2.setColor(Color.red);
g2.draw(new Line2D.Double(B, D));
} else if (state == STATE_AD) {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
g2.setColor(Color.red);
g2.draw(new Line2D.Double(A, D));
} else if (state == STATE_BC) {
g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
g2.setColor(Color.red);
g2.draw(new Line2D.Double(B, C));
} else {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
}
} else {
g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
if (state == STATE_AD) {
g2.setColor(Color.red);
g2.draw(new Line2D.Double(A, D));
} else if (state == STATE_AC) {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
g2.setColor(Color.red);
g2.draw(new Line2D.Double(A, C));
} else if (state == STATE_BD) {
g2.setColor(Color.red);
g2.draw(new Line2D.Double(B, D));
} else {
g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
}
}
}
use of java.awt.BasicStroke in project JMRI by JMRI.
the class TrackSegment method drawDashed.
// drawHidden(Graphics2D g2)
public void drawDashed(Graphics2D g2, boolean mainline) {
if ((!isHidden()) && getDashed() && (mainline == getMainline())) {
setColorForTrackBlock(g2, getLayoutBlock());
float trackWidth = layoutEditor.setTrackStrokeWidth(g2, mainline);
if (getArc()) {
calculateTrackSegmentAngle();
Stroke originalStroke = g2.getStroke();
Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
g2.setStroke(drawingStroke);
g2.draw(new Arc2D.Double(getCX(), getCY(), getCW(), getCH(), getStartadj(), getTmpAngle(), Arc2D.OPEN));
g2.setStroke(originalStroke);
} else if (getBezier()) {
Stroke originalStroke = g2.getStroke();
Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
g2.setStroke(drawingStroke);
Point2D pt1 = layoutEditor.getCoords(getConnect1(), getType1());
Point2D pt2 = layoutEditor.getCoords(getConnect2(), getType2());
int cnt = bezierControlPoints.size();
Point2D[] points = new Point2D[cnt + 2];
points[0] = pt1;
for (int idx = 0; idx < cnt; idx++) {
points[idx + 1] = bezierControlPoints.get(idx);
}
points[cnt + 1] = pt2;
MathUtil.drawBezier(g2, points);
g2.setStroke(originalStroke);
} else {
Point2D end1 = layoutEditor.getCoords(getConnect1(), getType1());
Point2D end2 = layoutEditor.getCoords(getConnect2(), getType2());
double delX = end1.getX() - end2.getX();
double delY = end1.getY() - end2.getY();
double cLength = Math.hypot(delX, delY);
// note: The preferred dimension of a dash (solid + blank space) is
// 5 * the track width - about 60% solid and 40% blank.
int nDashes = (int) (cLength / ((trackWidth) * 5.0));
if (nDashes < 3) {
nDashes = 3;
}
double delXDash = -delX / ((nDashes) - 0.5);
double delYDash = -delY / ((nDashes) - 0.5);
double begX = end1.getX();
double begY = end1.getY();
for (int k = 0; k < nDashes; k++) {
g2.draw(new Line2D.Double(new Point2D.Double(begX, begY), new Point2D.Double(begX + (delXDash * 0.5), begY + (delYDash * 0.5))));
begX += delXDash;
begY += delYDash;
}
}
}
}
use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.
the class Test7019861 method main.
public static void main(String[] argv) throws Exception {
BufferedImage im = getWhiteImage(30, 30);
Graphics2D g2 = (Graphics2D) im.getGraphics();
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);
g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g2.setBackground(Color.white);
g2.setColor(Color.black);
Path2D p = getPath(0, 0, 20);
g2.draw(p);
if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) {
throw new Exception("This pixel should be black");
}
}
use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.
the class DrawXORModeTest method paint.
@Override
public void paint(Graphics g) {
if (g == null || !(g instanceof Graphics2D)) {
return;
}
g.setColor(Color.white);
g.setXORMode(Color.black);
Graphics2D dg = (Graphics2D) g;
Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f);
dg.setStroke(stroke);
try {
dg.draw(new Line2D.Float(10, 10, 20, 20));
} catch (Throwable e) {
synchronized (this) {
theError = e;
}
} finally {
didDraw.countDown();
}
}
use of java.awt.BasicStroke in project processdash by dtuma.
the class FloppyDiskIcon method paintIcon.
@Override
protected void paintIcon(Graphics2D g2, Shape clip, float scale) {
// fill the background
g2.setColor(highlight);
g2.fill(area);
// paint the shutter
g2.setColor(gray);
g2.fill(new Rectangle2D.Float(5, 1, 6, 5 + 1 / scale));
g2.setColor(white);
g2.fill(new Rectangle2D.Float(8, 2 + 1 / scale, 2, 3));
// paint the label
g2.clip(area);
g2.setColor(white);
g2.fill(label);
g2.setStroke(new BasicStroke(1 / scale));
g2.setColor(gray);
g2.draw(label);
// draw text on the label
g2.setColor(highlight);
int t = 1;
for (float f = 10; f < 13; f += 2 / scale) {
g2.draw(new Line2D.Float(5, f, 10 - t, f));
t = (t + 2) % 3;
}
// paint the outer edge
g2.setClip(clip);
g2.setColor(edge);
g2.draw(area);
}
Aggregations