Java Code Examples for javafx.scene.canvas.GraphicsContext#setLineDashes()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#setLineDashes() .
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: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 5 votes |
protected void setGraphicsContextAttributes(final GraphicsContext gc, final String style) { final Color strokeColor = StyleParser.getColorPropertyValue(style, XYChartCss.STROKE_COLOR); if (strokeColor == null) { gc.setStroke(strokeColorMarker); } else { gc.setStroke(strokeColor); } final Color fillColor = StyleParser.getColorPropertyValue(style, XYChartCss.FILL_COLOR); if (fillColor == null) { gc.setFill(strokeColorMarker); } else { gc.setFill(fillColor); } final Double strokeWidth = StyleParser.getFloatingDecimalPropertyValue(style, XYChartCss.STROKE_WIDTH); if (strokeWidth == null) { gc.setLineWidth(strokeLineWidthMarker); } else { gc.setLineWidth(strokeWidth); } final Font font = StyleParser.getFontPropertyValue(style); if (font == null) { gc.setFont(Font.font(LabelledMarkerRenderer.DEFAULT_FONT, LabelledMarkerRenderer.DEFAULT_FONT_SIZE)); } else { gc.setFont(font); } final double[] dashPattern = StyleParser.getFloatingDecimalArrayPropertyValue(style, XYChartCss.STROKE_DASH_PATTERN); if (dashPattern == null) { gc.setLineDashes(strokeDashPattern); } else { gc.setLineDashes(dashPattern); } }
Example 2
Source File: DefaultRenderColorScheme.java From chart-fx with Apache License 2.0 | 5 votes |
public static void setGraphicsContextAttributes(final GraphicsContext gc, final String style) { if ((gc == null) || (style == null)) { return; } final Color strokeColor = StyleParser.getColorPropertyValue(style, XYChartCss.STROKE_COLOR); if (strokeColor != null) { gc.setStroke(strokeColor); } final Color fillColor = StyleParser.getColorPropertyValue(style, XYChartCss.FILL_COLOR); if (fillColor != null) { gc.setFill(fillColor); } final Double strokeWidth = StyleParser.getFloatingDecimalPropertyValue(style, XYChartCss.STROKE_WIDTH); if (strokeWidth != null) { gc.setLineWidth(strokeWidth); } final Font font = StyleParser.getFontPropertyValue(style); if (font != null) { gc.setFont(font); } final double[] dashPattern = StyleParser.getFloatingDecimalArrayPropertyValue(style, XYChartCss.STROKE_DASH_PATTERN); if (dashPattern != null) { gc.setLineDashes(dashPattern); } }
Example 3
Source File: DefaultRenderColorScheme.java From chart-fx with Apache License 2.0 | 5 votes |
public static void setLineScheme(final GraphicsContext gc, final String defaultStyle, final int dsIndex) { AssertUtils.gtEqThanZero("setLineScheme dsIndex", dsIndex); final Map<String, List<String>> map = splitQuery(defaultStyle); final Color lineColor = StyleParser.getColorPropertyValue(defaultStyle, XYChartCss.DATASET_STROKE_COLOR); final double[] lineDash = StyleParser.getStrokeDashPropertyValue(defaultStyle, XYChartCss.STROKE_DASH_PATTERN); final Color rawColor = lineColor == null ? getStrokeColor(dsIndex) : lineColor; gc.setLineWidth(defaultStrokeLineWidthProperty().get()); gc.setLineDashes(lineDash); gc.setFill(getFill(dsIndex)); gc.setStroke(getColorModifier(map, rawColor)); }
Example 4
Source File: GridRenderer.java From chart-fx with Apache License 2.0 | 5 votes |
protected static void applyGraphicsStyleFromLineStyle(final GraphicsContext gc, final Line style) { gc.setStroke(style.getStroke()); gc.setLineWidth(style.getStrokeWidth()); if (style.getStrokeDashArray() == null || style.getStrokeDashArray().isEmpty()) { gc.setLineDashes(DEFAULT_GRID_DASH_PATTERM); } else { final double[] dashes = style.getStrokeDashArray().stream().mapToDouble(d -> d).toArray(); gc.setLineDashes(dashes); } }
Example 5
Source File: ToolGraphics.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Strokes 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 pStyle The line style for the path. */ public static void strokeSharpPath(GraphicsContext pGraphics, Path pPath, LineStyle pStyle) { double[] oldDash = pGraphics.getLineDashes(); pGraphics.setLineDashes(pStyle.getLineDashes()); double width = pGraphics.getLineWidth(); pGraphics.setLineWidth(LINE_WIDTH); applyPath(pGraphics, pPath); pGraphics.stroke(); pGraphics.setLineDashes(oldDash); pGraphics.setLineWidth(width); }
Example 6
Source File: GanttDisplay.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
private void draw() { GraphicsContext gc = getGraphicsContext2D(); gc.setFill(Color.WHITE); gc.fillRect(0, 0, getWidth(), getHeight()); Date[] allstartsofday = DateUtils.getAllStartOfDays(startdatedisplaywindow, enddatedisplaywindow, businesscalendar); logger.fine(" |-- treating " + allstartsofday.length + " starts of days"); GanttTaskCell.drawSeparators(gc, startdatedisplaywindow, enddatedisplaywindow, getHeight() / 2, 0, getHeight(), latestCellWidth, businesscalendar, 1); Font font = Font.font(10); gc.setFont(font); gc.setLineDashes(null); gc.setStroke(Color.BLACK); gc.setFill(Color.BLACK); double lasthourx = -50; double lastdayx = -200; for (int i = 0; i < allstartsofday.length; i++) { Date separatortoprint = allstartsofday[i]; double separatorratio = DateUtils.genericDateToCoordinates(separatortoprint, startdatedisplaywindow, enddatedisplaywindow, businesscalendar).getValue(); double xdate = separatorratio * latestCellWidth + 2; if (xdate - lastdayx > 50) { // gc.strokeText(dateformat.format(separatortoprint),xdate, 14); gc.fillText(dateformat.format(separatortoprint), xdate, 14); lastdayx = xdate; } if (!GanttTaskCell.isReducedDisplay(allstartsofday)) for (int j = businesscalendar.getDaywindowhourstart() + 1; j < businesscalendar .getDaywindowhourend(); j++) { Date hour = new Date(separatortoprint.getTime() + (j - businesscalendar.getDaywindowhourstart()) * 3600 * 1000); double hourratio = DateUtils.genericDateToCoordinates(hour, startdatedisplaywindow, enddatedisplaywindow, businesscalendar).getValue(); double x = hourratio * latestCellWidth - 3; if (x - lasthourx > 15) { // gc.strokeText(""+j,x, 28); gc.fillText("" + j, x, 28); lasthourx = x; } } } }
Example 7
Source File: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * Draws horizontal markers with horizontal (default) labels attached to the top * * @param gc the graphics context from the Canvas parent * @param chart instance of the calling chart * @param dataSet instance of the data set that is supposed to be drawn * @param indexMin minimum index of data set to be drawn * @param indexMax maximum index of data set to be drawn */ protected void drawHorizontalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet, final int indexMin, final int indexMax) { final Axis yAxis = this.getFirstAxis(Orientation.VERTICAL, chart); gc.save(); setGraphicsContextAttributes(gc, dataSet.getStyle()); gc.setTextAlign(TextAlignment.RIGHT); final double width = chart.getCanvas().getWidth(); double lastLabel = -Double.MAX_VALUE; double lastFontSize = 0; for (int i = indexMin; i < indexMax; i++) { final double screenY = (int) yAxis.getDisplayPosition(dataSet.get(DataSet.DIM_Y, i)); final String label = dataSet.getDataLabel(i); if (label == null) { continue; } final String pointStyle = dataSet.getStyle(i); if (pointStyle != null) { gc.save(); setGraphicsContextAttributes(gc, pointStyle); } gc.strokeLine(0, screenY, width, screenY); if (Math.abs(screenY - lastLabel) > lastFontSize && !label.isEmpty()) { gc.save(); gc.setLineWidth(0.8); gc.setLineDashes(1.0); gc.translate(Math.ceil(screenY + 3), Math.ceil(0.99 * width)); gc.fillText(label, 0.0, 0); gc.restore(); lastLabel = screenY; lastFontSize = gc.getFont().getSize(); } if (pointStyle != null) { gc.restore(); } } gc.restore(); }
Example 8
Source File: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * Draws vertical markers with vertical (default) labels attached to the top * * @param gc the graphics context from the Canvas parent * @param chart instance of the calling chart * @param dataSet instance of the data set that is supposed to be drawn * @param indexMin minimum index of data set to be drawn * @param indexMax maximum index of data set to be drawn */ protected void drawVerticalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet, final int indexMin, final int indexMax) { Axis xAxis = this.getFirstAxis(Orientation.HORIZONTAL); if (xAxis == null) { xAxis = chart.getFirstAxis(Orientation.HORIZONTAL); } if (xAxis == null) { if (LOGGER.isWarnEnabled()) { LOGGER.atWarn().addArgument(LabelledMarkerRenderer.class.getSimpleName()).log("{}::drawVerticalLabelledMarker(...) getFirstAxis(HORIZONTAL) returned null skip plotting"); } return; } gc.save(); setGraphicsContextAttributes(gc, dataSet.getStyle()); gc.setTextAlign(TextAlignment.LEFT); final double height = chart.getCanvas().getHeight(); double lastLabel = -Double.MAX_VALUE; double lastFontSize = 0; for (int i = indexMin; i < indexMax; i++) { final double screenX = (int) xAxis.getDisplayPosition(dataSet.get(DataSet.DIM_X, i)); final String label = dataSet.getDataLabel(i); if (label == null) { continue; } final String pointStyle = dataSet.getStyle(i); if (pointStyle != null) { gc.save(); setGraphicsContextAttributes(gc, pointStyle); } gc.strokeLine(screenX, 0, screenX, height); if (Math.abs(screenX - lastLabel) > lastFontSize && !label.isEmpty()) { gc.save(); gc.setLineWidth(0.8); gc.setLineDashes(1.0); gc.translate(Math.ceil(screenX + 3), Math.ceil(0.01 * height)); gc.rotate(+90); gc.fillText(label, 0.0, 0); gc.restore(); lastLabel = screenX; lastFontSize = gc.getFont().getSize(); } if (pointStyle != null) { gc.restore(); } } gc.restore(); }
Example 9
Source File: ContourDataSetRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
private void drawContour(final GraphicsContext gc, final ContourDataSetCache lCache) { final double[] levels = new double[getNumberQuantisationLevels()]; for (int i = 0; i < levels.length; i++) { levels[i] = (i + 1) / (double) levels.length; } final int xSize = lCache.xSize; final int ySize = lCache.ySize; final double[][] data = new double[ySize][xSize]; for (int yIndex = 0; yIndex < ySize; yIndex++) { for (int xIndex = 0; xIndex < xSize; xIndex++) { final double offset = lCache.reduced[yIndex * xSize + xIndex]; data[ySize - 1 - yIndex][xIndex] = offset; } } // abort if min/max == 0 -> cannot compute contours final double zRange = Math.abs(lCache.zMax - lCache.zMin); if (zRange <= 0) { return; } final ColorGradient colorGradient = getColorGradient(); final MarchingSquares marchingSquares = new MarchingSquares(); final double scaleX = lCache.xDataPixelRange / xSize; final double scaleY = lCache.yDataPixelRange / ySize; gc.save(); gc.translate(lCache.xDataPixelMin, lCache.yDataPixelMin); gc.scale(scaleX, scaleY); final GeneralPath[] isolines; try { isolines = marchingSquares.buildContours(data, levels); int levelCount = 0; for (final GeneralPath path : isolines) { if (path.size() > getMaxContourSegments()) { levelCount++; continue; } final Color color = lCache.zInverted ? colorGradient.getColor(1 - levels[levelCount++]) : colorGradient.getColor(levels[levelCount++]); gc.setStroke(color); gc.setLineDashes(1.0); gc.setMiterLimit(10); gc.setFill(color); gc.setLineWidth(0.5); path.draw(gc); } } catch (InterruptedException | ExecutionException e) { if (LOGGER.isErrorEnabled()) { LOGGER.atError().setCause(e).log("marchingSquares algorithm"); } } finally { gc.restore(); } }
Example 10
Source File: GridRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
protected void drawPolarGrid(final GraphicsContext gc, XYChart xyChart) { final Axis xAxis = xyChart.getXAxis(); final Axis yAxis = xyChart.getYAxis(); final double xAxisWidth = xyChart.getCanvas().getWidth(); final double yAxisHeight = xyChart.getCanvas().getHeight(); final double xRange = xAxis.getWidth(); final double yRange = yAxis.getHeight(); final double xCentre = xRange / 2; final double yCentre = yRange / 2; final double maxRadius = 0.5 * Math.min(xRange, yRange) * 0.9; if (xAxis instanceof Node) { ((Node) xAxis).setVisible(false); } gc.save(); if (verMajorGridStyleNode.isVisible() || verMinorGridStyleNode.isVisible()) { applyGraphicsStyleFromLineStyle(gc, verMajorGridStyleNode); for (double phi = 0.0; phi <= 360; phi += xyChart.getPolarStepSize().get()) { final double x = xCentre + maxRadius * Math.sin(phi * GridRenderer.DEG_TO_RAD); final double y = yCentre - maxRadius * Math.cos(phi * GridRenderer.DEG_TO_RAD); final double xl = xCentre + maxRadius * Math.sin(phi * GridRenderer.DEG_TO_RAD) * 1.05; final double yl = yCentre - maxRadius * Math.cos(phi * GridRenderer.DEG_TO_RAD) * 1.05; gc.strokeLine(xCentre, yCentre, x, y); gc.save(); gc.setFont(yAxis.getTickLabelFont()); gc.setStroke(yAxis.getTickLabelFill()); gc.setLineDashes(null); gc.setTextBaseline(VPos.CENTER); if (phi < 350) { if (phi < 20) { gc.setTextAlign(TextAlignment.CENTER); } else if (phi <= 160) { gc.setTextAlign(TextAlignment.LEFT); } else if (phi <= 200) { gc.setTextAlign(TextAlignment.CENTER); } else { gc.setTextAlign(TextAlignment.RIGHT); } gc.strokeText(String.valueOf(phi), xl, yl); } gc.restore(); } if (xAxis.isLogAxis() || verMinorGridStyleNode.isVisible()) { applyGraphicsStyleFromLineStyle(gc, verMinorGridStyleNode); xAxis.getMinorTickMarks().stream().mapToDouble(TickMark::getPosition).forEach(xPos -> { if (xPos > 0 && xPos <= xAxisWidth) { gc.strokeLine(xPos, 0, xPos, yAxisHeight); } }); } } drawPolarCircle(gc, yAxis, yRange, xCentre, yCentre, maxRadius); gc.restore(); }
Example 11
Source File: ViewUtils.java From JetUML with GNU General Public License v3.0 | 3 votes |
/** * Draws a line with default attributes and a specified line style. * * @param pGraphics The graphics context. * @param pX1 The x-coordinate of the first point * @param pY1 The y-coordinate of the first point * @param pX2 The x-coordinate of the second point * @param pY2 The y-coordinate of the second point * @param pStyle The line style for the path. */ public static void drawLine(GraphicsContext pGraphics, int pX1, int pY1, int pX2, int pY2, LineStyle pStyle) { double[] oldDash = pGraphics.getLineDashes(); pGraphics.setLineDashes(pStyle.getLineDashes()); pGraphics.strokeLine(pX1 + 0.5, pY1 + 0.5, pX2 + 0.5, pY2 + 0.5); pGraphics.setLineDashes(oldDash); }