change listener<->observable designpattern

This commit is contained in:
sirjonasxx 2020-04-26 22:00:30 +02:00
parent eb8f6afecd
commit be2c8adecb
46 changed files with 274 additions and 235 deletions

View File

@ -1,8 +1,9 @@
package gearth.extensions; package gearth.extensions;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import gearth.services.extensionhandler.extensions.network.NetworkExtensionInfo; import gearth.services.extensionhandler.extensions.implementations.network.NetworkExtensionInfo;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
@ -139,7 +140,7 @@ public abstract class Extension implements IExtension{
int connectionPort = packet.readInteger(); int connectionPort = packet.readInteger();
String hotelVersion = packet.readString(); String hotelVersion = packet.readString();
String harbleMessagesPath = packet.readString(); String harbleMessagesPath = packet.readString();
notifyConnectionListeners(host, connectionPort, hotelVersion, harbleMessagesPath); onConnectionObservable.fireEvent(l -> l.onConnection(host, connectionPort, hotelVersion, harbleMessagesPath));
onStartConnection(); onStartConnection();
} }
else if (packet.headerId() == NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.CONNECTIONEND) { else if (packet.headerId() == NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.CONNECTIONEND) {
@ -367,17 +368,9 @@ public abstract class Extension implements IExtension{
} }
public interface OnConnectionListener { private Observable<OnConnectionListener> onConnectionObservable = new Observable<>();
void act(String host, int port, String hotelversion, String harbleMessagesPath);
}
private List<OnConnectionListener> onConnectionListeners = new ArrayList<>();
public void onConnect(OnConnectionListener listener){ public void onConnect(OnConnectionListener listener){
onConnectionListeners.add(listener); onConnectionObservable.addListener(listener);
}
private void notifyConnectionListeners(String host, int port, String hotelversion, String harbleMessagesPath) {
for (OnConnectionListener listener : onConnectionListeners) {
listener.act(host, port, hotelversion, harbleMessagesPath);
}
} }
} }

View File

@ -40,7 +40,7 @@ public abstract class ExtensionForm implements IExtension{
public boolean sendToClient(HPacket packet){ public boolean sendToClient(HPacket packet){
return extension.sendToClient(packet); return extension.sendToClient(packet);
} }
public void onConnect(Extension.OnConnectionListener listener) { public void onConnect(OnConnectionListener listener) {
extension.onConnect(listener); extension.onConnect(listener);
} }

View File

@ -14,6 +14,6 @@ public interface IExtension {
void intercept(HMessage.Direction direction, Extension.MessageListener messageListener); void intercept(HMessage.Direction direction, Extension.MessageListener messageListener);
boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback); boolean requestFlags(Extension.FlagsCheckListener flagRequestCallback);
void writeToConsole(String s); // not implemented in g-earth yet void writeToConsole(String s); // not implemented in g-earth yet
void onConnect(Extension.OnConnectionListener listener); void onConnect(OnConnectionListener listener);
} }

View File

@ -0,0 +1,5 @@
package gearth.extensions;
public interface OnConnectionListener {
void onConnection(String host, int port, String hotelversion, String harbleMessagesPath);
}

View File

@ -2,12 +2,11 @@ package gearth.extensions.extra.harble;
import gearth.extensions.ExtensionInfo; import gearth.extensions.ExtensionInfo;
import gearth.extensions.IExtension; import gearth.extensions.IExtension;
import gearth.extensions.OnConnectionListener;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by Jonas on 3/12/2018. * Created by Jonas on 3/12/2018.
*/ */
@ -23,6 +22,7 @@ public class ChatConsole {
private volatile String infoMessage; private volatile String infoMessage;
private volatile boolean firstTime = true; private volatile boolean firstTime = true;
private volatile Observable<ChatInputListener> chatInputObservable = new Observable<>();
public ChatConsole(final HashSupport hashSupport, IExtension extension) { public ChatConsole(final HashSupport hashSupport, IExtension extension) {
@ -42,7 +42,6 @@ public class ChatConsole {
this.infoMessage = infoMessage; this.infoMessage = infoMessage;
final boolean[] doOncePerConnection = {false}; final boolean[] doOncePerConnection = {false};
extension.onConnect((s, i, s1, h1) -> doOncePerConnection[0] = true); extension.onConnect((s, i, s1, h1) -> doOncePerConnection[0] = true);
extension.intercept(HMessage.Direction.TOSERVER, hMessage -> { extension.intercept(HMessage.Direction.TOSERVER, hMessage -> {
@ -81,7 +80,7 @@ public class ChatConsole {
writeOutput(infoMessage, false); writeOutput(infoMessage, false);
} }
else { else {
notifyChatInputListeners(str); chatInputObservable.fireEvent(l -> l.inputEntered(str));
} }
} }
}); });
@ -106,17 +105,8 @@ public class ChatConsole {
} }
} }
public interface ChatInputListener {
void inputEntered(String input);
}
private List<ChatInputListener> chatInputListenerList = new ArrayList<ChatInputListener>();
public void onInput(ChatInputListener listener) { public void onInput(ChatInputListener listener) {
chatInputListenerList.add(listener); chatInputObservable.addListener(listener);
}
private void notifyChatInputListeners (String s) {
for (ChatInputListener listener : chatInputListenerList) {
listener.inputEntered(s);
}
} }

View File

@ -0,0 +1,5 @@
package gearth.extensions.extra.harble;
public interface ChatInputListener {
void inputEntered(String input);
}

View File

