ttable navigation minimally working
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 28 Jul 2019 17:53:29 +0000 (12:53 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 28 Jul 2019 17:53:29 +0000 (12:53 -0500)
src/jexer/TApplication.java
src/jexer/TApplication.properties
src/jexer/TTableWidget.java
src/jexer/TTableWindow.java
src/jexer/bits/ColorTheme.java
src/jexer/menu/TMenu.java
src/jexer/menu/TMenu.properties
src/jexer/menu/TMenuItem.java

index 41fbea5b8459bb147cc099f2ddbd62f7b7cabd90..199fa1b66f41ced083466b7975d28233d8f24ff6 100644 (file)
@@ -2923,6 +2923,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.
      */
@@ -3101,6 +3116,13 @@ public class TApplication implements Runnable {
      */
     public final TMenu addTableMenu() {
         TMenu tableMenu = addMenu(i18n.getString("tableMenuTitle"));
+        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);
index 5c50457c72c4541c7d5122ad26cc37b2830fc645..299c6a3a90501469469dc7a8550a3c8f42cf146d 100644 (file)
@@ -12,6 +12,7 @@ helpMenuTitle=&Help
 helpMenuStatus=Access online help
 
 tableMenuTitle=&Table
+tableSubMenuView=&View
 tableSubMenuBorders=&Borders
 tableSubMenuDelete=&Delete
 tableSubMenuInsert=&Insert
index c5d96ddb2991511fcf083b3ac4cad4d17c70a94b..bd53977341d93799f93d6fde43903a24712fb52c 100644 (file)
@@ -389,6 +389,8 @@ public class TTableWidget extends TWidget {
                 field.setInactiveColorKey("ttable.inactive");
             }
 
+            assert (isVisible() == true);
+
             super.draw();
         }
 
@@ -462,6 +464,18 @@ public class TTableWidget extends TWidget {
         activate(columns.get(selectedColumn).get(selectedRow));
 
         alignGrid();
+
+        // Set the menu to match the flags.
+        getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS).
+                setChecked(showRowLabels);
+        getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS).
+                setChecked(showColumnLabels);
+        getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW).
+                setChecked(highlightRow);
+        getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN).
+                setChecked(highlightColumn);
+
+
     }
 
     // ------------------------------------------------------------------------
@@ -553,6 +567,18 @@ public class TTableWidget extends TWidget {
     @Override
     public void onMenu(final TMenuEvent menu) {
         switch (menu.getId()) {
+        case TMenu.MID_TABLE_VIEW_ROW_LABELS:
+            showRowLabels = getApplication().getMenuItem(menu.getId()).getChecked();
+            break;
+        case TMenu.MID_TABLE_VIEW_COLUMN_LABELS:
+            showColumnLabels = getApplication().getMenuItem(menu.getId()).getChecked();
+            break;
+        case TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW:
+            highlightRow = getApplication().getMenuItem(menu.getId()).getChecked();
+            break;
+        case TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN:
+            highlightColumn = getApplication().getMenuItem(menu.getId()).getChecked();
+            break;
         case TMenu.MID_TABLE_BORDER_NONE:
         case TMenu.MID_TABLE_BORDER_ALL:
         case TMenu.MID_TABLE_BORDER_RIGHT:
@@ -602,6 +628,8 @@ public class TTableWidget extends TWidget {
         default:
             super.onMenu(menu);
         }
+
+        alignGrid();
     }
 
     // ------------------------------------------------------------------------
@@ -609,12 +637,12 @@ public class TTableWidget extends TWidget {
     // ------------------------------------------------------------------------
 
     /**
-     * Draw the table row/column headings, and borders.
+     * Draw the table row/column labels, and borders.
      */
     @Override
     public void draw() {
-        CellAttributes headingColor = getTheme().getColor("ttable.heading");
-        CellAttributes headingColorSelected = getTheme().getColor("ttable.heading.selected");
+        CellAttributes labelColor = getTheme().getColor("ttable.label");
+        CellAttributes labelColorSelected = getTheme().getColor("ttable.label.selected");
         CellAttributes borderColor = getTheme().getColor("ttable.border");
 
         // Column labels.
@@ -625,7 +653,7 @@ public class TTableWidget extends TWidget {
                 }
                 putStringXY(columns.get(i).get(top).getX(), 0,
                     String.format(" %-6s ", columns.get(i).label),
-                    (i == selectedColumn ? headingColorSelected : headingColor));
+                    (i == selectedColumn ? labelColorSelected : labelColor));
             }
         }
 
@@ -637,7 +665,7 @@ public class TTableWidget extends TWidget {
                 }
                 putStringXY(0, rows.get(i).get(left).getY(),
                     String.format(" %-6s ", rows.get(i).label),
-                    (i == selectedRow ? headingColorSelected : headingColor));
+                    (i == selectedRow ? labelColorSelected : labelColor));
             }
         }
 
