Methods Summary |
---|
public void | focusNextComponent(java.awt.Component c)
Vector v = new Vector();
Hashtable list = getAllComponentsAtThisLevel(c, v);
String buttonText;
if (list != null) {
if (c instanceof JButton) {
JButton button = (JButton)c;
int currentIndex = v.indexOf(button.getText()) + 1;
if (currentIndex >= v.size())
buttonText = (String)v.firstElement();
else
buttonText = (String)v.elementAt(currentIndex);
JButton b = (JButton)list.get(buttonText);
b.grabFocus();
}
}
|
public void | focusPreviousComponent(java.awt.Component c)
Vector v = new Vector();
Hashtable list = getAllComponentsAtThisLevel(c, v);
String buttonText;
if (list != null) {
if (c instanceof JButton) {
JButton button = (JButton)c;
int currentIndex = v.indexOf(button.getText()) - 1;
if (currentIndex < 0)
buttonText = (String)v.lastElement();
else
buttonText = (String)v.elementAt(currentIndex);
JButton b = (JButton)list.get(buttonText);
b.grabFocus();
}
}
|
public java.util.Hashtable | getAllComponentsAtThisLevel(java.awt.Component c, java.util.Vector v)
Container cont = c.getParent();
if (cont == null)
return null;
Hashtable h = new Hashtable();
Component[] components = cont.getComponents();
v.removeAllElements();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof JButton) {
JButton button = (JButton)components[i];
v.addElement(button.getText());
h.put(button.getText(), button);
}
}
sortVector(v);
return h;
|
public void | processKeyEvent(java.awt.Component focusedComponent, java.awt.event.KeyEvent event)
if (event.getKeyCode() == KeyEvent.VK_TAB) {
// We are only interested in key presses, not key releases
if (event.getID() != KeyEvent.KEY_PRESSED) {
event.consume();
} else {
// If the user pressed SHIFT, then go to the previous
// component. Otherwise, go to the next component.
if ((event.getModifiers() & ActionEvent.SHIFT_MASK) ==
ActionEvent.SHIFT_MASK)
focusPreviousComponent(focusedComponent);
else
focusNextComponent(focusedComponent);
event.consume();
}
}
|
private void | sortVector(java.util.Vector v)
Collator c = Collator.getInstance();
int length = v.size();
// Sort the vector of strings using a standard sort
for (int i = 0; i < length; i++) {
for (int j = length-1; j >= i+1; j--) {
if (c.compare((String)v.elementAt(j-1),
(String)v.elementAt(j)) == 1) {
String temp = (String)v.elementAt(j);
v.setElementAt(v.elementAt(j-1),j);
v.setElementAt(temp, j-1);
}
}
}
|