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

The following are Jave code examples for showing how to use fill() of the java.awt.Graphics2D 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: openjdk-jdk10   File: RenderTests.java   View Source Code Vote up 6 votes
public void runTest(Object ctx, int numReps) {
    FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
    int size = cctx.size;
    int x = cctx.initX;
    int y = cctx.initY;
    Ellipse2D ellipse = cctx.ellipse;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        ellipse.setFrame(x, y, size, size);
        g2d.fill(ellipse);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example 2
Project: parabuild-ci   File: AbstractXYItemRenderer.java   View Source Code Vote up 6 votes
/**
 * Fills a band between two values on the axis.  This can be used to color
 * bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the domain axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
public void fillDomainGridBand(Graphics2D g2,
                               XYPlot plot,
                               ValueAxis axis,
                               Rectangle2D dataArea,
                               double start, double end) {

    double x1 = axis.valueToJava2D(start, dataArea,
            plot.getDomainAxisEdge());
    double x2 = axis.valueToJava2D(end, dataArea,
            plot.getDomainAxisEdge());
    // TODO: need to change the next line to take account of plot
    //       orientation...
    Rectangle2D band = new Rectangle2D.Double(x1, dataArea.getMinY(),
            x2 - x1, dataArea.getMaxY() - dataArea.getMinY());
    Paint paint = plot.getDomainTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 3
Project: jmt   File: StatiDrawer.java   View Source Code Vote up 6 votes
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	double pie = probability * 360;
	Color ctmp = g2d.getColor();
	if (bold) {
		g2d.setStroke(strokeB);
	}
	statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(sc);
	g2d.fill(statusE[status]);
	g2d.setPaint(pc);
	g2d.fill(statusP[status]);
	g2d.setPaint(borderC);
	g2d.draw(statusE[status]);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
	g2d.setColor(ctmp);
	g2d.setStroke(stroke);
}
 
Example 4
Project: QN-ACTR-Release   File: StatiDrawer.java   View Source Code Vote up 6 votes
public void drawLastStatus(String jobStr, double probability, Graphics2D g2d, Color sc, Color pc) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLenght() - 1) + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	Color ctmp = g2d.getColor();
	lastStatusE = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	g2d.setPaint(sc);
	g2d.fill(lastStatusE);
	//if(queueMax != 0){
	double pie = probability * 360;
	lastStatusP = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(pc);
	g2d.fill(lastStatusP);
	g2d.setPaint(Color.BLACK);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	//drawCenteredText("" + queueMax, Color.BLACK, x + STATUS_RAD, panelH/2.0, g2d, false);
	drawCenteredText(jobStr, Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
	//}
	g2d.setPaint(Color.BLACK);
	g2d.draw(lastStatusE);
	g2d.setColor(ctmp);
}
 
Example 5
Project: jdk8u-jdk   File: ShapeGraphicAttribute.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
public void draw(Graphics2D graphics, float x, float y) {

    // translating graphics to draw Shape !!!
    graphics.translate((int)x, (int)y);

    try {
        if (fStroke == STROKE) {
            // REMIND: set stroke to correct size
            graphics.draw(fShape);
        }
        else {
            graphics.fill(fShape);
        }
    }
    finally {
        graphics.translate(-(int)x, -(int)y);
    }
}
 
Example 6
Project: freecol   File: TileViewer.java   View Source Code Vote up 5 votes
/**
 * Displays Fog of War of the tile onto the given Graphics2D object,
 * if necessary.
 *
 * @param g The {@code Graphics2D} object on which to draw
 *     the {@code Tile}.
 * @param tile The {@code Tile} to draw.
 */
void displayFogOfWar(Graphics2D g, Tile tile) {
    if (hasFogOfWar(tile)) {
        g.setColor(Color.BLACK);
        Composite oldComposite = g.getComposite();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
                                                  0.2f));
        g.fill(fog);
        g.setComposite(oldComposite);
    }
}
 
Example 7
Project: trashjam2017   File: GradientEffect.java   View Source Code Vote up 5 votes
/**
 * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph)
 */
