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:org.kalypso.kalypsomodel1d2d.ui.map.grid.LinePointCollector.java

private static final void drawHandles(final Graphics g, final int[] x, final int[] y, final int pointRectWidth,
        final int selection) {
    final Color oldColor = g.getColor();
    g.setColor(oldColor.darker());
    // int sizeOuter = 4;
    final int halfRectWidth = pointRectWidth / 2;

    if (selection < 0) {
        for (int i = 0; i < y.length; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }/*  ww w .  j  a  v  a2s. c om*/
    } else {
        int i;
        for (i = 0; i < selection; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }
        // is is now selection
        g.drawOval(x[i] - pointRectWidth, y[i] - pointRectWidth, pointRectWidth + pointRectWidth,
                pointRectWidth + pointRectWidth);
        i++;
        for (; i < y.length; i++) {
            g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth);
        }
    }
    g.setColor(oldColor);
}

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

private static void drawWindDirection(Graphics graphics, double radius, double theta) {
    final double a = theta * Constants.DTOR;
    final int x1 = (int) (radius * FastMath.cos(a));
    final int y1 = (int) (radius * FastMath.sin(a));
    final int x2 = (int) ((radius + 50) * FastMath.cos(a));
    final int y2 = (int) ((radius + 50) * FastMath.sin(a));

    graphics.setColor(Color.black);
    graphics.drawLine(x1, y1, x2, y2);//w  w  w .j  a  va  2s.  c om

    drawArrowHead(graphics, x2, y2, theta, radius + 40);
}

From source file:Main.java

public static void flattenSplitPane(JSplitPane jSplitPane) {
    UIDefaults defaults = javax.swing.UIManager.getDefaults();
    final Color light = defaults.getColor("SplitPane.highlight");
    final Color dark = defaults.getColor("SplitPane.darkShadow");

    // *// ww  w. ja va  2 s  .c  om
    jSplitPane.setUI(new BasicSplitPaneUI() {
        public BasicSplitPaneDivider createDefaultDivider() {
            BasicSplitPaneDivider divider = new BasicSplitPaneDivider(this) {
                private static final long serialVersionUID = 1L;

                @Override
                public int getDividerSize() {
                    return 5;
                }

                @Override
                public void paint(Graphics g) {
                    // super.paint(g);
                    int orientation = this.getBasicSplitPaneUI().getOrientation();

                    Dimension size = this.getSize();

                    if (orientation == JSplitPane.VERTICAL_SPLIT) {
                        int[] lines = new int[2];
                        lines[0] = 0;
                        lines[1] = size.height - 2;

                        for (int i = 0; i < size.width; i += 4) {
                            for (int j = 0; j < lines.length; j++) {
                                int y = lines[j];
                                g.setColor(light);
                                g.fillRect(i, y, 2, 2);
                                g.setColor(dark);
                                g.fillRect(i, y, 1, 1);
                            }
                        }
                    } else {
                        int[] rows = new int[2];
                        rows[0] = 0;
                        rows[1] = size.width - 2;

                        for (int i = 0; i < size.height; i += 4) {
                            for (int j = 0; j < rows.length; j++) {
                                int x = rows[j];
                                g.setColor(light);
                                g.fillRect(x, i, 2, 2);
                                g.setColor(dark);
                                g.fillRect(x, i, 1, 1);
                            }
                        }
                    }
                }
            };
            return divider;
        }
    });
    jSplitPane.setBorder(null);
    // */
}

From source file:org.kalypso.ogc.gml.map.widgets.advanced.utils.GeometryPainter.java

public static void drawLineString(final IMapPanel mapPanel, final Graphics g, final Point[] myPoints,
        final Color color) throws GM_Exception {
    final List<java.awt.Point> awtPoints = new ArrayList<>();

    final Set<Coordinate> coordinates = new LinkedHashSet<>();

    for (final Point point : myPoints) {
        coordinates.add(point.getCoordinate());

        final GM_Point gmp = (GM_Point) JTSAdapter.wrap(point);
        final java.awt.Point awt = MapUtilities.retransform(mapPanel, gmp);

        awtPoints.add(awt);/*from  w w  w . j  a  va  2 s.c  o  m*/
    }

    final Color original = g.getColor();
    g.setColor(color);

    for (int i = 0; i < awtPoints.size() - 1; i++) {
        final java.awt.Point p1 = awtPoints.get(i);
        final java.awt.Point p2 = awtPoints.get(i + 1);

        g.drawLine(Double.valueOf(p1.getX()).intValue(), Double.valueOf(p1.getY()).intValue(),
                Double.valueOf(p2.getX()).intValue(), Double.valueOf(p2.getY()).intValue());
    }

    g.setColor(original);
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

private static void drawHelp(final Graphics g) {
    final int x = (int) (g.getClipBounds().getWidth() / 2);
    final int y = (int) (g.getClipBounds().getHeight() / 2);

    final FontMetrics metrics = g.getFontMetrics();
    final String name = "Right click here to add an operator";
    final Rectangle2D rect = metrics.getStringBounds(name, g);
    final int stringWidth = (int) rect.getWidth();

    g.setColor(Color.black);
    g.drawString(name, x - stringWidth / 2, y);
}

From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java

/**
 * //from  w  w  w.jav  a 2 s.  c o  m
 * @param g
 * @param fx
 * @param fy
 * @param size
 * @param repartition
 * @param total
 * @param colors
 */
public static void createPieChart(Graphics g, int fx, int fy, int size, Map<Object, Integer> repartition,
        int total, List<Paint> colors) {
    if (total > 0) {
        int startAngle = 0;
        int k = 0;
        double curValue = 0.0D;
        for (final Map.Entry<Object, Integer> entry : repartition.entrySet()) {
            startAngle = (int) (curValue * 360 / total);
            int arcAngle = (int) (entry.getValue() * 360 / total);
            g.setColor((Color) colors.get(k));
            g.fillArc(fx, fy, size, size, startAngle, arcAngle);
            curValue += entry.getValue();
            k++;
        }
    }
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.fillArc(5, 15, 50, 75, 25, 165);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.draw3DRect(5, 15, 50, 75, false);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.fillOval(5, 15, 50, 75);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.drawOval(5, 15, 50, 75);
}