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:oct.analysis.application.OCTSelection.java

protected void drawSelectButton(Graphics g, int imageOffsetX, int imageOffsetY) {
    Polygon buttonOutline = getSelectionButtonShape();
    buttonOutline.translate(imageOffsetX, imageOffsetY);
    g.setColor(Color.lightGray);
    g.drawPolygon(buttonOutline);/*from   w ww  . j a  v  a 2 s  . c o  m*/
    g.fillPolygon(buttonOutline);
    Polygon button = new Polygon();
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY);
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct, imageOffsetY + 20);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY);
    g.setColor(Color.DARK_GRAY);
    g.drawPolygon(button);
}

From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java

@Override
public final void paintComponent(final Graphics g) {
    try {/*w  w w  .  j  av  a  2 s.c  o  m*/
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        // // super.paintComponent(g);
        // // clear the graphics
        g.setColor(this.getBackground());
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        // copy the result of the rendering manager to the panel
        this.getRenderingManager().copyTo((Graphics2D) g);
        // if currently editing geometry
        this.paintGeometryEdition(g);
        this.paintOverlays(g);
        //
        if (this.recording) {
            this.saveImage();
        }
    } catch (Throwable t) {
        LayerViewAwtPanel.logger.error(I18N.getString("LayerViewAwtPanel.PaintError")); //$NON-NLS-1$
        t.printStackTrace();
        // TODO HANDLE EXCEPTIONS
    }
}

From source file:ExtendedParagraphExample.java

public void paint(Graphics g, Shape a) {
    Container comp = getContainer();
    Rectangle alloc = new Rectangle(a.getBounds());

    alloc.x += paraInsets.left;/*from  ww w .  ja v  a2s  .co m*/
    alloc.y += paraInsets.top;
    alloc.width -= paraInsets.left + paraInsets.right;
    alloc.height -= paraInsets.top + paraInsets.bottom;

    if (bgColor != null) {
        Color origColor = g.getColor();
        g.setColor(bgColor);
        g.fillRect(alloc.x, alloc.y, alloc.width, alloc.height);
        g.setColor(origColor);
    }

    if (border != null) {
        // Paint the border
        border.paintBorder(comp, g, alloc.x, alloc.y, alloc.width, alloc.height);
    }
    super.paint(g, a); // Note: pass ORIGINAL allocation
}

From source file:TalkServerThread.java

public void paint(Graphics g) {
        Dimension d = getSize();/*www.j a v  a 2 s .  c  o m*/
        Color bg = getBackground();

        g.setColor(bg);
        g.draw3DRect(0, 0, d.width - 1, d.height - 1, true);
        g.draw3DRect(3, 3, d.width - 7, d.height - 7, false);
    }

From source file:javazoom.jlgui.player.amp.visual.ui.SpectrumTimeAnalyzer.java

private void drawScope(Graphics pGrp, float[] pSample) {
    pGrp.setColor(scopeColor);
    int wLas = (int) (pSample[0] * (float) height_2) + height_2;
    int wSt = 2;//from  w w  w. java 2 s  .c om
    for (int a = wSt, c = 0; c < width; a += wSt, c++) {
        int wAs = (int) (pSample[a] * (float) height_2) + height_2;
        pGrp.drawLine(c, wLas, c + 1, wAs);
        wLas = wAs;
    }
}

From source file:FormattedTextFieldExample.java

protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
    workBuff.array = contentBuff.array;//from   w w  w . java  2 s  .co  m
    workBuff.offset = p0;
    workBuff.count = p1 - p0;
    g.setColor(selected);
    return Utilities.drawTabbedText(workBuff, x, y, g, this, p0);
}

From source file:com.tinypace.mobistore.servlet.ValidateCodeServlet.java

private String createCharacter(Graphics g) {
    char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T',
            'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };
    String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53",
            "\u96b6\u4e66" };
    Random random = new Random();
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < 4; i++) {
        String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
        g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
        g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26));
        g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
        s.append(r);/*from  w w w  .j a v a  2s .  co  m*/
    }
    return s.toString();
}

From source file:apm.common.servlet.ValidateCodeServlet.java

private String createCharacter(Graphics g) {
    char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T',
            'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };
    String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53",
            "\u96b6\u4e66" };
    Random random = new Random();
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < 4; i++) {
        String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
        g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
        g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26));
        g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
        //         g.drawString(r, i*w/4, h-5);
        s.append(r);//from   w  w w . ja v  a 2  s  .c om
    }
    return s.toString();
}

From source file:com.aistor.common.servlet.ValidateCodeServlet.java

private String createCharacter(Graphics g) {
    char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S',
            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53",
            "\u96b6\u4e66" };
    Random random = new Random();
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < 4; i++) {
        String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
        g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
        g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26));
        g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
        //         g.drawString(r, i*w/4, h-5);
        s.append(r);// www.  j av a 2 s  .  com
    }
    return s.toString();
}

From source file:org.openlegacy.terminal.render.DefaultTerminalSnapshotImageRenderer.java

private void drawText(TerminalSnapshot terminalSnapshot, Graphics graphics) {
    int columns = terminalSnapshot.getSize().getColumns();
    List<TerminalRow> rows = terminalSnapshot.getRows();
    String screenText = terminalSnapshot.getText();
    for (TerminalRow terminalRow : rows) {
        int rowNumber = terminalRow.getRowNumber();
        int startY = toHeight(rowNumber);

        if (drawLineNumbers) {
            // draw row number
            graphics.setColor(imageSorroundingTextColor);
            graphics.drawString(String.valueOf(String.format("%2d", terminalRow.getRowNumber())), 0, startY);
        }/*from  ww  w  .ja v a 2  s  . co  m*/

        int rowStart = (rowNumber - 1) * columns; // row is 1 based, drawing is 0 base
        String text = screenText.substring(rowStart, rowStart + columns);
        if (StringUtils.isBlank(text)) {
            continue;
        }
        for (int i = 0; i < text.length(); i++) {
            // text is 0 based, columns are 1 based
            TerminalField currentField = terminalSnapshot
                    .getField(SimpleTerminalPosition.newInstance(rowNumber, i + 1));
            if (currentField != null && currentField.getBackColor() != org.openlegacy.terminal.Color.BLACK) {
                graphics.setColor(imageBackgroundColor);
            } else {
                if (currentField != null) {
                    graphics.setColor(SnapshotUtils.convertColor(currentField.getColor()));
                    if (currentField.isBold()
                            && currentField.getColor() == org.openlegacy.terminal.Color.GREEN) {
                        graphics.setColor(imageBoldFieldColor);
                    }
                } else {
                    setDefaultColor(graphics);
                }
            }
            // 2 - place holder for row numbers
            char ch = text.charAt(i);
            if (hidePasswordFields && currentField != null && currentField.isPassword()) {
                if (currentField.isEmpty()) {
                    ch = ' ';
                } else {
                    ch = '*';
                }
            }
            graphics.drawString(String.valueOf(ch), toWidth(i + leftColumnsOffset), startY);
        }
    }
}