use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.
the class AAShapePipe method draw.
public void draw(SunGraphics2D sg, Shape s) {
BasicStroke bs;
if (sg.stroke instanceof BasicStroke) {
bs = (BasicStroke) sg.stroke;
} else {
s = sg.stroke.createStrokedShape(s);
bs = null;
}
renderPath(sg, s, bs);
}
use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.
the class LoopPipe method getStrokeSpans.
/*
* Return a ShapeSpanIterator ready to iterate the spans of the wide
* outline of Shape s using the attributes of the SunGraphics2D
* object.
*
* The ShapeSpanIterator returned will be fully constructed
* and filled with the geometry from the Shape widened by the
* appropriate BasicStroke and normalization parameters taken
* from the SunGraphics2D object and be ready to start returning
* spans.
*
* Note that the caller is responsible for calling dispose()
* on the returned ShapeSpanIterator inside a try/finally block.
* <pre>
* ShapeSpanIterator ssi = LoopPipe.getStrokeSpans(sg2d, s);
* try {
* // iterate the spans from ssi and operate on them
* } finally {
* ssi.dispose();
* }
* </pre>
*
* REMIND: This should return a SpanIterator interface object
* but the caller needs to dispose() the object and that method
* is only on ShapeSpanIterator.
* TODO: Add a dispose() method to the SpanIterator interface.
*/
public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d, Shape s) {
ShapeSpanIterator sr = new ShapeSpanIterator(false);
try {
sr.setOutputArea(sg2d.getCompClip());
sr.setRule(PathIterator.WIND_NON_ZERO);
BasicStroke bs = (BasicStroke) sg2d.stroke;
boolean thin = (sg2d.strokeState <= SunGraphics2D.STROKE_THINDASHED);
boolean normalize = (sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
RenderEngine.strokeTo(s, sg2d.transform, bs, thin, normalize, false, sr);
} catch (Throwable t) {
sr.dispose();
sr = null;
throw new InternalError("Unable to Stroke shape (" + t.getMessage() + ")", t);
}
return sr;
}
use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.
the class BorderFactory method createDashedBorder.
/**
* Creates a dashed border of the specified {@code paint}, {@code thickness},
* line shape, relative {@code length}, and relative {@code spacing}.
* If the specified {@code paint} is {@code null},
* the component's foreground color will be used to render the border.
*
* @param paint the {@link Paint} object used to generate a color
* @param thickness the width of a dash line
* @param length the relative length of a dash line
* @param spacing the relative spacing between dash lines
* @param rounded whether or not line ends should be round
* @return the {@code Border} object
*
* @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or
* if the specified {@code length} is less than {@code 1}, or
* if the specified {@code spacing} is less than {@code 0}
* @since 1.7
*/
public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) {
boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f);
if (shared && (sharedDashedBorder != null)) {
return sharedDashedBorder;
}
if (thickness < 1.0f) {
throw new IllegalArgumentException("thickness is less than 1");
}
if (length < 1.0f) {
throw new IllegalArgumentException("length is less than 1");
}
if (spacing < 0.0f) {
throw new IllegalArgumentException("spacing is less than 0");
}
int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE;
int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER;
float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) };
Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint);
if (shared) {
sharedDashedBorder = border;
}
return border;
}
use of java.awt.BasicStroke in project JMRI by JMRI.
the class RpsTrackingPanel method paint.
@Override
public void paint(Graphics g) {
// draw everything else
super.paint(g);
log.debug("paint invoked");
// Now show regions
// First, Graphics2D setup
Graphics2D g2 = (Graphics2D) g;
double xscale = this.getWidth() / (xmax - xorigin);
double yscale = this.getHeight() / (ymax - yorigin);
Stroke stroke = new BasicStroke((float) (2. / xscale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
g2.setStroke(stroke);
// Save the current transform
AffineTransform saveAT = g2.getTransform();
// Install the new one
currentAT = new AffineTransform();
currentAT.translate(0, this.getHeight());
currentAT.scale(xscale, -yscale);
// put origin in bottom corner
currentAT.translate(-xorigin, -yorigin);
g2.setTransform(currentAT);
if (showRegions) {
// Draw the regions
List<Region> l = Model.instance().getRegions();
for (int i = 0; i < l.size(); i++) {
g2.setPaint(regionOutlineColor);
// border (same color)
g2.draw(l.get(i).getPath());
g2.setPaint(regionFillColor);
g2.fill(l.get(i).getPath());
}
}
// Draw the measurements; changes graphics
for (int i = 0; i < measurementRepList.size(); i++) {
measurementRepList.get(i).draw(g2);
}
if (showReceivers) {
// draw receivers
for (int i = 1; i < Engine.instance().getMaxReceiverNumber() + 1; i++) {
// indexed from 1
Receiver r = Engine.instance().getReceiver(i);
Point3d p = Engine.instance().getReceiverPosition(i);
if (p != null && r != null) {
if (r.isActive()) {
g2.setPaint(Color.BLACK);
} else {
g2.setPaint(Color.GRAY);
}
Shape s = new Ellipse2D.Double(p.x - RECEIVER_SIZE / 2, p.y - RECEIVER_SIZE / 2, RECEIVER_SIZE, RECEIVER_SIZE);
g2.draw(s);
g2.fill(s);
}
}
}
// restore original transform
g2.setTransform(saveAT);
}
use of java.awt.BasicStroke in project processdash by dtuma.
the class LevelIndicator method paintComponent.
protected void paintComponent(Graphics g) {
int w = getWidth();
int h = getHeight();
if (w < 1 || h < 1)
return;
// fill with the background color.
g.setColor(bgColor);
g.fillRect(0, 0, w, h);
// create a new graphics context that removes DPI-based scaling, so we
// can perform our remaining operations with pixel precision
Graphics2D g2 = (Graphics2D) g.create();
AffineTransform t = g2.getTransform();
w = (int) (0.5 + w * t.getScaleX());
h = (int) (0.5 + h * t.getScaleY());
g2.scale(1 / t.getScaleX(), 1 / t.getScaleY());
g2.setStroke(new BasicStroke(1));
// draw the grid
g2.setColor(gridColor);
int space = (int) (gridSpacing * t.getScaleX());
for (int x = space / 2; x < w; x += space) g2.drawLine(x, 0, x, h - 1);
for (int y = 1; y < h; y += space) g2.drawLine(-1, y, w - 1, y);
// how wide/tall should the bar be, based on the current level?
int extent = (int) Math.round((vertical ? h : w) * level);
if (extent == 0 && level > 0)
extent = 1;
if (extent > 0) {
if (vertical) {
Color[] gradient = getBarGradient(w + 1);
for (int x = 0; x < gradient.length; x++) {
g2.setColor(gradient[x]);
g2.drawLine(x - 1, h - extent, x - 1, h - 1);
}
g2.setColor(barColor);
if (paintBarRect)
g2.drawRect(0, h - extent, w - 1, extent - 1);
else if (extent < h)
g2.drawLine(-1, h - extent, w - 1, h - extent);
} else {
Color[] gradient = getBarGradient(h + 1);
for (int y = 0; y < gradient.length; y++) {
g2.setColor(gradient[y]);
g2.drawLine(0, y - 1, extent - 1, y - 1);
}
g2.setColor(barColor);
if (paintBarRect)
g2.drawRect(0, 0, extent - 1, h - 1);
else if (extent < w)
g2.drawLine(extent - 1, -1, extent - 1, h - 1);
}
}
}
Aggregations