X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTApplication.java;h=91d2e98d7c039da4aeb9d01c84bb33385f762772;hb=55d2b2c2b29ce51f4f910448a115073371deeae8;hp=c43f436f6af3fb672c534e2950b54052ceef5fd1;hpb=6985c57265a980ceeb8cb10a8677fe387adb3eb7;p=fanfix.git diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index c43f436..91d2e98 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -370,6 +370,15 @@ public class TApplication implements Runnable { */ private Backend backend; + /** + * Get the Backend. + * + * @return the Backend + */ + public final Backend getBackend() { + return backend; + } + /** * Get the Screen. * @@ -618,12 +627,13 @@ public class TApplication implements Runnable { * @param y row position */ private void invertCell(final int x, final int y) { - synchronized (getScreen()) { - CellAttributes attr = getScreen().getAttrXY(x, y); - attr.setForeColor(attr.getForeColor().invert()); - attr.setBackColor(attr.getBackColor().invert()); - getScreen().putAttrXY(x, y, attr, false); + if (debugThreads) { + System.err.printf("invertCell() %d %d\n", x, y); } + CellAttributes attr = getScreen().getAttrXY(x, y); + attr.setForeColor(attr.getForeColor().invert()); + attr.setBackColor(attr.getBackColor().invert()); + getScreen().putAttrXY(x, y, attr, false); } /** @@ -635,18 +645,23 @@ public class TApplication implements Runnable { } if (!repaint) { - if ((oldMouseX != mouseX) || (oldMouseY != mouseY)) { - // The only thing that has happened is the mouse moved. - // Clear the old position and draw the new position. - invertCell(oldMouseX, oldMouseY); - invertCell(mouseX, mouseY); - oldMouseX = mouseX; - oldMouseY = mouseY; + if (debugThreads) { + System.err.printf("drawAll() !repaint\n"); } - if (getScreen().isDirty()) { - backend.flushScreen(); + synchronized (getScreen()) { + if ((oldMouseX != mouseX) || (oldMouseY != mouseY)) { + // The only thing that has happened is the mouse moved. + // Clear the old position and draw the new position. + invertCell(oldMouseX, oldMouseY); + invertCell(mouseX, mouseY); + oldMouseX = mouseX; + oldMouseY = mouseY; + } + if (getScreen().isDirty()) { + backend.flushScreen(); + } + return; } - return; } if (debugThreads) { @@ -712,6 +727,8 @@ public class TApplication implements Runnable { // Draw the mouse pointer invertCell(mouseX, mouseY); + oldMouseX = mouseX; + oldMouseY = mouseY; // Place the cursor if it is visible TWidget activeWidget = null; @@ -730,7 +747,9 @@ public class TApplication implements Runnable { } // Flush the screen contents - backend.flushScreen(); + if (getScreen().isDirty()) { + backend.flushScreen(); + } repaint = false; } @@ -762,6 +781,9 @@ public class TApplication implements Runnable { // wait until either the backend or the consumer threads have // something to do. try { + if (debugThreads) { + System.err.println("sleep " + timeout + " millis"); + } synchronized (this) { this.wait(timeout); } @@ -952,20 +974,35 @@ public class TApplication implements Runnable { if (event instanceof TKeypressEvent) { TKeypressEvent keypress = (TKeypressEvent) event; - // See if this key matches an accelerator, and if so dispatch the - // menu event. - TKeypress keypressLowercase = keypress.getKey().toLowerCase(); - TMenuItem item = null; - synchronized (accelerators) { - item = accelerators.get(keypressLowercase); + // See if this key matches an accelerator, and is not being + // shortcutted by the active window, and if so dispatch the menu + // event. + boolean windowWillShortcut = false; + for (TWindow window: windows) { + if (window.isActive()) { + if (window.isShortcutKeypress(keypress.getKey())) { + // We do not process this key, it will be passed to + // the window instead. + windowWillShortcut = true; + } + } } - if (item != null) { - if (item.isEnabled()) { - // Let the menu item dispatch - item.dispatch(); - return; + + if (!windowWillShortcut) { + TKeypress keypressLowercase = keypress.getKey().toLowerCase(); + TMenuItem item = null; + synchronized (accelerators) { + item = accelerators.get(keypressLowercase); + } + if (item != null) { + if (item.isEnabled()) { + // Let the menu item dispatch + item.dispatch(); + return; + } } } + // Handle the keypress if (onKeypress(keypress)) { return; @@ -1486,6 +1523,15 @@ public class TApplication implements Runnable { return false; } + /** + * Display the about dialog. + */ + protected void showAboutDialog() { + messageBox("About", "Jexer Version " + + this.getClass().getPackage().getImplementationVersion(), + TMessageBox.Type.OK); + } + /** * Method that TApplication subclasses can override to handle menu * events. @@ -1521,6 +1567,10 @@ public class TApplication implements Runnable { closeAllWindows(); return true; } + if (menu.getId() == TMenu.MID_ABOUT) { + showAboutDialog(); + return true; + } return false; } @@ -1646,7 +1696,7 @@ public class TApplication implements Runnable { * * @param event new event to add to the queue */ - public final void addMenuEvent(final TInputEvent event) { + public final void postMenuEvent(final TInputEvent event) { synchronized (fillEventQueue) { fillEventQueue.add(event); } @@ -1724,6 +1774,24 @@ public class TApplication implements Runnable { return windowMenu; } + /** + * Convenience function to add a default "Help" menu. + * + * @return the new menu + */ + public final TMenu addHelpMenu() { + TMenu helpMenu = addMenu("&Help"); + helpMenu.addDefaultItem(TMenu.MID_HELP_CONTENTS); + helpMenu.addDefaultItem(TMenu.MID_HELP_INDEX); + helpMenu.addDefaultItem(TMenu.MID_HELP_SEARCH); + helpMenu.addDefaultItem(TMenu.MID_HELP_PREVIOUS); + helpMenu.addDefaultItem(TMenu.MID_HELP_HELP); + helpMenu.addDefaultItem(TMenu.MID_HELP_ACTIVE_FILE); + helpMenu.addSeparator(); + helpMenu.addDefaultItem(TMenu.MID_ABOUT); + return helpMenu; + } + /** * Close all open windows. */ @@ -1732,11 +1800,8 @@ public class TApplication implements Runnable { if (activeMenu != null) { return; } - - synchronized (windows) { - for (TWindow window: windows) { - closeWindow(window); - } + while (windows.size() > 0) { + closeWindow(windows.get(0)); } }