Example usage for java.awt Graphics2D fill

List of usage examples for java.awt Graphics2D fill

Introduction

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

Prototype

public abstract void fill(Shape s);

Source Link

Document

Fills the interior of a Shape using the settings of the Graphics2D context.

Usage

From source file:Chart.java

 public void paintComponent(Graphics g)
{
   Graphics2D g2 = (Graphics2D) g;

   // compute the minimum and maximum values
   if (values == null) return;
   double minValue = 0;
   double maxValue = 0;
   for (double v : values)
   {/*w  w w  . j av  a2s  .c om*/
      if (minValue > v) minValue = v;
      if (maxValue < v) maxValue = v;
   }
   if (maxValue == minValue) return;

   int panelWidth = getWidth();
   int panelHeight = getHeight();

   Font titleFont = new Font("SansSerif", Font.BOLD, 20);
   Font labelFont = new Font("SansSerif", Font.PLAIN, 10);

   // compute the extent of the title
   FontRenderContext context = g2.getFontRenderContext();
   Rectangle2D titleBounds = titleFont.getStringBounds(title, context);
   double titleWidth = titleBounds.getWidth();
   double top = titleBounds.getHeight();

   // draw the title
   double y = -titleBounds.getY(); // ascent
   double x = (panelWidth - titleWidth) / 2;
   g2.setFont(titleFont);
   g2.drawString(title, (float) x, (float) y);

   // compute the extent of the bar labels
   LineMetrics labelMetrics = labelFont.getLineMetrics("", context);
   double bottom = labelMetrics.getHeight();

   y = panelHeight - labelMetrics.getDescent();
   g2.setFont(labelFont);

   // get the scale factor and width for the bars
   double scale = (panelHeight - top - bottom) / (maxValue - minValue);
   int barWidth = panelWidth / values.length;

   // draw the bars
   for (int i = 0; i < values.length; i++)
   {
      // get the coordinates of the bar rectangle
      double x1 = i * barWidth + 1;
      double y1 = top;
      double height = values[i] * scale;
      if (values[i] >= 0) y1 += (maxValue - values[i]) * scale;
      else
      {
         y1 += maxValue * scale;
         height = -height;
      }

      // fill the bar and draw the bar outline
      Rectangle2D rect = new Rectangle2D.Double(x1, y1, barWidth - 2, height);
      g2.setPaint(Color.RED);
      g2.fill(rect);
      g2.setPaint(Color.BLACK);
      g2.draw(rect);

      // draw the centered label below the bar
      Rectangle2D labelBounds = labelFont.getStringBounds(names[i], context);

      double labelWidth = labelBounds.getWidth();
      x = x1 + (barWidth - labelWidth) / 2;
      g2.drawString(names[i], (float) x, (float) y);
   }
}

From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java

/**
 *
 * @param g2/*from   w  ww . j  a  v a 2  s  .com*/
 * @param chartPanel
 */
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (isVisible()) {
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        g2.clip(dataArea);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
        ValueAxis yAxis = plot.getRangeAxis();
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
        Color c = g2.getColor();
        Color fillColor = peakAnnotations.getColor();
        if (fillColor == null || fillColor.equals(Color.WHITE)
                || fillColor.equals(new Color(255, 255, 255, 0))) {
            Logger.getLogger(getClass().getName())
                    .info("Peak annotation color was null or white, using color from treatment group!");
            fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor();
        }
        g2.setColor(ChartCustomizer.withAlpha(fillColor, 0.5f));
        for (IPeakAnnotationDescriptor descr : peakAnnotations.getMembers()) {
            double x = descr.getApexTime();
            double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
            double width = xAxis.valueToJava2D(1, dataArea, xAxisEdge);
            double mzRange = (descr.getMassValues()[descr.getMassValues().length - 1]
                    - descr.getMassValues()[0]);
            double y = mzRange / 2.0d;
            double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
            double height = yAxis.valueToJava2D(mzRange, dataArea, yAxisEdge);
            AffineTransform at = AffineTransform.getTranslateInstance(xx, yy);
            at.concatenate(AffineTransform.getTranslateInstance(-x, -y));
            Rectangle2D.Double r = new Rectangle2D.Double(xx - (width / 2.0d), yy, width, height);
            g2.fill(at.createTransformedShape(r));
        }
        g2.setColor(c);
        g2.setClip(savedClip);
    }
}

