PageRenderTime 60ms CodeModel.GetById 55ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/ShortcutPrefixActiveEvent.java

#
Java | 147 lines | 50 code | 12 blank | 85 comment | 1 complexity | 7c5235f64f5ec44c01b583bd5108418c 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 javax.swing.KeyStroke;
 27import java.awt.event.KeyEvent;
 28import java.awt.event.InputEvent;
 29import java.awt.Toolkit;
 30import java.util.Hashtable;
 31import java.util.StringTokenizer;
 32import org.gjt.sp.jedit.*;
 33import org.gjt.sp.util.Log;
 34import org.gjt.sp.jedit.msg.*;
 35import javax.swing.event.*;
 36//}}}
 37
 38/**
 39 *  Description of the Class
 40 *
 41 *@author     jchoyt
 42 *@created    December 17, 2005
 43 */
 44public class ShortcutPrefixActiveEvent extends ChangeEvent
 45{
 46
 47    /**
 48     *  Description of the Field
 49     */
 50    protected Hashtable bindings;
 51    /**
 52     *  Description of the Field
 53     */
 54    protected boolean active;//}}}
 55
 56        /**
 57     *  Description of the Field
 58     */
 59    protected static EventListenerList listenerList = new EventListenerList();
 60
 61    //{{{  Constructor
 62    /**
 63     *  Constructor for the ShortcutPrefixActiveEvent object
 64     *
 65     *@param  bindings  Description of the Parameter
 66     *@param  active    Description of the Parameter
 67     */
 68    public ShortcutPrefixActiveEvent( Hashtable bindings, boolean active )
 69    {
 70        super( new Object() );
 71        this.bindings = bindings;
 72        this.active = active;
 73	} //}}}
 74
 75    //{{{ addChangeEventListener() method
 76    /**
 77     *  Adds a feature to the ChangeEventListener attribute of the
 78     *  ShortcutPrefixActiveEvent class
 79     *
 80     *@param  l  The feature to be added to the ChangeEventListener attribute
 81     */
 82    public static void addChangeEventListener( ChangeListener l )
 83    {
 84        listenerList.add( ChangeListener.class, l );
 85        Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "Listener added.  " + listenerList.getListenerList().length + " left." );
 86    }//}}}
 87
 88    //{{{ removeChangeEventListener() method
 89    /**
 90     *  Description of the Method
 91     *
 92     *@param  l  Description of the Parameter
 93     */
 94    public static void removeChangeEventListener( ChangeListener l )
 95    {
 96        listenerList.remove( ChangeListener.class, l );
 97        Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "Listener removed.  " + listenerList.getListenerList().length + " left." );
 98    }//}}}
 99
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, boolean listeningForShortcutCompletion )
108    {
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        {
117            //Log.log( Log.DEBUG, ShortcutPrefixActiveEvent.class, "firePrefixStateChange() called, listening? " + listeningForShortcutCompletion );
118            ChangeEvent event = new ShortcutPrefixActiveEvent( bindings, listeningForShortcutCompletion );
119            ( ( ChangeListener ) listeners[i + 1] ).stateChanged( event );
120        }
121    }//}}}
122
123
124    //{{{  getBindings()
125    /**
126     *  Gets the bindings attribute of the ShortcutPrefixActiveEvent object
127     *
128     *@return    The bindings value
129     */
130    public Hashtable getBindings()
131    {
132        return bindings;
133    }//}}}
134
135    //{{{  getActive()
136    /**
137     *  Gets the active attribute of the ShortcutPrefixActiveEvent object
138     *
139     *@return    The active value
140     */
141    public boolean getActive()
142    {
143        return active;
144    }
145    //}}}
146}
147