Search in sources :

Example 16 with Node

use of expression.Node in project OpenNotebook by jaltekruse.

the class AbsoluteValueGraphic method requestSize.

@Override
public int[] requestSize(Graphics g, Font f, int x1, int y1) throws Exception {
    // g is used to decide the size of the text to display for this element
    g.setFont(f);
    space = (int) (2 * super.getRootNodeGraphic().DOC_ZOOM_LEVEL);
    overhang = (int) (1 * super.getRootNodeGraphic().DOC_ZOOM_LEVEL);
    widthInnerSpaceAndLine = (int) (2 * super.getRootNodeGraphic().DOC_ZOOM_LEVEL);
    // to draw this element later, the font must be the same, so its stored in this object
    setFont(f);
    int[] childSize = { 0, 0 };
    int[] symbolSize = { 0, 0 };
    int[] totalSize = { 0, 0 };
    // The call to getChild() skips the first paren inside of the operator, the parens are needed to have
    // an expression inside of a UnaryOp, but they are not usually displayed
    // if a user wants to show parens, the can use  two pairs of parens: abs((5/6))
    Node tempChild = (super.getValue()).getChild(0);
    NodeGraphic childValGraphic = makeNodeGraphic(tempChild);
    childSize = childValGraphic.requestSize(g, f, x1 + widthInnerSpaceAndLine + space, y1 + overhang);
    // set the west and east fields for inside an outside of the expression
    setMostInnerWest(this);
    childValGraphic.getMostInnerEast().setEast(this);
    setMostInnerEast(this);
    childValGraphic.getMostInnerWest().setWest(this);
    setChildGraphic(childValGraphic);
    super.getRootNodeGraphic().getComponents().add(childValGraphic);
    widthInnerSpaceAndLine += (int) Math.round(childSize[1] / 14.0);
    childValGraphic.shiftToX1(x1 + widthInnerSpaceAndLine + space);
    symbolSize[0] = childSize[0] + space * 2 + widthInnerSpaceAndLine * 2;
    symbolSize[1] = childSize[1] + overhang * 2;
    symbolY1 = y1;
    symbolY2 = symbolY1 + symbolSize[1];
    symbolX1 = x1;
    symbolX2 = x1 + symbolSize[0];
    setUpperHeight(childValGraphic.getUpperHeight() + overhang);
    setLowerHeight(childValGraphic.getLowerHeight() + overhang);
    totalSize[0] = symbolSize[0];
    totalSize[1] = symbolSize[1];
    // set the outer bounds of this element
    super.setX1(x1);
    super.setY1(y1);
    super.setX2(x1 + totalSize[0]);
    super.setY2(y1 + totalSize[1]);
    return totalSize;
}
Also used : Node(expression.Node)

Example 17 with Node

use of expression.Node in project OpenNotebook by jaltekruse.

the class ExponentGraphic method requestSize.

