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.esa.nest.dat.views.polarview.PolarCanvas.java

@Override
public void paint(Graphics g) {
    try {//from w  w w  .  j  a v  a2 s .c  o m
        if (isShowing()) {
            if (opaque)
                fillBackground(g);
            g.setColor(getForeground());
            g.setFont(getFont());
            paintComponents(this, g);
        }
        drawSynchronised(g, getSize());
    } catch (Throwable e) {
        Debug.trace(e);
    }
}

From source file:de.unidue.inf.is.ezdl.gframedl.tools.relations.DLObjectGraphView.java

private void setRenderers() {
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<DLObject, String>() {

        @Override//  ww w.  j  a  va  2 s  .c  o  m
        public String transform(DLObject v) {
            String result = "";
            if (v instanceof Person) {
                result = ((Person) v).getFirstName() + " " + ((Person) v).getLastName();
            }
            if (v instanceof TextDocument) {
                result = ((TextDocument) v).getTitle();
            }
            return result;
        }
    });
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    vv.getRenderContext().setVertexShapeTransformer(new VertexShapeFunction<DLObject>());

    vv.getRenderContext().setVertexIconTransformer(new Transformer<DLObject, Icon>() {

        @Override
        public Icon transform(final DLObject v) {
            final int size = getVertexSize(v);
            return new Icon() {

                @Override
                public int getIconHeight() {
                    return size;
                }

                @Override
                public int getIconWidth() {
                    return size;
                }

                @Override
                public void paintIcon(Component c, Graphics g, int x, int y) {
                    int halfSize = size / 2;
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.yellow);
                    } else {
                        g.setColor(Color.lightGray);
                    }
                    g.fillOval(x, y, size, size);

                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.red);
                    } else {
                        g.setColor(Color.black);
                    }
                    g.drawOval(x, y, size, size);

                    int iconX = x + halfSize - 8;
                    int iconY = y + halfSize - 8;

                    if (v instanceof Person) {
                        Icons.MEDIA_AUTHOR.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof TextDocument) {
                        Icons.MEDIA_TEXT.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof Term) {
                        Icons.MEDIA_TERM.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                }
            };
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.black));
    vv.setBackground(Color.white);
}

From source file:JapaneseCalendar.java

public void paintComponent(Graphics g) {
    int width = 400;
    int height = 400;

    Calendar cal = Calendar.getInstance(locale);
    cal.setTime(new Date());

    String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale);
    header += " " + cal.get(Calendar.YEAR);

    FontMetrics fm = g.getFontMetrics();
    Insets insets = getInsets();/*from   ww  w .ja  v a2 s .  c  om*/
    g.setColor(Color.black);
    g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight());

    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] weekdayNames = dfs.getShortWeekdays();
    int fieldWidth = (width - insets.left - insets.right) / 7;
    g.drawString(weekdayNames[Calendar.SUNDAY],
            insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.MONDAY],
            insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.TUESDAY],
            insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.WEDNESDAY],
            insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.THURSDAY],
            insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.FRIDAY],
            insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.SATURDAY],
            insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2,
            insets.top + 3 * fm.getHeight());

    int dom = cal.get(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    int col = 0;
    switch (cal.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        col = 1;
        break;

    case Calendar.TUESDAY:
        col = 2;
        break;

    case Calendar.WEDNESDAY:
        col = 3;
        break;

    case Calendar.THURSDAY:
        col = 4;
        break;

    case Calendar.FRIDAY:
        col = 5;
        break;

    case Calendar.SATURDAY:
        col = 6;
    }
    cal.set(Calendar.DAY_OF_MONTH, dom);

    int row = 5 * fm.getHeight();
    for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
        g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row);
        if (++col > 6) {
            col = 0;
            row += fm.getHeight();
        }
    }
}

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

public void draw(Graphics g) {
    if (!visible)
        return;/*from   www.j  a  v a 2  s.c  om*/
    gr.setGraphics(g);
    final FontMetrics fm = g.getFontMetrics(font);
    g.setColor(axisColor);
    gr.drawLine(0, 0, length + 2 * spacing, 0);
    int tickLength = this.tickLength;
    if (ticksInside)
        tickLength = -tickLength;
    final int maxTickCount = (int) (((float) length + 0.5F)
            / (float) gr.maxTickSize(tickNames, tickCount, font));
    final int minTickCount = Math.min(maxTickCount, bestTickCount);
    if (tickCount > maxTickCount)
        setTickCount(maxTickCount);
    else if (tickCount < minTickCount)
        setTickCount(minTickCount);
    for (int i = 0; i < tickCount; i++) {
        gr.drawTick(tickPos[i], tickLength);
    }
    g.setColor(labelColor);
    g.setFont(font);
    for (int i = 0; i < tickCount; i++) {
        gr.drawMultiLineTickName(tickNames[i], tickPos[i], tickLength, fm);
    }

    g.setFont(titleFont);
    gr.drawTitle(title, titleFont, length);
    if (!withGrid)
        return;
    g.setColor(gridColor);
    for (int i = 0; i < tickCount; i++) {
        gr.drawTick(tickPos[i], breadth);
    }
}

From source file:edu.ku.brc.af.ui.db.TextFieldWithInfo.java

