SerializedPduView is a control for displaying SerializedPdu objects.
You can import PetepLib.jar to Gluon Scene Builder and then add the SerializedPduView into your templates through it.
/**
* Serialized PDU view for displaying {@link SerializedPdu}.
*/
@PetepAPI
public class SerializedPduView extends AnchorPane {
private SerializedPdu serializedPdu;
@FXML
private TextField proxyField;
@FXML
private TextField connectionField;
@FXML
private TextField destinationField;
@FXML
private TextField interceptorField;
@FXML
private TextField sizeField;
@FXML
private TextField tagsField;
@FXML
private BytesEditor bytesEditor;
@FXML
private TextArea metadataArea;
@FXML
private AnchorPane metadataPane;
/**
* Constructs view without any PDU.
* @throws IOException If the template could not be loaded
*/
public SerializedPduView() throws IOException {
var loader = new FXMLLoader(getClass().getResource("/fxml/control/SerializedPduView.fxml"));
loader.setRoot(this);
loader.setController(this);
loader.setClassLoader(getClass().getClassLoader());
loader.load();
metadataPane.managedProperty().bind(metadataPane.visibleProperty());
metadataPane.setVisible(false);
}
/**
* Sets PDU to pane.
* @param serializedPdu Serialized PDU to be displayed
*/
public void setSerializedPdu(SerializedPdu serializedPdu) {
this.serializedPdu = serializedPdu;
if (serializedPdu.getProxy() != null) {
proxyField.setText(serializedPdu.getProxy());
}
if (serializedPdu.getConnection() != null) {
connectionField.setText(serializedPdu.getConnection());
}
if (serializedPdu.getDestination() != null) {
destinationField.setText(serializedPdu.getDestination().name());
}
if (serializedPdu.getInterceptor() != null) {
interceptorField.setText(serializedPdu.getInterceptor());
}
if (serializedPdu.getTags() != null) {
tagsField.setText(tagsToString(serializedPdu.getTags()));
}
if (serializedPdu.getBuffer() != null) {
bytesEditor.setData(serializedPdu.getBuffer(), serializedPdu.getCharset());
sizeField.setText(String.valueOf(serializedPdu.getBuffer().length));
}
if (serializedPdu.getMetadata() != null && !serializedPdu.getMetadata().isEmpty()) {
metadataPane.setVisible(true);
metadataArea.setText(GuiUtils.formatMetadata(serializedPdu.getMetadata()));
} else {
metadataPane.setVisible(false);
}
}
/**
* Obtains serialized PDU, which is currently displayed in the view.
* @return Serialized PDU
*/
public Optional<SerializedPdu> getSerializedPdu() {
return Optional.ofNullable(serializedPdu);
}
/**
* Clears the view.
*/
public void clear() {
serializedPdu = null;
proxyField.setText("");
connectionField.setText("");
destinationField.setText("");
interceptorField.setText("");
tagsField.setText("");
bytesEditor.clear();
sizeField.setText("");
metadataArea.setText("");
}
/**
* Converts tags to formatted string.
*/
protected String tagsToString(Set<String> tags) {
var tagJoiner = new StringJoiner(", ");
tags.forEach(tagJoiner::add);
return tagJoiner.toString();
}
}