📄 afocustraversalpolicy.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps;
import java.awt.*;
import javax.swing.*;
import org.compiere.swing.*;
/**
* Compiere Application Focus Traversal Policy
*
* @author Jorg Janke
* @version $Id: AFocusTraversalPolicy.java,v 1.3 2002/08/12 01:55:13 danb Exp $
*/
public class AFocusTraversalPolicy extends LayoutFocusTraversalPolicy
{
/**
* Get singleton
* @return AFocusTraversalPolicy
*/
public static AFocusTraversalPolicy get()
{
if (s_policy == null)
s_policy = new AFocusTraversalPolicy();
return s_policy;
} // get
/** Default Policy */
private static AFocusTraversalPolicy s_policy = new AFocusTraversalPolicy();
/*************************************************************************/
/**
* Constructor
*/
public AFocusTraversalPolicy ()
{
super();
} // AFocusTraversalPolicy
/**
* Returns the first Component in the traversal cycle. This method is used
* to determine the next Component to focus when traversal wraps in the
* forward direction.
*
* @param focusCycleRoot the focus cycle root whose first Component is to
* be returned
* @return the first Component in the traversal cycle when focusCycleRoot
* is the focus cycle root, or null if no suitable Component can be
* found
* @throws IllegalArgumentException if focusCycleRoot is null
*/
public Component getFirstComponent(Container focusCycleRoot)
{
Component c = super.getFirstComponent(focusCycleRoot);
// info ("Root: ", focusCycleRoot);
// info (" First: ", c);
return c;
} // getFirstComponent
/**
* Returns the Component that should receive the focus after aComponent.
* focusCycleRoot must be a focus cycle root of aComponent.
* <p>
* By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
* cycle. That is, during normal focus traversal, the Component
* traversed after a focus cycle root will be the focus-cycle-root's
* default Component to focus. This behavior can be disabled using the
* <code>setImplicitDownCycleTraversal</code> method.
*
* @param focusCycleRoot a focus cycle root of aComponent
* @param aComponent a (possibly indirect) child of focusCycleRoot, or
* focusCycleRoot itself
* @return the Component that should receive the focus after aComponent, or
* null if no suitable Component can be found
* @throws IllegalArgumentException if focusCycleRoot is not a focus cycle
* root of aComponent, or if either focusCycleRoot or aComponent is
* null
*/
public Component getComponentAfter(Container focusCycleRoot, Component aComponent)
{
Component c = super.getComponentAfter(focusCycleRoot, aComponent);
return c;
}
/**
* Returns the Component that should receive the focus before aComponent.
* focusCycleRoot must be a focus cycle root of aComponent.
* <p>
* By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
* cycle. That is, during normal focus traversal, the Component
* traversed after a focus cycle root will be the focus-cycle-root's
* default Component to focus. This behavior can be disabled using the
* <code>setImplicitDownCycleTraversal</code> method.
*
* @param focusCycleRoot a focus cycle root of aComponent
* @param aComponent a (possibly indirect) child of focusCycleRoot, or
* focusCycleRoot itself
* @return the Component that should receive the focus before aComponent,
* or null if no suitable Component can be found
* @throws IllegalArgumentException if focusCycleRoot is not a focus cycle
* root of aComponent, or if either focusCycleRoot or aComponent is
* null
*/
public Component getComponentBefore(Container focusCycleRoot, Component aComponent)
{
Component c = super.getComponentBefore(focusCycleRoot, aComponent);
return c;
}
/**
* Returns the last Component in the traversal cycle. This method is used
* to determine the next Component to focus when traversal wraps in the
* reverse direction.
*
* @param focusCycleRoot the focus cycle root whose last Component is to be
* returned
* @return the last Component in the traversal cycle when focusCycleRoot is
* the focus cycle root, or null if no suitable Component can be
* found
* @throws IllegalArgumentException if focusCycleRoot is null
*/
public Component getLastComponent(Container focusCycleRoot)
{
Component c = super.getLastComponent(focusCycleRoot);
return c;
}
/**
* Determines whether the specified <code>Component</code>
* is an acceptable choice as the new focus owner.
* This method performs the following sequence of operations:
* <ol>
* <li>Checks whether <code>aComponent</code> is visible, displayable,
* enabled, and focusable. If any of these properties is
* <code>false</code>, this method returns <code>false</code>.
* <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
* returns <code>true</code>.
* <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
* then returns the value of
* <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
* <li>If <code>aComponent</code> is a <code>JComponent</code>
* with a <code>JComponent.WHEN_FOCUSED</code>
* <code>InputMap</code> that is neither <code>null</code>
* nor empty, returns <code>true</code>.
* <li>Returns the value of
* <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
* </ol>
*
* @param aComponent the <code>Component</code> whose fitness
* as a focus owner is to be tested
* @see java.awt.Component#isVisible
* @see java.awt.Component#isDisplayable
* @see java.awt.Component#isEnabled
* @see java.awt.Component#isFocusable
* @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
* @see javax.swing.JComponent#getInputMap
* @see java.awt.DefaultFocusTraversalPolicy#accept
* @return <code>true</code> if <code>aComponent</code> is a valid choice
* for a focus owner;
* otherwise <code>false</code>
*/
protected boolean accept(Component aComponent)
{
if (!super.accept(aComponent))
return false;
// TabbedPane
if (aComponent instanceof JTabbedPane)
return false;
// R/O Editors
if (aComponent instanceof CEditor)
{
CEditor ed = (CEditor)aComponent;
if (!ed.isReadWrite())
return false;
}
// Toolbar Buttons
if (aComponent.getParent() instanceof JToolBar)
return false;
//
return true;
} // accept
/*************************************************************************/
/**
* Dump info
* @param title
* @param c
*/
private void info (String title, Component c)
{
System.out.print (title);
System.out.print (c.getClass().getName());
System.out.println (" - " + c.getName());
} // info
} // AFocusTraversalPolicy
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -