/*
 * AdditionNode.java
 *
 * Created on 2. prosinec 2005, 18:43
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package cz.pcland.functions.nodes;
import cz.pcland.gavisualization.*;
import java.awt.*;
/**
 *
 * @author petr
 */
public class AdditionNode extends BinaryOperation{
    
    /** Creates a new instance of AdditionNode */
    public AdditionNode(Node node1, Node node2) {
        super(node1,node2);
    }
    
    public double evaluate(double varValue, String varName) {
        return left.evaluate(varValue, varName)+right.evaluate(varValue, varName);
    }
    
    public String print(int priority) {
        if(priority > Priorities.ADDITION)
            return "(" + this.left.print(Priorities.ADDITION) + "+" + this.right.print(Priorities.ADDITION) + ")";
        else return this.left.print(Priorities.ADDITION) + "+" + this.right.print(Priorities.ADDITION);
    }
    
    public String printSyntax(int priority) {
        if(priority > Priorities.ADDITION)
            return Operations.getColoredText(Color.ORANGE, "(") + this.left.printSyntax(Priorities.ADDITION) + "+" + this.right.printSyntax(Priorities.ADDITION) + Operations.getColoredText(Color.ORANGE, ")");
        else return this.left.printSyntax(Priorities.ADDITION) + "+" + this.right.printSyntax(Priorities.ADDITION);
    }
    
}