public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
	int ascent = unicodeFont.getAscent();
	float height = (ascent) * scale;
	float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2;
	g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic));
	g.fill(glyph.getShape());
}
 
Example 8
Project: OpenJSharp   File: RenderTests.java   View Source Code Vote up 5 votes
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example 9
Project: rapidminer   File: OverviewPanel.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);
	double scaleX = (double) getWidth() / (double) processRenderer.getWidth();
	double scaleY = (double) getHeight() / (double) processRenderer.getHeight();
	scale = Math.min(scaleX, scaleY);
	double scaledW = processRenderer.getWidth() * scale;
	double scaledH = processRenderer.getHeight() * scale;

	Graphics2D g = (Graphics2D) graphics.create();
	g.translate((getWidth() - scaledW) / 2d, (getHeight() - scaledH) / 2d);
	g.scale(scale, scale);

	g.setRenderingHints(ProcessDrawer.LOW_QUALITY_HINTS);
	processRenderer.getOverviewPanelDrawer().draw(g, true);

	g.setStroke(new BasicStroke((int) (1d / scale)));

	Rectangle visibleRect = processRenderer.getVisibleRect();
	Rectangle drawRect = new Rectangle((int) visibleRect.getX(), (int) visibleRect.getY(),
			(int) visibleRect.getWidth() - 1, (int) visibleRect.getHeight() - 1);

	g.setColor(FILL_COLOR);
	g.fill(drawRect);

	g.setColor(DRAW_COLOR);
	g.draw(drawRect);

	g.dispose();
}
 
Example 10
Project: ramus   File: DFDSFunction.java   View Source Code Vote up 5 votes
@Override
public void paintTringle(Graphics2D g) {
    if (paintTriangle >= 0) {
        // g.setClip(rect);
        g.fill(getTrianglePath(paintTriangle).createTransformedShape(
                AffineTransform.getScaleInstance(movingArea.zoom,
                        movingArea.zoom)));
        // g.setClip(null);
    }
}
 
Example 11
Project: FreeCol   File: MapViewer.java   View Source Code Vote up 5 votes
/**
 * Draws the pentagram indicating a native capital.
 *
 * @param extent The nominal height of the image.
 * @param padding Padding to add around the image.
 * @param backgroundColor The image background color.
 * @return A suitable {@code BufferedImage}.
 */