From source file:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2             the graphics device.
 * @param state          the state.//from  w w w .  j  a v  a 2 s  .co  m
 * @param dataArea       the data area.
 * @param info           the plot rendering info.
 * @param plot           the plot.
 * @param domainAxis     the x-axis.
 * @param rangeAxis      the y-axis.
 * @param dataset        the dataset.
 * @param series         the series index.
 * @param item           the item index.
 * @param crosshairState the crosshair state.
 * @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) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    double max = paintScale.getUpperBound();
    double min = paintScale.getLowerBound();

    if (dataset instanceof XYZDataset)
        z = ((XYZDataset) dataset).getZValue(series, item);

    //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009)
    if (z > max)
        z = max;

    if (z < min)
        z = min;

    Color p = (Color) this.paintScale.getPaint(z);

    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    } else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setColor(p);
    g2.fill(block);

    if (gridLinesEnabled) {
        boolean aaOn = false;
        if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            aaOn = true;
        }
        g2.setPaint(gridLineColor);
        g2.setStroke(gridLineStroke);
        g2.draw(block);
        if (aaOn)
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        g2.setStroke(basicStroke);
        g2.draw(block);
    }
}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Paint the given tree layout//w w w . j a  va2s  .c  o  m
 * @param graphics
 *          the graphics to paint with
 * @param treeLayout
 *          the layout to paint
 */