@Override
public int[] requestSize(Graphics g, Font f, int x1, int y1) throws Exception {
    g.setFont(f);
    spaceBetweenBaseAndSuper = (int) (1 * getRootNodeGraphic().getFontSizeAdjustment());
    Node tempLeft = (super.getValue()).getChild(0);
    Node tempRight = (super.getValue()).getChild(1);
    NodeGraphic leftValGraphic = null;
    NodeGraphic rightValGraphic = null;
    int[] rightSize = { 0, 0 };
    int[] leftSize = { 0, 0 };
    int[] totalSize = { 0, 0 };
    if (false) {
    // if (style == Style.CARET)
    // {
    // BinExpressionGraphic ex = new BinExpressionGraphic(((BinExpression)getValue()), super.getCompExGraphic());
    // return ex.requestSize(g, f, x1, y1);
    } else if (style == Style.SUPERSCRIPT) {
        leftValGraphic = makeNodeGraphic(tempLeft);
        leftSize = leftValGraphic.requestSize(g, f, x1, y1);
        super.getRootNodeGraphic().getComponents().add(leftValGraphic);
        rightValGraphic = makeNodeGraphic(tempRight);
        rightSize = rightValGraphic.requestSize(g, getRootNodeGraphic().getSmallFont(), x1, y1);
        super.getRootNodeGraphic().getComponents().add(rightValGraphic);
        // set the west and east fields for inside and outside of the expression
        setMostInnerEast(this);
        setMostInnerWest(this);
        setMostInnerSouth(this);
        setMostInnerNorth(this);
        // the request to move to the east of the exponent will need to go down first
        // before being sent into the element east of this ExponentGraphic
        // usual moveEast: 45|+67, cursor at end of 45 -> 45+|67 cursor at end of +
        // skips the 0 position of the next element
        // In this case, the cursor clearly moves down from the superscript
        // moveEast: 4^5|+67, cursor at end of 5 in superscript -> 4^5|+/67 cursor at start of +
        // leftValGraphic.setNorth(this);
        // rightValGraphic.setSouth(this);
        rightValGraphic.getMostInnerWest().setWest(this);
        rightValGraphic.getMostInnerEast().setEast(this);
        leftValGraphic.getMostInnerWest().setWest(this);
        leftValGraphic.getMostInnerEast().setEast(this);
        // //set the west and east fields for inside and outside of the expression
        // setMostInnerWest(leftValGraphic.getMostInnerWest());
        // leftValGraphic.getMostInnerEast().setEast(rightValGraphic.getMostInnerWest());
        // leftValGraphic.getMostInnerNorth().setNorth(rightValGraphic.getMostInnerSouth());
        // this.setWest(leftValGraphic.getMostInnerEast());
        // this.setSouth(leftValGraphic.getMostInnerNorth());
        // this.setMostInnerWest(leftValGraphic.getMostInnerWest());
        // this.setMostInnerSouth(leftValGraphic.getMostInnerSouth());
        // 
        // setMostInnerNorth(rightValGraphic.getMostInnerNorth());
        // setMostInnerSouth(leftValGraphic.getMostInnerSouth());
        // 
        // setMostInnerEast(rightValGraphic.getMostInnerEast());
        // rightValGraphic.getMostInnerSouth().setSouth(leftValGraphic.getMostInnerEast());
        // rightValGraphic.getMostInnerWest().setWest(leftValGraphic.getMostInnerEast());
        // this.setNorth(rightValGraphic.getMostInnerSouth());
        // this.setEast(rightValGraphic.getMostInnerWest());
        // this.setMostInnerEast(rightValGraphic.getMostInnerEast());
        // this.setMostInnerNorth(rightValGraphic.getMostInnerNorth());
        setLeftGraphic(leftValGraphic);
        setRightGraphic(rightValGraphic);
        rightValGraphic.shiftToX1(x1 + leftSize[0] + spaceBetweenBaseAndSuper);
        int shiftDownLeft = 0;
        extraShiftUp = (int) (rightValGraphic.getUpperHeight() * 0.5);
        shiftDownLeft = rightValGraphic.getUpperHeight() + extraShiftUp;
        if (leftValGraphic instanceof ExponentGraphic) {
            if (((ExponentGraphic) leftValGraphic).getRightGraphic().getHeight() / 2.0 < rightValGraphic.getLowerHeight()) {
                shiftDownLeft = rightValGraphic.getHeight() + extraShiftUp - (int) Math.round(((ExponentGraphic) leftValGraphic).getRightGraphic().getHeight() / 2.0);
            }
        } else {
            if (leftValGraphic.getHeight() / 2.0 < rightValGraphic.getLowerHeight()) {
                shiftDownLeft = rightValGraphic.getHeight() + extraShiftUp - (int) Math.round(leftValGraphic.getHeight() / 2.0);
            }
        }
        leftValGraphic.shiftToY1(y1 + shiftDownLeft);
        setUpperHeight(shiftDownLeft + leftValGraphic.getUpperHeight());
        setLowerHeight(leftValGraphic.getLowerHeight());
        totalSize[0] = leftSize[0] + rightSize[0] + spaceBetweenBaseAndSuper;
        totalSize[1] = leftSize[1] + shiftDownLeft;
        super.setX1(x1);
        super.setY1(y1);
        super.setX2(x1 + totalSize[0]);
        super.setY2(y1 + totalSize[1]);
        return totalSize;
    }
    return null;
}
Also used : Node(expression.Node)

