X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWidget.java;h=a32b716a523eebe2231947b1f680da4b693aa2a2;hb=7668cb45fd91775da14504919d8a239af2f7c07e;hp=6cb0f98b1fe4c6634334c13f081a07fbd78a7e0e;hpb=92554d64c21c6a477fd23a06ca3a64a542b622a3;p=fanfix.git diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 6cb0f98..a32b716 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -133,7 +133,7 @@ public abstract class TWidget implements Comparable { * * @return if true, this widget will receive events */ - public final boolean getActive() { + public final boolean isActive() { return active; } @@ -267,7 +267,7 @@ public abstract class TWidget implements Comparable { * * @return if true, this widget can be tabbed to or receive events */ - public final boolean getEnabled() { + public final boolean isEnabled() { return enabled; } @@ -303,15 +303,15 @@ public abstract class TWidget implements Comparable { /** * If true, this widget has a cursor. */ - private boolean hasCursor = false; + private boolean cursorVisible = false; /** * Set visible cursor flag. * - * @param hasCursor if true, this widget has a cursor + * @param cursorVisible if true, this widget has a cursor */ - public final void setHasCursor(final boolean hasCursor) { - this.hasCursor = hasCursor; + public final void setCursorVisible(final boolean cursorVisible) { + this.cursorVisible = cursorVisible; } /** @@ -319,8 +319,8 @@ public abstract class TWidget implements Comparable { * * @return if true, this widget has a visible cursor */ - public final boolean visibleCursor() { - return hasCursor; + public final boolean isCursorVisible() { + return cursorVisible; } /** @@ -370,11 +370,16 @@ public abstract class TWidget implements Comparable { } /** - * Comparison operator sorts on tabOrder for TWidgets and z for TWindows. + * Comparison operator sorts on: + *
    + *
  • tabOrder for TWidgets
  • + *
  • z for TWindows
  • + *
  • text for TTreeItems
  • + *
* - * @param that another TWidget or TWindow instance + * @param that another TWidget, TWindow, or TTreeItem instance * @return difference between this.tabOrder and that.tabOrder, or - * difference between this.z and that.z + * difference between this.z and that.z, or String.compareTo(text) */ @Override public final int compareTo(final TWidget that) { @@ -383,6 +388,12 @@ public abstract class TWidget implements Comparable { ) { return (((TWindow) this).getZ() - ((TWindow) that).getZ()); } + if ((this instanceof TTreeItem) + && (that instanceof TTreeItem) + ) { + return (((TTreeItem) this).getText().compareTo( + ((TTreeItem) that).getText())); + } return (this.tabOrder - that.tabOrder); } @@ -392,11 +403,11 @@ public abstract class TWidget implements Comparable { * @return true if this widget is active and all of its parents are * active. */ - public final boolean getAbsoluteActive() { + public final boolean isAbsoluteActive() { if (parent == this) { return active; } - return (active && parent.getAbsoluteActive()); + return (active && parent.isAbsoluteActive()); } /** @@ -405,7 +416,7 @@ public abstract class TWidget implements Comparable { * @return absolute screen column number for the cursor's X position */ public final int getCursorAbsoluteX() { - assert (hasCursor); + assert (cursorVisible); return getAbsoluteX() + cursorX; } @@ -415,7 +426,7 @@ public abstract class TWidget implements Comparable { * @return absolute screen row number for the cursor's Y position */ public final int getCursorAbsoluteY() { - assert (hasCursor); + assert (cursorVisible); return getAbsoluteY() + cursorY; } @@ -781,12 +792,12 @@ public abstract class TWidget implements Comparable { for (TWidget widget: children) { if (widget instanceof TButton) { TButton button = (TButton) widget; - if (button.getEnabled() - && !keypress.getKey().getIsKey() - && keypress.getKey().getAlt() - && !keypress.getKey().getCtrl() + if (button.isEnabled() + && !keypress.getKey().isFnKey() + && keypress.getKey().isAlt() + && !keypress.getKey().isCtrl() && (Character.toLowerCase(button.getMnemonic().getShortcut()) - == Character.toLowerCase(keypress.getKey().getCh())) + == Character.toLowerCase(keypress.getKey().getChar())) ) { widget.handleEvent(new TKeypressEvent(kbEnter)); @@ -1272,4 +1283,34 @@ public abstract class TWidget implements Comparable { updateAction); } + /** + * Convenience function to add a tree view to this container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width width of tree view + * @param height height of tree view + */ + public final TTreeView addTreeView(final int x, final int y, + final int width, final int height) { + + return new TTreeView(this, x, y, width, height); + } + + /** + * Convenience function to add a tree view to this container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width width of tree view + * @param height height of tree view + * @param action action to perform when an item is selected + */ + public final TTreeView addTreeView(final int x, final int y, + final int width, final int height, final TAction action) { + + return new TTreeView(this, x, y, width, height, action); + } + + }