Java Code Examples for javafx.scene.canvas.Canvas#getGraphicsContext2D()

The following examples show how to use javafx.scene.canvas.Canvas#getGraphicsContext2D() . 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: PixelMatrix.java    From charts with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    // prefill matrix with pixelOffColor
    for (int y = 0 ; y < rows ; y++) {
        for (int x = 0 ; x < cols ; x++) {
            matrix[x][y] = pixelOffColor;
        }
    }

    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(preferredWidth, preferredHeight);
        }
    }

    canvas = new Canvas(preferredWidth, preferredHeight);
    ctx = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
Example 2
Source File: DrawingApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(800, 600);

    Canvas canvas = new Canvas(800, 600);
    g = canvas.getGraphicsContext2D();

    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            t += 0.017;
            draw();
        }
    };
    timer.start();

    root.getChildren().add(canvas);
    return root;
}
 
Example 3
Source File: SunburstChart.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    segmentPane = new Pane();

    chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    chartCanvas.setMouseTransparent(true);

    chartCtx    = chartCanvas.getGraphicsContext2D();

    pane = new Pane(segmentPane, chartCanvas);
    pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
    pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));

    getChildren().setAll(pane);

    prepareData();
}
 
Example 4
Source File: PixelMatrix.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void initGraphics() {
    // prefill matrix with pixelOffColor
    for (int y = 0 ; y < rows ; y++) {
        for (int x = 0 ; x < cols ; x++) {
            matrix[x][y] = pixelOffColor;
        }
    }

    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(preferredWidth, preferredHeight);
        }
    }

    canvas = new Canvas(preferredWidth, preferredHeight);
    ctx = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
    canvas.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
}
 
Example 5
Source File: Grid.java    From charts with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctx    = canvas.getGraphicsContext2D();

    pane   = new Pane(canvas);

    getChildren().setAll(pane);
}
 
Example 6
Source File: YOLOApp.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private Parent buildCenterPane() {
	Canvas canvas = new Canvas(yoloModel.getInputWidth(), yoloModel.getInputHeight());
	Parent spCanvas = ZoomPane.createZoomPane(new Group(canvas));
	ctx = canvas.getGraphicsContext2D();
	ctx.setTextAlign(TextAlignment.CENTER);
	ctx.fillText("Loading the model. This may take a while...", canvas.getWidth() / 2, canvas.getHeight() / 2);
	return spCanvas;
}
 
Example 7
Source File: DragAndDropHandler.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected static Image createDragImage(FxDockPane client)
{
	SnapshotParameters sp = new SnapshotParameters();
	sp.setFill(Color.TRANSPARENT);
	
	WritableImage im = client.snapshot(sp, null);

	if(client.isPaneMode())
	{
		return im;
	}
	
	// include selected tab
	FxDockTabPane tp = (FxDockTabPane)DockTools.getParent(client);
	Node n = tp.lookup(".tab:selected");
	WritableImage tim = n.snapshot(sp, null);
	
	double dy = tim.getHeight();
	
	// must adjust for the tab
	deltay += dy;
	
	double w = Math.max(im.getWidth(), tim.getWidth());
	double h = im.getHeight() + dy;
	Canvas c = new Canvas(w, h);
	GraphicsContext g = c.getGraphicsContext2D();
	g.drawImage(tim, 0, 0);
	g.drawImage(im, 0, dy);
	return c.snapshot(sp, null);
}
 
Example 8
Source File: ShipImage.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 補給ゲージ(燃料・弾薬)を取得します
 *
 * @param ship 艦娘
 * @return 補給ゲージ
 */
