1 19 20 package org.netbeans.lib.editor.codetemplates; 21 22 import java.awt.event.InputEvent ; 23 import java.awt.event.KeyEvent ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import javax.swing.KeyStroke ; 28 import org.netbeans.api.editor.mimelookup.MimeLookup; 29 import org.netbeans.api.editor.settings.CodeTemplateSettings; 30 import org.netbeans.api.editor.settings.KeyBindingSettings; 31 import org.netbeans.api.editor.settings.MultiKeyBinding; 32 import org.netbeans.editor.BaseKit; 33 import org.openide.util.Lookup; 34 import org.openide.util.LookupEvent; 35 import org.openide.util.LookupListener; 36 import org.openide.util.WeakListeners; 37 38 44 45 final class AbbrevSettings implements LookupListener { 46 47 private static final KeyStroke DEFAULT_EXPANSION_KEYSTROKE = KeyStroke.getKeyStroke(' '); 48 49 private static final Map mimeType2settings = new HashMap (); 50 51 public static synchronized AbbrevSettings get(String mimeType) { 52 AbbrevSettings settings = (AbbrevSettings)mimeType2settings.get(mimeType); 53 if (settings == null) { 54 settings = new AbbrevSettings(mimeType); 55 mimeType2settings.put(mimeType, settings); 56 } 57 return settings; 58 } 59 60 public static KeyStroke getDefaultExpansionKeyStroke() { 61 return DEFAULT_EXPANSION_KEYSTROKE; 62 } 63 64 65 private Lookup.Result codeTemplateSettingsLookupResult; 66 67 69 private KeyStroke expandKeyStroke; 70 71 72 AbbrevSettings(String mimeType) { 73 MimeLookup mimeLookup = MimeLookup.getMimeLookup(mimeType); 74 75 codeTemplateSettingsLookupResult = mimeLookup.lookup( 76 new Lookup.Template(CodeTemplateSettings.class)); 77 codeTemplateSettingsLookupResult.addLookupListener( 78 (LookupListener)WeakListeners.create(LookupListener.class, this, mimeLookup)); 79 80 86 87 resultChanged(null); } 89 90 public KeyStroke getExpandKeyStroke() { 91 KeyStroke eks = org.netbeans.modules.editor.options.BaseOptions.getCodeTemplateExpandKey(); 93 if (eks == null) { 94 eks = getDefaultExpansionKeyStroke(); 95 } 96 eks = patchExpandKeystroke(eks); 97 return eks; 98 } 99 100 public String getExpandKeyStrokeText() { 101 KeyStroke expandKeyStroke = getExpandKeyStroke(); 102 String expandKeyStrokeText; 103 if (expandKeyStroke.equals(KeyStroke.getKeyStroke(' '))) { 104 expandKeyStrokeText = "SPACE"; } else if (expandKeyStroke.equals(KeyStroke.getKeyStroke(new Character (' '), InputEvent.SHIFT_MASK))) { 106 expandKeyStrokeText = "Shift-SPACE"; } else if (expandKeyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) { 108 expandKeyStrokeText = "TAB"; } else if (expandKeyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) { 110 expandKeyStrokeText = "ENTER"; } else { 112 expandKeyStrokeText = expandKeyStroke.toString(); 113 } 114 return expandKeyStrokeText; 115 } 116 117 public void resultChanged(LookupEvent ev) { 118 121 129 130 135 } 136 137 private KeyStroke patchExpandKeystroke(KeyStroke eks) { 138 if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0))) { 140 eks = KeyStroke.getKeyStroke(' '); 141 } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK))) { 142 eks = KeyStroke.getKeyStroke(new Character (' '), InputEvent.SHIFT_MASK); 143 } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) { 144 } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) { 145 } 146 return eks; 147 } 148 149 150 151 } 152 | Popular Tags |