@@ -744,7 +772,6 @@ public class TTableWidget extends TWidget {
         // Adjust X locations to be visible -----------------------------------
 
         // Determine if we need to shift left or right.
-        int width = getMaximumWidth();
         int leftCellX = 0;
         if (showRowLabels == true) {
             // For now, all row labels are 8 cells wide.  TODO: make this
@@ -822,7 +849,6 @@ public class TTableWidget extends TWidget {
         // The same logic as above, but applied to the column Y.
 
         // Determine if we need to shift up or down.
-        int height = getMaximumHeight();
         int topCellY = 0;
         if (showColumnLabels == true) {
             // For now, all column labels are 1 cell high.  TODO: make this
@@ -867,10 +893,11 @@ public class TTableWidget extends TWidget {
          * selected cell Y is topCellY.
          */
         for (int x = 0; x < columns.size(); x++) {
-            if (columns.get(x).cells.get(0).isVisible() == false) {
-                // This entire column will not be visible, as determined by
-                // the width checks above.  Do no further processing.
-                break;
+
+            if (columns.get(x).get(0).isVisible() == false) {
+                // This column won't be visible as determined by the checks
+                // above, just continue to the next.
+                continue;
             }
 
             // All cells above the selected cell.
@@ -890,7 +917,6 @@ public class TTableWidget extends TWidget {
 
             // Selected cell.
             columns.get(x).cells.get(selectedRow).setY(topCellY);
-            assert (columns.get(x).cells.get(selectedRow).isVisible());
 
             // All cells below the selected cell.
             newCellY = topCellY + selectedRowCell.getHeight();
index 507dde72df8e923150e89ce7214d136658e21e68..33b8116c17da51664adf614a92979c409acbda41 100644 (file)
@@ -88,6 +88,10 @@ public class TTableWindow extends TScrollableWindow {
     public void onFocus() {
         // Enable the table menu items.
         getApplication().enableMenuItem(TMenu.MID_CUT);
+        getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS);
+        getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS);
+        getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW);
+        getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN);
         getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_NONE);
         getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_ALL);
         getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_RIGHT);
@@ -117,6 +121,10 @@ public class TTableWindow extends TScrollableWindow {
     public void onUnfocus() {
         // Disable the table menu items.
         getApplication().disableMenuItem(TMenu.MID_CUT);
+        getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS);
+        getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS);
+        getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW);
+        getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN);
         getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_NONE);
         getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_ALL);
         getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_RIGHT);
