+ /**
+ * The primary event handler thread.
+ */
+ private volatile WidgetEventHandler primaryEventHandler;
+
+ /**
+ * The secondary event handler thread.
+ */
+ private volatile WidgetEventHandler secondaryEventHandler;
+
+ /**
+ * The screen handler thread.
+ */
+ private volatile ScreenHandler screenHandler;
+
+ /**
+ * The widget receiving events from the secondary event handler thread.
+ */
+ private volatile TWidget secondaryEventReceiver;
+
+ /**
+ * Access to the physical screen, keyboard, and mouse.
+ */
+ private Backend backend;
+
+ /**
+ * The clipboard for copy and paste.
+ */
+ private Clipboard clipboard = new Clipboard();
+
+ /**
+ * Actual mouse coordinate X.
+ */
+ private int mouseX;
+
+ /**
+ * Actual mouse coordinate Y.
+ */
+ private int mouseY;
+
+ /**
+ * Old drawn version of mouse coordinate X.
+ */
+ private int oldDrawnMouseX;
+
+ /**
+ * Old drawn version mouse coordinate Y.
+ */
+ private int oldDrawnMouseY;
+
+ /**
+ * Old drawn version mouse cell.
+ */
+ private Cell oldDrawnMouseCell = new Cell();
+
+ /**
+ * The last mouse up click time, used to determine if this is a mouse
+ * double-click.
+ */
+ private long lastMouseUpTime;
+
+ /**
+ * The amount of millis between mouse up events to assume a double-click.
+ */
+ private long doubleClickTime = 250;
+
+ /**
+ * Event queue that is filled by run().
+ */
+ private List<TInputEvent> fillEventQueue;
+
+ /**
+ * Event queue that will be drained by either primary or secondary
+ * Thread.
+ */
+ private List<TInputEvent> drainEventQueue;
+
+ /**
+ * Top-level menus in this application.
+ */
+ private List<TMenu> menus;
+
+ /**
+ * Stack of activated sub-menus in this application.
+ */
+ private List<TMenu> subMenus;
+
+ /**
+ * The currently active menu.
+ */
+ private TMenu activeMenu = null;
+
+ /**
+ * Active keyboard accelerators.
+ */
+ private Map<TKeypress, TMenuItem> accelerators;
+
+ /**
+ * All menu items.
+ */
+ private List<TMenuItem> menuItems;
+
+ /**
+ * Windows and widgets pull colors from this ColorTheme.
+ */
+ private ColorTheme theme;
+
+ /**
+ * The top-level windows (but not menus).
+ */
+ private List<TWindow> windows;
+
+ /**
+ * Timers that are being ticked.
+ */
+ private List<TTimer> timers;
+
+ /**
+ * When true, the application has been started.
+ */
+ private volatile boolean started = false;
+
+ /**
+ * When true, exit the application.
+ */
+ private volatile boolean quit = false;
+
+ /**
+ * When true, repaint the entire screen.
+ */
+ private volatile boolean repaint = true;
+
+ /**
+ * Y coordinate of the top edge of the desktop. For now this is a
+ * constant. Someday it would be nice to have a multi-line menu or
+ * toolbars.
+ */
+ private int desktopTop = 1;
+
+ /**
+ * Y coordinate of the bottom edge of the desktop.
+ */
+ private int desktopBottom;
+
+ /**
+ * An optional TDesktop background window that is drawn underneath
+ * everything else.
+ */
+ private TDesktop desktop;
+
+ /**
+ * If true, focus follows mouse: windows automatically raised if the
+ * mouse passes over them.
+ */
+ private boolean focusFollowsMouse = false;
+
+ /**
+ * If true, display a text-based mouse cursor.
+ */
+ private boolean textMouse = true;
+
+ /**
+ * If true, hide the mouse after typing a keystroke.
+ */
+ private boolean hideMouseWhenTyping = false;
+
+ /**
+ * If true, the mouse should not be displayed because a keystroke was
+ * typed.
+ */
+ private boolean typingHidMouse = false;
+
+ /**
+ * If true, hide the status bar.
+ */
+ private boolean hideStatusBar = false;
+
+ /**
+ * If true, hide the menu bar.
+ */
+ private boolean hideMenuBar = false;
+
+ /**
+ * The list of commands to run before the next I/O check.
+ */
+ private List<Runnable> invokeLaters = new LinkedList<Runnable>();
+
+ /**
+ * The last time the screen was resized.
+ */
+ private long screenResizeTime = 0;
+
+ /**
+ * If true, screen selection is a rectangle.
+ */
+ private boolean screenSelectionRectangle = false;
+
+ /**
+ * If true, the mouse is dragging a screen selection.
+ */
+ private boolean inScreenSelection = false;
+
+ /**
+ * Screen selection starting X.
+ */
+ private int screenSelectionX0;
+
+ /**
+ * Screen selection starting Y.
+ */
+ private int screenSelectionY0;
+
+ /**
+ * Screen selection ending X.
+ */
+ private int screenSelectionX1;
+
+ /**
+ * Screen selection ending Y.
+ */
+ private int screenSelectionY1;
+
+ /**
+ * The help file data. Note package private access.
+ */
+ HelpFile helpFile;
+
+ /**
+ * The stack of help topics. Note package private access.
+ */
+ ArrayList<Topic> helpTopics = new ArrayList<Topic>();
+