/**
 * Simple GUI for controlling two RealTimePoll objects.
 *   @author davereed
 *   @version 2/10/13
 */
public class PollGUI extends javax.swing.JFrame {

    private RealTimePoll poll1;
    private RealTimePoll poll2;
    
    /** Creates new form PollGUI */
    public PollGUI() {
        initComponents();
        this.poll1 = new RealTimePoll();
        this.poll2 = new RealTimePoll();
    }

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

        cand1Field = new javax.swing.JTextField();
        cand1AvgLabel = new javax.swing.JLabel();
        cand1Slider = new javax.swing.JSlider();
        cand1MinLabel = new javax.swing.JLabel();
        cand1MaxLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        resetButton = new javax.swing.JButton();
        cand2Field = new javax.swing.JTextField();
        cand2AvgLabel = new javax.swing.JLabel();
        cand2Slider = new javax.swing.JSlider();
        cand2MinLabel = new javax.swing.JLabel();
        cand2MaxLabel = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        cand1Field.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cand1Field.setText("Candidate 1");

        cand1AvgLabel.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
        cand1AvgLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand1AvgLabel.setText("0.0");
        cand1AvgLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        cand1AvgLabel.setInheritsPopupMenu(false);

        cand1Slider.setMajorTickSpacing(1);
        cand1Slider.setMaximum(5);
        cand1Slider.setMinimum(-5);
        cand1Slider.setPaintLabels(true);
        cand1Slider.setPaintTicks(true);
        cand1Slider.setValue(0);
        cand1Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cand1SliderStateChanged(evt);
            }
        });

        cand1MinLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand1MinLabel.setText("0.0");
        cand1MinLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        cand1MaxLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand1MaxLabel.setText("0.0");
        cand1MaxLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        jLabel1.setText("min");

        jLabel2.setText("max");

        jLabel3.setText("average");

        resetButton.setText("RESET");
        resetButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                resetButtonMouseClicked(evt);
            }
        });

        cand2Field.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cand2Field.setText("Candidate 2");

        cand2AvgLabel.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
        cand2AvgLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand2AvgLabel.setText("0.0");
        cand2AvgLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        cand2AvgLabel.setInheritsPopupMenu(false);

        cand2Slider.setMajorTickSpacing(1);
        cand2Slider.setMaximum(5);
        cand2Slider.setMinimum(-5);
        cand2Slider.setPaintLabels(true);
        cand2Slider.setPaintTicks(true);
        cand2Slider.setValue(0);
        cand2Slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cand2SliderStateChanged(evt);
            }
        });

        cand2MinLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand2MinLabel.setText("0.0");
        cand2MinLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        cand2MaxLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        cand2MaxLabel.setText("0.0");
        cand2MaxLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        jLabel4.setText("min");

        jLabel5.setText("max");

        jLabel6.setText("average");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cand1Slider, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addComponent(cand1Field, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(cand1MinLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(cand1AvgLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE))
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cand1MaxLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                                .addGap(36, 36, 36)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(19, 19, 19)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resetButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cand2Slider, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addComponent(cand2Field, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(cand2MinLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(cand2AvgLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cand2MaxLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                                .addGap(36, 36, 36)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6))
                        .addGap(19, 19, 19)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cand2Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cand2MinLabel)
                            .addComponent(jLabel4))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(cand2AvgLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(jLabel6)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cand2MaxLabel)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cand2Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cand1Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(resetButton))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cand1MinLabel)
                            .addComponent(jLabel1))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(cand1AvgLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(jLabel3)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cand1MaxLabel)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cand1Slider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );

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

private void cand1SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cand1SliderStateChanged
    if (!this.cand1Slider.getValueIsAdjusting()) {
        double inputValue = this.cand1Slider.getValue();
            
        this.poll1.recordResponse(inputValue);
        this.cand1AvgLabel.setText(""+this.poll1.getAverage());
        this.cand1MinLabel.setText(""+this.poll1.getMinimum());
        this.cand1MaxLabel.setText(""+this.poll1.getMaximum());
    }
}//GEN-LAST:event_cand1SliderStateChanged

private void resetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseClicked
    this.poll1.reset();
    this.cand1AvgLabel.setText("0.0");
    this.cand1MaxLabel.setText("0.0");
    this.cand1MinLabel.setText("0.0");
    
    this.poll2.reset();
    this.cand2AvgLabel.setText("0.0");
    this.cand2MaxLabel.setText("0.0");
    this.cand2MinLabel.setText("0.0");
}//GEN-LAST:event_resetButtonMouseClicked

private void cand2SliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cand2SliderStateChanged
    if (!this.cand2Slider.getValueIsAdjusting()) {
        double inputValue = this.cand2Slider.getValue();
            
        this.poll2.recordResponse(inputValue);
        this.cand2AvgLabel.setText(""+this.poll2.getAverage());
        this.cand2MinLabel.setText(""+this.poll2.getMinimum());
        this.cand2MaxLabel.setText(""+this.poll2.getMaximum());
    }
}//GEN-LAST:event_cand2SliderStateChanged

    /**
     * @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(PollGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PollGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PollGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PollGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PollGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cand1AvgLabel;
    private javax.swing.JTextField cand1Field;
    private javax.swing.JLabel cand1MaxLabel;
    private javax.swing.JLabel cand1MinLabel;
    private javax.swing.JSlider cand1Slider;
    private javax.swing.JLabel cand2AvgLabel;
    private javax.swing.JTextField cand2Field;
    private javax.swing.JLabel cand2MaxLabel;
    private javax.swing.JLabel cand2MinLabel;
    private javax.swing.JSlider cand2Slider;
    private javax.swing.JLabel jLabel1;
    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.JButton resetButton;
    // End of variables declaration//GEN-END:variables
}
