Methods Summary |
---|
protected double | evaluate(java.lang.Object n)
if (n instanceof Integer) {
return ((Integer)n).doubleValue();
}
// must be an OpNode . . .
OpNode node = (OpNode) n;
double leftSide = evaluate(node.getChild(0));
double rightSide = evaluate(node.getChild(1));
String op = node.getOperator();
// Ok, do the correct calculation of leftside OP rightside
if (op.equals( OpNode.ADD )) return leftSide + rightSide;
if (op.equals( OpNode.SUBTRACT )) return leftSide - rightSide;
if (op.equals( OpNode.MULTIPLY )) return leftSide * rightSide;
if (op.equals( OpNode.DIVIDE )) return leftSide / rightSide;
// Shouldn't get here, but just in case
return Double.NaN;
|
public void | showEvaluation(java.lang.Object node)
double value = evaluate(node);
setText("Current expression value: " + value);
repaint();
|
public void | treeNodesChanged(javax.swing.event.TreeModelEvent tme)
Object source = tme.getSource();
if (source instanceof JTree) {
showEvaluation(((JTree)source).getModel().getRoot());
}
else if (tme.getSource() instanceof TreeModel) {
showEvaluation(((TreeModel)source).getRoot());
}
|
public void | treeNodesInserted(javax.swing.event.TreeModelEvent tme)
treeNodesChanged(tme);
|
public void | treeNodesRemoved(javax.swing.event.TreeModelEvent tme)
treeNodesChanged(tme);
|
public void | treeStructureChanged(javax.swing.event.TreeModelEvent tme)
treeNodesChanged(tme);
|