Java Code Examples for java.awt.Graphics2D#fill()

The following examples show how to use java.awt.Graphics2D#fill() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: astor   File: PaintSample.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fills the component with the current Paint.
 *
 * @param g  the graphics device.
 */
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();
    Insets insets = getInsets();
    double xx = insets.left;
    double yy = insets.top;
    double ww = size.getWidth() - insets.left - insets.right - 1;
    double hh = size.getHeight() - insets.top - insets.bottom - 1;
    Rectangle2D area = new Rectangle2D.Double(xx, yy, ww, hh);
    g2.setPaint(this.paint);
    g2.fill(area);
    g2.setPaint(Color.black);
    g2.draw(area);

}
 
Example 2
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example 3
@Override
protected void paintIcon( Component c, Graphics2D g ) {
	/*
		<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
		  <g fill="none" fill-rule="evenodd">
		    <polygon fill="#6E6E6E" points="2 3 5.5 3 7 5 9 5 9 9 13 9 13 5 14 5 14 13 2 13"/>
		    <path fill="#389FD6" d="M12,4 L12,8 L10,8 L10,4 L8,4 L11,1 L14,4 L12,4 Z"/>
		  </g>
		</svg>
	*/

	g.fill( FlatUIUtils.createPath( 2,3, 5.5,3, 7,5, 9,5, 9,9, 13,9, 13,5, 14,5, 14,13, 2,13 ) );

	g.setColor( blueColor );
	g.fill( FlatUIUtils.createPath( 12,4, 12,8, 10,8, 10,4, 8,4, 11,1, 14,4, 12,4 ) );
}
 
Example 4
public void doPaint(Graphics2D g2d) {

        g2d.translate(DIM*0.2, DIM*0.2);
        Shape s = new Rectangle2D.Float(0, 0, DIM*2, DIM*2);
        Point2D.Double p1 = new Point2D.Double(0.0, 0.0);
        Point2D.Double p2 = new Point2D.Double(DIM/2.0, DIM/2.0);

        // LinearGradientPaint
        //g2d.translate(DIM*2.2, 0);
        Color colors[] =  { Color.red, Color.blue} ;
        float fractions[]  = { 0.0f, 1.0f };

        LinearGradientPaint lgp =
           new LinearGradientPaint(p1, p2, fractions, colors,
              LinearGradientPaint.CycleMethod.NO_CYCLE);
        g2d.setPaint(lgp);
        g2d.fill(s);

        g2d.translate(DIM*2.2, 0);
        Color colors1[] =  { Color.red, Color.blue, Color.green, Color.white} ;
        float fractions1[]  = { 0.0f, 0.3f, 0.6f, 1.0f };

        LinearGradientPaint lgp1 =
           new LinearGradientPaint(p1, p2, fractions1, colors1,
              LinearGradientPaint.CycleMethod.REFLECT);
        g2d.setPaint(lgp1);
        g2d.fill(s);

        g2d.translate(-DIM*2.2, DIM*2.2);
        Color colors2[] =  { Color.red, Color.blue, Color.green, Color.white} ;
        float fractions2[]  = { 0.0f, 0.3f, 0.6f, 1.0f };

        LinearGradientPaint lgp2 =
           new LinearGradientPaint(p1, p2, fractions2, colors2,
              LinearGradientPaint.CycleMethod.REPEAT);
        g2d.setPaint(lgp2);
        g2d.fill(s);
    }
 
Example 5
public static void main(String a[]) {
    /* prepare blank image */
    BufferedImage bi = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) bi.getGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, 50, 50);

    /* draw outline somethere in the middle of the image */
    FontRenderContext frc = new FontRenderContext(null, false, false);
    g2.setColor(Color.RED);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    GlyphVector gv = g2.getFont().createGlyphVector(frc, "test");
    g2.fill(gv.getOutline(20, 20));

    /* Check if anything was drawn.
     * If y direction is not correct then image is still blank and
     * test will fail.
     */
    int bgcolor = Color.WHITE.getRGB();
    for (int i=0; i<bi.getWidth(); i++) {
        for(int j=0; j<bi.getHeight(); j++) {
           if (bi.getRGB(i, j) != bgcolor) {
               System.out.println("Test passed.");
               return;
           }
        }
    }
    throw new RuntimeException("Outline was not detected");
}
 
