001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing;
019:
020: import java.awt.Component;
021: import java.awt.Container;
022: import java.awt.FocusTraversalPolicy;
023:
024: import org.apache.harmony.x.swing.internal.nls.Messages;
025:
026: class BequestedFocusTraversalPolicy extends FocusTraversalPolicy {
027: private final FocusTraversalPolicy ancestor;
028:
029: private final Component fixedComponent;
030:
031: private final Component fixedNextComponent;
032:
033: /**
034: * Creates <code>FocusTraversalPolicy</code> that inherits all values
035: * returned by existing <code>FocusTraversalPolicy</code> and overlaps
036: * only two of them: value returned by <code>getComponentAfter()</code> for
037: * <code>fixedComponent</code> and <code>getComponentBefore()</code> for
038: * <code>fixedNextComponent</code>.
039: * @throws <code>IllegalArgumentException</code> if <code>ancestor</code> is <code>null</code>
040: */
041: public BequestedFocusTraversalPolicy(
042: final FocusTraversalPolicy ancestor,
043: final Component fixedComponent,
044: final Component fixedNextComponent) {
045: super ();
046: this .ancestor = ancestor;
047: if (this .ancestor == null) {
048: throw new IllegalArgumentException(Messages
049: .getString("swing.06")); //$NON-NLS-1$
050: }
051: this .fixedComponent = fixedComponent;
052: this .fixedNextComponent = fixedNextComponent;
053: }
054:
055: /**
056: * returns <code>fixedNextComponent</code> for <code>fixedComponent</code> or
057: * delegates call to <code>ancestor</code>
058: */
059: @Override
060: public Component getComponentAfter(final Container container,
061: final Component c) {
062: if (c == fixedComponent) {
063: return fixedNextComponent;
064: }
065: return ancestor.getComponentAfter(container, c);
066: }
067:
068: /**
069: * returns <code>fixedComponent</code> for <code>fixedNextComponent</code> or
070: * delegates call to <code>ancestor</code>
071: */
072: @Override
073: public Component getComponentBefore(final Container container,
074: final Component c) {
075: if (c == fixedNextComponent) {
076: return fixedComponent;
077: }
078: return ancestor.getComponentBefore(container, c);
079: }
080:
081: /**
082: * delegates call to <code>ancestor</code>
083: */
084: @Override
085: public Component getDefaultComponent(final Container container) {
086: return ancestor.getDefaultComponent(container);
087: }
088:
089: /**
090: * delegates call to <code>ancestor</code>
091: */
092: @Override
093: public Component getFirstComponent(final Container container) {
094: return ancestor.getFirstComponent(container);
095: }
096:
097: /**
098: * delegates call to <code>ancestor</code>
099: */
100: @Override
101: public Component getLastComponent(final Container container) {
102: return ancestor.getLastComponent(container);
103: }
104: }
|