}
}
+ /**
+ * 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.
*/
*/
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);
helpMenuStatus=Access online help
tableMenuTitle=&Table
+tableSubMenuView=&View
tableSubMenuBorders=&Borders
tableSubMenuDelete=&Delete
tableSubMenuInsert=&Insert
field.setInactiveColorKey("ttable.inactive");
}
+ assert (isVisible() == true);
+
super.draw();
}
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);
+
+
}
// ------------------------------------------------------------------------
@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:
default:
super.onMenu(menu);
}
+
+ alignGrid();
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/**
- * 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.
}
putStringXY(columns.get(i).get(top).getX(), 0,
String.format(" %-6s ", columns.get(i).label),
- (i == selectedColumn ? headingColorSelected : headingColor));
+ (i == selectedColumn ? labelColorSelected : labelColor));
}
}
}
putStringXY(0, rows.get(i).get(left).getY(),
String.format(" %-6s ", rows.get(i).label),
- (i == selectedRow ? headingColorSelected : headingColor));
+ (i == selectedRow ? labelColorSelected : labelColor));
}
}
// 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
// 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
* 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.
// 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();
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);
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);
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);
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 --------------------------------------------------------------
String label;
TKeypress key = null;
+ boolean checkable = false;
+ boolean checked = false;
switch (id) {
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;
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;
}
/**
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
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.
*