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

private void fillBackground(Graphics g) {
    final Rectangle clip = g.getClipBounds();
    final Color col = g.getColor();
    g.setColor(getBackground());
    g.fillRect(clip.x, clip.y, clip.width, clip.height);
    g.setColor(col);//w ww.ja va2s.c  om
}

From source file:org.apache.pdfbox.rendering.TestPDFToImage.java

/**
 * Create an image; the part between the smaller and the larger image is painted black, the rest
 * in white/*from  w  w  w.  j  ava2  s . c  om*/
 *
 * @param minWidth width of the smaller image
 * @param minHeight width of the smaller image
 * @param maxWidth height of the larger image
 * @param maxHeight height of the larger image
 *
 * @return
 */
private BufferedImage createEmptyDiffImage(int minWidth, int minHeight, int maxWidth, int maxHeight) {
    BufferedImage bim3 = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_RGB);
    Graphics graphics = bim3.getGraphics();
    if (minWidth != maxWidth || minHeight != maxHeight) {
        graphics.setColor(Color.BLACK);
        graphics.fillRect(0, 0, maxWidth, maxHeight);
    }
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, minWidth, minHeight);
    graphics.dispose();
    return bim3;
}

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;
    try {/*from  w w w  .j  av a  2  s .com*/
        r0 = c.modelToView(p0);
        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);
}

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

private void drawAxisLabels(Graphics graphics) {
    final int x = 20;
    final int y = origin.y;
    final int d = 50;

    graphics.setColor(Color.black);

    final int y2 = y - d;
    graphics.drawLine(x, y, x, y - d);//from  w w w  .  ja  v a  2  s  .c o  m
    graphics.drawLine(x, y2, x - 5, y2 + 5);
    graphics.drawLine(x, y2, x + 5, y2 + 5);
    graphics.drawString(axisLabel1, x - 15, y2 - 10);

    final int x2 = x + d;
    graphics.drawLine(x, y, x2, y);
    graphics.drawLine(x2, y, x2 - 5, y - 5);
    graphics.drawLine(x2, y, x2 - 5, y + 5);
    graphics.drawString(axisLabel2, x2 - 10, y + 20);
}

From source file:org.esa.s1tbx.ocean.toolviews.polarview.polarplot.PolarCanvas.java

private void drawAxisLabels(Graphics graphics) {
    final int x = 20;
    final int y = origin.y + 50;
    final int d = 50;

    graphics.setColor(Color.black);

    final int y2 = y - d;
    graphics.drawLine(x, y, x, y - d);//from w  w  w . j a v  a  2 s.  co m
    graphics.drawLine(x, y2, x - 5, y2 + 5);
    graphics.drawLine(x, y2, x + 5, y2 + 5);
    graphics.drawString(axisLabel1, x - 15, y2 - 10);

    final int x2 = x + d;
    graphics.drawLine(x, y, x2, y);
    graphics.drawLine(x2, y, x2 - 5, y - 5);
    graphics.drawLine(x2, y, x2 - 5, y + 5);
    graphics.drawString(axisLabel2, x2 - 10, y + 20);
}

From source file:com.yanbang.portal.controller.PortalController.java

/**
 * ???//from   w  w w . j  av  a  2 s  .c  om
 * 
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(params = "action=handleRnd")
public void handleRnd(HttpServletRequest request, HttpServletResponse response) throws Exception {
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0L);
    response.setContentType("image/jpeg");
    BufferedImage image = new BufferedImage(65, 25, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.GRAY);
    g.fillRect(0, 0, 65, 25);
    g.setColor(Color.yellow);
    Font font = new Font("", Font.BOLD, 20);
    g.setFont(font);
    Random r = new Random();
    String rnd = "";
    int ir = r.nextInt(10);
    rnd = rnd + "" + ir;
    g.drawString("" + ir, 5, 18);
    g.setColor(Color.red);
    ir = r.nextInt(10);
    rnd = rnd + "" + ir;
    g.drawString("" + ir, 20, 18);
    g.setColor(Color.blue);
    ir = r.nextInt(10);
    rnd = rnd + "" + ir;
    g.drawString("" + ir, 35, 18);
    g.setColor(Color.green);
    ir = r.nextInt(10);
    rnd = rnd + "" + ir;
    g.drawString("" + ir, 50, 18);
    request.getSession().setAttribute("RND", rnd);
    ServletOutputStream out = response.getOutputStream();
    out.write(ImageUtil.imageToBytes(image, "gif"));
    out.flush();
    out.close();
}

From source file:TextBouncer.java

protected void render() {
    Graphics g = getGraphics();//from   ww w.j  ava2  s.c  o  m
    if (g != null) {
        Dimension d = getSize();
        if (checkImage(d)) {
            Graphics imageGraphics = image.getGraphics();
            // Clear the image background.
            imageGraphics.setColor(getBackground());
            imageGraphics.fillRect(0, 0, d.width, d.height);
            imageGraphics.setColor(getForeground());
            // Draw this component offscreen.
            paint(imageGraphics);
            // Now put the offscreen image on the screen.
            g.drawImage(image, 0, 0, null);
            // Clean up.
            imageGraphics.dispose();
        }
        g.dispose();
    }
}

From source file:ClipDemo.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // get damaged region
    Rectangle clipRect = g.getClipBounds();
    int clipx = clipRect.x;
    int clipy = clipRect.y;
    int clipw = clipRect.width;
    int cliph = clipRect.height;

    // fill damaged region only
    g.setColor(Color.white);
    g.fillRect(clipx, clipy, clipw, cliph);

    if (clipx <= 240 && clipy <= 240) {
        g.setColor(Color.yellow);
        g.fillOval(0, 0, 240, 240);/*  www . j  av  a  2  s. c  o  m*/
        System.out.println(" yellow Oval repainted.");
    }

    if (clipx + clipw >= 160 && clipx <= 400 && clipy + cliph >= 160 && clipy <= 400) {
        g.setColor(Color.magenta);
        g.fillOval(160, 160, 240, 240);
        System.out.println(" magenta Oval repainted.");
    }

    int iconWidth = java2sLogo.getIconWidth();
    int iconHeight = java2sLogo.getIconHeight();

    if (clipx + clipw >= 280 - (iconWidth / 2) && clipx <= (280 + (iconWidth / 2))
            && clipy + cliph >= 120 - (iconHeight / 2) && clipy <= (120 + (iconHeight / 2))) {
        java2sLogo.paintIcon(this, g, 280 - (iconWidth / 2), 120 - (iconHeight / 2));
        System.out.println(" logo below blue Rect repainted.");
    }

    if (clipx + clipw >= 120 - (iconWidth / 2) && clipx <= (120 + (iconWidth / 2))
            && clipy + cliph >= 280 - (iconHeight / 2) && clipy <= (280 + (iconHeight / 2))) {
        java2sLogo.paintIcon(this, g, 120 - (iconWidth / 2), 280 - (iconHeight / 2));
        System.out.println(" logo below red Rect repainted.");
    }

    if (clipx + clipw >= 60 && clipx <= 180 && clipy + cliph >= 220 && clipy <= 340) {
        g.setColor(red);
        g.fillRect(60, 220, 120, 120);
        System.out.println(" red Rect repainted.");

    }

    if (clipx + clipw > 140 && clipx < 260 && clipy + cliph > 140 && clipy < 260) {
        g.setColor(green);
        g.fillOval(140, 140, 120, 120);
        System.out.println(" green Oval repainted.");

    }

    if (clipx + clipw > 220 && clipx < 380 && clipy + cliph > 60 && clipy < 180) {
        g.setColor(blue);
        g.fillRect(220, 60, 120, 120);
        System.out.println(" blue Rect repainted.");
    }

    g.setColor(Color.black);

    g.setFont(monoFont);
    FontMetrics fm = g.getFontMetrics();
    iconWidth = fm.stringWidth("Java Source");
    iconHeight = fm.getAscent();
    int d = fm.getDescent();
    if (clipx + clipw > 120 - (iconWidth / 2) && clipx < (120 + (iconWidth / 2))
            && clipy + cliph > (120 + (iconHeight / 4)) - iconHeight && clipy < (120 + (iconHeight / 4)) + d) {
        g.drawString("Java Source", 120 - (iconWidth / 2), 120 + (iconHeight / 4));
        System.out.println(" Java Source repainted.");
    }

    g.setFont(sanFont);
    fm = g.getFontMetrics();
    iconWidth = fm.stringWidth("and");
    iconHeight = fm.getAscent();
    d = fm.getDescent();
    if (clipx + clipw > 200 - (iconWidth / 2) && clipx < (200 + (iconWidth / 2))
            && clipy + cliph > (200 + (iconHeight / 4)) - iconHeight && clipy < (200 + (iconHeight / 4)) + d) {
        g.drawString("and", 200 - (iconWidth / 2), 200 + (iconHeight / 4));
        System.out.println(" and repainted.");
    }

    g.setFont(serifFont);
    fm = g.getFontMetrics();
    iconWidth = fm.stringWidth("Support.");
    iconHeight = fm.getAscent();
    d = fm.getDescent();

    if (clipx + clipw > 280 - (iconWidth / 2) && clipx < (280 + (iconWidth / 2))
            && clipy + cliph > (280 + (iconHeight / 4)) - iconHeight && clipy < (280 + (iconHeight / 4)) + d) {
        g.drawString("Support.", 280 - (iconWidth / 2), 280 + (iconHeight / 4));
        System.out.println(" Support. repainted.");
    }
}

From source file:net.rptools.tokentool.ui.TokenCompositionPanel.java

@Override
protected void paintComponent(Graphics g) {

    Dimension size = getSize();/* w  ww  .j a  v a2  s .  c  o  m*/
    g.setColor(Color.black);
    g.fillRect(0, 0, size.width, size.height);

    int messageY = 15;
    int messageX = 5;

    // BASE
    if (AppState.compositionProperties.isBase()) {
        paintOverlay(g, size);
    }

    // TOKEN
    if (tokenImage != null) {
        int width = (int) (tokenImage.getWidth() * tokenScale);
        int height = (int) (tokenImage.getHeight() * tokenScale);
        g.drawImage(tokenImage, tokenOffsetX, tokenOffsetY, width, height, this);
    } else {
        g.setColor(Color.white);
        g.drawString("Drag an image onto this pane", messageX, messageY);
        messageY += 15;
    }

    if (!AppState.compositionProperties.isBase()) {
        paintOverlay(g, size);
    }
}

From source file:CustomIconDemo.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    int length = xPoints.length;
    int adjustedXPoints[] = new int[length];
    int adjustedYPoints[] = new int[length];

    for (int i = 0; i < length; i++) {
        adjustedXPoints[i] = xPoints[i] + x;
        adjustedYPoints[i] = yPoints[i] + y;
    }/*ww w.  j  a  v a  2  s. c om*/

    if (c.isEnabled()) {
        g.setColor(Color.black);
    } else {
        g.setColor(Color.gray);
    }

    g.fillPolygon(adjustedXPoints, adjustedYPoints, length);
}