Example 6
/**
 * Draws the band.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param dataArea  the data area.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
                 double x, double y) {

    double h = getHeight(g2);
    Iterator iterator = this.markers.iterator();
    while (iterator.hasNext()) {
        IntervalMarker marker = (IntervalMarker) iterator.next();
        double start =  Math.max(
            marker.getStartValue(), this.axis.getRange().getLowerBound()
        );
        double end = Math.min(
            marker.getEndValue(), this.axis.getRange().getUpperBound()
        );
        double s = this.axis.valueToJava2D(
            start, dataArea, RectangleEdge.BOTTOM
        );
        double e = this.axis.valueToJava2D(
            end, dataArea, RectangleEdge.BOTTOM
        );
        Rectangle2D r = new Rectangle2D.Double(
            s, y + this.topOuterGap, e - s, 
            h - this.topOuterGap - this.bottomOuterGap
        );

        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha())
        );
        g2.setPaint(marker.getPaint());
        g2.fill(r);
        g2.setPaint(marker.getOutlinePaint());
        g2.draw(r);
        g2.setComposite(originalComposite);

        g2.setPaint(Color.black);
        drawStringInRect(g2, r, this.font, marker.getLabel());
    }

}
 
Example 7
public void draw (Graphics2D g,
                  Point2D topCenter,
                  Point2D botCenter,
                  SystemPart part,
                  double offset)
{
    int il = part.getScale()
            .getInterline();

    // Use a line stroke (=> problem with clipping)
    //            g.setStroke(new BasicStroke((float) (il * width)));
    //            Line2D line = new Line2D.Double(
    //                    new Point2D.Double(
    //                    topCenter.getX() + il * (offset + width / 2),
    //                    topCenter.getY()),
    //                    new Point2D.Double(
    //                    botCenter.getX() + il * (offset + width / 2),
    //                    botCenter.getY()));
    //            g.draw(line);

    // Use a polygon (no need to play with clipping)
    Polygon poly = new Polygon();
    poly.addPoint(
            (int) Math.rint(topCenter.getX() + (il * offset)),
            (int) Math.rint(topCenter.getY()));
    poly.addPoint(
            (int) Math.rint(topCenter.getX() + (il * (offset + width))),
            (int) Math.rint(topCenter.getY()));
    poly.addPoint(
            (int) Math.rint(botCenter.getX() + (il * (offset + width))),
            (int) Math.rint(botCenter.getY()));
    poly.addPoint(
            (int) Math.rint(botCenter.getX() + (il * offset)),
            (int) Math.rint(botCenter.getY()));
    g.fill(poly);
}
 
Example 8
void render(Thermostat t, View2D v, Graphics2D g) {

		if (!v.isVisible())
			return;

		if (t.getThermometer() != null) {

			Stroke oldStroke = g.getStroke();
			Color oldColor = g.getColor();
			g.setStroke(stroke1);
			g.setColor(Color.black);

			float x1 = v.convertPointToPixelXf(t.getThermometer().getX());
			float y1 = v.convertPointToPixelYf(t.getThermometer().getY());
			float x2 = v.convertPointToPixelXf(t.getPowerSource().getCenter().x);
			float y2 = v.convertPointToPixelYf(t.getPowerSource().getCenter().y);
			g.draw(new Line2D.Float(x1, y1, x1, y2));
			g.draw(new Line2D.Float(x1, y2, x2, y2));

			g.setStroke(stroke2);
			g.draw(new Ellipse2D.Float(x1 - 3, y1 - 3, 6, 6));
			g.draw(new Ellipse2D.Float(x2 - 3, y2 - 3, 6, 6));

			g.setColor(Color.white);
			g.draw(new Line2D.Float(x1, y1, x1, y2));
			g.draw(new Line2D.Float(x1, y2, x2, y2));
			g.fill(new Ellipse2D.Float(x1 - 2, y1 - 2, 4, 4));
			g.fill(new Ellipse2D.Float(x2 - 2, y2 - 2, 4, 4));

			g.setStroke(oldStroke);
			g.setColor(oldColor);

		} else {

		}

	}
 
Example 9
/**
 * Plots the data for a given series.
 * 
 * @param g2  the drawing surface.
 * @param dataArea  the data area.
 * @param info  collects plot rendering info.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param seriesIndex  the series index.
 */
public void drawSeries(Graphics2D g2, 
                       Rectangle2D dataArea, 
                       PlotRenderingInfo info,
                       PolarPlot plot,
                       XYDataset dataset,
                       int seriesIndex) {
    
    Polygon poly = new Polygon();
    int numPoints = dataset.getItemCount(seriesIndex);
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i);
        double radius = dataset.getYValue(seriesIndex, i);
        Point p = plot.translateValueThetaRadiusToJava2D(theta, radius, 
                dataArea);
        poly.addPoint(p.x, p.y);
    }
    g2.setPaint(lookupSeriesPaint(seriesIndex));
    g2.setStroke(lookupSeriesStroke(seriesIndex));
    if (isSeriesFilled(seriesIndex)) {
        Composite savedComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.5f));
        g2.fill(poly);
        g2.setComposite(savedComposite);
    }
    else {
        g2.draw(poly);
    }
}
 
