Java Utililty Methods Graphics Draw

List of utility methods to do Graphics Draw

Description

The list of methods to do Graphics Draw are organized into topic(s).

Method

voiddrawFilledOctagon(Graphics2D g, int x, int y, float size)
Draw a filled octagon at the specified position with the specified size
if (octagon == null) {
    octagon = new Polygon();
    octagon.addPoint(-3, -7); 
    octagon.addPoint(3, -7); 
    octagon.addPoint(7, -3); 
    octagon.addPoint(7, 3); 
    octagon.addPoint(3, 7); 
    octagon.addPoint(-3, 7); 
...
voiddrawFilter(Graphics g, Color c, double transparency, int midx, int midy, int rx, int ry)
Draw a filter with specified dimensions
g.setColor(Color.BLACK);
g.drawOval(midx - rx, midy - ry, 2 * rx, 2 * ry);
if (c != null) {
    float[] carr = c.getRGBComponents(null);
    carr[3] *= transparency;
    g.setColor(new Color(carr[0], carr[1], carr[2], carr[3]));
    g.fillOval(midx - rx, midy - ry, 2 * rx, 2 * ry);
voiddrawFleche1(Graphics g, double x, double y, double x1, double y1, int L)
draw Fleche
g.drawLine((int) x, (int) y, (int) x1, (int) y1);
double theta, delta;
if (x != x1) {
    theta = Math.atan((y1 - y) / (x1 - x));
    if (x > x1)
        theta += Math.PI;
} else {
    if (y < y1)
...
voiddrawFocus(Graphics g, int x, int y, int w, int h)
Draws a focus border.
Graphics2D g2d = (Graphics2D) g;
Stroke old = g2d.getStroke();
g2d.setStroke(
        new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1f, new float[] { 1f, 2f }, 1));
g2d.drawLine(x, y, x + w - 1, y);
g2d.drawLine(x, y + h, x + w - 1, y + h);
g2d.drawLine(x, y, x, y + h - 1);
g2d.drawLine(x + w, y, x + w, y + h - 1);
...
voiddrawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight)
Draw a focus rectangle on a graphics context.
int FOCUSTRANSPARENCY = 96;
Color beforeColor = g2.getColor();
Stroke beforeStroke = g2.getStroke();
g2.setColor(new Color(255, 255, 255, FOCUSTRANSPARENCY));
g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f,
        new float[] { 1.0f, 1.0f }, 0.0f));
g2.drawRect(iX, iY, iWidth - 1, iHeight - 1);
g2.setColor(new Color(0, 0, 0, FOCUSTRANSPARENCY));
...
voiddrawFrank(Graphics g, int x, int y)
draw Frank
g.setFont(new Font("Arial", Font.BOLD, 12));
g.setColor(Color.gray);
String s = "Quantum Workbench";
g.drawString(s, x + 1, y - 1);
g.drawString(s, x + 1, y + 1);
g.drawString(s, x - 1, y - 1);
g.drawString(s, x - 1, y + 1);
g.setColor(Color.white);
...
voiddrawGatter(Graphics g, int xDist, int yDist)
draw Gatter
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(gatterStroke);
g2.setPaint(new Color(230, 230, 230));
for (int x = 0; x < g2.getClipBounds().x + g2.getClipBounds().width; x += xDist) {
    g2.drawLine(x, 0, x, g2.getClipBounds().y + g2.getClipBounds().height);
for (int y = 0; y < g2.getClipBounds().y + g2.getClipBounds().height; y += yDist) {
    g2.drawLine(0, y, g2.getClipBounds().x + g2.getClipBounds().width, y);
...
voiddrawGlow(Graphics2D g2, Area area, double width, Color color)
draw Glow
Shape oldClip = g2.getClip();
Stroke oldStroke = g2.getStroke();
Composite oldComposite = g2.getComposite();
Paint oldPaint = g2.getPaint();
AffineTransform at = g2.getTransform();
double pixelWidth = getScale(g2.getTransform()) * width;
int steps = Math.min(Math.max(2, (int) Math.floor(pixelWidth / 1.4)), 8);
Area newClip = new Area(oldClip);
...
voiddrawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight)
draw Groove
Color oldColor = g.getColor(); 
g.translate(x, y);
g.setColor(shadow);
g.drawRect(0, 0, w - 2, h - 2);
g.setColor(highlight);
g.drawLine(1, h - 3, 1, 1);
g.drawLine(1, 1, w - 3, 1);
g.drawLine(0, h - 1, w - 1, h - 1);
...
voiddrawGroove(Graphics g, int x, int y, int width, int height, Color shadow, Color highlight)
Draws a rectangle that appears etched into the surface, given two colors that are used for drawing.
drawEtchedRect(g, x, y, width, height,  shadow,  highlight,
         shadow,  highlight);