/* ======================================================================
The Bodington System Software License, Version 1.0
  
Copyright (c) 2001 The University of Leeds.  All rights reserved.
  
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1.  Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2.  Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3.  The end-user documentation included with the redistribution, if any,
must include the following acknowledgement:  "This product includes
software developed by the University of Leeds
(http://www.bodington.org/)."  Alternately, this acknowledgement may
appear in the software itself, if and wherever such third-party
acknowledgements normally appear.

4.  The names "Bodington", "Nathan Bodington", "Bodington System",
"Bodington Open Source Project", and "The University of Leeds" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
d.gardner@leeds.ac.uk.

5.  The name "Bodington" may not appear in the name of products derived
from this software without prior written permission of the University of
Leeds.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  TITLE,  THE IMPLIED WARRANTIES 
OF QUALITY  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO 
EVENT SHALL THE UNIVERSITY OF LEEDS OR ITS CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
=========================================================

This software was originally created by the University of Leeds and may contain voluntary 
contributions from others.  For more information on the Bodington Open Source Project, please 
see http://bodington.org/

====================================================================== */

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 javax.swing.event.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

}
