1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.setup.Util; 29 30 import java.awt.FocusTraversalPolicy; 31 import javax.swing.JComponent; 32 33 public class DialogFocusTraversalPolicy extends FocusTraversalPolicy { 34 35 private JComponent order[]; 36 private java.util.List list; 37 38 public DialogFocusTraversalPolicy(JComponent _order[]) { 39 order = _order; 40 list = java.util.Arrays.asList(order); 41 } 42 43 public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot) { 44 return order[0]; 45 } 46 47 public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot) { 48 return order[order.length - 1]; 49 } 50 51 public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 52 int index = 0,x = -1; 53 index = list.indexOf(aComponent); 54 index++; // increasing automatically 55 if(!order[index % order.length].isEnabled() || 56 !order[index % order.length].isVisible()) { 57 x = index; 58 index = -1; 59 for (; x != order.length; x++) { 60 if(order[x].isEnabled() && order[x].isVisible()) { 61 index = x; 62 break; 63 } 64 } 65 if(index == -1) { 66 x = list.indexOf(aComponent); 67 for(int y = 0; y <= x; y++) { 68 if(order[y].isEnabled() && order[x].isVisible()) { 69 index = y; 70 break; 71 } 72 } 73 } 74 } 75 return order[ index % order.length]; 76 } 77 78 public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 79 int index = list.indexOf(aComponent), x = -1; 80 index--; 81 if(!order[(index + order.length) % order.length].isEnabled() || 82 !order[(index + order.length) % order.length].isVisible()) { 83 x = index; 84 index = -1; 85 for(; x >= 0; x--) { 86 if(order[x].isEnabled() && order[x].isVisible()) { 87 index = x; 88 break; 89 } 90 } 91 // if nothing has changed 92 if(index == -1) { 93 x = list.indexOf(aComponent); 94 for(int y = order.length -1; y >= x; y--) { 95 if(order[y].isEnabled() && order[x].isVisible()) { 96 index = y; 97 break; 98 } 99 } 100 } 101 } 102 return order[ (index + order.length) % order.length]; 103 } 104 105 public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot) { 106 return order[0]; 107 } 108 109 public java.awt.Component getInitialComponent(java.awt.Window window) { 110 return order[0]; 111 } 112 113 } 114 115 116