TextValueComponent.java
package edu.ntnu.idi.idatt.view.components.elements;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
/**
* Text-Value Component class.
*
* <p>
* JavaFX Component for handeling repetative tasks.
* Creates two labels with the right side (value) being available for color
* styling.
* </p>
*/
public class TextValueComponent extends HBox {
private final SimpleStringProperty value = new SimpleStringProperty();
private final SimpleStringProperty color = new SimpleStringProperty();
/**
* Constructor for TextValueComponent.
*
* @param prefix - Content of the first label (left side)
*/
public TextValueComponent(String prefix) {
Label prefixLabel = new Label(prefix);
Label valueLabel = new Label();
valueLabel.textProperty().bind(value);
CssUtils.apply(prefixLabel, CssUtils.MED_TEXT_16);
CssUtils.apply(valueLabel, CssUtils.MED_TEXT_16);
color.addListener((obs, oldVal, newVal) -> {
CssUtils.set(valueLabel, newVal);
CssUtils.apply(valueLabel, CssUtils.MED_TEXT_16);
});
this.getChildren().addAll(prefixLabel, valueLabel);
}
/**
* Getter for valueProperty
*
* @return SimpleStringProperty;
*/
public SimpleStringProperty valueProperty() {
return value;
}
/**
* Getter for colorProperty.
*
* @return SimpleStringProperty;
*/
public SimpleStringProperty colorProperty() {
return color;
}
}