use of java.awt.BasicStroke in project processdash by dtuma.
the class MilestoneIcon method paintIcon.
@Override
protected void paintIcon(Graphics2D g2, Shape clip, float scale) {
// fill the shape
g2.setColor(fill);
g2.fill(shape);
// draw shadow (bottom-right edge)
g2.setStroke(BEVEL);
g2.setColor(shadow);
clip(g2, clip, edges[1]);
g2.draw(shape);
// draw highlights (top-right and bottom-left edges)
g2.setColor(highlight);
clip(g2, clip, edges[0]);
g2.draw(shape);
clip(g2, clip, edges[2]);
g2.draw(shape);
// draw glare (top-left edge)
g2.setColor(glare);
clip(g2, clip, edges[3]);
g2.draw(shape);
// draw outline
g2.setStroke(new BasicStroke(Math.min(scale, 1) / scale));
g2.setColor(edge);
g2.setClip(clip);
g2.draw(shape);
}
use of java.awt.BasicStroke in project n2a by frothga.
the class RoundedPanel method paintComponent.
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
int shadowGap = this.shadowGap;
Color shadowColorA = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), shadowAlpha);
Graphics2D graphics = (Graphics2D) g;
// Sets antialiasing if HQ.
if (highQuality) {
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
// Draws shadow borders if any.
if (shady) {
graphics.setColor(shadowColorA);
graphics.fillRoundRect(// X position
shadowOffset, // Y position
shadowOffset, // width
width - strokeSize - shadowOffset, // height
height - strokeSize - shadowOffset, arcs.width, // arc Dimension
arcs.height);
} else {
shadowGap = 1;
}
// Draws the rounded opaque panel with borders.
graphics.setColor(getBackground());
graphics.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
graphics.setColor(getForeground());
graphics.setStroke(new BasicStroke(strokeSize));
graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
// System.out.println(height);
// Sets strokes to default, is better.
graphics.setStroke(new BasicStroke());
}
use of java.awt.BasicStroke in project Lucee by lucee.
the class ScratchFilter method filter.
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (dst == null)
dst = createCompatibleDestImage(src, null);
int width = src.getWidth();
int height = src.getHeight();
int numScratches = (int) (density * width * height / 100);
ArrayList lines = new ArrayList();
{
float l = length * width;
Random random = new Random(seed);
Graphics2D g = dst.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(new Color(color));
g.setStroke(new BasicStroke(this.width));
for (int i = 0; i < numScratches; i++) {
float x = width * random.nextFloat();
float y = height * random.nextFloat();
float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
float s = (float) Math.sin(a) * l;
float c = (float) Math.cos(a) * l;
float x1 = x - c;
float y1 = y - s;
float x2 = x + c;
float y2 = y + s;
g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
lines.add(new Line2D.Float(x1, y1, x2, y2));
}
g.dispose();
}
if (false) {
// int[] inPixels = getRGB( src, 0, 0, width, height, null );
int[] inPixels = new int[width * height];
int index = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
float sx = x, sy = y;
for (int i = 0; i < numScratches; i++) {
Line2D.Float l = (Line2D.Float) lines.get(i);
float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
if (dot > 0)
inPixels[index] |= (1 << i);
}
index++;
}
}
Colormap colormap = new LinearColormap();
index = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
inPixels[index] = colormap.getColor(f);
index++;
}
}
setRGB(dst, 0, 0, width, height, inPixels);
}
return dst;
}
use of java.awt.BasicStroke in project knime-core by knime.
the class HistogramColumn method paint.
/**
* Paints the {@code histogramData} to {@code g}.
*
* @param histogramData A {@link HistogramNumericModel}.
* @param g A {@link Graphics2D} object.
*/
private void paint(final HistogramModel<?> histogramData, final Graphics2D g) {
double binWidth = binWidth(histogramData);
int height = m_showMinMax && histogramData instanceof HistogramNumericModel ? m_height - MIN_MAX_AREA_HEIGHT : m_height;
// g.setFont(Font.getFont("Arial").deriveFont((float)(binWidth * .8d)));
g.setColor(m_fillColor);
if (histogramData.getBins().isEmpty()) {
g.setColor(new Color(0, 0, 0, 0));
g.drawRect(0, 0, m_width, m_height);
}
for (int i = histogramData.getBins().size(); i-- > 0; ) {
HistogramModel.Bin<?> bin = histogramData.getBins().get(i);
int upperPosition = upperPosition(histogramData, bin);
g.fillRect((int) (i * binWidth), upperPosition, (int) Math.ceil(binWidth), height - upperPosition);
}
g.setColor(m_lineColor);
g.drawLine(0, height, m_width, height);
g.setStroke(new BasicStroke(1.5f));
for (int i = histogramData.getBins().size(); i-- > 0; ) {
HistogramModel.Bin<?> bin = histogramData.getBins().get(i);
int startX = (int) (i * binWidth), nextX = (int) ((i + 1) * binWidth), upper = upperPosition(histogramData, bin);
drawCap(g, startX, nextX, upper, height);
}
g.setColor(ColorAttr.HILITE);
for (int i = histogramData.getBins().size(); i-- > 0; ) {
Bin<?> bin = histogramData.getBins().get(i);
if (bin.getHiLited() > 0) {
int upper = upperPosition(histogramData.getReferenceNumber(), bin.getHiLited());
g.fillRect((int) (i * binWidth), upper, (int) Math.ceil(binWidth), height - upper);
}
}
// g.setColor(ColorAttr.SELECTED_HILITE);
g.setColor(m_lineColor);
for (int i = histogramData.getBins().size(); i-- > 0; ) {
HistogramModel.Bin<?> bin = histogramData.getBins().get(i);
int startX = (int) (i * binWidth), nextX = (int) ((i + 1) * binWidth);
if (bin.getHiLited() > 0) {
int upper = upperPosition(histogramData.getReferenceNumber(), bin.getHiLited());
drawCap(g, startX, nextX, upper, height);
}
}
if (m_showMinMax) {
paintMinMax(histogramData, g, height);
}
}
use of java.awt.BasicStroke in project knime-core by knime.
the class ParallelCoordinateDrawingPane method drawCurve.
/**
* Draws a quad curve between the mapped data points of one
* {@link org.knime.base.node.viz.plotter.parcoord.LineInfo}.
*
* @param g graphics object
* @param line one line / row
*/
private void drawCurve(final Graphics2D g, final LineInfo line) {
// for each line
GeneralPath path = null;
Point ctrl = null;
// Point newCtrl = null;
if (m_fade && !line.isHilite()) {
if (line.isSelected()) {
g.setColor(ColorAttr.INACTIVE_SELECTED);
} else {
g.setColor(ColorAttr.INACTIVE);
}
} else if (!m_hide && !m_fade) {
g.setColor(line.getColor().getColor(line.isSelected(), line.isHilite()));
} else {
// bugfix : 1278
g.setColor(line.getColor().getColor(line.isSelected(), false));
}
int lineSize = getStrokeSize(line.getSize());
Stroke selectionStroke = new BasicStroke(lineSize, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { DASH }, 0);
((Graphics2D) g).setStroke(new BasicStroke(lineSize));
// for all points
for (int i = 0; i < line.getPoints().size() - 1; i++) {
Point p1 = line.getPoints().get(i);
Point p2 = line.getPoints().get(i + 1);
if (path == null) {
path = new GeneralPath();
path.moveTo(p1.x, p1.y);
// first control Point with offset
int x = p1.x + ((p2.x - p1.x) / 2);
int y = p1.y + ((p2.y - p1.y) / 2) + 10;
ctrl = new Point(x, y);
}
// create cubic curve
int firstX = p1.x + ((p2.x - p1.x) / 3);
int secondX = p1.x + ((p2.x - p1.x) / 2);
Point firstCtrl = getNextControlPoint(ctrl, p1, firstX);
Point secondCtrl = createAdditionalCtrlPoint(secondX, p2, firstCtrl);
path.curveTo(firstCtrl.x, firstCtrl.y, secondCtrl.x, secondCtrl.y, p2.x, p2.y);
ctrl = secondCtrl;
}
Color backupColor = g.getColor();
if (line.isHilite() && !m_hide && !m_fade) {
// draw additional "hilite" line
g.setColor(ColorAttr.HILITE);
Stroke backupStroke = g.getStroke();
g.setStroke(new BasicStroke(2 * lineSize));
g.draw(path);
g.setColor(backupColor);
g.setStroke(backupStroke);
}
g.draw(path);
if (line.isSelected()) {
// draw dotted line
Stroke backupStroke = ((Graphics2D) g).getStroke();
((Graphics2D) g).setStroke(selectionStroke);
g.setXORMode(Color.white);
g.draw(path);
((Graphics2D) g).setStroke(backupStroke);
g.setPaintMode();
}
if (m_showDots) {
for (Point p : line.getPoints()) {
int size = getStrokeSize(line.getSize());
paintDot(g, p, line, size);
}
}
}
Aggregations