Java Code Examples for java.util.EventListener

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project codjo-data-process, under directory /codjo-data-process-common/src/main/java/net/codjo/dataprocess/common/eventsbinder/.

Source file: EventsBinder.java

  18 
vote

protected void bindOneAnnotationToAllProperties(String[] propertyNames,Object boundObject,AnnotationManager annotationManager,Annotation currentAnnotation,MethodCallEventReaction methodCallReaction) throws GetterHelperException, EventBinderException {
  for (  String propertyName : propertyNames) {
    Object property=GetterHelper.getProperty(propertyName,boundObject);
    Class<? extends EventListener> listenerClass=annotationManager.getListenerClass(currentAnnotation);
    EventListener listener=DynamicListener.createEventListener(listenerClass,methodCallReaction,annotationManager.createEventChecker(currentAnnotation));
    annotationManager.registerListener(currentAnnotation,property,listener,listenerClass);
  }
}
 

Example 2

From project echo2, under directory /src/app/java/nextapp/echo2/app/event/.

Source file: EventListenerList.java

  18 
vote

/** 
 * @see java.io.Serializable
 */
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
  in.defaultReadObject();
  listeners=EMPTY;
  size=0;
  ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
  Object listenerClassName=in.readObject();
  while (listenerClassName != null) {
    EventListener listener=(EventListener)in.readObject();
    addListener(Class.forName((String)listenerClassName,true,classLoader),listener);
    listenerClassName=in.readObject();
  }
}
 

Example 3

From project echo3, under directory /src/server-java/app/nextapp/echo/app/event/.

Source file: EventListenerList.java

  18 
vote

/** 
 * @see java.io.Serializable
 */
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
  in.defaultReadObject();
  listeners=EMPTY;
  size=0;
  ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
  Object listenerClassName=in.readObject();
  while (listenerClassName != null) {
    EventListener listener=(EventListener)in.readObject();
    addListener(Class.forName((String)listenerClassName,true,classLoader),listener);
    listenerClassName=in.readObject();
  }
}
 

Example 4

From project jsf-test, under directory /stage/src/main/java/org/jboss/test/faces/.

Source file: FacesEnvironment.java

  18 
vote

public FacesEnvironment withSeam(){
  checkNotInitialized();
  try {
    Filter ajaxFilter=createInstance("org.jboss.seam.servlet.SeamFilter");
    withFilter("ajax4jsf",ajaxFilter);
    EventListener seamListener=createInstance("org.jboss.seam.servlet.SeamListener");
    facesServer.addWebListener(seamListener);
    webXmlDefault="org/jboss/test/faces/ajax-web.xml";
    return this;
  }
 catch (  ClassNotFoundException e) {
    throw new TestException(e);
  }
}
 

Example 5

From project jsword, under directory /src/main/java/org/crosswire/common/util/.

Source file: EventListenerList.java

  18 
vote

/** 
 * Serialization support
 */
private void writeObject(ObjectOutputStream oos) throws IOException {
  Object[] lList=getListenerList();
  oos.defaultWriteObject();
  for (int i=0; i < lList.length; i+=2) {
    Class<?> t=(Class<?>)lList[i];
    EventListener li=(EventListener)lList[i + 1];
    if ((li != null) && (li instanceof Serializable)) {
      oos.writeObject(t.getName());
      oos.writeObject(li);
    }
  }
  oos.writeObject(null);
}
 

Example 6

From project org.ops4j.pax.web, under directory /pax-web-extender-war/src/main/java/org/ops4j/pax/web/extender/war/internal/.

Source file: RegisterWebAppVisitorWC.java

  18 
vote

/** 
 * Registers listeners with web container.
 * @throws NullArgumentException if listener is null
 * @see WebAppVisitor#visit(org.ops4j.pax.web.extender.war.internal.model.WebAppListener)
 */
public void visit(final WebAppListener webAppListener){
  NullArgumentException.validateNotNull(webAppListener,"Web app listener");
  try {
    final EventListener listener=RegisterWebAppVisitorHS.newInstance(EventListener.class,m_bundleClassLoader,webAppListener.getListenerClass());
    webAppListener.setListener(listener);
    m_webContainer.registerEventListener(listener,m_httpContext);
  }
 catch (  Throwable ignore) {
    LOG.error("Registration exception. Skipping.",ignore);
  }
}
 

