Example usage for java.awt Graphics2D fillPolygon

List of usage examples for java.awt Graphics2D fillPolygon

Introduction

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

Prototype

public void fillPolygon(Polygon p) 

Source Link

Document

Fills the polygon defined by the specified Polygon object with the graphics context's current color.

Usage

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Draws an arrow from <code>(xCenter,yCenter)</code> to <code>(x,y)</code>.
 * Code stolen from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135.
 * //from   w ww  . j a v  a  2 s  . c  o  m
 * @param g the graphics context to draw in
 * @param headSize the size of the arrow head
 * @param xCenter the x-coord of the arrow tail
 * @param yCenter the y-coord of the arrow tail
 * @param x the x-coord of the arrow head's tip
 * @param y the y-coord of the arrow head's tip
 * @param stroke the <code>Stroke</code> to use
 */
public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y, int headSize, float stroke) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.addRenderingHints(hints);

    double aDir = Math.atan2(xCenter - x, yCenter - y);
    Stroke origStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(stroke)); // make the arrow head solid even if dash pattern has been specified
    g2d.drawLine(x, y, xCenter, yCenter);
    Polygon tmpPoly = new Polygon();
    int i1 = 2 * headSize + (int) stroke; //(stroke * 2);
    int i2 = headSize + (int) stroke; // make the arrow head the same size regardless of the length length
    tmpPoly.addPoint(x, y); // arrow tip
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);
    g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted
    g2d.setStroke(origStroke);
}

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);//  w w w  . ja  va2 s  .  c o m
        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);
            }
        }
    }
}

From source file:HelloUniverse.java

