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

The following examples show how to use javafx.scene.canvas.GraphicsContext#getStroke() . 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: DashPatternStyle.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public static void strokeDashedLine(final GraphicsContext gc, final double x0, final double y0, final double x1,
        final double y1) {
    final Paint color = gc.getStroke();
    final double strokeWidth = Math.max(gc.getLineWidth(), 1);
    final double strokeWidthHalf = strokeWidth / 2.0;
    final double[] pattern = gc.getLineDashes();
    final double width = Math.abs(x1 - x0);
    final double height = Math.abs(y1 - y0);
    final boolean isHorizontal = width > height;

    gc.setFill(DashPatternStyle.createDefaultHatch(color, strokeWidth, isHorizontal, pattern));
    if (isHorizontal) {
        gc.fillRect(x0, y0 - strokeWidthHalf, width, strokeWidth);
    } else {
        gc.fillRect(x0 - strokeWidthHalf, y0, strokeWidth, height);
    }

}
 
Example 2
Source File: Grid.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
    * Draws this grid inside a rectangle.
    * @param pGraphics the graphics context
    * @param pBounds the bounding rectangle
    */
public static void draw(GraphicsContext pGraphics, Rectangle pBounds)
{
	Paint oldStroke = pGraphics.getStroke();
	pGraphics.setStroke(GRID_COLOR);
	int x1 = pBounds.getX();
	int y1 = pBounds.getY();
	int x2 = pBounds.getMaxX();
	int y2 = pBounds.getMaxY();
	for(int x = x1; x < x2; x += GRID_SIZE)
	{
		ToolGraphics.strokeSharpLine(pGraphics, x, y1, x, y2);
	}
	for(int y = y1; y < y2; y += GRID_SIZE)
	{
		ToolGraphics.strokeSharpLine(pGraphics, x1, y, x2, y);
	}
	pGraphics.setStroke(oldStroke);
}
 
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: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a "rubberband" line on pGraphics. A rubberband line is a straight line
 * in the color of the selection tools.
 * 
 * @param pGraphics The graphics context on which to draw the line.
 * @param pLine The line that represents the rubberband.
 */
public static void drawRubberband(GraphicsContext pGraphics, Line pLine)
{
	Paint oldStroke = pGraphics.getStroke();
	pGraphics.setStroke(SELECTION_FILL_COLOR);
	strokeSharpLine(pGraphics, pLine.getX1(), pLine.getY1(), pLine.getX2(), pLine.getY2());
	pGraphics.setStroke(oldStroke);
}
 
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);
}