static Image getSupplyGauge(Ship ship) {
    Canvas canvas = new Canvas(36, 12);
    GraphicsContext gc = canvas.getGraphicsContext2D();

    Optional<ShipMst> mstOpt = Ships.shipMst(ship);
    if (mstOpt.isPresent()) {
        double width = canvas.getWidth();

        ShipMst mst = mstOpt.get();
        double fuelPer = (double) ship.getFuel() / (double) mst.getFuelMax();
        double ammoPer = (double) ship.getBull() / (double) mst.getBullMax();

        gc.setFill(Color.GRAY);
        gc.fillRect(0, 3, width, 2);

        gc.setFill(Color.GRAY);
        gc.fillRect(0, 10, width, 2);

        Color fuelColor = fuelPer >= 0.5D ? Color.GREEN : fuelPer >= 0.4D ? Color.ORANGE : Color.RED;
        Color ammoColor = ammoPer >= 0.5D ? Color.SADDLEBROWN : ammoPer >= 0.4D ? Color.ORANGE : Color.RED;

        gc.setFill(fuelColor);
        gc.fillRect(0, 0, width * fuelPer, 4);

        gc.setFill(ammoColor);
        gc.fillRect(0, 7, width * ammoPer, 4);
    }
    SnapshotParameters sp = new SnapshotParameters();
    sp.setFill(Color.TRANSPARENT);

    return canvas.snapshot(sp, null);
}
 
Example 9
Source File: CallEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Canvas createIcon(Edge pEdge)
{
	final float scale = 0.6f;
	final int offset = 15;
	Canvas canvas = new Canvas(BUTTON_SIZE, BUTTON_SIZE);
	GraphicsContext graphics = canvas.getGraphicsContext2D();
	canvas.getGraphicsContext2D().scale(scale, scale);
	Path path = new Path();
	path.getElements().addAll(new MoveTo(1, offset), new LineTo(BUTTON_SIZE*(1/scale)-1, offset));
	ToolGraphics.strokeSharpPath(graphics, path, LineStyle.SOLID);
	ArrowHead.V.view().draw(graphics, new Point(1, offset), new Point((int)(BUTTON_SIZE*(1/scale)-1), offset));
	return canvas;
}
 
Example 10
Source File: CycleStepTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    canvas = new Canvas();
    ctx    = canvas.getGraphicsContext2D();

    getChildren().setAll(canvas);
}
 
Example 11
Source File: FlipTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    timeline              = new Timeline();
    characters            = tile.getCharacterList();
    currentSelectionIndex = 0;
    nextSelectionIndex    = 1;

    centerX    = PREFERRED_WIDTH * 0.5;
    centerY    = PREFERRED_HEIGHT * 0.5;

    pane.setBackground(null);
    pane.setBorder(null);

    rotateFlap = new Rotate();
    rotateFlap.setAxis(Rotate.X_AXIS);
    rotateFlap.setAngle(0);

    flapHeight = PREFERRED_HEIGHT * 0.495;

    upperBackground    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    upperBackgroundCtx = upperBackground.getGraphicsContext2D();

    upperBackgroundText    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    upperBackgroundTextCtx = upperBackgroundText.getGraphicsContext2D();
    upperBackgroundTextCtx.setTextBaseline(VPos.CENTER);
    upperBackgroundTextCtx.setTextAlign(TextAlignment.CENTER);

    lowerBackground    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    lowerBackgroundCtx = lowerBackground.getGraphicsContext2D();

    lowerBackgroundText    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    lowerBackgroundTextCtx = lowerBackgroundText.getGraphicsContext2D();
    lowerBackgroundTextCtx.setTextBaseline(VPos.CENTER);
    lowerBackgroundTextCtx.setTextAlign(TextAlignment.CENTER);

    flap = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    flap.getTransforms().add(rotateFlap);
    flapCtx = flap.getGraphicsContext2D();

    flapTextFront = new Canvas();
    flapTextFront.getTransforms().add(rotateFlap);
    flapTextFrontCtx = flapTextFront.getGraphicsContext2D();
    flapTextFrontCtx.setTextBaseline(VPos.CENTER);
    flapTextFrontCtx.setTextAlign(TextAlignment.CENTER);

    flapTextBack  = new Canvas();
    flapTextBack.getTransforms().add(rotateFlap);
    flapTextBack.setOpacity(0);
    flapTextBackCtx = flapTextBack.getGraphicsContext2D();
    flapTextBackCtx.setTextBaseline(VPos.CENTER);
    flapTextBackCtx.setTextAlign(TextAlignment.CENTER);

    pane.getChildren().addAll(upperBackground,
                              lowerBackground,
                              upperBackgroundText,
                              lowerBackgroundText,
                              flap,
                              flapTextFront,
                              flapTextBack);
}
 
