| 1 |
package de.jensd.fx.glyphs.control.skin; |
| 2 |
|
| 3 |
import de.jensd.fx.glyphs.control.GlyphCheckBox; |
| 4 |
import javafx.beans.value.ObservableValue; |
| 5 |
import javafx.scene.control.skin.CheckBoxSkin; |
| 6 |
import javafx.scene.layout.StackPane; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
public class GlyphCheckBoxSkin extends CheckBoxSkin { |
| 13 |
|
| 14 |
private final StackPane box; |
| 15 |
|
| 16 |
public GlyphCheckBoxSkin(GlyphCheckBox checkbox) { |
| 17 |
super(checkbox); |
| 18 |
box = (StackPane) getChildren().get(getChildren().size() - 1); |
| 19 |
box.getStyleClass().clear(); |
| 20 |
box.getChildren().addAll(checkbox.getNotSelectedIcon()); |
| 21 |
checkbox.armedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { |
| 22 |
handleState(); |
| 23 |
}); |
| 24 |
checkbox.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { |
| 25 |
handleState(); |
| 26 |
}); |
| 27 |
handleState(); |
| 28 |
} |
| 29 |
|
| 30 |
private void handleState(){ |
| 31 |
if (getSkinnable().isSelected()) { |
| 32 |
box.getChildren().setAll(((GlyphCheckBox)getSkinnable()).getSelectedIcon()); |
| 33 |
} else { |
| 34 |
box.getChildren().setAll(((GlyphCheckBox)getSkinnable()).getNotSelectedIcon()); |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
} |