src/share/classes/javax/swing/LayoutFocusTraversalPolicy.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  30 import java.util.Comparator;
  31 import java.io.*;
  32 import sun.awt.SunToolkit;
  33 
  34 
  35 /**
  36  * A SortingFocusTraversalPolicy which sorts Components based on their size,
  37  * position, and orientation. Based on their size and position, Components are
  38  * roughly categorized into rows and columns. For a Container with horizontal
  39  * orientation, columns run left-to-right or right-to-left, and rows run top-
  40  * to-bottom. For a Container with vertical orientation, columns run top-to-
  41  * bottom and rows run left-to-right or right-to-left. See
  42  * <code>ComponentOrientation</code> for more information. All columns in a
  43  * row are fully traversed before proceeding to the next row.
  44  *
  45  * @author David Mendenhall
  46  *
  47  * @see java.awt.ComponentOrientation
  48  * @since 1.4
  49  */

  50 public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy
  51     implements Serializable
  52 {
  53     // Delegate most of our fitness test to Default so that we only have to
  54     // code the algorithm once.
  55     private static final SwingDefaultFocusTraversalPolicy fitnessTestPolicy =
  56         new SwingDefaultFocusTraversalPolicy();
  57 
  58     /**
  59      * Constructs a LayoutFocusTraversalPolicy.
  60      */
  61     public LayoutFocusTraversalPolicy() {
  62         super(new LayoutComparator());
  63     }
  64 
  65     /**
  66      * Constructs a LayoutFocusTraversalPolicy with the passed in
  67      * <code>Comparator</code>.
  68      */
  69     LayoutFocusTraversalPolicy(Comparator<? super Component> c) {


 248             // case where the developer has overriden isFocusTraversable to
 249             // return true.
 250         }
 251         return fitnessTestPolicy.accept(aComponent);
 252     }
 253 
 254     private void writeObject(ObjectOutputStream out) throws IOException {
 255         out.writeObject(getComparator());
 256         out.writeBoolean(getImplicitDownCycleTraversal());
 257     }
 258     private void readObject(ObjectInputStream in)
 259         throws IOException, ClassNotFoundException
 260     {
 261         setComparator((Comparator)in.readObject());
 262         setImplicitDownCycleTraversal(in.readBoolean());
 263     }
 264 }
 265 
 266 // Create our own subclass and change accept to public so that we can call
 267 // accept.

 268 class SwingDefaultFocusTraversalPolicy
 269     extends java.awt.DefaultFocusTraversalPolicy
 270 {
 271     public boolean accept(Component aComponent) {
 272         return super.accept(aComponent);
 273     }
 274 }
   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  30 import java.util.Comparator;
  31 import java.io.*;
  32 import sun.awt.SunToolkit;
  33 
  34 
  35 /**
  36  * A SortingFocusTraversalPolicy which sorts Components based on their size,
  37  * position, and orientation. Based on their size and position, Components are
  38  * roughly categorized into rows and columns. For a Container with horizontal
  39  * orientation, columns run left-to-right or right-to-left, and rows run top-
  40  * to-bottom. For a Container with vertical orientation, columns run top-to-
  41  * bottom and rows run left-to-right or right-to-left. See
  42  * <code>ComponentOrientation</code> for more information. All columns in a
  43  * row are fully traversed before proceeding to the next row.
  44  *
  45  * @author David Mendenhall
  46  *
  47  * @see java.awt.ComponentOrientation
  48  * @since 1.4
  49  */
  50 @SuppressWarnings("serial") // Parts of superclass are not serializable across versions
  51 public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy
  52     implements Serializable
  53 {
  54     // Delegate most of our fitness test to Default so that we only have to
  55     // code the algorithm once.
  56     private static final SwingDefaultFocusTraversalPolicy fitnessTestPolicy =
  57         new SwingDefaultFocusTraversalPolicy();
  58 
  59     /**
  60      * Constructs a LayoutFocusTraversalPolicy.
  61      */
  62     public LayoutFocusTraversalPolicy() {
  63         super(new LayoutComparator());
  64     }
  65 
  66     /**
  67      * Constructs a LayoutFocusTraversalPolicy with the passed in
  68      * <code>Comparator</code>.
  69      */
  70     LayoutFocusTraversalPolicy(Comparator<? super Component> c) {


 249             // case where the developer has overriden isFocusTraversable to
 250             // return true.
 251         }
 252         return fitnessTestPolicy.accept(aComponent);
 253     }
 254 
 255     private void writeObject(ObjectOutputStream out) throws IOException {
 256         out.writeObject(getComparator());
 257         out.writeBoolean(getImplicitDownCycleTraversal());
 258     }
 259     private void readObject(ObjectInputStream in)
 260         throws IOException, ClassNotFoundException
 261     {
 262         setComparator((Comparator)in.readObject());
 263         setImplicitDownCycleTraversal(in.readBoolean());
 264     }
 265 }
 266 
 267 // Create our own subclass and change accept to public so that we can call
 268 // accept.
 269 @SuppressWarnings("serial") // JDK-implementation class
 270 class SwingDefaultFocusTraversalPolicy
 271     extends java.awt.DefaultFocusTraversalPolicy
 272 {
 273     public boolean accept(Component aComponent) {
 274         return super.accept(aComponent);
 275     }
 276 }