/*
 * ProgressPanel.java
 *
 * Created on 03 May 2002, 14:57
 */

package org.bodington.applet.components;

import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author  bmb6jrm
 */
public class ProgressPanel extends javax.swing.JPanel {


    /** Creates new form ProgressPanel */
    public ProgressPanel() {
        initComponents();
    }

    /** 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.
     */
    private void initComponents()//GEN-BEGIN:initComponents
    {
	jProgressBar1 = new javax.swing.JProgressBar();
	jButton1 = new javax.swing.JButton();
	jButton2 = new javax.swing.JButton();
	error_text = new javax.swing.JTextArea();
	
	setLayout(new java.awt.GridBagLayout());
	java.awt.GridBagConstraints gridBagConstraints1;
	
	jProgressBar1.setMaximumSize(new java.awt.Dimension(32767, 20));
	jProgressBar1.setMinimumSize(new java.awt.Dimension(10, 20));
	jProgressBar1.setPreferredSize(new java.awt.Dimension(200, 20));
	jProgressBar1.setStringPainted(true);
	gridBagConstraints1 = new java.awt.GridBagConstraints();
	gridBagConstraints1.gridx = 1;
	gridBagConstraints1.gridy = 2;
	gridBagConstraints1.gridwidth = 2;
	gridBagConstraints1.insets = new java.awt.Insets(10, 10, 10, 10);
	add(jProgressBar1, gridBagConstraints1);
	
	jButton1.setText("Stop");
	jButton1.addActionListener(new java.awt.event.ActionListener()
	{
	    public void actionPerformed(java.awt.event.ActionEvent evt)
	    {
		jButton1ActionPerformed(evt);
	    }
	});
	
	gridBagConstraints1 = new java.awt.GridBagConstraints();
	gridBagConstraints1.gridx = 2;
	gridBagConstraints1.gridy = 3;
	gridBagConstraints1.insets = new java.awt.Insets(10, 10, 10, 10);
	add(jButton1, gridBagConstraints1);
	
	jButton2.setText("Close");
	jButton2.setEnabled(false);
	jButton2.addActionListener(new java.awt.event.ActionListener()
	{
	    public void actionPerformed(java.awt.event.ActionEvent evt)
	    {
		jButton2ActionPerformed(evt);
	    }
	});
	
	gridBagConstraints1 = new java.awt.GridBagConstraints();
	gridBagConstraints1.gridx = 1;
	gridBagConstraints1.gridy = 3;
	gridBagConstraints1.insets = new java.awt.Insets(10, 10, 10, 10);
	add(jButton2, gridBagConstraints1);
	
	error_text.setEditable(false);
	error_text.setLineWrap(true);
	error_text.setMinimumSize(new java.awt.Dimension(200, 100));
	error_text.setPreferredSize(new java.awt.Dimension(200, 100));
	error_text.setOpaque(false);
	gridBagConstraints1 = new java.awt.GridBagConstraints();
	gridBagConstraints1.gridx = 1;
	gridBagConstraints1.gridy = 1;
	gridBagConstraints1.gridwidth = 2;
	gridBagConstraints1.insets = new java.awt.Insets(5, 5, 5, 5);
	add(error_text, gridBagConstraints1);
	
    }//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
	// Add your handling code here:
	ActionEvent e = new ActionEvent( this, 
                                          ActionEvent.ACTION_PERFORMED,
					  "cancel",
					  System.currentTimeMillis(),
					  0 );
	fireActionPerformed( e );
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
	// Add your handling code here:
	ActionEvent e = new ActionEvent( this, 
                                          ActionEvent.ACTION_PERFORMED,
					  "close",
					  System.currentTimeMillis(),
					  0 );
	fireActionPerformed( e );
	
    }//GEN-LAST:event_jButton2ActionPerformed

    
    /**
     * Adds an <code>ActionListener</code> to the button.
     * @param l the <code>ActionListener</code> to be added
     */
    public void addActionListener(ActionListener l) {
        listenerList.add(ActionListener.class, l);
    }
    
    /**
     * Removes an <code>ActionListener</code> from the button.
     *
     * @param l the listener to be removed
     */
    public void removeActionListener(ActionListener l) {
	    listenerList.remove(ActionListener.class, l);
    }
    
    /**
     * Returns an array of all the <code>ActionListener</code>s added
     * to this AbstractButton with addActionListener().
     *
     * @return all of the <code>ActionListener</code>s added or an empty
     *         array if no listeners have been added
     * @since 1.4
     */
    public ActionListener[] getActionListeners() {
        return (ActionListener[])(listenerList.getListeners(
            ActionListener.class));
    }
    
    
    /**
     * Notifies all listeners that have registered interest for
     * notification on this event type.  The event instance 
     * is lazily created using the <code>event</code> 
     * parameter.
     *
     * @param event  the <code>ActionEvent</code> object
     * @see EventListenerList
     */
    protected void fireActionPerformed(ActionEvent event) {
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        ActionEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ActionListener.class) {
                // Lazily create the event:
                if (e == null) {
                      String actionCommand = event.getActionCommand();
                      if(actionCommand == null) {
                         actionCommand = "action";
                      }
                      e = new ActionEvent(this,
                                          ActionEvent.ACTION_PERFORMED,
                                          actionCommand,
                                          event.getWhen(),
                                          event.getModifiers());
                }
                ((ActionListener)listeners[i+1]).actionPerformed(e);
            }          
        }
    }
    
    public void setMessage(java.lang.String message)
	{
	jProgressBar1.setString( message );
	}

    public void setErrorMessage(java.lang.String message)
	{
	error_text.setText( message );
	}

    public void setCancelEnabled( boolean b )
	{
	jButton1.setEnabled( b );
	}

    public void setCloseEnabled( boolean b )
	{
	jButton2.setEnabled( b );
	}

    public JProgressBar getProgressBar()
	{
	return jProgressBar1;
	}
	
	

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JProgressBar jProgressBar1;
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JTextArea error_text;
	// End of variables declaration//GEN-END:variables

}
