Java Code Examples for javafx.scene.canvas.GraphicsContext#setLineWidth()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#setLineWidth() .
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: SubcircuitPeer.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void paint(GraphicsContext graphics, CircuitState circuitState) { GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION)); graphics.setFill(Color.WHITE); GuiUtils.drawShape(graphics::fillRect, this); graphics.setStroke(Color.BLACK); GuiUtils.drawShape(graphics::strokeRect, this); if(mouseEntered) { double width = getScreenWidth(); double height = getScreenHeight(); graphics.setLineWidth(1.5); graphics.strokeOval(getScreenX() + (width - 13) / 2, getScreenY() + (height - 13) / 2, 13, 13); graphics.setLineWidth(2.5); graphics.strokeLine(getScreenX() + width / 2 + 4.6, getScreenY() + height / 2 + 4.6, getScreenX() + width / 2 + 10, getScreenY() + height / 2 + 10); } }
Example 2
Source File: TileMap.java From mcaselector with MIT License | 6 votes |
private void drawChunkGrid(GraphicsContext ctx) { ctx.setLineWidth(Tile.GRID_LINE_WIDTH); ctx.setStroke(Tile.CHUNK_GRID_COLOR.makeJavaFXColor()); Point2f p = getChunkGridMin(offset, scale); Point2f pReg = getRegionGridMin(offset, scale); for (float x = p.getX() + Tile.CHUNK_SIZE / scale; x <= getWidth(); x += Tile.CHUNK_SIZE / scale) { if (showRegionGrid && (int) (pReg.getX() + Tile.SIZE / scale) == (int) x) { pReg.setX(pReg.getX() + Tile.SIZE / scale); continue; } ctx.strokeLine(x, 0, x, getHeight()); } for (float y = p.getY() + Tile.CHUNK_SIZE / scale; y <= getHeight(); y += Tile.CHUNK_SIZE / scale) { if (showRegionGrid && (int) (pReg.getY() + Tile.SIZE / scale) == (int) y) { pReg.setY(pReg.getY() + Tile.SIZE / scale); continue; } ctx.strokeLine(0, y, getWidth(), y); } }
Example 3
Source File: DebugDrawJavaFX.java From jbox2d with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) { Color s = cpool.getColor(color.x, color.y, color.z, 1f); GraphicsContext g = getGraphics(); saveState(g); double[] xs = xDoublePool.get(vertexCount); double[] ys = yDoublePool.get(vertexCount); for (int i = 0; i < vertexCount; i++) { getWorldToScreenToOut(vertices[i], temp); xs[i] = temp.x; ys[i] = temp.y; } g.setLineWidth(stroke); g.setStroke(s); g.strokePolygon(xs, ys, vertexCount); restoreState(g); }
Example 4
Source File: DebugDrawJavaFX.java From jbox2d with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) { GraphicsContext g = getGraphics(); Color f = cpool.getColor(color.x, color.y, color.z, .4f); Color s = cpool.getColor(color.x, color.y, color.z, 1f); saveState(g); double scaling = transformGraphics(g, center) * radius; g.setLineWidth(stroke / scaling); g.scale(radius, radius); g.setFill(f); g.fillOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight()); g.setStroke(s); g.strokeOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight()); if (axis != null) { g.rotate(MathUtils.atan2(axis.y, axis.x)); g.strokeLine(0, 0, 1, 0); } restoreState(g); }
Example 5
Source File: RadialBargraphSkin.java From Enzo with Apache License 2.0 | 5 votes |
private final void drawSections(final GraphicsContext CTX) { final double xy = (size - 0.87 * size) * 0.5; final double wh = size * 0.87; final double MIN_VALUE = getSkinnable().getMinValue(); final double OFFSET = 90 - getSkinnable().getStartAngle(); for (int i = 0 ; i < getSkinnable().getSections().size() ; i++) { final Section SECTION = getSkinnable().getSections().get(i); final double ANGLE_START = (SECTION.getStart() - MIN_VALUE) * angleStep; final double ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep; CTX.save(); switch(i) { case 0: CTX.setStroke(getSkinnable().getSectionFill0()); break; case 1: CTX.setStroke(getSkinnable().getSectionFill1()); break; case 2: CTX.setStroke(getSkinnable().getSectionFill2()); break; case 3: CTX.setStroke(getSkinnable().getSectionFill3()); break; case 4: CTX.setStroke(getSkinnable().getSectionFill4()); break; case 5: CTX.setStroke(getSkinnable().getSectionFill5()); break; case 6: CTX.setStroke(getSkinnable().getSectionFill6()); break; case 7: CTX.setStroke(getSkinnable().getSectionFill7()); break; case 8: CTX.setStroke(getSkinnable().getSectionFill8()); break; case 9: CTX.setStroke(getSkinnable().getSectionFill9()); break; } CTX.setLineWidth(size * 0.1); CTX.setLineCap(StrokeLineCap.BUTT); CTX.strokeArc(xy, xy, wh, wh, -(OFFSET + ANGLE_START), -ANGLE_EXTEND, ArcType.OPEN); CTX.restore(); } }
Example 6
Source File: Example2.java From Introduction-to-JavaFX-for-Game-Development with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void start(Stage theStage) { theStage.setTitle( "Canvas Example" ); Group root = new Group(); Scene theScene = new Scene( root ); theStage.setScene( theScene ); Canvas canvas = new Canvas( 400, 200 ); root.getChildren().add( canvas ); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill( Color.RED ); gc.setStroke( Color.BLACK ); gc.setLineWidth(2); Font theFont = Font.font( "Times New Roman", FontWeight.BOLD, 48 ); gc.setFont( theFont ); gc.fillText( "Hello, World!", 60, 50 ); gc.strokeText( "Hello, World!", 60, 50 ); Image earth = new Image( "earth.png" ); gc.drawImage( earth, 180, 100 ); theStage.show(); }
Example 7
Source File: Hexagon.java From chart-fx with Apache License 2.0 | 5 votes |
public void draw(GraphicsContext gc) { gc.save(); gc.setStroke(getStroke()); gc.setLineWidth(getStrokeWidth()); gc.setFill(getFill()); drawHexagon(gc); gc.restore(); }
Example 8
Source File: DeckView.java From Solitaire with GNU General Public License v2.0 | 5 votes |
private Canvas createNewGameImage() { double width = CardImages.getBack().getWidth(); double height = CardImages.getBack().getHeight(); Canvas canvas = new Canvas( width, height ); GraphicsContext context = canvas.getGraphicsContext2D(); // The reset image context.setStroke(Color.DARKGREEN); context.setLineWidth(IMAGE_NEW_LINE_WIDTH); context.strokeOval(width/4, height/2-width/4 + IMAGE_FONT_SIZE, width/2, width/2); // The text context.setTextAlign(TextAlignment.CENTER); context.setTextBaseline(VPos.CENTER); context.setFill(Color.DARKKHAKI); context.setFont(Font.font(Font.getDefault().getName(), IMAGE_FONT_SIZE)); if( GameModel.instance().isCompleted() ) { context.fillText("You won!", Math.round(width/2), IMAGE_FONT_SIZE); } else { context.fillText("Give up?", Math.round(width/2), IMAGE_FONT_SIZE); } context.setTextAlign(TextAlignment.CENTER); return canvas; }
Example 9
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 10
Source File: GaugeSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { if (getSkinnable().isHistogramEnabled()) { double xy; double wh; double step = 0; double OFFSET = 90 - getSkinnable().getStartAngle(); double ANGLE_EXTEND = (getSkinnable().getMaxValue()) * angleStep; CTX.setStroke(Color.rgb(200, 200, 200)); CTX.setLineWidth(size * 0.001); CTX.setLineCap(StrokeLineCap.BUTT); for (int i = 0 ; i < 5 ; i++) { xy = (size - (0.435 + step) * size) / 2; wh = size * (0.435 + step); CTX.strokeArc(xy, xy, wh, wh, -OFFSET, -ANGLE_EXTEND, ArcType.OPEN); step += 0.075; } } double sinValue; double cosValue; double startAngle = getSkinnable().getStartAngle(); double orthText = Gauge.TickLabelOrientation.ORTHOGONAL == getSkinnable().getTickLabelOrientation() ? 0.33 : 0.31; Point2D center = new Point2D(size * 0.5, size * 0.5); for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep, counter++) { sinValue = Math.sin(Math.toRadians(angle + startAngle)); cosValue = Math.cos(Math.toRadians(angle + startAngle)); Point2D innerMainPoint = new Point2D(center.getX() + size * 0.368 * sinValue, center.getY() + size * 0.368 * cosValue); Point2D innerMediumPoint = new Point2D(center.getX() + size * 0.388 * sinValue, center.getY() + size * 0.388 * cosValue); Point2D innerMinorPoint = new Point2D(center.getX() + size * 0.3975 * sinValue, center.getY() + size * 0.3975 * cosValue); Point2D outerPoint = new Point2D(center.getX() + size * 0.432 * sinValue, center.getY() + size * 0.432 * cosValue); Point2D textPoint = new Point2D(center.getX() + size * orthText * sinValue, center.getY() + size * orthText * cosValue); CTX.setStroke(getSkinnable().getTickMarkFill()); if (counter % getSkinnable().getMajorTickSpace() == 0) { // Draw major tickmark CTX.setLineWidth(size * 0.0055); CTX.strokeLine(innerMainPoint.getX(), innerMainPoint.getY(), outerPoint.getX(), outerPoint.getY()); // Draw text CTX.save(); CTX.translate(textPoint.getX(), textPoint.getY()); switch(getSkinnable().getTickLabelOrientation()) { case ORTHOGONAL: if ((360 - startAngle - angle) % 360 > 90 && (360 - startAngle - angle) % 360 < 270) { CTX.rotate((180 - startAngle - angle) % 360); } else { CTX.rotate((360 - startAngle - angle) % 360); } break; case TANGENT: if ((360 - startAngle - angle - 90) % 360 > 90 && (360 - startAngle - angle - 90) % 360 < 270) { CTX.rotate((90 - startAngle - angle) % 360); } else { CTX.rotate((270 - startAngle - angle) % 360); } break; case HORIZONTAL: default: break; } CTX.setFont(Font.font("Verdana", FontWeight.NORMAL, 0.045 * size)); CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(getSkinnable().getTickLabelFill()); CTX.fillText(Integer.toString((int) counter), 0, 0); CTX.restore(); } else if (getSkinnable().getMinorTickSpace() % 2 != 0 && counter % 5 == 0) { CTX.setLineWidth(size * 0.0035); CTX.strokeLine(innerMediumPoint.getX(), innerMediumPoint.getY(), outerPoint.getX(), outerPoint.getY()); } else if (counter % getSkinnable().getMinorTickSpace() == 0) { CTX.setLineWidth(size * 0.00225); CTX.strokeLine(innerMinorPoint.getX(), innerMinorPoint.getY(), outerPoint.getX(), outerPoint.getY()); } } }
Example 11
Source File: QuarterSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawAreasAndSections(final GraphicsContext CTX) { if (areas.isEmpty() && sections.isEmpty()) return; double value = gauge.getCurrentValue(); Pos knobPosition = gauge.getKnobPosition(); double scaledSize = size * 1.9; double offset = 90 - startAngle; double offsetX; double offsetY; double xy; double wh; int listSize; // Draw Areas if (areasVisible && !areas.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.078 * scaledSize : 0.0125 * scaledSize; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.846 : scaledSize * 0.97; offsetX = Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.475; offsetY = Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.475 : 0; listSize = areas.size(); for (int i = 0 ; i < listSize ; i++) { Section area = areas.get(i); double areaStartAngle; if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) { if (area.getStart() < minValue && area.getStop() < maxValue) { areaStartAngle = 0; } else { areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep; } double areaAngleExtend; if (area.getStop() > maxValue) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep; } else if (Double.compare(area.getStart(), minValue) < 0) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep; } else { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep; } CTX.save(); if (highlightAreas) { CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor()); } else { CTX.setFill(area.getColor()); } CTX.fillArc(xy + offsetX, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND); CTX.restore(); } } } // Draw Sections if (sectionsVisible && !sections.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.11675 * scaledSize : 0.03265 * scaledSize; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.7745 : scaledSize * 0.935; offsetX = TickLabelLocation.OUTSIDE == tickLabelLocation ? ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.0045 : -scaledSize * 0.4770 ) : ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.4738 ); offsetY = TickLabelLocation.OUTSIDE == tickLabelLocation ? ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4770 : -scaledSize * 0.0045 ) : ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4738 : 0 ); listSize = sections.size(); CTX.setLineWidth(scaledSize * 0.04); CTX.setLineCap(StrokeLineCap.BUTT); for (int i = 0; i < listSize; i++) { Section section = sections.get(i); double sectionStartAngle; if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) { if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) { sectionStartAngle = 0; } else { sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep; } double sectionAngleExtend; if (Double.compare(section.getStop(), maxValue) > 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep; } else if (Double.compare(section.getStart(), minValue) < 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep; } else { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep; } CTX.save(); if (highlightSections) { CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor()); } else { CTX.setStroke(section.getColor()); } CTX.strokeArc(xy + offsetX, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } } }
Example 12
Source File: ColorGradientAxis.java From chart-fx with Apache License 2.0 | 4 votes |
@Override protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth, final double axisHeight) { // N.B. axis canvas is (by-design) larger by 'padding' w.r.t. // required/requested axis length (needed for nicer label placements on // border. final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0; final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0; // for relative positioning of axes drawn on top of the main canvas final double axisCentre = getCenterAxisPosition(); final double gradientWidth = getGradientWidth(); // save css-styled line parameters final Path tickStyle = getMajorTickStyle(); gc.save(); gc.setStroke(tickStyle.getStroke()); gc.setLineWidth(tickStyle.getStrokeWidth()); if (getSide().isHorizontal()) { gc.setFill(new LinearGradient(0, 0, axisLength, 0, false, NO_CYCLE, getColorGradient().getStops())); } else { gc.setFill(new LinearGradient(0, axisLength, 0, 0, false, NO_CYCLE, getColorGradient().getStops())); } // N.B. important: translate by padding ie. canvas is +padding larger on // all size compared to region gc.translate(paddingX, paddingY); switch (getSide()) { case LEFT: // axis line on right side of canvas gc.fillRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); gc.strokeRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); break; case RIGHT: // axis line on left side of canvas gc.fillRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); gc.strokeRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); break; case TOP: // line on bottom side of canvas (N.B. (0,0) is top left corner) gc.fillRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); gc.strokeRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); break; case BOTTOM: // line on top side of canvas (N.B. (0,0) is top left corner) gc.rect(snap(0), snap(0), snap(axisLength), snap(gradientWidth)); break; case CENTER_HOR: // axis line at the centre of the canvas gc.fillRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); gc.strokeRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); break; case CENTER_VER: // axis line at the centre of the canvas gc.fillRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); gc.strokeRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); break; default: break; } gc.restore(); }
Example 13
Source File: AbstractAxis.java From chart-fx with Apache License 2.0 | 4 votes |
protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth, final double axisHeight) { // N.B. axis canvas is (by-design) larger by 'padding' w.r.t. // required/requested axis length (needed for nicer label placements on // border. final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0; final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0; // for relative positioning of axes drawn on top of the main canvas final double axisCentre = getCenterAxisPosition(); // save css-styled line parameters final Path tickStyle = getMajorTickStyle(); gc.save(); gc.setStroke(tickStyle.getStroke()); gc.setFill(tickStyle.getFill()); gc.setLineWidth(tickStyle.getStrokeWidth()); // N.B. important: translate by padding ie. canvas is +padding larger on // all size compared to region gc.translate(paddingX, paddingY); switch (getSide()) { case LEFT: // axis line on right side of canvas gc.strokeLine(snap(axisWidth), snap(0), snap(axisWidth), snap(axisLength)); break; case RIGHT: // axis line on left side of canvas gc.strokeLine(snap(0), snap(0), snap(0), snap(axisLength)); break; case TOP: // line on bottom side of canvas (N.B. (0,0) is top left corner) gc.strokeLine(snap(0), snap(axisHeight), snap(axisLength), snap(axisHeight)); break; case BOTTOM: // line on top side of canvas (N.B. (0,0) is top left corner) gc.strokeLine(snap(0), snap(0), snap(axisLength), snap(0)); break; case CENTER_HOR: // axis line at the centre of the canvas gc.strokeLine(snap(0), axisCentre * axisHeight, snap(axisLength), snap(axisCentre * axisHeight)); break; case CENTER_VER: // axis line at the centre of the canvas gc.strokeLine(snap(axisCentre * axisWidth), snap(0), snap(axisCentre * axisWidth), snap(axisLength)); break; default: break; } gc.restore(); }
Example 14
Source File: GanttTaskCell.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
/** * draw all separators in the gantt task cell * * @param gc graphics context * @param startdatedisplaywindow start date (first day) of the display window * @param enddatedisplaywindow end date (last day) of the display window * @param ystarthour start hour of the planning * @param ystartday start day of the planning * @param yend end of the cell in pixel * @param totalwidth total width in pixel * @param businesscalendar business calendar to use for displaying of * opening hours * @param extraxoffset extra offset in the display */ public static void drawSeparators( GraphicsContext gc, Date startdatedisplaywindow, Date enddatedisplaywindow, double ystarthour, double ystartday, double yend, double totalwidth, BusinessCalendar businesscalendar, float extraxoffset) { Date[] separatorstoconsider = DateUtils.getAllStartOfDays(startdatedisplaywindow, enddatedisplaywindow, businesscalendar); boolean isreduceddisplay = isReducedDisplay(separatorstoconsider); for (int i = 0; i < separatorstoconsider.length; i++) { if (isreduceddisplay) { gc.setLineWidth(0.5); gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY); } if (!isreduceddisplay) { gc.setLineWidth(1); gc.setStroke(GanttTaskCell.SCALE_GRAY); } gc.setEffect(null); Date separatortoprint = separatorstoconsider[i]; if (isMonday(separatortoprint)) { gc.setStroke(GanttTaskCell.SCALE_GRAY); if (!isreduceddisplay) gc.setLineWidth(2); if (isreduceddisplay) gc.setLineWidth(1); } double separatorratio = DateUtils.genericDateToCoordinates(separatortoprint, startdatedisplaywindow, enddatedisplaywindow, businesscalendar).getValue(); gc.strokeLine((long) (separatorratio * totalwidth + extraxoffset), (long) ystartday, (long) (separatorratio * totalwidth + extraxoffset), (long) (yend)); if (!isreduceddisplay) if (separatorstoconsider.length < 30) { 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(); gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY); gc.setLineWidth(0.5); gc.setEffect(null); gc.strokeLine((long) (hourratio * totalwidth + extraxoffset), (long) (ystarthour), (long) (hourratio * totalwidth + extraxoffset), (long) (yend)); } } } }
Example 15
Source File: ModernSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { double sinValue; double cosValue; double centerX = size * 0.5; double centerY = size * 0.5; double minorTickSpace = gauge.getMinorTickSpace(); double minValue = gauge.getMinValue(); double maxValue = gauge.getMaxValue(); double tmpAngleStep = angleStep * minorTickSpace; int decimals = gauge.getTickLabelDecimals(); BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace); BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace()); BigDecimal mediumCheck2 = BigDecimal.valueOf(2 * minorTickSpace); BigDecimal mediumCheck5 = BigDecimal.valueOf(5 * minorTickSpace); BigDecimal counterBD = BigDecimal.valueOf(minValue); double counter = minValue; boolean majorTickMarksVisible = gauge.getMajorTickMarksVisible(); boolean mediumTickMarksVisible = gauge.getMediumTickMarksVisible(); boolean tickLabelsVisible = gauge.getTickLabelsVisible(); TickLabelOrientation tickLabelOrientation = gauge.getTickLabelOrientation(); Color tickMarkColor = gauge.getTickMarkColor(); Color majorTickMarkColor = tickMarkColor; Color mediumTickMarkColor = tickMarkColor; Color tickLabelColor = gauge.getTickLabelColor(); double innerPointX; double innerPointY; double outerPointX; double outerPointY; double innerMediumPointX; double innerMediumPointY; double outerMediumPointX; double outerMediumPointY; double textPointX; double textPointY; double orthTextFactor = 0.46; //TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.46 : 0.46; Font tickLabelFont = Fonts.robotoCondensedLight((decimals == 0 ? 0.047 : 0.040) * size); CTX.setFont(tickLabelFont); CTX.setTextAlign(TextAlignment.CENTER); CTX.setTextBaseline(VPos.CENTER); CTX.setLineCap(StrokeLineCap.BUTT); CTX.setLineWidth(size * 0.0035); for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) { sinValue = Math.sin(Math.toRadians(angle + START_ANGLE)); cosValue = Math.cos(Math.toRadians(angle + START_ANGLE)); innerPointX = centerX + size * 0.375 * sinValue; innerPointY = centerY + size * 0.375 * cosValue; outerPointX = centerX + size * 0.425 * sinValue; outerPointY = centerY + size * 0.425 * cosValue; innerMediumPointX = centerX + size * 0.35 * sinValue; innerMediumPointY = centerY + size * 0.35 * cosValue; outerMediumPointX = centerX + size * 0.4 * sinValue; outerMediumPointY = centerY + size * 0.4 * cosValue; textPointX = centerX + size * orthTextFactor * sinValue; textPointY = centerY + size * orthTextFactor * cosValue; // Set the general tickmark color CTX.setStroke(tickMarkColor); if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) { // Draw major tick mark if (majorTickMarksVisible) { CTX.setFill(majorTickMarkColor); CTX.setStroke(majorTickMarkColor); CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY); } // Draw tick label text if (tickLabelsVisible) { CTX.save(); CTX.translate(textPointX, textPointY); Helper.rotateContextForText(CTX, START_ANGLE, angle, tickLabelOrientation); CTX.setFill(tickLabelColor); if (TickLabelOrientation.HORIZONTAL == tickLabelOrientation && (Double.compare(counter, minValue) == 0 || Double.compare(counter, maxValue) == 0)) { CTX.setFill(Color.TRANSPARENT); } CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0); CTX.restore(); } } else if (mediumTickMarksVisible && Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 && Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) { // Draw medium tick mark CTX.setFill(mediumTickMarkColor); CTX.setStroke(mediumTickMarkColor); CTX.strokeLine(innerMediumPointX, innerMediumPointY, outerMediumPointX, outerMediumPointY); } counterBD = counterBD.add(minorTickSpaceBD); counter = counterBD.doubleValue(); } }
Example 16
Source File: CustomPlainAmpSkin.java From medusademo with Apache License 2.0 | 4 votes |
private void drawSections(final GraphicsContext CTX) { final double x = -width * 0.03; final double y = height * 0.345; final double w = width * 1.06; final double h = height * 2.085; final double MIN_VALUE = gauge.getMinValue(); final double MAX_VALUE = gauge.getMaxValue(); final double OFFSET = 90 - START_ANGLE; final ObservableList<Section> sections = gauge.getSections(); final boolean highlightSections = gauge.isHighlightSections(); double value = gauge.getCurrentValue(); int listSize = sections.size(); for (int i = 0 ; i < listSize ; i++) { final Section SECTION = sections.get(i); final double SECTION_START_ANGLE; if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) { if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) { SECTION_START_ANGLE = 0; } else { SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep; } final double SECTION_ANGLE_EXTEND; if (SECTION.getStop() > MAX_VALUE) { SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep; } else { SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep; } CTX.save(); if (highlightSections) { CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor()); } else { CTX.setStroke(SECTION.getColor()); } CTX.setLineWidth(height * 0.0415); CTX.setLineCap(StrokeLineCap.BUTT); CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN); CTX.restore(); } } }
Example 17
Source File: InteractiveGaugeSkin.java From medusademo with Apache License 2.0 | 4 votes |
private void drawAreasAndSections(final GraphicsContext CTX) { if (areas.isEmpty() && sections.isEmpty()) return; double value = getSkinnable().getCurrentValue(); double offset = 90 - startAngle; double xy; double wh; int listSize; // Draw Areas if (areasVisible && !areas.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.0895 * size : 0.025 * size; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.821 : size * 0.95; listSize = areas.size(); for (int i = 0; i < listSize ; i++) { Section area = areas.get(i); double areaStartAngle; if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) { if (area.getStart() < minValue && area.getStop() < maxValue) { areaStartAngle = 0; } else { areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep; } double areaAngleExtend; if (area.getStop() > maxValue) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep; } else if (Double.compare(area.getStart(), minValue) < 0) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep; } else { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep; } CTX.save(); if (highlightAreas) { CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor()); } else { CTX.setFill(area.getColor()); } CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND); CTX.restore(); } } } // Draw Sections if (sectionsVisible && !sections.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.115 * size : 0.0515 * size; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.77 : size * 0.897; listSize = sections.size(); CTX.setLineWidth(size * 0.052); CTX.setLineCap(StrokeLineCap.BUTT); for (int i = 0; i < listSize; i++) { Section section = sections.get(i); double sectionStartAngle; if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) { if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) { sectionStartAngle = 0; } else { sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep; } double sectionAngleExtend; if (Double.compare(section.getStop(), maxValue) > 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep; } else if (Double.compare(section.getStart(), minValue) < 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep; } else { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep; } CTX.save(); if (highlightSections) { CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor()); } else { CTX.setStroke(section.getColor()); } CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } } }
Example 18
Source File: DebugDrawJavaFX.java From jbox2d with BSD 2-Clause "Simplified" License | 4 votes |
private void restoreState(GraphicsContext g) { g.setTransform(oldTrans); g.setLineWidth(oldStroke); }
Example 19
Source File: HSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawAreasAndSections(final GraphicsContext CTX) { if (areas.isEmpty() && sections.isEmpty()) return; double value = gauge.getCurrentValue(); double scaledWidth = width * 0.9; double offset = 90 - startAngle; double offsetY = -0.1 * height; double xy; double wh; int listSize; // Draw areas if (areasVisible && !areas.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1445 * scaledWidth : 0.081 * scaledWidth; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.821 : scaledWidth * 0.9505; listSize = areas.size(); for (int i = 0 ; i < listSize ; i++) { Section area = areas.get(i); double areaStartAngle; if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) { if (area.getStart() < minValue && area.getStop() < maxValue) { areaStartAngle = 0; } else { areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep; } double areaAngleExtend; if (area.getStop() > maxValue) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep; } else if (Double.compare(area.getStart(), minValue) < 0) { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep; } else { areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep; } CTX.save(); if (highlightAreas) { CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor()); } else { CTX.setFill(area.getColor()); } CTX.fillArc(xy, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND); CTX.restore(); } } } // Draw sections if (sectionsVisible && !sections.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1705 * scaledWidth : 0.107 * scaledWidth; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.77 : scaledWidth * 0.897; listSize = sections.size(); CTX.setLineWidth(scaledWidth * 0.052); CTX.setLineCap(StrokeLineCap.BUTT); for (int i = 0; i < listSize; i++) { Section section = sections.get(i); double sectionStartAngle; if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) { if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) { sectionStartAngle = 0; } else { sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep; } double sectionAngleExtend; if (Double.compare(section.getStop(), maxValue) > 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep; } else if (Double.compare(section.getStart(), minValue) < 0) { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep; } else { sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep; } CTX.save(); if (highlightSections) { CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor()); } else { CTX.setStroke(section.getColor()); } CTX.strokeArc(xy, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } } }
Example 20
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(); }