KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > AFocusTraversalPolicy


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import org.compiere.swing.*;
19
20 /**
21  * Compiere Application Focus Traversal Policy
22  *
23  * @author Jorg Janke
24  * @version $Id: AFocusTraversalPolicy.java,v 1.3 2002/08/12 01:55:13 danb Exp $
25  */

26 public class AFocusTraversalPolicy extends LayoutFocusTraversalPolicy
27 {
28     /**
29      * Get singleton
30      * @return AFocusTraversalPolicy
31      */

32     public static AFocusTraversalPolicy get()
33     {
34         if (s_policy == null)
35             s_policy = new AFocusTraversalPolicy();
36         return s_policy;
37     } // get
38

39     /** Default Policy */
40     private static AFocusTraversalPolicy s_policy = new AFocusTraversalPolicy();
41
42     /*************************************************************************/
43
44     /**
45      * Constructor
46      */

47     public AFocusTraversalPolicy ()
48     {
49         super();
50     } // AFocusTraversalPolicy
51

52     /**
53      * Returns the first Component in the traversal cycle. This method is used
54      * to determine the next Component to focus when traversal wraps in the
55      * forward direction.
56      *
57      * @param focusCycleRoot the focus cycle root whose first Component is to
58      * be returned
59      * @return the first Component in the traversal cycle when focusCycleRoot
60      * is the focus cycle root, or null if no suitable Component can be
61      * found
62      * @throws IllegalArgumentException if focusCycleRoot is null
63      */

64     public Component getFirstComponent(Container focusCycleRoot)
65     {
66         Component c = super.getFirstComponent(focusCycleRoot);
67     // info ("Root: ", focusCycleRoot);
68
// info (" First: ", c);
69
return c;
70     } // getFirstComponent
71

72     /**
73      * Returns the Component that should receive the focus after aComponent.
74      * focusCycleRoot must be a focus cycle root of aComponent.
75      * <p>
76      * By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
77      * cycle. That is, during normal focus traversal, the Component
78      * traversed after a focus cycle root will be the focus-cycle-root's
79      * default Component to focus. This behavior can be disabled using the
80      * <code>setImplicitDownCycleTraversal</code> method.
81      *
82      * @param focusCycleRoot a focus cycle root of aComponent
83      * @param aComponent a (possibly indirect) child of focusCycleRoot, or
84      * focusCycleRoot itself
85      * @return the Component that should receive the focus after aComponent, or
86      * null if no suitable Component can be found
87      * @throws IllegalArgumentException if focusCycleRoot is not a focus cycle
88      * root of aComponent, or if either focusCycleRoot or aComponent is
89      * null
90      */

91     public Component getComponentAfter(Container focusCycleRoot, Component aComponent)
92     {
93         Component c = super.getComponentAfter(focusCycleRoot, aComponent);
94         return c;
95     }
96
97     /**
98      * Returns the Component that should receive the focus before aComponent.
99      * focusCycleRoot must be a focus cycle root of aComponent.
100      * <p>
101      * By default, LayoutFocusTraversalPolicy implicitly transfers focus down-
102      * cycle. That is, during normal focus traversal, the Component
103      * traversed after a focus cycle root will be the focus-cycle-root's
104      * default Component to focus. This behavior can be disabled using the
105      * <code>setImplicitDownCycleTraversal</code> method.
106      *
107      * @param focusCycleRoot a focus cycle root of aComponent
108      * @param aComponent a (possibly indirect) child of focusCycleRoot, or
109      * focusCycleRoot itself
110      * @return the Component that should receive the focus before aComponent,
111      * or null if no suitable Component can be found
112      * @throws IllegalArgumentException if focusCycleRoot is not a focus cycle
113      * root of aComponent, or if either focusCycleRoot or aComponent is
114      * null
115      */

116     public Component getComponentBefore(Container focusCycleRoot, Component aComponent)
117     {
118         Component c = super.getComponentBefore(focusCycleRoot, aComponent);
119         return c;
120     }
121
122     /**
123      * Returns the last Component in the traversal cycle. This method is used
124      * to determine the next Component to focus when traversal wraps in the
125      * reverse direction.
126      *
127      * @param focusCycleRoot the focus cycle root whose last Component is to be
128      * returned
129      * @return the last Component in the traversal cycle when focusCycleRoot is
130      * the focus cycle root, or null if no suitable Component can be
131      * found
132      * @throws IllegalArgumentException if focusCycleRoot is null
133      */

134     public Component getLastComponent(Container focusCycleRoot)
135     {
136         Component c = super.getLastComponent(focusCycleRoot);
137         return c;
138     }
139
140     /**
141      * Determines whether the specified <code>Component</code>
142      * is an acceptable choice as the new focus owner.
143      * This method performs the following sequence of operations:
144      * <ol>
145      * <li>Checks whether <code>aComponent</code> is visible, displayable,
146      * enabled, and focusable. If any of these properties is
147      * <code>false</code>, this method returns <code>false</code>.
148      * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
149      * returns <code>true</code>.
150      * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
151      * then returns the value of
152      * <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
153      * <li>If <code>aComponent</code> is a <code>JComponent</code>
154      * with a <code>JComponent.WHEN_FOCUSED</code>
155      * <code>InputMap</code> that is neither <code>null</code>
156      * nor empty, returns <code>true</code>.
157      * <li>Returns the value of
158      * <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
159      * </ol>
160      *
161      * @param aComponent the <code>Component</code> whose fitness
162      * as a focus owner is to be tested
163      * @see java.awt.Component#isVisible
164      * @see java.awt.Component#isDisplayable
165      * @see java.awt.Component#isEnabled
166      * @see java.awt.Component#isFocusable
167      * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
168      * @see javax.swing.JComponent#getInputMap
169      * @see java.awt.DefaultFocusTraversalPolicy#accept
170      * @return <code>true</code> if <code>aComponent</code> is a valid choice
171      * for a focus owner;
172      * otherwise <code>false</code>
173      */

174     protected boolean accept(Component aComponent)
175     {
176         if (!super.accept(aComponent))
177             return false;
178
179         // TabbedPane
180
if (aComponent instanceof JTabbedPane)
181             return false;
182         // R/O Editors
183
if (aComponent instanceof CEditor)
184         {
185             CEditor ed = (CEditor)aComponent;
186             if (!ed.isReadWrite())
187                 return false;
188         }
189         // Toolbar Buttons
190
if (aComponent.getParent() instanceof JToolBar)
191             return false;
192         //
193
return true;
194     } // accept
195

196     /*************************************************************************/
197
198     /**
199      * Dump info
200      * @param title
201      * @param c
202      */

203     private void info (String JavaDoc title, Component c)
204     {
205         System.out.print (title);
206         System.out.print (c.getClass().getName());
207         System.out.println (" - " + c.getName());
208     } // info
209

210 } // AFocusTraversalPolicy
211
Popular Tags