Example 12
Source File: ClockSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    // Set initial size
    if (Double.compare(getSkinnable().getPrefWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getSkinnable().getWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getHeight(), 0.0) <= 0) {
        if (getSkinnable().getPrefWidth() > 0 && getSkinnable().getPrefHeight() > 0) {
            getSkinnable().setPrefSize(getSkinnable().getPrefWidth(), getSkinnable().getPrefHeight());
        } else {
            getSkinnable().setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsAndAreasCtx    = sectionsAndAreasCanvas.getGraphicsContext2D();

    tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    tickCtx    = tickCanvas.getGraphicsContext2D();

    alarmPane = new Pane();

    hour = new Rectangle(3, 60);
    hour.setArcHeight(3);
    hour.setArcWidth(3);
    hour.setStroke(getSkinnable().getHourColor());
    hour.getTransforms().setAll(hourRotate);

    minute = new Rectangle(3, 96);
    minute.setArcHeight(3);
    minute.setArcWidth(3);
    minute.setStroke(getSkinnable().getMinuteColor());
    minute.getTransforms().setAll(minuteRotate);

    second = new Rectangle(1, 96);
    second.setArcHeight(1);
    second.setArcWidth(1);
    second.setStroke(getSkinnable().getSecondColor());
    second.getTransforms().setAll(secondRotate);
    second.setVisible(getSkinnable().isSecondsVisible());
    second.setManaged(getSkinnable().isSecondsVisible());

    knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
    knob.setStroke(Color.web("#282a3280"));

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    shadowGroupHour   = new Group(hour);
    shadowGroupMinute = new Group(minute);
    shadowGroupSecond = new Group(second, knob);

    shadowGroupHour.setEffect(getSkinnable().getShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(getSkinnable().getShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(getSkinnable().getShadowsEnabled() ? dropShadow : null);

    title = new Text("");
    title.setVisible(getSkinnable().isTitleVisible());
    title.setManaged(getSkinnable().isTitleVisible());

    dateText = new Text("");
    dateText.setVisible(getSkinnable().isDateVisible());
    dateText.setManaged(getSkinnable().isDateVisible());

    text = new Text("");
    text.setVisible(getSkinnable().isTextVisible());
    text.setManaged(getSkinnable().isTextVisible());

    pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
    pane.setBorder(new Border(new BorderStroke(getSkinnable().getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(getSkinnable().getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(getSkinnable().getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 13
Source File: Led.java    From JFX8CustomControls with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    canvas = new Canvas();
    ctx    = canvas.getGraphicsContext2D();
    getChildren().add(canvas);
}
 
Example 14
Source File: Patterns.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
public static final ImagePattern createCarbonKevlarPattern() {
    final double WIDTH = 12;
    final double HEIGHT = 12;
    final Canvas CANVAS = new Canvas(WIDTH, HEIGHT);
    final GraphicsContext CTX = CANVAS.getGraphicsContext2D();

    double offsetY = 0;
    /// 1= border=yellow=dark========================================================
    CTX.beginPath();
    CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();

    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.5 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(105, 105, 0)),
            new Stop(1, Color.rgb(98, 98, 0))));
    CTX.fill();
    //  2=body=yellow==============================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.416666 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(138, 138, 0)),
            new Stop(1, Color.rgb(130, 130, 0))));
    CTX.fill();
    //  3=border=yellow=dark=============================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.5 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(105, 105, 0)),
            new Stop(1, Color.rgb(98, 98, 0))));
    CTX.fill();
    //  4=body=yellow============================================================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.416666 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(138, 138, 0)),
            new Stop(1, Color.rgb(130, 130, 0))));
    CTX.fill();
    //  5= border=gray=dark============================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.5 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(48, 48, 48)),
            new Stop(1, Color.rgb(30, 30, 30))));
    CTX.fill();
    //  6=body=gray=============================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.083333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.416666 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(53, 53, 53)),
            new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fill();
    //  7= border=gray=dark=============================
    CTX.beginPath();
    CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.5 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(48, 48, 48)),
            new Stop(1, Color.rgb(40, 40, 40))));
    CTX.fill();
    //  8= body=gray=light==============================
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.583333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
            0, 0.416666 * HEIGHT + offsetY * HEIGHT,
            false, CycleMethod.NO_CYCLE,
            new Stop(0, Color.rgb(53, 53, 53)),
            new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fill();

    final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
    final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false);

    return PATTERN;
}
 
