Example usage for java.awt Graphics2D getColor

List of usage examples for java.awt Graphics2D getColor

Introduction

In this page you can find the example usage for java.awt Graphics2D getColor.

Prototype

public abstract Color getColor();

Source Link

Document

Gets this graphics context's current color.

Usage

From source file:Main.java

public static BufferedImage joinBufferedImage(BufferedImage img1, BufferedImage img2) {
    int offset = 2;
    int width = img1.getWidth() + img2.getWidth() + offset;
    int height = Math.max(img1.getHeight(), img2.getHeight()) + offset;
    BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = newImage.createGraphics();
    Color oldColor = g2.getColor();
    g2.setPaint(Color.BLACK);/*from   www  . ja v a2  s  . c o  m*/
    g2.fillRect(0, 0, width, height);
    g2.setColor(oldColor);
    g2.drawImage(img1, null, 0, 0);
    g2.drawImage(img2, null, img1.getWidth() + offset, 0);
    g2.dispose();
    return newImage;
}

From source file:Main.java

public static void drawShadowText(Graphics2D g2, String s, int x, int y, Color shadowColor, int offset) {
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    Color c = g2.getColor();
    g2.setColor(shadowColor);//  ww w  .  j  a v  a2  s. com
    g2.drawString(s, x, y + offset);
    g2.setColor(c);
    g2.drawString(s, x, y);
}

From source file:de.codesourcery.planning.swing.DateAxis.java

protected static void debugBoundingBox(BoundingBox box, Graphics2D g) {
    if (DEBUG) {/*w w  w.ja va2s.c om*/
        Color old = g.getColor();
        g.setColor(Color.RED);
        g.drawRect(box.getX(), box.getY(), box.getWidth(), box.getHeight());
        g.setColor(old);
    }
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawText(Graphics2D g2, Rectangle2D imageArea,
        LinkedHashMap<Rectangle2D, String> textContentMap, JFreeChart chart) {
    if (textContentMap == null || textContentMap.size() == 0) {
        return;// w w  w.ja va2s  . c om
    }
    //      for (Entry<Rectangle2D, String> textEntry : textMap.entrySet()) {
    //         Rectangle2D rect = textEntry.getKey();
    //         String text = textEntry.getValue();
    //         drawText(g2, imageArea, rect, text, chart);
    //      }
    Color oldColor = g2.getColor();
    g2.setColor(Color.BLACK);
    for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) {
        Rectangle2D rect = entry.getKey();
        Point2D screenPoint = ChartMaskingUtilities
                .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, chart);
        String text = entry.getValue();
        if (text == null) {
            continue;
        }
        String[] lines = text.split("\n");
        g2.setColor(Color.BLACK);
        for (int i = 0; i < lines.length; i++) {
            g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15);
        }
        //         if (rect == selectedTextWrapper) {
        //            FontMetrics fm = g2.getFontMetrics();
        //            int maxWidth = 0;
        //            int maxHeight = 0;
        //            for (int i = 0; i < lines.length; i++) {
        //               int lineWidth = fm.stringWidth(lines[i]);
        //               if (lineWidth > maxWidth) {
        //                  maxWidth = lineWidth;
        //               }
        //            }
        //            maxHeight = 15 * lines.length;
        //            if (maxWidth < 100) {
        //               maxWidth = 100;
        //            }
        //            Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight);
        //              Color fillColor = new Color(250, 250, 50, 30);
        //              g2.setPaint(fillColor);
        //              g2.fill(inputBox);
        //            g2.setColor(Color.ORANGE);
        //            g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight);
        //
        //         }
        //         g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3);
    }
    g2.setColor(oldColor);
}

From source file:org.slage.TextObject.java

/**
 * Draw text at the object's position/*from w ww .  j  a  v a 2s. c  om*/
 * 
 * @param G2D graphics context to render the text to
 */
