1 4 package org.columba.mail.gui.composer; 5 6 import java.util.List ; 7 import java.util.regex.Pattern ; 8 9 import javax.swing.text.BadLocationException ; 10 import javax.swing.text.Document ; 11 import javax.swing.text.JTextComponent ; 12 13 import org.frapuccino.addresscombobox.PatternSeparatedAutoCompleter; 14 import org.frapuccino.addresscombobox.TextParser; 15 16 20 public class EmailNameAutoCompleter extends PatternSeparatedAutoCompleter { 21 22 28 public EmailNameAutoCompleter(JTextComponent comp, List completionList, Pattern separatorPattern, boolean ignoreCase) { 29 super(comp, completionList, separatorPattern, ignoreCase); 30 } 31 32 35 @Override 36 protected void acceptedListItem(Object selected) { 37 if (selected == null) 38 return; 39 40 int caret = textComp.getCaretPosition(); 41 String value = TextParser.getItemAt(textComp.getText(), separatorPattern, textComp 42 .getCaretPosition()); 43 44 try { 45 Document doc = textComp.getDocument(); 46 value = value.trim(); 48 int startingPos = caret - value.length(); 49 doc.remove(startingPos, value.length()); 50 51 String selectedStr = selected.toString(); 53 String sep = separatorPattern.toString(); 54 if (selectedStr.contains(sep)) 55 selectedStr = '"' + selectedStr + '"'; 56 textComp.getDocument().insertString(startingPos, selectedStr + separatorPattern.toString() +" ", null); 57 } catch (BadLocationException e) { 58 e.printStackTrace(); 59 } 60 61 popup.setVisible(false); 62 } 63 64 } 65 | Popular Tags |