index 86fc9b28d6a03f34a738b5ee7d4658ae859c5a2e..701ea75d17b09ee81018aea373c9fdfd933cbeaa 100644 (file)
@@ -654,12 +654,12 @@ public class ColorTheme {
         color.setForeColor(Color.BLACK);
         color.setBackColor(Color.WHITE);
         color.setBold(false);
-        colors.put("ttable.heading", color);
+        colors.put("ttable.label", color);
         color = new CellAttributes();
         color.setForeColor(Color.BLUE);
         color.setBackColor(Color.WHITE);
         color.setBold(false);
-        colors.put("ttable.heading.selected", color);
+        colors.put("ttable.label.selected", color);
         color = new CellAttributes();
         color.setForeColor(Color.WHITE);
         color.setBackColor(Color.BLUE);
index 1bcc80055a63b70e79ac8f9f95da8cb9b05945b6..142045699e9601963c2d3356beaaf6a6c9898bff 100644 (file)
@@ -102,26 +102,30 @@ public class TMenu extends TWindow {
     public static final int MID_ABOUT                   = 56;
 
     // Table menu
-    public static final int MID_TABLE_BORDER_NONE               = 60;
-    public static final int MID_TABLE_BORDER_ALL                = 61;
-    public static final int MID_TABLE_BORDER_RIGHT              = 62;
-    public static final int MID_TABLE_BORDER_LEFT               = 63;
-    public static final int MID_TABLE_BORDER_TOP                = 64;
-    public static final int MID_TABLE_BORDER_BOTTOM             = 65;
-    public static final int MID_TABLE_BORDER_DOUBLE_BOTTOM      = 66;
-    public static final int MID_TABLE_BORDER_THICK_BOTTOM       = 67;
-    public static final int MID_TABLE_DELETE_LEFT               = 68;
-    public static final int MID_TABLE_DELETE_UP                 = 69;
-    public static final int MID_TABLE_DELETE_ROW                = 70;
-    public static final int MID_TABLE_DELETE_COLUMN             = 71;
-    public static final int MID_TABLE_INSERT_LEFT               = 72;
-    public static final int MID_TABLE_INSERT_RIGHT              = 73;
-    public static final int MID_TABLE_INSERT_ABOVE              = 74;
-    public static final int MID_TABLE_INSERT_BELOW              = 75;
-    public static final int MID_TABLE_COLUMN_NARROW             = 76;
-    public static final int MID_TABLE_COLUMN_WIDEN              = 77;
-    public static final int MID_TABLE_FILE_SAVE_CSV             = 78;
-    public static final int MID_TABLE_FILE_SAVE_TEXT            = 79;
+    public static final int MID_TABLE_VIEW_ROW_LABELS           = 60;
+    public static final int MID_TABLE_VIEW_COLUMN_LABELS        = 61;
+    public static final int MID_TABLE_VIEW_HIGHLIGHT_ROW        = 62;
+    public static final int MID_TABLE_VIEW_HIGHLIGHT_COLUMN     = 63;
+    public static final int MID_TABLE_BORDER_NONE               = 64;
+    public static final int MID_TABLE_BORDER_ALL                = 65;
+    public static final int MID_TABLE_BORDER_RIGHT              = 66;
+    public static final int MID_TABLE_BORDER_LEFT               = 67;
+    public static final int MID_TABLE_BORDER_TOP                = 68;
+    public static final int MID_TABLE_BORDER_BOTTOM             = 69;
+    public static final int MID_TABLE_BORDER_DOUBLE_BOTTOM      = 70;
+    public static final int MID_TABLE_BORDER_THICK_BOTTOM       = 71;
+    public static final int MID_TABLE_DELETE_LEFT               = 72;
+    public static final int MID_TABLE_DELETE_UP                 = 73;
+    public static final int MID_TABLE_DELETE_ROW                = 74;
+    public static final int MID_TABLE_DELETE_COLUMN             = 75;
+    public static final int MID_TABLE_INSERT_LEFT               = 76;
+    public static final int MID_TABLE_INSERT_RIGHT              = 77;
+    public static final int MID_TABLE_INSERT_ABOVE              = 78;
+    public static final int MID_TABLE_INSERT_BELOW              = 79;
+    public static final int MID_TABLE_COLUMN_NARROW             = 80;
+    public static final int MID_TABLE_COLUMN_WIDEN              = 81;
+    public static final int MID_TABLE_FILE_SAVE_CSV             = 82;
+    public static final int MID_TABLE_FILE_SAVE_TEXT            = 83;
 
     // ------------------------------------------------------------------------
     // Variables --------------------------------------------------------------
@@ -530,6 +534,8 @@ public class TMenu extends TWindow {
 
         String label;
         TKeypress key = null;
+        boolean checkable = false;
+        boolean checked = false;
 
         switch (id) {
 
@@ -649,6 +655,27 @@ public class TMenu extends TWindow {
             label = i18n.getString("menuHelpAbout");
             break;
 
+        case MID_TABLE_VIEW_ROW_LABELS:
+            label = i18n.getString("menuTableViewRowLabels");
+            checkable = true;
+            checked = true;
+            break;
+        case MID_TABLE_VIEW_COLUMN_LABELS:
+            label = i18n.getString("menuTableViewColumnLabels");
+            checkable = true;
+            checked = true;
+            break;
+        case MID_TABLE_VIEW_HIGHLIGHT_ROW:
+            label = i18n.getString("menuTableViewHighlightRow");
+            checkable = true;
+            checked = true;
+            break;
+        case MID_TABLE_VIEW_HIGHLIGHT_COLUMN:
+            label = i18n.getString("menuTableViewHighlightColumn");
+            checkable = true;
+            checked = true;
+            break;
+
         case MID_TABLE_BORDER_NONE:
             label = i18n.getString("menuTableBorderNone");
             break;
@@ -716,7 +743,9 @@ public class TMenu extends TWindow {
             throw new IllegalArgumentException("Invalid menu ID: " + id);
         }
 
-        return addItemInternal(id, label, key, enabled);
+        TMenuItem item = addItemInternal(id, label, key, enabled);
+        item.setCheckable(checkable);
+        return item;
     }
 
     /**
index c64da1876249bac2b42d18e5161f451488ca3d6f..327415756bf2bf7b68a00bd8f7c87513e17d4935 100644 (file)
@@ -26,6 +26,10 @@ menuHelpHelp=&Help on help
 menuHelpActive=Active &file...
 menuHelpAbout=&About...
 
+menuTableViewRowLabels=&Row Labels
+menuTableViewColumnLabels=&Column Labels
+menuTableViewHighlightRow=Highlight Selected R&ow
+menuTableViewHighlightColumn=Highlight Selected Co&lumn
 menuTableBorderNone=&None
 menuTableBorderAll=&All
 menuTableBorderRight=&Right
index 6e455d8e99c2bc2756ff0ae23302e73fdbc001ae..bd149abb08b4ae8e6c65943b249832e954c4e78d 100644 (file)
@@ -263,6 +263,30 @@ public class TMenuItem extends TWidget {
         this.checkable = checkable;
     }
 
+    /**
+     * Get checkable flag.
+     *
+     * @return true if this menu item is both checkable and checked
+     */
+    public final boolean getChecked() {
+        return ((checkable == true) && (checked == true));
+    }
+
+    /**
+     * Set checked flag.  Note that setting checked on an item checkable will
+     * do nothing.
+     *
+     * @param checked if true, and if this menu item is checkable, then
+     * getChecked() will return true
+     */
+    public final void setChecked(final boolean checked) {
+        if (checkable) {
+            this.checked = checked;
+        } else {
+            this.checked = false;
+        }
+    }
+
     /**
      * Get the mnemonic string for this menu item.
      *