Example usage for java.awt Polygon getBounds

List of usage examples for java.awt Polygon getBounds

Introduction

In this page you can find the example usage for java.awt Polygon getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounding box of this Polygon .

Usage

From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java

public void calcGrids() {
    Rectangle2D rect = getBounds2D();
    double w = rect.getWidth();

    double h = rect.getHeight();

    if (h > 150 || w > 150) {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").fine("Error: " + this);
        return;/*from  ww  w  .  j  a v a2s  . c  om*/
    }

    int x = (int) rect.getX();
    int y = (int) rect.getY();

    int xSteps = (int) (w / (int) Grid.SIZE);
    int ySteps = (int) (h / (int) Grid.SIZE);

    for (int i = 0; i < xSteps; i++) {
        for (int j = 0; j < ySteps; j++) {
            Polygon p = new Polygon();
            p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
            p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
            if (this.contains(p.getBounds().x + Grid.SIZE / 2, p.getBounds().y + Grid.SIZE / 2)) {
                Pnt topLeft = new Pnt(x + i * Grid.SIZE, y + j * Grid.SIZE);
                Pnt bottomRight = new Pnt(x + i * Grid.SIZE + Grid.SIZE, y + Grid.SIZE + j * Grid.SIZE);
                Grid grid = new Grid(topLeft, bottomRight);
                grids.add(grid);
            }
        }
    }
}

From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java

public void fillRegion(Graphics2D g, boolean chessboard) {
    if (!resolved) {
        fillcolor = getColor(mainClass.classIndex);
        Color c = repairColor(fillcolor);
        g.setColor(c);/*from   ww  w.j  a va2 s  . com*/
        if (segments.isEmpty()) {
            return;
        }
        g.fillPolygon(this);
    } else {
        if (chessboard) {
            if (polygons == null) { // calculate polygons
                polygons = new ArrayList<Polygon>();

                Rectangle2D rect = getBounds2D();
                double w = rect.getWidth();

                double h = rect.getHeight();

                if (h > 200 || w > 200) {
                    Logger.getLogger("at.tuwien.ifs.somtoolbox").info("ERROR: h>200 || w>200");
                    return;
                }

                int x = (int) rect.getX();
                int y = (int) rect.getY();

                int xSteps = (int) (w / (int) Grid.SIZE);
                int ySteps = (int) (h / (int) Grid.SIZE);
                // int n = classes.size();
                for (int i = 0; i < xSteps; i++) {
                    for (int j = 0; j < ySteps; j++) {
                        Polygon p = new Polygon();
                        p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE),
                                (int) (y + Grid.SIZE + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
                        if (!this.contains(p.getBounds())) {
                            continue;
                        }
                        SOMClass clss = indexGenerator.getNextIndex();
                        g.setColor(getColor(clss.classIndex));
                        g.fillPolygon(p);
                        polygons.add(p);
                    }
                }
            } else { // use pre-calculated polygons
                for (int i = 0; i < polygons.size(); i++) {
                    SOMClass clss = indexGenerator.getNextIndex();
                    g.setColor(getColor(clss.classIndex));
                    Polygon p = polygons.get(i);
                    g.fillPolygon(p);
                }
            }
        } else {
            for (int i = 0; i < grids.size(); i++) {
                Grid grid = grids.get(i);
                if (grid.clss == null) {
                    continue;
                }
                g.setColor(getColor(grid.clss.classIndex));
                g.fillRect((int) grid.topLeft.coord(0), (int) grid.topLeft.coord(1), (int) Grid.SIZE,
                        (int) Grid.SIZE);
            }
        }
    }
}