X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTApplication.java;h=ab9c1962f6334094a03c6342eaad21eee6a03e8e;hb=3e0743556d1f31723a11a6019b5c2b018b4b2104;hp=b80e7a30dd483bebfd6fc130da3b091810463b5e;hpb=56661844475522242093c8858ceb20fb15589da5;p=fanfix.git diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index b80e7a3..ab9c196 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -44,7 +44,6 @@ import java.util.Map; import jexer.bits.CellAttributes; import jexer.bits.ColorTheme; -import jexer.bits.GraphicsChars; import jexer.event.TCommandEvent; import jexer.event.TInputEvent; import jexer.event.TKeypressEvent; @@ -52,16 +51,19 @@ import jexer.event.TMenuEvent; import jexer.event.TMouseEvent; import jexer.event.TResizeEvent; import jexer.backend.Backend; +import jexer.backend.Screen; import jexer.backend.SwingBackend; import jexer.backend.ECMA48Backend; -import jexer.io.Screen; +import jexer.backend.TWindowBackend; import jexer.menu.TMenu; import jexer.menu.TMenuItem; import static jexer.TCommand.*; import static jexer.TKeypress.*; /** - * TApplication sets up a full Text User Interface application. + * TApplication is the main driver class for a full Text User Interface + * application. It manages windows, provides a menu bar and status bar, and + * processes events received from the user. */ public class TApplication implements Runnable { @@ -404,7 +406,15 @@ public class TApplication implements Runnable { * @return the Screen */ public final Screen getScreen() { - return backend.getScreen(); + if (backend instanceof TWindowBackend) { + // We are being rendered to a TWindow. We can't use its + // getScreen() method because that is how it is rendering to a + // hardware backend somewhere. Instead use its getOtherScreen() + // method. + return ((TWindowBackend) backend).getOtherScreen(); + } else { + return backend.getScreen(); + } } /** @@ -580,6 +590,32 @@ public class TApplication implements Runnable { return result; } + /** + * If true, focus follows mouse: windows automatically raised if the + * mouse passes over them. + */ + private boolean focusFollowsMouse = false; + + /** + * Get focusFollowsMouse flag. + * + * @return true if focus follows mouse: windows automatically raised if + * the mouse passes over them + */ + public boolean getFocusFollowsMouse() { + return focusFollowsMouse; + } + + /** + * Set focusFollowsMouse flag. + * + * @param focusFollowsMouse if true, focus follows mouse: windows + * automatically raised if the mouse passes over them + */ + public void setFocusFollowsMouse(final boolean focusFollowsMouse) { + this.focusFollowsMouse = focusFollowsMouse; + } + // ------------------------------------------------------------------------ // General behavior ------------------------------------------------------- // ------------------------------------------------------------------------ @@ -610,6 +646,12 @@ public class TApplication implements Runnable { switch (backendType) { case SWING: + // The default SwingBackend is 80x25, 20 pt font. If you want to + // change that, you can pass the extra arguments to the + // SwingBackend constructor here. For example, if you wanted + // 90x30, 16 pt font: + // + // backend = new SwingBackend(this, 90, 30, 16); backend = new SwingBackend(this); break; case XTERM: @@ -686,6 +728,7 @@ public class TApplication implements Runnable { */ public TApplication(final Backend backend) { this.backend = backend; + backend.setListener(this); TApplicationImpl(); } @@ -877,6 +920,13 @@ public class TApplication implements Runnable { // Main loop -------------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Force this application to exit. + */ + public void exit() { + quit = true; + } + /** * Run this application until it exits. */ @@ -1962,55 +2012,64 @@ public class TApplication implements Runnable { return; } - // Only switch if there are multiple windows - if (windows.size() < 2) { + // If a menu is still active, don't switch windows + if (activeMenu != null) { return; } - // Switch on the upclick - if (mouse.getType() != TMouseEvent.Type.MOUSE_UP) { + // Only switch if there are multiple windows + if (windows.size() < 2) { return; } - synchronized (windows) { - Collections.sort(windows); - if (windows.get(0).isModal()) { - // Modal windows don't switch - return; - } + if (((focusFollowsMouse == true) + && (mouse.getType() == TMouseEvent.Type.MOUSE_MOTION)) + || (mouse.getType() == TMouseEvent.Type.MOUSE_UP) + ) { + synchronized (windows) { + Collections.sort(windows); + if (windows.get(0).isModal()) { + // Modal windows don't switch + return; + } - for (TWindow window: windows) { - assert (!window.isModal()); + for (TWindow window: windows) { + assert (!window.isModal()); - if (window.isHidden()) { - assert (!window.isActive()); - continue; - } + if (window.isHidden()) { + assert (!window.isActive()); + continue; + } - if (window.mouseWouldHit(mouse)) { - if (window == windows.get(0)) { - // Clicked on the same window, nothing to do - assert (window.isActive()); + if (window.mouseWouldHit(mouse)) { + if (window == windows.get(0)) { + // Clicked on the same window, nothing to do + assert (window.isActive()); + return; + } + + // We will be switching to another window + assert (windows.get(0).isActive()); + assert (windows.get(0) == activeWindow); + assert (!window.isActive()); + activeWindow.onUnfocus(); + activeWindow.setActive(false); + activeWindow.setZ(window.getZ()); + activeWindow = window; + window.setZ(0); + window.setActive(true); + window.onFocus(); return; } - - // We will be switching to another window - assert (windows.get(0).isActive()); - assert (windows.get(0) == activeWindow); - assert (!window.isActive()); - activeWindow.onUnfocus(); - activeWindow.setActive(false); - activeWindow.setZ(window.getZ()); - activeWindow = window; - window.setZ(0); - window.setActive(true); - window.onFocus(); - return; } } + + // Clicked on the background, nothing to do + return; } - // Clicked on the background, nothing to do + // Nothing to do: this isn't a mouse up, or focus isn't following + // mouse. return; }