Example usage for java.awt Graphics2D fillOval

List of usage examples for java.awt Graphics2D fillOval

Introduction

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

Prototype

public abstract void fillOval(int x, int y, int width, int height);

Source Link

Document

Fills an oval bounded by the specified rectangle with the current color.

Usage

From source file:au.org.ala.layers.web.UserDataService.java

@RequestMapping(value = WS_USERDATA_WMS, method = RequestMethod.GET)
public void getPointsMap(
        @RequestParam(value = "CQL_FILTER", required = false, defaultValue = "") String cql_filter,
        @RequestParam(value = "ENV", required = false, defaultValue = "") String env,
        @RequestParam(value = "BBOX", required = false, defaultValue = "") String bboxString,
        @RequestParam(value = "WIDTH", required = false, defaultValue = "") String widthString,
        @RequestParam(value = "HEIGHT", required = false, defaultValue = "") String heightString,
        HttpServletRequest request, HttpServletResponse response) {
    RecordsLookup.setUserDataDao(userDataDao);

    response.setHeader("Cache-Control", "max-age=86400"); //age == 1 day
    response.setContentType("image/png"); //only png images generated

    int width = 256, height = 256;
    try {/*from   w w  w  .j  a  v  a2 s  .c o m*/
        width = Integer.parseInt(widthString);
        height = Integer.parseInt(heightString);
    } catch (Exception e) {
        logger.error("error parsing to int: " + widthString + " or " + heightString, e);
    }

    try {
        env = URLDecoder.decode(env, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.error("error decoding env from UTF-8: " + env, e);
    }
    int red = 0, green = 0, blue = 0, alpha = 0;
    String name = "circle";
    int size = 4;
    boolean uncertainty = false;
    String highlight = null;
    String colourMode = null;
    for (String s : env.split(";")) {
        String[] pair = s.split(":");
        if (pair[0].equals("color")) {
            while (pair[1].length() < 6) {
                pair[1] = "0" + pair[1];
            }
            red = Integer.parseInt(pair[1].substring(0, 2), 16);
            green = Integer.parseInt(pair[1].substring(2, 4), 16);
            blue = Integer.parseInt(pair[1].substring(4), 16);
        } else if (pair[0].equals("name")) {
            name = pair[1];
        } else if (pair[0].equals("size")) {
            size = Integer.parseInt(pair[1]);
        } else if (pair[0].equals("opacity")) {
            alpha = (int) (255 * Double.parseDouble(pair[1]));
            //            } else if (pair[0].equals("uncertainty")) {
            //                uncertainty = true;
        } else if (pair[0].equals("sel")) {
            try {
                highlight = URLDecoder.decode(s.substring(4), "UTF-8").replace("%3B", ";");
            } catch (Exception e) {
            }
        } else if (pair[0].equals("colormode")) {
            colourMode = pair[1];
        }
    }

    double[] bbox = new double[4];
    int i;
    i = 0;
    for (String s : bboxString.split(",")) {
        try {
            bbox[i] = Double.parseDouble(s);
            i++;
        } catch (Exception e) {
            logger.error("error converting bounding box value to double: " + s, e);
        }
    }
    try {

        //adjust bbox extents with half pixel width/height
        double pixelWidth = (bbox[2] - bbox[0]) / width;
        double pixelHeight = (bbox[3] - bbox[1]) / height;
        bbox[0] += pixelWidth / 2;
        bbox[2] -= pixelWidth / 2;
        bbox[1] += pixelHeight / 2;
        bbox[3] -= pixelHeight / 2;

        //offset for points bounding box by size
        double xoffset = (bbox[2] - bbox[0]) / (double) width
                * (size + (highlight != null ? HIGHLIGHT_RADIUS * 2 + size * 0.2 : 0) + 5);
        double yoffset = (bbox[3] - bbox[1]) / (double) height
                * (size + (highlight != null ? HIGHLIGHT_RADIUS * 2 + size * 0.2 : 0) + 5);

        //check offset for points bb by maximum uncertainty (?? 30k ??)
        if (uncertainty) {
            double xuoffset = 30000;
            double yuoffset = 30000;
            if (xoffset < xuoffset) {
                xoffset = xuoffset;
            }
            if (yoffset < yuoffset) {
                yoffset = yuoffset;
            }
        }

        //adjust offset for pixel height/width
        xoffset += pixelWidth;
        yoffset += pixelHeight;

        double[][] bb = {
                { SpatialUtils.convertMetersToLng(bbox[0] - xoffset),
                        SpatialUtils.convertMetersToLat(bbox[1] - yoffset) },
                { SpatialUtils.convertMetersToLng(bbox[2] + xoffset),
                        SpatialUtils.convertMetersToLat(bbox[3] + yoffset) } };

        double[] pbbox = new double[4]; //pixel bounding box
        pbbox[0] = SpatialUtils.convertLngToPixel(SpatialUtils.convertMetersToLng(bbox[0]));
        pbbox[1] = SpatialUtils.convertLatToPixel(SpatialUtils.convertMetersToLat(bbox[1]));
        pbbox[2] = SpatialUtils.convertLngToPixel(SpatialUtils.convertMetersToLng(bbox[2]));
        pbbox[3] = SpatialUtils.convertLatToPixel(SpatialUtils.convertMetersToLat(bbox[3]));

        String lsid = null;
        int p1 = 0;
        int p2 = cql_filter.indexOf('&', p1 + 1);
        if (p2 < 0) {
            p2 = cql_filter.indexOf(';', p1 + 1);
        }
        if (p2 < 0) {
            p2 = cql_filter.length();
        }
        if (p1 >= 0) {
            lsid = cql_filter.substring(0, p2);
        }

        double[] points = null;
        ArrayList<QueryField> listHighlight = null;
        QueryField colours = null;
        double[] pointsBB = null;
        Facet facet = null;
        String[] facetFields = null;
        if (highlight != null && !(colourMode != null && colourMode.equals("grid"))) {
            facet = Facet.parseFacet(highlight);
            facetFields = facet.getFields();
            listHighlight = new ArrayList<QueryField>();
        }

        int[] idx = null;
        if (lsid != null) {
            Object[] data = (Object[]) RecordsLookup.getData(lsid);
            points = (double[]) data[1];
            pointsBB = (double[]) data[4];
            idx = (int[]) data[5];

            if (points == null || points.length == 0 || pointsBB[0] > bb[1][0] || pointsBB[2] < bb[0][0]
                    || pointsBB[1] > bb[1][1] || pointsBB[3] < bb[0][1]) {
                setImageBlank(response);
                return;
            }

            ArrayList<QueryField> fields = (ArrayList<QueryField>) data[2];

            for (int j = 0; j < fields.size(); j++) {
                if (facet != null) {
                    for (int k = 0; k < facetFields.length; k++) {
                        if (facetFields[k].equals(fields.get(j).getName())) {
                            listHighlight.add(fields.get(j));
                        }
                    }
                }
                if (colourMode != null) {
                    if (fields.get(j).getName().equals(colourMode)) {
                        synchronized (fields.get(j)) {
                            //need to resize 'colours' facet to the correct length and store as new QueryField
                            for (int k = 0; k < fields.size(); k++) {
                                if (fields.get(k).getName().equals(colourMode + " resized")) {
                                    colours = fields.get(k);
                                }
                            }

                            if (colours == null) {
                                colours = fields.get(j);

                                //does it need to be rebuilt to the correct length?
                                int count = colours.getIntData() != null ? colours.getIntData().length
                                        : colours.getLongData() != null ? colours.getLongData().length
                                                : colours.getFloatData() != null ? colours.getFloatData().length
                                                        : colours.getDoubleData() != null
                                                                ? colours.getDoubleData().length
                                                                : 0;
                                if (count != points.length / 2) {
                                    QueryField qf = new QueryField();
                                    qf.setDisplayName(colours.getDisplayName());
                                    qf.setName(colours.getName() + " resized");
                                    for (int k = 0; k < idx.length; k++) {
                                        qf.add(colours.getAsString(idx[k]));
                                    }
                                    qf.store();

                                    fields.add(qf);

                                    colours = qf;
                                }
                            }
                        }
                    }
                }
            }
        }

        /* TODO: make this a copy instead of create */
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) img.getGraphics();
        g.setColor(new Color(0, 0, 0, 0));
        g.fillRect(0, 0, width, height);

        g.setColor(new Color(red, green, blue, alpha));
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        int x, y;
        int pointWidth = size * 2 + 1;
        double width_mult = (width / (pbbox[2] - pbbox[0]));
        double height_mult = (height / (pbbox[1] - pbbox[3]));

        if (colourMode != null && colourMode.equals("grid")) {
            int divs = 16;
            double grid_width_mult = (width / (pbbox[2] - pbbox[0])) / (256 / divs);
            double grid_height_mult = (height / (pbbox[1] - pbbox[3])) / (256 / divs);
            int[][] gridCounts = new int[divs][divs];
            for (i = 0; i < points.length; i += 2) {
                x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * grid_width_mult);
                y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3]) * grid_height_mult);
                if (x >= 0 && x < divs && y >= 0 && y < divs) {
                    gridCounts[x][y]++;
                }
            }
            int xstep = 256 / divs;
            int ystep = 256 / divs;
            for (x = 0; x < divs; x++) {
                for (y = 0; y < divs; y++) {
                    int v = gridCounts[x][y];
                    if (v > 0) {
                        if (v > 500) {
                            v = 500;
                        }
                        int colour = Legend.getLinearColour(v, 0, 500, 0xFFFFFF00, 0xFFFF0000);
                        g.setColor(new Color(colour));
                        g.fillRect(x * xstep, y * ystep, xstep, ystep);
                    }
                }
            }
        } else {
            //circle type
            if (name.equals("circle")) {
                if (colours == null) {
                    for (i = 0; i < points.length; i += 2) {
                        if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1]
                                && points[i + 1] <= bb[1][1]) {
                            x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult);
                            y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3])
                                    * height_mult);
                            g.fillOval(x - size, y - size, pointWidth, pointWidth);
                        }
                    }
                } else {
                    int prevColour = -1; //!= colours[0]
                    g.setColor(new Color(prevColour));
                    for (i = 0; i < points.length; i += 2) {
                        if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1]
                                && points[i + 1] <= bb[1][1]) {
                            //colours is made the correct length, see above
                            int thisColour = colours.getColour(i / 2);
                            if (thisColour != prevColour) {
                                g.setColor(new Color(thisColour));
                                prevColour = thisColour;
                            }
                            x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult);
                            y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3])
                                    * height_mult);
                            g.fillOval(x - size, y - size, pointWidth, pointWidth);
                        }
                    }
                }
            }

            if (highlight != null && facet != null) {
                g.setStroke(new BasicStroke(2));
                g.setColor(new Color(255, 0, 0, 255));
                int sz = size + HIGHLIGHT_RADIUS;
                int w = sz * 2 + 1;

                for (i = 0; i < points.length; i += 2) {
                    if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1]
                            && points[i + 1] <= bb[1][1]) {

                        if (facet.isValid(listHighlight, idx[i / 2])) {
                            x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult);
                            y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3])
                                    * height_mult);
                            g.drawOval(x - sz, y - sz, w, w);
                        }
                    }
                }
            }
        }

        g.dispose();

        try {
            OutputStream os = response.getOutputStream();
            ImageIO.write(img, "png", os);
            os.flush();
            os.close();
        } catch (IOException e) {
            logger.error("error in outputting wms/reflect image as png", e);
        }
    } catch (Exception e) {
        logger.error("error generating wms/reflect tile", e);
    }

    //logger.debug("[wms tile: " + (System.currentTimeMillis() - start) + "ms]");
}