Example 7

From project cipango, under directory /cipango-server/src/main/java/org/cipango/server/sipapp/.

Source file: MetaData.java

  17 
vote

private void initListeners(SipAppContext context){
  for (  String className : _listeners) {
    SipServletHolder holder=getServlet(context,className);
    boolean found=false;
    if (context.getEventListeners() != null) {
      for (      EventListener listener : context.getEventListeners()) {
        if (listener.getClass().getName().equals(className)) {
          LOG.debug("Found multiple listener declaration " + className);
          if (holder != null)           holder.setServlet((SipServlet)listener);
          found=true;
          break;
        }
      }
    }
    if (found)     continue;
    try {
      @SuppressWarnings("rawtypes") Class listenerClass=context.getWebAppContext().loadClass(className);
      @SuppressWarnings("unchecked") EventListener listener=newListenerInstance(context,listenerClass);
      if (holder != null)       holder.setServlet((SipServlet)listener);
      context.addEventListener(listener);
    }
 catch (    Exception e) {
      LOG.warn("Could not instantiate listener: " + className,e);
    }
  }
}
 

Example 8

From project components, under directory /common/rules/src/main/java/org/switchyard/component/common/rules/util/drools/.

Source file: Events.java

  17 
vote

/** 
 * Adds EventListeners specified in the ComponentImplementationConfig to the provided KnowledgeRuntimeEventManager. If the EventListeners provide a Constructor taking a single KnowledgeRuntimeEventManager as a parameter, that is used and it is assumed it will do the work of registering itself.  Otherwise, a no-arg constructor is assumed, and this method will do the work of registering the EventListener for each of the respected interfaces it implements. Those interfaces being: <ul> <li> {@link org.drools.event.WorkingMemoryEventListener}</li> <li> {@link org.drools.event.rule.WorkingMemoryEventListener}</li> <li> {@link org.drools.event.AgendaEventListener}</li> <li> {@link org.drools.event.rule.AgendaEventListener}</li> <li> {@link org.drools.event.RuleBaseEventListener}</li> <li> {@link org.drools.event.knowledgebase.KnowledgeBaseEventListener}</li> <li> {@link org.drools.event.process.ProcessEventListener}</li> </ul>
 * @param cic the ComponentImplementationConfig
 * @param krem the KnowledgeRuntimeEventManager
 * @return the List of EventListeners that were created and added
 */
public static final List<EventListener> addEventListeners(ComponentImplementationConfig cic,KnowledgeRuntimeEventManager krem){
  List<EventListener> list=new ArrayList<EventListener>();
  if (cic != null) {
    ComponentImplementationModel cim=cic.getModel();
    if (cim != null) {
      for (      EventListenerModel elm : cim.getEventListeners()) {
        ClassLoader loader=cic.getLoader();
        if (loader == null) {
          loader=Events.class.getClassLoader();
        }
        Class<? extends EventListener> elc=elm.getClazz(loader);
        if (elc != null) {
          EventListener el;
          try {
            @SuppressWarnings("unused") Constructor<? extends EventListener> cnstr=elc.getDeclaredConstructor(KnowledgeRuntimeEventManager.class);
            el=Construction.construct(elc,new Class[]{KnowledgeRuntimeEventManager.class},new Object[]{krem});
          }
 catch (          NoSuchMethodException nsme1) {
            try {
              @SuppressWarnings("unused") Constructor<? extends EventListener> cnstr=elc.getDeclaredConstructor();
              el=Construction.construct(elc);
              registerEventListener(el,krem);
            }
 catch (            NoSuchMethodException nsme2) {
              el=null;
            }
          }
          if (el != null) {
            list.add(el);
          }
 else {
            LOGGER.error("Could not find appropriate constructor in class " + elc.getName());
          }
        }
      }
    }
  }
  return list;
}
 

Example 9

From project meteo, under directory /core/src/main/java/com/ning/metrics/meteo/server/.

