Files
VisualForecast-1000/src/com/flaremicro/visualforecast/graphics/DrawingUtil.java
Flare Microsystems 0564334f93 Added providers
2024-03-07 14:12:38 -08:00

77 lines
2.9 KiB
Java

package com.flaremicro.visualforecast.graphics;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Polygon;
public class DrawingUtil {
public static void drawGradientRect(Graphics2D g, int x, int y, int w, int h, int borderWidth, Color innerColor, Color outerColor) {
g.setColor(innerColor);
g.fillRect(x, y, w, h);
g.setPaint(new GradientPaint(x, 0, outerColor, x + borderWidth, 0, innerColor));
g.fillRect(x, y, borderWidth, h);
g.setPaint(new GradientPaint(x + w - borderWidth, 0, innerColor, x + w, 0, outerColor));
g.fillRect(x + w - borderWidth, y, borderWidth, h);
g.setPaint(new GradientPaint(0, y, outerColor, 0, y + borderWidth, innerColor));
g.setClip(new Polygon(new int[] { x, x + w, x + w - borderWidth, x + borderWidth }, new int[] { y, y, y + borderWidth, y + borderWidth }, 4));
g.fillRect(x, y, w, borderWidth);
g.setClip(new Polygon(new int[] { x, x + w, x + w - borderWidth, x + borderWidth }, new int[] { y + h, y + h, y + h - borderWidth, y + h - borderWidth }, 4));
g.setPaint(new GradientPaint(0, y + h - borderWidth, innerColor, 0, y + h, outerColor));
g.fillRect(x, y + h - borderWidth, w, borderWidth);
g.setClip(null);
}
public static void drawOutlinedString(Graphics2D g2d, int x, int y, String text, Color textColor, Color outline, int outlineSize) {
g2d.setColor(outline);
for (int i = 1; i <= outlineSize; i++)
{
g2d.drawString(text, x + i, y);
g2d.drawString(text, x - i, y);
g2d.drawString(text, x, y + i);
g2d.drawString(text, x, y - i);
g2d.drawString(text, x + i, y + i);
g2d.drawString(text, x - i, y - i);
g2d.drawString(text, x - i, y + i);
g2d.drawString(text, x + i, y - i);
}
g2d.setColor(textColor);
g2d.drawString(text, x, y);
/*
* AffineTransform transform = g2d.getTransform();
* transform.translate(x, y); g2d.transform(transform);
* g2d.setColor(outline); FontRenderContext frc =
* g2d.getFontRenderContext(); TextLayout tl = new TextLayout(text,
* g2d.getFont(), frc); Shape shape = tl.getOutline(null);
* g2d.setStroke(new BasicStroke(outlineSize)); g2d.draw(shape);
* g2d.setColor(textColor); g2d.fill(shape);
*/
}
public static void drawOutlinedString(Graphics2D g2d, int x, int y, String text, Color textColor, Color outline, int outlineSize, float outlineStep) {
g2d.setColor(outline);
for (int i = 1; i <= outlineSize; i++)
{
g2d.drawString(text, x + i*outlineStep, y);
g2d.drawString(text, x - i*outlineStep, y);
g2d.drawString(text, x, y + i*outlineStep);
g2d.drawString(text, x, y - i*outlineStep);
g2d.drawString(text, x + i*outlineStep, y + i*outlineStep);
g2d.drawString(text, x - i*outlineStep, y - i*outlineStep);
g2d.drawString(text, x - i*outlineStep, y + i*outlineStep);
g2d.drawString(text, x + i*outlineStep, y - i*outlineStep);
}
g2d.setColor(textColor);
g2d.drawString(text, x, y);
}
}