Development Guide

Example - First Config

Our proxy, that we will create in the next chapter, will need to know the number of fake connections it has to spawn. In order to do this, we will create our own proxy configuration.

Proxy Config

Let's define our proxy configuration that will contain number of fake connection the user wants to spawn.

proxy.config.ExampleProxyConfig
/**
 * Configuration of example proxy.
 */
@AllArgsConstructor
@Getter
public class ExampleProxyConfig {
    private int connectionCount;
}

We need our configuration to be created by user, so let's create ConfigPane:

proxy.config.ExampleProxyConfigurator
/**
 * Configurator for example proxy.
 */
public class ExampleProxyConfigurator extends ConfigPane<ExampleProxyConfig> {
    @FXML
    private TextField connectionCountInput;

    public ExampleProxyConfigurator() throws IOException {
        super("/fxml/ExampleProxyConfigurator.fxml");
    }

    @Override
    public ExampleProxyConfig getConfig() {
        return new ExampleProxyConfig(Integer.valueOf(connectionCountInput.getText()));
    }

    @Override
    public void setConfig(ExampleProxyConfig config) {
        connectionCountInput.setText(String.valueOf(config.getConnectionCount()));
    }

    @Override
    public boolean isValid() {
        return connectionCountInput.getText().matches("-?\\d+");
    }
}

We also have to create the template we specified in the constructor:

fxml/ExampleProxyConfigurator.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>

<fx:root xmlns:fx="http://javafx.com/fxml/1" prefHeight="44.0" prefWidth="249.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/11.0.1">
    <children>
        <Label layoutX="7.0" layoutY="13.0" styleClass="input-label" text="Num of connections:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="13.0"/>
        <TextField fx:id="connectionCountInput" layoutX="129.0" layoutY="2.0" prefHeight="25.0" prefWidth="110.0" text="4" AnchorPane.leftAnchor="129.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"/>
    </children>
</fx:root>