X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjexer%2FTSplitPane.java;h=277f080e22af099cf0bb576eb09dd4637027e4c2;hb=6738825512004e0992555778e7124b568dd5044c;hp=0a3443b85eeda57511fd486db0539dc663e08f6a;hpb=5ffeabccc177e9fdadb62002c6d3bf1f6ae650fa;p=nikiroo-utils.git diff --git a/src/jexer/TSplitPane.java b/src/jexer/TSplitPane.java index 0a3443b..277f080 100644 --- a/src/jexer/TSplitPane.java +++ b/src/jexer/TSplitPane.java @@ -81,6 +81,11 @@ public class TSplitPane extends TWidget { */ private boolean inSplitMove = false; + /** + * The last seen mouse position. + */ + private TMouseEvent mouse; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -136,6 +141,7 @@ public class TSplitPane extends TWidget { */ @Override public void onMouseDown(final TMouseEvent mouse) { + this.mouse = mouse; inSplitMove = false; @@ -161,6 +167,7 @@ public class TSplitPane extends TWidget { */ @Override public void onMouseUp(final TMouseEvent mouse) { + this.mouse = mouse; if (inSplitMove && mouse.isMouse1()) { // Stop moving split @@ -179,6 +186,16 @@ public class TSplitPane extends TWidget { */ @Override public void onMouseMotion(final TMouseEvent mouse) { + this.mouse = mouse; + + if ((mouse.getAbsoluteX() - getAbsoluteX() < 0) + || (mouse.getAbsoluteX() - getAbsoluteX() >= getWidth()) + || (mouse.getAbsoluteY() - getAbsoluteY() < 0) + || (mouse.getAbsoluteY() - getAbsoluteY() >= getHeight()) + ) { + // Mouse has travelled out of my window. + inSplitMove = false; + } if (inSplitMove) { if (vertical) { @@ -209,10 +226,29 @@ public class TSplitPane extends TWidget { if (vertical) { vLineXY(split, 0, getHeight(), GraphicsChars.WINDOW_SIDE, attr); // TODO: draw intersections of children + + if ((mouse != null) + && (mouse.getAbsoluteX() == getAbsoluteX() + split) + && (mouse.getAbsoluteY() >= getAbsoluteY()) && + (mouse.getAbsoluteY() < getAbsoluteY() + getHeight()) + ) { + putCharXY(split, mouse.getAbsoluteY() - getAbsoluteY(), + '\u2194', attr); + } } else { hLineXY(0, split, getWidth(), GraphicsChars.SINGLE_BAR, attr); // TODO: draw intersections of children + + if ((mouse != null) + && (mouse.getAbsoluteY() == getAbsoluteY() + split) + && (mouse.getAbsoluteX() >= getAbsoluteX()) && + (mouse.getAbsoluteX() < getAbsoluteX() + getWidth()) + ) { + putCharXY(mouse.getAbsoluteX() - getAbsoluteX(), split, + '\u2195', attr); + } } + } // ------------------------------------------------------------------------ @@ -382,4 +418,56 @@ public class TSplitPane extends TWidget { layoutChildren(); } + /** + * Remove this split, removing the widget specified. + * + * @param widgetToRemove the widget to remove + * @param doClose if true, call the close() method before removing the + * child + * @return the pane that remains, or null if nothing is retained + */ + public TWidget removeSplit(final TWidget widgetToRemove, + final boolean doClose) { + + TWidget keep = null; + if (vertical) { + if ((widgetToRemove != left) && (widgetToRemove != right)) { + throw new IllegalArgumentException("widget to remove is not " + + "either of the panes in this splitpane"); + } + if (widgetToRemove == left) { + keep = right; + } else { + keep = left; + } + + } else { + if ((widgetToRemove != top) && (widgetToRemove != bottom)) { + throw new IllegalArgumentException("widget to remove is not " + + "either of the panes in this splitpane"); + } + if (widgetToRemove == top) { + keep = bottom; + } else { + keep = top; + } + } + + // Remove me from my parent widget. + TWidget newParent = getParent(); + setParent(null, false); + + if (keep == null) { + // Nothing is left of either pane. Remove me and bail out. + return null; + } + + keep.setParent(newParent, false); + keep.setDimensions(getX(), getY(), getWidth(), getHeight()); + keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(), + getHeight())); + + return keep; + } + }