Development Guide

Example - First PDU

Let's create our own PDU that will be based on DefaultPdu. It will add one String and one integer parameter.

pdu.ExamplePdu
public class ExamplePdu extends DefaultPdu {
  private String stringParam;
  private int integerParam;

  public ExamplePdu(
      Proxy proxy,
      Connection connection,
      PduDestination destination,
      byte[] buffer,
      int size,
      String stringParam,
      int integerParam) {
    super(proxy, connection, destination, buffer, size);

    this.stringParam = stringParam;
    this.integerParam = integerParam;
  }

  public ExamplePdu(
      Proxy proxy,
      Connection connection,
      PduDestination destination,
      byte[] buffer,
      int size,
      Set<String> tags,
      String stringParam,
      int integerParam) {
    super(proxy, connection, destination, buffer, size, tags);

    this.stringParam = stringParam;
    this.integerParam = integerParam;
  }

  public void setStringParam(String param) {
    stringParam = param;
  }

  public void setIntegerParam(int param) {
    integerParam = param;
  }

  public String getStringParam() {
    return stringParam;
  }

  public int getIntegerParam() {
    return integerParam;
  }

  @Override
  public PDU copy() {
    ExamplePdu pdu =
        new ExamplePdu(proxy, connection, destination, buffer, size, stringParam, integerParam);
    pdu.addTags(tags);
    return pdu;
  }
}

And now, let's create metadata editor (for our string and integer values):

pdu.ExamplePduMetadataPane
public class ExamplePduMetadataPane extends PduMetadataPane {
  @FXML private TextField stringInput;
  @FXML private TextField integerInput;

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

  @Override
  public PDU getPdu(
      Proxy proxy, Connection connection, PduDestination destination, byte[] buffer, int size) {
    return new ExamplePdu(
        proxy,
        connection,
        destination,
        buffer,
        size,
        stringInput.getText(),
        Integer.parseInt(integerInput.getText()));
  }

  @Override
  public void setPdu(PDU pdu) {
    stringInput.setText(((ExamplePdu) pdu).getStringParam());
    integerInput.setText(String.valueOf(((ExamplePdu) pdu).getIntegerParam()));
  }

  @Override
  public void clear() {
    stringInput.clear();
    integerInput.clear();
  }
}

It is up to you how you make your medatada editor look, here is an example:

fxml/ExamplePduMetadataPane.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="69.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="String:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="13.0" />
      <TextField fx:id="stringInput" layoutX="90.0" layoutY="2.0" text="" AnchorPane.leftAnchor="85.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" />
      <Label layoutX="10.0" layoutY="43.0" styleClass="input-label" text="Integer:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="43.0" />
      <TextField fx:id="integerInput" layoutX="85.0" layoutY="39.0" prefHeight="25.0" prefWidth="154.0" text="1" AnchorPane.leftAnchor="85.0" AnchorPane.rightAnchor="10.0" />
   </children>
</fx:root>

We will use our Pdu and Metadata Pane in the following chapters.

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