1*9a1eeea9SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9a1eeea9SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9a1eeea9SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9a1eeea9SAndrew Rist * distributed with this work for additional information 6*9a1eeea9SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9a1eeea9SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9a1eeea9SAndrew Rist * "License"); you may not use this file except in compliance 9*9a1eeea9SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9a1eeea9SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9a1eeea9SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9a1eeea9SAndrew Rist * software distributed under the License is distributed on an 15*9a1eeea9SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9a1eeea9SAndrew Rist * KIND, either express or implied. See the License for the 17*9a1eeea9SAndrew Rist * specific language governing permissions and limitations 18*9a1eeea9SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9a1eeea9SAndrew Rist *************************************************************/ 21*9a1eeea9SAndrew Rist 22*9a1eeea9SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package org.openoffice.setup.Util; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.awt.FocusTraversalPolicy; 27cdf0e10cSrcweir import javax.swing.JComponent; 28cdf0e10cSrcweir 29cdf0e10cSrcweir public class DialogFocusTraversalPolicy extends FocusTraversalPolicy { 30cdf0e10cSrcweir 31cdf0e10cSrcweir private JComponent order[]; 32cdf0e10cSrcweir private java.util.List list; 33cdf0e10cSrcweir DialogFocusTraversalPolicy(JComponent _order[])34cdf0e10cSrcweir public DialogFocusTraversalPolicy(JComponent _order[]) { 35cdf0e10cSrcweir order = _order; 36cdf0e10cSrcweir list = java.util.Arrays.asList(order); 37cdf0e10cSrcweir } 38cdf0e10cSrcweir getFirstComponent(java.awt.Container focusCycleRoot)39cdf0e10cSrcweir public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot) { 40cdf0e10cSrcweir return order[0]; 41cdf0e10cSrcweir } 42cdf0e10cSrcweir getLastComponent(java.awt.Container focusCycleRoot)43cdf0e10cSrcweir public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot) { 44cdf0e10cSrcweir return order[order.length - 1]; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent)47cdf0e10cSrcweir public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 48cdf0e10cSrcweir int index = 0,x = -1; 49cdf0e10cSrcweir index = list.indexOf(aComponent); 50cdf0e10cSrcweir index++; // increasing automatically 51cdf0e10cSrcweir if(!order[index % order.length].isEnabled() || 52cdf0e10cSrcweir !order[index % order.length].isVisible()) { 53cdf0e10cSrcweir x = index; 54cdf0e10cSrcweir index = -1; 55cdf0e10cSrcweir for (; x != order.length; x++) { 56cdf0e10cSrcweir if(order[x].isEnabled() && order[x].isVisible()) { 57cdf0e10cSrcweir index = x; 58cdf0e10cSrcweir break; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir } 61cdf0e10cSrcweir if(index == -1) { 62cdf0e10cSrcweir x = list.indexOf(aComponent); 63cdf0e10cSrcweir for(int y = 0; y <= x; y++) { 64cdf0e10cSrcweir if(order[y].isEnabled() && order[x].isVisible()) { 65cdf0e10cSrcweir index = y; 66cdf0e10cSrcweir break; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir } 69cdf0e10cSrcweir } 70cdf0e10cSrcweir } 71cdf0e10cSrcweir return order[ index % order.length]; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent)74cdf0e10cSrcweir public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 75cdf0e10cSrcweir int index = list.indexOf(aComponent), x = -1; 76cdf0e10cSrcweir index--; 77cdf0e10cSrcweir if(!order[(index + order.length) % order.length].isEnabled() || 78cdf0e10cSrcweir !order[(index + order.length) % order.length].isVisible()) { 79cdf0e10cSrcweir x = index; 80cdf0e10cSrcweir index = -1; 81cdf0e10cSrcweir for(; x >= 0; x--) { 82cdf0e10cSrcweir if(order[x].isEnabled() && order[x].isVisible()) { 83cdf0e10cSrcweir index = x; 84cdf0e10cSrcweir break; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir // if nothing has changed 88cdf0e10cSrcweir if(index == -1) { 89cdf0e10cSrcweir x = list.indexOf(aComponent); 90cdf0e10cSrcweir for(int y = order.length -1; y >= x; y--) { 91cdf0e10cSrcweir if(order[y].isEnabled() && order[x].isVisible()) { 92cdf0e10cSrcweir index = y; 93cdf0e10cSrcweir break; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir return order[ (index + order.length) % order.length]; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir getDefaultComponent(java.awt.Container focusCycleRoot)101cdf0e10cSrcweir public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot) { 102cdf0e10cSrcweir return order[0]; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir getInitialComponent(java.awt.Window window)105cdf0e10cSrcweir public java.awt.Component getInitialComponent(java.awt.Window window) { 106cdf0e10cSrcweir return order[0]; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir 112