org.problets.domain.model.expression.node
Class NodeView

java.lang.Object
  extended by org.problets.domain.model.expression.node.NodeView
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
OperatorView, StudentNodeView

public class NodeView
extends java.lang.Object
implements java.lang.Cloneable

To display one node - serves as base class for OperatorView

Author:
Amruth Kumar

Constructor Summary
NodeView(NodeModel inNode)
          This constructor will be called for the root of a complete expression tree.
 
Method Summary
 void classifyNodes(java.util.Vector operatorViewVector, java.util.Vector operandViewVector)
          Does an in-order traversal of the view tree (to preserve left to right order) and adds leaf operators to operatorView, and leaf operands to operandView
 java.lang.Object clone()
          This simply returns a shallow copy of NodeView
 void explain(java.util.Vector explanation)
           
 int getBackupLeftX()
           
 int getBackupRightX()
           
 java.lang.String getContent()
           
 int getContentWidth()
           
 NodeView getCopyIfExists(java.util.Vector availableViews, java.lang.String presumedValue)
          If actualNodeView exists in availableViews, return a copy of it, else return null actualNodeView is part of the actual answer, an OperatorView or OperandView object.
 java.awt.FontMetrics getFontMetrics()
           
 NodeView getLeftChild()
           
 int getLeftMax()
           
 int getLeftMin()
           
 int getLeftX()
           
 NodeModel getNode()
           
static NodeView getNodeView(NodeModel node)
          Factory method to return the correct OperatorView
 NodeView getRightChild()
           
 int getRightMax()
           
 int getRightMin()
           
 int getRightX()
           
 java.util.Vector getSideEffects()
          Returns a vector of views of AssignmentStep objects
 java.lang.String getValue()
           
 boolean isCovered(int leftCoord, int rightCoord)
          Returns true if this node is straddled by leftX and rightX, and false otherwise.
 void paintExpression(java.awt.Graphics g, int y)
          Method should be called only after this node has been typeset first
 void print()
           
 void setLeftChild(NodeView child)
          Method used by OperatorView.getCopyIfExists() to construct student's answer
 void setRightChild(NodeView child)
          Method used by OperatorView.getCopyIfExists() to construct student's answer
 java.lang.String toString()
          Returns a string representation of this nodeview
 int typeset(java.awt.Graphics g, java.awt.FontMetrics inFontMetrics, int x, int y, int spacing)
          Given the graphics context and the font metrics used, this method will calculate the left and right extents of all the operators and operands in an expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeView

public NodeView(NodeModel inNode)
This constructor will be called for the root of a complete expression tree. However, the nodeView's data members are not all initialized until the nodeView is typeset().

Method Detail

clone

public java.lang.Object clone()
This simply returns a shallow copy of NodeView

Overrides:
clone in class java.lang.Object

getNodeView

public static NodeView getNodeView(NodeModel node)
Factory method to return the correct OperatorView


paintExpression

public void paintExpression(java.awt.Graphics g,
                            int y)
Method should be called only after this node has been typeset first


typeset

public int typeset(java.awt.Graphics g,
                   java.awt.FontMetrics inFontMetrics,
                   int x,
                   int y,
                   int spacing)
Given the graphics context and the font metrics used, this method will calculate the left and right extents of all the operators and operands in an expression.


getLeftX

public int getLeftX()

getRightX

public int getRightX()

getLeftMin

public int getLeftMin()

getLeftMax

public int getLeftMax()

getLeftChild

public NodeView getLeftChild()

getRightChild

public NodeView getRightChild()

getRightMin

public int getRightMin()

getRightMax

public int getRightMax()

getBackupLeftX

public int getBackupLeftX()

getBackupRightX

public int getBackupRightX()

getContent

public java.lang.String getContent()

getNode

public NodeModel getNode()

getValue

public java.lang.String getValue()

getContentWidth

public int getContentWidth()

getFontMetrics

public java.awt.FontMetrics getFontMetrics()

classifyNodes

public void classifyNodes(java.util.Vector operatorViewVector,
                          java.util.Vector operandViewVector)
Does an in-order traversal of the view tree (to preserve left to right order) and adds leaf operators to operatorView, and leaf operands to operandView


isCovered

public boolean isCovered(int leftCoord,
                         int rightCoord)
Returns true if this node is straddled by leftX and rightX, and false otherwise. This method is used by ExpressionProblemView to check which NodeView objects in the correct answer were covered by an underbrace drawn by a student. Since correct answer NodeViews will have recalculated leftX and rightX to reflect the intermediate result, we use backupLeftX and backupRightX for comparison here since they represent the content (i.e., symbol) of the operator, not its value.


getCopyIfExists

public NodeView getCopyIfExists(java.util.Vector availableViews,
                                java.lang.String presumedValue)
If actualNodeView exists in availableViews, return a copy of it, else return null actualNodeView is part of the actual answer, an OperatorView or OperandView object. availableViews consists of OperandViews and StudentNodeViews/BailedOutStudentNodeViews. Short-circuits any newly constructed operator nodes


getSideEffects

public java.util.Vector getSideEffects()
Returns a vector of views of AssignmentStep objects


setLeftChild

public void setLeftChild(NodeView child)
Method used by OperatorView.getCopyIfExists() to construct student's answer


setRightChild

public void setRightChild(NodeView child)
Method used by OperatorView.getCopyIfExists() to construct student's answer


explain

public void explain(java.util.Vector explanation)

print

public void print()

toString

public java.lang.String toString()
Returns a string representation of this nodeview

Overrides:
toString in class java.lang.Object