Java Code Examples for javafx.scene.layout.Region#setStyle()

The following examples show how to use javafx.scene.layout.Region#setStyle() . 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: Builders.java    From PDF4Teachers with Apache License 2.0 6 votes vote down vote up
public static void setPosition(Region element, double x, double y, double width, double height, boolean force){

        if(x >= 0){
            element.setLayoutX(x);
        }if(y >= 0){
            element.setLayoutY(y);
        }
        element.setPrefSize(width, height);

        if(force){
            element.setStyle("-fx-min-width: " + width + ";");
            element.setStyle("-fx-min-height: " + height + ";");
            element.minWidthProperty().bind(new SimpleDoubleProperty(width));
            element.minHeightProperty().bind(new SimpleDoubleProperty(height));
        }
    }
 
Example 2
Source File: TaskProgressIndicatorSkin.java    From archivo with GNU General Public License v3.0 6 votes vote down vote up
private void rebuild() {
    // update indeterminate indicator
    final int segments = indeterminateSegmentCount.get();
    opacities.clear();
    pathsG.getChildren().clear();
    final double step = 0.8 / (segments - 1);
    for (int i = 0; i < segments; i++) {
        Region region = new Region();
        region.setScaleShape(false);
        region.setCenterShape(false);
        region.getStyleClass().addAll("segment", "segment" + i);
        if (fillOverride instanceof Color) {
            Color c = (Color) fillOverride;
            region.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," + c.getOpacity() + ");");
        } else {
            region.setStyle(null);
        }
        pathsG.getChildren().add(region);
        opacities.add(Math.max(0.1, (1.0 - (step * i))));
    }
}
 
Example 3
Source File: StaticProgressIndicatorSkin.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void rebuild() {
    // update indeterminate indicator
    final int segments = skin.indeterminateSegmentCount.get();
    opacities.clear();
    pathsG.getChildren().clear();
    final double step = 0.8 / (segments - 1);
    for (int i = 0; i < segments; i++) {
        Region region = new Region();
        region.setScaleShape(false);
        region.setCenterShape(false);
        region.getStyleClass().addAll("segment", "segment" + i);
        if (fillOverride instanceof Color) {
            Color c = (Color) fillOverride;
            region.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
                    "" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
                    "" + c.getOpacity() + ");");
        } else {
            region.setStyle(null);
        }
        double opacity = Math.min(1, i * step);
        opacities.add(opacity);
        region.setOpacity(opacity);
        pathsG.getChildren().add(region);
    }
}
 
Example 4
Source File: LedSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    frame = new Region();
    frame.setOpacity(getSkinnable().isFrameVisible() ? 1 : 0);

    led = new Region();
    led.setStyle("-led-color: " + Util.colorToCss((Color) getSkinnable().getLedColor()) + ";");

    innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);

    glow = new DropShadow(BlurType.TWO_PASS_BOX, (Color) getSkinnable().getLedColor(), 20, 0d, 0d, 0d);
    glow.setInput(innerShadow);

    highlight = new Region();

    // Set the appropriate style classes
    changeStyle();

    // Add all nodes
    getChildren().setAll(frame, led, highlight);
}
 
Example 5
Source File: LedSkin.java    From JFX8CustomControls with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    frame = new Region();
    frame.getStyleClass().setAll("frame");
    frame.setOpacity(getSkinnable().isFrameVisible() ? 1 : 0);

    led = new Region();
    led.getStyleClass().setAll("main");
    led.setStyle("-led-color: " + (getSkinnable().getLedColor()).toString().replace("0x", "#") + ";");

    innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);

    glow = new DropShadow(BlurType.TWO_PASS_BOX, (Color) getSkinnable().getLedColor(), 20, 0d, 0d, 0d);
    glow.setInput(innerShadow);

    highlight = new Region();
    highlight.getStyleClass().setAll("highlight");

    getChildren().addAll(frame, led, highlight);
}
 
Example 6
Source File: Led.java    From JFX8CustomControls with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    frame = new Region();
    frame.getStyleClass().setAll("frame");
    frame.setOpacity(isFrameVisible() ? 1 : 0);

    led = new Region();
    led.getStyleClass().setAll("main");
    led.setStyle("-led-color: " + (getLedColor()).toString().replace("0x", "#") + ";");

    innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);

    glow = new DropShadow(BlurType.TWO_PASS_BOX, getLedColor(), 20, 0d, 0d, 0d);
    glow.setInput(innerShadow);

    highlight = new Region();
    highlight.getStyleClass().setAll("highlight");

    // Add all nodes
    getChildren().addAll(frame, led, highlight);
}
 
Example 7
Source File: TaskSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TaskSample() {
    TableView<DailySales> tableView = new TableView<DailySales>();
    Region veil = new Region();
    veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
    ProgressIndicator p = new ProgressIndicator();
    p.setMaxSize(150, 150);
    //Define table columns
    TableColumn idCol = new TableColumn();
    idCol.setText("ID");
    idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
    tableView.getColumns().add(idCol);
    TableColumn qtyCol = new TableColumn();
    qtyCol.setText("Qty");
    qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
    tableView.getColumns().add(qtyCol);
    TableColumn dateCol = new TableColumn();
    dateCol.setText("Date");
    dateCol.setCellValueFactory(new PropertyValueFactory("date"));
    dateCol.setMinWidth(240);
    tableView.getColumns().add(dateCol);
    StackPane stack = new StackPane();
    stack.getChildren().addAll(tableView, veil, p);

    // Use binding to be notified whenever the data source chagnes
    Task<ObservableList<DailySales>> task = new GetDailySalesTask();
    p.progressProperty().bind(task.progressProperty());
    veil.visibleProperty().bind(task.runningProperty());
    p.visibleProperty().bind(task.runningProperty());
    tableView.itemsProperty().bind(task.valueProperty());

    getChildren().add(stack);
    new Thread(task).start();
}
 
Example 8
Source File: TaskSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TaskSample() {
    TableView<DailySales> tableView = new TableView<DailySales>();
    Region veil = new Region();
    veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
    ProgressIndicator p = new ProgressIndicator();
    p.setMaxSize(150, 150);
    //Define table columns
    TableColumn idCol = new TableColumn();
    idCol.setText("ID");
    idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
    tableView.getColumns().add(idCol);
    TableColumn qtyCol = new TableColumn();
    qtyCol.setText("Qty");
    qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
    tableView.getColumns().add(qtyCol);
    TableColumn dateCol = new TableColumn();
    dateCol.setText("Date");
    dateCol.setCellValueFactory(new PropertyValueFactory("date"));
    dateCol.setMinWidth(240);
    tableView.getColumns().add(dateCol);
    StackPane stack = new StackPane();
    stack.getChildren().addAll(tableView, veil, p);

    // Use binding to be notified whenever the data source chagnes
    Task<ObservableList<DailySales>> task = new GetDailySalesTask();
    p.progressProperty().bind(task.progressProperty());
    veil.visibleProperty().bind(task.runningProperty());
    p.visibleProperty().bind(task.runningProperty());
    tableView.itemsProperty().bind(task.valueProperty());

    getChildren().add(stack);
    new Thread(task).start();
}
 
Example 9
Source File: OnOffSwitchSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.5 * PREFERRED_HEIGHT)); // "OpenSans"
    font = Font.font("Open Sans", 0.5 * PREFERRED_HEIGHT);

    background = new Region();
    background.getStyleClass().setAll("background");
    background.setStyle("-switch-color: " + Util.colorToCss((Color) getSkinnable().getSwitchColor()) + ";");

    selectedText  = new Text("1");
    selectedText.setFont(font);
    selectedText.getStyleClass().setAll("selected-text");
    selectedText.setStyle("-text-color-on: " + Util.colorToCss((Color) getSkinnable().getTextColorOn()) + ";");

    deselectedText = new Text("0");
    deselectedText.setFont(font);
    deselectedText.getStyleClass().setAll("deselected-text");
    deselectedText.setStyle("-text-color-off: " + Util.colorToCss((Color) getSkinnable().getTextColorOff()) + ";");

    thumb = new Region();
    thumb.getStyleClass().setAll("thumb");
    thumb.setMouseTransparent(true);
    thumb.setStyle("-thumb-color: " + Util.colorToCss((Color) getSkinnable().getThumbColor()) + ";");

    pane = new Pane(background, selectedText, deselectedText, thumb);
    pane.getStyleClass().setAll("on-off-switch");

    moveToDeselected = new TranslateTransition(Duration.millis(180), thumb);
    moveToSelected = new TranslateTransition(Duration.millis(180), thumb);

    // Add all nodes
    getChildren().setAll(pane);
}
 
Example 10
Source File: IconSwitchSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.5 * PREFERRED_HEIGHT)); // "OpenSans"
    font = Font.font("Open Sans", 0.5 * PREFERRED_HEIGHT);

    background = new Region();
    background.getStyleClass().setAll("background");
    background.setStyle("-switch-color: " + Util.colorToCss((Color) getSkinnable().getSwitchColor()) + ";");

    symbol = getSkinnable().getSymbol();
    symbol.setMouseTransparent(true);

    text = new Label(getSkinnable().getText());
    text.setTextAlignment(TextAlignment.CENTER);
    text.setAlignment(Pos.CENTER);
    text.setTextFill(getSkinnable().getSymbolColor());
    text.setFont(font);

    thumb = new Region();
    thumb.getStyleClass().setAll("thumb");
    thumb.setStyle("-thumb-color: " + Util.colorToCss((Color) getSkinnable().getThumbColor()) + ";");
    thumb.setMouseTransparent(true);

    pane = new Pane(background, symbol, text, thumb);
    pane.getStyleClass().setAll("icon-switch");

    moveToDeselected = new TranslateTransition(Duration.millis(180), thumb);
    moveToSelected = new TranslateTransition(Duration.millis(180), thumb);

    // Add all nodes
    getChildren().setAll(pane);
}
 
Example 11
Source File: ServiceSample.java    From JavaFX with MIT License 5 votes vote down vote up
private void init(Stage primaryStage) {
	Group root = new Group();
	primaryStage.setScene(new Scene(root));

	VBox vbox = new VBox(5);
	vbox.setPadding(new Insets(12));
	ListView<String> listView = new ListView<>();
	listView.setEditable(true);
	Button button = new Button("Refresh");
	button.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent t) {
			service.restart();
		}
	});
	listView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
		@Override
		public ListCell<String> call(ListView<String> param) {
			return new InstantEditingCell();
		}
	});
	listView.setPrefHeight(200);
	vbox.getChildren().addAll(listView, button);

	Region veil = new Region();
	veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
	ProgressIndicator p = new ProgressIndicator();
	p.setMaxSize(150, 150);

	p.progressProperty().bind(service.progressProperty());
	veil.visibleProperty().bind(service.runningProperty());
	p.visibleProperty().bind(service.runningProperty());
	listView.itemsProperty().bind(service.valueProperty());

	StackPane stack = new StackPane();
	stack.getChildren().addAll(vbox, veil, p);

	root.getChildren().add(stack);
	service.start();
}
 
Example 12
Source File: ServiceSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ServiceSample() {

        VBox vbox = new VBox(5);
        vbox.setPadding(new Insets(12));
        TableView tableView = new TableView();
        Button button = new Button("Refresh");
        button.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent t) {
                service.restart();
            }
        });
        vbox.getChildren().addAll(tableView, button);

        Region veil = new Region();
        veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
        ProgressIndicator p = new ProgressIndicator();
        p.setMaxSize(150, 150);

        //Define table columns
        TableColumn idCol = new TableColumn();
        idCol.setText("ID");
        idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
        tableView.getColumns().add(idCol);
        TableColumn qtyCol = new TableColumn();
        qtyCol.setText("Qty");
        qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
        tableView.getColumns().add(qtyCol);
        TableColumn dateCol = new TableColumn();
        dateCol.setText("Date");
        dateCol.setCellValueFactory(new PropertyValueFactory("date"));
        dateCol.setMinWidth(240);
        tableView.getColumns().add(dateCol);


        p.progressProperty().bind(service.progressProperty());
        veil.visibleProperty().bind(service.runningProperty());
        p.visibleProperty().bind(service.runningProperty());
        tableView.itemsProperty().bind(service.valueProperty());

        StackPane stack = new StackPane();
        stack.getChildren().addAll(vbox, veil, p);

        getChildren().add(stack);
        service.start();
    }
 
Example 13
Source File: ServiceSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ServiceSample() {

        VBox vbox = new VBox(5);
        vbox.setPadding(new Insets(12));
        TableView tableView = new TableView();
        Button button = new Button("Refresh");
        button.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent t) {
                service.restart();
            }
        });
        vbox.getChildren().addAll(tableView, button);

        Region veil = new Region();
        veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
        ProgressIndicator p = new ProgressIndicator();
        p.setMaxSize(150, 150);

        //Define table columns
        TableColumn idCol = new TableColumn();
        idCol.setText("ID");
        idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
        tableView.getColumns().add(idCol);
        TableColumn qtyCol = new TableColumn();
        qtyCol.setText("Qty");
        qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
        tableView.getColumns().add(qtyCol);
        TableColumn dateCol = new TableColumn();
        dateCol.setText("Date");
        dateCol.setCellValueFactory(new PropertyValueFactory("date"));
        dateCol.setMinWidth(240);
        tableView.getColumns().add(dateCol);


        p.progressProperty().bind(service.progressProperty());
        veil.visibleProperty().bind(service.runningProperty());
        p.visibleProperty().bind(service.runningProperty());
        tableView.itemsProperty().bind(service.valueProperty());

        StackPane stack = new StackPane();
        stack.getChildren().addAll(vbox, veil, p);

        getChildren().add(stack);
        service.start();
    }