import java.awt.event.*;
import javax.swing.*;
import java.awt.GridLayout;

class FunctionButtonPanel extends JPanel
{
    private CalculatorModel myModel;
    
    /**
     * make model
     */

    FunctionButtonPanel(CalculatorModel model)
    {
        // construct superclass and make button array
        super(new GridLayout(4,4));
        myModel = model;
        makeButtons();
    }

    /**
     * Makes the buttons for this GUI/view. The number
     * of buttons is determined my the size of the array
     * myButtons. This helper function takes some of
     * the busy work out of the ButtonPanel constructor.
     */
    protected void makeButtons()
    {
        // make listener to do the move chosen by user
        ActionListener funcProc = new ActionListener(){
                public void actionPerformed(ActionEvent e)
                {
                    String func = e.getActionCommand();
                    myModel.unaryOp(func);
                }
            };
        
        String[] labels = {
            "e^x", "ln", "log",
            "sin", "cos", "tan",
            "n!", "1/x", "x^2",
            "x^3", "pi", "e"
        };

        for(int k=0; k < labels.length; k++){
            CalcButton button = new CalcButton(labels[k],labels[k]);
            button.setForeground(java.awt.Color.BLUE);
            button.addActionListener(funcProc);
            add(button);
        }
    }
}
