Java Code Examples for javafx.scene.shape.Rectangle#setVisible()

The following examples show how to use javafx.scene.shape.Rectangle#setVisible() . 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: ParallelCoordinatesChart.java    From charts 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);
        }
    }

    axisCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    axisCtx    = axisCanvas.getGraphicsContext2D();

    Color selectionRectColor = getSelectionRectColor();
    rect = new Rectangle();
    rect.setMouseTransparent(true);
    rect.setVisible(false);
    rect.setStroke(Helper.getColorWithOpacity(selectionRectColor, 0.5));
    rect.setFill(Helper.getColorWithOpacity(selectionRectColor, 0.25));

    connectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    connectionCanvas.setMouseTransparent(true);
    connectionCtx = connectionCanvas.getGraphicsContext2D();
    connectionCtx.setTextAlign(TextAlignment.LEFT);
    connectionCtx.setTextBaseline(VPos.CENTER);

    dragText = new Text("");
    dragText.setVisible(false);
    dragText.setTextOrigin(VPos.CENTER);
    dragText.setFill(Helper.getColorWithOpacity(getHeaderColor(), 0.5));


    getChildren().setAll(axisCanvas, rect, connectionCanvas, dragText);
}
 
Example 2
Source File: BaseMap.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
public BaseMap() {
    for (int i = 0; i < tiles.length; i++) {
        tiles[i] = new HashMap<>();
    }
    area = new Rectangle(-10, -10, 810, 610);
    area.setVisible(false);
   
    prefCenterLat.addListener(o -> doSetCenter(prefCenterLat.get(), prefCenterLon.get()));
    prefCenterLon.addListener(o -> doSetCenter(prefCenterLat.get(), prefCenterLon.get()));
    prefZoom.addListener(o -> doZoom(prefZoom.get()));

    area.widthProperty().addListener(resizeListener);
    area.heightProperty().addListener(resizeListener);
    area.translateXProperty().bind(translateXProperty().multiply(-1));
    area.translateYProperty().bind(translateYProperty().multiply(-1));

    if (sceneListener == null) {
        sceneListener = (o, oldScene, newScene) -> {
                if (newScene != null) {
                    //TODO Do we need to unbind from previous scene?
                    getParent().layoutBoundsProperty().addListener(e -> {
                        area.setWidth(getParent().getLayoutBounds().getWidth());
                        area.setHeight(getParent().getLayoutBounds().getHeight());
                    });
                    markDirty();
                }
                if (abortedTileLoad) {
                    abortedTileLoad = false;
                    doSetCenter(lat, lon);
                }
        };
    }
    this.sceneProperty().addListener(sceneListener);
}
 
Example 3
Source File: MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public MenuItem(String name, int width) {
    setAlignment(Pos.CENTER_LEFT);

    text = new Text(name);
    text.setTranslateX(5);
    text.setFont(font);
    text.setFill(Colors.MENU_TEXT);
    text.setStroke(Color.BLACK);

    shadow = new DropShadow(5, Color.BLACK);
    text.setEffect(shadow);

    selection = new Rectangle(width - 45, 30);
    selection.setFill(Colors.MENU_ITEM_SELECTION);
    selection.setStroke(Color.BLACK);
    selection.setVisible(false);

    GaussianBlur blur = new GaussianBlur(8);
    selection.setEffect(blur);

    getChildren().addAll(selection, text);

    setOnMouseEntered(e -> {
        onSelect();
    });

    setOnMouseExited(e -> {
        onDeselect();
    });

    setOnMousePressed(e -> {
        text.setFill(Color.YELLOW);
    });
}
 
Example 4
Source File: Canvas.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private void setVisibleSelectionBorder(final double x, final double y, final double w, final double h, final boolean ongoing) {
	final Rectangle rec = ongoing ? ongoingSelectionBorder : selectionBorder;
	rec.setLayoutX(x);
	rec.setLayoutY(y);
	rec.setWidth(w);
	rec.setHeight(h);
	rec.setVisible(true);
}
 
Example 5
Source File: TimerControlTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    currentValueListener = o -> {
        if (tile.isRunning()) { return; } // Update time only if clock is not already running
        updateTime(ZonedDateTime.ofInstant(Instant.ofEpochSecond(tile.getCurrentTime()), ZoneId.of(ZoneId.systemDefault().getId())));
    };
    timeListener         = o -> updateTime(tile.getTime());

    dateFormatter = DateTimeFormatter.ofPattern("EE d", tile.getLocale());

    sectionMap   = new HashMap<>(tile.getTimeSections().size());
    for (TimeSection section : tile.getTimeSections()) { sectionMap.put(section, new Arc()); }

    minuteRotate = new Rotate();
    hourRotate   = new Rotate();
    secondRotate = new Rotate();

    sectionsPane = new Pane();
    sectionsPane.getChildren().addAll(sectionMap.values());
    Helper.enableNode(sectionsPane, tile.getSectionsVisible());

    minuteTickMarks = new Path();
    minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
    minuteTickMarks.setFill(null);
    minuteTickMarks.setStroke(tile.getMinuteColor());
    minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

    hourTickMarks = new Path();
    hourTickMarks.setFillRule(FillRule.EVEN_ODD);
    hourTickMarks.setFill(null);
    hourTickMarks.setStroke(tile.getHourColor());
    hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

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

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

    second = new Rectangle(1, 96);
    second.setArcHeight(1);
    second.setArcWidth(1);
    second.setStroke(tile.getSecondColor());
    second.getTransforms().setAll(secondRotate);
    second.setVisible(tile.isSecondsVisible());
    second.setManaged(tile.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(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(tile.isShadowsEnabled() ? dropShadow : null);

    titleText = new Text("");
    titleText.setTextOrigin(VPos.TOP);
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    amPmText = new Text(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");

    dateText = new Text("");
    Helper.enableNode(dateText, tile.isDateVisible());

    text = new Text("");
    Helper.enableNode(text, tile.isTextVisible());

    getPane().getChildren().addAll(sectionsPane, hourTickMarks, minuteTickMarks, titleText, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
}
 
Example 6
Source File: TimerControlTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    currentValueListener = o -> {
        if (tile.isRunning()) { return; } // Update time only if clock is not already running
        updateTime(ZonedDateTime.ofInstant(Instant.ofEpochSecond(tile.getCurrentTime()), ZoneId.of(ZoneId.systemDefault().getId())));
    };
    timeListener         = o -> updateTime(tile.getTime());

    dateFormatter = DateTimeFormatter.ofPattern("EE d", tile.getLocale());

    sectionMap   = new HashMap<>(tile.getTimeSections().size());
    for (TimeSection section : tile.getTimeSections()) { sectionMap.put(section, new Arc()); }

    minuteRotate = new Rotate();
    hourRotate   = new Rotate();
    secondRotate = new Rotate();

    sectionsPane = new Pane();
    sectionsPane.getChildren().addAll(sectionMap.values());
    Helper.enableNode(sectionsPane, tile.getSectionsVisible());

    minuteTickMarks = new Path();
    minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
    minuteTickMarks.setFill(null);
    minuteTickMarks.setStroke(tile.getMinuteColor());
    minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

    hourTickMarks = new Path();
    hourTickMarks.setFillRule(FillRule.EVEN_ODD);
    hourTickMarks.setFill(null);
    hourTickMarks.setStroke(tile.getHourColor());
    hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

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

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

    second = new Rectangle(1, 96);
    second.setArcHeight(1);
    second.setArcWidth(1);
    second.setStroke(tile.getSecondColor());
    second.getTransforms().setAll(secondRotate);
    second.setVisible(tile.isSecondsVisible());
    second.setManaged(tile.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(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(tile.isShadowsEnabled() ? dropShadow : null);

    titleText = new Text("");
    titleText.setTextOrigin(VPos.TOP);
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    amPmText = new Text(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");

    dateText = new Text("");
    Helper.enableNode(dateText, tile.isDateVisible());

    text = new Text("");
    Helper.enableNode(text, tile.isTextVisible());

    getPane().getChildren().addAll(sectionsPane, hourTickMarks, minuteTickMarks, titleText, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
}
 
Example 7
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 8
Source File: TileClockSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    // Set initial size
    if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
        if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
            clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
        } else {
            clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    minuteTickMarks = new Path();
    minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
    minuteTickMarks.setFill(null);
    minuteTickMarks.setStroke(clock.getMinuteColor());
    minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

    hourTickMarks = new Path();
    hourTickMarks.setFillRule(FillRule.EVEN_ODD);
    hourTickMarks.setFill(null);
    hourTickMarks.setStroke(clock.getHourColor());
    hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

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

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

    second = new Rectangle(1, 96);
    second.setArcHeight(1);
    second.setArcWidth(1);
    second.setStroke(clock.getSecondColor());
    second.getTransforms().setAll(secondRotate);
    second.setVisible(clock.isSecondsVisible());
    second.setManaged(clock.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(clock.getShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);

    title = new Text("");
    title.setTextOrigin(VPos.TOP);
    Helper.enableNode(title, clock.isTitleVisible());

    amPmText = new Text(clock.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");

    dateText = new Text("");
    Helper.enableNode(dateText, clock.isDateVisible());

    text = new Text("");
    Helper.enableNode(text, clock.isTextVisible());

    pane = new Pane(hourTickMarks, minuteTickMarks, title, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
    pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(clock.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 9
Source File: Canvas.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the canvas.
 */
@Inject
public Canvas(final PreferencesService prefs, final ViewFactory viewFactory) {
	super();
	this.viewFactory = Objects.requireNonNull(viewFactory);
	modified = false;
	drawing = ShapeFactory.INST.createDrawing();
	zoom = new SimpleDoubleProperty(1d);
	tempView = Optional.empty();
	page = new PageView(prefs, getOrigin());
	magneticGrid = new MagneticGrid(this, prefs);
	disposables = new ArrayList<>();

	widgetsPane = new Group();
	shapesPane = new Group();
	shapesToViewMap = new HashMap<>();
	selectionBorder = new Rectangle();
	ongoingSelectionBorder = new Rectangle();

	widgetsPane.setFocusTraversable(false);
	ongoingSelectionBorder.setFocusTraversable(false);
	ongoingSelectionBorder.setMouseTransparent(true);
	ongoingSelectionBorder.setFill(null);
	ongoingSelectionBorder.setStroke(Color.GRAY);
	ongoingSelectionBorder.setStrokeLineCap(StrokeLineCap.BUTT);
	ongoingSelectionBorder.getStrokeDashArray().addAll(7d, 7d);

	getChildren().add(page);
	getChildren().add(magneticGrid);
	getChildren().add(shapesPane);
	getChildren().add(widgetsPane);
	widgetsPane.getChildren().add(selectionBorder);
	widgetsPane.getChildren().add(ongoingSelectionBorder);
	widgetsPane.relocate(ORIGIN.getX(), ORIGIN.getY());
	shapesPane.relocate(ORIGIN.getX(), ORIGIN.getY());

	defineShapeListToViewBinding();

	selectionBorder.setFocusTraversable(false);
	selectionBorder.setVisible(false);
	selectionBorder.setFill(null);
	selectionBorder.setStroke(Color.GRAY);
	selectionBorder.setStrokeLineCap(StrokeLineCap.BUTT);
	selectionBorder.getStrokeDashArray().addAll(7d, 7d);

	// Bloody key shortcuts. To work the canvas must grab the focus
	// Must be a MOUSE_CLICKED, not a MOUSE_PRESSED, do not know why...
	io.github.interacto.jfx.binding.Bindings
		.anonCmdBinder(() -> requestFocus())
		.usingInteraction(Click::new)
		.on(this)
		.bind();

	// Instead of triggering the update on each change, wait for 20 ms
	disposables.add(JavaFxObservable.<ObservableList<Shape>>changesOf(drawing.getSelection().getShapes())
		.throttleLast(20, TimeUnit.MILLISECONDS)
		.observeOn(JavaFxScheduler.platform())
		.subscribe(next -> updateSelectionBorders(), ex -> BadaboomCollector.INSTANCE.add(ex)));

	disposables.add(CommandsRegistry.getInstance().commands()
		.filter(c -> c instanceof Modifying || c instanceof Undo || c instanceof Redo)
		.subscribe(c -> update()));

	shapesPane.setFocusTraversable(false);

	prefWidthProperty().bind(Bindings.createDoubleBinding(() -> margins * 2d + prefs.getPage().getWidth() * Shape.PPC, prefs.pageProperty()));
	prefHeightProperty().bind(Bindings.createDoubleBinding(() -> margins * 2d + prefs.getPage().getHeight() * Shape.PPC, prefs.pageProperty()));
}