public void draw(java.awt.Graphics2D G2D) {

    Font oldFont = G2D.getFont();
    Color oldColor = G2D.getColor();

    G2D.setFont(font);
    G2D.setColor(color);

    G2D.drawString(getName(), getPosition().x, getPosition().y);

    G2D.setFont(oldFont);
    G2D.setColor(oldColor);
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

protected void drawTextInfo(Graphics2D graphics, int hOffset) {
    if (!useEdgingOnly) {
        Color color = graphics.getColor();
        graphics.setColor(DrawProperties.getTextColor());
        if (swimlaneName != null) {
            hOffset = drawText(graphics, "(" + swimlaneName + ")", hOffset);
            // additional space after swimlane label
            hOffset += 3;/* w  w w  .  ja  va 2  s  . c  o m*/
        }
        drawText(graphics, node.getName(), hOffset);
        graphics.setColor(color);
    }
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.datastructures.annotations.AnnotationLayer.java

/**
 *
 * @param gd/*ww w  .  jav  a2  s  .c om*/
 * @param xyplot
 * @param rd
 * @param va
 * @param va1
 * @param i
 * @param pri
 */
@Override
public void draw(Graphics2D gd, XYPlot xyplot, Rectangle2D rd, ValueAxis va, ValueAxis va1, int i,
        PlotRenderingInfo pri) {
    if (visible) {
        Color oldC = gd.getColor();
        for (XYSelectableShapeAnnotation<?> xys : this.xya) {
            xys.draw(gd, xyplot, rd, va, va1, i, pri);
        }
        gd.setColor(oldC);
    }
}

From source file:de.dakror.villagedefense.game.entity.Entity.java

public void drawBump(Graphics2D g, boolean above) {
    if (bump == null || (!hovered && !clicked))
        return;//from w  w w .ja v  a  2s  . com

    Color oldColor = g.getColor();
    g.setColor(clicked ? Color.black : Color.darkGray);
    if (above) {
        g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x, (int) y + bump.y + bump.height); // left
        g.drawLine((int) x + bump.x, (int) y + bump.y + bump.height, (int) x + bump.x + bump.width,
                (int) y + bump.y + bump.height); // bottom
        g.drawLine((int) x + bump.x + bump.width, (int) y + bump.y, (int) x + bump.x + bump.width,
                (int) y + bump.y + bump.height); // right
    } else {
        g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x + bump.width, (int) y + bump.y); // top
    }
    g.setColor(oldColor);
}

From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java

private void plotSubset(final Graphics2D g, final int start, final int end, final String title,
        final double startX, final double width, final double stepY, final double mean) {
    final FontMetrics fm = g.getFontMetrics();
    final Color color = g.getColor();
    g.setColor(Color.black);//from  w  w w. j ava 2  s.  com
    g.drawString(title, (int) (startX + width / 2 - fm.stringWidth(title) / 2), 975);
    final String tmp = String.format("Mean: %.3fus", mean);
    g.drawString(tmp, (int) (startX + width / 2 - fm.stringWidth(tmp) / 2), 990);
    g.setColor(color);
    final double stepX = width / (end - start);
    for (int i = start; i < end; i++) {
        final int posX = (int) (startX + stepX * (i - start));
        final int posY = 960 - ((int) (stepY * (timestamps[i] / 1000.0)) + 1);
        g.drawLine(posX, posY, posX, 960);
    }
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

@Override
public void draw(Graphics2D g) {
    g.drawImage(getImage(), (int) x, (int) y, Game.w);

    if (getAttackArea().getBounds().width > 0 && (clicked || hovered)) {
        Color oldColor = g.getColor();
        g.setColor(Color.darkGray);

        g.draw(getAttackArea());//w  ww . ja  va  2s  . c  o m
        g.setColor(oldColor);
    }

    // TODO: DEBUG
    // for (Vector p : structPoints.entries)
    // {
    // Vector v = p.clone();
    // v.mul(Tile.SIZE);
    // v.add(new Vector(x, y));
    //
    // Color old = g.getColor();
    // g.setColor(Color.green);
    // g.fillRect((int) v.x, (int) v.y, 4, 4);
    // g.setColor(old);
    // }
}