Search in sources :

Example 6 with ToggleGroup

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));
}
Also used : Slider(javafx.scene.control.Slider) MultiplierOption(com.exalttech.trex.ui.components.MultiplierOption) MultiplierType(com.exalttech.trex.ui.MultiplierType) CheckBox(javafx.scene.control.CheckBox) ToggleGroup(javafx.scene.control.ToggleGroup) TextField(javafx.scene.control.TextField) AnchorPane(javafx.scene.layout.AnchorPane) Separator(javafx.scene.control.Separator)

Example 7 with ToggleGroup

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);
}
Also used : TextField(javafx.scene.control.TextField) MultiplierType(com.exalttech.trex.ui.MultiplierType) Util(com.exalttech.trex.util.Util) UnaryOperator(java.util.function.UnaryOperator) KeyEvent(javafx.scene.input.KeyEvent) TextFormatter(javafx.scene.control.TextFormatter) Logger(org.apache.log4j.Logger) ToggleGroup(javafx.scene.control.ToggleGroup) AnchorPane(javafx.scene.layout.AnchorPane) RadioButton(javafx.scene.control.RadioButton) ObservableValue(javafx.beans.value.ObservableValue) MultiplierSelectionEvent(com.exalttech.trex.ui.components.events.MultiplierSelectionEvent) Tooltip(javafx.scene.control.Tooltip) ObservableValue(javafx.beans.value.ObservableValue) TextField(javafx.scene.control.TextField) RadioButton(javafx.scene.control.RadioButton)

Aggregations

ToggleGroup (javafx.scene.control.ToggleGroup)7 MultiplierType (com.exalttech.trex.ui.MultiplierType)2 TextField (javafx.scene.control.TextField)2 AnchorPane (javafx.scene.layout.AnchorPane)2 MultiplierOption (com.exalttech.trex.ui.components.MultiplierOption)1 MultiplierSelectionEvent (com.exalttech.trex.ui.components.events.MultiplierSelectionEvent)1 Util (com.exalttech.trex.util.Util)1 JFXRadioButton (com.jfoenix.controls.JFXRadioButton)1 AltCoinAccountsView (io.bitsquare.gui.main.account.content.altcoinaccounts.AltCoinAccountsView)1 ArbitratorSelectionView (io.bitsquare.gui.main.account.content.arbitratorselection.ArbitratorSelectionView)1 BackupView (io.bitsquare.gui.main.account.content.backup.BackupView)1 FiatAccountsView (io.bitsquare.gui.main.account.content.fiataccounts.FiatAccountsView)1 PasswordView (io.bitsquare.gui.main.account.content.password.PasswordView)1 SeedWordsView (io.bitsquare.gui.main.account.content.seedwords.SeedWordsView)1 UnaryOperator (java.util.function.UnaryOperator)1 ObservableValue (javafx.beans.value.ObservableValue)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 CheckBox (javafx.scene.control.CheckBox)1 Menu (javafx.scene.control.Menu)1