Example 18 with Node

use of expression.Node in project OpenNotebook by jaltekruse.

the class ParenGraphic method requestSize.

@Override
public int[] requestSize(Graphics g, Font f, int x1, int y1) throws Exception {
    // g is used to decide the size of the text to display for this element
    g.setFont(f);
    // to draw this element later, the font must be the same, so its stored in this object
    setFont(f);
    space = (int) (2 * super.getRootNodeGraphic().DOC_ZOOM_LEVEL);
    overhang = (int) (3 * super.getRootNodeGraphic().DOC_ZOOM_LEVEL);
    widthParens = 3;
    Node tempChild = super.getValue();
    // prevent the call below to make a NodeGrpahic from making an infinite number of parenthesis
    // as the displayParenthesis flag is used to determine if a set of parens should be added
    tempChild.setDisplayParentheses(false);
    NodeGraphic childValGraphic = null;
    int[] childSize = { 0, 0 };
    int[] symbolSize = { 0, 0 };
    int[] totalSize = { 0, 0 };
    childValGraphic = makeNodeGraphic(tempChild);
    childSize = childValGraphic.requestSize(g, f, x1 + widthParens + space, y1 + overhang);
    // set the west and east fields for inside an outside of the expression
    setMostInnerWest(this);
    childValGraphic.getMostInnerEast().setEast(this);
    setMostInnerEast(this);
    childValGraphic.getMostInnerWest().setWest(this);
    setMostInnerNorth(this);
    setMostInnerSouth(this);
    setChildGraphic(childValGraphic);
    super.getRootNodeGraphic().getComponents().add(childValGraphic);
    widthParens += (int) Math.round(childSize[1] / 14.0);
    childValGraphic.shiftToX1(x1 + widthParens + space);
    symbolSize[0] = childSize[0] + space * 2 + widthParens * 2;
    symbolSize[1] = childSize[1] + overhang * 2;
    int symbolY1 = y1;
    int symbolY2 = symbolY1 + symbolSize[1];
    setUpperHeight((symbolY2 - symbolY1) / 2);
    setLowerHeight(getUpperHeight());
    totalSize[0] = symbolSize[0];
    totalSize[1] = symbolSize[1];
    // set the outer bounds of this element
    super.setX1(x1);
    super.setY1(y1);
    super.setX2(x1 + totalSize[0]);
    super.setY2(y1 + totalSize[1]);
    return totalSize;
}
Also used : Node(expression.Node)

Example 19 with Node

use of expression.Node in project OpenNotebook by jaltekruse.

the class BinExpressionGraphic method requestSize.

