1 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 ; 29 import java.awt.event.KeyEvent ; 30 31 35 public abstract class AbstractInputHandler 36 { 37 protected int lastActionCount; 38 protected KeyListener keyEventInterceptor; 39 protected String readNextChar; 40 protected int repeatCount; 41 protected static final int REPEAT_COUNT_THRESHOLD = 20; 43 44 public AbstractInputHandler() 45 { 46 repeatCount = 1; 47 } 48 49 54 public int getLastActionCount() 55 { 56 return lastActionCount; 57 } 59 66 public void resetLastActionCount() 67 { 68 lastActionCount = 0; 69 } 71 public KeyListener getKeyEventInterceptor() 72 { 73 return keyEventInterceptor; 74 } 75 76 public void setKeyEventInterceptor(KeyListener keyEventInterceptor) 77 { 78 this.keyEventInterceptor = keyEventInterceptor; 79 } 80 81 85 public boolean isPrefixActive() 86 { 87 return readNextChar != null; 88 } 90 98 public abstract boolean handleKey(KeyEventTranslator.Key keyStroke,boolean dryRun); 99 101 public abstract void processKeyEvent(KeyEvent evt, int from, boolean global); 102 103 protected void processKeyEventKeyStrokeHandling(KeyEvent evt,int from,String 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 } } 128 | Popular Tags |