private void paintPhylogenyTree(Graphics2D graphics, VisualTreeNode treeLayout) {
    int childNodeCount = treeLayout.getChildNodes().size();
    for (int i = 0; i < childNodeCount; i++) {
        VisualTreeNode visualChild = treeLayout.getChildNodes().get(i);

        Shape branchShape = new Line2D.Double(treeLayout.getPosition(), visualChild.getPosition());
        Shape branchShadowShape = SHADOW_TRANSFORM.createTransformedShape(branchShape);

        graphics.setColor(SHADOW_COLOR);
        graphics.draw(branchShadowShape);

        if (this.paintScale != null) {
            PhylogenyTreeEdge phylogenyEdge = treeLayout.getPhylogenyTreeNode().getChildEdges().get(i);
            if (phylogenyEdge instanceof PhylogenyTreeEdgeWithRealValue) {
                PhylogenyTreeEdgeWithRealValue phylogenyEdgeWithValue = (PhylogenyTreeEdgeWithRealValue) phylogenyEdge;
                Paint paint = this.paintScale.getPaint(phylogenyEdgeWithValue.getRealValue());
                graphics.setPaint(paint);
            } else {
                graphics.setColor(FOREGROUND_COLOR);
            }
        } else {
            graphics.setColor(FOREGROUND_COLOR);
        }
        graphics.draw(branchShape);

        // recurse
        this.paintPhylogenyTree(graphics, visualChild);
    }

    if (!treeLayout.getPhylogenyTreeNode().getStrains().isEmpty()) {
        Shape textShape = this.getLabelShape(treeLayout, graphics.getFontRenderContext());
        Shape borderShape = this.getLabelBorder(textShape);

        graphics.setColor(BACKGROUND_COLOR);
        graphics.fill(borderShape);

        graphics.setColor(SHADOW_COLOR);
        Area borderShadowShape = new Area(SHADOW_TRANSFORM.createTransformedShape(borderShape));
        borderShadowShape.subtract(new Area(borderShape));
        graphics.draw(borderShadowShape);

        graphics.setColor(FOREGROUND_COLOR);
        graphics.draw(borderShape);

        graphics.fill(textShape);
    }
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {

    if (newBufferedImage) {
        x = Math.random() * w;//www. java  2s .  c o m
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {
    if (newBufferedImage) {
        x = Math.random() * w;/*from w  w w . j a va  2  s . com*/
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java

/**
 * This function is taken directly from JFreeChart with adjustments to draw differently colored
 * items.//from  w  ww  .  j a  v  a2  s .c  om
 * 
 * When updating JFreeChart this function must probably be adapted.
 * 
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset;
    List values = dataSet.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (getUseSeriesOffset()) {
            x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow,
                    visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
        } else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        int idx = dataSet.getValueIndex(row, column, i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, idx);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }
}

From source file:lcmc.common.ui.ResourceGraph.java

protected final void drawInsideVertex(final Graphics2D g2d, final Vertex v, final Color[] colors,
        final double x, final double y, final float height, final float width) {
    final int number = colors.length;
    if (number > 1) {
        for (int i = 1; i < number; i++) {
            final Paint p = new GradientPaint((float) x + width / number, (float) y,
                    getVertexFillSecondaryColor(v), (float) x + width / number, (float) y + height, colors[i],
                    false);//from  w  w  w .j  av  a  2s .c om
            g2d.setPaint(p);
            final Shape s = new Rectangle2D.Double(x + width / 2 + (width / number / 2) * i, y,
                    width / number / 2, height - 2);
            g2d.fill(s);
        }
    }
}

From source file:Paints.java

/** Draw the example */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Paint the entire background using a GradientPaint.
    // The background color varies diagonally from deep red to pale blue
    g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255)));
    g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background

    // Use a different GradientPaint to draw a box.
    // This one alternates between deep opaque green and transparent green.
    // Note: the 4th arg to Color() constructor specifies color opacity
    g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true));
    g.setStroke(new BasicStroke(15)); // use wide lines
    g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box

    // The glyphs of fonts can be used as Shape objects, which enables
    // us to use Java2D techniques with letters Just as we would with
    // any other shape. Here we get some letter shapes to draw.
    Font font = new Font("Serif", Font.BOLD, 10); // a basic font
    Font bigfont = // a scaled up version
            font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0));
    GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV");
    Shape jshape = gv.getGlyphOutline(0); // Shape of letter J
    Shape ashape = gv.getGlyphOutline(1); // Shape of letter A
    Shape vshape = gv.getGlyphOutline(2); // Shape of letter V

    // We're going to outline the letters with a 5-pixel wide line
    g.setStroke(new BasicStroke(5.0f));

    // We're going to fake shadows for the letters using the
    // following Paint and AffineTransform objects
    Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black
    AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right
    shadowTransform.scale(1.0, 0.5); // Scale height by 1/2

    // Move to the baseline of our first letter
    g.translate(65, 270);/*from w  w  w.  ja  v  a 2  s .c o m*/

    // Draw the shadow of the J shape
    g.setPaint(shadowPaint);
    g.translate(15, 20); // Compensate for the descender of the J
    // transform the J into the shape of its shadow, and fill it
    g.fill(shadowTransform.createTransformedShape(jshape));
    g.translate(-15, -20); // Undo the translation above

    // Now fill the J shape with a solid (and opaque) color
    g.setPaint(Color.blue); // Fill with solid, opaque blue
    g.fill(jshape); // Fill the shape
    g.setPaint(Color.black); // Switch to solid black
    g.draw(jshape); // And draw the outline of the J

    // Now draw the A shadow
    g.translate(75, 0); // Move to the right
    g.setPaint(shadowPaint); // Set shadow color
    g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow

    // Draw the A shape using a solid transparent color
    g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint
    g.fill(ashape); // Fill the shape
    g.setPaint(Color.black); // Switch to solid back
    g.draw(ashape); // Draw the outline

    // Move to the right and draw the shadow of the letter V
    g.translate(175, 0);
    g.setPaint(shadowPaint);
    g.fill(shadowTransform.createTransformedShape(vshape));

    // We're going to fill the next letter using a TexturePaint, which
    // repeatedly tiles an image. The first step is to obtain the image.
    // We could load it from an image file, but here we create it
    // ourselves by drawing a into an off-screen image. Note that we use
    // a GradientPaint to fill the off-screen image, so the fill pattern
    // combines features of both Paint classes.
    BufferedImage tile = // Create an image
            new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing
    tg.setColor(Color.pink);
    tg.fillRect(0, 0, 50, 50); // Fill tile background with pink
    tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient
            0, 40, Color.gray)); // green to gray
    tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient

    // Use this new tile to create a TexturePaint and fill the letter V
    g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50)));
    g.fill(vshape); // Fill letter shape
    g.setPaint(Color.black); // Switch to solid black
    g.draw(vshape); // Draw outline of letter

    // Move to the right and draw the shadow of the final A
    g.translate(160, 0);
    g.setPaint(shadowPaint);
    g.fill(shadowTransform.createTransformedShape(ashape));

    g.fill(ashape); // Fill letter A
    g.setPaint(Color.black); // Revert to solid black
    g.draw(ashape); // Draw the outline of the A
}

From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

@Override
@SuppressWarnings("unchecked")
public void paintComponent(final Graphics g) {
    final Graphics2D gfx = (Graphics2D) g.create();
    try {//www.  ja v a2  s .c om
        final String error = this.errorText;

        Utils.prepareGraphicsForQuality(gfx);
        if (error != null) {
            drawErrorText(gfx, this.getSize(), error);
        } else {
            revalidate();
            drawOnGraphicsForConfiguration(gfx, this.config, this.model, true, this.selectedTopics);
            drawDestinationElement(gfx, this.config);
        }

        paintChildren(g);

        if (this.draggedElement != null) {
            this.draggedElement.draw(gfx);
        } else if (this.mouseDragSelection != null) {
            gfx.setColor(COLOR_MOUSE_DRAG_SELECTION);
            gfx.fill(this.mouseDragSelection.asRectangle());
        }
    } finally {
        gfx.dispose();
    }
}