/*
 Eteria IRC Client, an RFC 1459 compliant client program written in Java.
 Copyright (C) 2000  Javier Kohen <jkohen at tough.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
 package ar.com.jkohen.awt.event;
 
 import java.awt.Component;
 import java.awt.AWTEvent;
 import java.awt.event.MouseEvent;
 import java.lang.reflect.*;
 
 public class NewMouseWheelEvent extends MouseEvent
 {
 	public static long EventMask;
 	public static Class EventClass;
 	private static Method getWheelRotation;
 	private static Method getUnitsToScroll;
 	
 	private int unitsToScroll = 0;
 	private int wheelRotation = 0;
 	
 	public NewMouseWheelEvent(MouseEvent e)  
 	{
 		super((Component)e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());	
 		
 		try
 		{
 			/*
 			**	unitsToScroll = ((MouseWheelEvent)e).getUnitsToScroll();
 			*/
 			Object obj = getUnitsToScroll.invoke(e, new Object[] {});
 			unitsToScroll = ((Integer)obj).intValue();
 		
 			/*
 		   	**	wheelRotation = ((MouseWheelEvent)e).getWheelRotation();
 		   	*/
 			obj = getWheelRotation.invoke(e, new Object[] {});
 			wheelRotation = ((Integer)obj).intValue();
 		}
 		catch (Exception ex) {}
 	}
 	
 	public int getUnitsToScroll()
 	{
 		return(unitsToScroll);
 	}
 	
 	public int getWheelRotation()
 	{
 		return(wheelRotation);
 	}
 	
 	public static void checkMouseWheelSupport()
 	{
 		try
 		{
 			/*
 			** java.awt.AWTEvent.MOUSE_WHEEL_EVENT_MASK
 			*/
 			Field wheelField = AWTEvent.class.getField("MOUSE_WHEEL_EVENT_MASK");
 			
 			if (wheelField != null)
 			{
 				NewMouseWheelEvent.EventMask = wheelField.getLong(null);
 				Class evClass = Class.forName("java.awt.event.MouseWheelEvent");
 				NewMouseWheelEvent.EventClass = evClass;
 				NewMouseWheelEvent.getWheelRotation = evClass.getMethod("getWheelRotation", new Class[] {});
 	   			NewMouseWheelEvent.getUnitsToScroll = evClass.getMethod("getUnitsToScroll", new Class[] {});
 			}
 		}
 		catch (Exception ex) { System.out.println("No mouse wheel support found."); }
 	}
 }