01: package net.suberic.util.swing;
02:
03: import javax.swing.*;
04: import javax.swing.text.*;
05: import java.awt.event.KeyEvent;
06: import java.awt.AWTKeyStroke;
07: import java.awt.KeyboardFocusManager;
08: import java.util.*;
09:
10: /**
11: * This is a subclass of JTextArea which allows for tab field navigation.
12: */
13: public class EntryTextArea extends JTextArea {
14:
15: boolean keysUpdated = false;
16:
17: /**
18: * Constructor; calls super.
19: */
20: public EntryTextArea() {
21: super ();
22: }
23:
24: /**
25: * Constructor; calls super.
26: */
27: public EntryTextArea(Document doc) {
28: super (doc);
29: updateFocusTraversalKeys();
30: }
31:
32: /**
33: * Constructor; calls super.
34: */
35: public EntryTextArea(Document doc, String text, int rows,
36: int columns) {
37: super (doc, text, rows, columns);
38: updateFocusTraversalKeys();
39: }
40:
41: /**
42: * Constructor; calls super.
43: */
44: public EntryTextArea(int rows, int columns) {
45: super (rows, columns);
46: updateFocusTraversalKeys();
47: }
48:
49: /**
50: * Constructor; calls super.
51: */
52: public EntryTextArea(String text) {
53: super (text);
54: updateFocusTraversalKeys();
55: }
56:
57: /**
58: * Constructor; calls super.
59: */
60: public EntryTextArea(String text, int rows, int columns) {
61: super (text, rows, columns);
62: updateFocusTraversalKeys();
63: }
64:
65: /**
66: * updates the focus traversal keys to include tab and shift-tab.
67: */
68: protected void updateFocusTraversalKeys() {
69: if (!keysUpdated) {
70: keysUpdated = true;
71: Set forward = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
72:
73: Set newForward = new HashSet(forward);
74: newForward.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB"));
75:
76: setFocusTraversalKeys(
77: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
78: newForward);
79:
80: Set backward = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
81:
82: Set newBackward = new HashSet(backward);
83: newBackward.add(AWTKeyStroke
84: .getAWTKeyStroke("shift pressed TAB"));
85:
86: setFocusTraversalKeys(
87: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
88: newBackward);
89: }
90: }
91:
92: }
|