private static BufferedImage createCapitalLabel(int extent, int padding,
                                                Color backgroundColor) {
    // create path
    double deg2rad = Math.PI/180.0;
    double angle = -90.0 * deg2rad;
    double offset = extent * 0.5;
    double size1 = (extent - padding - padding) * 0.5;

    GeneralPath path = new GeneralPath();
    path.moveTo(Math.cos(angle) * size1 + offset, Math.sin(angle) * size1 + offset);
    for (int i = 0; i < 4; i++) {
        angle += 144 * deg2rad;
        path.lineTo(Math.cos(angle) * size1 + offset, Math.sin(angle) * size1 + offset);
    }
    path.closePath();

    // draw everything
    BufferedImage bi = new BufferedImage(extent, extent, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(backgroundColor);
    g.fill(new RoundRectangle2D.Float(0, 0, extent, extent, padding, padding));
    g.setColor(Color.BLACK);
    g.setStroke(new BasicStroke(2.4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    g.draw(path);
    g.setColor(Color.WHITE);
    g.fill(path);
    g.dispose();
    return bi;
}
 
Example 12
Project: parabuild-ci   File: StandardLegend.java   View Source Code Vote up 5 votes
/**
 * Draws the bounding box for the legend.
 * 
 * @param g2  the graphics device.
 * @param legendArea  the legend area.
 */
private void drawLegendBox(Graphics2D g2, RectangularShape legendArea) {
    // Draw the legend's bounding box
    g2.setPaint(this.backgroundPaint);
    g2.fill(legendArea);
    g2.setPaint(this.outlinePaint);
    g2.setStroke(this.outlineStroke);
    g2.draw(legendArea);
}
 
Example 13
Project: rapidminer   File: SurveyPlotter.java   View Source Code Vote up 5 votes
private void paintSurveyColumn(Graphics graphics, int column, float currentX, float columnDistance) {
	Graphics2D g = (Graphics2D) graphics.create();
	g.translate(currentX, 0);

	// draw weight rect
	if (dataTable.isSupportingColumnWeights()) {
		Color weightColor = getWeightColor(dataTable.getColumnWeight(column), this.maxWeight);
		Rectangle2D weightRect = new Rectangle2D.Double(0, MARGIN, columnDistance, this.dataTable.getNumberOfRows());
		g.setColor(weightColor);
		g.fill(weightRect);
	}

	if (this.dataTable.getNumberOfColumns() <= 10) {
		g.drawString(this.dataTable.getColumnName(column), 0, MARGIN - 3);
	}
	g.translate(0, MARGIN);

	g.setColor(GRID_COLOR);
	g.drawLine(0, 0, 0, this.dataTable.getNumberOfRows());

	g.translate(1, 0);
	columnDistance--;
	int counter = 0;
	Iterator<SurveyRow> s = dataRows.iterator();
	while (s.hasNext()) {
		SurveyRow row = s.next();
		double[] data = row.data;
		double length = norm(data, column) * columnDistance;
		double color = row.color;
		g.setColor(getColorProvider().getPointColor(color));
		g.drawLine(0, counter, (int) length, counter);
		counter++;
	}
}
 
Example 14
Project: rapidminer   File: ColoredBlockContainer.java   View Source Code Vote up 5 votes
/**
 * Draws a colored background. Returns the area wich has been filled.
 */
private Rectangle2D drawFill(Graphics2D g2, Rectangle2D area) {
	Rectangle2D filledArea = (Rectangle2D) area.clone();
	filledArea = trimMargin(filledArea);
	filledArea = trimBorder(filledArea);
	area = trimPadding(area);
	g2.setPaint(this.fillPaint);
	g2.fill(filledArea);
	drawBorder(g2, filledArea);
	return filledArea;
}
 
Example 15
Project: geomapapp   File: FocalMechanismSolutionDB.java   View Source Code Vote up 4 votes
private void drawEQ(Graphics2D g, GeneralPath shape) {
	g.setColor(Color.green);
	g.fill(shape);
	g.setColor( Color.blue );
	g.draw( shape );
}
 
Example 16
Project: rapidminer   File: RadioButtonMenuItemIcon.java   View Source Code Vote up 4 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	JMenuItem b = (JMenuItem) c;
	ButtonModel bm = b.getModel();

	g.translate(x, y);

	boolean isSelected = bm.isSelected();
	boolean isEnabled = bm.isEnabled();
	boolean isPressed = bm.isPressed();

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

	// drawing background section
	if (!isEnabled) {
		g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
	} else {
		if (isPressed) {
			g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
		} else {
			g2.setColor(Colors.RADIOBUTTON_BORDER);
		}
	}
	g2.setStroke(RADIO_STROKE);
	Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
	g2.draw(circle);

	// drawing sphere
	if (isSelected) {
		if (isEnabled) {
			g2.setColor(Colors.RADIOBUTTON_CHECKED);
		} else {
			g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
		}
		circle = new Ellipse2D.Double(3, 3, 4, 4);
		g2.fill(circle);
	}

	g.translate(-x, -y);
}
 
Example 17
Project: freecol   File: MapViewer.java   View Source Code Vote up 4 votes
/**
 * Draws a cross indicating a religious mission is present in the
 * native village.
 *
 * @param extent The nominal height of the image.
 * @param padding Padding to add around the image.
 * @param backgroundColor The image background color.
 * @param expertMissionary True if the label should show expertise.
 * @return A suitable {@code BufferedImage}.
 */
private static BufferedImage createReligiousMissionLabel(int extent,
        int padding, Color backgroundColor, boolean expertMissionary) {
    // create path
    double offset = extent * 0.5;
    double size1 = extent - padding - padding;
    double bar = size1 / 3.0;
    double inset = 0.0;
    double kludge = 0.0;

    GeneralPath circle = new GeneralPath();
    GeneralPath cross = new GeneralPath();
    if (expertMissionary) {
        // this is meant to represent the eucharist (the -1, +1 thing is a nasty kludge)
        circle.append(new Ellipse2D.Double(padding-1, padding-1, size1+1, size1+1), false);
        inset = 4.0;
        bar = (size1 - inset - inset) / 3.0;
        // more nasty -1, +1 kludges
        kludge = 1.0;
    }
    offset -= 1.0;
    cross.moveTo(offset, padding + inset - kludge);
    cross.lineTo(offset, extent - padding - inset);
    cross.moveTo(offset - bar, padding + bar + inset);
    cross.lineTo(offset + bar + 1, padding + bar + inset);

    // draw everything
    BufferedImage bi = new BufferedImage(extent, extent, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(backgroundColor);
    g.fill(new RoundRectangle2D.Float(0, 0, extent, extent, padding, padding));
    g.setColor(ImageLibrary.getForegroundColor(backgroundColor));
    if (expertMissionary) {
        g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.draw(circle);
        g.setStroke(new BasicStroke(1.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    } else {
        g.setStroke(new BasicStroke(2.4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    }
    g.draw(cross);
    g.dispose();
    return bi;
}
 
Example 18
Project: rapidminer   File: SystemMonitor.java   View Source Code Vote up 4 votes
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath path = new GeneralPath();

	Dimension d = getSize();
	int monitorWidth = (int) d.getWidth() - 2 * MARGIN;
	int monitorHeight = (int) d.getHeight() - 2 * MARGIN;

	long total = Runtime.getRuntime().totalMemory();

	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (this.font == null) {
		this.font = g2d.getFont().deriveFont(12f);
	}

	g2d.setColor(Colors.WHITE);
	g2d.fillRect(MARGIN, MARGIN, monitorWidth, monitorHeight);

	path.moveTo(MARGIN, MARGIN + monitorHeight);
	for (int i = 0; i < memory.length; i++) {
		int index = (currentMeasurement + i) % memory.length;
		path.lineTo(MARGIN + i * monitorWidth / (memory.length - 1),
				MARGIN + monitorHeight - monitorHeight * memory[index] / total);
	}
	path.lineTo(MARGIN + monitorWidth, MARGIN + monitorHeight);
	path.closePath();

	g2d.setColor(gridColor);
	for (int x = 0; x < GRID_X + 1; x++) {
		g2d.drawLine(MARGIN + x * monitorWidth / GRID_X, MARGIN, MARGIN + x * monitorWidth / GRID_X,
				MARGIN + monitorHeight);
	}
	for (int y = 0; y < GRID_Y + 1; y++) {
		g2d.drawLine(MARGIN, MARGIN + y * monitorHeight / GRID_Y, MARGIN + monitorWidth,
				MARGIN + y * monitorHeight / GRID_Y);
	}

	Color currentMemoryColor = memoryColor;
	if (currentlyUsed > 0.2d * Runtime.getRuntime().maxMemory()) {
		double more = currentlyUsed - 0.2d * Runtime.getRuntime().maxMemory();
		double factor = more / (0.6d * Runtime.getRuntime().maxMemory());
		currentMemoryColor = getMemoryColor(Math.max(Math.min(1.0d, factor), 0.0d));
	}
	g2d.setColor(currentMemoryColor);
	g2d.fill(path);
	g2d.setColor(lineColor);
	g2d.draw(path);

	// text
	String maxString = Tools.formatSizeInBytes(total) + " used. Will use up to "
			+ Tools.formatSizeInBytes(Runtime.getRuntime().maxMemory());
	int totalHeight = 2 * font.getSize() + 2 * MARGIN;
	// MARGIN;
	if (totalHeight < getHeight()) {
		g2d.setFont(font);
		g2d.setColor(textColor);
		g2d.drawString(maxString, 2 * MARGIN, monitorHeight - font.getSize() + MARGIN);
	}
}
 
Example 19
Project: geomapapp   File: SurveyLine.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics2D g) {
	float wrap = (float)map.getWrap();
	
	//get the limits of the displayed map
	Rectangle2D rect = map.getClipRect2D();
	double xmin = rect.getMinX();
	double xmax = rect.getMaxX();
	
	Projection proj = map.getProjection();
	Point2D.Double pt = new Point2D.Double();
	pt.x = getStartLon();
	pt.y = getStartLat();
	Point2D.Double p_start = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_start.x <= xmin ){p_start.x+=wrap;}
		while( p_start.x >= xmax ){p_start.x-=wrap;}
	}
	
	pt.x = getEndLon();
	pt.y = getEndLat();
	Point2D.Double p_end = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_end.x <= xmin ){p_end.x+=wrap;}
		while( p_end.x > wrap + xmin ){p_end.x-=wrap;}
	}
	
	//draw the shortest line - either p_start.x to p_end.x or the x+wrap values. 
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
		((p_start.x - (p_end.x + wrap)) * (p_start.x - (p_end.x + wrap))) )  {p_end.x += wrap;}
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
	(((p_start.x + wrap) - p_end.x) * ((p_start.x + wrap) - p_end.x)) )  {p_start.x += wrap;}
	
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
	
	double zoom = map.getZoom();
	g.setStroke( new BasicStroke( 2f/(float)zoom ));

   	double arr_size = 6./zoom;
   	double sq_size = 6./zoom;
       double dx = p_end.x - p_start.x, dy = p_end.y - p_start.y;
       double angle = Math.atan2(dy, dx);
       double len = Math.sqrt(dx*dx + dy*dy);

       AffineTransform at = g.getTransform(); 
       g.translate(p_start.x, p_start.y);
       g.rotate(angle);

       //draw the line
       g.draw(new Line2D.Double(0, 0, len, 0));
       //draw the arrow
       Path2D arrow = new Path2D.Double();
       double xpts[] = {len/3d, len/3d-arr_size, len/3d-arr_size, len/3d};
       double ypts[] = {0, -arr_size, arr_size, 0};
       arrow.moveTo(xpts[0], ypts[0]);
       arrow.lineTo(xpts[1], ypts[1]);
       arrow.lineTo(xpts[2], ypts[2]);
       arrow.closePath();
	if (lineNum == 1) g.setColor( Color.ORANGE ); 
	else g.setColor( Color.ORANGE );
       g.fill(arrow);
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
       //draw squares at the end points
       Rectangle2D startSq = new Rectangle2D.Double(0d-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
       Rectangle2D endSq = new Rectangle2D.Double(len-sq_size/2d, 0d-sq_size/2d,  sq_size, sq_size);
       g.fill(startSq);
       g.fill(endSq);

       g.setTransform(at);
       
}
 