private void drawZPip(Graphics2D g2, float zAngle) {
    AffineTransform trans = new AffineTransform();
    Color origColor = g2.getColor();

    trans.translate(margin, margin);/*from   w ww. j  a v  a  2s  . c  o  m*/
    trans.rotate(zAngle, diameter / 2, diameter / 2);

    g2.setXORMode(getBackground());
    g2.setTransform(trans);
    g2.setColor(Color.red);
    g2.fillPolygon(zPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

private void drawLegendLine(Graphics2D g2, int verticalOffset, double horizontalNumberOffset, Color col,
        String txt, String numberText, boolean textIsPlural, boolean withSubSegment, String subSegmentText,
        String subNumberText, boolean subTextIsPlural) {
    int left = 620;
    // col == null --> total --> kein Rechteck
    if (col != null) {
        g2.drawImage(keyShadow.getImage(), left, 30 + verticalOffset, keyShadow.getImageObserver());
        g2.setColor(col);//  w  w  w. ja  v a  2 s. c  o  m
        g2.fillRect(left + 13, 37 + verticalOffset, 45, 45);
        if (withSubSegment) {
            Polygon p = new Polygon(new int[] { left + 13 + 45, left + 13 + 45, left + 13 },
                    new int[] { verticalOffset + 37, verticalOffset + 37 + 45, verticalOffset + 37 + 45 }, 3);
            g2.setColor(col.darker());
            g2.fillPolygon(p);
        }
    }
    g2.setColor(Color.BLACK);
    StringBuffer sb = new StringBuffer(numberText);
    sb.append("  ").append(plural(textIsPlural, txt));
    if (withSubSegment) {
        sb.append(" with ");
        sb.append(subNumberText);
        sb.append(" ");
        sb.append(plural(subTextIsPlural, subSegmentText));
    }
    g2.drawString(sb.toString(), (int) (left + 80 + horizontalNumberOffset), 30 + 41 + verticalOffset);

}

From source file:HelloUniverse.java

private void drawXPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int y;/*from w  w w  . ja  v  a2s .c om*/
    int xOrig = margin + diameter + space;
    int yOrig = margin;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        y = yOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        y = yOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront of wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(xBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(xOrig + pipOffset, y);
    g2.setTransform(trans);
    g2.fillPolygon(xPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:HelloUniverse.java

private void drawYPip(Graphics2D g2, float angle) {
    AffineTransform trans = new AffineTransform();
    int x;// w w  w .j  a va 2s .  c  o m
    int xOrig = margin;
    int yOrig = margin + diameter + space;
    Color origColor = g2.getColor();

    if (angle <= Math.PI) {
        x = xOrig + diameter - (int) ((Math.abs(angle - Math.PI / 2) / (Math.PI / 2)) * diameter / 2);
    } else
        x = xOrig + (int) ((Math.abs((angle - Math.PI * 1.5)) / (Math.PI / 2)) * diameter / 2);

    if (angle < Math.PI / 2 || angle > Math.PI * 1.5)
        g2.setColor(Color.red); // Infront on wheel
    else {
        g2.setColor(Color.black); // Behind Wheel
        g2.setClip(yBackClip);
    }

    g2.setXORMode(getBackground());
    trans.setToTranslation(x, yOrig + pipOffset);
    g2.setTransform(trans);
    g2.fillPolygon(yPip);

    // Reset graphics context
    trans.setToIdentity();
    g2.setTransform(trans);
    g2.setColor(origColor);
    g2.setPaintMode();
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintCollapsedNode(final Graphics2D g, final PhylogenyNode node,
        final boolean to_graphics_file, final boolean to_pdf, final boolean is_in_found_nodes) {
    if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
        g.setColor(Color.BLACK);//from   ww  w.ja  v  a  2 s  .c o  m
    } else if (is_in_found_nodes) {
        g.setColor(getTreeColorSet().getFoundColor());
    } else if (getControlPanel().isColorAccordingToTaxonomy()) {
        g.setColor(getTaxonomyBasedColor(node));
    } else {
        g.setColor(getTreeColorSet().getCollapseFillColor());
    }
    double d = node.getAllExternalDescendants().size();
    if (d > 1000) {
        d = (3 * _y_distance) / 3;
    } else {
        d = (Math.log10(d) * _y_distance) / 2.5;
    }
    if (d < BOX_SIZE) {
        d = BOX_SIZE;
    }
    _polygon.reset();
    _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() - TreePanel.BOX_SIZE),
            ForesterUtil.roundToInt(node.getYcoord()));
    _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() + TreePanel.BOX_SIZE),
            ForesterUtil.roundToInt(node.getYcoord() - d));
    _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() + TreePanel.BOX_SIZE),
            ForesterUtil.roundToInt(node.getYcoord() + d));
    g.fillPolygon(_polygon);
    paintNodeData(g, node, to_graphics_file, to_pdf, is_in_found_nodes);
}

From source file:lu.fisch.unimozer.Diagram.java

