Java Code Examples for java.awt.Graphics.fillPolygon()

The following are Jave code examples for showing how to use fillPolygon() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Logisim   File: ComponentIcon.java   View Source Code Vote up 7 votes
@Override
public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
	// draw tool icon
	Graphics gIcon = g.create();
	ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon);
	comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet());
	gIcon.dispose();

	if (triangleState != TRIANGLE_NONE) {
		int[] xp;
		int[] yp;
		if (triangleState == TRIANGLE_CLOSED) {
			xp = new int[] { x + 13, x + 13, x + 17 };
			yp = new int[] { y + 11, y + 19, y + 15 };
		} else {
			xp = new int[] { x + 11, x + 19, x + 15 };
			yp = new int[] { y + 13, y + 13, y + 17 };
		}
		g.setColor(Color.LIGHT_GRAY);
		g.fillPolygon(xp, yp, 3);
		g.setColor(Color.DARK_GRAY);
		g.drawPolygon(xp, yp, 3);
	}
}
 
Example 2
Project: sumo   File: MaskGeometries.java   View Source Code Vote up 6 votes
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {

	// create the buffered image of the size of the Rectangle
    BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
    GeometryFactory gf = new GeometryFactory();

    // define the clipping region in full scale
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};

    Polygon geom = gf.createPolygon(gf.createLinearRing(coords));

    Graphics g2d = image.getGraphics();

    g2d.setColor(Color.white);
    for (Geometry p : maskGeometries) {
    	/*if(p instanceof MultiPolygon){
    		p=p.getBoundary();
    	}*/
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
            int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
                yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
                i++;
            }
            g2d.fillPolygon(xPoints, yPoints, i);
        }
    }
    g2d.dispose();
    return image;

}
 
Example 3
Project: incubator-netbeans   File: TapPanel.java   View Source Code Vote up 5 votes
public void paintIcon (java.awt.Component c, Graphics g, int x, int y) {

            g.setColor ( armed ?
                    UIManager.getColor ( "List.selectionForeground" ) : //NOI18N
                    UIManager.getColor ( "controlShadow" ) ); //NOI18N
/*            int[] xPoints = new int[] {x+getIconWidth()/2, x+getIconWidth(), x};
            int[] yPoints = new int[] {y, y+getIconHeight()-1, y+getIconHeight()-1};
 */
            int[] xPoints = new int[]{x, x + 8, x + 4};
            int[] yPoints = new int[]{y + 5, y + 5, y};

            g.fillPolygon ( xPoints, yPoints, 3 );
        }
 
Example 4
Project: incubator-netbeans   File: TapPanel.java   View Source Code Vote up 5 votes
public void paintIcon (java.awt.Component c, Graphics g, int x, int y) {
    x++;
    g.setColor ( armed ?
            UIManager.getColor ( "List.selectionForeground" ) : //NOI18N
            UIManager.getColor ( "controlShadow" ) ); //NOI18N
    /*
    int[] xPoints = new int[] {(x+getIconWidth()/2), x+getIconWidth()-1, x};
    int[] yPoints = new int[] {y+getIconHeight()-2, y, y};
     */
    int[] xPoints = new int[]{x, x + 8, x + 4};
    int[] yPoints = new int[]{y, y, y + 4};

    g.fillPolygon ( xPoints, yPoints, 3 );
}
 
Example 5
Project: sumo   File: InterpolatedVectorLayer.java   View Source Code Vote up 5 votes
public BufferedImage rasterize(BufferedImage image, int offsetX, int offsetY, double scalingFactor) {
    Rectangle rect = image.getRaster().getBounds();
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    Graphics g2d = image.getGraphics();
    g2d.setColor(Color.WHITE);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x - offsetX) * scalingFactor);
                yPoints[i++] = (int) ((c.y - offsetY) * scalingFactor);
            }
            g2d.fillPolygon(xPoints, yPoints, p.getNumPoints());
        }
    }
    g2d.dispose();
    return image;
}
 
Example 6
Project: VASSAL-src   File: MenuScroller.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(Color.GRAY);
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(Color.BLACK);
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
Example 7
Project: JDigitalSimulator   File: SevenSegmentDisplay.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.drawRect(10, 0, size.width-10, size.height);
	for(int input=0;input<inputs.length;input++) {
		Polygon polygon = new Polygon(POLYGONS_X[input], POLYGONS_Y[input], 7);
		polygon.translate(15, 4);
		if(inputs[input].isCharged()) {
			graphics.setColor(Color.RED);
			graphics.fillPolygon(polygon);
		}
		graphics.setColor(Color.BLACK);
		graphics.drawPolyline(polygon.xpoints, polygon.ypoints, polygon.npoints);
	}
	ContactUtilities.paintSolderingJoints(graphics, 10, 0, inputs);
}
 
