001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: NotificationSupport.java,v $ 023 Revision 1.4 2004/05/05 22:16:57 markl 024 comment block updates 025 026 Revision 1.3 2003/01/19 09:34:09 markl 027 Javadoc & comment header updates. 028 029 Revision 1.2 2001/03/12 01:38:49 markl 030 Source code cleanup. 031 032 Revision 1.1 1999/06/08 06:48:50 markl 033 Initial revision 034 ---------------------------------------------------------------------------- 035*/ 036 037package kiwi.event; 038 039import java.awt.event.*; 040import javax.swing.event.*; 041 042/** A support object for generating <code>NotificationEvent</code>s. 043 * 044 * @see kiwi.event.NotificationEvent 045 * @see kiwi.event.NotificationListener 046 * 047 * @author Mark Lindner 048 */ 049 050public class NotificationSupport 051 { 052 private EventListenerList listeners; 053 private Object source; 054 055 /** Construct a new <code>NotificationSupport</code> object. 056 * 057 * @param source The owner of this object (and the source of the events that 058 * will be generated by it). 059 */ 060 061 public NotificationSupport(Object source) 062 { 063 this.source = source; 064 listeners = new EventListenerList(); 065 } 066 067 /** Add a <code>NotificationListener</code> to this object's list of 068 * listeners. 069 * 070 * @param listener The listener to add. 071 */ 072 073 public void addNotificationListener(NotificationListener listener) 074 { 075 listeners.add(NotificationListener.class, listener); 076 } 077 078 /** Remove a <code>NotificationListener</code> from this object's list of 079 * listeners. 080 * 081 * @param listener The listener to remove. 082 */ 083 084 public void removeNotificationListener(NotificationListener listener) 085 { 086 listeners.remove(NotificationListener.class, listener); 087 } 088 089 /** Fire a <code>NotificationEvent</code> with the specified ID. 090 */ 091 092 public void fireNotificationEvent(int id) 093 { 094 NotificationEvent evt = null; 095 096 Object[] list = listeners.getListenerList(); 097 098 for(int i = list.length - 2; i >= 0; i -= 2) 099 { 100 if(list[i] == NotificationListener.class) 101 { 102 // Lazily create the event: 103 if(evt == null) 104 evt = new NotificationEvent(source, id); 105 ((NotificationListener)list[i + 1]).notificationPerformed(evt); 106 } 107 } 108 } 109 110 } 111 112/* end of source file */