package audiobook;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;

/**
 * This class represents a simple dialog containing a progress bar and two labels
 * @author Kim
 * @see JProgressBar
 * @see JLabel
 */
public class ProgressDialog extends javax.swing.JDialog implements PropertyChangeListener {

    /** Creates new form ProgressDialog */
    public ProgressDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setLocationRelativeTo(parent);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        progressBar = new javax.swing.JProgressBar();
        ActionLabel = new javax.swing.JLabel();
        MessageLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle(".POD Datei erstellen");

        ActionLabel.setText("ActionLabel");

        MessageLabel.setText("MessageLabel");

        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.LEADING)
                    .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                    .addComponent(ActionLabel)
                    .addComponent(MessageLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ActionLabel)
                .addGap(18, 18, 18)
                .addComponent(MessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

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

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        switch(evt.getPropertyName()){
            case "ActionLabel": 
                ActionLabel.setText(evt.getNewValue().toString());
                break;
            case "MessageLabel":
                MessageLabel.setText(evt.getNewValue().toString());
                break;
            case "Maximum":
                progressBar.setMaximum(Integer.parseInt(evt.getNewValue().toString()));
                break;
            case "ProgressValue":
                progressBar.setValue(Integer.parseInt(evt.getNewValue().toString()));
                break;
            case "Error":
                JOptionPane.showMessageDialog(this, evt.getNewValue(), "Fehler", JOptionPane.ERROR_MESSAGE);
                break;
            case "Finish":
                if(Boolean.parseBoolean(evt.getNewValue().toString())){
                    JOptionPane.showMessageDialog(this, "Prozess erfolgreich abgeschlossen", "Fertig", JOptionPane.INFORMATION_MESSAGE);
                } else{
                    JOptionPane.showMessageDialog(this, "Der Prozess konnte nicht abgeschlossen werden.", "Fehler", JOptionPane.INFORMATION_MESSAGE);
                }
                setVisible(false);
                dispose();
                break;
        }
    }
    //<editor-fold defaultstate="collapsed" desc="Variables declaration">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JLabel ActionLabel;
    public javax.swing.JLabel MessageLabel;
    public javax.swing.JProgressBar progressBar;
    // End of variables declaration//GEN-END:variables
    //</editor-fold>
}