Example 8
Project: LivroJavaComoProgramar10Edicao   File: PolygonsJPanel.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 

   // draw polygon with Polygon object
   int[] xValues = {20, 40, 50, 30, 20, 15};
   int[] yValues = {50, 50, 60, 80, 80, 60};
   Polygon polygon1 = new Polygon(xValues, yValues, 6);
   g.drawPolygon(polygon1);

   // draw polylines with two arrays
   int[] xValues2 = {70, 90, 100, 80, 70, 65, 60};
   int[] yValues2 = {100, 100, 110, 110, 130, 110, 90};
   g.drawPolyline(xValues2, yValues2, 7);

   // fill polygon with two arrays
   int[] xValues3 = {120, 140, 150, 190};
   int[] yValues3 = {40, 70, 80, 60};
   g.fillPolygon(xValues3, yValues3, 4);

   // draw filled polygon with Polygon object
   Polygon polygon2 = new Polygon();
   polygon2.addPoint(165, 135);
   polygon2.addPoint(175, 150);
   polygon2.addPoint(270, 200);
   polygon2.addPoint(200, 220);
   polygon2.addPoint(130, 180);
   g.fillPolygon(polygon2);
}
 
Example 9
Project: jaer   File: MenuScroller.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(Color.GRAY);
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(Color.BLACK);
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
Example 10
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.fillPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 11
Project: OpenJSharp   File: BasicIconFactory.java   View Source Code Vote up 5 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Polygon p = new Polygon();
    p.addPoint(x, y);
    p.addPoint(x+getIconWidth(), y+getIconHeight()/2);
    p.addPoint(x, y+getIconHeight());
    g.fillPolygon(p);

}
 
Example 12
Project: openjdk-jdk10   File: MotifIconFactory.java   View Source Code Vote up 4 votes
public void drawCheckBezel(Graphics g, int x, int y, int csize,
                       boolean shade, boolean out, boolean check, boolean flat)
{


    Color oldColor = g.getColor();
    g.translate(x, y);


    //bottom
    if(!flat) {
        if (out) {
            g.setColor(control);
            g.fillRect(1,1,csize-2,csize-2);
            g.setColor(shadow);
        } else {
            g.setColor(lightShadow);
            g.fillRect(0,0,csize,csize);
            g.setColor(highlight);
        }

        g.drawLine(1,csize-1,csize-2,csize-1);
        if (shade) {
            g.drawLine(2,csize-2,csize-3,csize-2);
            g.drawLine(csize-2,2,csize-2 ,csize-1);
            if (out) {
                g.setColor(highlight);
            } else {
                g.setColor(shadow);
            }
            g.drawLine(1,2,1,csize-2);
            g.drawLine(1,1,csize-3,1);
            if (out) {
                g.setColor(shadow);
            } else {
                g.setColor(highlight);
            }
        }
        //right
        g.drawLine(csize-1,1,csize-1,csize-1);

        //left
        if (out) {
            g.setColor(highlight);
        } else {
            g.setColor(shadow);
        }
        g.drawLine(0,1,0,csize-1);

        //top
        g.drawLine(0,0,csize-1,0);
    }

    if (check) {
        // draw check
        g.setColor(foreground);
        int[] xa = {csize - 12, csize - 8, csize - 7, csize - 4,
                    csize - 2, csize - 2, csize - 8, csize - 10,
                    csize - 11};
        int[] ya = new int[]{6, 10, 10, 4, 2, 1, 7, 5, 5};
        g.fillPolygon(xa, ya, 9);
    }
    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 13
Project: openjdk-jdk10   File: CSSBorder.java   View Source Code Vote up 4 votes
public void paint(Polygon shape, Graphics g, Color color, int side) {
    g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ?
                        getShadowColor(color) : getLightColor(color));
    g.fillPolygon(shape);
}
 
Example 14
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
* This function draw te area among the axis and the point of the convex hull
 * @param g The graphic object
 * @param allConvex The vector with the points of the convex hull
 * @param allDominants The vector with the dominant points
 * @param area The filter area
 * @param maskedoff The vector with the masked-off points
 */
public void drawArea(Graphics g, Vector<Point2D> allConvex, Vector<Point2D> allDominants, Color area, Color maskedoff) {
	//The first color in the maskedoff color beacause after will be draw
	//the non-maskedoff areas
	g.setColor(maskedoff);
	Polygon poly = new Polygon();

	DPoint p;
	p = (DPoint) allConvex.get(0);

	poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y);

	//Add the point a the polygon for paint the convex area
	for (int i = 0; i < allConvex.size(); i++) {
		p = (DPoint) allConvex.get(i);
		poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
	}

	p = (DPoint) allConvex.get(allConvex.size() - 1);
	poly.addPoint(1 + tran_x, tran_y - (int) (p.getY() * scale));
	poly.addPoint(1 + tran_x, tran_y);
	g.fillPolygon(poly);
	g.setColor(Color.GRAY);
	g.drawPolygon(poly);

	//Draw the non-maskedoff area for each dominant point
	Polygon masked = new Polygon();
	g.setColor(area);

	int k = 0;
	for (k = 0; k < allDominants.size() - 1; k++) {
		p = (DPoint) allDominants.get(k);
		if (!p.intEquals((DPoint) allDominants.get(k + 1))) {
			masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
			g.fillPolygon(masked);
		}
	}
	//Last area is 1 point small
	p = (DPoint) allDominants.get(k);
	masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale) + 1);
	g.fillPolygon(masked);
}
 