private void drawCompoAggregation2(Graphics2D g, MyClass thisClass, MyClass otherClass,
        Hashtable<MyClass, Vector<MyClass>> classUsings, boolean isComposition) {
    if (thisClass != otherClass) {
        Point thisTop = new Point(thisClass.getX() + thisClass.getWidth() / 2, thisClass.getY());
        Point thisBottom = new Point(thisClass.getX() + thisClass.getWidth() / 2,
                thisClass.getY() + thisClass.getHeight());
        Point thisLeft = new Point(thisClass.getX(), thisClass.getY() + thisClass.getHeight() / 2);
        Point thisRight = new Point(thisClass.getX() + thisClass.getWidth(),
                thisClass.getY() + thisClass.getHeight() / 2);
        Point[] thisPoints = { thisTop, thisBottom, thisLeft, thisRight };

        Point otherTop = new Point(otherClass.getX() + otherClass.getWidth() / 2, otherClass.getY());
        Point otherBottom = new Point(otherClass.getX() + otherClass.getWidth() / 2,
                otherClass.getY() + otherClass.getHeight());
        Point otherLeft = new Point(otherClass.getX(), otherClass.getY() + otherClass.getHeight() / 2);
        Point otherRight = new Point(otherClass.getX() + otherClass.getWidth(),
                otherClass.getY() + otherClass.getHeight() / 2);
        Point[] otherPoints = { otherTop, otherBottom, otherLeft, otherRight };

        double min = Double.MAX_VALUE;
        Point thisPoint = null;//from   w ww .ja  v  a2  s  .c o  m
        Point otherPoint = null;
        double thisMin;

        // determine closest middelst
        for (int i = 0; i < thisPoints.length; i++)
            for (int j = 0; j < otherPoints.length; j++) {
                thisMin = thisPoints[i].distance(otherPoints[j]);
                if (thisMin < min) {
                    min = thisMin;
                    thisPoint = thisPoints[i];
                    otherPoint = otherPoints[j];
                }
            }

        //Vector<MyClass> others = classUsings.get(thisClass);
        Vector<MyClass> usingsThisClass = classUsings.get(thisClass);
        // iterate through all usages
        /*Set<MyClass> set = classUsings.keySet();
        Iterator<MyClass> itr = set.iterator();
        while (itr.hasNext())
        {
        // get the actual class ...
        MyClass actual = itr.next();
        // ... and the list of classes it uses
        Vector<MyClass> actualUses = classUsings.get(actual);
        // iterate through that list
        for(MyClass used : actualUses)
        {
            // add the actual class if
            // - it usesd the "otherClass"
            // - and the actual class has not yet been captured
            if(used==thisClass && !usingsThisClass.contains(actual)) usingsThisClass.add(actual);
        }
        }*/

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) {
            // get the actual class ...
            MyClass actual = entry.getKey();
            // ... and the list of classes it uses
            Vector<MyClass> actualUses = classUsings.get(actual);
            // iterate through that list
            for (MyClass used : actualUses) {
                // add the actual class if
                // - it usesd the "otherClass"
                // - and the actual class has not yet been captured
                if (used == thisClass && !usingsThisClass.contains(actual))
                    usingsThisClass.add(actual);
            }
        }

        Stroke oldStroke = g.getStroke();

        if (thisPoint == thisTop) {
            // init number of connectionx
            int thisCon = 1;
            // init the direction into which to move
            int thisDir = 1;
            if (thisPoint.x > otherPoint.x)
                thisDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsThisClass) {
                // check goto right
                if ((other.getCenter().y < thisClass.getCenter().y)
                        && (other.getCenter().x >= thisClass.getCenter().x)
                        && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1))
                    thisCon++;
                // check goto left
                if ((other.getCenter().y < thisClass.getCenter().y)
                        && (other.getCenter().x < thisClass.getCenter().x)
                        && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1))
                    thisCon++;
            }
            int con = thisCon;
            thisCon = (int) ((thisCon - 0.5) * (12 * thisDir));

            Polygon p = new Polygon();
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2,
                    thisClass.getPosition().y);
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4,
                    thisClass.getPosition().y - 8);
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2,
                    thisClass.getPosition().y - 16);
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4,
                    thisClass.getPosition().y - 8);
            if (isComposition)
                g.fillPolygon(p);
            else
                g.drawPolygon(p);

            thisPoint.y -= 15;
            thisPoint.x += thisCon;

            Point movePoint = new Point(thisPoint);
            movePoint.y -= (usingsThisClass.size() - con) * 8;
            g.setStroke(dashed);
            drawLine(g, thisPoint, movePoint);
            thisPoint = movePoint;
        } else if (thisPoint == thisBottom) {
            // init number of connectionx
            int thisCon = 1;
            // init the direction into which to move
            int thisDir = 1;
            if (thisPoint.x > otherPoint.x)
                thisDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsThisClass) {
                // check goto right
                if ((other.getCenter().y >= thisClass.getCenter().y)
                        && (other.getCenter().x >= thisClass.getCenter().x)
                        && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1))
                    thisCon++;
                // check goto left
                if ((other.getCenter().y >= thisClass.getCenter().y)
                        && (other.getCenter().x < thisClass.getCenter().x)
                        && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1))
                    thisCon++;
            }
            int con = thisCon;
            thisCon = (int) ((thisCon - 0.5) * (12 * thisDir));

            // bottom
            Polygon p = new Polygon();
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2,
                    thisClass.getPosition().y + thisClass.getHeight());
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4,
                    thisClass.getPosition().y + thisClass.getHeight() + 8);
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2,
                    thisClass.getPosition().y + thisClass.getHeight() + 16);
            p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4,
                    thisClass.getPosition().y + thisClass.getHeight() + 8);
            if (isComposition)
                g.fillPolygon(p);
            else
                g.drawPolygon(p);

            thisPoint.y += 15;
            thisPoint.x += thisCon;

            Point movePoint = new Point(thisPoint);
            movePoint.y += (usingsThisClass.size() - con) * 8;
            g.setStroke(dashed);
            drawLine(g, thisPoint, movePoint);
            thisPoint = movePoint;
        } else if (thisPoint == thisRight) {
            // init number of connectionx
            int thisCon = 1;
            // init the direction into which to move
            int thisDir = 1;
            if (thisPoint.y > otherPoint.y)
                thisDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsThisClass) {
                // check goto up
                if ((other.getCenter().x >= thisClass.getCenter().x)
                        && (other.getCenter().y >= thisClass.getCenter().y)
                        && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1))
                    thisCon++;
                // check goto down
                if ((other.getCenter().x >= thisClass.getCenter().x)
                        && (other.getCenter().y < thisClass.getCenter().y)
                        && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1))
                    thisCon++;
            }
            int con = thisCon;
            thisCon = (int) ((thisCon - 0.5) * (12 * thisDir));

            // right
            Polygon p = new Polygon();
            //thisCON = thisClass.getConnector().getNewBottom(otherDIR);
            p.addPoint(thisClass.getPosition().x + thisClass.getWidth(),
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2);
            p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4);
            p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 16,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2);
            p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4);
            if (isComposition)
                g.fillPolygon(p);
            else
                g.drawPolygon(p);

            thisPoint.x += 15;
            thisPoint.y += thisCon;

            Point movePoint = new Point(thisPoint);
            movePoint.x += (usingsThisClass.size() - con) * 8;
            g.setStroke(dashed);
            drawLine(g, thisPoint, movePoint);
            thisPoint = movePoint;
        } else // left
        {
            // init number of connectionx
            int thisCon = 1;
            // init the direction into which to move
            int thisDir = 1;
            if (thisPoint.y > otherPoint.y)
                thisDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsThisClass) {
                // check goto up
                if ((other.getCenter().x < thisClass.getCenter().x)
                        && (other.getCenter().y >= thisClass.getCenter().y)
                        && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1))
                    thisCon++;
                // check goto down
                if ((other.getCenter().x < thisClass.getCenter().x)
                        && (other.getCenter().y < thisClass.getCenter().y)
                        && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1))
                    thisCon++;
            }
            int con = thisCon;
            thisCon = (int) ((thisCon - 0.5) * (12 * thisDir));

            Polygon p = new Polygon();
            p.addPoint(thisClass.getPosition().x,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2);
            p.addPoint(thisClass.getPosition().x - 8,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4);
            p.addPoint(thisClass.getPosition().x - 16,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2);
            p.addPoint(thisClass.getPosition().x - 8,
                    thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4);
            if (isComposition)
                g.fillPolygon(p);
            else
                g.drawPolygon(p);

            thisPoint.y += thisCon;
            thisPoint.x -= 15;

            Point movePoint = new Point(thisPoint);
            movePoint.x -= (usingsThisClass.size() - con) * 8;
            g.setStroke(dashed);
            drawLine(g, thisPoint, movePoint);
            thisPoint = movePoint;
        }

        //Vector<MyClass> others = classUsings.get(otherClass);
        Vector<MyClass> usingsOtherClass = classUsings.get(otherClass);
        /*
        // iterate through all usages
        set = classUsings.keySet();
        itr = set.iterator();
        while (itr.hasNext())
        {
        // get the actual class ...
        MyClass actual = itr.next();
        // ... and the list of classes it uses
        Vector<MyClass> actualUses = classUsings.get(actual);
        // iterate through that list
        for(MyClass used : actualUses)
        {
            // add the actual class if
            // - it usesd the "otherClass"
            // - and the actual class has not yet been captured
            if(used==otherClass && !usingsOtherClass.contains(actual)) usingsOtherClass.add(actual);
        }
        }
        */

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) {
            // get the actual class ...
            MyClass actual = entry.getKey();
            // ... and the list of classes it uses
            Vector<MyClass> actualUses = classUsings.get(actual);
            // iterate through that list
            for (MyClass used : actualUses) {
                // add the actual class if
                // - it usesd the "otherClass"
                // - and the actual class has not yet been captured
                if (used == otherClass && !usingsOtherClass.contains(actual))
                    usingsOtherClass.add(actual);
            }
        }

        Point stopUp;
        Point stopDown;
        Point stopOut;
        Point step;
        Point start = thisPoint;
        Point stop;

        if (otherPoint == otherTop) {
            // init number of connectionx
            int otherCon = 1;
            // init the direction into which to move
            int otherDir = 1;
            if (otherPoint.x > thisPoint.x)
                otherDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsOtherClass) {
                // check goto right
                if ((other.getCenter().y < otherClass.getCenter().y)
                        && (other.getCenter().x >= otherClass.getCenter().x)
                        && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == 1))
                    otherCon++;
                // check goto left
                if ((other.getCenter().y < otherClass.getCenter().y)
                        && (other.getCenter().x < otherClass.getCenter().x)
                        && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == -1))
                    otherCon++;
            }
            otherCon = (int) ((otherCon - 0.5) * (12 * otherDir));

            otherPoint.x += otherCon;

            stopUp = new Point(otherPoint.x - 4, otherPoint.y - 8);
            stopDown = new Point(otherPoint.x + 4, otherPoint.y - 8);
            stopOut = new Point(otherPoint.x, otherPoint.y - 8);
            stop = stopOut;
            step = new Point(stop.x, start.y);
        } else if (otherPoint == otherBottom) {
            // init number of connectionx
            int otherCon = 1;
            // init the direction into which to move
            int otherDir = 1;
            if (otherPoint.x > thisPoint.x)
                otherDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsOtherClass) {
                // check goto right
                if ((other.getCenter().y >= otherClass.getCenter().y)
                        && (other.getCenter().x >= otherClass.getCenter().x)
                        && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == 1))
                    otherCon++;
                // check goto left
                if ((other.getCenter().y >= otherClass.getCenter().y)
                        && (other.getCenter().x < otherClass.getCenter().x)
                        && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == -1))
                    otherCon++;
            }
            otherCon = (int) ((otherCon - 0.5) * (12 * otherDir));

            otherPoint.x += otherCon;

            stopUp = new Point(otherPoint.x - 4, otherPoint.y + 8);
            stopDown = new Point(otherPoint.x + 4, otherPoint.y + 8);
            stopOut = new Point(otherPoint.x, otherPoint.y + 8);
            stop = stopOut;
            step = new Point(stop.x, start.y);
        } else if (otherPoint == otherRight) {
            // init number of connectionx
            int otherCon = 1;
            // init the direction into which to move
            int otherDir = 1;
            if (otherPoint.y > thisPoint.y)
                otherDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsOtherClass) {
                // check goto up
                if ((other.getCenter().x >= otherClass.getCenter().x)
                        && (other.getCenter().y >= otherClass.getCenter().y)
                        && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == 1))
                    otherCon++;
                // check goto down
                if ((other.getCenter().x >= otherClass.getCenter().x)
                        && (other.getCenter().y < otherClass.getCenter().y)
                        && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == -1))
                    otherCon++;
            }
            otherCon = (int) ((otherCon - 0.5) * (12 * otherDir));

            otherPoint.y += otherCon;

            stopUp = new Point(otherPoint.x + 8, otherPoint.y - 4);
            stopDown = new Point(otherPoint.x + 8, otherPoint.y + 4);
            stopOut = new Point(otherPoint.x + 8, otherPoint.y);
            stop = stopOut;
            step = new Point(start.x, stop.y);
        } else // left
        {
            // init number of connectionx
            int otherCon = 1;
            // init the direction into which to move
            int otherDir = 1;
            if (otherPoint.y > thisPoint.y)
                otherDir = -1;
            // loop through others to determine position
            for (MyClass other : usingsOtherClass) {
                // check goto up
                if ((other.getCenter().x < otherClass.getCenter().x)
                        && (other.getCenter().y >= otherClass.getCenter().y)
                        && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == 1))
                    otherCon++;
                // check goto down
                if ((other.getCenter().x < otherClass.getCenter().x)
                        && (other.getCenter().y < otherClass.getCenter().y)
                        && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == -1))
                    otherCon++;
            }
            otherCon = (int) ((otherCon - 0.5) * (12 * otherDir));

            otherPoint.y += otherCon;

            stopUp = new Point(otherPoint.x - 8, otherPoint.y - 4);
            stopDown = new Point(otherPoint.x - 8, otherPoint.y + 4);
            stopOut = new Point(otherPoint.x + 8, otherPoint.y);
            stop = stopOut;
            step = new Point(start.x, stop.y);
        }

        //            drawLine(g,thisPoint,otherPoint);

        boolean inter = false;

        /*
                
        if(otherClass.getPosition().y+otherClass.getHeight()/2 < thisClass.getPosition().y+thisClass.getHeight()/2)
        { // top
        if(stop.y>start.y)
        {
            step = new Point(start.x,thisClass.getPosition().y);
            inter = true;
        }
        else
        {
            step = new Point(start.x,stop.y);
        }
        }
        else
        { // bottom
        if(stop.y<thisClass.getPosition().y+thisClass.getHeight() || thisClass==otherClass)
        {
            step = new Point(start.x,
                             thisClass.getPosition().y+thisClass.getHeight());
            inter = true;
        }
        else
        {
            step = new Point(start.x,stop.y);
        }
                
        }
                
                
        drawLine(g,start,step);
                
        if(inter==true)
        {
        int middle;
        if(thisClass==otherClass)
        {
            middle = otherClass.getPosition().x+otherClass.getWidth()+16;//-otherCON;
        }
        else if(otherClass.getPosition().x+otherClass.getWidth()/2 > thisClass.getPosition().x+thisClass.getWidth()/2)
        { // left
            middle = (-(thisClass.getPosition().x+thisClass.getWidth())+(otherClass.getPosition().x))/2+thisClass.getPosition().x+thisClass.getWidth();
        }
        else
        { // right
            middle = (-(otherClass.getPosition().x+otherClass.getWidth())+(thisClass.getPosition().x))/2+otherClass.getPosition().x+otherClass.getWidth();
        }
        Point next = new Point(middle,step.y);
        drawLine(g,step,next);
        step = new Point(middle,stop.y);
        drawLine(g,step,next);
        }
        */
        /*
        g.setColor(Color.red);
        drawLine(g,start,step);
        drawLine(g,step,stop);
                
        g.setColor(Color.blue);
        step = new Point(stop.x,start.y);
        drawLine(g,start,step);
        drawLine(g,step,stop);
                
        g.setColor(Color.orange);
        drawLine(g,start,
               new Point(start.x,(start.y+stop.y)/2));
        drawLine(g,new Point(start.x,(start.y+stop.y)/2),
               new Point((start.x+stop.y)/2,(start.y+stop.y)/2));
        drawLine(g,new Point((start.x+stop.y)/2,(start.y+stop.y)/2),
               new Point((start.x+stop.y)/2,stop.y));
        drawLine(g,new Point((start.x+stop.y)/2,stop.y),
               stop);
                
        g.setColor(Color.black);/**/

        drawLine(g, start, step);
        drawLine(g, step, stop);

        drawLine(g, otherPoint, stop);
        g.setStroke(oldStroke);
        drawLine(g, stopUp, otherPoint);
        drawLine(g, stopDown, otherPoint);
    }
}