Source file: JettyServer.java

  17 
vote

public void start(final Injector injector) throws Exception {
  final long startTime=System.currentTimeMillis();
  server=new Server();
  final MBeanContainer mbContainer=new MBeanContainer(mbeanServer);
  server.getContainer().addEventListener(mbContainer);
  server.addBean(mbContainer);
  mbContainer.addBean(Log.getLog());
  final Connector connector=new SelectChannelConnector();
  connector.setStatsOn(config.isJettyStatsOn());
  connector.setHost(config.getLocalIp());
  connector.setPort(config.getLocalPort());
  server.addConnector(connector);
  server.setStopAtShutdown(true);
  final ServletContextHandler context=new ServletContextHandler(server,"/",ServletContextHandler.SESSIONS);
  context.setContextPath("/");
  context.addEventListener(new GuiceServletContextListener(){
    @Override protected Injector getInjector(){
      return injector;
    }
  }
);
  final EventListener listener=new SetupJULBridge();
  context.addEventListener(listener);
  final FilterHolder filterHolder=new FilterHolder(GuiceFilter.class);
  context.addFilter(filterHolder,"/*",EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
  final ServletHolder sh=new ServletHolder(DefaultServlet.class);
  context.addServlet(sh,"/*");
  server.start();
  final long secondsToStart=(System.currentTimeMillis() - startTime) / 1000;
  log.info(String.format("Jetty server started in %d:%02d",secondsToStart / 60,secondsToStart % 60));
}
 

Example 10

From project ning-service-skeleton, under directory /core/src/main/java/com/ning/jetty/core/server/.

Source file: HttpServer.java

  17 
vote

private ServletContextHandler createServletContextHandler(final String resourceBase,final Iterable<EventListener> eventListeners,final Map<FilterHolder,String> filterHolders){
  final ServletContextHandler context=new ServletContextHandler(server,"/",ServletContextHandler.NO_SESSIONS);
  context.setContextPath("/");
  if (resourceBase != null) {
    final String webapp=this.getClass().getClassLoader().getResource(resourceBase).toExternalForm();
    context.setResourceBase(webapp);
  }
  final EventListener listener=new SetupJULBridge();
  context.addEventListener(listener);
  for (  final EventListener eventListener : eventListeners) {
    context.addEventListener(eventListener);
  }
  for (  final FilterHolder filterHolder : filterHolders.keySet()) {
    context.addFilter(filterHolder,filterHolders.get(filterHolder),EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
  }
  final FilterHolder filterHolder=new FilterHolder(GuiceFilter.class);
  context.addFilter(filterHolder,"/*",EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
  final ServletHolder sh=new ServletHolder(DefaultServlet.class);
  context.addServlet(sh,"/*");
  return context;
}
 

Example 11

From project codjo-standalone-common, under directory /src/main/java/net/codjo/gui/broadcast/.

Source file: BroadcastColumnsDetailWindow.java

  15 
vote

private void initFieldName(){
  EventListener[] el=DB_TABLE_NAME.getListeners(ActionListener.class);
  for (  EventListener anEl : el) {
    if (anEl.getClass().isInstance(tableNameListener)) {
      return;
    }
  }
  DB_TABLE_NAME.addActionListener(tableNameListener);
}
 

Example 12

From project echo3extras, under directory /src/server-java/app/nextapp/echo/extras/app/.

Source file: AccordionPane.java

  15 
vote

/** 
 * Notifies <code>TabSelectionListener</code>s that the user has selected a tab.
 */
protected void fireTabSelected(int tabIndex){
  if (!hasEventListenerList()) {
    return;
  }
  EventListener[] listeners=getEventListenerList().getListeners(TabSelectionListener.class);
  if (listeners.length == 0) {
    return;
  }
  TabSelectionEvent e=new TabSelectionEvent(this,tabIndex);
  for (int i=0; i < listeners.length; ++i) {
    ((TabSelectionListener)listeners[i]).tabSelected(e);
  }
}
 

Example 13

From project event-bus, under directory /src/main/java/com/northconcepts/eventbus/.

Source file: EventBus.java

  15 
vote

public <T extends EventListener>void addListener(Class<T> eventListenerClass,EventFilter filter,T listener){
  TypedListenerList<T> list;
synchronized (typedListeners) {
    list=getTypedListenerList(eventListenerClass);
    if (list == null) {
      list=new TypedListenerList<T>(eventListenerClass);
      typedListeners.put(eventListenerClass,list);
    }
  }
  list.getList().add(new EventListenerStub.Typed<T>(filter,listener,garbageTypedListeners));
}
 

Example 14

From project freemind, under directory /freemind/accessories/plugins/time/.

Source file: TimeList.java

  15 
vote

protected void processKeyEvent(KeyEvent e){
  if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    EventListener[] el=super.getListeners(KeyListener.class);
    if (e.getID() != KeyEvent.KEY_RELEASED)     return;
    for (int i=0; i < el.length; i++) {
      KeyListener kl=(KeyListener)el[i];
      kl.keyReleased(e);
    }
    return;
  }
  super.processKeyEvent(e);
}
 

Example 15

From project groundhog-reader, under directory /src/main/java/org/apache/commons/net/io/.

Source file: CopyStreamAdapter.java

  15 
vote

/** 
 * This method is not part of the JavaBeans model and is used by the static methods in the org.apache.commons.io.Util class for efficiency. It is invoked after a block of bytes to inform the listener of the transfer.  The CopyStreamAdapater will create a CopyStreamEvent from the arguments and relay the event to all of its registered listeners, listing itself as the source of the event.
 * @param totalBytesTransferred  The total number of bytes transferredso far by the copy operation.
 * @param bytesTransferred  The number of bytes copied by the most recentwrite.
 * @param streamSize The number of bytes in the stream being copied.This may be equal to CopyStreamEvent.UNKNOWN_STREAM_SIZE if the size is unknown.
 */
public void bytesTransferred(long totalBytesTransferred,int bytesTransferred,long streamSize){
  CopyStreamEvent event;
  event=new CopyStreamEvent(this,totalBytesTransferred,bytesTransferred,streamSize);
  for (  EventListener listener : internalListeners) {
    ((CopyStreamListener)(listener)).bytesTransferred(event);
  }
}
 

Example 16

From project iee, under directory /org.eclipse.iee.sample.graph/src/org/jfree/experimental/chart/swt/.

Source file: ChartComposite.java

  15 
vote

/** 
 * Hook an SWT listener on the canvas where the chart is drawn. The purpose of this method is to allow some degree of customization.
 * @param listener The SWT listener to attach to the canvas.
 */
public void addSWTListener(EventListener listener){
  if (listener instanceof ControlListener) {
    this.canvas.addControlListener((ControlListener)listener);
  }
 else   if (listener instanceof DisposeListener) {
    this.canvas.addDisposeListener((DisposeListener)listener);
  }
 else   if (listener instanceof FocusListener) {
    this.canvas.addFocusListener((FocusListener)listener);
  }
 else   if (listener instanceof HelpListener) {
    this.canvas.addHelpListener((HelpListener)listener);
  }
 else   if (listener instanceof KeyListener) {
    this.canvas.addKeyListener((KeyListener)listener);
  }
 else   if (listener instanceof MouseListener) {
    this.canvas.addMouseListener((MouseListener)listener);
  }
 else   if (listener instanceof MouseMoveListener) {
    this.canvas.addMouseMoveListener((MouseMoveListener)listener);
  }
 else   if (listener instanceof MouseTrackListener) {
    this.canvas.addMouseTrackListener((MouseTrackListener)listener);
  }
 else   if (listener instanceof PaintListener) {
    this.canvas.addPaintListener((PaintListener)listener);
  }
 else   if (listener instanceof TraverseListener) {
    this.canvas.addTraverseListener((TraverseListener)listener);
  }
}
 

Example 17

From project inproctester, under directory /inproctester-jersey/src/main/java/com/thoughtworks/inproctester/jersey/.

Source file: InProcessTestContainerFactory.java

  15 
vote

private void instantiateInprocessWebServer(){
  httpServer=new HttpAppTester(contextPath);
  if (servletClass != null) {
    httpServer.addServlet(servletClass,servletPath,initParams);
  }
  if (contextParams != null) {
    for (    Map.Entry<String,String> parameterEntry : contextParams.entrySet()) {
      httpServer.setInitParameter(parameterEntry.getKey(),parameterEntry.getValue());
    }
  }
  if (eventListeners != null) {
    for (    Class<? extends EventListener> eventListener : eventListeners) {
      try {
        httpServer.addEventListener(eventListener.newInstance());
      }
 catch (      InstantiationException e) {
        throw new RuntimeException(e);
      }
catch (      IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
  }
}
 

Example 18

From project jetty-project, under directory /jetty-jboss/src/main/java/org/mortbay/j2ee/session/.

Source file: Manager.java

  15 
vote

public void addEventListener(EventListener listener) throws IllegalArgumentException, IllegalStateException {
synchronized (_startedLock) {
    if (isStarted())     throw new IllegalStateException("EventListeners must be added before a Session Manager starts");
    boolean known=false;
    if (listener instanceof HttpSessionAttributeListener) {
      _sessionAttributeListeners.add(listener);
      known=true;
    }
    if (listener instanceof HttpSessionListener) {
      _sessionListeners.add(listener);
      known=true;
    }
    if (!known)     throw new IllegalArgumentException("Unknown EventListener type " + listener);
  }
}
 

Example 19

From project nodebox, under directory /src/main/java/nodebox/client/.

Source file: ColorWell.java

  15 
vote

protected void fireStateChanged(){
  if (changeEvent == null) {
    changeEvent=new ChangeEvent(this);
  }
  for (  EventListener l : listenerList.getListeners(ChangeListener.class)) {
    ((ChangeListener)l).stateChanged(changeEvent);
  }
}
 

Example 20

From project Openbravo-POS-iPhone-App, under directory /UnicentaPOS/src-beans/com/openbravo/editor/.

Source file: JEditorKeys.java

  15 
vote

protected void fireActionPerformed(){
  EventListener[] l=listeners.getListeners(ActionListener.class);
  ActionEvent e=null;
  for (int i=0; i < l.length; i++) {
    if (e == null) {
      e=new ActionEvent(this,ActionEvent.ACTION_PERFORMED,null);
    }
    ((ActionListener)l[i]).actionPerformed(e);
  }
}
 

Example 21

From project pos_1, under directory /src-beans/com/openbravo/editor/.

Source file: JEditorKeys.java

  15 
vote

protected void fireActionPerformed(){
  EventListener[] l=listeners.getListeners(ActionListener.class);
  ActionEvent e=null;
  for (int i=0; i < l.length; i++) {
    if (e == null) {
      e=new ActionEvent(this,ActionEvent.ACTION_PERFORMED,null);
    }
    ((ActionListener)l[i]).actionPerformed(e);
  }
}
 

Example 22

From project tabris, under directory /com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/.

Source file: ClientCanvasTest.java

  15 
vote

@Test public void testAddsDispatchListenerLast(){
  PaintListener listener=mock(PaintListener.class);
  clientCanvas.addPaintListener(listener);
  IEventAdapter adapter=clientCanvas.getAdapter(IEventAdapter.class);
  EventListener[] listeners=adapter.getListener(PaintListener.class);
  assertEquals(listener,listeners[0]);
  assertEquals(2,listeners.length);
}
 

Example 23

From project undertow, under directory /servlet/src/main/java/io/undertow/servlet/api/.

Source file: ListenerInfo.java

  15 
vote

public ListenerInfo(final Class<? extends EventListener> listenerClass,final InstanceFactory<? extends EventListener> instanceFactory){
  this.listenerClass=listenerClass;
  this.instanceFactory=instanceFactory;
  boolean ok=false;
  for (  Class c : LISTENER_CLASSES) {
    if (c.isAssignableFrom(listenerClass)) {
      ok=true;
      break;
    }
  }
  if (!ok) {
    throw UndertowServletMessages.MESSAGES.listenerMustImplementListenerClass(listenerClass);
  }
}