Example 15
Project: jdk8u-jdk   File: CSSBorder.java   View Source Code Vote up 4 votes
public void paint(Polygon shape, Graphics g, Color color, int side) {
    g.setColor(color);
    g.fillPolygon(shape);
}
 
Example 16
Project: Logisim   File: Shifter.java   View Source Code Vote up 4 votes
private void drawArrow(Graphics g, int x, int y, int d) {
	int[] px = { x + d, x, x + d };
	int[] py = { y + d, y, y - d };
	g.fillPolygon(px, py, 3);
}
 
Example 17
Project: Equella   File: DecisionRenderer.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	final int centreX = (int) bounds.getCenterX();

	// Draw the leading arrow
	drawLeadingInArrow(g, centreX, bounds.y, HALF_ARROW_HEIGHT);

	// Draw the trailing arrow
	drawLeadingOutArrow(g, centreX, bounds.y + bounds.height - HALF_ARROW_HEIGHT, HALF_ARROW_HEIGHT);

	// Get ready to draw our child
	Dimension childSize = super.getSizeWithNoPadding(g);
	Rectangle childBound = new Rectangle();
	childBound.x = centreX - (childSize.width / 2);
	childBound.y = bounds.y + (HALF_ARROW_HEIGHT * 2) + DIAMOND_SIZE;
	childBound.width = childSize.width;
	childBound.height = childSize.height;

	// Draw child
	super.draw(g, childBound);

	// Do some general calculations
	Rectangle2D textSize = g.getFontMetrics().getStringBounds(nodeName, g);

	int diamondTop = bounds.y + HALF_ARROW_HEIGHT;
	int halfDiamondY = DIAMOND_SIZE / 2;
	int halfDiamondX = (int) (textSize.getWidth() / 2) + (PADDING_SIZE * 2);

	int textStartX = centreX - (int) (textSize.getWidth() / 2);
	int textStartY = diamondTop + halfDiamondY + (int) (textSize.getHeight() / 2);

	// Draw the diamond
	int[] pointsX = {centreX, centreX - halfDiamondX, centreX, centreX + halfDiamondX};
	int[] pointsY = {diamondTop, diamondTop + halfDiamondY, diamondTop + DIAMOND_SIZE, diamondTop + halfDiamondY};

	if( getHilight() != null )
	{
		g.setColor(getHilight());
		g.fillPolygon(pointsX, pointsY, pointsX.length);
	}

	g.setColor(Color.BLACK);
	g.drawPolygon(pointsX, pointsY, pointsX.length);

	// Draw the text
	g.setColor(Color.BLACK);
	g.drawString(nodeName, textStartX, textStartY - 3);

	// Draw the arrow leading out from the diamond
	drawLeadingOutArrow(g, centreX, diamondTop + DIAMOND_SIZE, HALF_ARROW_HEIGHT);

	// Draw connecting lines
	int lineX1 = centreX - (childSize.width / 2) - PADDING_SIZE;
	int lineX2 = centreX - halfDiamondX;
	int lineY1 = diamondTop + halfDiamondY;
	int lineY2 = lineY1 + HALF_ARROW_HEIGHT + halfDiamondY + childSize.height;

	lineX1 = Math.min(lineX1, lineX2);

	g.setColor(ARROW_COLOUR);
	g.drawLine(lineX1, lineY1, lineX2, lineY1);
	g.drawLine(lineX1, lineY2, centreX, lineY2);
	g.drawLine(lineX1, lineY1, lineX1, lineY2);

	// Draw sideways pointer on arrow
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 - ARROW_HEAD_WIDTH, centreX, lineY2);
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 + ARROW_HEAD_WIDTH, centreX, lineY2);
}
 
Example 18
Project: OpenJSharp   File: CSSBorder.java   View Source Code Vote up 4 votes
public void paint(Polygon shape, Graphics g, Color color, int side) {
    g.setColor(color);
    g.fillPolygon(shape);
}
 
Example 19
Project: OpenJSharp   File: CSSBorder.java   View Source Code Vote up 4 votes
public void paint(Polygon shape, Graphics g, Color color, int side) {
    g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ?
                        getShadowColor(color) : getLightColor(color));
    g.fillPolygon(shape);
}
 
Example 20
Project: java-course   File: BarChartComponent.java   View Source Code Vote up 3 votes
/**
 * Draws a filled triangle at given points.
 * 
 * @param x
 *            Points on x-axis.
 * @param y
 *            Points on y-axis.
 * @param g
 *            The {@link Graphics} object.
 */
private void drawTriangle(int[] x, int[] y, Graphics g) {
    int n = 3;
    Polygon p = new Polygon(x, y, n);
    g.setColor(Color.GRAY);
    g.fillPolygon(p);
}