From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java

private void createNodeImage(long id, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int x, int y,
        Graphics2D g2) {
    Integer channel = channelMap.get(id);
    Integer colorIndex = colorMap.get(id);
    int radius = 11;
    if (channel == null || channel == 0 || colorIndex == null || colorIndex > startChannelColors.length - 1) {
        g2.setColor(new Color(180, 180, 180));
        g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
        return;//  w w  w.  ja  v a  2  s  . c  o m
    }
    g2.setColor(startChannelColors[colorIndex]);
    g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
    int dy = 6, w = 21;
    g2.fillRect(x, y - dy, w, dy + dy);
    dy = 5;
    g2.setColor(new Color(255, 255, 255));
    g2.fillRect(x + 1, y - dy, w - 2, dy + dy);
    g2.setColor(new Color(0, 51, 102));
    int chx = x + 2;
    if (channel < 100) {
        chx += 3;
    }
    if (channel < 10) {
        chx += 3;
    }
    g2.drawString("" + channel, chx, y + 4);
}

From source file:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java

public java.awt.Paint getSeriesPaint(int row) {
    BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bufferedImage.createGraphics();
    TexturePaint texture = null;/*from  w w  w .j ava 2  s . c o  m*/
    int rowNum = row + 1;
    int patNum = 13;
    int formula = rowNum - ((rowNum / patNum) * patNum);

    if (formula == 0) {
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);

    } else if (formula == 1) {
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 2) {
        Color color = Color.blue;
        big.setColor(Color.white);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(0, 1, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 3) {
        Color color = Color.yellow;
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(1, 1, 4, 4);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 4) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 5) {
        big.setColor(Color.magenta);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.pink);
        big.fillRect(0, 0, 4, 4);

        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 6) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);
        }

        big.setColor(new Color(226, 199, 252));
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.blue);
        big.setStroke(new BasicStroke(1.0f));

        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 7) {
        big.setColor(Color.lightGray);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.red);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 8) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);

        }
        big.setColor(Color.blue);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.cyan);
        big.setStroke(new BasicStroke(2.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 9) {
        Color color = new Color(0xBBBBDD);
        big.setColor(color);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(199, 201, 230));
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 10) {
        float[] x = { 1, 2, 3, 4, 5 };
        float[] y = { 1, 2, 3, 4, 5 };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[1]);
        path.lineTo(x[1], y[0]);
        path.moveTo(x[0], y[2]);
        path.lineTo(x[2], y[0]);
        path.moveTo(x[0], y[3]);
        path.lineTo(x[3], y[0]);
        path.moveTo(x[0], y[4]);
        path.lineTo(x[4], y[0]);
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(242, 242, 193));
        big.setStroke(new BasicStroke(3.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 11) {
        big.setColor(new Color(252, 169, 171));
        big.fillOval(0, 0, 5, 6);
        big.setColor(new Color(252, 230, 230));
        big.fillOval(0, 0, 3, 3);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 12) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(20, 178, 38));
        big.fillRect(2, 2, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    }
    return texture;

}

