package DisplayProject.plaf;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JComponent;
import javax.swing.LayoutFocusTraversalPolicy;
import DisplayProject.actions.SkipOnTab;
import DisplayProject.controls.ArrayField;
import DisplayProject.table.ArrayFieldCellHelper;
/**
* Special focus traversal rules.
*
* @author Craig Mitchell
* @since 01/09/2008 (abstracted from CompoundFieldFactory).
*/
@SuppressWarnings("serial")
public class ForteLayoutFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
private boolean swingDisplayerIgnoreArrayField = false;
@Override
// ITC_CONV:Start:TF:25-Mar-08:Handle SkipOnTab focus traversal
public Component getComponentAfter(Container aContainer, Component aComponent) {
// Traversing out of an ArrayField is handled via code inside the ArrayField. CraigM 29/08/2007.
ArrayField af = ArrayFieldCellHelper.getArrayField(aComponent);
if (af != null && isSwingDisplayerIgnoreArrayField() == false) {
return af; // Stay in the ArrayField
}
Component result = super.getComponentAfter(aContainer, aComponent);
while (result instanceof JComponent && SkipOnTab.get((JComponent)result)) {
if (result == aComponent) {
// We've got a compound field where none of the children are tabbable, return null
return null;
}
result = getComponentAfter(aContainer, result);
}
af = ArrayFieldCellHelper.getArrayField(result);
if (af != null && isSwingDisplayerIgnoreArrayField() == false) {
return af; // Stay in the ArrayField
}
return result;
}
/**
* Override the getComponentBefore method to allow for SkipOnTab
*/
@Override
public Component getComponentBefore(Container container, Component component) {
Component result = super.getComponentBefore(container, component);
while (result instanceof JComponent && SkipOnTab.get((JComponent)result)) {
// We can't allow this field to be tabbed into, go onto the next one
if (result == component) {
// We've got a compound field where none of the children are tabbable, return null
return null;
}
result = getComponentBefore(container, result);
}
return result;
}
/**
* Override the getFirstComponent method to allow for SkipOnTab
*/
@Override
public Component getFirstComponent(Container container) {
Component result = super.getFirstComponent(container);
if (result instanceof JComponent && SkipOnTab.get((JComponent)result)) {
// We can't allow this field to be tabbed into, go onto the next one
return getComponentAfter(container, result);
}
return result;
}
/**
* Override the getLastComponent method to allow for SkipOnTab
*/
@Override
public Component getLastComponent(Container container) {
// CraigM:24/06/2008 - Fixed to call getLastComponent
Component result = super.getLastComponent(container);
if (result instanceof JComponent && SkipOnTab.get((JComponent)result)) {
// We can't allow this field to be tabbed into, go onto the next one
return getComponentBefore(container, result);
}
return result;
}
// ITC_CONV:End:TF:25-Mar-08
public void setSwingDisplayerIgnoreArrayField(boolean swingDisplayerIgnoreArrayField) {
this.swingDisplayerIgnoreArrayField = swingDisplayerIgnoreArrayField;
}
public boolean isSwingDisplayerIgnoreArrayField() {
return swingDisplayerIgnoreArrayField;
}
}