Example 15
Source File: SimpleSectionSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionCtx    = sectionCanvas.getGraphicsContext2D();

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, gauge.getStartAngle() + 90, -ANGLE_RANGE);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, gauge.getStartAngle() + 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(gauge.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    valueText = new Text();
    valueText.setStroke(null);
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    unitText = new Text();
    unitText.setStroke(null);
    unitText.setFill(gauge.getUnitColor());
    Helper.enableNode(unitText, gauge.isValueVisible() && !gauge.getUnit().isEmpty());

    pane = new Pane(barBackground, sectionCanvas, titleText, valueText, unitText, bar);

    getChildren().setAll(pane);
}
 
Example 16
Source File: FireworksSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public SanFranciscoFireworks() {
    // create a color palette of 180 colors
    colors = new Paint[181];
    colors[0] = new RadialGradient(0, 0, 0.5, 0.5, 0.5, true, CycleMethod.NO_CYCLE, 
                new Stop(0, Color.WHITE),
                new Stop(0.2, Color.hsb(59, 0.38, 1)),
                new Stop(0.6, Color.hsb(59, 0.38, 1,0.1)),
                new Stop(1, Color.hsb(59, 0.38, 1,0))
                );
    for (int h=0;h<360;h+=2) {
        colors[1+(h/2)] = new RadialGradient(0, 0, 0.5, 0.5, 0.5, true, CycleMethod.NO_CYCLE, 
                new Stop(0, Color.WHITE),
                new Stop(0.2, Color.hsb(h, 1, 1)),
                new Stop(0.6, Color.hsb(h, 1, 1,0.1)),
                new Stop(1, Color.hsb(h, 1, 1,0))
                );
    }
    // create canvas
    canvas = new Canvas(1024, 500);

    canvas.setBlendMode(BlendMode.ADD);
    canvas.setEffect(new Reflection(0,0.4,0.15,0));
    background = new ImageView(getClass().getResource("sf.jpg").toExternalForm());
    getChildren().addAll(background,canvas);
    // create animation timer that will be called every frame
    // final AnimationTimer timer = new AnimationTimer() {
    timer = new AnimationTimer() {

        @Override public void handle(long now) {
            GraphicsContext gc = canvas.getGraphicsContext2D();
            // clear area with transparent black
            gc.setFill(Color.rgb(0, 0, 0, 0.2));
            gc.fillRect(0, 0, 1024, 708);
            // draw fireworks
            drawFireworks(gc);
            // countdown to launching the next firework
            if (countDownTillNextFirework == 0) {
                countDownTillNextFirework = 10 + (int)(Math.random()*30);
                fireParticle();
            }
            countDownTillNextFirework --;
        }
    };
}
 
