Development Guide

Example - First Config

Our proxy, that we will create in the next chapter, will need to know the number of connection 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
public class ExampleProxyConfig {
  private int connectionCount;

  public ExampleProxyConfig(int connectionCount) {
    this.connectionCount = connectionCount;
  }

  public int getConnectionCount() {
    return connectionCount;
  }
}

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

proxy.config.ExampleProxyConfigurator
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 boolean isValid() {
    return connectionCountInput.getText().matches("-?\\d+");
  }

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

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.AnchorPane?>

<fx:root prefHeight="44.0" prefWidth="249.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/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>
Získejte registraci domén s tld .online, .space, .store, .tech zdarma!
Stačí si k jedné z těchto domén vybrat hosting Plus nebo Mega a registraci domény od nás dostanete za 0 Kč!
Objednat