Example usage for java.awt Graphics2D drawPolygon

List of usage examples for java.awt Graphics2D drawPolygon

Introduction

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

Prototype

public void drawPolygon(Polygon p) 

Source Link

Document

Draws the outline of a polygon defined by the specified Polygon object.

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 w  w .  j av  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 drawRegion(Graphics2D g) {
    if (segments.size() > 0) {
        g.setColor(borderColor);/*  ww  w .jav a 2 s  .  co  m*/
        g.setStroke(new BasicStroke(0.0f));
        g.drawPolygon(this);
    }
}

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 w w. j av  a2  s  . c om
        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);
                }//from   w w  w  . j a va2s.  co  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);
    }

}