/** * Draw little time box to indicate exactly the date time when * showMouseHoverIndicator is on */ public void drawTimeBox() { if (showMouseHoverIndicator.getValue()){ double x = mouseX.getValue(); double w = 45; x = x - w; double wd = 2 * w; double hi = 20; Calendar curDate = getDayByXPos(mouseX.getValue()); if (curDate != null) { SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); String strDateLabel = sf.format(curDate.getTime()); GraphicsContext gc = getGraphicsContext2D(); gc.setFill(Color.web("#010a23")); gc.fillRect(x, 0, wd, hi); gc.setFill(Color.web("#4bf221")); gc.fillText(strDateLabel, x+14, 14); } } }
/** * Paint a black/white stone onto a graphics context with a grid * @param gc Graphics context * @param startX Start (top left) x coordinate of the grid * @param startY Start (top left) y coordinate of the grid * @param cellSize Size of the grid cells * @param row Row position of the stone * @param col Column position of the stone * @param index Index of the stone (1 = black, 2 = white) * @param transparent Transparency value, 0.5 alpha if true */ private static void paintStone(GraphicsContext gc, double startX, double startY, double cellSize, int row, int col, int index, boolean transparent) { double x = startX + col*cellSize; double y = startY + row*cellSize; double offset = (cellSize * 0.7) / 2; gc.save(); if(transparent) { gc.setGlobalAlpha(0.5); } switch(index) { case 1: gc.setFill(blackGradient); gc.fillOval(x - offset, y - offset, cellSize * 0.7, cellSize * 0.7); break; case 2: gc.setFill(whiteGradient); gc.fillOval(x - offset, y - offset, cellSize * 0.7, cellSize * 0.7); break; } gc.restore(); }
@Override public void drawYValueBox() { if (showMouseHoverIndicator.getValue()){ double y = mouseY.getValue(); y = y - 10; double x = 0; double wd = 150; double ht = 18; if (mouseY == null) { return; } int yIntPos = (int)Math.round(mouseY.getValue()); Float yValue = this.getValueByYPos(yIntPos); if ( yValue != null && yValue != 0){ String strVolume = String.format("%.2f", yValue); GraphicsContext gc = getGraphicsContext2D(); gc.setFill(Color.web("#010a23")); gc.fillRect(x, y, wd, ht); gc.setFill(Color.web("#4bf221")); gc.fillText(strVolume, x + 13, y+13); } } }
/** * Instantiates a new Train view. * * @param graphicsContext the graphics context */ public TrainView(GraphicsContext graphicsContext) { this.graphicsContext = graphicsContext; try { trainCarts = new HashMap<>(); for (String color: model.util.Color.getValidColors()) { try (FileInputStream fi = new FileInputStream("sprites/cart_" + color + ".png")) { trainCarts.put(color, new Image(fi)); } } trainParts = new HashMap<>(); for (String type: trainPartTypes) { try (FileInputStream fi = new FileInputStream("sprites/" + type + ".png")) { trainParts.put(type, new Image(fi)); } } } catch (IOException e) { System.err.println("TrainView.TrainView(): File error: " + e.getMessage()); } }
/** * Constructs {@link NodeTooltip}. * * @param graphicsContext the context * @param node the node * @param middleX the middle x position of the node * @param belowY the below y position of the node */ public NodeTooltip(final GraphVisualizer graphVisualizer, final GraphicsContext graphicsContext, final GfaNode node, final double middleX, final double belowY) { int tempHeight = DEFAULT_HEIGHT; this.graphVisualizer = graphVisualizer; this.graphicsContext = graphicsContext; this.node = node; this.middleX = middleX; this.belowY = belowY; if (node.hasMetadata()) { tempHeight += Math.min(node.getMetadata().getGenomes().size(), MAX_GENOME_COUNT + 1) * LINE_HEIGHT + 10; } if (node.getSegments().get(0).getSequenceLength() > MAX_SEQUENCE_LENGTH) { tempHeight += LINE_HEIGHT * 1.5; } this.height = tempHeight; }
private void drawFireworks(GraphicsContext gc) { Iterator<Particle> iter = particles.iterator(); List<Particle> newParticles = new ArrayList<Particle>(); while(iter.hasNext()) { Particle firework = iter.next(); // if the update returns true then particle has expired if(firework.update()) { // remove particle from those drawn iter.remove(); // check if it should be exploded if(firework.shouldExplodeChildren) { if(firework.size == 9) { explodeCircle(firework, newParticles); } else if(firework.size == 8) { explodeSmallCircle(firework, newParticles); } } } firework.draw(gc); } particles.addAll(newParticles); }
public void draw(GraphicsContext context) { final double x = Math.round(posX); final double y = Math.round(posY); final double xVel = (x - lastPosX) * -5; final double yVel = (y - lastPosY) * -5; // set the opacity for all drawing of this particle context.setGlobalAlpha(Math.random() * this.alpha); // draw particle context.setFill(color); context.fillOval(x-size, y-size, size+size, size+size); // draw the arrow triangle from where we were to where we are now if (hasTail) { context.setFill(Color.rgb(255,255,255,0.3)); context.fillPolygon(new double[]{posX + 1.5,posX + xVel,posX - 1.5}, new double[]{posY,posY + yVel,posY}, 3); } }
public NodeView(GraphicsContext graphicsContext) { this.graphicsContext = graphicsContext; graphicsContext.setLineWidth(12); try { spriteNodes = new HashMap<>(); for (String type: nodeTypes) { try (FileInputStream fi = new FileInputStream("sprites/" + type + ".png")) { spriteNodes.put(type, new Image(fi)); } } spriteStations=new HashMap<>(); spriteLoaderStations=new HashMap<>(); for (String color: model.util.Color.getValidColors()) { try (FileInputStream fi = new FileInputStream("sprites/station_" + color + ".png")) { spriteStations.put(color, new Image(fi)); } try (FileInputStream fi = new FileInputStream("sprites/loader_" + color + ".png")) { spriteLoaderStations.put(color, new Image(fi)); } } } catch (IOException e) { System.err.println("NodeView.NodeView: File error: " + e.getMessage()); } }
public void render(GraphicsContext gc) { currentFrame++; if(currentFrame/frameRepeat >= frameCount) { currentFrame = 0; } gc.drawImage ( source, (int)(currentFrame/frameRepeat)*sourceWidth, 0, sourceWidth, sourceHeight, x - (width/2), y - (height/2), width, height ); }
@Override public void drawTextTick(double x, double y, double value) { GraphicsContext gc = getGraphicsContext2D(); double bigTickLength = 10; //Big Tick //Draw ticks and draw texts gc.setLineWidth(0.1); gc.setStroke(ChartTickColorProperty.getValue()); gc.strokeLine(x, y, x + bigTickLength, y); String strValue = ""; if (value >= 0 && value <= 0.01) { strValue = String.format("%.4f", value); } else if (value > 0.01 && value <= 0.1) { strValue = String.format("%.3f", value); } else if (value > 0.1 && value <= 1.0) { strValue = String.format("%.3f", value); } else if (value > 1.0 && value <= 10.0) { strValue = String.format("%.2f", value); } else { strValue = String.format("%.2f", value); } gc.setFill(ChartTickColorProperty.getValue()); gc.fillText(strValue, x + bigTickLength + 3, y + 5); }
@Override public void initialize(URL location, ResourceBundle resources) { LOG.info("Loading map data."); worldMapCanvas.setOnDragDetected(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { LOG.info("Drag detected."); } }); worldMapCanvas.setOnMouseClicked(event -> { LOG.info("Click detected."); }); // Testing final GraphicsContext gc = worldMapCanvas.getGraphicsContext2D(); gc.setFill(Color.AZURE); gc.fillRect(0, 0, worldMapCanvas.getWidth(), worldMapCanvas.getHeight()); gc.setFill(Color.GREEN); gc.strokeLine(40, 10, 10, 40); }
private void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double TEXT_ANGLE, final TickLabelOrientation ORIENTATION) { switch (ORIENTATION) { case ORTHOGONAL: if ((360 - START_ANGLE - TEXT_ANGLE) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE) % 360 < 270) { CTX.rotate((180 - START_ANGLE - TEXT_ANGLE) % 360); } else { CTX.rotate((360 - START_ANGLE - TEXT_ANGLE) % 360); } break; case TANGENT: if ((360 - START_ANGLE - TEXT_ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE - 90) % 360 < 270) { CTX.rotate((90 - START_ANGLE - TEXT_ANGLE) % 360); } else { CTX.rotate((270 - START_ANGLE - TEXT_ANGLE) % 360); } break; case HORIZONTAL: default: break; } }
public void render(int indexX, int indexY, GraphicsContext gc) { if (this == STANDARD) { gc.setFill(Color.valueOf("#debf89")); gc.fillRoundRect(indexX * 64, indexY * 64, 64, 64, 10, 10); } if (this == CORK) { gc.setFill(Color.valueOf("#debf89").brighter().brighter()); gc.fillRoundRect(indexX * 64, indexY * 64, 64, 64, 10, 10); } if (this == HOLE) { gc.setFill(Color.GRAY.brighter()); gc.fillOval(indexX * 64, indexY * 64, 64, 64); } }
/** * 设置图形节点为选中样式 */ @Override public void drawConner() { canvas.setMouseTransparent(true); isConnerShow = true; GraphicsContext gc = canvas.getGraphicsContext2D(); double whiteR = 12; double blueR = 10; if (x1 != null) { double X = x.doubleValue(); double Y = y.doubleValue(); gc.setFill(Color.WHITE); gc.fillOval(x1.doubleValue() -6+ X, y1.doubleValue() -6+ Y, whiteR, whiteR); gc.fillOval(x2.doubleValue() - 6+ X, y2.doubleValue() - 6 + Y, whiteR, whiteR); gc.setFill(Color.color(0.03, 0.43, 0.81)); gc.fillOval(x1.doubleValue() -5 + X, y1.doubleValue() -5 + Y, blueR, blueR); gc.fillOval(x2.doubleValue()-5+ X, y2.doubleValue() - 5 + Y, blueR, blueR); } }
public void drawGrid() { GraphicsContext gc = drawingCanvas.getGraphicsContext2D(); // Task: draw a grid paper with horizontal lines 20 pixels apart // and the vertical lines 20 pixels apart, as well double width = drawingCanvas.getWidth(); double height = drawingCanvas.getHeight(); gc.setStroke(Color.RED); for (int x = 0; x <= width; x += 20) gc.strokeLine(x, 0, x, height); for (int y = 0; y <= height; y += 20) gc.strokeLine(0, y, width, y); gc.setStroke(Color.BLUE); for (int x = 0; x <= width; x += 100) gc.strokeLine(x, 0, x, height); for (int y = 0; y <= height; y += 100) gc.strokeLine(0, y, width, y); }
private static void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) { double x = BOUNDS.getX(); double y = BOUNDS.getY(); double width = BOUNDS.getWidth(); double height = BOUNDS.getHeight(); double xPlusWidth = x + width; double yPlusHeight = y + height; CTX.beginPath(); CTX.moveTo(x + RADII.getTopRight(), y); CTX.lineTo(xPlusWidth - RADII.getTopRight(), y); CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight()); CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight()); CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight); CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight); CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft()); CTX.lineTo(x, y + RADII.getTopRight()); CTX.quadraticCurveTo(x, y, x + RADII.getTopRight(), y); CTX.closePath(); }
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) { double x = BOUNDS.getX(); double y = BOUNDS.getY(); double width = BOUNDS.getWidth(); double height = BOUNDS.getHeight(); double xPlusWidth = x + width; double yPlusHeight = y + height; CTX.beginPath(); CTX.moveTo(x + RADII.getTopLeft(), y); CTX.lineTo(xPlusWidth - RADII.getTopRight(), y); CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight()); CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight()); CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight); CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight); CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft()); CTX.lineTo(x, y + RADII.getTopLeft()); CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y); CTX.closePath(); }
/** * Draws the content of the canvas and updates the * {@code renderingInfo} attribute with the latest rendering * information. */ public final void draw() { GraphicsContext ctx = getGraphicsContext2D(); ctx.save(); double width = getWidth(); double height = getHeight(); if (width > 0 && height > 0) { ctx.clearRect(0, 0, width, height); this.info = new ChartRenderingInfo(); if (this.chart != null) { this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info); } } ctx.restore(); for (OverlayFX overlay : this.overlays) { overlay.paintOverlay(g2, this); } this.anchor = null; }
private void initDraw(GraphicsContext gc) { double canvasWidth = gc.getCanvas().getWidth(); double canvasHeight = gc.getCanvas().getHeight(); log.info("canvasWidth = {}, canvasHeight = {}", canvasWidth, canvasHeight); gc.clearRect(0, 0, canvasWidth, canvasHeight); gc.setStroke(borderRectangleColor); gc.setLineWidth(5); gc.strokeRect(0, // x of the upper left corner 0, // y of the upper left corner canvasWidth, // width of the rectangle canvasHeight); // height of the rectangle gc.setFill(Color.RED); gc.setStroke(Color.BLUE); gc.setLineWidth(drawLineWidth); }
@Override public void draw(DungeonTileRenderer renderer, GraphicsContext g) { RAND.setSeed((long)(renderer.posX * 17 + renderer.posY)); double ds = MAX_BORDER - MIN_BORDER; double dx = RAND.nextDouble() * ds + MIN_BORDER; double dy = RAND.nextDouble() * ds + MIN_BORDER; double dw = RAND.nextDouble() * ds + MIN_BORDER; double dh = RAND.nextDouble() * ds + MIN_BORDER; drawBlock(renderer, g, this.chestPaint, dx, dy, 1 - dx - dw, 1 - dy - dh); if (this.outlinePaint != null) { g.setStroke(this.outlinePaint); } g.setLineWidth(OUTLINE_WIDTH); g.strokeRect(dx, dy, 1 - dx - dw, 1 - dy - dh); }
protected static void drawConnectedBlock(DungeonTileRenderer renderer, GraphicsContext g, Paint p, double border) { if (p == null) p = getRegionalPaint(renderer.region); g.setFill(p); g.fillRect(0, 0, 1, 1); byte direction = renderer.direction; if (border > 0 && direction != 15) { boolean east = (direction & 1) != 0; boolean north = (direction & 2) != 0; boolean west = (direction & 4) != 0; boolean south = (direction & 8) != 0; if (!east) g.clearRect(1 - border, 0, border, 1); if (!north) g.clearRect(0, 0, 1, border); if (!west) g.clearRect(0, 0, border, 1); if (!south) g.clearRect(0, 1 - border, 1, border); } }
public void render(GraphicsContext g) { g.setFill(COLOR_BACKGROUND); g.fillRect(this.x, this.y, this.width, this.height); g.setLineWidth(this.enabled ? OUTLINE_LINE_WIDTH : INACTIVE_LINE_WIDTH); g.setStroke(this.outline); g.strokeRoundRect(this.x, this.y, this.width, this.height, OUTLINE_ROUND_RADIUS, OUTLINE_ROUND_RADIUS); this.onRender(g); if (!this.enabled) { g.setFill(COLOR_DISABLED_OVERLAY); g.fillRoundRect(this.x, this.y, this.width, this.height, OUTLINE_ROUND_RADIUS, OUTLINE_ROUND_RADIUS); } }
private void drawStone(DrawCoords position, StoneColour colour, double radius) { GraphicsContext context = getGraphicsContext(); if ( colour == BLACK ) context.setFill(javafx.scene.paint.Paint.valueOf("#000000")); else context.setFill(Paint.valueOf("#FFFFFF")); drawCircle(position, radius); }
/** * Draw mouse hover indicator */ public void drawVIndicator() { if (showMouseHoverIndicator.getValue()) { double height = getHeight(); GraphicsContext gc = getGraphicsContext2D(); gc.setLineWidth(0.1); gc.setStroke(CrossIndicatorLineColorProperty.getValue()); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); gc.strokeLine(mouseX.getValue(), 0, mouseX.getValue(), height); Calendar current = myTimeLine.getDayByXPos(mouseX.getValue()); if(current!=null){ currentCalendar.setValue(current); OHLC ohlc = getOHLCByDate(current); if (ohlc != null){ openProperty.setValue(ohlc.getOpen()); highProperty.setValue(ohlc.getHigh()); lowProperty.setValue(ohlc.getLow()); closeProperty.setValue(ohlc.getClose()); volumeProperty.setValue(ohlc.getVolume()); } } } }
/** * Add a grid to the canvas, send it to the back */ public void addGrid() { double w = getBoundsInLocal().getWidth(); double h = getBoundsInLocal().getHeight(); // add grid Canvas grid = new Canvas(w, h); // don't catch mouse events grid.setMouseTransparent(true); GraphicsContext gc = grid.getGraphicsContext2D(); gc.setStroke(Color.GRAY); gc.setLineWidth(1); // draw grid lines double offset = 50; for (double i = offset; i < w; i += offset) { gc.strokeLine(i, 0, i, h); gc.strokeLine(0, i, w, i); } getChildren().add(grid); grid.toBack(); }
@Override public void drawNormalTick(double x, double y) { GraphicsContext gc = getGraphicsContext2D(); double tickLength = 5; //Small Tick //Draw ticks and draw texts gc.setLineWidth(0.1); gc.setStroke(ChartTickColorProperty.getValue()); gc.strokeLine(x, y, x + tickLength, y); }
public void drawGhostStones(Collection<Coords> stones, StoneColour colour) { GraphicsContext context = getGraphicsContext(); context.setGlobalAlpha(0.5); drawStones(stones, colour); context.setGlobalAlpha(1); }
private void displayMassStationsForReview() { int heightOfMassPlot = 150; // plotting mass variations // only show those with auto-centering on with count_time_sec > 0 in the run table at the mas station int widthOfView = squidProject.getPrawnFileRuns().size() * 25 + 350; scrolledAnchorPane.setPrefWidth(widthOfView + 150); int massCounter = 0; Map<Integer, MassStationDetail> mapOfIndexToMassStationDetails = PrawnFileUtilities.createMapOfIndexToMassStationDetails(squidProject.getPrawnFileRuns()); for (Map.Entry<Integer, MassStationDetail> entry : mapOfIndexToMassStationDetails.entrySet()) { if (entry.getValue().autoCentered()) { AbstractDataView canvas = new MassStationAuditViewForShrimp(new Rectangle(25, (massCounter * heightOfMassPlot) + 25, widthOfView, heightOfMassPlot), entry.getValue().getMassStationLabel(), entry.getValue().getMeasuredTrimMasses(), entry.getValue().getTimesOfMeasuredTrimMasses(), entry.getValue().getIndicesOfScansAtMeasurementTimes(), entry.getValue().getIndicesOfRunsAtMeasurementTimes()); scrolledAnchorPane.getChildren().add(canvas); GraphicsContext gc1 = canvas.getGraphicsContext2D(); canvas.preparePanel(); canvas.paint(gc1); massCounter++; } } scrolledAnchorPane.setPrefHeight((massCounter * heightOfMassPlot) + 50); }
@Override public void beforeEach() { segmentDrawingToolkit = new SegmentDrawingToolkit(); graphicsContext = mock(GraphicsContext.class); segmentDrawingToolkit.setGraphicsContext(graphicsContext); }
public void draw() { drawGrid(); GraphicsContext gc = drawingCanvas.getGraphicsContext2D(); gc.setStroke(Color.BLACK); gc.setLineWidth(5); plotFunction(); // Hometasks: // 1. Draw a circle right at the center with radius of 150 pixels // 2. Draw 20 concentric circles in the top left box // 3. Draw a sun (circle + rays) // 4. Draw a regular n-gon (like pentagon) }
@Override public void drawTextTick(double x, double y, double value) { GraphicsContext gc = getGraphicsContext2D(); double bigTickLength = 10; //Big Tick //Draw ticks and draw texts gc.setLineWidth(0.1); gc.setStroke(ChartTickColorProperty.getValue()); gc.strokeLine(x, y, x + bigTickLength, y); String strValue = ""; if (value >= 0 && value <= 0.01) { strValue = String.format("%.4f m", value); } else if (value > 0.01 && value <= 0.1) { strValue = String.format("%.3f m", value); } else if (value > 0.1 && value <= 1.0) { strValue = String.format("%.3f m", value); } else if (value > 1.0 && value <= 10.0) { strValue = String.format("%.2f m", value); } else { strValue = String.format("%.2f m", value); } gc.setFill(ChartTickColorProperty.getValue()); gc.fillText(strValue, x + bigTickLength + 3, y + 5); }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Drawing Operations Test"); Group root = new Group(); Canvas canvas = new Canvas(300, 250); GraphicsContext gc = canvas.getGraphicsContext2D(); drawShapes(gc); root.getChildren().add(canvas); primaryStage.setScene(new Scene(root)); primaryStage.show(); }
@FXML private void handleMouseClick(MouseEvent event) { double x = event.getX(); double y = event.getY(); GraphicsContext gc = drawingCanvas.getGraphicsContext2D(); gc.strokeLine(0, 0, x, y); System.out.printf("User clicked at (%.2f, %.2f)\n", x, y); }
/** * Draw text tick * @param x POS * @param y POS * @param value - the text to be drawn */ @Override public void drawTextTick(double x, double y, double value) { GraphicsContext gc = getGraphicsContext2D(); double bigTickLength = 10; //Big Tick //Draw ticks and draw texts gc.setLineWidth(0.1); gc.setStroke(ChartTickColorProperty.getValue()); gc.strokeLine(x, y, x + bigTickLength, y); String strValue = ""; if (value >= 0 && value <= 0.01) { strValue = String.format("%.4f", value); } else if (value > 0.01 && value <= 0.1) { strValue = String.format("%.3f", value); } else if (value > 0.1 && value <= 1.0) { strValue = String.format("%.3f", value); } else if (value > 1.0 && value <= 10.0) { strValue = String.format("%.2f", value); } else { strValue = String.format("%.2f", value); } gc.setFill(ChartTickColorProperty.getValue()); gc.fillText(strValue, x + bigTickLength + 3, y + 5); }
public void showPaint(Paint paint) { GraphicsContext graphics = canvas.getGraphicsContext2D(); graphics.clearRect(0, 0, width, height); // graphics.setStroke(Color.BLACK); // graphics.setLineWidth(line); // graphics.strokeRect(line / 2, line / 2, width + line, height + line); graphics.setFill(paint); graphics.fillRect(0, 0, width, height); contentPane.getChildren().setAll(canvas); showPopup(); }