@Override
public int[] requestSize(Graphics g, Font f, int x1, int y1) throws Exception {
    g.setFont(f);
    setFont(f);
    space = (int) (4 * getRootNodeGraphic().getFontSizeAdjustment());
    Node tempLeft = (super.getValue()).getChild(0);
    Node tempRight = (super.getValue()).getChild(1);
    NodeGraphic leftValGraphic = null;
    NodeGraphic rightValGraphic = null;
    int[] rightSize = { 0, 0 };
    int[] leftSize = { 0, 0 };
    int[] symbolSize = { 0, 0 };
    int[] totalSize = { 0, 0 };
    leftValGraphic = makeNodeGraphic(tempLeft);
    super.getRootNodeGraphic().getComponents().add(leftValGraphic);
    leftSize = leftValGraphic.requestSize(g, f, x1, y1);
    rightValGraphic = makeNodeGraphic(tempRight);
    rightSize = rightValGraphic.requestSize(g, f, x1, y1);
    super.getRootNodeGraphic().getComponents().add(rightValGraphic);
    // set the west and east fields for inside an outside of the expression
    setMostInnerWest(leftValGraphic.getMostInnerWest());
    leftValGraphic.getMostInnerEast().setEast(this);
    this.setWest(leftValGraphic.getMostInnerEast());
    setMostInnerNorth(this);
    setMostInnerSouth(this);
    setMostInnerEast(rightValGraphic.getMostInnerEast());
    rightValGraphic.getMostInnerWest().setWest(this);
    this.setEast(rightValGraphic.getMostInnerWest());
    symbolSize[0] = getRootNodeGraphic().getStringWidth(getValue().getOperator().getSymbol(), f) + 2 * space;
    symbolSize[1] = getRootNodeGraphic().getFontHeight(f);
    rightValGraphic.shiftToX1(leftSize[0] + symbolSize[0] + x1);
    int height = 0;
    if (leftValGraphic.getUpperHeight() > rightValGraphic.getUpperHeight()) {
        height = leftValGraphic.getUpperHeight();
        symbolY1 = leftValGraphic.getUpperHeight() + y1 - (int) (Math.round((symbolSize[1] / 2.0)));
        symbolY2 = symbolY1 + symbolSize[1];
        setUpperHeight(leftValGraphic.getUpperHeight());
        rightValGraphic.shiftToY1(y1 - rightValGraphic.getUpperHeight() + leftValGraphic.getUpperHeight());
    } else {
        height = rightValGraphic.getUpperHeight();
        symbolY1 = rightValGraphic.getUpperHeight() + y1 - (int) (Math.round((symbolSize[1] / 2.0)));
        symbolY2 = symbolY1 + symbolSize[1];
        setUpperHeight(rightValGraphic.getUpperHeight());
        leftValGraphic.shiftToY1(y1 - leftValGraphic.getUpperHeight() + rightValGraphic.getUpperHeight());
    }
    if (leftValGraphic.getLowerHeight() > rightValGraphic.getLowerHeight()) {
        height += leftValGraphic.getLowerHeight();
        setLowerHeight(leftValGraphic.getLowerHeight());
    } else {
        height += rightValGraphic.getLowerHeight();
        setLowerHeight(rightValGraphic.getLowerHeight());
    }
    symbolX1 = x1 + leftSize[0];
    symbolX2 = x1 + leftSize[0] + symbolSize[0];
    setLeftGraphic(leftValGraphic);
    setRightGraphic(rightValGraphic);
    totalSize[0] = symbolX2 + rightSize[0] - x1;
    totalSize[1] = height;
    super.setX1(x1);
    super.setY1(y1);
    super.setX2(x1 + totalSize[0]);
    super.setY2(y1 + totalSize[1]);
    return totalSize;
}
Also used : Node(expression.Node)

Example 20 with Node

use of expression.Node in project OpenNotebook by jaltekruse.

the class DotMultiplication method requestSize.

