Custom Component: SelectableTitledPane

I’m working on a form to provide search criteria to find pictures in picmodo.
My goal is to provide a very easy to use interface.

Each search criteria is represented by a SelectableTitledPane which contains the parameter settings.
Basically I have set a CheckBox as graphic component of a TitlePane and modified the CSS of the Default-Skin com.sun.javafx.scene.control.skin.TitledPaneSkin.

picmodo search panel

The Checkbox‘s selectedProperty is bound to the expandedProperty of TitledPane to toggle the expand state and to get an indicator to enable / disable the criteria:

public class SelectableTitledPane extends TitledPane {

  private CheckBox checkBox;

  public SelectableTitledPane(String title, Node content) {
    super(title, content);
    checkBox = new CheckBox(title);
    checkBox.selectedProperty().
            bindBidirectional(this.expandedProperty());
    setExpanded(false);
    setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    setGraphic(checkBox);
    setSkin(new TitledPaneSkin(this));
    lookup(".arrow").
            setVisible(false);
    lookup(".title").
            setStyle("-fx-padding: 0 0 4 -10;"
            + "-fx-background-color: null;");
    lookup(".content").
            setStyle("-fx-background-color: null; -fx-padding:  0.2em 0.2em 0.2em 1.316667em;");
  }

  public BooleanProperty getSelectedProperty() {
    return checkBox.selectedProperty();
  }

  public boolean isSelected() {
    return checkBox.isSelected();
  }

  public void setSelected(boolean selected) {
    checkBox.setSelected(selected);
  }
}

Basically the SelectableTitledPane can then be used as a TitledPane, e.g.:

ComboBox ownerBox = ComboBoxBuilder.<AppUser>create().
            prefWidth(150).
            promptText(resourceBundle
            .getString("search.prompt.owner")).
            build();

SelectableTitledPaneownerParams = new SelectableTitledPane(resourceBundle
            .getString("search.checkbox.owner"), ownerBox);

Custom Component: Starter with hover effect

I was looking for a starter component for to use on the dock like main entry page of our application. It should have a hover effect on mouse enter/ mouse exit and a start effect on mouse click.

As JavaFX has already very useful Transition implementations I gave the ScaleTransition a try. I wanted a smooth expand and shrink effect on mouse enter and exit. Unfortunately transitions can on be played backwards. Reverse play is only supported when using the auto reverse option combined with an appropriate cycle count.

But I saw that changing the properties of an existing ScaleTransition instance and playFromStart() is a working approach:

        setOnMouseEntered(new EventHandler()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(expandToMaxProperty.get());
                scaleTransition.setToY(expandToMaxProperty.get());
                scaleTransition.playFromStart();
            }
        });

        setOnMouseExited(new EventHandler()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(1);
                scaleTransition.setToY(1);
                scaleTransition.playFromStart();
            }
        });

The start effect played on mouse click is a combination of both sequential and parallel played transitions: scale and fade out are played in parallel and in the end the starter goes back to an initial position:

        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);
      
        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(scaleTransition,
                fadeTransition);

        initTransition = new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

Whole Starter code

public class Starter extends StackPane
{

    private ParallelTransition startTransition;
    private ScaleTransition scaleTransition;
    private ScaleTransition initTransition;
    private FadeTransition fadeTransition;
    private SequentialTransition startsSequentialTransition;
    private DoubleProperty expandToMaxProperty;
    private ImageView baseImage;

    public Starter(String base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    public Starter(Image base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    private void init(double fitWidth, double fitHeight)
    {
        expandToMaxProperty = new SimpleDoubleProperty(1.2);

        baseImage.setFitWidth(fitWidth);
        baseImage.setFitHeight(fitHeight);

        Color selectedColor = Color.rgb(0, 0, 0, 0.5);
        DropShadow dropShadow = DropShadowBuilder.create()
                .color(selectedColor)
                .build();
        setEffect(dropShadow);

        dropShadow.radiusProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetXProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetYProperty()
                .bind(scaleYProperty()
                .multiply(8));

        scaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        scaleTransition.setCycleCount(1);
        scaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);



        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(scaleTransition,
                fadeTransition);

        initTransition =
                new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

        getChildren()
                .addAll(baseImage);

        setOnMouseEntered(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(expandToMaxProperty.get());
                scaleTransition.setToY(expandToMaxProperty.get());
                scaleTransition.playFromStart();
            }
        });