Example 10
Source Project: seaglass   File: MenuItemPainter.java    License: Apache License 2.0 5 votes vote down vote up
protected void paintBackgroundMouseOver(Graphics2D g, JComponent c, int width, int height) {
    Shape s = shapeGenerator.createRectangle(0, 0, width, height);
    g.setPaint(getMenuItemBackgroundPaint(s));

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.fill(s);
    Rectangle b = s.getBounds();
    int width1 = b.width;
    int height1 = b.height;
    g.setColor(getMenuItemBottomLinePaint(c));
    g.drawLine(0, height1 - 1, width1 - 1, height1 - 1);
}
 
Example 11
private void draw(GMLShape shape, Graphics2D g, ScreenTransform transform) {
    List<GMLCoordinates> coords = shape.getUnderlyingCoordinates();
    int n = coords.size();
    int[] xs = new int[n];
    int[] ys = new int[n];
    int i = 0;
    for (GMLCoordinates next : coords) {
        xs[i] = transform.xToScreen(next.getX());
        ys[i] = transform.yToScreen(next.getY());
        ++i;
    }
    g.fill(new Polygon(xs, ys, n));
}
 
Example 12
/**
 * Draw plot
 *
 * @param g Graphics2D
 * @param area Drawing area
 */
@Override
public void draw(Graphics2D g, Rectangle2D area) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    Rectangle2D graphArea;
    graphArea = this.getPositionArea();
    this.setGraphArea(graphArea);

    //Draw title
    this.drawTitle(g, graphArea);

    if (graphArea.getWidth() < 10 || graphArea.getHeight() < 10) {
        return;
    }

    //Draw background
    if (this.background != null) {
        g.setColor(this.getBackground());
        //g.fill(graphArea);
        Ellipse2D ellipse=new Ellipse2D.Double();
        ellipse.setFrame(graphArea);
        g.fill(ellipse);
    }
    
    if (this.getGridLine().isTop()){
        //Draw graph        
        this.drawGraph(g, graphArea);
        //Draw grid line
        this.drawGridLine(g, graphArea);
    } else {
        //Draw grid line
        this.drawGridLine(g, graphArea);
        //Draw graph        
        this.drawGraph(g, graphArea);
    }  
    this.drawGridLabel(g, graphArea);

    //Draw border circle
    this.drawBorder(g, graphArea);

    //Draw neat line
    if (this.isDrawNeatLine()) {
        g.setStroke(new BasicStroke(1.0f));
        g.setColor(Color.black);
        g.draw(graphArea);
    }

    //Draw text
    this.drawText(g, graphArea);

    //Draw legend
    this.drawLegend(g, area, graphArea);

}
 
Example 13
public void render() {
    SerializableImage img = getImg();
    Rectangle rect = getRect();
    if (img == null) {
        return;
    }

    Graphics2D g2 = null;
    VolatileImage ri;
    do {
        ri = this.renderImage;
        if (ri == null) {
            return;
        }

        int valid = ri.validate(View.getDefaultConfiguration());

        if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
            ri = View.createRenderImage(getWidth(), getHeight(), Transparency.TRANSLUCENT);
        }

        try {
            g2 = ri.createGraphics();
            g2.setPaint(View.transparentPaint);
            g2.fill(new Rectangle(0, 0, getWidth(), getHeight()));
            g2.setComposite(AlphaComposite.SrcOver);
            g2.setPaint(View.getSwfBackgroundColor());
            g2.fill(new Rectangle(0, 0, getWidth(), getHeight()));

            g2.setComposite(AlphaComposite.SrcOver);
            if (rect != null) {
                g2.drawImage(img.getBufferedImage(), rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, 0, 0, img.getWidth(), img.getHeight(), null);
            }
        } finally {
            if (g2 != null) {
                g2.dispose();
            }
        }

    } while (ri.contentsLost());
}
 