From source file:org.colombbus.tangara.CommandSelection.java

/**
 * Initializes the icons//from   w w  w  . j a v a  2s  .  c o m
 *
 */
private void initializeIcons() {
    BufferedImage imageSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) imageSelected.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(selectedBackgroundColor);
    g.fillRect(0, 0, iconSize, iconSize);
    g.setColor(Color.green);
    g.fillOval(0, 0, iconSize - 1, iconSize - 1);
    iconSelected = new ImageIcon(imageSelected);
    BufferedImage imageNotSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB);
    g = (Graphics2D) imageNotSelected.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(Color.white);
    g.fillRect(0, 0, iconSize, iconSize);
    g.setColor(Color.lightGray);
    g.fillOval(0, 0, iconSize - 1, iconSize - 1);
    iconNotSelected = new ImageIcon(imageNotSelected);
}

From source file:org.openiot.gsn.vsensor.DemoVSensor.java

public void dataAvailable(String inputStreamName, StreamElement data) {
    if (inputStreamName.equalsIgnoreCase("SSTREAM")) {
        String action = (String) data.getData("STATUS");
        /**/*from   w  w  w . jav  a2  s  . com*/
         * 
         */
        String moteId = (String) data.getData("ID");
        if (moteId.toLowerCase().indexOf("mica") < 0)
            return;
        if (action.toLowerCase().indexOf("add") >= 0)
            counter++;
        if (action.toLowerCase().indexOf("remove") >= 0)
            counter--;
    }
    if (inputStreamName.equalsIgnoreCase("CSTREAM")) {

        BufferedImage bufferedImage = null;
        outputStream.reset();
        byte[] rawData = (byte[]) data.getData("IMAGE");
        input = new ByteArrayInputStream(rawData);
        try {
            bufferedImage = ImageIO.read(input);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
        int size = 30;
        int locX = 0;
        int locY = 0;
        if (counter < 0)
            counter = 0;
        switch (counter) {
        case 0:
            graphics.setColor(Color.RED);
            break;
        case 1:
            graphics.setColor(Color.ORANGE);
            break;

        case 2:
            graphics.setColor(Color.YELLOW);
            break;

        case 3:
            graphics.setColor(Color.GREEN);
            break;
        default:
            logger.warn(
                    new StringBuilder().append("Shouldn't happen.>").append(counter).append("<").toString());
        }
        graphics.fillOval(locX, locY, size, size);
        try {
            ImageIO.write(bufferedImage, "jpeg", outputStream);
            outputStream.close();

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        StreamElement outputSE = new StreamElement(OUTPUT_FIELDS, OUTPUT_TYPES,
                new Serializable[] { outputStream.toByteArray() }, data.getTimeStamp());
        dataProduced(outputSE);
    }
    if (logger.isInfoEnabled())
        logger.info(new StringBuilder().append("Data received under the name: ").append(inputStreamName)
                .toString());
}

From source file:org.pmedv.blackboard.components.BoardEditor.java

@Override
protected void paintComponent(Graphics g) {
    Boolean useLayerColor = (Boolean) Preferences.values
            .get("org.pmedv.blackboard.BoardDesignerPerspective.useLayerColor");

    // clear all      
    // g.clearRect(0, 0, getWidth(), getHeight());
    g.setColor(BLANK);//from   w  ww. ja  v  a2s  .c  o m
    g.fillRect(0, 0, getWidth(), getHeight());
    // some nice anti aliasing...
    Graphics2D g2 = (Graphics2D) g;
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHints(rh);

    // TODO : Should this be done here?
    // Sort layers by z-index

    g2.setColor(Color.LIGHT_GRAY);
    g2.setStroke(BoardUtil.stroke_1_0f);

    Collections.sort(model.getLayers());
    for (int i = model.getLayers().size() - 1; i >= 0; i--) {
        // Sort items by z-index
        Collections.sort(model.getLayers().get(i).getItems());
        drawLayer(model.getLayers().get(i), g2);
    }

    // draw selection border
    if (state.equals(SelectionState.DRAGGING_NEW_SELECTION) && button1Pressed) {
        g2.setColor(Color.GREEN);
        g2.setStroke(BoardUtil.stroke_1_0f);
        if (dragStopX < dragStartX && dragStopY > dragStartY) {
            selectionBorder.setSize(dragStartX - dragStopX, dragStopY - dragStartY);
            selectionBorder.setLocation(dragStopX, dragStartY);
        } else if (dragStopY < dragStartY && dragStopX > dragStartX) {
            selectionBorder.setSize(dragStopX - dragStartX, dragStartY - dragStopY);
            selectionBorder.setLocation(dragStartX, dragStopY);
        } else if (dragStopX < dragStartX && dragStopY < dragStartY) {
            selectionBorder.setSize(dragStartX - dragStopX, dragStartY - dragStopY);
            selectionBorder.setLocation(dragStopX, dragStopY);
        } else {
            selectionBorder.setSize(dragStopX - dragStartX, dragStopY - dragStartY);
            selectionBorder.setLocation(dragStartX, dragStartY);
        }
        g2.draw(selectionBorder);
    }
    // display shape currently being drawed
    if (lineStartX > 0 && lineStartY > 0 && lineStopX > 0 && lineStopY > 0) {

        if (useLayerColor)
            g2.setColor(model.getCurrentLayer().getColor());
        else
            g2.setColor(palette.getCurrentColor());

        g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem());
        // draw new line
        if (editorMode.equals(EditorMode.DRAW_LINE)) {

            if (useLayerColor)
                currentDrawingLine.setColor(model.getCurrentLayer().getColor());
            else
                currentDrawingLine.setColor(palette.getCurrentColor());

            currentDrawingLine.setStartType((LineEdgeType) shapesPanel.getStartLineCombo().getSelectedItem());
            currentDrawingLine.setEndType((LineEdgeType) shapesPanel.getEndLineCombo().getSelectedItem());
            currentDrawingLine.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem());
            currentDrawingLine.getStart().setLocation(lineStartX, lineStartY);
            currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY);
            currentDrawingLine.draw(g2);
        } else if (editorMode.equals(EditorMode.DRAW_MEASURE)) {
            currentDrawingLine.setStroke(Measure.DEFAULT_STROKE);
            currentDrawingLine.getStart().setLocation(lineStartX, lineStartY);
            currentDrawingLine.getEnd().setLocation(lineStopX, lineStopY);
            currentDrawingLine.draw(g2);
        }
        // draw new box or ellipse
        else if (editorMode.equals(EditorMode.DRAW_RECTANGLE) || editorMode.equals(EditorMode.DRAW_ELLIPSE)) {
            int xLoc = lineStartX;
            int yLoc = lineStartY;
            int width = lineStopX - lineStartX;
            int height = lineStopY - lineStartY;
            ShapeStyle style = (ShapeStyle) shapesPanel.getStyleCombo().getSelectedItem();
            if (style == null || style.equals(ShapeStyle.FILLED)) {
                if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) {
                    g2.fillRect(xLoc, yLoc, width, height);
                } else {
                    g2.fillOval(xLoc, yLoc, width, height);
                }
            } else if (style.equals(ShapeStyle.OUTLINED)) {
                g2.setStroke((BasicStroke) shapesPanel.getThicknessCombo().getSelectedItem());
                if (editorMode.equals(EditorMode.DRAW_RECTANGLE)) {
                    g2.drawRect(xLoc, yLoc, width, height);
                } else {
                    g2.drawOval(xLoc, yLoc, width, height);
                }
            }
        }
    }
    // draw selection handles
    if (selectedItem != null) {
        g2.setStroke(BoardUtil.stroke_1_0f);
        g2.setColor(Color.GREEN);
        selectedItem.drawHandles(g2, 8);
    }

    // draw border

    if (zoomLayer != null) {
        TransformUI ui = (TransformUI) (Object) zoomLayer.getUI();
        DefaultTransformModel xmodel = (DefaultTransformModel) ui.getModel();

        if (xmodel.isMirror()) {
            g2.setColor(Color.RED);
        } else {
            g2.setColor(Color.GREEN);
        }
    } else {
        g2.setColor(Color.GREEN);
    }

    g2.setStroke(DEFAULT_STROKE);

    Rectangle border = new Rectangle(0, 0, model.getWidth() - 1, model.getHeight() - 1);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2.draw(border);

    if (model.getType().equals(BoardType.STRIPES) || model.getType().equals(BoardType.HOLES)) {

        g2.setColor(Color.BLACK);
        g2.setFont(miniFont);

        int index = 1;

        for (int x = 12; x < model.getWidth() - 16; x += 16) {
            g2.drawString(String.valueOf(index++), x, 8);
        }

        index = 1;

        for (int y = 18; y < model.getHeight(); y += 16) {
            g2.drawString(String.valueOf(index++), 3, y);
        }

    }

    if (editorMode.equals(EditorMode.CHECK_CONNECTIONS)) {
        if (connectedLines != null) {
            for (Line line : connectedLines) {
                line.drawFat(g2);
            }
        }
    }

    if (drawing) {

        g2.setColor(Color.BLUE);
        g2.setStroke(DEFAULT_STROKE);

        if (selectedPin != null) {
            g2.drawRect(lineStopX - 8, lineStopY - 8, 16, 16);
        }

    }

    super.paintComponents(g2);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.DebugVisualizationUtility.java

