Package barrysoft.gui

Source Code of barrysoft.gui.GUIEventsDispatcher

package barrysoft.gui;

import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.util.Vector;

public class GUIEventsDispatcher<Type> {
 
  private final Vector<Component> targets =
    new Vector<Component>();
 
  public void addTarget(Component target)
  {
    targets.add(target);
  }
 
  public void removeTarget(Component target)
  {
    targets.remove(target);
  }
 
  public void dispatch(Type event)
  {
    dispatch(new GUIEvent<Type>(event, new Object[] {}));
  }
 
  public void dispatch(Type event, Object... data)
  {
    dispatch(new GUIEvent<Type>(event, data));
  }
 
  public void dispatch(int id, Type event, Object... data)
  {
    dispatch(new GUIEvent<Type>(id, event, data));
  }
 
  public void dispatch(GUIEvent<Type> event)
  {
    EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
   
    for (Component target : targets)
    {
      GUIEvent<Type> eventCopy = event.copy();
      eventCopy.setSource(target);
     
      eventQueue.postEvent(eventCopy);
    }   
  }

}
TOP

Related Classes of barrysoft.gui.GUIEventsDispatcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.