publicvoid updateView(Object with) {
FormulaView view = FormulaView.get(this);
// Note: we may not do the following:
// remove(0); add(getView(left),0);
// remove (2); add(getView(right),0);
// because remove(0) unlinks the right component
// off the tree, so getView(right) would give us null.
Component lview = view.getView(model.left);
Component rview = view.getView(model.right);
// Note that
// remove(0); add(lview,0); remove(2); add(lview,2);
// also not works. This is because adding lview at position 0
// removes it at the position where it was (being position 2),
// so remove(2); would fail.
remove(2);
remove(0);
add(lview,0);
add(rview,2);
validate();
}
public Object getModel() { return model; }
publicvoid setCursorPos(int pos) {
switch (pos) {
case Somewhere_LEFT:
FormulaView.get(this).setCursorPart(model.left,Somewhere_LEFT);
break;
case Somewhere_RIGHT:
FormulaView.get(this).setCursorPart(model.right,Somewhere_RIGHT);
break;
case Somewhere_MYLEFT:
getOperatorView().setCursorPos(Somewhere_LEFT);
break;
case Somewhere_MYRIGHT:
getOperatorView().setCursorPos(Somewhere_RIGHT);
break;
default:
getOperatorView().setCursorPos(pos >=0 ? pos : Somewhere);
}
}
publicint getCursorPos() {
FormulaView view = FormulaView.get(this);
Part cursorpart = view.getCursorPart();
if (Part.isDescendantOr(cursorpart,model.left))
return Somewhere_LEFT;
if (Part.isDescendantOr(cursorpart,model.right))
return Somewhere_RIGHT;
if (cursorpart == model)
return getOperatorView().getCursorPos();
return Somewhere;
}
publicvoid activate() {
if (getComponentCount() == 3)
getOperatorView().activate();
}
publicvoid deactivate() {
// While dismantling etc., left or right child could
// already be removed. In that case, do nothing
if (getComponentCount() == 3)
getOperatorView().deactivate();
}
Return the View of the operator itself (i.e. without the left
and right arguments). This is our middle child.