Example 14
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  an optional info object that will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    float anchorX = (float) domainAxis.valueToJava2D(
            this.x, dataArea, domainEdge);
    float anchorY = (float) rangeAxis.valueToJava2D(
            this.y, dataArea, rangeEdge);

    if (orientation == PlotOrientation.HORIZONTAL) {
        float tempAnchor = anchorX;
        anchorX = anchorY;
        anchorY = tempAnchor;
    }

    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, anchorX, anchorY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());
    if (this.outlineVisible) {
        g2.setStroke(this.outlineStroke);
        g2.setPaint(this.outlinePaint);
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 15
@Override
public Dimension render(Graphics2D graphics)
{
	Color outsideStrokeColor = new Color(
		(int) (backgroundColor.getRed() * OUTER_COLOR_OFFSET),
		(int) (backgroundColor.getGreen() * OUTER_COLOR_OFFSET),
		(int) (backgroundColor.getBlue() * OUTER_COLOR_OFFSET),
		Math.min(255, (int) (backgroundColor.getAlpha() * ALPHA_COLOR_OFFSET))
	);

	Color insideStrokeColor = new Color(
		Math.min(255, (int) (backgroundColor.getRed() * INNER_COLOR_OFFSET)),
		Math.min(255, (int) (backgroundColor.getGreen() * INNER_COLOR_OFFSET)),
		Math.min(255, (int) (backgroundColor.getBlue() * INNER_COLOR_OFFSET)),
		Math.min(255, (int) (backgroundColor.getAlpha() * ALPHA_COLOR_OFFSET))
	);

	// Render background
	if (fill)
	{
		graphics.setColor(backgroundColor);
		graphics.fill(rectangle);
	}

	// Render outside stroke
	final Rectangle outsideStroke = new Rectangle();
	outsideStroke.setLocation(rectangle.x, rectangle.y);
	outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET / 2);
	graphics.setColor(outsideStrokeColor);
	graphics.draw(outsideStroke);

	// Render inside stroke
	final Rectangle insideStroke = new Rectangle();
	insideStroke.setLocation(rectangle.x + BORDER_OFFSET / 2, rectangle.y + BORDER_OFFSET / 2);
	insideStroke.setSize(rectangle.width - BORDER_OFFSET - BORDER_OFFSET / 2,
			rectangle.height - BORDER_OFFSET - BORDER_OFFSET / 2);
	graphics.setColor(insideStrokeColor);
	graphics.draw(insideStroke);

	return new Dimension(rectangle.getSize());
}
 
Example 16
Source Project: mars-sim   File: Compass.java    License: GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_BIG_ROSE_POINTER_Image(final int WIDTH) {
    final BufferedImage IMAGE = UTIL.createImage((int) (WIDTH * 0.0546875f), (int) (WIDTH * 0.2f), java.awt.Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();

    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    G2.setStroke(new BasicStroke(0.75f));

    // Define arrow shape of pointer
    final GeneralPath POINTER_WHITE_LEFT = new GeneralPath();
    final GeneralPath POINTER_WHITE_RIGHT = new GeneralPath();

    POINTER_WHITE_LEFT.moveTo(IMAGE_WIDTH - IMAGE_WIDTH * 0.95f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, 0);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.closePath();

    POINTER_WHITE_RIGHT.moveTo(IMAGE_WIDTH * 0.95f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, 0);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.closePath();

    final Area POINTER_FRAME_WHITE = new Area(POINTER_WHITE_LEFT);
    POINTER_FRAME_WHITE.add(new Area(POINTER_WHITE_RIGHT));

    final Color STROKE_COLOR = getBackgroundColor().SYMBOL_COLOR.darker();
    final Color FILL_COLOR = getBackgroundColor().SYMBOL_COLOR;

    G2.setColor(STROKE_COLOR);
    G2.fill(POINTER_WHITE_RIGHT);
    G2.setColor(FILL_COLOR);
    G2.fill(POINTER_WHITE_LEFT);
    G2.setColor(STROKE_COLOR);
    G2.draw(POINTER_FRAME_WHITE);

    G2.dispose();

    return IMAGE;
}
 
Example 17
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  an optional info object that will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    float anchorX = (float) domainAxis.valueToJava2D(
            this.x, dataArea, domainEdge);
    float anchorY = (float) rangeAxis.valueToJava2D(
            this.y, dataArea, rangeEdge);

    if (orientation == PlotOrientation.HORIZONTAL) {
        float tempAnchor = anchorX;
        anchorX = anchorY;
        anchorY = tempAnchor;
    }

    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, anchorX, anchorY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());
    if (this.outlineVisible) {
        g2.setStroke(this.outlineStroke);
        g2.setPaint(this.outlinePaint);
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 18
Source Project: seaglass   File: TreePainter.java    License: Apache License 2.0 4 votes vote down vote up
private void paintExpandedIconEnabledAndSelected(Graphics2D g, int width, int height) {
    Shape s = decodeExpandedPath(width, height);
    g.setPaint(selectedColor);
    g.fill(s);
}
 
Example 19
Source Project: astor   File: MeterPlot.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Fills an arc on the dial between the given values.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum data value.
 * @param maxValue  the maximum data value.
 * @param paint  the background paint (<code>null</code> not permitted).
 * @param dial  a flag that indicates whether the arc represents the whole
 *              dial.
 */
protected void fillArc(Graphics2D g2, Rectangle2D area,
                       double minValue, double maxValue, Paint paint,
                       boolean dial) {
    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument");
    }
    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    int joinType = Arc2D.OPEN;
    if (this.shape == DialShape.PIE) {
        joinType = Arc2D.PIE;
    }
    else if (this.shape == DialShape.CHORD) {
        if (dial && this.meterAngle > 180) {
            joinType = Arc2D.CHORD;
        }
        else {
            joinType = Arc2D.PIE;
        }
    }
    else if (this.shape == DialShape.CIRCLE) {
        joinType = Arc2D.PIE;
        if (dial) {
            extent = 360;
        }
    }
    else {
        throw new IllegalStateException("DialShape not recognised.");
    }

    g2.setPaint(paint);
    Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent,
            joinType);
    g2.fill(arc);
}
 