@Override
public int[] requestSize(Graphics g, Font f, int x1, int y1) throws Exception {
    g.setFont(f);
    setFont(f);
    space = (int) Math.round(10 * super.getRootNodeGraphic().getFontSizeAdjustment() * getRootNodeGraphic().DOC_ZOOM_LEVEL);
    Node tempLeft = (super.getValue()).getChild(0);
    Node tempRight = (super.getValue()).getChild(1);
    NodeGraphic leftValGraphic = null;
    NodeGraphic rightValGraphic = null;
    int[] rightSize = { 0, 0 };
    int[] leftSize = { 0, 0 };
    int[] symbolSize = { 0, 0 };
    int[] totalSize = { 0, 0 };
    leftValGraphic = makeNodeGraphic(tempLeft);
    super.getRootNodeGraphic().getComponents().add(leftValGraphic);
    leftSize = leftValGraphic.requestSize(g, f, x1, y1);
    rightValGraphic = makeNodeGraphic(tempRight);
    rightSize = rightValGraphic.requestSize(g, f, x1, y1);
    super.getRootNodeGraphic().getComponents().add(rightValGraphic);
    // set the west and east fields for inside an outside of the expression
    setMostInnerWest(leftValGraphic.getMostInnerWest());
    leftValGraphic.getMostInnerEast().setEast(this);
    this.setWest(leftValGraphic.getMostInnerEast());
    setMostInnerNorth(this);
    setMostInnerSouth(this);
    setMostInnerEast(rightValGraphic.getMostInnerEast());
    rightValGraphic.getMostInnerWest().setWest(this);
    this.setEast(rightValGraphic.getMostInnerWest());
    symbolSize[0] = space;
    symbolSize[1] = getRootNodeGraphic().getFontHeight(f);
    rightValGraphic.shiftToX1(leftSize[0] + symbolSize[0] + x1);
    int height = 0;
    if (leftValGraphic.getUpperHeight() > rightValGraphic.getUpperHeight()) {
        height = leftValGraphic.getUpperHeight();
        symbolY1 = leftValGraphic.getUpperHeight() + y1 - (int) (Math.round((symbolSize[1] / 2.0)));
        symbolY2 = symbolY1 + symbolSize[1];
        setUpperHeight(leftValGraphic.getUpperHeight());
        rightValGraphic.shiftToY1(y1 - rightValGraphic.getUpperHeight() + leftValGraphic.getUpperHeight());
    } else {
        height = rightValGraphic.getUpperHeight();
        symbolY1 = rightValGraphic.getUpperHeight() + y1 - (int) (Math.round((symbolSize[1] / 2.0)));
        symbolY2 = symbolY1 + symbolSize[1];
        setUpperHeight(rightValGraphic.getUpperHeight());
        leftValGraphic.shiftToY1(y1 - leftValGraphic.getUpperHeight() + rightValGraphic.getUpperHeight());
    }
    if (leftValGraphic.getLowerHeight() > rightValGraphic.getLowerHeight()) {
        height += leftValGraphic.getLowerHeight();
        setLowerHeight(leftValGraphic.getLowerHeight());
    } else {
        height += rightValGraphic.getLowerHeight();
        setLowerHeight(rightValGraphic.getLowerHeight());
    }
    symbolX1 = x1 + leftSize[0];
    symbolX2 = symbolX1 + symbolSize[0];
    setLeftGraphic(leftValGraphic);
    setRightGraphic(rightValGraphic);
    totalSize[0] = symbolX2 + rightSize[0] - x1;
    totalSize[1] = height;
    super.setX1(x1);
    super.setY1(y1);
    super.setX2(x1 + totalSize[0]);
    super.setY2(y1 + totalSize[1]);
    return totalSize;
}
Also used : Node(expression.Node)

Aggregations

Node (expression.Node)29 Expression (expression.Expression)10 NodeException (expression.NodeException)10 Number (expression.Number)9 Operator (expression.Operator)7 Vector (java.util.Vector)6 StringAttribute (doc.attributes.StringAttribute)4 AttributeException (doc.attributes.AttributeException)3 Identifier (expression.Identifier)2 BasicStroke (java.awt.BasicStroke)2 Graphics2D (java.awt.Graphics2D)2 Point (java.awt.Point)2 RootNodeGraphic (math_rendering.RootNodeGraphic)2 ListAttribute (doc.attributes.ListAttribute)1 ExpressionObject (doc.mathobjects.ExpressionObject)1 GeneratedProblem (doc.mathobjects.GeneratedProblem)1 Multiplication (expression.Operator.Multiplication)1 Color (java.awt.Color)1 Cursor (math_rendering.Cursor)1