see inputstring in scheduler instead of hpacket.toString() to support structures

This commit is contained in:
sirjonasxx 2020-04-28 03:59:42 +02:00
parent 1066f6f3d2
commit a80ebeb28d
4 changed files with 64 additions and 49 deletions

View File

@ -15,7 +15,7 @@ import gearth.protocol.HPacket;
/**
* Created by Jonas on 07/04/18.
*/
public class ScheduleItem implements StringifyAble {
public class ScheduleItem {
private SimpleIntegerProperty indexProperty;
private SimpleBooleanProperty pausedProperty;
@ -23,11 +23,13 @@ public class ScheduleItem implements StringifyAble {
private SimpleObjectProperty<HPacket> packetProperty;
private SimpleObjectProperty<HMessage.Direction> destinationProperty;
public ScheduleItem() {}
public ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
construct(index, paused, delay, packet, destination);
}
private void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
protected void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
this.indexProperty = new SimpleIntegerProperty(index);
this.pausedProperty = new SimpleBooleanProperty(paused);
this.delayProperty = new SimpleObjectProperty<>(delay);
@ -35,10 +37,6 @@ public class ScheduleItem implements StringifyAble {
this.destinationProperty = new SimpleObjectProperty<>(destination);
}
public ScheduleItem(String stringifyAbleRepresentation) {
constructFromString(stringifyAbleRepresentation);
}
public SimpleIntegerProperty getIndexProperty() {
return indexProperty;
}
@ -58,34 +56,4 @@ public class ScheduleItem implements StringifyAble {
public SimpleObjectProperty<HMessage.Direction> getDestinationProperty() {
return destinationProperty;
}
@Override
public String stringify() {
StringBuilder b = new StringBuilder();
b .append(indexProperty.get())
.append("\t")
.append(pausedProperty.get() ? "true" : "false")
.append("\t")
.append(delayProperty.get().toString())
.append("\t")
.append(packetProperty.get().toString())
.append("\t")
.append(destinationProperty.get().name());
return b.toString();
}
@Override
public void constructFromString(String str) {
String[] parts = str.split("\t");
if (parts.length == 5) {
int index = Integer.parseInt(parts[0]);
boolean paused = parts[1].equals("true");
Interval delay = new Interval(parts[2]);
HPacket packet = new HPacket(parts[3]);
HMessage.Direction direction = parts[4].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
construct(index, paused, delay, packet, direction);
}
}
}

View File

@ -1,5 +1,6 @@
package gearth.ui.scheduler;
import gearth.misc.StringifyAble;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
@ -9,14 +10,24 @@ import gearth.services.scheduler.listeners.OnBeingUpdatedListener;
import gearth.services.scheduler.listeners.OnDeleteListener;
import gearth.services.scheduler.listeners.OnEditListener;
import gearth.services.scheduler.listeners.OnUpdatedListener;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
public class InteractableScheduleItem extends ScheduleItem {
public InteractableScheduleItem(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
public class InteractableScheduleItem extends ScheduleItem implements StringifyAble {
private SimpleStringProperty packetAsStringProperty;
public InteractableScheduleItem(int index, boolean paused, Interval delay, HPacket packet, String inputPacket, HMessage.Direction destination) {
super(index, paused, delay, packet, destination);
this.packetAsStringProperty = new SimpleStringProperty(inputPacket);
}
public InteractableScheduleItem(String stringifyAbleRepresentation) {
super(stringifyAbleRepresentation);
constructFromString(stringifyAbleRepresentation);
}
public SimpleStringProperty getPacketAsStringProperty() {
return packetAsStringProperty;
}
private Observable<OnDeleteListener> onDeleteObservable = new Observable<>(OnDeleteListener::onDelete);
@ -51,4 +62,38 @@ public class InteractableScheduleItem extends ScheduleItem {
onBeingUpdatedObservable.fireEvent();
}
@Override
public String stringify() {
StringBuilder b = new StringBuilder();
b .append(getIndexProperty().get())
.append("\t")
.append(getPausedProperty().get() ? "true" : "false")
.append("\t")
.append(getDelayProperty().get().toString())
.append("\t")
.append(getPacketProperty().get().toString())
.append("\t")
.append(getDestinationProperty().get().name())
.append("\t")
.append(getPacketAsStringProperty().get());
return b.toString();
}
@Override
public void constructFromString(String str) {
String[] parts = str.split("\t");
if (parts.length == 6) {
int index = Integer.parseInt(parts[0]);
boolean paused = parts[1].equals("true");
Interval delay = new Interval(parts[2]);
HPacket packet = new HPacket(parts[3]);
HMessage.Direction direction = parts[4].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
String packetAsString = parts[5];
construct(index, paused, delay, packet, direction);
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
}
}
}

View File

@ -17,15 +17,15 @@ import gearth.ui.buttons.PauseResumeButton;
*/
public class ScheduleItemContainer extends GridPane {
public static final int[] columnWidths = {10, 39, 16, 18, 15};
InteractableScheduleItem item;
private static final int[] columnWidths = {10, 39, 16, 18, 15};
private InteractableScheduleItem item;
Label indexLabel;
Label packetLabel;
Label delayLabel;
Label destinationLabel;
private Label indexLabel;
private Label packetLabel;
private Label delayLabel;
private Label destinationLabel;
VBox parent;
private VBox parent;
ScheduleItemContainer(InteractableScheduleItem item, VBox parent, ScrollPane scrollPane) {
super();
@ -51,7 +51,7 @@ public class ScheduleItemContainer extends GridPane {
}
indexLabel = initNewLabelColumn(item.getIndexProperty().get()+"");
packetLabel = initNewLabelColumn(item.getPacketProperty().get().toString());
packetLabel = initNewLabelColumn(item.getPacketAsStringProperty().get());
delayLabel = initNewLabelColumn(item.getDelayProperty().get()+"");
destinationLabel = initNewLabelColumn(item.getDestinationProperty().get().name());
@ -63,7 +63,7 @@ public class ScheduleItemContainer extends GridPane {
// getChildren().addAll(indexLabel, packetLabel, delayLabel, destinationLabel);
item.getIndexProperty().addListener(observable -> indexLabel.setText(item.getIndexProperty().get()+""));
item.getPacketProperty().addListener(observable -> packetLabel.setText(item.getPacketProperty().get().toString()));
item.getPacketAsStringProperty().addListener(observable -> packetLabel.setText(item.getPacketAsStringProperty().get()));
item.getDelayProperty().addListener(observable -> delayLabel.setText(item.getDelayProperty().get()+""));
item.getDestinationProperty().addListener(observable -> destinationLabel.setText(item.getDestinationProperty().get().name()));

View File

@ -116,6 +116,7 @@ public class SchedulerController extends SubForm {
false,
new Interval(txt_delay.getText()),
new HPacket(txt_packet.getText()),
txt_packet.getText(),
rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER);
addItem(newItem);
@ -123,6 +124,7 @@ public class SchedulerController extends SubForm {
else {
isBeingEdited.getPacketProperty().set(new HPacket(txt_packet.getText()));
isBeingEdited.getPacketAsStringProperty().set(txt_packet.getText());
isBeingEdited.getDelayProperty().set(new Interval(txt_delay.getText()));
isBeingEdited.getDestinationProperty().set(rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER);
isBeingEdited.isUpdatedTrigger();
@ -154,7 +156,7 @@ public class SchedulerController extends SubForm {
}
if (isBeingEdited != newItem) {
txt_packet.setText(newItem.getPacketProperty().get().toString());
txt_packet.setText(newItem.getPacketAsStringProperty().get());
txt_delay.setText(newItem.getDelayProperty().get().toString());
rb_incoming.setSelected(newItem.getDestinationProperty().get() == HMessage.Direction.TOCLIENT);
rb_outgoing.setSelected(newItem.getDestinationProperty().get() == HMessage.Direction.TOSERVER);