+ /**
+ * Remove a widget, regardless of what pane it is on.
+ *
+ * @param widget the widget to remove
+ */
+ public void removeWidget(final TWidget widget) {
+ if (widget == null) {
+ throw new IllegalArgumentException("cannot remove null widget");
+ }
+ if (left == widget) {
+ left = null;
+ assert(right != widget);
+ assert(top != widget);
+ assert(bottom != widget);
+ return;
+ }
+ if (right == widget) {
+ right = null;
+ assert(left != widget);
+ assert(top != widget);
+ assert(bottom != widget);
+ return;
+ }
+ if (top == widget) {
+ top = null;
+ assert(left != widget);
+ assert(right != widget);
+ assert(bottom != widget);
+ return;
+ }
+ if (bottom == widget) {
+ bottom = null;
+ assert(left != widget);
+ assert(right != widget);
+ assert(top != widget);
+ return;
+ }
+ throw new IllegalArgumentException("widget " + widget +
+ " not in this split");
+ }
+
+ /**
+ * Replace a widget, regardless of what pane it is on, with another
+ * widget.
+ *
+ * @param oldWidget the widget to remove
+ * @param newWidget the widget to replace it with
+ */
+ public void replaceWidget(final TWidget oldWidget,
+ final TWidget newWidget) {
+
+ if (oldWidget == null) {
+ throw new IllegalArgumentException("cannot remove null oldWidget");
+ }
+ if (left == oldWidget) {
+ setLeft(newWidget);
+ assert(right != newWidget);
+ assert(top != newWidget);
+ assert(bottom != newWidget);
+ return;
+ }
+ if (right == oldWidget) {
+ setRight(newWidget);
+ assert(left != newWidget);
+ assert(top != newWidget);
+ assert(bottom != newWidget);
+ return;
+ }
+ if (top == oldWidget) {
+ setTop(newWidget);
+ assert(left != newWidget);
+ assert(right != newWidget);
+ assert(bottom != newWidget);
+ return;
+ }
+ if (bottom == oldWidget) {
+ setBottom(newWidget);
+ assert(left != newWidget);
+ assert(right != newWidget);
+ assert(top != newWidget);
+ return;
+ }
+ throw new IllegalArgumentException("oldWidget " + oldWidget +
+ " not in this split");
+ }
+