Example usage for java.awt Graphics2D setColor

List of usage examples for java.awt Graphics2D setColor

Introduction

In this page you can find the example usage for java.awt Graphics2D 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:com.ikon.module.common.CommonWorkflowModule.java

/**
 * Get Process Definition Image//  w  w w.  j  a  va 2 s . com
 */
public static byte[] getProcessDefinitionImage(long processDefinitionId, String node) throws WorkflowException {
    log.debug("getProcessDefinitionImage({}, {})", new Object[] { processDefinitionId, node });
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    byte[] image = null;

    try {
        GraphSession graphSession = jbpmContext.getGraphSession();
        org.jbpm.graph.def.ProcessDefinition pd = graphSession.getProcessDefinition(processDefinitionId);
        FileDefinition fileDef = pd.getFileDefinition();

        WorkflowUtils.DiagramInfo dInfo = WorkflowUtils.getDiagramInfo(fileDef.getInputStream("gpd.xml"));
        WorkflowUtils.DiagramNodeInfo dNodeInfo = dInfo.getNodeMap().get(node);
        BufferedImage img = ImageIO.read(fileDef.getInputStream("processimage.jpg"));

        // Obtain all nodes Y and X
        List<Integer> ordenadas = new ArrayList<Integer>();
        List<Integer> abcisas = new ArrayList<Integer>();

        for (WorkflowUtils.DiagramNodeInfo nodeInfo : dInfo.getNodeMap().values()) {
            ordenadas.add(nodeInfo.getY());
            abcisas.add(nodeInfo.getX());
        }

        // Calculate minimal Y
        Collections.sort(ordenadas);
        int fixOrd = ordenadas.get(0) < 0 ? ordenadas.get(0) : 0;

        // Calculate minimal X
        Collections.sort(abcisas);
        int fixAbs = abcisas.get(0) < 0 ? abcisas.get(0) : 0;

        if (dNodeInfo != null) {
            // Select node
            log.debug("DiagramNodeInfo: {}", dNodeInfo);
            Graphics g = img.getGraphics();
            Graphics2D g2d = (Graphics2D) g;
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25F));
            g2d.setColor(Color.blue);
            g2d.fillRect(dNodeInfo.getX() - fixAbs, dNodeInfo.getY() - fixOrd, dNodeInfo.getWidth(),
                    dNodeInfo.getHeight());
            g.dispose();
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(img, "jpg", baos);
        image = baos.toByteArray();
        baos.flush();
        baos.close();
    } catch (JbpmException e) {
        throw new WorkflowException(e.getMessage(), e);
    } catch (IOException e) {
        throw new WorkflowException(e.getMessage(), e);
    } finally {
        jbpmContext.close();
    }

    log.debug("getProcessDefinitionImage: {}", image);
    return image;
}

From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java

/**
 * Default constructor.// w w  w.  j  a  v  a  2s  . com
 */
public TilingPatternExample() {
    //Created TexturePaint instance
    this.tile = new BufferedImage(40, 20, BufferedImage.TYPE_INT_RGB);
    Graphics2D tileg2d = tile.createGraphics();
    tileg2d.setBackground(Color.WHITE);
    tileg2d.clearRect(0, 0, tile.getWidth(), tile.getHeight());
    tileg2d.setColor(Color.BLUE);
    tileg2d.fillOval(2, 2, tile.getWidth() - 2, tile.getHeight() - 2);
    tileg2d.dispose();
    Rectangle2D rect = new Rectangle2D.Double(2, 2, tile.getWidth() / 2.0, tile.getHeight() / 2.0);
    this.paint = new TexturePaint(tile, rect);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.intersects(20, 20, 300, 300);/*from   w  ww . j  a v  a  2  s .c om*/

    g2.setColor(Color.orange);
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("intersect", 20, 140);
}

From source file:org.n52.server.sos.generator.DiagramGenerator.java

/**
 * Creates a time series chart diagram and writes it to the OutputStream.
 * //from  w ww  . ja  v a2  s . com
 * @param entireCollMap
 * @param options
 * @param out
 * @throws OXFException
 * @throws IOException
 */
public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        FileOutputStream out, boolean compress) throws OXFException, IOException {

    // render features:
    int width = options.getWidth();
    int height = options.getHeight();
    Calendar begin = Calendar.getInstance();
    begin.setTimeInMillis(options.getBegin());
    Calendar end = Calendar.getInstance();
    end.setTimeInMillis(options.getEnd());

    DiagramRenderer renderer = new DiagramRenderer(false);

    JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress);
    diagramChart.removeLegend();

    // draw chart into image:
    BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB);
    Graphics2D chartGraphics = diagramImage.createGraphics();
    chartGraphics.setColor(Color.white);
    chartGraphics.fillRect(0, 0, width, height);

    diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));

    JPEGEncodeParam p = new JPEGEncodeParam();
    p.setQuality(1f);
    ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p);

    encoder.encode(diagramImage);
}

