Example usage for java.awt Polygon addPoint

List of usage examples for java.awt Polygon addPoint

Introduction

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

Prototype

public void addPoint(int x, int y) 

Source Link

Document

Appends the specified coordinates to this Polygon .

Usage

From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.// w  ww  . ja  v a 2  s. c om
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    XYAreaRendererState areaState = (XYAreaRendererState) state;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    int itemCount = dataset.getItemCount(series);
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());

    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
    double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());

    double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
    Polygon hotspot = null;
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        hotspot = new Polygon();
        hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) transY1, (int) transX1);
        hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0));
        hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0));
    } else { // vertical orientation
        hotspot = new Polygon();
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero);
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0));
        hotspot.addPoint((int) transX1, (int) transY1);
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0));
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero);
    }

    if (item == 0) { // create a new area polygon for the series
        areaState.area = new Polygon();
        // the first point is (x, 0)
        double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
        if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            areaState.area.addPoint((int) transX1, (int) zero);
        } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            areaState.area.addPoint((int) zero, (int) transX1);
        }
    }

    // Add each point to Area (x, y)
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        areaState.area.addPoint((int) transX1, (int) transY1);
    } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        areaState.area.addPoint((int) transY1, (int) transX1);
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke stroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(stroke);

    Shape shape = null;
    if (getPlotShapes()) {
        shape = getItemShape(series, item);
        if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        }
        g2.draw(shape);
    }

    if (getPlotLines()) {
        if (item > 0) {
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                areaState.line.setLine(transX0, transY0, transX1, transY1);
            } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                areaState.line.setLine(transY0, transX0, transY1, transX1);
            }
            g2.draw(areaState.line);
        }
    }

    // Check if the item is the last item for the series.
    // and number of items > 0.  We can't draw an area for a single point.
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {

        if (orientation == PlotOrientation.VERTICAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transX1, (int) transZero);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transZero, (int) transX1);
        }

        Paint fillPaint = getItemFillPaint(series, item);
        if (fillPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) fillPaint;
            GradientPaintTransformer t = new StandardGradientPaintTransformer();
            fillPaint = t.transform(gp, areaState.area.getBounds());
        }
        g2.setPaint(fillPaint);
        g2.fill(areaState.area);

        // draw an outline around the Area.
        if (isOutline()) {
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.setPaint(getItemOutlinePaint(series, item));
            g2.draw(areaState.area);
        }
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null && hotspot != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private void processCategoryArea(Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataSet, LineFillItemRendererState rendererState, int row,
        int column, double currentValue, double currentItemYPoint, int totalColumns, boolean isFirstItem,
        boolean isLastItem) {
    RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
    double zeroRangePoint = calculateItemYPoint(plot, rangeAxis, dataArea, 0.0);
    double categoryStartXPoint = domainAxis.getCategoryStart(column, totalColumns, dataArea, domainAxisEdge);
    double categoryMiddleXPoint = domainAxis.getCategoryMiddle(column, totalColumns, dataArea, domainAxisEdge);
    double categoryEndXPoint = domainAxis.getCategoryEnd(column, totalColumns, dataArea, domainAxisEdge);

    if (isFirstItem) {
        categoryStartXPoint = categoryMiddleXPoint;
    } else if (isLastItem) {
        categoryEndXPoint = categoryMiddleXPoint;
    }/* w w w.  jav a  2  s .  c  o  m*/

    double previousItemYValue = 0.0;
    if (!isFirstItem) {
        Number previousItemValue = dataSet.getValue(row, column - 1);

        if (previousItemValue != null) {
            previousItemYValue = (previousItemValue.doubleValue() + currentValue) / 2.0;

            if (domainAxis instanceof CategoryAxisAdapter) {
                categoryStartXPoint -= ((CategoryAxisAdapter) domainAxis).calculateCategoryGapSize(totalColumns,
                        dataArea, domainAxisEdge) / 2.0;
            }
        } else {
            categoryStartXPoint = categoryMiddleXPoint;
        }
    }

    double nextItemYValue = 0.0;
    if (!isLastItem) {
        Number nextValue = dataSet.getValue(row, column + 1);
        if (nextValue != null) {
            nextItemYValue = (nextValue.doubleValue() + currentValue) / 2.0;

            if (domainAxis instanceof CategoryAxisAdapter) {
                categoryEndXPoint += ((CategoryAxisAdapter) domainAxis).calculateCategoryGapSize(totalColumns,
                        dataArea, domainAxisEdge) / 2.0;
            }
        } else {
            categoryEndXPoint = categoryMiddleXPoint;
        }
    }

    double previousItemYPoint = rangeAxis.valueToJava2D(previousItemYValue, dataArea, rangeAxisEdge);
    double nextItemYPoint = rangeAxis.valueToJava2D(nextItemYValue, dataArea, rangeAxisEdge);

    Polygon polygon = rendererState.getAreaPolygon();
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        polygon.addPoint((int) categoryStartXPoint, (int) zeroRangePoint);
        polygon.addPoint((int) categoryStartXPoint, (int) previousItemYPoint);
        polygon.addPoint((int) categoryMiddleXPoint, (int) currentItemYPoint);
        polygon.addPoint((int) categoryEndXPoint, (int) nextItemYPoint);
        polygon.addPoint((int) categoryEndXPoint, (int) zeroRangePoint);
    } else {
        polygon.addPoint((int) zeroRangePoint, (int) categoryStartXPoint);
        polygon.addPoint((int) previousItemYPoint, (int) categoryStartXPoint);
        polygon.addPoint((int) currentItemYPoint, (int) categoryMiddleXPoint);
        polygon.addPoint((int) nextItemYPoint, (int) categoryEndXPoint);
        polygon.addPoint((int) zeroRangePoint, (int) categoryEndXPoint);
    }
}

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2,
        double x3, double y3) {
    Line2D edge1, edge2, mainLine;
    Polygon fillArea;
    Stroke mainLineStroke, edgeLineStroke;
    Paint mainLinePaint, edgeLinePaint, fillPaint;

    double x0 = line.getX1();
    double y0 = line.getY1();
    double x1 = line.getX2();
    double y1 = line.getY2();

    mainLine = new Line2D.Double(x0, y0, x1, y1);
    edge1 = new Line2D.Double(x0, y0, x2, y2);
    edge2 = new Line2D.Double(x0, y0, x3, y3);
    fillArea = new Polygon();
    fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0));
    fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2));
    fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3));

    mainLinePaint = paint;//from   w w  w.j  a  v  a  2s . co m
    if (mainLinePaint instanceof Color) {
        Color c = (Color) mainLinePaint;
        Color dark = transp(c, calcAlpha(c));
        Color light = transp(c, 0.01);
        edgeLinePaint = fillPaint = c;
        try {
            fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light,
                    new Point2D.Double(x1, y1), dark, true);
        } catch (Exception e) {
        }
    } else {
        edgeLinePaint = fillPaint = mainLinePaint;
    }

    if (stroke instanceof BasicStroke) {
        float lineWidth = ((BasicStroke) stroke).getLineWidth();
        edgeLineStroke = new BasicStroke(lineWidth / 4);
        mainLineStroke = new BasicStroke(lineWidth * 2);
    } else {
        mainLineStroke = edgeLineStroke = stroke;
    }

    g2.setPaint(fillPaint);
    g2.fill(fillArea);
    g2.fill(fillArea);

    g2.setStroke(edgeLineStroke);
    g2.setPaint(edgeLinePaint);
    g2.draw(edge1);
    g2.draw(edge2);

    g2.setStroke(mainLineStroke);
    g2.setPaint(mainLinePaint);
    g2.draw(mainLine);
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private void addPointToAreaPolygon(Polygon polygon, XYPlot plot, double currentItemX, double currentItemY) {
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        polygon.addPoint((int) currentItemX, (int) currentItemY);
    } else {/*from   w  ww.j av  a  2s  . c  o m*/
        polygon.addPoint((int) currentItemY, (int) currentItemX);
    }
}

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 w ww  .j  a va2 s  .  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:rod_design_compute.ShowPanel.java

private void drawBlock(Rod rod, Point point, Graphics g) {
    int[] x = new int[4];
    int[] y = new int[4];
    int l = lengthBlock;
    double theta = rod.getAngle();

    x[0] = (int) ((2 * Math.cos(theta) + Math.sin(theta)) * l / 4);
    y[0] = (int) ((2 * Math.sin(theta) - Math.cos(theta)) * l / 4);
    x[1] = (int) ((2 * Math.cos(theta) - Math.sin(theta)) * l / 4);
    y[1] = (int) ((2 * Math.sin(theta) + Math.cos(theta)) * l / 4);
    x[2] = -x[0];//from  ww w  .j  a  v a2 s.  com
    y[2] = -y[0];
    x[3] = -x[1];
    y[3] = -y[1];

    Polygon block = new Polygon();
    for (int i = 0; i < 4; i++) {
        x[i] = toScreenX(point.X) + x[i];
        y[i] = toScreenY(point.Y) - y[i];
        block.addPoint(x[i], y[i]);
    }

    g.setColor(Color.white);
    g.fillPolygon(block);
    g.setColor(Color.black);
    g.drawPolygon(block);
}

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 .  j a  v  a2s . 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:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private Polygon createEntityArea(XYPlot plot, double previousItemX, double previousItemY, double currentItemX,
        double currentItemY, double nextItemX, double nextItemY, double zeroPoint) {
    Polygon entityAreaPolygon = new Polygon();
    final int halfwayPrevX = (int) ((previousItemX + currentItemX) / 2.0);
    final int halfwayPrevY = (int) ((previousItemY + currentItemY) / 2.0);
    final int halfwayNextY = (int) ((currentItemY + nextItemY) / 2.0);
    final int halfwayNextX = (int) ((currentItemX + nextItemX) / 2.0);
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        entityAreaPolygon.addPoint((int) zeroPoint, halfwayPrevX);
        entityAreaPolygon.addPoint(halfwayPrevY, halfwayPrevX);
        entityAreaPolygon.addPoint((int) currentItemY, (int) currentItemX);
        entityAreaPolygon.addPoint(halfwayNextY, halfwayNextX);
        entityAreaPolygon.addPoint((int) zeroPoint, halfwayNextX);
    } else {/* ww  w  . j a  v  a  2  s  . co m*/
        entityAreaPolygon.addPoint(halfwayPrevX, (int) zeroPoint);
        entityAreaPolygon.addPoint(halfwayPrevX, halfwayPrevY);
        entityAreaPolygon.addPoint((int) currentItemX, (int) currentItemY);
        entityAreaPolygon.addPoint(halfwayNextX, halfwayNextY);
        entityAreaPolygon.addPoint(halfwayNextX, (int) zeroPoint);
    }

    return entityAreaPolygon;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void computeConnections() {

    connections = new HashMap<AnnotationObject, Polygon>();
    connections_cp = new HashMap<AnnotationObject, Point2D>();

    for (AnnotationObject a : theDocument.getAnnotations()) {
        Rectangle rect = rectangles_complete.get(a);
        Point2D cp = dataToScreenCoords(theDocument.getControlPoint(a));
        Point2D peak = dataToScreenCoords(a.getPeakPoint());

        // select anchor
        Point2D anchor = computeAnchor(rect, cp, peak);
        boolean add_cp = (peak.getY() > bottom(rect));

        if (anchor.distance(peak) > 10) {
            // create shape
            Polygon connection = new Polygon();
            connection.addPoint((int) anchor.getX(), (int) anchor.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());
            connection.addPoint((int) peak.getX(), (int) peak.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());

            // save
            connections.put(a, connection);
            if (add_cp)
                connections_cp.put(a, cp);
        }//from  w ww .j  ava2 s .c om
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void paintAnnotations(Graphics2D g2d) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    // set font// w  w w  . java2 s  . com
    Font old_font = g2d.getFont();
    Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE);

    // compute bboxes
    PositionManager pman = new PositionManager();
    BBoxManager bbman = new BBoxManager();
    computeRectangles(pman, bbman);

    // compute connections
    computeConnections();

    // paint connections
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean selected = !is_printing && selections.contains(a);

        // paint arrow        
        Polygon connection = connections.get(a);
        if (connection != null) {
            g2d.setColor(theOptions.CONNECTION_LINES_COLOR);
            g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH))
                    : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH));
            g2d.draw(connection);
            g2d.setStroke(new BasicStroke(1));
        }

        // paint control point       
        if (selected) {
            g2d.setColor(Color.black);
            Point2D cp = connections_cp.get(a);
            if (cp != null) {
                int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH);
                g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s));
            }
        }
    }

    // paint glycans
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean highlighted = a.isHighlighted();
        boolean selected = !is_printing && selections.contains(a);

        // set scale
        theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));

        // paint highlighted region
        if (highlighted) {
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setColor(theOptions.HIGHLIGHTED_COLOR);
            g2d.setXORMode(Color.white);
            g2d.fill(c_bbox);
            g2d.setPaintMode();

            g2d.setColor(Color.black);
            g2d.draw(c_bbox);
        }

        // paint glycan
        for (Glycan s : a.getStructures())
            theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman);

        // paint MZ text
        g2d.setFont(new_font);
        g2d.setColor(theOptions.MASS_TEXT_COLOR);
        String mz_text = mz_df.format(a.getPeakPoint().getX());
        Rectangle mz_bbox = rectangles_text.get(a);
        g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height);

        // paint selection        
        if (selected) {
            // paint rectangle
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setStroke(new BasicStroke(highlighted ? 2 : 1));
            g2d.setColor(Color.black);

            g2d.draw(c_bbox);

            g2d.setStroke(new BasicStroke(1));

            // paint resize points        
            Polygon p1 = new Polygon();
            int cx1 = right(c_bbox);
            int cy1 = top(c_bbox);
            p1.addPoint(cx1, cy1);
            p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1);
            p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p1);

            Polygon p2 = new Polygon();
            int cx2 = left(c_bbox);
            int cy2 = top(c_bbox);
            p2.addPoint(cx2, cy2);
            p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2);
            p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p2);
        }
    }

    g2d.setFont(old_font);
}