@Override
public void paint(Graphics g) {
    super.paint(g);

    if (this.isInError && textField.isEnabled()) {
        Dimension dim = getSize();
        g.setColor(valtextcolor.getColor());
        g.drawRect(0, 0, dim.width - 1, dim.height - 1);
    }//  w  ww . j av  a2  s  .c  o  m
}

From source file:Main.java

public void paintStrikeLine(Graphics g, Shape a) {
    Color c = (Color) getElement().getAttributes().getAttribute("strike-color");
    if (c != null) {
        int y = a.getBounds().y + a.getBounds().height - (int) getGlyphPainter().getDescent(this);
        y = y - (int) (getGlyphPainter().getAscent(this) * 0.3f);
        int x1 = (int) a.getBounds().getX();
        int x2 = (int) (a.getBounds().getX() + a.getBounds().getWidth());

        Color old = g.getColor();
        g.setColor(c);
        g.drawLine(x1, y, x2, y);//w w w .  ja  v  a2 s  . c  o m
        g.setColor(old);
    }
}

From source file:org.deegree.ogcwebservices.wms.dataaccess.ID2PInterpolation.java

private void writeErrorMessage() {
    Graphics g = image.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, getMap.getWidth(), getMap.getHeight());
    g.setColor(Color.RED);/*from  w w w.  j  a  v a  2 s .c o  m*/
    g.drawString("not enough values for interpolation available", 10, 50);
    g.dispose();
}

From source file:Animate.java

public void paint(Graphics g) {
    super.paint(g);
    if (insets == null) {
        insets = getInsets();//ww  w  .ja v a2s . c o  m
    }
    // Calculate each time in case of resize
    int x = insets.left;
    int y = insets.top;
    int width = getWidth() - insets.left - insets.right;
    int height = getHeight() - insets.top - insets.bottom;
    int start = 0;
    int steps = colors.length;
    int stepSize = 360 / steps;
    synchronized (colors) {
        for (int i = 0; i < steps; i++) {
            g.setColor(colors[i]);
            g.fillArc(x, y, width, height, start, stepSize);
            start += stepSize;
        }
    }
}

From source file:AccessibleScrollDemo.java

public void paintComponent(Graphics g) {
    Rectangle drawHere = g.getClipBounds();

    // Fill clipping area with dirty brown/orange.
    g.setColor(new Color(230, 163, 4));
    g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);

    // Do the ruler labels in a small font that's black.
    g.setFont(new Font("SansSerif", Font.PLAIN, 10));
    g.setColor(Color.black);//from  ww w  . ja v a2s .  c  o m

    // Some vars we need.
    int end = 0;
    int start = 0;
    int tickLength = 0;
    String text = null;

    // Use clipping bounds to calculate first tick
    // and last tick location.
    if (orientation == HORIZONTAL) {
        start = (drawHere.x / increment) * increment;
        end = (((drawHere.x + drawHere.width) / increment) + 1) * increment;
    } else {
        start = (drawHere.y / increment) * increment;
        end = (((drawHere.y + drawHere.height) / increment) + 1) * increment;
    }

    // Make a special case of 0 to display the number
    // within the rule and draw a units label.
    if (start == 0) {
        text = Integer.toString(0) + (isMetric ? " cm" : " in");
        tickLength = 10;
        if (orientation == HORIZONTAL) {
            g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1);
            g.drawString(text, 2, 21);
        } else {
            g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0);
            g.drawString(text, 9, 10);
        }
        text = null;
        start = increment;
    }

    // ticks and labels
    for (int i = start; i < end; i += increment) {
        if (i % units == 0) {
            tickLength = 10;
            text = Integer.toString(i / units);
        } else {
            tickLength = 7;
            text = null;
        }

        if (tickLength != 0) {
            if (orientation == HORIZONTAL) {
                g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1);
                if (text != null)
                    g.drawString(text, i - 3, 21);
            } else {
                g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i);
                if (text != null)
                    g.drawString(text, 9, i + 3);
            }
        }
    }
}

From source file:LineHighlightPainter.java

public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {

    Rectangle r0 = null, r1 = null, rbounds = bounds.getBounds();
    int xmax = rbounds.x + rbounds.width; // x coordinate of right edge
    try { // convert positions to pixel coordinates
        r0 = c.modelToView(p0);// w ww.  java2  s. c om
        r1 = c.modelToView(p1);
    } catch (BadLocationException ex) {
        return;
    }
    if ((r0 == null) || (r1 == null))
        return;

    g.setColor(c.getSelectionColor());

    // special case if p0 and p1 are on the same line
    if (r0.y == r1.y) {
        paintLine(g, r0, r1.x);
        return;
    }

    // first line, from p1 to end-of-line
    paintLine(g, r0, xmax);

    // all the full lines in between, if any (assumes that all lines have
    // the same height--not a good assumption with JEditorPane/JTextPane)
    r0.y += r0.height; // move r0 to next line
    r0.x = rbounds.x; // move r0 to left edge
    while (r0.y < r1.y) {
        paintLine(g, r0, xmax);
        r0.y += r0.height; // move r0 to next line
    }

    // last line, from beginning-of-line to p1
    paintLine(g, r0, r1.x);
}