*
* The MIT License (MIT)
*
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
import java.util.List;
import jexer.event.TInputEvent;
+import jexer.event.TCommandEvent;
+import static jexer.TCommand.*;
/**
* This abstract class provides a screen, keyboard, and mouse to
*/
public abstract class GenericBackend implements Backend {
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* The session information.
*/
protected SessionInfo sessionInfo;
+ /**
+ * The screen to draw on.
+ */
+ protected Screen screen;
+
+ /**
+ * Input events are processed by this Terminal.
+ */
+ protected TerminalReader terminal;
+
+ /**
+ * By default, GenericBackend adds a cmAbort after it sees
+ * cmBackendDisconnect, so that TApplication will exit when the user
+ * closes the Swing window or disconnects the ECMA48 streams. But
+ * MultiBackend wraps multiple Backends, and needs to decide when to send
+ * cmAbort differently. Setting this to false is how it manages that.
+ * Note package private access.
+ */
+ boolean abortOnDisconnect = true;
+
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // Backend ----------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* Getter for sessionInfo.
*
return sessionInfo;
}
- /**
- * The screen to draw on.
- */
- protected Screen screen;
-
/**
* Getter for screen.
*
}
/**
- * Input events are processed by this Terminal.
+ * Check if there are events in the queue.
+ *
+ * @return if true, getEvents() has something to return to the application
*/
- protected TerminalReader terminal;
+ public boolean hasEvents() {
+ return terminal.hasEvents();
+ }
/**
* Get keyboard, mouse, and screen resize events.
public void getEvents(final List<TInputEvent> queue) {
if (terminal.hasEvents()) {
terminal.getEvents(queue);
+
+ // This default backend assumes a single user, and if that user
+ // becomes disconnected we should terminate the application.
+ if ((queue.size() > 0) && (abortOnDisconnect == true)) {
+ TInputEvent event = queue.get(queue.size() - 1);
+ if (event instanceof TCommandEvent) {
+ TCommandEvent command = (TCommandEvent) event;
+ if (command.equals(cmBackendDisconnect)) {
+ queue.add(new TCommandEvent(cmAbort));
+ }
+ }
+ }
}
}
terminal.setListener(listener);
}
+ /**
+ * Reload backend options from System properties.
+ */
+ public void reloadOptions() {
+ terminal.reloadOptions();
+ }
+
}