diff --git a/G-Earth/src/main/java/gearth/services/scheduler/ScheduleItem.java b/G-Earth/src/main/java/gearth/services/scheduler/ScheduleItem.java index f28df1e..1c85f61 100644 --- a/G-Earth/src/main/java/gearth/services/scheduler/ScheduleItem.java +++ b/G-Earth/src/main/java/gearth/services/scheduler/ScheduleItem.java @@ -11,6 +11,7 @@ import javafx.beans.property.SimpleObjectProperty; import gearth.misc.StringifyAble; import gearth.protocol.HMessage; import gearth.protocol.HPacket; +import javafx.beans.property.SimpleStringProperty; /** * Created by Jonas on 07/04/18. @@ -20,20 +21,20 @@ public class ScheduleItem { private SimpleIntegerProperty indexProperty; private SimpleBooleanProperty pausedProperty; private SimpleObjectProperty delayProperty; - private SimpleObjectProperty packetProperty; private SimpleObjectProperty destinationProperty; + private SimpleStringProperty packetAsStringProperty; public ScheduleItem() {} - public ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) { - construct(index, paused, delay, packet, destination); + public ScheduleItem (int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) { + construct(index, paused, delay, packetAsString, destination); } - protected void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) { + protected void construct(int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) { this.indexProperty = new SimpleIntegerProperty(index); this.pausedProperty = new SimpleBooleanProperty(paused); this.delayProperty = new SimpleObjectProperty<>(delay); - this.packetProperty = new SimpleObjectProperty<>(packet); + this.packetAsStringProperty = new SimpleStringProperty(packetAsString); this.destinationProperty = new SimpleObjectProperty<>(destination); } @@ -49,8 +50,8 @@ public class ScheduleItem { return delayProperty; } - public SimpleObjectProperty getPacketProperty() { - return packetProperty; + public SimpleStringProperty getPacketAsStringProperty() { + return packetAsStringProperty; } public SimpleObjectProperty getDestinationProperty() { diff --git a/G-Earth/src/main/java/gearth/services/scheduler/Scheduler.java b/G-Earth/src/main/java/gearth/services/scheduler/Scheduler.java index 7e46b4e..6a0ff04 100644 --- a/G-Earth/src/main/java/gearth/services/scheduler/Scheduler.java +++ b/G-Earth/src/main/java/gearth/services/scheduler/Scheduler.java @@ -2,6 +2,7 @@ package gearth.services.scheduler; import gearth.protocol.HConnection; import gearth.protocol.HMessage; +import gearth.protocol.HPacket; import java.util.ArrayList; import java.util.HashSet; @@ -36,11 +37,13 @@ public class Scheduler { Interval cur = item.getDelayProperty().get(); for (int i = 0; i < changed; i++) { if ((t - i) % cur.getDelay() == cur.getOffset()) { + HPacket hPacket = new HPacket(item.getPacketAsStringProperty().getName()); + if (item.getDestinationProperty().get() == HMessage.Direction.TOSERVER) { - connection.sendToServerAsync(item.getPacketProperty().get()); + connection.sendToServer(hPacket); } else { - connection.sendToClientAsync(item.getPacketProperty().get()); + connection.sendToClient(hPacket); } } } diff --git a/G-Earth/src/main/java/gearth/ui/scheduler/InteractableScheduleItem.java b/G-Earth/src/main/java/gearth/ui/scheduler/InteractableScheduleItem.java index d663145..0b82bdc 100644 --- a/G-Earth/src/main/java/gearth/ui/scheduler/InteractableScheduleItem.java +++ b/G-Earth/src/main/java/gearth/ui/scheduler/InteractableScheduleItem.java @@ -15,21 +15,15 @@ import javafx.beans.property.SimpleStringProperty; 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(int index, boolean paused, Interval delay, String inputPacket, HMessage.Direction destination) { + super(index, paused, delay, inputPacket, destination); } public InteractableScheduleItem(String stringifyAbleRepresentation) { constructFromString(stringifyAbleRepresentation); } - public SimpleStringProperty getPacketAsStringProperty() { - return packetAsStringProperty; - } - private Observable onDeleteObservable = new Observable<>(OnDeleteListener::onDelete); public void onDelete(OnDeleteListener listener) { onDeleteObservable.addListener(listener); @@ -72,8 +66,6 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA .append("\t") .append(getDelayProperty().get().toString()) .append("\t") -// .append(getPacketProperty().get().toString()) -// .append("\t") .append(getDestinationProperty().get().name()) .append("\t") .append(getPacketAsStringProperty().get()); @@ -87,13 +79,10 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA 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[3].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT; String packetAsString = parts[4]; - HPacket packet = new HPacket(packetAsString); - construct(index, paused, delay, packet, direction); - this.packetAsStringProperty = new SimpleStringProperty(packetAsString); + construct(index, paused, delay, packetAsString, direction); } }