Search in sources :

Example 1 with Gradient

use of com.fxexperience.tools.util.Gradient in project fxexperience2 by EricCanull.

the class StylerController method initialize.

@Override
public void initialize(URL url, ResourceBundle rb) {
    try {
        previewPanel = FXMLLoader.load(PreviewPanelController.class.getResource(AppPaths.FXML_PATH + "FXMLPreviewPanel.fxml"));
        previewPane.setCenter(previewPanel);
    } catch (IOException ex) {
        Logger.getLogger(StylerController.class.getName()).log(Level.SEVERE, null, ex);
    }
    // populate fonts choicebox
    fontChoiceBox.getItems().setAll(Font.getFamilies());
    fontChoiceBox.getSelectionModel().select("System");
    // create listener to call update css
    ChangeListener<Object> updateCssListener = (ObservableValue<?> arg0, Object arg1, Object arg2) -> {
        updateCss();
    };
    // add listeners to call update css
    fontChoiceBox.valueProperty().addListener(updateCssListener);
    fontSizeSlider.valueProperty().addListener(updateCssListener);
    paddingSlider.valueProperty().addListener(updateCssListener);
    borderRadiusSlider.valueProperty().addListener(updateCssListener);
    borderWidthSlider.valueProperty().addListener(updateCssListener);
    // create Integer Fields
    createNumberFieldForSlider(fontSizeSlider, textGridPanel, 2, 1);
    createNumberFieldForSlider(paddingSlider, sizeGridPanel, 2, 0);
    createNumberFieldForSlider(borderWidthSlider, sizeGridPanel, 2, 1);
    createNumberFieldForSlider(borderRadiusSlider, sizeGridPanel, 2, 2);
    // Add color pickers Title Pane
    simpleGridPane.getChildren().addAll(basePicker, backgroundColorPicker, focusColorPicker, textColorPicker, fieldBackgroundPicker, fieldTextColorPicker, bkgdTextColorPicker);
    // Set color pickers grid constraints
    GridPane.setConstraints(basePicker, 1, 0, 2, 1);
    GridPane.setConstraints(textColorPicker, 1, 1);
    GridPane.setConstraints(backgroundColorPicker, 1, 2);
    GridPane.setConstraints(bkgdTextColorPicker, 1, 3);
    GridPane.setConstraints(fieldBackgroundPicker, 1, 4);
    GridPane.setConstraints(fieldTextColorPicker, 1, 5);
    GridPane.setConstraints(focusColorPicker, 1, 6);
    basePicker.colorProperty().addListener(updateCssListener);
    backgroundColorPicker.colorProperty().addListener(updateCssListener);
    focusColorPicker.colorProperty().addListener(updateCssListener);
    textColorPicker.colorProperty().addListener(updateCssListener);
    baseTextToggle.selectedProperty().addListener(updateCssListener);
    textColorPicker.disableProperty().bind(baseTextToggle.selectedProperty().not());
    fieldBackgroundPicker.colorProperty().addListener(updateCssListener);
    fieldTextColorPicker.colorProperty().addListener(updateCssListener);
    fieldTextToggle.selectedProperty().addListener(updateCssListener);
    fieldTextColorPicker.disableProperty().bind(fieldTextToggle.selectedProperty().not());
    bkgdTextColorPicker.colorProperty().addListener(updateCssListener);
    backgroundTextToggle.selectedProperty().addListener(updateCssListener);
    bkgdTextColorPicker.disableProperty().bind(backgroundTextToggle.selectedProperty().not());
    // add listeners to sliders
    topHighlightSlider.valueProperty().addListener(updateCssListener);
    bottomHighlightSlider.valueProperty().addListener(updateCssListener);
    // Populate gradient combo
    gradientComboBox.getItems().addAll(Gradient.GRADIENTS);
    gradientComboBox.setCellFactory((ListView<Gradient> gradientList) -> {
        ListCell<Gradient> cell = new ListCell<Gradient>() {

            @Override
            protected void updateItem(Gradient gradient, boolean empty) {
                super.updateItem(gradient, empty);
                if (empty || gradient == null) {
                    setText(null);
                    setGraphic(null);
                } else {
                    setText(gradient.getName());
                    Region preview = new Region();
                    preview.setPrefSize(30, 30);
                    preview.setStyle("-fx-border-color: #111; -fx-background-color: " + gradient.getCss());
                    setGraphic(preview);
                }
            }
        };
        cell.setStyle("-fx-cell-size: 40;");
        return cell;
    });
    gradientComboBox.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends Gradient> arg0, Gradient arg1, Gradient newGradient) -> {
        bodyTopSlider.setValue(newGradient.getTopDerivation());
        bodyBottomSlider.setValue(newGradient.getBottomDerivation());
        if (newGradient.isShinny()) {
            topMiddleToggle.setSelected(true);
            bottomMiddleToggle.setSelected(true);
            bodyTopMiddleSlider.setValue(newGradient.getTopMidDerivation());
            bodyBottomMiddleSlider.setValue(newGradient.getBottomMidDerivation());
        } else {
            topMiddleToggle.setSelected(false);
            bottomMiddleToggle.setSelected(false);
        }
        updateCss();
    });
    gradientComboBox.getSelectionModel().select(0);
    // Advanced toggle buttons
    topMiddleToggle.selectedProperty().addListener(updateCssListener);
    bottomMiddleToggle.selectedProperty().addListener(updateCssListener);
    borderToggle.selectedProperty().addListener(updateCssListener);
    shadowToggle.selectedProperty().addListener(updateCssListener);
    inputBorderToggle.selectedProperty().addListener(updateCssListener);
    bodyTopSlider.valueProperty().addListener(updateCssListener);
    bodyTopMiddleSlider.valueProperty().addListener(updateCssListener);
    bodyBottomMiddleSlider.valueProperty().addListener(updateCssListener);
    bodyBottomSlider.valueProperty().addListener(updateCssListener);
    borderSlider.valueProperty().addListener(updateCssListener);
    shadowSlider.valueProperty().addListener(updateCssListener);
    inputBorderSlider.valueProperty().addListener(updateCssListener);
    bodyTopMiddleSlider.disableProperty().bind(topMiddleToggle.selectedProperty().not());
    bodyBottomMiddleSlider.disableProperty().bind(bottomMiddleToggle.selectedProperty().not());
    borderSlider.disableProperty().bind(borderToggle.selectedProperty().not());
    shadowSlider.disableProperty().bind(shadowToggle.selectedProperty().not());
    inputBorderSlider.disableProperty().bind(inputBorderToggle.selectedProperty().not());
}
Also used : Gradient(com.fxexperience.tools.util.Gradient) ObservableValue(javafx.beans.value.ObservableValue) Region(javafx.scene.layout.Region)

Aggregations

Gradient (com.fxexperience.tools.util.Gradient)1 ObservableValue (javafx.beans.value.ObservableValue)1 Region (javafx.scene.layout.Region)1