        setOnMouseExited(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(1);
                scaleTransition.setToY(1);
                scaleTransition.playFromStart();
            }
        });

        setOnMouseClicked(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent t)
            {
                scaleTransition.setFromX(getScaleX());
                scaleTransition.setFromY(getScaleY());
                scaleTransition.setToX(2);
                scaleTransition.setToY(2);
                fadeTransition.setFromValue(1.0f);
                fadeTransition.setToValue(0.5f);
                startsSequentialTransition.playFromStart();
            }
        });
    }

    public DoubleProperty expandToMaxProperty()
    {
        return expandToMaxProperty;
    }
}

[ U P D A T E 21-10-2014]

Made some modifications to get the Starter running on Java 8:

public class Starter extends StackPane
{

    private ParallelTransition startTransition;
    private ScaleTransition scaleTransition;
    private ScaleTransition startScaleTransition;
    private ScaleTransition initTransition;
    private FadeTransition fadeTransition;
    private SequentialTransition startsSequentialTransition;
    private DoubleProperty expandToMaxProperty;
    private final ImageView baseImage;

    public Starter(String base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    public Starter(Image base, double fitWidth, double fitHeight)
    {
        baseImage = new ImageView(base);
        init(fitWidth, fitHeight);
    }

    private void init(double fitWidth, double fitHeight)
    {
        expandToMaxProperty = new SimpleDoubleProperty(1.2);

        baseImage.setFitWidth(fitWidth);
        baseImage.setFitHeight(fitHeight);

        Color selectedColor = Color.rgb(0, 0, 0, 0.5);
        DropShadow dropShadow = DropShadowBuilder.create()
                .color(selectedColor)
                .build();
        setEffect(dropShadow);

        dropShadow.radiusProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetXProperty()
                .bind(scaleXProperty()
                .multiply(8));
        dropShadow.offsetYProperty()
                .bind(scaleYProperty()
                .multiply(8));

        scaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        scaleTransition.setCycleCount(1);
        scaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startScaleTransition =
                new ScaleTransition(Duration.millis(200), this);
        startScaleTransition.setCycleCount(1);
        startScaleTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        fadeTransition = new FadeTransition(Duration.millis(200), this);
        fadeTransition.setCycleCount(1);
        fadeTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startTransition = new ParallelTransition();
        startTransition.setCycleCount(2);
        startTransition.setAutoReverse(true);
        startTransition.getChildren()
                .addAll(startScaleTransition, fadeTransition);

        initTransition =
                new ScaleTransition(Duration.millis(200), this);
        initTransition.setToX(1);
        initTransition.setToY(1);
        initTransition.setCycleCount(1);
        initTransition
                .setInterpolator(Interpolator.EASE_BOTH);

        startsSequentialTransition = new SequentialTransition();
        startsSequentialTransition.getChildren()
                .addAll(
                startTransition,
                initTransition);

        getChildren()
                .addAll(baseImage);

        setOnMouseEntered((MouseEvent t) -> {
            scaleTransition.setFromX(getScaleX());
            scaleTransition.setFromY(getScaleY());
            scaleTransition.setToX(expandToMaxProperty.get());
            scaleTransition.setToY(expandToMaxProperty.get());
            scaleTransition.playFromStart();
        });

        setOnMouseExited((MouseEvent t) -> {
            scaleTransition.setFromX(getScaleX());
            scaleTransition.setFromY(getScaleY());
            scaleTransition.setToX(1);
            scaleTransition.setToY(1);
            scaleTransition.playFromStart();
        });

        setOnMouseClicked((MouseEvent t) -> {
            startScaleTransition.setFromX(getScaleX());
            startScaleTransition.setFromY(getScaleY());
            startScaleTransition.setToX(2);
            startScaleTransition.setToY(2);
            fadeTransition.setFromValue(1.0f);
            fadeTransition.setToValue(0.5f);
            startsSequentialTransition.playFromStart();
        });
    }

    public DoubleProperty expandToMaxProperty()
    {
        return expandToMaxProperty;
    }
}

Find complete code repo at BitBucket.

JavaFX in Action: picmodo-teasers (updated 19-04-2013)

I have uploaded two teasers of my current spare-time project “picmodo” (it’s yet another network based picture DB).
The GUI shown in the clips is in german language, but i18n is supported of course ;-).

Picmodo – Login:

Picmodo – Login failed:

Picmodo – Upload new pictures:

Picmodo – Export Pictures:

Picmodo – Search Pictures: