01: /*
02: * CompletionSearchField.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.completion;
13:
14: import java.awt.Color;
15: import java.awt.event.KeyEvent;
16: import java.awt.event.KeyListener;
17: import javax.swing.BorderFactory;
18: import javax.swing.JTextField;
19: import javax.swing.event.DocumentEvent;
20: import javax.swing.event.DocumentListener;
21:
22: /**
23: * A quick search field for the auto completion popup
24: *
25: * @author support@sql-workbench.net
26: */
27: public class CompletionSearchField extends JTextField implements
28: KeyListener, DocumentListener {
29: private CompletionPopup parent;
30:
31: public CompletionSearchField(CompletionPopup popup, String text) {
32: super (text);
33: this .parent = popup;
34: this .setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
35: this .addKeyListener(this );
36: this .getDocument().addDocumentListener(this );
37: }
38:
39: public void keyTyped(KeyEvent e) {
40: }
41:
42: public void keyPressed(KeyEvent e) {
43: if (e.getKeyCode() == KeyEvent.VK_ENTER) {
44: e.consume();
45: parent.quickSearchValueSelected();
46: } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
47: e.consume();
48: this .parent.closeQuickSearch();
49: } else if (e.getKeyCode() == KeyEvent.VK_DOWN
50: || e.getKeyCode() == KeyEvent.VK_UP) {
51: parent.keyPressed(e);
52: }
53: }
54:
55: public void keyReleased(KeyEvent e) {
56: }
57:
58: public void insertUpdate(DocumentEvent e) {
59: this .parent.selectMatchingEntry(this .getText());
60: }
61:
62: public void removeUpdate(DocumentEvent e) {
63: this .parent.selectMatchingEntry(this .getText());
64: }
65:
66: public void changedUpdate(DocumentEvent e) {
67: this.parent.selectMatchingEntry(this.getText());
68: }
69:
70: }
|