/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package clientetv;

import com.sun.jna.NativeLibrary;
import java.awt.Canvas;
import static java.lang.System.exit;
import java.util.Vector;


public class Ventana extends javax.swing.JFrame {

    /**
     * Creates new form Ventana
     */
    public Ventana() {
        channels = new Vector();
        channels.add("rtp://225.0.0.1:5555");
        channels.add("rtp://225.0.0.1:5556");
        channels.add("rtp://225.0.0.1:5557");
        canal=0;
        initComponents();
        volumen = 100;
        TV = new ClienteTV("rtp://225.0.0.1:5555");
        TV.Play();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        channelUp = new javax.swing.JButton();
        channelDown = new javax.swing.JButton();
        volUp = new javax.swing.JButton();
        volDown = new javax.swing.JButton();
        turnOff = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Control");
        setFont(new java.awt.Font("Segoe Print", 2, 18)); // NOI18N
        setForeground(java.awt.Color.orange);
        setPreferredSize(new java.awt.Dimension(640, 85));
        setResizable(false);

        channelUp.setText("CH +");
        channelUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                channelUpActionPerformed(evt);
            }
        });

        channelDown.setText("CH -");
        channelDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                channelDownActionPerformed(evt);
            }
        });

        volUp.setText("Vol +");
        volUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volUpActionPerformed(evt);
            }
        });

        volDown.setText("Vol -");
        volDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volDownActionPerformed(evt);
            }
        });

        turnOff.setText("Off");
        turnOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                turnOffActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(channelUp)
                .addGap(18, 18, 18)
                .addComponent(channelDown)
                .addGap(18, 18, 18)
                .addComponent(volUp)
                .addGap(18, 18, 18)
                .addComponent(volDown)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 297, Short.MAX_VALUE)
                .addComponent(turnOff)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(channelUp, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                    .addComponent(channelDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(volUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(volDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(turnOff, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void channelUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_channelUpActionPerformed
        canal++;
        if(canal>channels.size()-1)
            canal = 0;
        TV.changeChannel(channels.get(canal));
        TV.Play();
    }//GEN-LAST:event_channelUpActionPerformed

    private void volUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volUpActionPerformed
        volumen+=20;
        if(volumen>200)
            volumen=200;
        TV.setVol(volumen);
    }//GEN-LAST:event_volUpActionPerformed

    private void volDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volDownActionPerformed
        volumen-=20;
        if(volumen<0)
            volumen=0;
        TV.setVol(volumen);
    }//GEN-LAST:event_volDownActionPerformed

    private void channelDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_channelDownActionPerformed
        canal--;
        if(canal<0)
            canal = channels.size()-1;
        TV.changeChannel(channels.get(canal));
        TV.Play();
    }//GEN-LAST:event_channelDownActionPerformed

    private void turnOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_turnOffActionPerformed
        TV.Stop();
        exit(0);
    }//GEN-LAST:event_turnOffActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        NativeLibrary.addSearchPath("libvlc", "F:\\PDS\\ClienteTV\\VLC");
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ventana().setVisible(true);
            }
        });
    }
    
    private ClienteTV TV;
    private Vector<String> channels;
    private int canal;
    private int volumen;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton channelDown;
    private javax.swing.JButton channelUp;
    private javax.swing.JButton turnOff;
    private javax.swing.JButton volDown;
    private javax.swing.JButton volUp;
    // End of variables declaration//GEN-END:variables
}
