001 package nl.cwi.sen1.gui.plugin; 002 003 import javax.swing.event.EventListenerList; 004 005 /** 006 * A default implementation of a StudioPlugin for your convenience. 007 * This class simply provides the implementation of the Observer 008 * design pattern already. The other methods of StudioPlugin need 009 * still to be implemented. 010 */ 011 public abstract class DefaultStudioPlugin implements StudioPlugin { 012 private EventListenerList listenerList = new EventListenerList(); 013 014 public void addStudioPluginListener(StudioPluginListener l) { 015 listenerList.add(StudioPluginListener.class, l); 016 } 017 018 public void removeStudioPluginListener(StudioPluginListener l) { 019 listenerList.remove(StudioPluginListener.class, l); 020 } 021 022 protected void fireStudioPluginClosed() { 023 Object[] listeners = listenerList.getListenerList(); 024 for (int i = listeners.length - 2; i >= 0; i -= 2) { 025 if (listeners[i] == StudioPluginListener.class) { 026 ((StudioPluginListener) listeners[i + 1]) 027 .studioPluginClosed(this); 028 } 029 } 030 } 031 }