/*$cb
 *    This file is a part of libopenmhp.
 *
 *    Copyright (C) 2005 Mikko Novaro <miknov@gmail.com>
 *
 *    See main header file (libopenmhp/openmhp.h) for licensing and
 *    contact information.
 $ce*/

package libopenmhp.xmlhandler.elem;

import libopenmhp.xmlhandler.XMLElement;
import libopenmhp.Debug;

import org.dvb.event.EventManager;

import java.awt.Container;

public class keyevent extends XMLElement {

    public void end() {
        int keycode = 0;
        try {
            keycode = new Integer(getChildNode("keycode").getData()).intValue();
        } catch (Exception e) {
	    Debug.err(this, "error decoding keycode \"" + getChildNode("keycode").getData() + "\".");
	    e.printStackTrace();
            throw new RuntimeException("Error in decoding keycode.");
        }
        // DEBUG: System.out.println("xmlhandler: Received keyevent (\""+keycode+"\")");
	
        // Pass the received key event to OpenMHP:
    	try {
    	    libopenmhp.InterfaceServer.eventManager.fireUserEvent(this, new java.awt.event.KeyEvent(new Container(), 0, 0, 0, keycode));
    	} catch (Throwable t) {
	    Debug.err(this, "error delivering key event.");
	    t.printStackTrace();
	}
    	// org.openmhp.system.TVScreenAwt.instance.repaint();
    }
    
}
