@ListenerSupport

peichhorn edited this page Jun 30, 2012 · 2 revisions

@ListenerSupport

Overview

(Documentation pending)

Example

With Lombok

import lombok.ListenerSupport;

import java.awt.event.KeyListener
import java.awt.event.MouseWheelListener

@ListenerSupport({KeyListener.class, MouseWheelListener.class})
class ListenerSupportExample {
}

Vanilla Java

class ListenerSupportExample {
  private final java.util.List<java.awt.event.KeyListener> $registeredKeyListener = new java.util.concurrent.CopyOnWriteArrayList<java.awt.event.KeyListener>();
  private final java.util.List<java.awt.event.MouseWheelListener> $registeredMouseWheelListener = new java.util.concurrent.CopyOnWriteArrayList<java.awt.event.MouseWheelListener>();

  public void addKeyListener(final java.awt.event.KeyListener l) {
    if (!$registeredKeyListener.contains(l)) $registeredKeyListener.add(l);
  }

  public void removeKeyListener(final java.awt.event.KeyListener l) {
    $registeredKeyListener.remove(l);
  }

  protected void fireKeyTyped(final java.awt.event.KeyEvent arg0) {
    for (java.awt.event.KeyListener l : $registeredKeyListener) l.keyTyped(arg0);
  }

  protected void fireKeyPressed(final java.awt.event.KeyEvent arg0) {
    for (java.awt.event.KeyListener l : $registeredKeyListener) l.keyPressed(arg0);
  }

  protected void fireKeyReleased(final java.awt.event.KeyEvent arg0) {
    for (java.awt.event.KeyListener l : $registeredKeyListener) l.keyReleased(arg0);
  }

  public void addMouseWheelListener(final java.awt.event.MouseWheelListener l) {
    if (!$registeredMouseWheelListener.contains(l)) $registeredMouseWheelListener.add(l);
  }

  public void removeMouseWheelListener(final java.awt.event.MouseWheelListener l) {
    $registeredMouseWheelListener.remove(l);
  }

  protected void fireMouseWheelMoved(final java.awt.event.MouseWheelEvent arg0) {
    for (java.awt.event.MouseWheelListener l : $registeredMouseWheelListener) l.mouseWheelMoved(arg0);
  }
}

Behind the Scenes

(Documentation pending)

Configuration

Nothing to configure yet.