use of java.awt.GradientPaint in project processdash by dtuma.
the class HierarchyNoteIcon method paintIcon.
@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
// fill the background area and trace its outline
Shape shape = new RoundRectangle2D.Float(0, 0, width - 1, height - 1, 5 * scale, 5 * scale);
g2.setPaint(new GradientPaint(0, 0, fill, width, height, Color.white));
g2.fill(shape);
g2.setStroke(new BasicStroke(1));
g2.setColor(edge);
g2.draw(shape);
// draw text in the center
int x = (int) (2 * Math.min(scale, 2));
int y = (int) (3 * scale);
int lineSpacing = (int) (2.3 * scale);
g2.setClip(new RoundRectangle2D.Float(x, x, width - 2 * x, height - 2 * x, 2 * scale, 2 * scale));
g2.setFont(new Font("Dialog", Font.BOLD, 10).deriveFont(1.9f * scale));
g2.setColor(text);
String s = TEXT;
while (y <= height - 2) {
g2.drawString(s, x, y);
s = s.substring(10);
y += lineSpacing;
}
}
use of java.awt.GradientPaint in project processdash by dtuma.
the class RangeXYItemRenderer method drawItemRangeGradient.
private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2, double x3, double y3) {
Line2D edge1, edge2, mainLine;
Polygon fillArea;
Stroke mainLineStroke, edgeLineStroke;
Paint mainLinePaint, edgeLinePaint, fillPaint;
double x0 = line.getX1();
double y0 = line.getY1();
double x1 = line.getX2();
double y1 = line.getY2();
mainLine = new Line2D.Double(x0, y0, x1, y1);
edge1 = new Line2D.Double(x0, y0, x2, y2);
edge2 = new Line2D.Double(x0, y0, x3, y3);
fillArea = new Polygon();
fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0));
fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2));
fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3));
mainLinePaint = paint;
if (mainLinePaint instanceof Color) {
Color c = (Color) mainLinePaint;
Color dark = transp(c, calcAlpha(c));
Color light = transp(c, 0.01);
edgeLinePaint = fillPaint = c;
try {
fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light, new Point2D.Double(x1, y1), dark, true);
} catch (Exception e) {
}
} else {
edgeLinePaint = fillPaint = mainLinePaint;
}
if (stroke instanceof BasicStroke) {
float lineWidth = ((BasicStroke) stroke).getLineWidth();
edgeLineStroke = new BasicStroke(lineWidth / 4);
mainLineStroke = new BasicStroke(lineWidth * 2);
} else {
mainLineStroke = edgeLineStroke = stroke;
}
g2.setPaint(fillPaint);
g2.fill(fillArea);
g2.fill(fillArea);
g2.setStroke(edgeLineStroke);
g2.setPaint(edgeLinePaint);
g2.draw(edge1);
g2.draw(edge2);
g2.setStroke(mainLineStroke);
g2.setPaint(mainLinePaint);
g2.draw(mainLine);
}
use of java.awt.GradientPaint in project processdash by dtuma.
the class TrashCanIcon method paintIcon.
@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
// calculate the gradient for shading
Color shadow = PaintUtils.mixColors(fill, edge, 0.3f);
GradientPaint gradient = new GradientPaint(0, 0, fill, width, 0, shadow);
// draw the can
float s2 = 2 * scale;
int hPad = (int) s2;
int ww = width - 2 * hPad - 2;
int top = (int) (2 * scale + 1);
RoundRectangle2D can = new //
RoundRectangle2D.Float(//
hPad, //
top, ww, height - top - 1, s2, s2);
g2.setPaint(gradient);
g2.fill(can);
g2.setColor(edge);
g2.draw(can);
// draw lines on the can
int lineSpacing = Math.min(5, Math.max(2, ww / 5));
int lineIndent = Math.max(2, (lineSpacing + ww % lineSpacing) / 2);
for (int x = hPad + lineIndent; x < can.getMaxX() - 1; x += lineSpacing) g2.drawLine(x, top, x, height - 3);
// draw the handle
hPad = (int) (5 * scale);
ww = width - 2 * hPad - 2;
g2.setStroke(new BasicStroke(1));
g2.setColor(edge);
g2.draw(new RoundRectangle2D.Float(hPad, 0, ww, 3 * scale, s2, s2));
// draw the lid
hPad = (int) scale;
ww = width - 2 * hPad - 2;
int lh = (int) (2 * scale + 0.5);
Area lid = new Area();
lid.add(new Area(new //
RoundRectangle2D.Float(//
hPad, //
2 * hPad, ww, lh * 2, s2, s2)));
lid.intersect(new Area(new Rectangle2D.Float(hPad, 2 * hPad, ww, lh)));
g2.setPaint(gradient);
g2.fill(lid);
g2.setPaint(edge);
g2.draw(lid);
}
Aggregations