/**
 * This file is part of WiiuseJ.
 *
 *  WiiuseJ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  WiiuseJ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with WiiuseJ.  If not, see <http://www.gnu.org/licenses/>.
 */
package wiiusej.utils;

import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.GuitarHeroButtonsEvent;
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;

/**
 * This panel is used to display what happens on the buttons of the
 * Guitar Hero 3 controller.
 * @author  guiguito
 */
public class GuitarHero3ButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener {

    /** Creates new form GuitarHero3ButtonsEventPanel */
    public GuitarHero3ButtonsEventPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        leftPanel = new javax.swing.JPanel();
        plusButton = new javax.swing.JToggleButton();
        minusButton = new javax.swing.JToggleButton();
        strumPanel = new javax.swing.JPanel();
        strumUpButton = new javax.swing.JToggleButton();
        strumDownButton = new javax.swing.JToggleButton();
        RightPanel = new javax.swing.JPanel();
        coloredButtonsPanel = new javax.swing.JPanel();
        orangeButton = new javax.swing.JToggleButton();
        blueButton = new javax.swing.JToggleButton();
        yellowButton = new javax.swing.JToggleButton();
        redButton = new javax.swing.JToggleButton();
        greenButton = new javax.swing.JToggleButton();

        setBackground(new java.awt.Color(0, 0, 0));
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS));

        leftPanel.setBackground(new java.awt.Color(0, 0, 0));
        leftPanel.setLayout(new javax.swing.BoxLayout(leftPanel, javax.swing.BoxLayout.LINE_AXIS));

        plusButton.setBackground(new java.awt.Color(255, 255, 255));
        plusButton.setFont(new java.awt.Font("Arial", 1, 24));
        plusButton.setText("+");
        leftPanel.add(plusButton);

        minusButton.setBackground(new java.awt.Color(255, 255, 255));
        minusButton.setFont(new java.awt.Font("Arial", 1, 24));
        minusButton.setText("-");
        leftPanel.add(minusButton);

        strumPanel.setBackground(new java.awt.Color(0, 0, 0));
        strumPanel.setLayout(new javax.swing.BoxLayout(strumPanel, javax.swing.BoxLayout.Y_AXIS));

        strumUpButton.setBackground(new java.awt.Color(255, 255, 255));
        strumUpButton.setFont(new java.awt.Font("Arial", 1, 24));
        strumUpButton.setText("Strum UP");
        strumPanel.add(strumUpButton);

        strumDownButton.setBackground(new java.awt.Color(255, 255, 255));
        strumDownButton.setFont(new java.awt.Font("Arial", 1, 24));
        strumDownButton.setText("Strum DOWN");
        strumPanel.add(strumDownButton);

        leftPanel.add(strumPanel);

        add(leftPanel);

        RightPanel.setBackground(new java.awt.Color(0, 0, 0));
        RightPanel.setLayout(new javax.swing.BoxLayout(RightPanel, javax.swing.BoxLayout.LINE_AXIS));

        coloredButtonsPanel.setLayout(new javax.swing.BoxLayout(coloredButtonsPanel, javax.swing.BoxLayout.LINE_AXIS));

        orangeButton.setBackground(new java.awt.Color(255, 153, 0));
        orangeButton.setFont(new java.awt.Font("Arial", 1, 24));
        orangeButton.setText("O");
        coloredButtonsPanel.add(orangeButton);

        blueButton.setBackground(new java.awt.Color(0, 0, 204));
        blueButton.setFont(new java.awt.Font("Arial", 1, 24));
        blueButton.setText("O");
        coloredButtonsPanel.add(blueButton);

        yellowButton.setBackground(new java.awt.Color(255, 255, 0));
        yellowButton.setFont(new java.awt.Font("Arial", 1, 24));
        yellowButton.setText("O");
        coloredButtonsPanel.add(yellowButton);

        redButton.setBackground(new java.awt.Color(255, 0, 0));
        redButton.setFont(new java.awt.Font("Arial", 1, 24));
        redButton.setText("O");
        coloredButtonsPanel.add(redButton);

        greenButton.setBackground(new java.awt.Color(51, 255, 0));
        greenButton.setFont(new java.awt.Font("Arial", 1, 24));
        greenButton.setText("O");
        coloredButtonsPanel.add(greenButton);

        RightPanel.add(coloredButtonsPanel);

        add(RightPanel);
    }// </editor-fold>//GEN-END:initComponents
    public void onButtonsEvent(WiimoteButtonsEvent arg0) {
    //do nothing
    }

    public void onIrEvent(IREvent arg0) {
    //do nothing
    }

    public void onMotionSensingEvent(MotionSensingEvent arg0) {
    //do nothing
    }

    public void onExpansionEvent(ExpansionEvent arg0) {
        if (arg0 instanceof GuitarHeroEvent) {
            GuitarHeroEvent guitar = (GuitarHeroEvent) arg0;
            GuitarHeroButtonsEvent buttons = guitar.getButtonsEvent();

            //orange button
            if (buttons.isButtonOrangeJustPressed()) {
                orangeButton.setSelected(true);
                orangeButton.setText("X");                        
            } else if (buttons.isButtonOrangeJustReleased()) {
                orangeButton.setSelected(false);
                orangeButton.setText("O");
            }

            //blue button
            if (buttons.isButtonBlueJustPressed()) {
                blueButton.setSelected(true);
                blueButton.setText("X");
            } else if (buttons.isButtonBlueJustReleased()) {
                blueButton.setSelected(false);
                blueButton.setText("O");
            }

            //Yellow button
            if (buttons.isButtonYellowJustPressed()) {
                yellowButton.setSelected(true);
                yellowButton.setText("X");
            } else if (buttons.isButtonYellowJustReleased()) {
                yellowButton.setSelected(false);
                yellowButton.setText("O");
            }

            //Red button
            if (buttons.isButtonRedJustPressed()) {
                redButton.setSelected(true);
                redButton.setText("X");
            } else if (buttons.isButtonRedJustReleased()) {
                redButton.setSelected(false);
                redButton.setText("O");
            }

            //Green button
            if (buttons.isButtonGreenJustPressed()) {
                greenButton.setSelected(true);
                greenButton.setText("X");
            } else if (buttons.isButtonGreenJustReleased()) {
                greenButton.setSelected(false);
                greenButton.setText("O");
            }

            //Plus button
            if (buttons.isButtonPlusJustPressed()) {
                plusButton.setSelected(true);                
            } else if (buttons.isButtonPlusJustReleased()) {
                plusButton.setSelected(false);
            }

            //Minus button
            if (buttons.isButtonMinusJustPressed()) {
                minusButton.setSelected(true);
            } else if (buttons.isButtonMinusJustReleased()) {
                minusButton.setSelected(false);
            }

            //Strum up button
            if (buttons.isButtonStrumUpJustPressed()) {
                strumUpButton.setSelected(true);
            } else if (buttons.isButtonStrumUpJustReleased()) {
                strumUpButton.setSelected(false);
            }

            //Strum down button
            if (buttons.isButtonStrumDownJustPressed()) {
                strumDownButton.setSelected(true);
            } else if (buttons.isButtonStrumDownJustReleased()) {
                strumDownButton.setSelected(false);
            }
        }
    }

    public void onStatusEvent(StatusEvent arg0) {
    //do nothing
    }

    public void onDisconnectionEvent(DisconnectionEvent arg0) {
    //do nothing
    }

    public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
    //do nothing
    }

    public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
    //do nothing
    }

    public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
    //do nothing
    }

    public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
    //do nothing
    }

    public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
    //do nothing
    }

    public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
    //do nothing
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel RightPanel;
    private javax.swing.JToggleButton blueButton;
    private javax.swing.JPanel coloredButtonsPanel;
    private javax.swing.JToggleButton greenButton;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JToggleButton minusButton;
    private javax.swing.JToggleButton orangeButton;
    private javax.swing.JToggleButton plusButton;
    private javax.swing.JToggleButton redButton;
    private javax.swing.JToggleButton strumDownButton;
    private javax.swing.JPanel strumPanel;
    private javax.swing.JToggleButton strumUpButton;
    private javax.swing.JToggleButton yellowButton;
    // End of variables declaration//GEN-END:variables
}
