1package org.sleuthkit.autopsy.guicomponentutils;
3import java.awt.event.ActionEvent;
4import java.awt.event.ActionListener;
5import java.awt.event.FocusAdapter;
6import java.awt.event.FocusEvent;
7import java.awt.event.FocusListener;
8import java.awt.event.KeyAdapter;
9import java.awt.event.KeyEvent;
10import java.awt.event.KeyListener;
11import java.beans.PropertyChangeEvent;
12import java.beans.PropertyChangeListener;
13import javax.swing.ComboBoxEditor;
14import javax.swing.ComboBoxModel;
15import javax.swing.JComboBox;
16import javax.swing.text.AttributeSet;
17import javax.swing.text.BadLocationException;
18import javax.swing.text.JTextComponent;
19import javax.swing.text.PlainDocument;
49 comboBox.addActionListener(
new ActionListener() {
51 public void actionPerformed(ActionEvent e) {
57 comboBox.addPropertyChangeListener(
new PropertyChangeListener() {
59 public void propertyChange(PropertyChangeEvent e) {
60 if (e.getPropertyName().equals(
"editor")) {
61 configureEditor((ComboBoxEditor) e.getNewValue());
63 if (e.getPropertyName().equals(
"model")) {
64 model = (ComboBoxModel) e.getNewValue();
70 public void keyPressed(KeyEvent e) {
75 switch (e.getKeyCode()) {
77 case KeyEvent.VK_BACK_SPACE:
82 case KeyEvent.VK_DELETE:
94 public void focusGained(FocusEvent e) {
99 public void focusLost(FocusEvent e) {
106 configureEditor(
comboBox.getEditor());
108 Object selected =
comboBox.getSelectedItem();
109 if (selected !=
null) {
122 void configureEditor(ComboBoxEditor newEditor) {
128 if (newEditor !=
null) {
129 editor = (JTextComponent) newEditor.getEditorComponent();
136 public void remove(
int offs,
int len)
throws BadLocationException {
154 super.remove(offs, len);
159 public void insertString(
int offs, String str, AttributeSet a)
throws BadLocationException {
165 super.insertString(offs, str, a);
167 Object item =
lookupItem(getText(0, getLength()));
174 offs = offs - str.length();
186 super.remove(0, getLength());
187 super.insertString(0, text,
null);
188 }
catch (BadLocationException e) {
189 throw new RuntimeException(e.toString());
194 editor.setCaretPosition(getLength());
195 editor.moveCaretPosition(start);
200 model.setSelectedItem(item);
205 Object selectedItem =
model.getSelectedItem();
211 for (
int i = 0, n =
model.getSize(); i < n; i++) {
212 Object currentItem =
model.getElementAt(i);
225 return str1.toUpperCase().startsWith(str2.toUpperCase());
void setSelectedItem(Object item)
static final long serialVersionUID
void setText(String text)
AutoCompletion(final JComboBox<?> comboBox)
void insertString(int offs, String str, AttributeSet a)
static void enable(JComboBox<?> comboBox)
KeyListener editorKeyListener
boolean hitBackspaceOnSelection
FocusListener editorFocusListener
void highlightCompletedText(int start)
boolean hidePopupOnFocusLoss
Object lookupItem(String pattern)
boolean startsWithIgnoreCase(String str1, String str2)