static { preferences = Preferences.userNodeForPackage(ThemeManager.class); final StringProperty _baseColorProperty = new SimpleStringProperty(); // restore the old value fontScaleProperty.set(preferences.getDouble(FONT_SIZE, 1)); // Save the value when it changes fontScaleProperty.addListener( (observable, oldValue, newValue) -> { if (newValue != null) { preferences.putDouble(FONT_SIZE, newValue.doubleValue()); } }); baseColorProperty.setValue(Color.web(preferences.get(BASE_COLOR, DEFAULT_MODENA_BASE_COLOR))); // restore the old base color value switch (preferences.get(LAST, Application.STYLESHEET_MODENA)) { case Application.STYLESHEET_CASPIAN: baseColorProperty.setValue( Color.web(preferences.get(BASE_COLOR, DEFAULT_CASPIAN_BASE_COLOR))); break; case Application.STYLESHEET_MODENA: baseColorProperty.setValue( Color.web(preferences.get(BASE_COLOR, DEFAULT_MODENA_BASE_COLOR))); break; default: baseColorProperty.setValue( Color.web(preferences.get(BASE_COLOR, DEFAULT_MODENA_BASE_COLOR))); } _baseColorProperty.setValue(colorToHex(baseColorProperty.getValue())); // Save the value when it changes baseColorProperty.addListener( (observable, oldValue, newValue) -> { if (newValue != null) { preferences.put(BASE_COLOR, colorToHex(newValue)); _baseColorProperty.setValue(colorToHex(newValue)); } }); // Create the binding format for the style / font size styleProperty = Bindings.format( "-fx-font-size: %1$.6fem; -fx-base:%2$s", fontScaleProperty, _baseColorProperty); }
@Override public void start(Stage stage) { DropShadow dropShadow = new DropShadow(10.0, Color.rgb(150, 50, 50, .688)); dropShadow.setOffsetX(4); dropShadow.setOffsetY(6); StackPane stackPane = new StackPane(); stackPane.setAlignment(Pos.CENTER); stackPane.setEffect(dropShadow); Rectangle rectangle = new Rectangle(100, 50, Color.LEMONCHIFFON); rectangle.setArcWidth(30); rectangle.setArcHeight(30); Text text = new Text(); text.setFont(Font.font("Tahoma", FontWeight.BOLD, 18)); stackPane.getChildren().addAll(rectangle, text); final Scene scene = new Scene(stackPane, 400, 200, Color.LIGHTSKYBLUE); stage.setTitle("Custom Binding"); rectangle.widthProperty().bind(scene.widthProperty().divide(2)); rectangle.heightProperty().bind(scene.heightProperty().divide(2)); DoubleBinding opacityBinding = new DoubleBinding() { { // List the dependencies with super.bind() super.bind(scene.widthProperty(), scene.heightProperty()); } @Override protected double computeValue() { // Return the computed value double opacity = (scene.getWidth() + scene.getHeight()) / 1000; return (opacity > 1.0) ? 1.0 : opacity; } }; rectangle.opacityProperty().bind(opacityBinding); text.textProperty().bind((Bindings.format("opacity = %.2f", opacityBinding))); ObjectBinding<Color> colorBinding = new ObjectBinding<Color>() { { super.bind(scene.fillProperty()); } @Override protected Color computeValue() { if (scene.getFill() instanceof Color) { return ((Color) scene.getFill()).darker(); } else { return Color.GRAY; } } }; text.fillProperty().bind(colorBinding); stage.setScene(scene); stage.show(); }
private void createViewTab(final HeatChartMaster heatChart) { for (Tab selTab : pane.getTabs()) { if (selTab.getId() != null && selTab.getId().equalsIgnoreCase(heatChart.getChartNumber())) { pane.getSelectionModel().select(selTab); return; } } Tab tab = new Tab("View Heat Chart : " + heatChart.getChartNumber()); tab.setId(heatChart.getChartNumber()); VBox main = ViewLayout.getMainVBox("Heat Chart", "Details"); GridPane form = new GridPane(); form.setHgap(ViewLayout.H_SPACE); form.setVgap(ViewLayout.V_SPACE); Label equipmentLabel = new Label("Equipment"); equipmentLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox equipmentTextField = new ViewBox("Equipment", heatChart.equipmentProperty()); Label customerLabel = new Label("Customer"); customerLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox customerTextField = new ViewBox("Customer", heatChart.customerProperty()); Label poDetailsLabel = new Label("PO Details"); poDetailsLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox poDetailsTextField = new ViewBox("PO Details", heatChart.poDetailsProperty()); Label drawingLabel = new Label("Drawing No."); drawingLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox drawingTextField = new ViewBox("Drawing No.", heatChart.drawingNumberProperty()); Label suryeyorLabel = new Label("Surveyor"); suryeyorLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox suryeyorTextField = new ViewBox("Suryeyor", heatChart.surveyorProperty()); Label tagNumberLabel = new Label("Tag Number"); suryeyorLabel.setPrefWidth(ViewLayout.LABEL_WIDTH); final ViewBox tagNumberTextField = new ViewBox("Tag Number", heatChart.tagNumberProperty()); form.add(equipmentLabel, 0, 0); form.add(equipmentTextField, 1, 0); form.add(customerLabel, 2, 0); form.add(customerTextField, 3, 0); form.add(poDetailsLabel, 4, 0); form.add(poDetailsTextField, 5, 0); form.add(drawingLabel, 0, 1); form.add(drawingTextField, 1, 1); form.add(suryeyorLabel, 2, 1); form.add(suryeyorTextField, 3, 1); form.add(tagNumberLabel, 4, 1); form.add(tagNumberTextField, 5, 1); main.getChildren().addAll(form); final ObservableList<HeatChartSheets> data = FXCollections.observableArrayList(); TableView<HeatChartSheets> table = TableUtil.createViewHeatChartSheetTable(); data.setAll(heatChart.getHeatChartSheets()); table.setItems(data); main.getChildren().addAll(ControlsUtil.makeScrollable(table)); final HBox buttons = new HBox(ViewLayout.H_SPACE); buttons.setTranslateY(32); final Button printButton = new Button("Print"); printButton.getStyleClass().add("submit-button"); buttons.getChildren().addAll(printButton); main.getChildren().addAll(buttons); printButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { printHeatChart.setHeatChart(heatChart); printHeatChart.restart(); } }); Context.getWindowBottomText() .textProperty() .bind(Bindings.format("%s", printHeatChart.stateProperty())); printHeatChart .stateProperty() .addListener( new ChangeListener<Worker.State>() { @Override public void changed( ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newState) { if (newState == Worker.State.SUCCEEDED) { Alert.showAlert( Context.getWindowStage(), "Alert", "Alert", "The report has been saved as " + printHeatChart.getValue()); Context.getHostServices().showDocument(printHeatChart.getValue()); } else if (newState == Worker.State.FAILED) { Alert.showAlert( Context.getWindowStage(), "Error", "Error", "Some error cooured. Details : " + printHeatChart.getException().getCause()); } } }); tab.setContent(ControlsUtil.makeScrollable(main)); pane.getTabs().add(tab); }