From source file:net.sqs2.omr.session.logic.PageImageRenderer.java

private static void drawFormAreas(int pageIndex, float densityThreshold, FormMaster master,
        PageTaskResult pageTaskResult, Graphics2D g, MarkRecognitionConfig markRecognizationConfig,
        DeskewedImageSource pageSource, int focusedColumnIndex, Rectangle scope) {
    int formAreaIndexInPage = 0;

    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;

    for (FormArea formArea : master.getFormAreaListByPageIndex(pageIndex)) {
        FormAreaResult result = (FormAreaResult) pageTaskResult.getPageAreaResultList()
                .get(formAreaIndexInPage);
        if (formArea.isMarkArea()) {
            if (focusedColumnIndex == formArea.getQuestionIndex()) {

                Rectangle rect = formArea.getRect();

                Point2D p1 = pageSource.getPoint((int) rect.getX(), (int) rect.getY());
                Point2D p2 = pageSource.getPoint((int) (rect.getX() + rect.getWidth()),
                        (int) (rect.getY() + rect.getHeight()));

                minX = Math.min(minX, (int) p1.getX());
                minY = Math.min(minY, (int) p1.getY());
                maxX = Math.max(maxX, (int) p2.getX());
                maxY = Math.max(maxY, (int) p2.getY());

                if (result.getDensity() < densityThreshold) {
                    g.setColor(FOCUSED_MARKED_COLOR);
                } else {
                    g.setColor(FOCUSED_NO_MARKED_COLOR);
                }/* ww w . j a v  a 2s.c  o m*/

            } else {
                if (result.getDensity() < densityThreshold) {
                    g.setColor(MARKED_COLOR);
                } else {
                    g.setColor(NO_MARKED_COLOR);
                }
            }

            g.fillPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin(),
                            markRecognizationConfig.getVerticalMargin())));
            g.drawPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin() + 3,
                            markRecognizationConfig.getVerticalMargin() + 3)));

        } else {
            g.setColor(TEXTAREA_COLOR);
            g.fillPolygon(pageSource.createRectPolygon(formArea.getRect()));
        }
        formAreaIndexInPage++;
    }

    if (scope != null) {
        int borderMarginX = 20;
        int borderMarginY = 3;
        int margin = 40;

        int x = minX - borderMarginX;
        int y = minY - borderMarginY;
        int width = maxX - minX + borderMarginX * 2;
        int height = maxY - minY + borderMarginY * 2;

        scope.x = minX - margin;
        scope.y = minY - margin;
        scope.width = maxX - minX + margin * 2;
        scope.height = maxY - minY + margin * 2;

        Stroke stroke = new BasicStroke(4.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 2.0f,
                new float[] { 4.0f, 8.0f }, 0.0f);
        g.setStroke(stroke);
        g.setColor(FOCUSED_SCOPE_COLOR);
        g.drawRoundRect(x, y, width, height, 20, 20);
    }

}

From source file:net.sqs2.omr.session.logic.PageImageRenderer.java

private static DeskewedImageSource drawCorners(FormMaster master, Point2D[] corners, BufferedImage image,
        Graphics2D g) {
    DeskewedImageSource pageSource = new DeskewedImageSource(image, master.getDeskewGuideCenterPoints(),
            corners);/*from   w w  w.ja  v a 2 s. c  o  m*/
    g.setColor(CORNER_COLOR);
    g.setStroke(new BasicStroke(5));
    double size = 40;
    for (int y = 0; y < 2; y++) {
        int i = y * 2;
        g.fillPolygon(pageSource.createPolygon(new Point2D[] { corners[i],
                new Point2D.Double(corners[i].getX() - 1 * size, corners[i].getY() + 1 * size),
                new Point2D.Double(corners[i].getX() - 1 * size, corners[i].getY() - 1 * size) }));
        i++;
        g.fillPolygon(pageSource.createPolygon(new Point2D[] { corners[i],
                new Point2D.Double(corners[i].getX() + 1 * size, corners[i].getY() - 1 * size),
                new Point2D.Double(corners[i].getX() + 1 * size, corners[i].getY() + 1 * size) }));
    }
    return pageSource;
}