Package net.helipilot50.stocktrade.displayproject.plaf

Source Code of net.helipilot50.stocktrade.displayproject.plaf.ForteLayoutFocusTraversalPolicy

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package net.helipilot50.stocktrade.displayproject.plaf;

import java.awt.Component;
import java.awt.Container;

import javax.swing.JComponent;
import javax.swing.LayoutFocusTraversalPolicy;

import net.helipilot50.stocktrade.displayproject.actions.SkipOnTab;
import net.helipilot50.stocktrade.displayproject.controls.ArrayField;
import net.helipilot50.stocktrade.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;
  }
}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.plaf.ForteLayoutFocusTraversalPolicy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.