/*
 * @@COPYRIGHT@@
 */
package xal.tools.swing.wheelswitch;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;

import xal.tools.swing.wheelswitch.comp.ArrowButton;
import xal.tools.swing.wheelswitch.util.ColorHelper;

/**
 * Descedant of <code>javax.swing.JComponent</code> that contains two 
 * <code>ArrowButton</code>s acting as a two-way (up/down) control. 
 * 
 * @author <a href="mailto:jernej.kamenik@cosylab.com">Jernej Kamenik</a>
 * @version $id$
 */
public class UpDownButton extends JComponent {
	protected EventListenerList listenerList = null; 
	protected ChangeEvent changeEvent = null;
	
	private int value = 0;

	public static int UP_PRESSED = -1;
	public static int DOWN_PRESSED = -2;
		
	/**
	 * Constructor for UpDownButton.
	 */			
	public UpDownButton() {
		super();
		listenerList = new EventListenerList();	
		setLayout(new UpDownLayout());
		ArrowButton bn = new ArrowButton(ArrowButton.Orientation.UP);
		bn.setFocusable(false);
		bn.setEnabled(isEnabled());
	    bn.setBackground(ColorHelper.getCosyControl());
		bn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				value = UP_PRESSED;
				fireUpDownChanged();				
			}
		});
		ArrowButton bs = new ArrowButton(ArrowButton.Orientation.DOWN);
		bs.setFocusable(false);
		bs.setEnabled(isEnabled());
	    bs.setBackground(ColorHelper.getCosyControl());
		bs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				value = DOWN_PRESSED;
				fireUpDownChanged();				
			}
		});
		add(bn);
		add(bs);
	}		

	/**
	 * Returns <code>UpDownButton.UP_PRESSED</code> if the upper arrowed button was last pressed
	 * and <code>UpDownButton.DOWN_PRESSED</code> if the lower arrowed button was last pressed
	 */			
	public int getValue() {
		return value;
	}

  /**
   * Adds an <code>UpDownListener</code> to the array
   * of listeners currently registered for listening to the changes 
   * of the <code>UpDownButton</code>. These listeners are notified
   * whenever the user clicks the <code>UpDownButton</code>.
   * 
   * @param l
   * @see UpDownListener
   */
	public void addUpDownListener(UpDownListener l) {
	   listenerList.add(UpDownListener.class, l);	
	}

  /**
   * Fires a <code>java.swing.event.ChangeEvent</code> to all currently
   * registered <code>UpDownListener</code>s of the <code>UpDownButton</code>.
   */
	public void fireUpDownChanged() {
		Object[] listeners = listenerList.getListenerList();
		for (int i = listeners.length-2; i>=0; i-=2) {
		    if (listeners[i]==UpDownListener.class) {
				if (changeEvent == null) {
					changeEvent = new ChangeEvent(this);
				}
				((UpDownListener)listeners[i+1]).upDownChanged(changeEvent);
		    }	       
		}
	}	

  /**
   * Removes an <code>UpDownListener</code> from the array
   * of listeners currently registered for listening to the
   * changes of the <code>UpDownButton</code>.
   */
	public void removeUpDownListener(UpDownListener l) {
	   listenerList.remove(UpDownListener.class, l);		
	}

  /**
   * This method was overridden to implement correct 
   * <code>UpDownButton<code> placement inside the 
   * <code>Wheelswitch</code> container.
   * 
   * @see JComponent#getPreferredSize()
   */
	public Dimension getPreferredSize() {
		return new Dimension(24,48);
	}
	
  /**
   * This method was overridden to implement correct 
   * <code>UpDownButton<code> placement inside the 
   * <code>Wheelswitch</code> container.
   * 
   * @see JComponent#getMinimumSize()
   */
	public Dimension getMinimumSize() {
		return new Dimension(12,24);
	}	
	/* (non-Javadoc)
	 * @see java.awt.Component#setEnabled(boolean)
	 */
	public void setEnabled(boolean arg0) {
		super.setEnabled(arg0);
		getComponent(0).setEnabled(arg0);
		getComponent(1).setEnabled(arg0);
	}

}


@@ -671,59 +671,8 @@
 t %7B%0A
-%09protected EventListenerList listenerList = null; %0A
 %09pro
@@ -1184,32 +1184,54 @@
 ionListener() %7B%0A
+            @Override%0A
 %09%09%09public void a
@@ -1547,16 +1547,38 @@
 ner() %7B%0A
+            @Override%0A
 %09%09%09publi
@@ -3371,32 +3371,46 @@
 redSize()%0A   */%0A
+    @Override%0A
 %09public Dimensio
@@ -3667,24 +3667,38 @@
 ize()%0A   */%0A
+    @Override%0A
 %09public Dime
@@ -3824,24 +3824,38 @@
 olean)%0A%09 */%0A
+    @Override%0A
 %09public void

Fix trivial warnings in 'UpDownButton' class.