예제 #1
0
 @Override
 public void keyTyped(KeyEvent e) {
   Character typed = e.getKeyChar();
   switch (typed) {
     case KeyEvent.VK_BACK_SPACE:
       if (input.length() > 0) {
         input.deleteCharAt(input.length() - 1);
         if (!Words.isDictionaryWord(input.toString()))
           suggestion = Words.ending(input.toString());
         else suggestion = "";
       }
       word = null;
       break;
     case KeyEvent.VK_ENTER:
       if (suggestion != null && suggestion.length() > 0) {
         input.append(suggestion);
         suggestion = "";
       }
       word = Words.getWord(input.toString());
       break;
     case KeyEvent.VK_TAB:
       previous = mode;
       previousSet = System.currentTimeMillis();
       mode = Theme.next(mode);
       break;
   }
   if (allowed.matcher(typed.toString()).matches()) {
     input.append(typed);
     String focus = input.substring(input.lastIndexOf(" ") + 1);
     word = Words.getWord(focus);
     suggestion = word == null ? Words.ending(focus) : "";
   }
 }