import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
 * This is the starter code for paintbrush.
 * I have included 3 panels, put your tools all in the toolpanel.
 * Put your colors in colorPanel
 * If you want to change the size, change the dimensions included
 * 
 *
 * @author Jeff Borland
 * @updated 11/17/15
 */
public class PaintBrush extends BorlandBase
{   
    //This time we are using 3 panels (sections) on the applet    
    JPanel toolPanel=new JPanel();
    JPanel colorPanel=new JPanel();
    JPanel drawingPanel=new JPanel();

    //Most of these buttons will have pictures instead of text.
    JButton drawButton= new JButton();
    JButton circleButton= new JButton();
    JButton squareButton= new JButton();
    JButton lineButton= new JButton();
    JButton clearButton=new JButton("Clear");
    //all of the color buttons will have 
    JButton colorBlackButton = new JButton();
    JButton colorRedButton = new JButton();
    JButton colorOrangeButton = new JButton();
    JButton colorYellowButton = new JButton();
    JButton colorGreenButton = new JButton();
    JButton colorBlueButton = new JButton();
    JButton colorMagentaButton = new JButton();
    JButton colorWhiteButton = new JButton();        

    public void initialize()
    {

        //I create a toolpanel so you have tools lined up on the left. 
        //If you want to change it, change the dimension below, or see me
        toolPanel.setPreferredSize(new Dimension(150,450));
        toolPanel.setBorder(BorderFactory.createLineBorder(Color.black));
        toolPanel.setBackground(Color.green);

        //Add images to the JButtons
        drawButton=new JButton(new ImageIcon(this.getClass().getResource("pencil.png")));
        circleButton=new JButton(new ImageIcon(this.getClass().getResource("circle.png")));
        squareButton=new JButton(new ImageIcon(this.getClass().getResource("Square.png")));
        lineButton=new JButton(new ImageIcon(this.getClass().getResource("Line.png")));

        //Add all your tools to the tool panel
        addItem(toolPanel,drawButton);
        addItem(toolPanel,circleButton);
        addItem(toolPanel,squareButton);
        addItem(toolPanel,lineButton);
        addItem(toolPanel,clearButton);

        //Now I add my panel for drawing        
        drawingPanel.setPreferredSize(new Dimension(340,450));
        drawingPanel.setBackground(Color.white);
        drawingPanel.setBorder(BorderFactory.createLineBorder(Color.black));

        //Now we create a color panel for the 8 color buttons.  I also specify the size and color of those buttons      
        colorPanel.setPreferredSize(new Dimension(500,50));
        colorPanel.setBackground(Color.gray);      
        colorPanel.setBorder(BorderFactory.createLineBorder(Color.black));

        colorWhiteButton.setPreferredSize(new Dimension(30, 30));
        colorWhiteButton.setBackground(Color.white);
        addItem(colorPanel,colorWhiteButton);        
        colorBlackButton.setPreferredSize(new Dimension(30, 30));
        colorBlackButton.setBackground(Color.black);
        addItem(colorPanel,colorBlackButton);
        colorRedButton.setPreferredSize(new Dimension(30, 30));
        colorRedButton.setBackground(Color.red);
        addItem(colorPanel,colorRedButton);
        colorOrangeButton.setPreferredSize(new Dimension(30, 30));
        colorOrangeButton.setBackground(Color.orange);
        addItem(colorPanel,colorOrangeButton);        
        colorYellowButton.setPreferredSize(new Dimension(30, 30));
        colorYellowButton.setBackground(Color.yellow);
        addItem(colorPanel,colorYellowButton);
        colorGreenButton.setPreferredSize(new Dimension(30, 30));
        colorGreenButton.setBackground(Color.green);
        addItem(colorPanel,colorGreenButton);
        colorBlueButton.setPreferredSize(new Dimension(30, 30));
        colorBlueButton.setBackground(Color.blue);
        addItem(colorPanel,colorBlueButton);
        colorMagentaButton.setPreferredSize(new Dimension(30, 30));
        colorMagentaButton.setBackground(Color.magenta);
        addItem(colorPanel,colorMagentaButton); 

        //we are using a borderlayout with our panels in different regions
        setScreenLayout(new BorderLayout());
        addPanel(toolPanel,BorderLayout.WEST);
        addPanel(drawingPanel,BorderLayout.CENTER);
        addPanel(colorPanel,BorderLayout.SOUTH);
    }

    /**
     * This method if you would like to do drawing on your screen
     */
    public void paintScreen (Graphics g)
    {       
    }
    //When someone presses the mouse button
    public void mousePressed(MouseEvent e)
    {

    }

    //When someone releases the mouse button
    public void mouseReleased(MouseEvent e)
    {
    }

    //When the mouse button is clicked
    public void mouseClicked(MouseEvent e)
    {
    }

    //The mouse button is pressed and the mouse makes a significantly large movement
    public void mouseDragged(MouseEvent e)
    {
        int x=e.getX();
        int y=e.getY();
        Graphics g=getTempG();
        g.setColor(Color.red);
        g.fillOval(x,y,20,20);
        drawScreen();
    }

    public void buttonPressed (Component c)
    {

        if (c == drawButton)
        {
        }
        if (c==circleButton)
        {
        }
        if (c==squareButton)
        {
        }
        if (c==lineButton)
        {
        }      
        if (c==clearButton)
        {
        }
        if (c==colorBlackButton)
        {
        }
        if (c==colorWhiteButton)
        {
        }
        if (c==colorRedButton)
        {
        }
        if (c==colorMagentaButton)
        {
        }
        if (c==colorOrangeButton)
        {
        }
        if (c==colorYellowButton)
        {
        }
        if (c==colorGreenButton)
        {
        }
        if (c==colorBlueButton)
        {
        }

    }

    public static void runAsApplet()
    {
        try{  BorlandBase.runAsApplet((BorlandBase)(new Object() { }.getClass().getEnclosingClass().newInstance()));  }
        catch (Exception e){e.printStackTrace();}
    }

    public static void main(String[] args) {
        try{  BorlandBase.main((BorlandBase)(new Object() { }.getClass().getEnclosingClass().newInstance()));  }
        catch (Exception e){e.printStackTrace();}
    }
}