Home » openjdk-7 » javax » swing » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package javax.swing;
   19   
   20   import java.awt.Component;
   21   import java.awt.Container;
   22   import java.awt.FocusTraversalPolicy;
   23   
   24   import org.apache.harmony.x.swing.internal.nls.Messages;
   25   
   26   class BequestedFocusTraversalPolicy extends FocusTraversalPolicy {
   27       private final FocusTraversalPolicy ancestor;
   28   
   29       private final Component fixedComponent;
   30   
   31       private final Component fixedNextComponent;
   32   
   33       /**
   34        * Creates <code>FocusTraversalPolicy</code> that inherits all values
   35        * returned by existing <code>FocusTraversalPolicy</code> and overlaps
   36        * only two of them: value returned by <code>getComponentAfter()</code> for
   37        * <code>fixedComponent</code> and <code>getComponentBefore()</code> for
   38        * <code>fixedNextComponent</code>.
   39        * @throws <code>IllegalArgumentException</code> if <code>ancestor</code> is <code>null</code>
   40        */
   41       public BequestedFocusTraversalPolicy(final FocusTraversalPolicy ancestor,
   42               final Component fixedComponent, final Component fixedNextComponent) {
   43           super();
   44           this.ancestor = ancestor;
   45           if (this.ancestor == null) {
   46               throw new IllegalArgumentException(Messages.getString("swing.06")); //$NON-NLS-1$
   47           }
   48           this.fixedComponent = fixedComponent;
   49           this.fixedNextComponent = fixedNextComponent;
   50       }
   51   
   52       /**
   53        * returns <code>fixedNextComponent</code> for <code>fixedComponent</code> or
   54        * delegates call to <code>ancestor</code>
   55        */
   56       @Override
   57       public Component getComponentAfter(final Container container, final Component c) {
   58           if (c == fixedComponent) {
   59               return fixedNextComponent;
   60           }
   61           return ancestor.getComponentAfter(container, c);
   62       }
   63   
   64       /**
   65        * returns <code>fixedComponent</code> for <code>fixedNextComponent</code> or
   66        * delegates call to <code>ancestor</code>
   67        */
   68       @Override
   69       public Component getComponentBefore(final Container container, final Component c) {
   70           if (c == fixedNextComponent) {
   71               return fixedComponent;
   72           }
   73           return ancestor.getComponentBefore(container, c);
   74       }
   75   
   76       /**
   77        * delegates call to <code>ancestor</code>
   78        */
   79       @Override
   80       public Component getDefaultComponent(final Container container) {
   81           return ancestor.getDefaultComponent(container);
   82       }
   83   
   84       /**
   85        * delegates call to <code>ancestor</code>
   86        */
   87       @Override
   88       public Component getFirstComponent(final Container container) {
   89           return ancestor.getFirstComponent(container);
   90       }
   91   
   92       /**
   93        * delegates call to <code>ancestor</code>
   94        */
   95       @Override
   96       public Component getLastComponent(final Container container) {
   97           return ancestor.getLastComponent(container);
   98       }
   99   }

Home » openjdk-7 » javax » swing » [javadoc | source]