Java Code Examples for javafx.scene.canvas.GraphicsContext#getFill()

The following examples show how to use javafx.scene.canvas.GraphicsContext#getFill() . 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 File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Strokes and fills a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pFill The fill color for the path.
 * @param pShadow True to include a drop shadow.
 */
public static void strokeAndFillSharpPath(GraphicsContext pGraphics, Path pPath, Paint pFill, boolean pShadow)
{
	double width = pGraphics.getLineWidth();
	Paint fill = pGraphics.getFill();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.setFill(pFill);
	applyPath(pGraphics, pPath);
	
	if( pShadow )
	{
		pGraphics.setEffect(DROP_SHADOW);
	}
	pGraphics.fill();
	pGraphics.stroke();
	pGraphics.setLineWidth(width);
	pGraphics.setFill(fill);
	pGraphics.setEffect(null);
}
 
Example 2
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void drawLabel(StateTransitionEdge pEdge, GraphicsContext pGraphics)
{
	adjustLabelFont(pEdge);
	Rectangle2D labelBounds = getLabelBounds(pEdge);
	double x = labelBounds.getMinX();
	double y = labelBounds.getMinY();
	
	Paint oldFill = pGraphics.getFill();
	Font oldFont = pGraphics.getFont();
	pGraphics.translate(x, y);
	pGraphics.setFill(Color.BLACK);
	pGraphics.setFont(aFont);
	pGraphics.setTextAlign(TextAlignment.CENTER);
	pGraphics.fillText(pEdge.getMiddleLabel(), labelBounds.getWidth()/2, 0);
	pGraphics.setFill(oldFill);
	pGraphics.setFont(oldFont);
	pGraphics.translate(-x, -y);        
}
 
Example 3
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a handle on pGraphics that is centered at the position
 * (pX, pY).
 * 
 * @param pGraphics The graphics context on which to draw the handle.
 * @param pX The x-coordinate of the center of the handle.
 * @param pY The y-coordinate of the center of the handle.
 */
private static void drawHandle(GraphicsContext pGraphics, int pX, int pY)
{
	Paint oldStroke = pGraphics.getStroke();
	Paint oldFill = pGraphics.getFill();
	pGraphics.setStroke(SELECTION_COLOR);
	pGraphics.strokeRect((int)(pX - HANDLE_SIZE / 2.0) + 0.5, (int)(pY - HANDLE_SIZE / 2.0)+ 0.5, HANDLE_SIZE, HANDLE_SIZE);
	pGraphics.setFill(SELECTION_FILL_COLOR);
	pGraphics.fillRect((int)(pX - HANDLE_SIZE / 2.0)+0.5, (int)(pY - HANDLE_SIZE / 2.0)+0.5, HANDLE_SIZE, HANDLE_SIZE);
	pGraphics.setStroke(oldStroke);
	pGraphics.setFill(oldFill);
}
 
Example 4
Source File: SegmentedEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a string.
 * @param pGraphics the graphics context
 * @param pEndPoint1 an endpoint of the segment along which to draw the string
 * @param pEndPoint2 the other endpoint of the segment along which to draw the string
 * @param pString the string to draw 
 * @param pCenter true if the string should be centered along the segment
 */
private static void drawString(GraphicsContext pGraphics, Point2D pEndPoint1, Point2D pEndPoint2, 
		ArrowHead pArrowHead, String pString, boolean pCenter)
{
	if (pString == null || pString.length() == 0)
	{
		return;
	}
	Rectangle bounds = getStringBounds(pEndPoint1, pEndPoint2, pArrowHead, pString, pCenter);
	
	Paint oldFill = pGraphics.getFill();
	VPos oldVPos = pGraphics.getTextBaseline();
	TextAlignment oldAlign = pGraphics.getTextAlign();
	pGraphics.translate(bounds.getX(), bounds.getY());
	pGraphics.setFill(Color.BLACK);
	int textX = 0;
	int textY = 0;
	if(pCenter) 
	{
		textX = bounds.getWidth()/2;
		textY = bounds.getHeight() - textDimensions(pString).getHeight()/2;
		pGraphics.setTextBaseline(VPos.CENTER);
		pGraphics.setTextAlign(TextAlignment.CENTER);
	}
	pGraphics.fillText(pString, textX, textY);
	pGraphics.translate(-bounds.getX(), -bounds.getY()); 
	pGraphics.setFill(oldFill);
	pGraphics.setTextBaseline(oldVPos);
	pGraphics.setTextAlign(oldAlign);
}
 
Example 5
Source File: ViewUtils.java    From JetUML with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Strokes and fills a rectangle, originally in integer coordinates, so that it aligns precisely
 * with the JavaFX coordinate system, which is 0.5 away from the pixel. See
 * the documentation for javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context on which to draw the rectangle.
 * @param pStroke The stroke (border) color for the rectangle.
 * @param pFill The fill (background) color for the rectangle.
 * @param pX The x-coordinate of the origin.
 * @param pY The y-coordinate of the origin.
 * @param pWidth The width.
 * @param pHeight The height.
 */
public static void drawRectangle(GraphicsContext pGraphics, Paint pStroke, Paint pFill, 
		int pX, int pY, int pWidth, int pHeight)
{
	Paint oldFill = pGraphics.getFill();
	Paint oldStroke = pGraphics.getStroke();
	pGraphics.setFill(pFill);
	pGraphics.setStroke(pStroke);
	pGraphics.fillRect(pX + 0.5, pY + 0.5, pWidth, pHeight);
	pGraphics.strokeRect(pX + 0.5, pY + 0.5, pWidth, pHeight);
	pGraphics.setFill(oldFill);
	pGraphics.setStroke(oldStroke);
}