Example 17
Source File: SimpleGaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT)); // "OpenSans"

    sectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsCtx    = sectionsCanvas.getGraphicsContext2D();

    measuredRangeCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    measuredRangeCanvas.setManaged(getSkinnable().isMeasuredRangeVisible());
    measuredRangeCanvas.setVisible(getSkinnable().isMeasuredRangeVisible());
    measuredRangeCtx    = measuredRangeCanvas.getGraphicsContext2D();        
    
    if (getSkinnable().getValue() < getSkinnable().getMinValue()) getSkinnable().setValue(getSkinnable().getMinValue());
    if (getSkinnable().getValue() > getSkinnable().getMaxValue()) getSkinnable().setValue(getSkinnable().getMaxValue());

    needleRotate = new Rotate(180 - getSkinnable().getStartAngle());
    if (getSkinnable().getMinValue() < 0) {
        needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() - getSkinnable().getMinValue()) * angleStep);
    } else {
        //needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() + getSkinnable().getMinValue()) * angleStep);
    }

    angleStep = getSkinnable().getAngleRange() / (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
    needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue()) * angleStep);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getStyleClass().setAll("needle");
    needle.getTransforms().setAll(needleRotate);       

    value = new Text(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinValue()) + getSkinnable().getUnit());
    value.setMouseTransparent(true);
    value.setTextOrigin(VPos.CENTER);
    value.getStyleClass().setAll("value");

    title = new Text(getSkinnable().getTitle());
    title.setTextOrigin(VPos.CENTER);
    title.getStyleClass().setAll("title");

    // Add all nodes
    pane = new Pane();
    pane.getStyleClass().add("simple-gauge");
    pane.getChildren().setAll(sectionsCanvas,
                              measuredRangeCanvas,
                              needle,
                              value,
                              title);

    getChildren().setAll(pane);
    resize();
}
 
Example 18
Source File: FireworksSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public SanFranciscoFireworks() {
    // create a color palette of 180 colors
    colors = new Paint[181];
    colors[0] = new RadialGradient(0, 0, 0.5, 0.5, 0.5, true, CycleMethod.NO_CYCLE, 
                new Stop(0, Color.WHITE),
                new Stop(0.2, Color.hsb(59, 0.38, 1)),
                new Stop(0.6, Color.hsb(59, 0.38, 1,0.1)),
                new Stop(1, Color.hsb(59, 0.38, 1,0))
                );
    for (int h=0;h<360;h+=2) {
        colors[1+(h/2)] = new RadialGradient(0, 0, 0.5, 0.5, 0.5, true, CycleMethod.NO_CYCLE, 
                new Stop(0, Color.WHITE),
                new Stop(0.2, Color.hsb(h, 1, 1)),
                new Stop(0.6, Color.hsb(h, 1, 1,0.1)),
                new Stop(1, Color.hsb(h, 1, 1,0))
                );
    }
    // create canvas
    canvas = new Canvas(1024, 500);

    canvas.setBlendMode(BlendMode.ADD);
    canvas.setEffect(new Reflection(0,0.4,0.15,0));
    background = new ImageView(getClass().getResource("sf.jpg").toExternalForm());
    getChildren().addAll(background,canvas);
    // create animation timer that will be called every frame
    // final AnimationTimer timer = new AnimationTimer() {
    timer = new AnimationTimer() {

        @Override public void handle(long now) {
            GraphicsContext gc = canvas.getGraphicsContext2D();
            // clear area with transparent black
            gc.setFill(Color.rgb(0, 0, 0, 0.2));
            gc.fillRect(0, 0, 1024, 708);
            // draw fireworks
            drawFireworks(gc);
            // countdown to launching the next firework
            if (countDownTillNextFirework == 0) {
                countDownTillNextFirework = 10 + (int)(Math.random()*30);
                fireParticle();
            }
            countDownTillNextFirework --;
        }
    };
}
 