From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer4xPhenomenons.java

/**
 * The resulting IVisualization shows a chart which consists a TimeSeries for each FeatureOfInterest
 * contained in the observationCollection.
 */// www  . ja  v  a2  s . c om
public IVisualization renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon,
        int width, int height) {
    JFreeChart chart = renderChart(observationCollection, paramCon);

    // draw plot into image:
    Plot plot = chart.getPlot();
    BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D chartGraphics = chartImage.createGraphics();
    chartGraphics.setColor(Color.white);
    chartGraphics.fillRect(0, 0, width, height);
    plot.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height), null, null, null);

    // draw legend into image:
    LegendTitle legend = chart.getLegend();
    BufferedImage legendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D legendGraphics = legendImage.createGraphics();
    legendGraphics.setColor(Color.white);
    legendGraphics.fillRect(0, 0, (int) legend.getWidth(), (int) legend.getHeight());
    legend.draw(legendGraphics, new Rectangle2D.Float(0, 0, width, height));

    return new StaticVisualization(chartImage, legendImage);
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D twoD = (Graphics2D) g;

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    twoD.setRenderingHints(rh);//  www  . ja  v a2 s  .co m

    twoD.setColor(Color.BLACK);

    twoD.drawString(raised, 5, 90);
}

From source file:com.hofbauer.robocode.robots.RobotSimWithAction.java

@Override
public void onPaint(Graphics2D g) {
    g.setColor(Color.red);
    g.drawOval((int) (getX() - 50), (int) (getY() - 50), 100, 100);
    g.setColor(new Color(0, 0xFF, 0, 30));
    g.fillOval((int) (getX() - 60), (int) (getY() - 60), 120, 120);
}

From source file:MouseMoveScale.java

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

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    g2d.setColor(new Color(0, 0, 200));
    g2d.fill(myRect);/*from   w ww . java  2s .  c  o m*/
}

From source file:Pear.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();//from  ww w .j a v  a2 s .  co m
    int w = d.width;
    int h = d.height;
    double ew = w / 2;
    double eh = h / 2;

    g2.setColor(Color.green);

    // Creates the first leaf by filling the intersection of two Area objects
    // created from an ellipse.
    leaf.setFrame(ew - 16, eh - 29, 15.0, 15.0);
    leaf1 = new Area(leaf);
    leaf.setFrame(ew - 14, eh - 47, 30.0, 30.0);
    leaf2 = new Area(leaf);
    leaf1.intersect(leaf2);
    g2.fill(leaf1);

    // Creates the second leaf.
    leaf.setFrame(ew + 1, eh - 29, 15.0, 15.0);
    leaf1 = new Area(leaf);
    leaf2.intersect(leaf1);
    g2.fill(leaf2);

    g2.setColor(Color.black);

    // Creates the stem by filling the Area resulting from the subtraction of
    // two Area objects created from an ellipse.
    stem.setFrame(ew, eh - 42, 40.0, 40.0);
    st1 = new Area(stem);
    stem.setFrame(ew + 3, eh - 47, 50.0, 50.0);
    st2 = new Area(stem);
    st1.subtract(st2);
    g2.fill(st1);

    g2.setColor(Color.yellow);

    // Creates the pear itself by filling the Area resulting from the union of
    // two Area objects created by two different ellipses.
    circle.setFrame(ew - 25, eh, 50.0, 50.0);
    oval.setFrame(ew - 19, eh - 20, 40.0, 70.0);
    circ = new Area(circle);
    ov = new Area(oval);
    circ.add(ov);
    g2.fill(circ);
}

From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java

private void generateMarkerWithFlag(String basePath, String company, String entity, String color)
        throws IOException {
    BufferedImage templateIcon = ImageIO.read(new File(getIconFolder(basePath, ICON_FOLDER) + TEMPLATE_FILE));
    BufferedImage icon = new BufferedImage(templateIcon.getWidth(), templateIcon.getHeight() + ICON_INCR_HEIGHT,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = icon.createGraphics();
    graphics.setColor(new Color(Integer.parseInt(color, 16)));
    graphics.drawRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT);
    graphics.fillRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT);
    graphics.drawImage(templateIcon, 0, ICON_INCR_HEIGHT, null);
    graphics.dispose();// w  ww .  j  av  a  2s  .  c o  m
    ImageIO.write(icon, ICON_TYPE, new File(getIconFolder(basePath, ICON_FOLDER_CACHE) + company + "-" + entity
            + "-" + color + ICON_EXTENSION));
}