|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||||
|
||||||
001 /************************************************************************* 002 * 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * Copyright 2008 by Sun Microsystems, Inc. 006 * 007 * OpenOffice.org - a multi-platform office productivity suite 008 * 009 * $RCSfile: DialogFocusTraversalPolicy.java,v $ 010 * $Revision: 1.4 $ 011 * 012 * This file is part of OpenOffice.org. 013 * 014 * OpenOffice.org is free software: you can redistribute it and/or modify 015 * it under the terms of the GNU Lesser General Public License version 3 016 * only, as published by the Free Software Foundation. 017 * 018 * OpenOffice.org is distributed in the hope that it will be useful, 019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 021 * GNU Lesser General Public License version 3 for more details 022 * (a copy is included in the LICENSE file that accompanied this code). 023 * 024 * You should have received a copy of the GNU Lesser General Public License 025 * version 3 along with OpenOffice.org. If not, see 026 * <http://www.openoffice.org/license.html> 027 * for a copy of the LGPLv3 License. 028 * 029 ************************************************************************/ 030 031 package org.openoffice.setup.Util; 032 033 import java.awt.FocusTraversalPolicy; 034 import javax.swing.JComponent; 035 036 public class DialogFocusTraversalPolicy extends FocusTraversalPolicy { 037 038 private JComponent order[]; 039 private java.util.List list; 040 041 public DialogFocusTraversalPolicy(JComponent _order[]) { 042 order = _order; 043 list = java.util.Arrays.asList(order); 044 } 045 046 public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot) { 047 return order[0]; 048 } 049 050 public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot) { 051 return order[order.length - 1]; 052 } 053 054 public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 055 int index = 0,x = -1; 056 index = list.indexOf(aComponent); 057 index++; // increasing automatically 058 if(!order[index % order.length].isEnabled() || 059 !order[index % order.length].isVisible()) { 060 x = index; 061 index = -1; 062 for (; x != order.length; x++) { 063 if(order[x].isEnabled() && order[x].isVisible()) { 064 index = x; 065 break; 066 } 067 } 068 if(index == -1) { 069 x = list.indexOf(aComponent); 070 for(int y = 0; y <= x; y++) { 071 if(order[y].isEnabled() && order[x].isVisible()) { 072 index = y; 073 break; 074 } 075 } 076 } 077 } 078 return order[ index % order.length]; 079 } 080 081 public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent) { 082 int index = list.indexOf(aComponent), x = -1; 083 index--; 084 if(!order[(index + order.length) % order.length].isEnabled() || 085 !order[(index + order.length) % order.length].isVisible()) { 086 x = index; 087 index = -1; 088 for(; x >= 0; x--) { 089 if(order[x].isEnabled() && order[x].isVisible()) { 090 index = x; 091 break; 092 } 093 } 094 // if nothing has changed 095 if(index == -1) { 096 x = list.indexOf(aComponent); 097 for(int y = order.length -1; y >= x; y--) { 098 if(order[y].isEnabled() && order[x].isVisible()) { 099 index = y; 100 break; 101 } 102 } 103 } 104 } 105 return order[ (index + order.length) % order.length]; 106 } 107 108 public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot) { 109 return order[0]; 110 } 111 112 public java.awt.Component getInitialComponent(java.awt.Window window) { 113 return order[0]; 114 } 115 116 } 117 118
| [ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |
| This page was automatically generated by the LXR engine. The LXR team |
|