<project name="jexer" basedir="." default="jar">
- <property name="version" value="0.3.0"/>
+ <property name="version" value="0.3.1"/>
<property name="src.dir" value="src"/>
<property name="resources.dir" value="resources"/>
<property name="build.dir" value="build"/>
version="true"
use="true"
access="protected"
- windowtitle="Jexer - Java Text User Interface - API docs">
-
+ windowtitle="Jexer - Java Text User Interface - API docs"
+ additionalparam="--frames"
+ >
<fileset dir="${src.dir}" defaultexcludes="yes">
<include name="jexer/**/*.java"/>
</fileset>
* Run this application until it exits.
*/
public void run() {
+ // System.err.println("*** TApplication.run() begins ***");
+
// Start the main consumer thread
primaryEventHandler = new WidgetEventHandler(this, true);
(new Thread(primaryEventHandler)).start();
// resources.
closeAllWindows();
+ // Give the overarching application an opportunity to release
+ // resources.
+ onExit();
+
+ // System.err.println("*** TApplication.run() exits ***");
}
// ------------------------------------------------------------------------
// Abort everything
if (event instanceof TCommandEvent) {
TCommandEvent command = (TCommandEvent) event;
- if (command.getCmd().equals(cmAbort)) {
+ if (command.equals(cmAbort)) {
exit();
return;
}
String version = getClass().getPackage().getImplementationVersion();
if (version == null) {
// This is Java 9+, use a hardcoded string here.
- version = "0.3.0";
+ version = "0.3.1";
}
messageBox(i18n.getString("aboutDialogTitle"),
MessageFormat.format(i18n.getString("aboutDialogText"), version),
}
}
+ /**
+ * Subclasses can use this hook to cleanup resources. Called as the last
+ * step of TApplication.run().
+ */
+ public void onExit() {
+ // Default does nothing.
+ }
+
// ------------------------------------------------------------------------
// TWindow management -----------------------------------------------------
// ------------------------------------------------------------------------
*/
public static final int SAVE = 30;
+ /**
+ * Backend disconnected.
+ */
+ public static final int BACKEND_DISCONNECT = 100;
+
public static final TCommand cmAbort = new TCommand(ABORT);
public static final TCommand cmExit = new TCommand(EXIT);
public static final TCommand cmQuit = new TCommand(EXIT);
public static final TCommand cmHelp = new TCommand(HELP);
public static final TCommand cmSave = new TCommand(SAVE);
public static final TCommand cmMenu = new TCommand(MENU);
+ public static final TCommand cmBackendDisconnect = new TCommand(BACKEND_DISCONNECT);
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
import jexer.bits.Cell;
import jexer.bits.CellAttributes;
import jexer.bits.Color;
+import jexer.event.TCommandEvent;
import jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TResizeEvent;
+import static jexer.TCommand.*;
import static jexer.TKeypress.*;
/**
}
} // while ((done == false) && (stopReaderThread == false))
- // TODO: pass an event up to TApplication to tell it this Backend is
- // done.
+ // Pass an event up to TApplication to tell it this Backend is done.
+ synchronized (eventQueue) {
+ eventQueue.add(new TCommandEvent(cmBackendDisconnect));
+ }
+ if (listener != null) {
+ synchronized (listener) {
+ listener.notifyAll();
+ }
+ }
// System.err.println("*** run() exiting..."); System.err.flush();
}
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 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) {
+ TInputEvent event = queue.get(queue.size() - 1);
+ if (event instanceof TCommandEvent) {
+ TCommandEvent command = (TCommandEvent) event;
+ if (command.equals(cmBackendDisconnect)) {
+ queue.add(new TCommandEvent(cmAbort));
+ }
+ }
+ }
}
}