欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

piyeventlistener.java

PIY(Program It Yourself)是一个基于Java的应用程序开发环境
JAVA
字号:
package piy;

import java.util.*;

/**
* Each event in piy on each component can have an ActionList attached to it.  
* Subclasses of this should represent (valid) java Listeners (ie must implement
* the relevant Listener methods).  However, they should delegate all actions
* back to this class - it takes care of handling which action list should
* be triggered by which action.
* @author David Vivash
* @version 1.0.2, 22/04/01
*/
public abstract class PiyEventListener {

	private HashMap pairs = new HashMap(2);

	/**
	* This method tells PIY which types of components can have the event 
	* listener attached. This must be overriden by implementing listeners.
	* @return the type of components that trigger the events being listened to
	*/
	public static Class getSupportedClass() {
		throw new RuntimeException("Implementing listener doesn't override the " + 
									"getSupportedClass() method in PiyEventListener");
	}

	/**
	* Binds an actionlist to be triggered whenever the event specified occurs.
	* @param event the event to triggers  the list (from the getEvents() method)
	* @param list the ActionList to be triggerred
	*/
	public void setActionList(String event, ActionList list) {
		pairs.put(event, list);
	}

	/**
	* Adds a set of event->list mappings in one go.
	* @param eventsToLists a map mapping event names (Strings) to lists (ActionLists)
	*/
	public void setActionLists(AbstractMap eventsToLists) {
		if (eventsToLists != null) {
			Iterator items = eventsToLists.keySet().iterator();
			while (items.hasNext()) {
				String event = (String)items.next();
				ActionList list = (ActionList)eventsToLists.get(event);
				pairs.put(event, list);
			}
		}
	}

	/**
	* A subclass should call this method whenever it detects the event has occured. For
	* example, if the subclass listens to see when a button click occurs, it might have a 
	* method like: 
	* <code> 
	* public void actionPerformed(ActionEvent e) { super.eventTriggered("Button Clicked"); }
	* </code>
	* @param event the event that has been triggered
	*/
	public void eventTriggered(String event) {
		ActionList toRun = (ActionList)pairs.get(event);
		if (toRun != null) toRun.execute();
	}

	/**
	* Gets the event names that are supported by this listener.
	* @return the event names
	*/
	public abstract String[] getEvents();

	/**
	* Gets the method name that should be used to add the concrete listener to the component
	* as a listener.  This is the full method name, as in <code>addActionListener</code>.
	* @return the String name of the method
	*/
	public abstract String getAddListenerMethod();

	/**
	* Get the type of the listener that the addListener method expects to receie.  ie. the
	* <code>addActionListener</code> method expects to receive an ActionListener class as a 
	* parameter.
	* @return the type of the parameter
	*/
	public abstract Class getAddListenerType();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -