0

I was trying to simplify my markup for an options application I'm writing and decided to subclass some JavaFX components with custom attributes. The way to do this, apparently, is to provide getters and setters for the attributes like in my interface:

public interface ConfigNode {
    public String getSection();
    public void setSection(String section);

    public String getKey();
    public void setKey(String key);

    public Wini getConfig();
    public void setConfig(Wini config);
}

The corresponding fxml code:

<GridPane fx:id="root" xmlns:fx="http://javafx.com/fxml" fx:controller="org.syntax_austria.league_config.OptionController" disable="true">
    <ResolutionBox />
    <QualityBox section="Performance" key="ShadowsEnabled" />
</GridPane>

This doesn't work, though, telling me that both attributes are read-only.

I found some example where the setters took Objects as parameters and tried that, to no avail. Help would be appreciated.

EDIT: since asked, here is one implementer:

public class ModeBox<T> extends ChoiceBox<T> implements ConfigNode {
    String section;
    String key;
    Wini config;

    @Override
    public String getSection() {
        return section;
    }

    @Override
    public void setSection(String section) {
        if(section instanceof String)
            this.section = (String)section;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public void setKey(String key) {
        if(key instanceof String)
            this.key = (String)key;
    }

    @Override
    public Wini getConfig() {
        return config;
    }

    @Override
    public void setConfig(Wini config) {
        this.config = config;
        getSelectionModel().select(config.get(section, key, Integer.class));
        getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) {
                getConfig().put(section, key, number2.intValue());
            }
        });
    }
}

And QualityBox, which extends that:

public class QualityBox extends ModeBox<String> {
    public QualityBox() {
        setItems(FXCollections.observableArrayList("Very Low", "Low", "Medium", "High", "Very High"));
    }
}
4

1 回答 1

0

Question solved itself (sort of)

After trying out some things, I did another clean of my project and it now executes properly.

IntelliJ IDEA still complains about the properties being read-only and after a bit of digging this seems to be a problem with the annotation inspector.

于 2013-09-15T19:38:14.383 回答