cjk support wip
[fanfix.git] / src / jexer / TApplication.java
index 96f91f2943696d38a7f6e4d72b8fab2036da3482..7c96258b4405c00a5660788262a235a3c69c74d9 100644 (file)
  */
 package jexer;
 
+import java.io.File;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -60,6 +62,7 @@ import jexer.backend.ECMA48Backend;
 import jexer.backend.TWindowBackend;
 import jexer.menu.TMenu;
 import jexer.menu.TMenuItem;
+import jexer.menu.TSubMenu;
 import static jexer.TCommand.*;
 import static jexer.TKeypress.*;
 
@@ -129,6 +132,11 @@ public class TApplication implements Runnable {
      */
     private volatile WidgetEventHandler secondaryEventHandler;
 
+    /**
+     * The screen handler thread.
+     */
+    private volatile ScreenHandler screenHandler;
+
     /**
      * The widget receiving events from the secondary event handler thread.
      */
@@ -280,11 +288,6 @@ public class TApplication implements Runnable {
      */
     private boolean focusFollowsMouse = false;
 
-    /**
-     * The images that might be displayed.  Note package private access.
-     */
-    private List<TImage> images;
-
     /**
      * The list of commands to run before the next I/O check.
      */
@@ -430,9 +433,9 @@ public class TApplication implements Runnable {
                         // resumes working on the primary.
                         application.secondaryEventHandler = null;
 
-                        // DO NOT UNLOCK.  Primary thread just came back from
-                        // primaryHandleEvent() and will unlock in the else
-                        // block below.  Just wake it up.
+                        // We are ready to exit, wake up the primary thread.
+                        // Remember that it is currently sleeping inside its
+                        // primaryHandleEvent().
                         synchronized (application.primaryEventHandler) {
                             application.primaryEventHandler.notify();
                         }
@@ -452,6 +455,96 @@ public class TApplication implements Runnable {
         }
     }
 
+    /**
+     * ScreenHandler pushes screen updates to the physical device.
+     */
+    private class ScreenHandler implements Runnable {
+        /**
+         * The main application.
+         */
+        private TApplication application;
+
+        /**
+         * The dirty flag.
+         */
+        private boolean dirty = false;
+
+        /**
+         * Public constructor.
+         *
+         * @param application the main application
+         */
+        public ScreenHandler(final TApplication application) {
+            this.application = application;
+        }
+
+        /**
+         * The screen update loop.
+         */
+        public void run() {
+            // Wrap everything in a try, so that if we go belly up we can let
+            // the user have their terminal back.
+            try {
+                runImpl();
+            } catch (Throwable t) {
+                this.application.restoreConsole();
+                t.printStackTrace();
+                this.application.exit();
+            }
+        }
+
+        /**
+         * The update loop.
+         */
+        private void runImpl() {
+
+            // Loop forever
+            while (!application.quit) {
+
+                // Wait until application notifies me
+                while (!application.quit) {
+                    try {
+                        synchronized (this) {
+                            if (dirty) {
+                                dirty = false;
+                                break;
+                            }
+
+                            // Always check within 50 milliseconds.
+                            this.wait(50);
+                        }
+                    } catch (InterruptedException e) {
+                        // SQUASH
+                    }
+                } // while (!application.quit)
+
+                assert (dirty == true);
+
+                // Flush the screen contents
+                if (debugThreads) {
+                    System.err.printf("%d %s backend.flushScreen()\n",
+                        System.currentTimeMillis(), Thread.currentThread());
+                }
+                synchronized (getScreen()) {
+                    backend.flushScreen();
+                }
+            } // while (true) (main runnable loop)
+
+            // Shutdown the user I/O thread(s)
+            backend.shutdown();
+        }
+
+        /**
+         * Set the dirty flag.
+         */
+        public void setDirty() {
+            synchronized (this) {
+                dirty = true;
+            }
+        }
+
+    }
+
     // ------------------------------------------------------------------------
     // Constructors -----------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -603,7 +696,6 @@ public class TApplication implements Runnable {
         accelerators    = new HashMap<TKeypress, TMenuItem>();
         menuItems       = new LinkedList<TMenuItem>();
         desktop         = new TDesktop(this);
-        images          = new LinkedList<TImage>();
 
         // Special case: the Swing backend needs to have a timer to drive its
         // blink state.
@@ -636,6 +728,12 @@ public class TApplication implements Runnable {
      * Run this application until it exits.
      */
     public void run() {
+        // System.err.println("*** TApplication.run() begins ***");
+
+        // Start the screen updater thread
+        screenHandler = new ScreenHandler(this);
+        (new Thread(screenHandler)).start();
+
         // Start the main consumer thread
         primaryEventHandler = new WidgetEventHandler(this, true);
         (new Thread(primaryEventHandler)).start();
@@ -712,13 +810,15 @@ public class TApplication implements Runnable {
             }
         }
 
-        // Shutdown the user I/O thread(s)
-        backend.shutdown();
-
         // Close all the windows.  This gives them an opportunity to release
         // resources.
         closeAllWindows();
 
+        // Give the overarching application an opportunity to release
+        // resources.
+        onExit();
+
+        // System.err.println("*** TApplication.run() exits ***");
     }
 
     // ------------------------------------------------------------------------
@@ -812,11 +912,23 @@ public class TApplication implements Runnable {
             closeAllWindows();
             return true;
         }
+        if (menu.getId() == TMenu.MID_ABOUT) {
+            showAboutDialog();
+            return true;
+        }
         if (menu.getId() == TMenu.MID_REPAINT) {
             getScreen().clearPhysical();
             doRepaint();
             return true;
         }
+        if (menu.getId() == TMenu.MID_VIEW_IMAGE) {
+            openImage();
+            return true;
+        }
+        if (menu.getId() == TMenu.MID_CHANGE_FONT) {
+            new TFontChooserWindow(this);
+            return true;
+        }
         return false;
     }
 
@@ -870,6 +982,9 @@ public class TApplication implements Runnable {
             drawAll();
         }
 
+        // Wake up the screen repainter
+        wakeScreenHandler();
+
         if (debugThreads) {
             System.err.printf(System.currentTimeMillis() + " " +
                 Thread.currentThread() + " finishEventProcessing() END\n");
@@ -900,7 +1015,7 @@ public class TApplication implements Runnable {
         // Abort everything
         if (event instanceof TCommandEvent) {
             TCommandEvent command = (TCommandEvent) event;
-            if (command.getCmd().equals(cmAbort)) {
+            if (command.equals(cmAbort)) {
                 exit();
                 return;
             }
@@ -922,6 +1037,7 @@ public class TApplication implements Runnable {
                 if (desktop != null) {
                     desktop.setDimensions(0, 0, resize.getWidth(),
                         resize.getHeight() - 1);
+                    desktop.onResize(resize);
                 }
 
                 // Change menu edges if needed.
@@ -969,7 +1085,10 @@ public class TApplication implements Runnable {
                 mouseX = mouse.getX();
                 mouseY = mouse.getY();
             } else {
-                if (mouse.getType() == TMouseEvent.Type.MOUSE_UP) {
+                if ((mouse.getType() == TMouseEvent.Type.MOUSE_DOWN)
+                    && (!mouse.isMouseWheelUp())
+                    && (!mouse.isMouseWheelDown())
+                ) {
                     if ((mouse.getTime().getTime() - lastMouseUpTime) <
                         doubleClickTime) {
 
@@ -1151,7 +1270,10 @@ public class TApplication implements Runnable {
                 mouseX = mouse.getX();
                 mouseY = mouse.getY();
             } else {
-                if (mouse.getType() == TMouseEvent.Type.MOUSE_UP) {
+                if ((mouse.getType() == TMouseEvent.Type.MOUSE_DOWN)
+                    && (!mouse.isMouseWheelUp())
+                    && (!mouse.isMouseWheelDown())
+                ) {
                     if ((mouse.getTime().getTime() - lastMouseUpTime) <
                         doubleClickTime) {
 
@@ -1300,6 +1422,19 @@ public class TApplication implements Runnable {
         }
     }
 
+    /**
+     * Wake the sleeping screen handler.
+     */
+    private void wakeScreenHandler() {
+        if (!started) {
+            return;
+        }
+
+        synchronized (screenHandler) {
+            screenHandler.notify();
+        }
+    }
+
     // ------------------------------------------------------------------------
     // TApplication -----------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -1314,6 +1449,7 @@ public class TApplication implements Runnable {
         synchronized (invokeLaters) {
             invokeLaters.add(command);
         }
+        doRepaint();
     }
 
     /**
@@ -1452,6 +1588,53 @@ public class TApplication implements Runnable {
         this.focusFollowsMouse = focusFollowsMouse;
     }
 
+    /**
+     * Display the about dialog.
+     */
+    protected void showAboutDialog() {
+        String version = getClass().getPackage().getImplementationVersion();
+        if (version == null) {
+            // This is Java 9+, use a hardcoded string here.
+            version = "0.3.2";
+        }
+        messageBox(i18n.getString("aboutDialogTitle"),
+            MessageFormat.format(i18n.getString("aboutDialogText"), version),
+            TMessageBox.Type.OK);
+    }
+
+    /**
+     * Handle the Tool | Open image menu item.
+     */
+    private void openImage() {
+        try {
+            List<String> filters = new ArrayList<String>();
+            filters.add("^.*\\.[Jj][Pp][Gg]$");
+            filters.add("^.*\\.[Jj][Pp][Ee][Gg]$");
+            filters.add("^.*\\.[Pp][Nn][Gg]$");
+            filters.add("^.*\\.[Gg][Ii][Ff]$");
+            filters.add("^.*\\.[Bb][Mm][Pp]$");
+            String filename = fileOpenBox(".", TFileOpenBox.Type.OPEN, filters);
+            if (filename != null) {
+                new TImageWindow(this, new File(filename));
+            }
+        } catch (IOException e) {
+            // Show this exception to the user.
+            new TExceptionDialog(this, e);
+        }
+    }
+
+    /**
+     * Check if application is still running.
+     *
+     * @return true if the application is running
+     */
+    public final boolean isRunning() {
+        if (quit == true) {
+            return false;
+        }
+        return true;
+    }
+
     // ------------------------------------------------------------------------
     // Screen refresh loop ----------------------------------------------------
     // ------------------------------------------------------------------------
@@ -1463,10 +1646,42 @@ public class TApplication implements Runnable {
      * @param y row position
      */
     private void invertCell(final int x, final int y) {
+        invertCell(x, y, false);
+    }
+
+    /**
+     * Invert the cell color at a position.  This is used to track the mouse.
+     *
+     * @param x column position
+     * @param y row position
+     * @param onlyThisCell if true, only invert this cell
+     */
+    private void invertCell(final int x, final int y,
+        final boolean onlyThisCell) {
+
         if (debugThreads) {
             System.err.printf("%d %s invertCell() %d %d\n",
                 System.currentTimeMillis(), Thread.currentThread(), x, y);
+
+            if (activeWindow != null) {
+                System.err.println("activeWindow.hasHiddenMouse() " +
+                    activeWindow.hasHiddenMouse());
+            }
         }
+
+        // If this cell is on top of a visible window that has requested a
+        // hidden mouse, bail out.
+        if ((activeWindow != null) && (activeMenu == null)) {
+            if ((activeWindow.hasHiddenMouse() == true)
+                && (x > activeWindow.getX())
+                && (x < activeWindow.getX() + activeWindow.getWidth() - 1)
+                && (y > activeWindow.getY())
+                && (y < activeWindow.getY() + activeWindow.getHeight() - 1)
+            ) {
+                return;
+            }
+        }
+
         Cell cell = getScreen().getCharXY(x, y);
         if (cell.isImage()) {
             cell.invertImage();
@@ -1483,6 +1698,29 @@ public class TApplication implements Runnable {
             }
         }
         getScreen().putCharXY(x, y, cell);
+        if ((onlyThisCell == true) || (cell.getWidth() == Cell.Width.SINGLE)) {
+            return;
+        }
+
+        // This cell is one half of a fullwidth glyph.  Invert the other
+        // half.
+        if (cell.getWidth() == Cell.Width.LEFT) {
+            if (x < getScreen().getWidth() - 1) {
+                Cell rightHalf = getScreen().getCharXY(x + 1, y);
+                if (rightHalf.getWidth() == Cell.Width.RIGHT) {
+                    invertCell(x + 1, y, true);
+                    return;
+                }
+            }
+        }
+        assert (cell.getWidth() == Cell.Width.RIGHT);
+
+        if (x > 0) {
+            Cell leftHalf = getScreen().getCharXY(x - 1, y);
+            if (leftHalf.getWidth() == Cell.Width.LEFT) {
+                invertCell(x - 1, y, true);
+            }
+        }
     }
 
     /**
@@ -1521,7 +1759,7 @@ public class TApplication implements Runnable {
                 getScreen().putCharXY(oldDrawnMouseX, oldDrawnMouseY,
                     oldDrawnMouseCell);
                 oldDrawnMouseCell = getScreen().getCharXY(mouseX, mouseY);
-                if ((images.size() > 0) && (backend instanceof ECMA48Backend)) {
+                if (backend instanceof ECMA48Backend) {
                     // Special case: the entire row containing the mouse has
                     // to be re-drawn if it has any image data, AND any rows
                     // in between.
@@ -1548,8 +1786,8 @@ public class TApplication implements Runnable {
                 oldDrawnMouseX = mouseX;
                 oldDrawnMouseY = mouseY;
             }
-            if ((images.size() > 0) || getScreen().isDirty()) {
-                backend.flushScreen();
+            if (getScreen().isDirty()) {
+                screenHandler.setDirty();
             }
             return;
         }
@@ -1650,7 +1888,7 @@ public class TApplication implements Runnable {
                 oldDrawnMouseX, oldDrawnMouseY);
         }
         oldDrawnMouseCell = getScreen().getCharXY(mouseX, mouseY);
-        if ((images.size() > 0) && (backend instanceof ECMA48Backend)) {
+        if (backend instanceof ECMA48Backend) {
             // Special case: the entire row containing the mouse has to be
             // re-drawn if it has any image data, AND any rows in between.
             if (oldDrawnMouseY != mouseY) {
@@ -1700,11 +1938,9 @@ public class TApplication implements Runnable {
             getScreen().hideCursor();
         }
 
-        // Flush the screen contents
-        if ((images.size() > 0) || getScreen().isDirty()) {
-            backend.flushScreen();
+        if (getScreen().isDirty()) {
+            screenHandler.setDirty();
         }
-
         repaint = false;
     }
 
@@ -1718,6 +1954,14 @@ public class TApplication implements Runnable {
         }
     }
 
+    /**
+     * Subclasses can use this hook to cleanup resources.  Called as the last
+     * step of TApplication.run().
+     */
+    public void onExit() {
+        // Default does nothing.
+    }
+
     // ------------------------------------------------------------------------
     // TWindow management -----------------------------------------------------
     // ------------------------------------------------------------------------
@@ -1833,7 +2077,8 @@ public class TApplication implements Runnable {
 
         assert (!window.isActive());
         if (activeWindow != null) {
-            assert (activeWindow.getZ() == 0);
+            // TODO: see if this assertion is really necessary.
+            // assert (activeWindow.getZ() == 0);
 
             activeWindow.setActive(false);
 
@@ -1959,29 +2204,33 @@ public class TApplication implements Runnable {
             int z = window.getZ();
             window.setZ(-1);
             window.onUnfocus();
+            windows.remove(window);
             Collections.sort(windows);
-            windows.remove(0);
             activeWindow = null;
+            int newZ = 0;
+            boolean foundNextWindow = false;
+
             for (TWindow w: windows) {
+                w.setZ(newZ);
+                newZ++;
 
                 // Do not activate a hidden window.
                 if (w.isHidden()) {
                     continue;
                 }
 
-                if (w.getZ() > z) {
-                    w.setZ(w.getZ() - 1);
-                    if (w.getZ() == 0) {
-                        w.setActive(true);
-                        w.onFocus();
-                        assert (activeWindow == null);
-                        activeWindow = w;
-                    } else {
-                        if (w.isActive()) {
-                            w.setActive(false);
-                            w.onUnfocus();
-                        }
-                    }
+                if (foundNextWindow == false) {
+                    foundNextWindow = true;
+                    w.setActive(true);
+                    w.onFocus();
+                    assert (activeWindow == null);
+                    activeWindow = w;
+                    continue;
+                }
+
+                if (w.isActive()) {
+                    w.setActive(false);
+                    w.onUnfocus();
                 }
             }
         }
@@ -2162,6 +2411,21 @@ public class TApplication implements Runnable {
         return false;
     }
 
+    /**
+     * Check if there is a window with overridden menu flag on top.
+     *
+     * @return true if the active window is overriding the menu
+     */
+    private boolean overrideMenuWindowActive() {
+        if (activeWindow != null) {
+            if (activeWindow.hasOverriddenMenu()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Close all open windows.
      */
@@ -2401,46 +2665,6 @@ public class TApplication implements Runnable {
         window.setY(windowY);
     }
 
-    // ------------------------------------------------------------------------
-    // TImage management ------------------------------------------------------
-    // ------------------------------------------------------------------------
-
-    /**
-     * Add an image to the list.  Note package private access.
-     *
-     * @param image the image to add
-     * @throws IllegalArgumentException if the image is already used in
-     * another TApplication
-     */
-    final void addImage(final TImage image) {
-        if ((image.getApplication() != null)
-            && (image.getApplication() != this)
-        ) {
-            throw new IllegalArgumentException("Image " + image +
-                " is already " + "part of application " +
-                image.getApplication());
-        }
-        images.add(image);
-    }
-
-    /**
-     * Remove an image from the list.  Note package private access.
-     *
-     * @param image the image to remove
-     * @throws IllegalArgumentException if the image is already used in
-     * another TApplication
-     */
-    final void removeImage(final TImage image) {
-        if ((image.getApplication() != null)
-            && (image.getApplication() != this)
-        ) {
-            throw new IllegalArgumentException("Image " + image +
-                " is already " + "part of application " +
-                image.getApplication());
-        }
-        images.remove(image);
-    }
-
     // ------------------------------------------------------------------------
     // TMenu management -------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -2492,6 +2716,7 @@ public class TApplication implements Runnable {
         if ((mouse.getType() == TMouseEvent.Type.MOUSE_DOWN)
             && (mouse.isMouse1())
             && (!modalWindowActive())
+            && (!overrideMenuWindowActive())
             && (mouse.getAbsoluteY() == 0)
         ) {
 
@@ -2557,7 +2782,7 @@ public class TApplication implements Runnable {
 
         if (((focusFollowsMouse == true)
                 && (mouse.getType() == TMouseEvent.Type.MOUSE_MOTION))
-            || (mouse.getType() == TMouseEvent.Type.MOUSE_UP)
+            || (mouse.getType() == TMouseEvent.Type.MOUSE_DOWN)
         ) {
             synchronized (windows) {
                 Collections.sort(windows);
@@ -2794,6 +3019,21 @@ public class TApplication implements Runnable {
         }
     }
 
+    /**
+     * Get the menu item associated with this ID.
+     *
+     * @param id the menu item ID
+     * @return the menu item, or null if not found
+     */
+    public final TMenuItem getMenuItem(final int id) {
+        for (TMenuItem item: menuItems) {
+            if (item.getId() == id) {
+                return item;
+            }
+        }
+        return null;
+    }
+
     /**
      * Recompute menu x positions based on their title length.
      */
@@ -2873,6 +3113,22 @@ public class TApplication implements Runnable {
         return menu;
     }
 
+    /**
+     * Convenience function to add a default tools (hamburger) menu.
+     *
+     * @return the new menu
+     */
+    public final TMenu addToolMenu() {
+        TMenu toolMenu = addMenu(i18n.getString("toolMenuTitle"));
+        toolMenu.addDefaultItem(TMenu.MID_REPAINT);
+        toolMenu.addDefaultItem(TMenu.MID_VIEW_IMAGE);
+        toolMenu.addDefaultItem(TMenu.MID_CHANGE_FONT);
+        TStatusBar toolStatusBar = toolMenu.newStatusBar(i18n.
+            getString("toolMenuStatus"));
+        toolStatusBar.addShortcutKeypress(kbF1, cmHelp, i18n.getString("Help"));
+        return toolMenu;
+    }
+
     /**
      * Convenience function to add a default "File" menu.
      *
@@ -2880,9 +3136,8 @@ public class TApplication implements Runnable {
      */
     public final TMenu addFileMenu() {
         TMenu fileMenu = addMenu(i18n.getString("fileMenuTitle"));
-        fileMenu.addDefaultItem(TMenu.MID_OPEN_FILE);
-        fileMenu.addSeparator();
         fileMenu.addDefaultItem(TMenu.MID_SHELL);
+        fileMenu.addSeparator();
         fileMenu.addDefaultItem(TMenu.MID_EXIT);
         TStatusBar statusBar = fileMenu.newStatusBar(i18n.
             getString("fileMenuStatus"));
@@ -2950,6 +3205,64 @@ public class TApplication implements Runnable {
         return helpMenu;
     }
 
+    /**
+     * Convenience function to add a default "Table" menu.
+     *
+     * @return the new menu
+     */
+    public final TMenu addTableMenu() {
+        TMenu tableMenu = addMenu(i18n.getString("tableMenuTitle"));
+        tableMenu.addDefaultItem(TMenu.MID_TABLE_RENAME_COLUMN, false);
+        tableMenu.addDefaultItem(TMenu.MID_TABLE_RENAME_ROW, false);
+        tableMenu.addSeparator();
+
+        TSubMenu viewMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuView"));
+        viewMenu.addDefaultItem(TMenu.MID_TABLE_VIEW_ROW_LABELS, false);
+        viewMenu.addDefaultItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS, false);
+        viewMenu.addDefaultItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW, false);
+        viewMenu.addDefaultItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN, false);
+
+        TSubMenu borderMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuBorders"));
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_NONE, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_ALL, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_CELL_NONE, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_CELL_ALL, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_RIGHT, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_LEFT, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_TOP, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_BOTTOM, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_DOUBLE_BOTTOM, false);
+        borderMenu.addDefaultItem(TMenu.MID_TABLE_BORDER_THICK_BOTTOM, false);
+        TSubMenu deleteMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuDelete"));
+        deleteMenu.addDefaultItem(TMenu.MID_TABLE_DELETE_LEFT, false);
+        deleteMenu.addDefaultItem(TMenu.MID_TABLE_DELETE_UP, false);
+        deleteMenu.addDefaultItem(TMenu.MID_TABLE_DELETE_ROW, false);
+        deleteMenu.addDefaultItem(TMenu.MID_TABLE_DELETE_COLUMN, false);
+        TSubMenu insertMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuInsert"));
+        insertMenu.addDefaultItem(TMenu.MID_TABLE_INSERT_LEFT, false);
+        insertMenu.addDefaultItem(TMenu.MID_TABLE_INSERT_RIGHT, false);
+        insertMenu.addDefaultItem(TMenu.MID_TABLE_INSERT_ABOVE, false);
+        insertMenu.addDefaultItem(TMenu.MID_TABLE_INSERT_BELOW, false);
+        TSubMenu columnMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuColumn"));
+        columnMenu.addDefaultItem(TMenu.MID_TABLE_COLUMN_NARROW, false);
+        columnMenu.addDefaultItem(TMenu.MID_TABLE_COLUMN_WIDEN, false);
+        TSubMenu fileMenu = tableMenu.addSubMenu(i18n.
+            getString("tableSubMenuFile"));
+        fileMenu.addDefaultItem(TMenu.MID_TABLE_FILE_OPEN_CSV, false);
+        fileMenu.addDefaultItem(TMenu.MID_TABLE_FILE_SAVE_CSV, false);
+        fileMenu.addDefaultItem(TMenu.MID_TABLE_FILE_SAVE_TEXT, false);
+
+        TStatusBar statusBar = tableMenu.newStatusBar(i18n.
+            getString("tableMenuStatus"));
+        statusBar.addShortcutKeypress(kbF1, cmHelp, i18n.getString("Help"));
+        return tableMenu;
+    }
+
     // ------------------------------------------------------------------------
     // TTimer management ------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -3222,7 +3535,7 @@ public class TApplication implements Runnable {
     public final TTerminalWindow openTerminal(final int x, final int y,
         final int flags, final String commandLine) {
 
-        return new TTerminalWindow(this, x, y, flags, commandLine.split("\\s"));
+        return new TTerminalWindow(this, x, y, flags, commandLine.split("\\s+"));
     }
 
     /**
@@ -3239,7 +3552,7 @@ public class TApplication implements Runnable {
     public final TTerminalWindow openTerminal(final int x, final int y,
         final int flags, final String commandLine, final boolean closeOnExit) {
 
-        return new TTerminalWindow(this, x, y, flags, commandLine.split("\\s"),
+        return new TTerminalWindow(this, x, y, flags, commandLine.split("\\s+"),
             closeOnExit);
     }