+ // ------------------------------------------------------------------------
+ // TWidget ----------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Draw the bar.
+ */
+ @Override
+ public void draw() {
+ CellAttributes barColor = new CellAttributes();
+ barColor.setTo(getTheme().getColor("tstatusbar.text"));
+ CellAttributes keyColor = new CellAttributes();
+ keyColor.setTo(getTheme().getColor("tstatusbar.button"));
+ CellAttributes selectedColor = new CellAttributes();
+ selectedColor.setTo(getTheme().getColor("tstatusbar.selected"));
+
+ // Status bar is weird. Its draw() method is called directly by
+ // TApplication after everything is drawn, and after
+ // Screen.resetClipping(). So at this point we are drawing in
+ // absolute coordinates, not relative to our TWindow.
+ int row = getScreen().getHeight() - 1;
+ int width = getScreen().getWidth();
+
+ hLineXY(0, row, width, ' ', barColor);
+
+ int col = 0;
+ for (TStatusBarKey key: keys) {
+ String keyStr = key.key.toString();
+ if (key.selected) {
+ putCharXY(col++, row, ' ', selectedColor);
+ putStringXY(col, row, keyStr, selectedColor);
+ col += StringUtils.width(keyStr);
+ putCharXY(col++, row, ' ', selectedColor);
+ putStringXY(col, row, key.label, selectedColor);
+ col += StringUtils.width(key.label);
+ putCharXY(col++, row, ' ', selectedColor);
+ } else {
+ putCharXY(col++, row, ' ', barColor);
+ putStringXY(col, row, keyStr, keyColor);
+ col += StringUtils.width(keyStr) + 1;
+ putStringXY(col, row, key.label, barColor);
+ col += StringUtils.width(key.label);
+ putCharXY(col++, row, ' ', barColor);
+ }
+ }
+ if (text.length() > 0) {
+ if (keys.size() > 0) {
+ putCharXY(col++, row, GraphicsChars.VERTICAL_BAR, barColor);
+ }
+ putCharXY(col++, row, ' ', barColor);
+ putStringXY(col, row, text, barColor);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // TStatusBar -------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add a key to this status bar.
+ *
+ * @param key the key to trigger on
+ * @param cmd the command event to issue when key is pressed or this item
+ * is clicked
+ * @param label the label for this action
+ */
+ public void addShortcutKeypress(final TKeypress key, final TCommand cmd,
+ final String label) {
+
+ TStatusBarKey newKey = new TStatusBarKey(key, cmd, label);
+ if (keys.size() > 0) {
+ TStatusBarKey oldKey = keys.get(keys.size() - 1);
+ newKey.x = oldKey.x + oldKey.width();
+ }
+ keys.add(newKey);
+ }
+
+ /**
+ * Set the text to display on the right side of the shortcut keys.
+ *
+ * @param text the new text
+ */
+ public void setText(final String text) {
+ this.text = text;
+ }
+