1 package SnowMailClient.keyboard; 2 3 import java.util.*; 4 5 7 public class KeyboardMap 8 { 9 protected final Vector<KeyboardKey> keys = new Vector<KeyboardKey>(); 10 private String name = ""; 11 private int columnCount; 12 13 public Vector<KeyboardKey> getKeys() { return keys; } 14 public final int getColumnCount() { return columnCount; } 15 public final String getName() { return name; } 16 17 19 public int getVisibleKeys() { return keys.size(); } 21 23 public String getCharset() { return "utf-8"; } 24 25 public KeyboardMap(String name, int columnCount) 26 { 27 this.name = name; 28 this.columnCount = columnCount; 29 } 30 31 public Vector<Object > getVectorRepresentation() 32 { 33 Vector<Object > rep = new Vector<Object >(); 34 rep.addElement(1); rep.addElement(name); rep.addElement(columnCount); Vector<Object > keysRep = new Vector<Object >(); 38 rep.addElement(keysRep); for(KeyboardKey key: keys) 40 { 41 keysRep.addElement(key.getVectorRepresentation()); 42 } 43 return rep; 44 } 45 46 public void createFromVectorRepresentation(Vector<Object > rep) 47 { 48 int version = (Integer ) rep.elementAt(0); 49 name = (String ) rep.elementAt(1); 50 columnCount = (Integer ) rep.elementAt(2); 51 @SuppressWarnings ("unchecked") 52 Vector<Vector<Object >> keysRep = (Vector<Vector<Object >>) rep.elementAt(3); 53 keys.clear(); 54 for(Vector<Object > krep: keysRep) 55 { 56 keys.add(new KeyboardKey(krep)); 57 } 58 } 59 60 61 public Vector<KeyboardKey> getKeyStartingWithShortcut(String _s) 62 { 63 Vector<KeyboardKey> rep = new Vector<KeyboardKey>(); 64 if(_s.length()==0) return rep; 65 66 String s = _s; 68 if(Character.isUpperCase(_s.charAt(0))) 69 { 70 s = _s.toUpperCase(); 71 for(KeyboardKey k:keys) 72 { 73 for(String sc: k.getAllShortcuts()) 74 { 75 if(sc.toUpperCase().startsWith(s)) 76 { 77 rep.addElement(k); 78 k.matchCapital = true; 79 break; } 81 } 82 } 83 } 84 else 85 { 86 s = _s.toLowerCase(); 87 for(KeyboardKey k:keys) 88 { 89 for(String sc: k.getAllShortcuts()) 90 { 91 if(sc.toLowerCase().startsWith(s)) 92 { 93 rep.addElement(k); 94 k.matchCapital = false; 95 break; } 97 } 98 } 99 } 100 101 if(rep.size()>0) return rep; 103 return rep; 104 } 105 106 107 public KeyboardKey getKeyWithShortcut(String _s) 108 { 109 if(_s.length()==0) return null; 110 111 String s = _s; 113 if(Character.isUpperCase(_s.charAt(0))) 114 { 115 String supper = _s.toUpperCase(); 117 118 for(KeyboardKey k:keys) 119 { 120 for(String sc: k.getAllShortcuts()) 121 { 122 if(sc.toUpperCase().equals(supper)) 123 { 124 k.matchCapital = true; 125 return k; 126 } 127 } 128 } 129 130 } 131 else 132 { 133 String slow = _s.toLowerCase(); 135 136 for(KeyboardKey k:keys) 137 { 138 for(String sc: k.getAllShortcuts()) 139 { 140 if(sc.toLowerCase().equals(slow)) 141 { 142 k.matchCapital = false; 143 return k; 144 } 145 } 146 } 147 } 148 149 150 return null; 151 } 152 153 public String toString() { return this.getName(); } 154 155 } | Popular Tags |