Example 19
Source File: FlipTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    timeline              = new Timeline();
    characters            = tile.getCharacterList();
    currentSelectionIndex = 0;
    nextSelectionIndex    = 1;

    centerX    = PREFERRED_WIDTH * 0.5;
    centerY    = PREFERRED_HEIGHT * 0.5;

    pane.setBackground(null);
    pane.setBorder(null);

    rotateFlap = new Rotate();
    rotateFlap.setAxis(Rotate.X_AXIS);
    rotateFlap.setAngle(0);

    flapHeight = PREFERRED_HEIGHT * 0.495;

    upperBackground    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    upperBackgroundCtx = upperBackground.getGraphicsContext2D();

    upperBackgroundText    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    upperBackgroundTextCtx = upperBackgroundText.getGraphicsContext2D();
    upperBackgroundTextCtx.setTextBaseline(VPos.CENTER);
    upperBackgroundTextCtx.setTextAlign(TextAlignment.CENTER);

    lowerBackground    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    lowerBackgroundCtx = lowerBackground.getGraphicsContext2D();

    lowerBackgroundText    = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    lowerBackgroundTextCtx = lowerBackgroundText.getGraphicsContext2D();
    lowerBackgroundTextCtx.setTextBaseline(VPos.CENTER);
    lowerBackgroundTextCtx.setTextAlign(TextAlignment.CENTER);

    flap = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT * 0.495);
    flap.getTransforms().add(rotateFlap);
    flapCtx = flap.getGraphicsContext2D();

    flapTextFront = new Canvas();
    flapTextFront.getTransforms().add(rotateFlap);
    flapTextFrontCtx = flapTextFront.getGraphicsContext2D();
    flapTextFrontCtx.setTextBaseline(VPos.CENTER);
    flapTextFrontCtx.setTextAlign(TextAlignment.CENTER);

    flapTextBack  = new Canvas();
    flapTextBack.getTransforms().add(rotateFlap);
    flapTextBack.setOpacity(0);
    flapTextBackCtx = flapTextBack.getGraphicsContext2D();
    flapTextBackCtx.setTextBaseline(VPos.CENTER);
    flapTextBackCtx.setTextAlign(TextAlignment.CENTER);

    pane.getChildren().addAll(upperBackground,
                              lowerBackground,
                              upperBackgroundText,
                              lowerBackgroundText,
                              flap,
                              flapTextFront,
                              flapTextBack);
}
 
Example 20
Source File: Helper.java    From Medusa with Apache License 2.0 4 votes vote down vote up
public static final ImagePattern createCarbonPattern() {
    final double          SIZE   = 12;
    final Canvas          CANVAS = new Canvas(SIZE, SIZE);
    final GraphicsContext CTX    = CANVAS.getGraphicsContext2D();

    CTX.setFill(new LinearGradient(0, 0, 0, 0.5 * SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(35, 35, 35)),
                                   new Stop(1, Color.rgb(23, 23, 23))));
    CTX.fillRect(0, 0, SIZE * 0.5, SIZE * 0.5);

    CTX.setFill(new LinearGradient(0, 0, 0, 0.416666 * SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(38, 38, 38)),
                                   new Stop(1, Color.rgb(30, 30, 30))));
    CTX.fillRect(SIZE * 0.083333, 0, SIZE * 0.333333, SIZE * 0.416666);

    CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(35, 35, 35)),
                                   new Stop(1, Color.rgb(23, 23, 23))));
    CTX.fillRect(SIZE * 0.5, SIZE * 0.5, SIZE * 0.5, SIZE * 0.5);

    CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, 0.916666 * SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(38, 38, 38)),
                                   new Stop(1, Color.rgb(30, 30, 30))));
    CTX.fillRect(SIZE * 0.583333, SIZE * 0.5, SIZE * 0.333333, SIZE * 0.416666);

    CTX.setFill(new LinearGradient(0, 0, 0, 0.5 * SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(48, 48, 48)),
                                   new Stop(1, Color.rgb(40, 40, 40))));
    CTX.fillRect(SIZE * 0.5, 0, SIZE * 0.5, SIZE * 0.5);

    CTX.setFill(new LinearGradient(0, 0.083333 * SIZE, 0, 0.5 * SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(53, 53, 53)),
                                   new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fillRect(SIZE * 0.583333, SIZE * 0.083333, SIZE * 0.333333, SIZE * 0.416666);

    CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(48, 48, 48)),
                                   new Stop(1, Color.rgb(40, 40, 40))));
    CTX.fillRect(0, SIZE * 0.5, SIZE * 0.5, SIZE * 0.5);

    CTX.setFill(new LinearGradient(0, 0.583333 * SIZE, 0, SIZE,
                                   false, CycleMethod.NO_CYCLE,
                                   new Stop(0, Color.rgb(53, 53, 53)),
                                   new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fillRect(SIZE * 0.083333, SIZE * 0.583333, SIZE * 0.333333, SIZE * 0.416666);

    final Image        PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
    final ImagePattern PATTERN       = new ImagePattern(PATTERN_IMAGE, 0, 0, SIZE, SIZE, false);

    return PATTERN;
}