/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Rectangle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tom
 */
public class AllInOneStatusDialog extends javax.swing.JDialog {
    private boolean finished = false;
    private int status = 0;
    private Thread thread = null;
    
    /**
     * Creates new form AllInOneStatusDialog
     */
    public AllInOneStatusDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        Rectangle parentBounds = parent.getBounds();
        this.setBounds((int)(parentBounds.getWidth()/2-getBounds().getWidth()/2) + (int)parentBounds.getX(), 
                       (int)(parentBounds.getHeight()/2-getBounds().getHeight()/2) + (int)parentBounds.getY(), 
                       (int)getBounds().getWidth(), (int)getBounds().getHeight());
        
        lblCheck1.setEnabled(false);
        lblCheck2.setEnabled(false);
        lblCheck3.setEnabled(false);
        lblCheck4.setEnabled(false);
        lblCheck5.setEnabled(false);
        startBlinking();
    }

    public void setLabelEnabled(int id){
        status = id;
        switch (id){
            case 1:
                lblCheck1.setEnabled(true);
                break;
            case 2:
                lblCheck2.setEnabled(true);
                break;
            case 3:
                lblCheck3.setEnabled(true);
                break;
            case 4:
                lblCheck4.setEnabled(true);
                break;
            case 5:
                finished = true;
                lblCheck5.setEnabled(true);
                break;
        }
    }
    
    private void startBlinking(){
        thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    blinkLabel();
                }
            });
            thread.start();
    }
    
    private void blinkLabel(){
        while (!finished){
            switch (status){
                case 0:
                    lblCheck1.setEnabled(!lblCheck1.isEnabled());
                    break;
                case 1:
                    lblCheck2.setEnabled(!lblCheck2.isEnabled());
                    break;
                case 2:
                    lblCheck3.setEnabled(!lblCheck3.isEnabled());
                    break;
                case 3:
                    lblCheck4.setEnabled(!lblCheck4.isEnabled());
                    break;
                case 4:
                    lblCheck5.setEnabled(!lblCheck5.isEnabled());
                    break;
                case 5: //nothing
                    break;
            }
            try {
                thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(ComposingStatusDialog.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
    /**
     * 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() {

        jPanel1 = new javax.swing.JPanel();
        lblCheck1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblCheck2 = new javax.swing.JLabel();
        lblCheck4 = new javax.swing.JLabel();
        lblCheck5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblCheck3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Status");
        setUndecorated(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblCheck1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/check_mark.png"))); // NOI18N

        jLabel2.setText("analysing category (note amounts, instruments, tonality)");

        jLabel3.setText("detecting polyphonic motifs");

        jLabel4.setText("analysing tempo of beats");

        jLabel5.setText("analysing interestingness measure of beats");

        lblCheck2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/check_mark.png"))); // NOI18N

        lblCheck4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/check_mark.png"))); // NOI18N

        lblCheck5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/check_mark.png"))); // NOI18N

        jLabel1.setText("analysing beat transitions");

        lblCheck3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/check_mark.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblCheck2)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(lblCheck3)
                            .addGap(18, 18, 18)
                            .addComponent(jLabel1))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(lblCheck4)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel4))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(lblCheck5)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel5)))
                            .addGap(33, 33, 33)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblCheck1)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(lblCheck1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(lblCheck2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(lblCheck3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(lblCheck4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblCheck5)
                    .addComponent(jLabel5))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

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

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AllInOneStatusDialog dialog = new AllInOneStatusDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    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.JPanel jPanel1;
    private javax.swing.JLabel lblCheck1;
    private javax.swing.JLabel lblCheck2;
    private javax.swing.JLabel lblCheck3;
    private javax.swing.JLabel lblCheck4;
    private javax.swing.JLabel lblCheck5;
    // End of variables declaration//GEN-END:variables
}
