use of javafx.scene.control.ToggleGroup in project trex-stateless-gui by cisco-system-traffic-generator.
the class MultiplierView method buildUI.
/**
* Build UI
*/
private void buildUI() {
// add slider area
addLabel("Bandwidth", 7, 336);
addLabel("0", 22, 287);
addLabel("100", 22, 454);
slider = new Slider(0, 100, 1);
slider.setDisable(true);
getChildren().add(slider);
MultiplierView.setTopAnchor(slider, 22d);
MultiplierView.setLeftAnchor(slider, 304d);
slider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
// check min value for slider
if ((double) newValue < MultiplierType.percentage.getMinRate(rate)) {
slider.setValue(MultiplierType.percentage.getMinRate(rate));
}
updateOptionsValues(slider.getValue(), updateAll);
if (fireUpdateCommand) {
optionValueChangeHandler.optionValueChanged();
}
}
});
// add separator
Separator separator = new Separator(Orientation.HORIZONTAL);
separator.setPrefHeight(1);
getChildren().add(separator);
MultiplierView.setTopAnchor(separator, 50d);
MultiplierView.setLeftAnchor(separator, 15d);
MultiplierView.setRightAnchor(separator, 15d);
group = new ToggleGroup();
int index = 0;
double prevComponentWidth = 0;
AnchorPane optionContainer = new AnchorPane();
getChildren().add(optionContainer);
MultiplierView.setTopAnchor(optionContainer, 51d);
MultiplierView.setLeftAnchor(optionContainer, 15d);
MultiplierView.setRightAnchor(optionContainer, 150d);
for (MultiplierType type : MultiplierType.values()) {
MultiplierOption option = new MultiplierOption(type.getTitle(), group, type, this);
option.setMultiplierSelectionEvent(this);
optionContainer.getChildren().add(option);
double leftSpace = prevComponentWidth + (index * 15);
MultiplierView.setLeftAnchor(option, leftSpace);
MultiplierView.setTopAnchor(option, 0d);
MultiplierView.setBottomAnchor(option, 0d);
multiplierOptionMap.put(type, option);
index++;
prevComponentWidth += option.getComponentWidth();
}
multiplierOptionMap.get(MultiplierType.pps).setSelected();
// add suration
Separator vSeparator = new Separator(Orientation.VERTICAL);
vSeparator.setPrefWidth(1);
getChildren().add(vSeparator);
MultiplierView.setTopAnchor(vSeparator, 93d);
MultiplierView.setLeftAnchor(vSeparator, 560d);
MultiplierView.setBottomAnchor(vSeparator, 15d);
addLabel("Duration", 70, 606);
durationCB = new CheckBox();
getChildren().add(durationCB);
MultiplierView.setTopAnchor(durationCB, 94d);
MultiplierView.setLeftAnchor(durationCB, 581d);
MultiplierView.setBottomAnchor(durationCB, 20d);
durationTF = new TextField("0");
durationTF.setPrefSize(70, 22);
durationTF.setDisable(true);
getChildren().add(durationTF);
MultiplierView.setTopAnchor(durationTF, 93d);
MultiplierView.setLeftAnchor(durationTF, 606d);
MultiplierView.setBottomAnchor(durationTF, 15d);
durationTF.disableProperty().bind(durationCB.selectedProperty().not());
durationTF.setTextFormatter(Util.getNumberFilter(4));
}
use of javafx.scene.control.ToggleGroup in project trex-stateless-gui by cisco-system-traffic-generator.
the class MultiplierOption method buildUI.
/**
* Build multiplier view UI
*
* @param title
* @param group
*/
private void buildUI(String title, ToggleGroup group) {
// add radio button
selection = new RadioButton(title);
selection.setToggleGroup(group);
selection.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (newValue) {
multiplierSelectionEvent.onMultiplierSelect(type);
}
value.setDisable(!newValue);
});
setTooltip();
getChildren().add(selection);
MultiplierOption.setTopAnchor(selection, 15d);
MultiplierOption.setLeftAnchor(selection, 0d);
// text field
value = new TextField();
value.setPrefSize(120, 22);
value.setDisable(true);
value.addEventFilter(KeyEvent.KEY_RELEASED, multiplierSelectionEvent.validateInput());
String regex = unitRegex();
final UnaryOperator<TextFormatter.Change> keyPressFilter = c -> {
String text = c.getControlNewText();
if (text.matches(regex)) {
return c;
} else {
return null;
}
};
value.setTextFormatter(new TextFormatter<>(keyPressFilter));
getChildren().add(value);
MultiplierOption.setTopAnchor(value, 43d);
MultiplierOption.setLeftAnchor(value, 0d);
MultiplierOption.setBottomAnchor(value, 15d);
}
Aggregations