Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8216507: StyleablePropertyFactory: example in class javadoc does not …
…compile

Reviewed-by: angorya, aghaisas
  • Loading branch information
karthikpandelu authored and Andy Goryachev committed Jan 4, 2023
1 parent 012fa16 commit 94fb7ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Expand Up @@ -121,12 +121,14 @@ public final class MyButton extends Button {
* <pre><code>
public final class MyButton extends Button {
private static {@literal CssMetaData<MyButton, Boolean>} SELECTED;
private static final {@literal StyleablePropertyFactory<MyButton>} FACTORY =
new {@literal StyleablePropertyFactory<>}(Button.getClassCssMetaData()) {
{
createBooleanCssMetaData("-my-selected", s {@literal ->} s.selected, false, false);
SELECTED = createBooleanCssMetaData("-my-selected", s {@literal ->} s.selected, false, false);
}
}
};
MyButton(String labelText) {
Expand All @@ -141,7 +143,7 @@ public final class MyButton extends Button {
// StyleableProperty implementation reduced to one line
private final {@literal StyleableProperty<Boolean>} selected =
new SimpleStyleableBooleanProperty(this, "selected", "my-selected");
new SimpleStyleableBooleanProperty(SELECTED, "selected", "my-selected");
public static {@literal List<CssMetaData<? extends Styleable, ?>>} getClassCssMetaData() {
return FACTORY.getCssMetaData();
Expand Down
Expand Up @@ -57,6 +57,7 @@
import javafx.css.Styleable;
import javafx.css.StyleableProperty;
import javafx.css.StyleablePropertyFactory;
import javafx.css.SimpleStyleableBooleanProperty;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -125,7 +126,8 @@ public void describeTo(Description description) {
},
{new Data("myNumber", "-my-number: 2em;", Font.getDefault().getSize()*2)},
{new Data("myString", "-my-string: \"yaba daba do\";", "yaba daba do")},
{new Data("myUrl", "-my-url: url('http://www.oracle.com');", "http://www.oracle.com")}
{new Data("myUrl", "-my-url: url('http://www.oracle.com');", "http://www.oracle.com")},
{new Data("mySelected", "-my-selected: false;", Boolean.FALSE)}
});

}
Expand Down Expand Up @@ -204,6 +206,17 @@ public MyStyleable() {
public void setMyUrl(String value) { myUrl.setValue(value); }
private final StyleableProperty<String> myUrl = fac.createStyleableUrlProperty(this, "myUrl", "-my-url", s -> ((MyStyleable) s).myUrl);

private static CssMetaData<MyStyleable, Boolean> SELECTED;
private static final StyleablePropertyFactory<MyStyleable> FACTORY = new StyleablePropertyFactory<>(null){
{
SELECTED = createBooleanCssMetaData("-my-selected", s -> ((MyStyleable) s).mySelected, false, false);
}
};
public ObservableValue<Boolean> mySelectedProperty() { return (ObservableValue<Boolean>)mySelected; }
public final boolean getMySelected() { return mySelected.getValue(); }
public final void setMySelected(boolean isSelected) { mySelected.setValue(isSelected); }
private final StyleableProperty<Boolean> mySelected = new SimpleStyleableBooleanProperty(SELECTED, "mySelected", "my-selected");

@Override
public String getTypeSelector() {
return "MyStyleable";
Expand Down

1 comment on commit 94fb7ed

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.