Example usage for java.awt Graphics setColor

List of usage examples for java.awt Graphics setColor

Introduction

In this page you can find the example usage for java.awt Graphics setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:br.fapesp.myutils.MyUtils.java

/**
 * Plot a matrix consisting of 0's and 1's.
 * //w w w  . j  a  v  a  2  s  .  co  m
 * @param map
 */
public static void plotBinaryMatrix(final int[][] map, int width, int height) {
    JFrame frame = new JFrame("Binary matrix plot");

    frame.add(new JComponent() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            int w = getWidth() / map.length;
            int h = getHeight() / map[0].length;

            for (int i = 0; i < map.length; i++) {
                for (int j = 0; j < map[0].length; j++) {
                    if (map[i][j] != 0) {
                        g.setColor(new Color(map[i][j]));
                        g.fillRect(i * w, j * h, w, h);
                    }
                }
            }
        }
    });

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, height);
    frame.setVisible(true);
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private void draw(Graphics g, Dimension size) {
    final int annotationHeight = 100;
    final int x = Math.max((int) (size.height * 0.05), 10);
    final int y = Math.max((int) (size.width * 0.05), 10);
    final int bottom = Math.max((int) (size.height * 0.1) + annotationHeight, 20);
    final int right = Math.max((int) (size.width * 0.1), 20);
    final Rectangle r = positionPlot(size, x, y, bottom, right);
    plotRadius = Math.min(r.width / 2, r.height / 2);
    final Dimension quadrantSize = new Dimension(plotRadius, plotRadius);
    g.translate(0, origin.y + r.height);
    if (data != null) {
        loadColorBar(data.getColorScale());
        drawColorBar(g, colourAxis);//from   w ww.  jav  a 2 s .  c  o  m
    }
    g.translate(0, -origin.y - r.height);

    origin.y += r.height / 2;
    origin.x += r.width / 2;
    final Graphics graphics = g.create();
    graphics.translate(origin.x, origin.y);
    radialAxis.setSize(quadrantSize);
    if (data != null)
        data.draw(graphics);
    if (rings != null) {
        int ri = 0;
        for (double ring : rings) {
            final int rad = radialAxis.getScreenPoint(ring);
            final int rad2 = rad + rad;
            graphics.setColor(Color.lightGray);
            graphics.drawOval(-rad, -rad, rad2, rad2);
            if (ringText != null && ringText[ri] != null) {
                graphics.setColor(Color.black);
                graphics.drawString(ringText[ri], 0, -rad);
            }
            ++ri;
        }
    } else {
        radialAxis.draw(graphics);
    }

    // draw wind direction & speed
    if (showWindDirection)
        drawWindDirection(graphics, plotRadius, windDirection - 90);

    graphics.translate(-origin.x, -origin.y);

    drawAxisLabels(graphics);

    graphics.dispose();
}

From source file:rod_design_compute.ShowPanel.java

private void drawJunctionPoint(Point point, Graphics g) {
    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.white);
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    g.setColor(Color.black);//  w w  w  .  j  a  v  a2  s  .com
    g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}

From source file:rod_design_compute.ShowPanel.java

private void drawOtherPoint(Point point, Graphics g) {
    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.white);
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    g.setColor(Color.red);/* ww  w .java 2s  .  co m*/
    g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}

From source file:RedGreenBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color horizontalColor;//from   w ww.  j  a va2s  .  co m
    Color verticalColor;
    if (c.isEnabled()) {
        boolean pressed = false;
        if (c instanceof AbstractButton) {
            ButtonModel model = ((AbstractButton) c).getModel();
            pressed = model.isPressed();
        }
        if (pressed) {
            horizontalColor = Color.red;
            verticalColor = Color.green;
        } else {
            horizontalColor = Color.green;
            verticalColor = Color.red;
        }
    } else {
        horizontalColor = Color.lightGray;
        verticalColor = Color.lightGray;
    }
    g.setColor(horizontalColor);

    g.translate(x, y);

    // top
    g.fillRect(0, 0, width, insets.top);
    // bottom
    g.fillRect(0, height - insets.bottom, width, insets.bottom);

    g.setColor(verticalColor);
    // left
    g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom);
    g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
    g.translate(-x, -y);
}

From source file:edu.ku.brc.af.prefs.PrefsToolbar.java

@Override
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);

    Color base = getBackground();
    Dimension size = getSize();//from  w  ww  .ja  va2s. c o  m

    Color grad_top = base;
    Color grad_bot = UIHelper.makeDarker(base, UIHelper.isMacOS() ? 0.15 : 0.1);
    GradientPaint bg = new GradientPaint(new Point(0, 0), grad_top, new Point(0, size.height), grad_bot);
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(bg);
    g2.fillRect(0, 0, size.width, size.height);

    g.setColor(UIHelper.makeDarker(base, 0.5));
    g.drawLine(0, size.height - 1, size.width, size.height - 1);
}

From source file:org.kchine.r.server.impl.RGraphicsPanelRemote.java

public synchronized void paintComponent(Graphics g) {
    super.paintComponent(g);

    Dimension d = getSize();// w  w  w.jav a 2s  .  c  o m

    if (!d.equals(_lastSize)) {
        _lastResizeTime = System.currentTimeMillis();
        _lastSize = d;
        return;
    } else {

    }

    if (forceAntiAliasing) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }

    int i = 0, j = _l.size();
    g.setFont(_gs.f);
    g.setClip(0, 0, d.width, d.height); // reset clipping rect
    g.setColor(Color.white);
    g.fillRect(0, 0, d.width, d.height);
    while (i < j) {
        GDObject o = (GDObject) _l.elementAt(i++);
        o.paint(this, _gs, g);
    }
}

From source file:rod_design_compute.ShowPanel.java

private void drawChooseRod(Point a, Point b, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    g.setColor(Color.blue);
    g.drawLine(toScreenX(a.X), toScreenY(a.Y), toScreenX(b.X), toScreenY(b.Y));
}

From source file:MainClass.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color horizontalColor;/*  ww w .  j  a va2s  .  co  m*/
    Color verticalColor;
    if (c.isEnabled()) {
        boolean pressed = false;
        if (c instanceof AbstractButton) {
            ButtonModel model = ((AbstractButton) c).getModel();
            pressed = model.isPressed();
        }
        if (pressed) {
            horizontalColor = Color.WHITE;
            verticalColor = Color.BLACK;
        } else {
            horizontalColor = Color.BLACK;
            verticalColor = Color.WHITE;
        }
    } else {
        horizontalColor = Color.LIGHT_GRAY;
        verticalColor = Color.LIGHT_GRAY;
    }
    g.setColor(horizontalColor);

    g.translate(x, y);

    // top
    g.fillRect(0, 0, width, insets.top);
    // bottom
    g.fillRect(0, height - insets.bottom, width, insets.bottom);

    g.setColor(verticalColor);
    // left
    g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom);
    // right
    g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
    g.translate(-x, -y);
}

From source file:org.deegree.portal.standard.wms.control.DynLegendListener.java

/**
 * Draws the given symbol to the given image
 * /*from  w  ww  .ja v a2 s  . c  o  m*/
 * @param map
 *            Hashmap holding the properties of the legend
 * @param bi
 *            image of the legend
 * @param color
 *            color to fill the graphic
 * @return The drawn BufferedImage
 */
private BufferedImage drawSymbolsToBI(HashMap<String, Object> map, BufferedImage bi, Color color) {

    Graphics g = bi.getGraphics();
    g.setColor(color);
    g.fillRect(0, 0, bi.getWidth(), bi.getHeight());

    String[] layers = (String[]) map.get("NAMES");
    String[] titles = (String[]) map.get("TITLES");
    BufferedImage[] legs = (BufferedImage[]) map.get("IMAGES");
    int h = topMargin;
    for (int i = layers.length - 1; i >= 0; i--) {
        g.drawImage(legs[i], leftMargin, h, null);
        g.setColor(Color.BLACK);
        // just draw title if the flag has been set in listener configuration,
        // the legend image is less than a defined value and a legend image
        // (not missing) has been accessed
        if (useLayerTitle && legs[i].getHeight() < maxNNLegendSize && !missing.contains(layers[i])) {
            g.drawString(titles[i], leftMargin + legs[i].getWidth() + 10,
                    h + (int) (legs[i].getHeight() / 1.2));
        }
        h += legs[i].getHeight() + 5;
        if (separator != null && i > 0) {
            g.drawImage(separator, leftMargin, h, null);
            h += separator.getHeight() + 5;
        }
    }
    g.dispose();
    return bi;
}