Example 20
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 4 votes
/** Renders the caret */
public @Override void paint(Graphics g) {
    JTextComponent c = component;
    if (c == null) return;

    // #70915 Check whether the caret was moved but the component was not
    // validated yet and therefore the caret bounds are still null
    // and if so compute the bounds and scroll the view if necessary.
    if (getDot() != 0 && caretBounds == null) {
        update(true);
    }
    if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("BaseCaret.paint(): caretBounds=" + caretBounds + dumpVisibility() + '\n');
    }
    if (caretBounds != null && isVisible() && blinkVisible) {
        paintCustomCaret(g);
    }
    if (rectangularSelection && rsPaintRect != null && g instanceof Graphics2D) {
        Graphics2D g2d = (Graphics2D) g;
        Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {4, 2}, 0);
        Stroke origStroke = g2d.getStroke();
        Color origColor = g2d.getColor();
        try {
            // Render translucent rectangle
            Color selColor = c.getSelectionColor();
            g2d.setColor(selColor);
            Composite origComposite = g2d.getComposite();
            try {
                g2d.setComposite(AlphaComposite.SrcOver.derive(0.2f));
                g2d.fill(rsPaintRect);
            } finally {
                g2d.setComposite(origComposite);
            }
            // Paint stroked line around rectangular selection rectangle
            g.setColor(c.getCaretColor());
            g2d.setStroke(stroke);
            Rectangle onePointSmallerRect = new Rectangle(rsPaintRect);
            onePointSmallerRect.width--;
            onePointSmallerRect.height--;
            g2d.draw(onePointSmallerRect);

        } finally {
            g2d.setStroke(origStroke);
            g2d.setColor(origColor);
        }
    }
}