001: /*
002: * ShortcutPrefixActiveEvent.java - Event fired when jEdit starts and stops
003: * listening for shortcut completions
004: * :tabSize=8:indentSize=8:noTabs=false:
005: * :folding=explicit:collapseFolds=1:
006: *
007: * Copyright (C) 2005 Jeffrey Hoyt
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: */
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import java.util.Hashtable;
027:
028: import javax.swing.event.ChangeEvent;
029: import javax.swing.event.ChangeListener;
030: import javax.swing.event.EventListenerList;
031:
032: import org.gjt.sp.util.Log;
033:
034: //}}}
035:
036: /**
037: * Description of the Class
038: *
039: *@author jchoyt
040: *@created December 17, 2005
041: */
042: public class ShortcutPrefixActiveEvent extends ChangeEvent {
043:
044: /**
045: * Description of the Field
046: */
047: protected Hashtable bindings;
048: /**
049: * Description of the Field
050: */
051: protected boolean active;
052:
053: /**
054: * Description of the Field
055: */
056: protected static EventListenerList listenerList = new EventListenerList();
057:
058: //{{{ Constructor
059: /**
060: * Constructor for the ShortcutPrefixActiveEvent object
061: *
062: * @param bindings Description of the Parameter
063: * @param active Description of the Parameter
064: */
065: public ShortcutPrefixActiveEvent(Hashtable bindings, boolean active) {
066: super (new Object());
067: this .bindings = bindings;
068: this .active = active;
069: } //}}}
070:
071: //{{{ addChangeEventListener() method
072: /**
073: * Adds a feature to the ChangeEventListener attribute of the
074: * ShortcutPrefixActiveEvent class
075: *
076: * @param l The feature to be added to the ChangeEventListener attribute
077: */
078: public static void addChangeEventListener(ChangeListener l) {
079: listenerList.add(ChangeListener.class, l);
080: Log.log(Log.DEBUG, ShortcutPrefixActiveEvent.class,
081: "Listener added. "
082: + listenerList.getListenerList().length
083: + " left.");
084: }//}}}
085:
086: //{{{ removeChangeEventListener() method
087: /**
088: * Description of the Method
089: *
090: * @param l Description of the Parameter
091: */
092: public static void removeChangeEventListener(ChangeListener l) {
093: listenerList.remove(ChangeListener.class, l);
094: Log.log(Log.DEBUG, ShortcutPrefixActiveEvent.class,
095: "Listener removed. "
096: + listenerList.getListenerList().length
097: + " left.");
098: }//}}}
099:
100: //{{{ firePrefixStateChange() method
101: /**
102: * Description of the Method
103: *
104: * @param bindings Description of the Parameter
105: * @param listeningForShortcutCompletion Description of the Parameter
106: */
107: protected static void firePrefixStateChange(Hashtable bindings,
108: boolean listeningForShortcutCompletion) {
109: //Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "firePrefixStateChange() called, listening? " + listeningForShortcutCompletion );
110: // Guaranteed to return a non-null array
111: Object[] listeners = listenerList.getListenerList();
112: //Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, listeners.length + " listeners." );
113: // Process the listeners last to first, notifying
114: // those that are interested in this event
115: for (int i = listeners.length - 2; i >= 0; i -= 2) {
116: //Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "firePrefixStateChange() called, listening? " + listeningForShortcutCompletion );
117: ChangeEvent event = new ShortcutPrefixActiveEvent(bindings,
118: listeningForShortcutCompletion);
119: ((ChangeListener) listeners[i + 1]).stateChanged(event);
120: }
121: }//}}}
122:
123: //{{{ getBindings()
124: /**
125: * Gets the bindings attribute of the ShortcutPrefixActiveEvent object
126: *
127: * @return The bindings value
128: */
129: public Hashtable getBindings() {
130: return bindings;
131: }//}}}
132:
133: //{{{ getActive()
134: /**
135: * Gets the active attribute of the ShortcutPrefixActiveEvent object
136: *
137: * @return The active value
138: */
139: public boolean getActive() {
140: return active;
141: }
142: //}}}
143: }
|