private static byte[] drawPartHeatmap(byte[] imageBytes, Model.PartType partType, float[][][] outputTensor,
        Color color) {/*from  ww  w.  j  av a2  s  .c om*/

    return new ImageGraphicsTemplate() {
        @Override
        public void drawWithingImage(Graphics2D g) {
            g.setColor(color);
            for (int x = 0; x < outputTensor.length; x++) {
                for (int y = 0; y < outputTensor[0].length; y++) {
                    float partScore = outputTensor[x][y][partType.getId()];
                    g.fillOval(y * 8, x * 8, (int) (15 * partScore), (int) (15 * partScore));
                }
            }
        }
    }.draw(imageBytes);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.DebugVisualizationUtility.java

private static byte[] drawPartCandidate(byte[] imageBytes, Part partCandidate, Color color) {

    return new ImageGraphicsTemplate() {
        @Override//from ww w.j ava  2 s. c  o  m
        public void drawWithingImage(Graphics2D g) {
            g.setColor(color);
            int partScore = (int) (20 * partCandidate.getConfidence());
            g.fillOval(partCandidate.getNormalizedX() - partScore / 2,
                    partCandidate.getNormalizedY() - partScore / 2, partScore, partScore);

        }
    }.draw(imageBytes);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.DebugVisualizationUtility.java

private static byte[] drawLimbCandidate(byte[] imageBytes, Limb limb) {

    return new ImageGraphicsTemplate() {
        @Override/*from   w w  w .j  ava  2  s. c om*/
        public void drawWithingImage(Graphics2D g) {
            Part from = limb.getFromPart();
            Part to = limb.getToPart();

            int x1 = from.getNormalizedX();
            int x2 = to.getNormalizedX();

            int y1 = from.getNormalizedY();
            int y2 = to.getNormalizedY();

            int xl = (x2 - x1) / 2;
            int yl = (y2 - y1) / 2;

            g.setColor(GraphicsUtils.yellow);
            g.drawString(String.format("%.2f", limb.getPafScore()), x1 + xl + 5, y1 + yl + 5);

            g.setColor(new Color(167, 252, 0));
            g.draw(new Line2D.Double(from.getNormalizedX(), from.getNormalizedY(), to.getNormalizedX(),
                    to.getNormalizedY()));

            g.setColor(GraphicsUtils.CLASS_COLOR2[from.getPartType().getId()]);
            g.fillOval(from.getNormalizedX() - OVAL_WIDTH / 2, from.getNormalizedY() - OVAL_WIDTH / 2,
                    OVAL_WIDTH, OVAL_HEIGHT);
            g.setColor(GraphicsUtils.CLASS_COLOR2[to.getPartType().getId()]);
            g.fillOval(to.getNormalizedX() - OVAL_WIDTH / 2, to.getNormalizedY() - OVAL_WIDTH / 2, OVAL_WIDTH,
                    OVAL_HEIGHT);
        }
    }.draw(imageBytes);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java

private void drawPartOval(Part part, int radius, Graphics2D g) {
    int partX = part.getNormalizedX();
    int partY = part.getNormalizedY();

    g.setColor(GraphicsUtils.LIMBS_COLORS[part.getPartType().getId()]);
    g.fillOval(partX - radius, partY - radius, 2 * radius, 2 * radius);

    if (this.poseProperties.isDrawPartLabels()) {
        String label = part.getPartType().getId() + ":" + part.getPartType().name();
        FontMetrics fm = g.getFontMetrics();
        int labelX = partX + 5;
        int labelY = partY - 5;
        AffineTransform t = g.getTransform();
        g.setTransform(AffineTransform.getRotateInstance(Math.toRadians(-35), labelX, labelY));

        g.drawString(label, labelX, labelY);
        g.setTransform(t);//  w  w w  .j  a va  2s  .  c o m
    }

}