KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > input > AbstractInputHandler


1 /*
2  * ServiceManager.java - Handles services.xml files in plugins
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2006 Matthieu Casanova
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22 package org.gjt.sp.jedit.input;
23
24 import org.gjt.sp.jedit.gui.KeyEventTranslator;
25 import org.gjt.sp.jedit.Debug;
26 import org.gjt.sp.util.Log;
27
28 import java.awt.event.KeyListener JavaDoc;
29 import java.awt.event.KeyEvent JavaDoc;
30
31 /**
32  * @author Matthieu Casanova
33  * @version $Id: FoldHandler.java 5568 2006-07-10 20:52:23Z kpouer $
34  */

35 public abstract class AbstractInputHandler
36 {
37     protected int lastActionCount;
38     protected KeyListener JavaDoc keyEventInterceptor;
39     protected String JavaDoc readNextChar;
40     protected int repeatCount;
41     //{{{ Protected members
42
protected static final int REPEAT_COUNT_THRESHOLD = 20;
43
44     public AbstractInputHandler()
45     {
46         repeatCount = 1;
47     }
48
49     //{{{ getLastActionCount() method
50
/**
51      * Returns the number of times the last action was executed.
52      * @since jEdit 2.5pre5
53      */

54     public int getLastActionCount()
55     {
56         return lastActionCount;
57     } //}}}
58

59     //{{{ resetLastActionCount() method
60
/**
61      * Resets the last action count. This should be called when an
62      * editing operation that is not an action is invoked, for example
63      * a mouse click.
64      * @since jEdit 4.0pre1
65      */

66     public void resetLastActionCount()
67     {
68         lastActionCount = 0;
69     } //}}}
70

71     public KeyListener JavaDoc getKeyEventInterceptor()
72     {
73         return keyEventInterceptor;
74     }
75
76     public void setKeyEventInterceptor(KeyListener JavaDoc keyEventInterceptor)
77     {
78         this.keyEventInterceptor = keyEventInterceptor;
79     }
80
81     //{{{ isPrefixActive() method
82
/**
83      * Returns if a prefix key has been pressed.
84      */

85     public boolean isPrefixActive()
86     {
87         return readNextChar != null;
88     } //}}}
89

90     //{{{ handleKey() method
91
/**
92      * Handles a keystroke.
93      * @param keyStroke The key stroke.
94      * @param dryRun only calculate the return value, do not have any other effect
95      * @return true if the input could be handled.
96      * @since jEdit 4.3pre7
97      */

98     public abstract boolean handleKey(KeyEventTranslator.Key keyStroke,boolean dryRun);
99     //}}}
100

101     public abstract void processKeyEvent(KeyEvent JavaDoc evt, int from, boolean global);
102
103     //{{{ processKeyEventKeyStrokeHandling() method
104
protected void processKeyEventKeyStrokeHandling(KeyEvent JavaDoc evt,int from,String JavaDoc mode,boolean global)
105     {
106         KeyEventTranslator.Key keyStroke = KeyEventTranslator.translateKeyEvent2(evt);
107
108         if(keyStroke != null)
109         {
110             keyStroke.setIsFromGlobalContext(global);
111             if(Debug.DUMP_KEY_EVENTS)
112             {
113                 Log.log(Log.DEBUG,this,"Translated (key "+mode+"): "+keyStroke+" from "+from);
114             }
115             boolean consumed = false;
116             if(handleKey(keyStroke,keyStroke.isPhantom())) {
117                 evt.consume();
118
119                 consumed = true;
120             }
121             if(Debug.DUMP_KEY_EVENTS)
122             {
123                 Log.log(Log.DEBUG,this,"Translated (key "+mode+"): "+keyStroke+" from "+from+": consumed="+consumed+'.');
124             }
125         }
126     } //}}}
127
}
128
Popular Tags