Example 20
Source Project: seaglass   File: SeaGlassProgressBarUI.java    License: Apache License 2.0 4 votes vote down vote up
protected void paint(SeaGlassContext context, Graphics g) {
    JProgressBar pBar = (JProgressBar) context.getComponent();
    Insets pBarInsets = pBar.getInsets();
    Rectangle bounds = calcBounds(pBar);
    // Save away the track bounds.
    savedRect.setBounds(bounds);
    // Subtract out any insets for the progress indicator.
    bounds.x += pBarInsets.left + progressPadding;
    bounds.y += pBarInsets.top + progressPadding;
    bounds.width -= pBarInsets.left + pBarInsets.right + progressPadding + progressPadding;
    bounds.height -= pBarInsets.top + pBarInsets.bottom + progressPadding + progressPadding;

    int size = 0;
    boolean isFinished = false;
    if (!pBar.isIndeterminate()) {
        double percentComplete = pBar.getPercentComplete();
        if (percentComplete == 1.0) {
            isFinished = true;
        } else if (percentComplete > 0.0) {
            if (pBar.getOrientation() == JProgressBar.HORIZONTAL) {
                size = (int) (percentComplete * bounds.width);
            } else { // JProgressBar.VERTICAL
                size = (int) (percentComplete * bounds.height);
            }
        }
    }

    // Create a translucent intermediate image in which we can perform soft
    // clipping.
    GraphicsConfiguration gc = ((Graphics2D) g).getDeviceConfiguration();
    BufferedImage img = gc.createCompatibleImage(bounds.width, bounds.height, Transparency.TRANSLUCENT);
    Graphics2D g2d = img.createGraphics();

    // Clear the image so all pixels have zero alpha
    g2d.setComposite(AlphaComposite.Clear);
    g2d.fillRect(0, 0, bounds.width, bounds.height);

    // Render our clip shape into the image. Enable antialiasing to achieve
    // a soft clipping effect.
    g2d.setComposite(AlphaComposite.Src);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(bgFillColor);
    CornerSize cornerSize = pBar.getOrientation() == JProgressBar.HORIZONTAL ? CornerSize.ROUND_HEIGHT : CornerSize.ROUND_WIDTH;
    g2d.fill(shapeGenerator.createRoundRectangle(0, 0, bounds.width, bounds.height, cornerSize));

    // Use SrcAtop, which effectively uses the alpha value as a coverage
    // value for each pixel stored in the destination. At the edges, the
    // antialiasing of the rounded rectangle gives us the desired soft
    // clipping effect.
    g2d.setComposite(AlphaComposite.SrcAtop);

    // We need to redraw the background, otherwise the interior is
    // completely white.
    context.getPainter().paintProgressBarBackground(context, g2d, savedRect.x - bounds.x, savedRect.y - bounds.y, savedRect.width,
        savedRect.height, pBar.getOrientation());
    paintProgressIndicator(context, g2d, bounds.width, bounds.height, size, isFinished);

    // Dispose of the image graphics and copy our intermediate image to the
    // main graphics.
    g2d.dispose();
    g.drawImage(img, bounds.x, bounds.y, null);

    if (pBar.isStringPainted()) {
        paintText(context, g, pBar.getString());
    }
}