PageRenderTime 27ms CodeModel.GetById 19ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/ShortcutPrefixActiveEvent.java

#
Java | 144 lines | 45 code | 14 blank | 85 comment | 1 complexity | 37562b1fa0735987ed6d5fc6e8b458aa MD5 | raw file
  1/*
  2 *  ShortcutPrefixActiveEvent.java - Event fired when jEdit starts and stops
  3 *  listening for shortcut completions
  4 *  :tabSize=8:indentSize=8:noTabs=false:
  5 *  :folding=explicit:collapseFolds=1:
  6 *
  7 *  Copyright (C) 2005 Jeffrey Hoyt
  8 *
  9 *  This program is free software; you can redistribute it and/or
 10 *  modify it under the terms of the GNU General Public License
 11 *  as published by the Free Software Foundation; either version 2
 12 *  of the License, or any later version.
 13 *
 14 *  This program is distributed in the hope that it will be useful,
 15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 *  GNU General Public License for more details.
 18 *
 19 *  You should have received a copy of the GNU General Public License
 20 *  along with this program; if not, write to the Free Software
 21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 22 */
 23package org.gjt.sp.jedit.gui;
 24
 25//{{{ Imports
 26import java.util.Hashtable;
 27
 28import javax.swing.event.ChangeEvent;
 29import javax.swing.event.ChangeListener;
 30import javax.swing.event.EventListenerList;
 31
 32import org.gjt.sp.util.Log;
 33//}}}
 34
 35/**
 36 *  Description of the Class
 37 *
 38 * @author     jchoyt
 39 * created    December 17, 2005
 40 */
 41public class ShortcutPrefixActiveEvent extends ChangeEvent
 42{
 43
 44	/**
 45	 * Description of the Field
 46	 */
 47	protected Hashtable bindings;
 48	/**
 49	 * Description of the Field
 50	 */
 51	protected boolean active;
 52
 53	/**
 54	 * Description of the Field
 55	 */
 56	protected static EventListenerList listenerList = new EventListenerList();
 57
 58	//{{{  Constructor
 59	/**
 60	 * Constructor for the ShortcutPrefixActiveEvent object
 61	 *
 62	 * @param bindings Description of the Parameter
 63	 * @param active   Description of the Parameter
 64	 */
 65	public ShortcutPrefixActiveEvent(Hashtable bindings, boolean active)
 66	{
 67		super(new Object());
 68		this.bindings = bindings;
 69		this.active = active;
 70	} //}}}
 71
 72	//{{{ addChangeEventListener() method
 73	/**
 74	 * Adds a feature to the ChangeEventListener attribute of the
 75	 * ShortcutPrefixActiveEvent class
 76	 *
 77	 * @param l The feature to be added to the ChangeEventListener attribute
 78	 */
 79	public static void addChangeEventListener(ChangeListener l)
 80	{
 81		listenerList.add(ChangeListener.class, l);
 82		Log.log(Log.DEBUG, ShortcutPrefixActiveEvent.class, "Listener added.  " + listenerList.getListenerList().length + " left.");
 83	}//}}}
 84
 85	//{{{ removeChangeEventListener() method
 86	/**
 87	 * Description of the Method
 88	 *
 89	 * @param l Description of the Parameter
 90	 */
 91	public static void removeChangeEventListener(ChangeListener l)
 92	{
 93		listenerList.remove(ChangeListener.class, l);
 94		Log.log(Log.DEBUG, ShortcutPrefixActiveEvent.class, "Listener removed.  " + listenerList.getListenerList().length + " left.");
 95	}//}}}
 96
 97	//{{{ firePrefixStateChange() method
 98	/**
 99	 * Description of the Method
100	 *
101	 * @param bindings                       Description of the Parameter
102	 * @param listeningForShortcutCompletion Description of the Parameter
103	 */
104	public static void firePrefixStateChange(Hashtable bindings, boolean listeningForShortcutCompletion)
105	{
106		//Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "firePrefixStateChange() called, listening? " + listeningForShortcutCompletion );
107		// Guaranteed to return a non-null array
108		Object[] listeners = listenerList.getListenerList();
109		//Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, listeners.length + " listeners." );
110		// Process the listeners last to first, notifying
111		// those that are interested in this event
112		for (int i = listeners.length - 2; i >= 0; i -= 2)
113		{
114			//Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "firePrefixStateChange() called, listening? " + listeningForShortcutCompletion );
115			ChangeEvent event = new ShortcutPrefixActiveEvent(bindings, listeningForShortcutCompletion);
116			((ChangeListener) listeners[i + 1]).stateChanged(event);
117		}
118	}//}}}
119
120
121	//{{{  getBindings()
122	/**
123	 * Gets the bindings attribute of the ShortcutPrefixActiveEvent object
124	 *
125	 * @return The bindings value
126	 */
127	public Hashtable getBindings()
128	{
129		return bindings;
130	}//}}}
131
132	//{{{  getActive()
133	/**
134	 * Gets the active attribute of the ShortcutPrefixActiveEvent object
135	 *
136	 * @return The active value
137	 */
138	public boolean getActive()
139	{
140		return active;
141	}
142	//}}}
143}
144