FirstForm.java Source code

Java tutorial

Introduction

Here is the source code for FirstForm.java

Source

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;

/*
 * 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.
 */

/**
 *
 * @author user
 */
public class FirstForm extends javax.swing.JFrame {

    private boolean indiceOrSensibility;
    private Border defaultBorder;

    public FirstForm() {
        initComponents();
        initBoxes();
        initSpinners();
        initCharts();
        initPanels();
        initSliders();
        resetButtonActionPerformed(null);
    }

    /**
     * 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() {

        jLabel2 = new javax.swing.JLabel();
        modularButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        tipoModulacionBox = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        desviacionLabel = new javax.swing.JLabel();
        indiceSpinner = new javax.swing.JSpinner();
        jPanel2 = new javax.swing.JPanel();
        funcionPortadoraBox = new javax.swing.JComboBox<String>();
        jLabel3 = new javax.swing.JLabel();
        frecuenciaPortadoraSpinner = new javax.swing.JSpinner();
        frecuenciaPortadoraUnidad = new javax.swing.JComboBox<String>();
        jLabel4 = new javax.swing.JLabel();
        fasePortadoraSpinner = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        amplitudPortadoraSpinner = new javax.swing.JSpinner();
        amplitudPortadoraUnidad = new javax.swing.JComboBox<String>();
        ruidoPortadoraCheck = new javax.swing.JCheckBox();
        portadoraButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        funcionModuladoraBox = new javax.swing.JComboBox<String>();
        jLabel6 = new javax.swing.JLabel();
        frecuenciaModuladoraSpinner = new javax.swing.JSpinner();
        frecuenciaModuladoraUnidad = new javax.swing.JComboBox<String>();
        jLabel7 = new javax.swing.JLabel();
        faseModuladoraSpinner = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        amplitudModuladoraSpinner = new javax.swing.JSpinner();
        amplitudModuladoraUnidad = new javax.swing.JComboBox<String>();
        ruidoModuladoraCheck = new javax.swing.JCheckBox();
        moduladoraButton = new javax.swing.JButton();
        portadoraPanel = new javax.swing.JPanel();
        moduladoraPanel = new javax.swing.JPanel();
        moduladaPanel = new javax.swing.JPanel();
        velocidadSlider = new javax.swing.JSlider();
        framesSlider = new javax.swing.JSlider();
        jLabel13 = new javax.swing.JLabel();
        sensibilidadSpinner = new javax.swing.JSpinner();
        desviacionLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMaximumSize(new java.awt.Dimension(2147483647, 600));
        setMinimumSize(new java.awt.Dimension(700, 700));
        setPreferredSize(new java.awt.Dimension(600, 600));

        jLabel2.setText("Tipo de Modulacion");

        modularButton.setText("Modular");
        modularButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modularButtonActionPerformed(evt);
            }
        });

        resetButton.setText("Resetear");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        tipoModulacionBox.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel12.setText("Velocidad                            ");

        desviacionLabel.setText("Indice de Modulacion");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Seal Portadora",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        funcionPortadoraBox.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        funcionPortadoraBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                funcionPortadoraBoxActionPerformed(evt);
            }
        });

        jLabel3.setText("Frecuencia");

        frecuenciaPortadoraUnidad.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel4.setText("Fase (Rad)");

        jLabel5.setText("Amplitud");

        amplitudPortadoraUnidad.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ruidoPortadoraCheck.setText("Ruido");

        portadoraButton.setText("Ver Seal");
        portadoraButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                portadoraButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(funcionPortadoraBox, javax.swing.GroupLayout.Alignment.TRAILING, 0,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                jPanel2Layout.createSequentialGroup()
                                                        .addGroup(jPanel2Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel3).addComponent(jLabel4))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                        .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel5)
                                                .addGap(15, 15, 15)))
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(amplitudPortadoraSpinner,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                                                .addComponent(frecuenciaPortadoraSpinner,
                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(fasePortadoraSpinner,
                                                        javax.swing.GroupLayout.Alignment.LEADING))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(amplitudPortadoraUnidad,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(frecuenciaPortadoraUnidad,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(ruidoPortadoraCheck)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(portadoraButton, javax.swing.GroupLayout.PREFERRED_SIZE, 165,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                        .addComponent(funcionPortadoraBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(frecuenciaPortadoraSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(frecuenciaPortadoraUnidad, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(fasePortadoraSpinner,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(amplitudPortadoraSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(amplitudPortadoraUnidad, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ruidoPortadoraCheck).addComponent(portadoraButton))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Seal Moduladora",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        funcionModuladoraBox.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setText("Frecuencia");

        frecuenciaModuladoraUnidad.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel7.setText("Fase(Rad)");

        jLabel8.setText("Amplitud");

        amplitudModuladoraUnidad.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ruidoModuladoraCheck.setText("Ruido");

        moduladoraButton.setText("Ver Seal");
        moduladoraButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moduladoraButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(funcionModuladoraBox, javax.swing.GroupLayout.Alignment.TRAILING, 0,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createSequentialGroup().addComponent(ruidoModuladoraCheck)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(moduladoraButton, javax.swing.GroupLayout.PREFERRED_SIZE, 164,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel6).addComponent(jLabel7)).addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel8).addGap(15, 15,
                                        15)))
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(amplitudModuladoraSpinner)
                                        .addComponent(faseModuladoraSpinner,
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(frecuenciaModuladoraSpinner,
                                                javax.swing.GroupLayout.Alignment.LEADING))
                                .addGap(10, 10, 10).addGroup(
                                        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(frecuenciaModuladoraUnidad,
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(amplitudModuladoraUnidad,
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(funcionModuladoraBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6)
                                .addComponent(frecuenciaModuladoraSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(frecuenciaModuladoraUnidad, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7).addComponent(faseModuladoraSpinner,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(amplitudModuladoraSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(amplitudModuladoraUnidad, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ruidoModuladoraCheck).addComponent(moduladoraButton))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        portadoraPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grafica Seal Portadora",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        javax.swing.GroupLayout portadoraPanelLayout = new javax.swing.GroupLayout(portadoraPanel);
        portadoraPanel.setLayout(portadoraPanelLayout);
        portadoraPanelLayout.setHorizontalGroup(portadoraPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 293, Short.MAX_VALUE));
        portadoraPanelLayout.setVerticalGroup(portadoraPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));

        moduladoraPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grafica Seal Moduladora",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        javax.swing.GroupLayout moduladoraPanelLayout = new javax.swing.GroupLayout(moduladoraPanel);
        moduladoraPanel.setLayout(moduladoraPanelLayout);
        moduladoraPanelLayout.setHorizontalGroup(moduladoraPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        moduladoraPanelLayout.setVerticalGroup(moduladoraPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));

        moduladaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grafica Seal Modulada",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        javax.swing.GroupLayout moduladaPanelLayout = new javax.swing.GroupLayout(moduladaPanel);
        moduladaPanel.setLayout(moduladaPanelLayout);
        moduladaPanelLayout.setHorizontalGroup(moduladaPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        moduladaPanelLayout.setVerticalGroup(moduladaPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));

        jLabel13.setText("frames/seg");

        desviacionLabel1.setText("Sensibilidad a la Desviacion");

        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().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                layout.createSequentialGroup()
                                        .addComponent(modularButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(resetButton,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tipoModulacionBox, javax.swing.GroupLayout.Alignment.LEADING, 0,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(indiceSpinner,
                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(velocidadSlider,
                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                                        .addComponent(desviacionLabel))
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(desviacionLabel1)
                                        .addComponent(framesSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 130,
                                                Short.MAX_VALUE)
                                        .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(sensibilidadSpinner))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(portadoraPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(moduladoraPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(moduladaPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(portadoraPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(moduladoraPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(tipoModulacionBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(desviacionLabel).addComponent(desviacionLabel1))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(indiceSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(sensibilidadSpinner,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(10, 10, 10)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel12).addComponent(jLabel13))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(velocidadSlider,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(framesSlider, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(modularButton).addComponent(resetButton)))
                                .addComponent(moduladaPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));

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

    private void modularButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modularButtonActionPerformed

        if (validarCamposVacios()) {
            ModulateSignal modulada = armarModuladada();
            System.out.println(modulada);
            if (Validador.getInstance().validarModulacion(modulada)) {
                generarGraficaModuladoda(modulada);
                ResultScreen result = new ResultScreen(modulada);
                result.setVisible(true);
            } else
                Validador.getInstance().mostrarErrorMsj(this, "Frecuencias no Validas!");
        }

    }//GEN-LAST:event_modularButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        resetPortadora();
        resetModuladora();
        resetModulada();
    }//GEN-LAST:event_resetButtonActionPerformed

    private void portadoraButtonActionPerformed(java.awt.event.ActionEvent evt) {
        Signal portadora = armarPortadora();
        System.out.println(portadora);
        portadoraThread = cambiarGrafica(portadora, portadoraChart, portadoraThread);
    }

    private void moduladoraButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moduladoraButtonActionPerformed
        Signal moduladora = armarModuladora();
        System.out.println(moduladora);
        moduladoraThread = cambiarGrafica(moduladora, moduladoraChart, moduladoraThread);
    }//GEN-LAST:event_moduladoraButtonActionPerformed

    private void funcionPortadoraBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_funcionPortadoraBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_funcionPortadoraBoxActionPerformed

    private void initBoxes() {
        ComboBoxManager manager = ComboBoxManager.getInstance();
        manager.initAmplitudBox(this.amplitudModuladoraUnidad);
        manager.initAmplitudBox(amplitudPortadoraUnidad);
        manager.initFrequencyBox(frecuenciaModuladoraUnidad);
        manager.initFrequencyBox(frecuenciaPortadoraUnidad);
        manager.initModulationTypeBox(tipoModulacionBox);
        manager.initSignalFunctionBox(funcionModuladoraBox);
        manager.initSignalFunctionBox(funcionPortadoraBox);
    }

    private Signal armarPortadora() {
        double frecuencia = (double) frecuenciaPortadoraSpinner.getValue();
        double phase = (double) fasePortadoraSpinner.getValue();
        double amplitud = (double) amplitudPortadoraSpinner.getValue();
        boolean ruido = ruidoPortadoraCheck.isSelected();
        String amplitudUnidad = (String) this.amplitudPortadoraUnidad.getSelectedItem();
        String freqUnidad = (String) this.frecuenciaPortadoraUnidad.getSelectedItem();
        String tipoFuncion = (String) this.funcionPortadoraBox.getSelectedItem();
        frecuencia = ConversorDeUnidades.getInstance().convertir(frecuencia, freqUnidad);
        amplitud = ConversorDeUnidades.getInstance().convertir(amplitud, amplitudUnidad);
        return new Signal(frecuencia, amplitud, phase, ruido, tipoFuncion);
    }

    private void initPanels() {
        GridLayout gL = new GridLayout();
        gL.setColumns(1);
        gL.setRows(1);
        portadoraPanel.setLayout(gL);
        portadoraPanel.setPreferredSize(new Dimension(60, 50));
        moduladoraPanel.setLayout(gL);
        moduladoraPanel.setPreferredSize(new Dimension(60, 50));
        moduladaPanel.setLayout(gL);
        moduladaPanel.setPreferredSize(new Dimension(60, 140));
        portadoraPanel.add(portadoraChart);
        moduladoraPanel.add(moduladoraChart);
        moduladaPanel.add(moduladaChart);
    }

    private void initSpinners() {
        defaultBorder = this.indiceSpinner.getBorder();
        this.indiceSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 30.0, 0.1));
        this.faseModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.fasePortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.amplitudModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.amplitudPortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.frecuenciaPortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.frecuenciaModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.sensibilidadSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
        this.sensibilidadSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                indiceOrSensibility = false;
                indiceSpinner.setBorder(defaultBorder);
                sensibilidadSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
            }
        });
        this.indiceSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                indiceOrSensibility = true;
                sensibilidadSpinner.setBorder(defaultBorder);
                indiceSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
            }
        });

        this.indiceSpinner.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                indiceOrSensibility = true;
                sensibilidadSpinner.setBorder(defaultBorder);
                indiceSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
            }

            @Override
            public void focusLost(FocusEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        this.sensibilidadSpinner.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                indiceOrSensibility = false;
                indiceSpinner.setBorder(defaultBorder);
                sensibilidadSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
            }

            @Override
            public void focusLost(FocusEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
    }

    private Signal armarModuladora() {
        double frecuencia = (double) frecuenciaModuladoraSpinner.getValue();
        double phase = (double) faseModuladoraSpinner.getValue();
        double amplitud = (double) amplitudModuladoraSpinner.getValue();
        boolean ruido = ruidoModuladoraCheck.isSelected();
        String amplitudUnidad = (String) this.amplitudModuladoraUnidad.getSelectedItem();
        String freqUnidad = (String) this.frecuenciaModuladoraUnidad.getSelectedItem();
        String tipoFuncion = (String) this.funcionModuladoraBox.getSelectedItem();
        frecuencia = ConversorDeUnidades.getInstance().convertir(frecuencia, freqUnidad);
        amplitud = ConversorDeUnidades.getInstance().convertir(amplitud, amplitudUnidad);
        return new Signal(frecuencia, amplitud, phase, ruido, tipoFuncion);
    }

    private ChartPanel moduladoraChart;
    private ChartPanel portadoraChart;
    private ChartPanel moduladaChart;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner amplitudModuladoraSpinner;
    private javax.swing.JComboBox<String> amplitudModuladoraUnidad;
    private javax.swing.JSpinner amplitudPortadoraSpinner;
    private javax.swing.JComboBox<String> amplitudPortadoraUnidad;
    private javax.swing.JLabel desviacionLabel;
    private javax.swing.JLabel desviacionLabel1;
    private javax.swing.JSpinner faseModuladoraSpinner;
    private javax.swing.JSpinner fasePortadoraSpinner;
    private javax.swing.JSlider framesSlider;
    private javax.swing.JSpinner frecuenciaModuladoraSpinner;
    private javax.swing.JComboBox<String> frecuenciaModuladoraUnidad;
    private javax.swing.JSpinner frecuenciaPortadoraSpinner;
    private javax.swing.JComboBox<String> frecuenciaPortadoraUnidad;
    private javax.swing.JComboBox<String> funcionModuladoraBox;
    private javax.swing.JComboBox<String> funcionPortadoraBox;
    private javax.swing.JSpinner indiceSpinner;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel moduladaPanel;
    private javax.swing.JButton moduladoraButton;
    private javax.swing.JPanel moduladoraPanel;
    private javax.swing.JButton modularButton;
    private javax.swing.JButton portadoraButton;
    private javax.swing.JPanel portadoraPanel;
    private javax.swing.JButton resetButton;
    private javax.swing.JCheckBox ruidoModuladoraCheck;
    private javax.swing.JCheckBox ruidoPortadoraCheck;
    private javax.swing.JSpinner sensibilidadSpinner;
    private javax.swing.JComboBox tipoModulacionBox;
    private javax.swing.JSlider velocidadSlider;
    // End of variables declaration//GEN-END:variables
    private ChartThread moduladoraThread;
    private ChartThread portadoraThread;
    private ChartThread moduladaThread;

    private void initCharts() {
        moduladoraChart = new ChartPanel(null);
        moduladoraChart.setToolTipText("Click Para Pausar");
        moduladoraChart.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent cme) {
                if (moduladoraThread != null)
                    moduladoraThread.switchPause();
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent cme) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        portadoraChart = new ChartPanel(null);
        portadoraChart.setToolTipText("Click Para Pausar");
        portadoraChart.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent cme) {
                if (portadoraThread != null)
                    portadoraThread.switchPause();
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent cme) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        moduladaChart = new ChartPanel(null);
        moduladaChart.setToolTipText("Click Para Pausar");
        moduladaChart.setDisplayToolTips(true);
        moduladaChart.addChartMouseListener(new ChartMouseListener() {

            @Override
            public void chartMouseClicked(ChartMouseEvent cme) {
                if (moduladaThread != null)
                    moduladaThread.switchPause();
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent cme) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

            }
        });
    }

    private void resetPortadora() {
        portadoraChart.setChart(null);
        fasePortadoraSpinner.setValue(0.0);
        frecuenciaPortadoraSpinner.setValue(0.0);
        frecuenciaPortadoraUnidad.setSelectedIndex(2);
        amplitudPortadoraSpinner.setValue(0.0);
        amplitudPortadoraUnidad.setSelectedIndex(3);
        ruidoPortadoraCheck.setSelected(false);
        funcionPortadoraBox.setSelectedIndex(0);
        if (portadoraThread != null) {
            portadoraThread.switchPause();
        }

    }

    private void resetModuladora() {
        moduladoraChart.setChart(null);
        faseModuladoraSpinner.setValue(0.0);
        frecuenciaModuladoraSpinner.setValue(0.0);
        frecuenciaModuladoraUnidad.setSelectedIndex(2);
        amplitudModuladoraSpinner.setValue(0.0);
        amplitudModuladoraUnidad.setSelectedIndex(3);
        ruidoModuladoraCheck.setSelected(false);
        funcionModuladoraBox.setSelectedIndex(0);
        if (moduladoraThread != null) {
            moduladoraThread.switchPause();
        }
    }

    private void resetModulada() {
        moduladaChart.setChart(null);
        this.indiceSpinner.setValue(0.0);
        this.tipoModulacionBox.setSelectedIndex(0);
        if (moduladaThread != null) {
            moduladaThread.switchPause();
        }
    }

    private ModulateSignal armarModuladada() {

        double m = (double) this.indiceSpinner.getValue();
        double k = (double) this.sensibilidadSpinner.getValue();
        int type = tipoModulacionBox.getSelectedIndex();
        if (indiceOrSensibility)
            return new ModulateSignal(armarPortadora(), armarModuladora(), m, type);
        else
            return new ModulateSignal(armarPortadora(), armarModuladora(), k, type, 0);
    }

    private void generarGraficaModuladoda(ModulateSignal modulada) {
        //int desde = (int)pDSpinner.getValue();
        //int hasta = (int)pHSpinner.getValue();
        //String unidadTiempo = (String)this.timeUnidadSpinner.getSelectedItem();
        //moduladaChart.setChart(GeneradorDeGraphicas.getInstance().drawSignal(modulada, desde, hasta,
        //      ConversorDeUnidades.getInstance().retornarMultiploUnidad(unidadTiempo)));
        //moduladaThread = new ChartThread(modulada,moduladaChart);
        //moduladaThread.start();
        moduladaThread = cambiarGrafica(modulada, moduladaChart, moduladaThread);
    }

    private ChartThread cambiarGrafica(IEvaluableEnTiempo s, ChartPanel panel, ChartThread thread) {

        if (thread == null) {
            thread = new ChartThread(s, panel);
            thread.start();
        } else {
            if (!thread.isPause())
                thread.switchPause();
            thread.changeEvaluable(s);
            thread.switchPause();
        }
        return thread;
    }

    private void initSliders() {
        velocidadSlider.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (moduladoraThread != null)
                    moduladoraThread.changeTime(500 - velocidadSlider.getValue());

                if (moduladaThread != null)
                    moduladaThread.changeTime(500 - velocidadSlider.getValue());

                if (portadoraThread != null)
                    portadoraThread.changeTime(500 - velocidadSlider.getValue());
            }
        });
        framesSlider.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (moduladoraThread != null)
                    moduladoraThread.changeFrames(framesSlider.getValue());

                if (moduladaThread != null)
                    moduladaThread.changeFrames(framesSlider.getValue());

                if (portadoraThread != null)
                    portadoraThread.changeFrames(framesSlider.getValue());
            }
        });

        velocidadSlider.setMinimum(0);
        velocidadSlider.setMaximum(420);
        framesSlider.setMaximum(500);
        framesSlider.setMinimum(200);
        velocidadSlider.setValue(350);
        framesSlider.setValue(225);
    }

    //TODO ver que hacer aqui? 
    private boolean validarCamposVacios() {
        boolean indiceNoValido;
        if (indiceOrSensibility)
            indiceNoValido = ((double) indiceSpinner.getValue()) <= 0;
        else
            indiceNoValido = ((double) sensibilidadSpinner.getValue()) <= 0;
        if (indiceNoValido) {
            if (indiceOrSensibility)
                Validador.getInstance().mostrarErrorMsj(this, "El Indice de Modulacion tiene que ser mayor a 0");
            else
                Validador.getInstance().mostrarErrorMsj(this,
                        "La Sensibilidada a La desviacion tiene que ser Mayor a 0");
            return false;
        }
        return true;
    }
}