@ -3,6 +3,7 @@ package gearth.misc;
/** /**
* Created by Jonas on 14/06/18. * Created by Jonas on 14/06/18.
* This interface defines an object which can FULLY be represented as a String (all fields). An object must be able to be recreated having the String representation * This interface defines an object which can FULLY be represented as a String (all fields). An object must be able to be recreated having the String representation
* So this is basically "Serializable" but for Strings
*/ */
public interface StringifyAble { public interface StringifyAble {

View File

@ -0,0 +1,36 @@
package gearth.misc.listenerpattern;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class Observable<Listener> {
private Consumer<Listener> defaultConsumer = null;
public Observable(Consumer<Listener> defaultConsumer) {
this.defaultConsumer = defaultConsumer;
}
public Observable() {
// no default consumer
this(listener -> {});
}
private List<Listener> listeners = new ArrayList<>();
public void addListener(Listener listener) {
listeners.add(listener);
}
public void removeListener(Listener listener) {
listeners.remove(listener);
}
public void fireEvent(Consumer<Listener> consumer) {
for (int i = listeners.size() - 1; i >= 0; i--) {
consumer.accept(listeners.get(i));
}
}
public void fireEvent() {
fireEvent(defaultConsumer);
}
}

View File

@ -0,0 +1,22 @@
package gearth.misc.listenerpattern;
import java.util.function.Consumer;
public class SynchronizedObservable<Listener> extends Observable<Listener> {
public SynchronizedObservable(Consumer<Listener> defaultConsumer) {
super(defaultConsumer);
}
public SynchronizedObservable() {
super();
}
@Override
public void fireEvent(Consumer<Listener> consumer) {
synchronized (this) {
super.fireEvent(consumer);
}
}
}

View File

@ -2,6 +2,7 @@ package gearth.protocol;
import gearth.misc.Cacher; import gearth.misc.Cacher;
import gearth.misc.OSValidator; import gearth.misc.OSValidator;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.hostreplacer.hostsfile.HostReplacer; import gearth.protocol.hostreplacer.hostsfile.HostReplacer;
import gearth.protocol.hostreplacer.hostsfile.HostReplacerFactory; import gearth.protocol.hostreplacer.hostsfile.HostReplacerFactory;
import gearth.protocol.hostreplacer.ipmapping.IpMapper; import gearth.protocol.hostreplacer.ipmapping.IpMapper;
@ -17,9 +18,6 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.*; import java.util.*;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class HConnection { public class HConnection {
@ -122,8 +120,9 @@ public class HConnection {
private static final HostReplacer hostsReplacer = HostReplacerFactory.get(); private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
private volatile boolean hostRedirected = false; private volatile boolean hostRedirected = false;
private volatile Object[] trafficListeners = {new ArrayList<TrafficListener>(), new ArrayList<TrafficListener>(), new ArrayList<TrafficListener>()}; private volatile Object[] trafficObservables = {new Observable<TrafficListener>(), new Observable<TrafficListener>(), new Observable<TrafficListener>()};
private volatile List<StateChangeListener> stateChangeListeners = new ArrayList<>(); private volatile Observable<StateChangeListener> stateObservable = new Observable<>();
private volatile State state = State.NOT_CONNECTED; private volatile State state = State.NOT_CONNECTED;
public static class Proxy { public static class Proxy {
@ -416,8 +415,8 @@ public class HConnection {
final boolean[] aborted = new boolean[1]; final boolean[] aborted = new boolean[1];
Rc4Obtainer rc4Obtainer = new Rc4Obtainer(this); Rc4Obtainer rc4Obtainer = new Rc4Obtainer(this);
OutgoingPacketHandler outgoingHandler = new OutgoingPacketHandler(habbo_server_out, trafficListeners); OutgoingPacketHandler outgoingHandler = new OutgoingPacketHandler(habbo_server_out, trafficObservables);
IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client_out, trafficListeners); IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client_out, trafficObservables);
rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler); rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler);
outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> { outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> {
@ -593,13 +592,15 @@ public class HConnection {
State buffer = this.state; State buffer = this.state;
this.state = state; this.state = state;
for (StateChangeListener listener : stateChangeListeners) { stateObservable.fireEvent(l -> l.stateChanged(buffer, state));
listener.stateChanged(buffer, state);
}
} }
} }
public Observable<StateChangeListener> getStateObservable() {
return stateObservable;
}
/** /**
* 3 orders: * 3 orders:
* 0 = before modification ¹ * 0 = before modification ¹
@ -609,19 +610,12 @@ public class HConnection {
* ¹don't edit the packet (block, replace) * ¹don't edit the packet (block, replace)
*/ */
public void addTrafficListener(int order, TrafficListener listener) { public void addTrafficListener(int order, TrafficListener listener) {
((List<TrafficListener>)trafficListeners[order]).add(listener); ((Observable<TrafficListener>) trafficObservables[order]).addListener(listener);
} }
public void removeTrafficListener(TrafficListener listener) { public void removeTrafficListener(TrafficListener listener) {
((List<TrafficListener>)trafficListeners[0]).remove(listener); ((Observable<TrafficListener>) trafficObservables[0]).removeListener(listener);
((List<TrafficListener>)trafficListeners[1]).remove(listener); ((Observable<TrafficListener>) trafficObservables[1]).removeListener(listener);
((List<TrafficListener>)trafficListeners[2]).remove(listener); ((Observable<TrafficListener>) trafficObservables[2]).removeListener(listener);
}
public void addStateChangeListener(StateChangeListener listener) {
stateChangeListeners.add(listener);
}
public void removeStateChangeListener(StateChangeListener listener) {
stateChangeListeners.remove(listener);
} }
public int getServerPort() { public int getServerPort() {

View File

@ -41,11 +41,11 @@ public class Rc4Obtainer {
public void act() { public void act() {
if (handler.isEncryptedStream()) { if (handler.isEncryptedStream()) {
onSendFirstEncryptedMessage(handler); onSendFirstEncryptedMessage(handler);
handler.removeBufferChangeListener(this); handler.getBufferChangeObservable().removeListener(this);
} }
} }
}; };
handler.onBufferChanged(bufferChangeListener); handler.getBufferChangeObservable().addListener(bufferChangeListener);
} }

View File

@ -1,5 +1,6 @@
package gearth.protocol.packethandler; package gearth.protocol.packethandler;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import gearth.protocol.TrafficListener; import gearth.protocol.TrafficListener;
@ -10,25 +11,25 @@ import java.util.List;
public class IncomingPacketHandler extends PacketHandler { public class IncomingPacketHandler extends PacketHandler {
public IncomingPacketHandler(OutputStream outputStream, Object[] listeners) { public IncomingPacketHandler(OutputStream outputStream, Object[] trafficObservables) {
super(outputStream, listeners); super(outputStream, trafficObservables);
TrafficListener listener = new TrafficListener() { TrafficListener listener = new TrafficListener() {
@Override @Override
public void onCapture(HMessage message) { public void onCapture(HMessage message) {
if (isDataStream && message.getPacket().structureEquals("s,b")) { if (isDataStream && message.getPacket().structureEquals("s,b")) {
((List<TrafficListener>)listeners[0]).remove(this); ((Observable<TrafficListener>)trafficObservables[0]).removeListener(this);
HPacket packet = message.getPacket(); HPacket packet = message.getPacket();
packet.readString(); packet.readString();
isEncryptedStream = packet.readBoolean(); isEncryptedStream = packet.readBoolean();
} }
else if (message.getIndex() > 3) { else if (message.getIndex() > 3) {
((List<TrafficListener>)listeners[0]).remove(this); ((Observable<TrafficListener>)trafficObservables[0]).removeListener(this);
} }
} }
}; };
((List<TrafficListener>)listeners[0]).add(listener); ((Observable<TrafficListener>)trafficObservables[0]).addListener(listener);
} }
@Override @Override

View File

@ -10,8 +10,8 @@ import java.util.List;
public class OutgoingPacketHandler extends PacketHandler { public class OutgoingPacketHandler extends PacketHandler {
public OutgoingPacketHandler(OutputStream outputStream, Object[] listeners) { public OutgoingPacketHandler(OutputStream outputStream, Object[] trafficObservables) {
super(outputStream, listeners); super(outputStream, trafficObservables);
} }
private List<OnDatastreamConfirmedListener> onDatastreamConfirmedListeners = new ArrayList<>(); private List<OnDatastreamConfirmedListener> onDatastreamConfirmedListeners = new ArrayList<>();

View File

@ -1,5 +1,6 @@
package gearth.protocol.packethandler; package gearth.protocol.packethandler;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
@ -17,7 +18,7 @@ public abstract class PacketHandler {
volatile PayloadBuffer payloadBuffer = new PayloadBuffer(); volatile PayloadBuffer payloadBuffer = new PayloadBuffer();
volatile OutputStream out; volatile OutputStream out;
volatile Object[] listeners = null; //get notified on packet send volatile Object[] trafficObservables; //get notified on packet send
volatile boolean isTempBlocked = false; volatile boolean isTempBlocked = false;
volatile boolean isDataStream = false; volatile boolean isDataStream = false;
volatile int currentIndex = 0; volatile int currentIndex = 0;
@ -31,8 +32,8 @@ public abstract class PacketHandler {
protected volatile boolean isEncryptedStream = false; protected volatile boolean isEncryptedStream = false;
public PacketHandler(OutputStream outputStream, Object[] listeners) { public PacketHandler(OutputStream outputStream, Object[] trafficObservables) {
this.listeners = listeners; this.trafficObservables = trafficObservables;
out = outputStream; out = outputStream;
} }
@ -47,7 +48,7 @@ public abstract class PacketHandler {
public abstract void act(byte[] buffer) throws IOException; public abstract void act(byte[] buffer) throws IOException;
protected void continuedAct(byte[] buffer) throws IOException { protected void continuedAct(byte[] buffer) throws IOException {
notifyBufferListeners(); bufferChangeObservable.fireEvent();
if (!isEncryptedStream) { if (!isEncryptedStream) {
payloadBuffer.push(buffer); payloadBuffer.push(buffer);
@ -111,10 +112,10 @@ public abstract class PacketHandler {
*/ */
void notifyListeners(HMessage message) { void notifyListeners(HMessage message) {
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
for (int i = ((List<TrafficListener>)listeners[x]).size() - 1; i >= 0; i--) { ((Observable<TrafficListener>) trafficObservables[x]).fireEvent(trafficListener -> {
message.getPacket().resetReadIndex(); message.getPacket().resetReadIndex();
((List<TrafficListener>)listeners[x]).get(i).onCapture(message); trafficListener.onCapture(message);
} });
} }
message.getPacket().resetReadIndex(); message.getPacket().resetReadIndex();
} }
@ -164,17 +165,9 @@ public abstract class PacketHandler {
protected abstract void printForDebugging(byte[] bytes); protected abstract void printForDebugging(byte[] bytes);
private List<BufferChangeListener> bufferChangeListeners = new ArrayList<>(); private Observable<BufferChangeListener> bufferChangeObservable = new Observable<>(BufferChangeListener::act);
public void onBufferChanged(BufferChangeListener listener) { public Observable<BufferChangeListener> getBufferChangeObservable() {
bufferChangeListeners.add(listener); return bufferChangeObservable;
}
public void removeBufferChangeListener(BufferChangeListener listener) {
bufferChangeListeners.remove(listener);
}
void notifyBufferListeners() {
for (int i = bufferChangeListeners.size() - 1; i >= 0; i -= 1) {
bufferChangeListeners.get(i).act();
}
} }
public int getCurrentIndex() { public int getCurrentIndex() {

View File

@ -0,0 +1,7 @@
package gearth.services.extensionhandler;
import gearth.services.extensionhandler.extensions.GEarthExtension;
public interface ExtensionConnectedListener {
void onExtensionConnect(GEarthExtension e);
}

View File

@ -2,6 +2,7 @@ package gearth.services.extensionhandler;
import gearth.Main; import gearth.Main;
import gearth.misc.harble_api.HarbleAPIFetcher; import gearth.misc.harble_api.HarbleAPIFetcher;
import gearth.misc.listenerpattern.Observable;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
@ -12,12 +13,22 @@ import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionP
import gearth.services.extensionhandler.extensions.GEarthExtension; import gearth.services.extensionhandler.extensions.GEarthExtension;
import java.util.*; import java.util.*;
import java.util.function.Consumer;
public class ExtensionHandler { public class ExtensionHandler {
private final List<GEarthExtension> gEarthExtensions = new ArrayList<>(); private final List<GEarthExtension> gEarthExtensions = new ArrayList<>();
private final HConnection hConnection; private final HConnection hConnection;
private List<ExtensionProducer> extensionProducers; private List<ExtensionProducer> extensionProducers;
private Observable<ExtensionConnectedListener> observable = new Observable<>() {
@Override
public void addListener(ExtensionConnectedListener extensionConnectedListener) {
super.addListener(extensionConnectedListener);
for (GEarthExtension gEarthExtension : gEarthExtensions) {
extensionConnectedListener.onExtensionConnect(gEarthExtension);
}
}
};
public ExtensionHandler(HConnection hConnection) { public ExtensionHandler(HConnection hConnection) {
@ -27,7 +38,7 @@ public class ExtensionHandler {
private void initialize() { private void initialize() {
hConnection.addStateChangeListener((oldState, newState) -> { hConnection.getStateObservable().addListener((oldState, newState) -> {
if (newState == HConnection.State.CONNECTED) { if (newState == HConnection.State.CONNECTED) {
HarbleAPIFetcher.fetch(hConnection.getHotelVersion()); HarbleAPIFetcher.fetch(hConnection.getHotelVersion());
synchronized (gEarthExtensions) { synchronized (gEarthExtensions) {
@ -76,12 +87,12 @@ public class ExtensionHandler {
collection.remove(extension); collection.remove(extension);
} }
extension.removeExtensionListener(this); extension.getExtensionObservable().removeListener(this);
} }
} }
} }
}; };
extension.registerExtensionListener(respondCallback); extension.getExtensionObservable().addListener(respondCallback);
} }
} }
@ -134,7 +145,7 @@ public class ExtensionHandler {
private void initializeExtensionProducer(ExtensionProducer producer) { private void initializeExtensionProducer(ExtensionProducer producer) {
producer.startProducing(new ExtensionProducerObserver() { producer.startProducing(new ExtensionProducerObserver() {
@Override @Override
public void onExtensionConnect(GEarthExtension extension) { public void onExtensionProduced(GEarthExtension extension) {
synchronized (gEarthExtensions) { synchronized (gEarthExtensions) {
gEarthExtensions.add(extension); gEarthExtensions.add(extension);
} }
@ -167,12 +178,12 @@ public class ExtensionHandler {
synchronized (gEarthExtensions) { synchronized (gEarthExtensions) {
gEarthExtensions.remove(extension); gEarthExtensions.remove(extension);
} }
extension.removeExtensionListener(this); extension.getExtensionObservable().removeListener(this);
extension.delete(); extension.getDeletedObservable().fireEvent();
} }
}; };
extension.registerExtensionListener(listener); extension.getExtensionObservable().addListener(listener);
extension.init(); extension.init();
if (hConnection.getState() == HConnection.State.CONNECTED) { if (hConnection.getState() == HConnection.State.CONNECTED) {
@ -184,10 +195,10 @@ public class ExtensionHandler {
); );
} }
extension.onRemoveClick(observable -> extension.close()); extension.getRemoveClickObservable().addListener(extension::close);
extension.onClick(observable -> extension.doubleclick()); extension.getClickedObservable().addListener(extension::doubleclick);
notifyExtensionConnectListeners(extension); observable.fireEvent(l -> l.onExtensionConnect(extension));
} }
}); });
} }
@ -197,24 +208,9 @@ public class ExtensionHandler {
return extensionProducers; return extensionProducers;
} }
public interface ExtensionConnectListener { public Observable<ExtensionConnectedListener> getObservable() {
void extensionConnected(GEarthExtension e); return observable;
}
private List<ExtensionConnectListener> listeners = new ArrayList<>();
public void onExtensionConnected(ExtensionConnectListener extensionConnectListener) {
synchronized (gEarthExtensions) {
for (GEarthExtension gEarthExtension : gEarthExtensions) {
extensionConnectListener.extensionConnected(gEarthExtension);
}
}
listeners.add(extensionConnectListener);
}
public void removeExtensionConnectListener(ExtensionConnectListener extensionConnectListener) {
listeners.remove(extensionConnectListener);
}
private void notifyExtensionConnectListeners(GEarthExtension extension) {
for (int i = listeners.size() - 1; i >= 0; i--) {
listeners.get(i).extensionConnected(extension);
}
} }
} }

View File

@ -1,12 +1,12 @@
package gearth.services.extensionhandler.extensions; package gearth.services.extensionhandler.extensions;
import gearth.misc.listenerpattern.Observable;
import gearth.misc.listenerpattern.SynchronizedObservable;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import javafx.beans.InvalidationListener; import gearth.services.extensionhandler.extensions.listeners.OmRemoveClickListener;
import gearth.services.extensionhandler.extensions.listeners.OnClickListener;
import java.util.ArrayList; import gearth.services.extensionhandler.extensions.listeners.OnDeleteListener;
import java.util.List;
import java.util.function.Consumer;
public abstract class GEarthExtension { public abstract class GEarthExtension {
@ -47,45 +47,36 @@ public abstract class GEarthExtension {
// ----------------- listen to the extension --------------------- // ----------------- listen to the extension ---------------------
protected final List<ExtensionListener> extensionListeners = new ArrayList<>();
public void registerExtensionListener(ExtensionListener listener) {
this.extensionListeners.add(listener);
}
public void removeExtensionListener(ExtensionListener listener) {
this.extensionListeners.remove(listener);
}
private void notifyListeners(Consumer<ExtensionListener> consumer) {
for (int i = extensionListeners.size() - 1; i >= 0; i--) {
consumer.accept(extensionListeners.get(i));
}
extensionListeners.forEach(consumer); protected final Observable<ExtensionListener> extensionObservable = new Observable<>();
public Observable<ExtensionListener> getExtensionObservable() {
return extensionObservable;
} }
protected void sendManipulatedPacket(HMessage hMessage) { protected void sendManipulatedPacket(HMessage hMessage) {
int orgIndex = hMessage.getPacket().getReadIndex(); int orgIndex = hMessage.getPacket().getReadIndex();
notifyListeners(listener -> { extensionObservable.fireEvent(listener -> {
hMessage.getPacket().setReadIndex(6); hMessage.getPacket().setReadIndex(6);
listener.manipulatedPacket(hMessage); listener.manipulatedPacket(hMessage);
}); });
hMessage.getPacket().setReadIndex(orgIndex); hMessage.getPacket().setReadIndex(orgIndex);
} }
protected void requestFlags() { protected void requestFlags() {
notifyListeners(ExtensionListener::flagsRequest); extensionObservable.fireEvent(ExtensionListener::flagsRequest);
} }
protected void sendMessage(HMessage.Direction direction, HPacket packet) { protected void sendMessage(HMessage.Direction direction, HPacket packet) {
int orgIndex = packet.getReadIndex(); int orgIndex = packet.getReadIndex();
notifyListeners(listener -> { extensionObservable.fireEvent(listener -> {
packet.setReadIndex(6); packet.setReadIndex(6);
listener.sendMessage(direction, packet); listener.sendMessage(direction, packet);
}); });
packet.setReadIndex(orgIndex); packet.setReadIndex(orgIndex);
} }
protected void log(String text) { protected void log(String text) {
notifyListeners(listener -> listener.log(text)); extensionObservable.fireEvent(listener -> listener.log(text));
} }
protected void hasClosed() { protected void hasClosed() {
notifyListeners(ExtensionListener::hasClosed); extensionObservable.fireEvent(ExtensionListener::hasClosed);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -97,46 +88,19 @@ public abstract class GEarthExtension {
// ----------- methods for interaction with G-Earth UI, don't use/change them ---------------- // ----------- methods for interaction with G-Earth UI, don't use/change them ----------------
private final List<InvalidationListener> onRemoveClickListener = new ArrayList<>(); private final Observable<OmRemoveClickListener> removeClickObservable = new SynchronizedObservable<>(OmRemoveClickListener::onRemove);
public void onRemoveClick(InvalidationListener listener) { public Observable<OmRemoveClickListener> getRemoveClickObservable() {
synchronized (onRemoveClickListener) { return removeClickObservable;
onRemoveClickListener.add(listener);
}
}
public void isRemoveClickTrigger() {
synchronized (onRemoveClickListener) {
for (int i = onRemoveClickListener.size() - 1; i >= 0; i--) {
onRemoveClickListener.get(i).invalidated(null);
}
}
} }
private final List<InvalidationListener> onClickListener = new ArrayList<>(); private final Observable<OnClickListener> clickedObservable = new SynchronizedObservable<>(OnClickListener::onClick);
public void onClick(InvalidationListener listener) { public Observable<OnClickListener> getClickedObservable() {
synchronized (onClickListener) { return clickedObservable;
onClickListener.add(listener);
}
}
public void isClickTrigger() {
synchronized (onClickListener) {
for (int i = onClickListener.size() - 1; i >= 0; i--) {
onClickListener.get(i).invalidated(null);
}
}
} }
private final List<InvalidationListener> onDeleteListeners = new ArrayList<>(); private final Observable<OnDeleteListener> deletedObservable = new SynchronizedObservable<>(OnDeleteListener::onDelete);
public void onDelete(InvalidationListener listener) { public Observable<OnDeleteListener> getDeletedObservable() {
synchronized (onDeleteListeners) { return deletedObservable;
onDeleteListeners.add(listener);
}
}
public void delete() {
synchronized (onDeleteListeners) {
for (int i = onDeleteListeners.size() - 1; i >= 0; i--) {
onDeleteListeners.get(i).invalidated(null);
}
}
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
package gearth.services.extensionhandler.extensions.extensionproducers; package gearth.services.extensionhandler.extensions.extensionproducers;
import gearth.services.extensionhandler.extensions.network.NetworkExtensionsProducer; import gearth.services.extensionhandler.extensions.implementations.network.NetworkExtensionsProducer;
import gearth.services.extensionhandler.extensions.simple.SimpleExtensionProducer; import gearth.services.extensionhandler.extensions.implementations.simple.SimpleExtensionProducer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -3,5 +3,5 @@ package gearth.services.extensionhandler.extensions.extensionproducers;
import gearth.services.extensionhandler.extensions.GEarthExtension; import gearth.services.extensionhandler.extensions.GEarthExtension;
public interface ExtensionProducerObserver { public interface ExtensionProducerObserver {
void onExtensionConnect(GEarthExtension extension); void onExtensionProduced(GEarthExtension extension);
} }

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.network; package gearth.services.extensionhandler.extensions.implementations.network;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.services.extensionhandler.extensions.GEarthExtension; import gearth.services.extensionhandler.extensions.GEarthExtension;
@ -63,7 +63,7 @@ public class NetworkExtension extends GEarthExtension {
HPacket message = new HPacket(headerandbody); HPacket message = new HPacket(headerandbody);
message.fixLength(); message.fixLength();
synchronized (selff.extensionListeners) { synchronized (selff.extensionObservable) {
if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.REQUESTFLAGS) { if (message.headerId() == NetworkExtensionInfo.INCOMING_MESSAGES_IDS.REQUESTFLAGS) {
requestFlags(); requestFlags();
} }
@ -96,7 +96,7 @@ public class NetworkExtension extends GEarthExtension {
} catch (IOException e) { } catch (IOException e) {
// An extension disconnected, which is OK // An extension disconnected, which is OK
} finally { } finally {
synchronized (selff.extensionListeners) { synchronized (selff.extensionObservable) {
hasClosed(); hasClosed();
} }
if (!connection.isClosed()) { if (!connection.isClosed()) {

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.network; package gearth.services.extensionhandler.extensions.implementations.network;
public class NetworkExtensionInfo { public class NetworkExtensionInfo {

View File

@ -1,9 +1,9 @@
package gearth.services.extensionhandler.extensions.network; package gearth.services.extensionhandler.extensions.implementations.network;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducer; import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducer;
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver; import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver;
import gearth.services.extensionhandler.extensions.network.authentication.Authenticator; import gearth.services.extensionhandler.extensions.implementations.network.authentication.Authenticator;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
@ -63,7 +63,7 @@ public class NetworkExtensionsProducer implements ExtensionProducer {
); );
if (Authenticator.evaluate(gEarthExtension)) { if (Authenticator.evaluate(gEarthExtension)) {
observer.onExtensionConnect(gEarthExtension); observer.onExtensionProduced(gEarthExtension);
} }
else { else {
gEarthExtension.close(); //you shall not pass... gEarthExtension.close(); //you shall not pass...

View File

@ -1,7 +1,7 @@
package gearth.services.extensionhandler.extensions.network.authentication; package gearth.services.extensionhandler.extensions.implementations.network.authentication;
import gearth.misc.ConfirmationDialog; import gearth.misc.ConfirmationDialog;
import gearth.services.extensionhandler.extensions.network.NetworkExtension; import gearth.services.extensionhandler.extensions.implementations.network.NetworkExtension;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.network.executer; package gearth.services.extensionhandler.extensions.implementations.network.executer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.network.executer; package gearth.services.extensionhandler.extensions.implementations.network.executer;
/** /**
* Created by Jonas on 21/09/18. * Created by Jonas on 21/09/18.

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.network.executer; package gearth.services.extensionhandler.extensions.implementations.network.executer;
/** /**
* Created by Jonas on 22/09/18. * Created by Jonas on 22/09/18.

View File

@ -1,7 +1,7 @@
package gearth.services.extensionhandler.extensions.network.executer; package gearth.services.extensionhandler.extensions.implementations.network.executer;
import gearth.Main; import gearth.Main;
import gearth.services.extensionhandler.extensions.network.authentication.Authenticator; import gearth.services.extensionhandler.extensions.implementations.network.authentication.Authenticator;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.simple; package gearth.services.extensionhandler.extensions.implementations.simple;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.services.extensionhandler.extensions.GEarthExtension; import gearth.services.extensionhandler.extensions.GEarthExtension;

View File

@ -1,4 +1,4 @@
package gearth.services.extensionhandler.extensions.simple; package gearth.services.extensionhandler.extensions.implementations.simple;
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducer; import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducer;
import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver; import gearth.services.extensionhandler.extensions.extensionproducers.ExtensionProducerObserver;

View File

@ -0,0 +1,5 @@
package gearth.services.extensionhandler.extensions.listeners;
public interface OmRemoveClickListener {
void onRemove();
}

View File

@ -0,0 +1,5 @@
package gearth.services.extensionhandler.extensions.listeners;
public interface OnClickListener {
void onClick();
}

View File

@ -0,0 +1,5 @@
package gearth.services.extensionhandler.extensions.listeners;
public interface OnDeleteListener {
void onDelete();
}

View File

@ -73,7 +73,7 @@ public class Connection extends SubForm {
} }
public void onParentSet(){ public void onParentSet(){
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> { getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
txtfield_hotelversion.setText(getHConnection().getHotelVersion()); txtfield_hotelversion.setText(getHConnection().getHotelVersion());
Platform.runLater(() -> { Platform.runLater(() -> {
if (newState == HConnection.State.NOT_CONNECTED) { if (newState == HConnection.State.NOT_CONNECTED) {

View File

@ -12,10 +12,10 @@ import javafx.scene.paint.Paint;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import gearth.misc.ConfirmationDialog; import gearth.misc.ConfirmationDialog;
import gearth.ui.buttons.*; import gearth.ui.buttons.*;
import gearth.services.extensionhandler.extensions.network.executer.ExecutionInfo; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExecutionInfo;
import gearth.services.extensionhandler.extensions.network.executer.ExtensionRunner; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExtensionRunner;
import gearth.services.extensionhandler.extensions.network.executer.ExtensionRunnerFactory; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExtensionRunnerFactory;
import gearth.services.extensionhandler.extensions.network.executer.NormalExtensionRunner; import gearth.services.extensionhandler.extensions.implementations.network.executer.NormalExtensionRunner;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -161,14 +161,14 @@ public class ExtensionItemContainer extends GridPane {
exitButton.removeEventHandler(MouseEvent.MOUSE_CLICKED, onExit); exitButton.removeEventHandler(MouseEvent.MOUSE_CLICKED, onExit);
clickButton.removeEventHandler(MouseEvent.MOUSE_CLICKED, onClick); clickButton.removeEventHandler(MouseEvent.MOUSE_CLICKED, onClick);
} }
onExit = event -> item.isRemoveClickTrigger(); onExit = event -> item.getRemoveClickObservable().fireEvent();
onClick = event -> item.isClickTrigger(); onClick = event -> item.getClickedObservable().fireEvent();
exitButton.addEventHandler(MouseEvent.MOUSE_CLICKED, onExit); exitButton.addEventHandler(MouseEvent.MOUSE_CLICKED, onExit);
clickButton.addEventHandler(MouseEvent.MOUSE_CLICKED, onClick); clickButton.addEventHandler(MouseEvent.MOUSE_CLICKED, onClick);
ExtensionItemContainer this2 = this; ExtensionItemContainer this2 = this;
item.onDelete(observable -> Platform.runLater(() -> { item.getDeletedObservable().addListener(() -> Platform.runLater(() -> {
if (item.isInstalledExtension()) { if (item.isInstalledExtension()) {
setBackground(new Background(new BackgroundFill(Paint.valueOf("#cccccc"),null, null))); setBackground(new Background(new BackgroundFill(Paint.valueOf("#cccccc"),null, null)));
getChildren().remove(buttonsBox); getChildren().remove(buttonsBox);

View File

@ -1,10 +1,10 @@
package gearth.ui.extensions; package gearth.ui.extensions;
import gearth.services.extensionhandler.ExtensionHandler; import gearth.services.extensionhandler.ExtensionHandler;
import gearth.services.extensionhandler.extensions.network.NetworkExtensionsProducer; import gearth.services.extensionhandler.extensions.implementations.network.NetworkExtensionsProducer;
import gearth.services.extensionhandler.extensions.network.executer.ExecutionInfo; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExecutionInfo;
import gearth.services.extensionhandler.extensions.network.executer.ExtensionRunner; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExtensionRunner;
import gearth.services.extensionhandler.extensions.network.executer.ExtensionRunnerFactory; import gearth.services.extensionhandler.extensions.implementations.network.executer.ExtensionRunnerFactory;
import gearth.ui.SubForm; import gearth.ui.SubForm;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@ -43,7 +43,7 @@ public class Extensions extends SubForm {
protected void onParentSet() { protected void onParentSet() {
ExtensionItemContainerProducer producer = new ExtensionItemContainerProducer(extensioncontainer, scroller); ExtensionItemContainerProducer producer = new ExtensionItemContainerProducer(extensioncontainer, scroller);
extensionHandler = new ExtensionHandler(getHConnection()); extensionHandler = new ExtensionHandler(getHConnection());
extensionHandler.onExtensionConnected((e -> { extensionHandler.getObservable().addListener((e -> {
Platform.runLater(() -> producer.extensionConnected(e)); Platform.runLater(() -> producer.extensionConnected(e));
})); }));

View File

@ -59,7 +59,7 @@ public class Extra extends SubForm implements ConnectionInfoOverrider {
cbx_alwaysOnTop.selectedProperty().addListener(observable -> parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected())); cbx_alwaysOnTop.selectedProperty().addListener(observable -> parentController.getStage().setAlwaysOnTop(cbx_alwaysOnTop.isSelected()));
cbx_advanced.selectedProperty().addListener(observable -> updateAdvancedUI()); cbx_advanced.selectedProperty().addListener(observable -> updateAdvancedUI());
getHConnection().addStateChangeListener((oldState, newState) -> { getHConnection().getStateObservable().addListener((oldState, newState) -> {
if (oldState == HConnection.State.NOT_CONNECTED || newState == HConnection.State.NOT_CONNECTED) { if (oldState == HConnection.State.NOT_CONNECTED || newState == HConnection.State.NOT_CONNECTED) {
updateAdvancedUI(); updateAdvancedUI();
} }

View File

@ -21,7 +21,7 @@ public class Injection extends SubForm {
public Button btn_sendToClient; public Button btn_sendToClient;
protected void onParentSet() { protected void onParentSet() {
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(this::updateUI)); getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(this::updateUI));
inputPacket.textProperty().addListener(event -> Platform.runLater(this::updateUI)); inputPacket.textProperty().addListener(event -> Platform.runLater(this::updateUI));
} }

View File

@ -35,7 +35,7 @@ public class Logger extends SubForm {
private PacketLogger packetLogger = PacketLoggerFactory.get(); private PacketLogger packetLogger = PacketLoggerFactory.get();
public void onParentSet(){ public void onParentSet(){
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> { getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
if (newState == HConnection.State.PREPARING) { if (newState == HConnection.State.PREPARING) {
miniLogText(Color.ORANGE, "Connecting to "+getHConnection().getDomain() + ":" + getHConnection().getServerPort()); miniLogText(Color.ORANGE, "Connecting to "+getHConnection().getDomain() + ":" + getHConnection().getServerPort());
} }

View File

@ -1,5 +1,10 @@
package gearth.ui.scheduler; package gearth.ui.scheduler;
import gearth.misc.listenerpattern.Observable;
import gearth.ui.scheduler.listeners.OnBeingUpdatedListener;
import gearth.ui.scheduler.listeners.OnDeleteListener;
import gearth.ui.scheduler.listeners.OnEditListener;
import gearth.ui.scheduler.listeners.OnUpdatedListener;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
@ -16,11 +21,11 @@ import java.util.List;
*/ */
public class ScheduleItem implements StringifyAble { public class ScheduleItem implements StringifyAble {
private SimpleIntegerProperty indexProperty = null; private SimpleIntegerProperty indexProperty;
private SimpleBooleanProperty pausedProperty = null; private SimpleBooleanProperty pausedProperty;
private SimpleObjectProperty<Interval> delayProperty = null; private SimpleObjectProperty<Interval> delayProperty;
private SimpleObjectProperty<HPacket> packetProperty = null; private SimpleObjectProperty<HPacket> packetProperty;
private SimpleObjectProperty<HMessage.Direction> destinationProperty = null; private SimpleObjectProperty<HMessage.Direction> destinationProperty;
ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) { ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
construct(index, paused, delay, packet, destination); construct(index, paused, delay, packet, destination);
@ -59,44 +64,36 @@ public class ScheduleItem implements StringifyAble {
} }
private List<InvalidationListener> onDeleteListeners = new ArrayList<>(); private Observable<OnDeleteListener> onDeleteObservable = new Observable<>(OnDeleteListener::onDelete);
public void onDelete(InvalidationListener listener) { public void onDelete(OnDeleteListener listener) {
onDeleteListeners.add(listener); onDeleteObservable.addListener(listener);
} }
public void delete() { public void delete() {
for (int i = onDeleteListeners.size() - 1; i >= 0; i--) { onDeleteObservable.fireEvent();
onDeleteListeners.get(i).invalidated(null);
}
} }
private List<InvalidationListener> onEditListeners = new ArrayList<>(); private Observable<OnEditListener> onEditObservable = new Observable<>(OnEditListener::onEdit);
public void onEdit(InvalidationListener listener) { public void onEdit(OnEditListener listener) {
onEditListeners.add(listener); onEditObservable.addListener(listener);
} }
public void edit() { public void edit() {
for (int i = onEditListeners.size() - 1; i >= 0; i--) { onEditObservable.fireEvent();
onEditListeners.get(i).invalidated(null);
}
} }
private List<InvalidationListener> onIsupdatedListeners = new ArrayList<>(); private Observable<OnUpdatedListener> onUpdatedObservable = new Observable<>(OnUpdatedListener::onUpdated);
public void onIsupdated(InvalidationListener listener) { public void onIsupdated(OnUpdatedListener listener) {
onIsupdatedListeners.add(listener); onUpdatedObservable.addListener(listener);
} }
public void isUpdatedTrigger() { public void isUpdatedTrigger() {
for (int i = onIsupdatedListeners.size() - 1; i >= 0; i--) { onUpdatedObservable.fireEvent();
onIsupdatedListeners.get(i).invalidated(null);
}
} }
private List<InvalidationListener> OnIsBeingUpdatedListeners = new ArrayList<>(); private Observable<OnBeingUpdatedListener> onBeingUpdatedObservable = new Observable<>(OnBeingUpdatedListener::onBeingUpdated);
public void onIsBeingUpdated(InvalidationListener listener) { public void onIsBeingUpdated(OnBeingUpdatedListener listener) {
OnIsBeingUpdatedListeners.add(listener); onBeingUpdatedObservable.addListener(listener);
} }
public void onIsBeingUpdatedTrigger() { public void onIsBeingUpdatedTrigger() {
for (int i = OnIsBeingUpdatedListeners.size() - 1; i >= 0; i--) { onBeingUpdatedObservable.fireEvent();
OnIsBeingUpdatedListeners.get(i).invalidated(null);
}
} }
@Override @Override

View File

@ -87,9 +87,9 @@ public class ScheduleItemContainer extends GridPane {
GridPane this2 = this; GridPane this2 = this;
item.onDelete(observable -> parent.getChildren().remove(this2)); item.onDelete(() -> parent.getChildren().remove(this2));
item.onIsBeingUpdated(observable -> setStyle("-fx-background-color: #faebcc;")); item.onIsBeingUpdated(() -> setStyle("-fx-background-color: #faebcc;"));
item.onIsupdated(observable -> setStyle("-fx-background-color: #ffffff;")); item.onIsupdated(() -> setStyle("-fx-background-color: #ffffff;"));
} }
private Label initNewLabelColumn(String text) { private Label initNewLabelColumn(String text) {

View File

@ -173,7 +173,7 @@ public class Scheduler extends SubForm {
scheduleItemList.add(newItem); scheduleItemList.add(newItem);
newItem.onDelete(observable -> { newItem.onDelete(() -> {
if (isBeingEdited == newItem) { if (isBeingEdited == newItem) {
setInputDefault(); setInputDefault();
isBeingEdited = null; isBeingEdited = null;
@ -183,7 +183,7 @@ public class Scheduler extends SubForm {
scheduleItemList.get(i).getIndexProperty().set(i); scheduleItemList.get(i).getIndexProperty().set(i);
} }
}); });
newItem.onEdit(observable -> { newItem.onEdit(() -> {
if (isBeingEdited != null) { if (isBeingEdited != null) {
isBeingEdited.isUpdatedTrigger(); isBeingEdited.isUpdatedTrigger();
} }
@ -195,7 +195,7 @@ public class Scheduler extends SubForm {
rb_outgoing.setSelected(newItem.getDestinationProperty().get() == HMessage.Direction.TOSERVER); rb_outgoing.setSelected(newItem.getDestinationProperty().get() == HMessage.Direction.TOSERVER);
isBeingEdited = newItem; isBeingEdited = newItem;
btn_addoredit.setText("Edit schedule item"); //Add to scheduler btn_addoredit.setText("Edit");
updateUI(); updateUI();
newItem.onIsBeingUpdatedTrigger(); newItem.onIsBeingUpdatedTrigger();
} }
@ -213,7 +213,7 @@ public class Scheduler extends SubForm {
rb_incoming.setSelected(true); rb_incoming.setSelected(true);
rb_outgoing.setSelected(false); rb_outgoing.setSelected(false);
btn_addoredit.setText("Add to scheduler"); btn_addoredit.setText("Add");
updateUI(); updateUI();
} }

View File

@ -0,0 +1,5 @@
package gearth.ui.scheduler.listeners;
public interface OnBeingUpdatedListener {
void onBeingUpdated();
}

View File

@ -0,0 +1,5 @@
package gearth.ui.scheduler.listeners;
public interface OnDeleteListener {
void onDelete();
}

View File

@ -0,0 +1,5 @@
package gearth.ui.scheduler.listeners;
public interface OnEditListener {
void onEdit();
}

View File

@ -0,0 +1,5 @@
package gearth.ui.scheduler.listeners;
public interface OnUpdatedListener {
void onUpdated();
}