/*
 * PowerNode.java
 *
 * Created on 3. prosinec 2005, 14:28
 *
 * 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 java.util.*;
import java.awt.*;
import cz.pcland.gavisualization.*;
/**
 *
 * @author petr
 */
public class PowerNode extends BinaryOperation{
    
    /** Creates a new instance of PowerNode */
    
    /** Creates a new instance of AdditionNode */
    public PowerNode(Node node1, Node node2) {
        super(node1,node2); 
    }
    
    public double evaluate(double varValue, String varName) {
        return Math.pow(left.evaluate(varValue, varName),right.evaluate(varValue, varName));
    }
   
    public String print(int priority) {
         if(priority > Priorities.POWER) return "(" + this.left.print(Priorities.POWER) + "^" + this.right.print(Priorities.POWERR) + ")";
         else return this.left.print(Priorities.POWER) + "^" + this.right.print(Priorities.POWERR);
    }
    
    public String printSyntax(int priority) {
        if(priority > Priorities.POWER) return Operations.getColoredText(Color.ORANGE, "(") + this.left.printSyntax(Priorities.POWER) + "^" + this.right.printSyntax(Priorities.POWERR) + Operations.getColoredText(Color.ORANGE, ")");
        else return this.left.printSyntax(Priorities.POWER) + "^" + this.right.printSyntax(Priorities.POWERR);
    } 
}