use of java.awt.GradientPaint in project processdash by dtuma.
the class ReportsAndToolsIcon method paintLargeIconImpl.
private void paintLargeIconImpl(Graphics2D g2, int pw, int ph) {
// draw a white page with a black outline.
int pageHeight = ph - 1;
int pageWidth = ph * 9 / 11;
g2.setColor(Color.white);
g2.fillRect(0, 0, pageWidth, pageHeight);
g2.setColor(Color.gray);
g2.drawRect(0, 0, pageWidth, pageHeight);
// draw text onto the page
int pad = 1 + ph / 20;
float lineSpacing = Math.max(2, ph / 14);
float fontSize = 0.85f * lineSpacing;
float y = pad + lineSpacing;
g2.setClip(pad + 1, pad, pageWidth - 2 * pad, pageHeight - 2 * pad);
g2.setFont(new Font("Dialog", Font.PLAIN, 10).deriveFont(fontSize));
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setColor(Color.darkGray);
String s = TEXT;
while (y <= ph) {
g2.drawString(s, pad + 1, y);
s = s.substring(20);
if (s.charAt(0) == ' ')
s = s.substring(1);
y += lineSpacing;
}
// calculate the geometry for the chart in the lower-left corner
int barWidth = pageWidth / 5;
int chartHeight = (int) (pageHeight * 0.4);
int chartTop = pageHeight - pad - chartHeight;
Rectangle2D[] bars = new Rectangle2D[BAR_DELTA.length];
for (int i = bars.length; i-- > 0; ) {
float barGap = chartHeight * BAR_DELTA[i];
bars[i] = new Rectangle2D.Float(pad + 1 + barWidth * i, chartTop + barGap, barWidth, chartHeight);
}
// draw white areas to ensure the text doesn't run into the bars
g2.setColor(Color.white);
g2.setStroke(new BasicStroke(Math.max(3, 1 + pad * 1.2f)));
for (int i = bars.length; i-- > 0; ) g2.draw(bars[i]);
// draw the bars themselves
for (int i = bars.length; i-- > 0; ) {
Color light = PaintUtils.mixColors(BAR_COLORS[i], Color.white, 0.7);
g2.setPaint(new GradientPaint((int) bars[i].getX(), 0, BAR_COLORS[i], (int) bars[i].getMaxX(), 0, light));
g2.fill(bars[i]);
}
// draw the calculator
ImageIcon calc = loadImage("calc.png");
int calcHeight = ph * 2 / 3;
float calcScale = calcHeight / (float) calc.getIconHeight();
int calcWidth = (int) (0.5 + calc.getIconWidth() * calcScale);
int calcLeft = (int) (pageWidth - pad * 2 / 3);
int calcTop = ph / 4;
Image scaledCalc = new ImageIcon(//
calc.getImage().getScaledInstance(calcWidth, calcHeight, Image.SCALE_SMOOTH)).getImage();
g2.setClip(null);
g2.drawImage(scaledCalc, calcLeft, calcTop, null);
}
use of java.awt.GradientPaint in project processdash by dtuma.
the class CGIChartBase method writeContents.
/** Generate CGI chart output. */
@Override
protected void writeContents() throws IOException {
// get the data for display
buildData();
chromeless = (parameters.get("chromeless") != null);
JFreeChart chart = createChart();
int width = getIntSetting("width");
int height = getIntSetting("height");
Color initGradColor = getColorSetting("initGradColor");
Color finalGradColor = getColorSetting("finalGradColor");
chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
if (parameters.get("hideOutline") != null)
chart.getPlot().setOutlinePaint(INVISIBLE);
String title = getSetting("title");
if (chromeless || title == null || title.length() == 0)
chart.setTitle((TextTitle) null);
else {
chart.setTitle(Translator.translate(title));
String titleFontSize = getSetting("titleFontSize");
if (titleFontSize != null)
try {
float fontSize = Float.parseFloat(titleFontSize);
TextTitle t = chart.getTitle();
t.setFont(t.getFont().deriveFont(fontSize));
} catch (Exception tfe) {
}
}
if (chromeless || parameters.get("hideLegend") != null)
chart.removeLegend();
else {
LegendTitle l = chart.getLegend();
String legendFontSize = getSetting("legendFontSize");
if (l != null && legendFontSize != null)
try {
float fontSize = Float.parseFloat(legendFontSize);
l.setItemFont(l.getItemFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
}
chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));
Axis xAxis = getHorizontalAxis(chart);
if (xAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
xAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) {
String tfs = getParameter("xTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
}
}
Axis yAxis = getVerticalAxis(chart);
if (yAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
yAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) {
String tfs = getParameter("yTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
}
}
String axisFontSize = getSetting("axisLabelFontSize");
if (axisFontSize != null)
try {
float fontSize = Float.parseFloat(axisFontSize);
if (xAxis != null)
xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
if (yAxis != null)
yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
} catch (Exception afs) {
}
ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = img.createGraphics();
if ("auto".equals(getSetting("titleFontSize")))
maybeAdjustTitleFontSize(chart, g2, width);
chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
g2.dispose();
String outputFormat = getSetting("outputFormat");
OutputStream imgOut;
if (isHtmlMode()) {
imgOut = PngCache.getOutputStream();
} else {
imgOut = outStream;
}
ImageIO.write(img, outputFormat, imgOut);
imgOut.flush();
imgOut.close();
if (isHtmlMode())
writeImageHtml(width, height, imgOut.hashCode(), info);
}
use of java.awt.GradientPaint in project jdk8u_jdk by JetBrains.
the class TransformedPaintTest method createPaint.
private Paint createPaint(PaintType type, int startx, int starty, int w, int h) {
// make sure that the blue color doesn't show up when filling a
// w by h rect
w++;
h++;
int endx = startx + w;
int endy = starty + h;
Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
switch(type) {
case COLOR:
return Color.red;
case GRADIENT:
return new GradientPaint(startx, starty, Color.red, endx, endy, Color.green);
case LINEAR_GRADIENT:
return new LinearGradientPaint(startx, starty, endx, endy, new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue });
case RADIAL_GRADIENT:
return new RadialGradientPaint(startx, starty, (float) Math.sqrt(w * w + h * h), new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue }, CycleMethod.NO_CYCLE);
case TEXTURE:
{
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
g.fillRect(0, 0, w, h);
return new TexturePaint(bi, r);
}
}
return Color.green;
}
use of java.awt.GradientPaint in project processdash by dtuma.
the class FilterIcon method finalizeColors.
@Override
protected void finalizeColors() {
Color shadow = PaintUtils.mixColors(fill, Color.black, 0.3f);
this.gradient = new GradientPaint(width / 2, 0, fill, width, 0, shadow);
}
use of java.awt.GradientPaint in project processdash by dtuma.
the class FolderIcon method paintIcon.
@Override
protected void paintIcon(Graphics2D g2, Shape clip, float scale) {
// paint the back of the folder
g2.setColor(shadow);
g2.fill(back);
g2.setStroke(new BasicStroke(1 / scale));
g2.setColor(edge);
g2.draw(back);
// paint the front of the folder
g2.setPaint(new GradientPaint(12, 7, fill, 13, 12, shadow));
g2.fill(front);
g2.setColor(edge);
g2.draw(front);
}
Aggregations