1 /* FocusManager.java -- 2 Copyright (C) 2002, 2004 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package javax.swing; 40 41 import java.awt.AWTEvent; 42 import java.awt.Component; 43 import java.awt.Container; 44 import java.awt.DefaultKeyboardFocusManager; 45 import java.awt.FocusTraversalPolicy; 46 import java.awt.KeyEventDispatcher; 47 import java.awt.KeyEventPostProcessor; 48 import java.awt.KeyboardFocusManager; 49 import java.awt.Window; 50 import java.awt.event.KeyEvent; 51 import java.beans.PropertyChangeListener; 52 import java.beans.VetoableChangeListener; 53 import java.util.Set; 54 55 /** 56 * This class has been obsoleted by the new 57 * {@link java.awt.KeyboardFocusManager} and 58 * {@link java.awt.DefaultKeyboardFocusManager} API. 59 * 60 * @author Andrew Selkirk 61 */ 62 public abstract class FocusManager 63 extends DefaultKeyboardFocusManager 64 { 65 /** 66 * A FocusManager that wraps an AWT KeyboardFocusManager and forwards all 67 * method calls to it. This is used for compatibility with the new focus 68 * system. 69 * 70 * @author Roman Kennke (kennke@aicas.com) 71 */ 72 private static class WrappingFocusManager 73 extends FocusManager 74 { 75 /** 76 * The wrapped KeyboardFocusManager. 77 */ 78 private KeyboardFocusManager wrapped; 79 80 /** 81 * Creates a new instance of WrappedFocusManager. 82 * 83 * @param fm the focus manager to wrap 84 */ WrappingFocusManager(KeyboardFocusManager fm)85 WrappingFocusManager(KeyboardFocusManager fm) 86 { 87 wrapped = fm; 88 } 89 90 /** 91 * Wraps {@link DefaultKeyboardFocusManager#dispatchEvent(AWTEvent)}. 92 * 93 * @param ev the event to dispatch 94 * 95 * @return <code>true</code> if the event has been dispatched, 96 * <code>false</code> otherwise 97 */ dispatchEvent(AWTEvent ev)98 public boolean dispatchEvent(AWTEvent ev) 99 { 100 return wrapped.dispatchEvent(ev); 101 } 102 103 /** 104 * Wraps {@link DefaultKeyboardFocusManager#dispatchKeyEvent(KeyEvent)}. 105 * 106 * @param ev the event to dispatch 107 * 108 * @return <code>true</code> if the event has been dispatched, 109 * <code>false</code> otherwise 110 */ dispatchKeyEvent(KeyEvent ev)111 public boolean dispatchKeyEvent(KeyEvent ev) 112 { 113 return wrapped.dispatchKeyEvent(ev); 114 } 115 116 /** 117 * Wraps {@link DefaultKeyboardFocusManager#downFocusCycle(Container)}. 118 * 119 * @param c the container 120 */ downFocusCycle(Container c)121 public void downFocusCycle(Container c) 122 { 123 wrapped.downFocusCycle(c); 124 } 125 126 /** 127 * Wraps {@link DefaultKeyboardFocusManager#upFocusCycle(Container)}. 128 * 129 * @param c the container 130 */ upFocusCycle(Container c)131 public void upFocusCycle(Container c) 132 { 133 wrapped.upFocusCycle(c); 134 } 135 136 /** 137 * Wraps {@link DefaultKeyboardFocusManager#focusNextComponent(Component)}. 138 * 139 * @param c the component 140 */ focusNextComponent(Component c)141 public void focusNextComponent(Component c) 142 { 143 wrapped.focusNextComponent(c); 144 } 145 146 /** 147 * Wraps 148 * {@link DefaultKeyboardFocusManager#focusPreviousComponent(Component)}. 149 * 150 * @param c the component 151 */ focusPreviousComponent(Component c)152 public void focusPreviousComponent(Component c) 153 { 154 wrapped.focusPreviousComponent(c); 155 } 156 157 /** 158 * Wraps {@link DefaultKeyboardFocusManager#postProcessKeyEvent(KeyEvent)}. 159 * 160 * @param e the key event 161 * 162 * @return a boolead 163 */ postProcessKeyEvent(KeyEvent e)164 public boolean postProcessKeyEvent(KeyEvent e) 165 { 166 return wrapped.postProcessKeyEvent(e); 167 } 168 169 /** 170 * Wraps 171 * {@link DefaultKeyboardFocusManager#processKeyEvent(Component, KeyEvent)}. 172 * 173 * @param c the component 174 * @param e the key event 175 */ processKeyEvent(Component c, KeyEvent e)176 public void processKeyEvent(Component c, KeyEvent e) 177 { 178 wrapped.processKeyEvent(c, e); 179 } 180 181 /** 182 * Wraps 183 * {@link KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)}. 184 * 185 * @param d the dispatcher 186 */ addKeyEventDispatcher(KeyEventDispatcher d)187 public void addKeyEventDispatcher(KeyEventDispatcher d) 188 { 189 wrapped.addKeyEventDispatcher(d); 190 } 191 192 /** 193 * Wraps 194 * {@link KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)}. 195 * 196 * @param p the post processor 197 */ addKeyEventPostProcessor(KeyEventPostProcessor p)198 public void addKeyEventPostProcessor(KeyEventPostProcessor p) 199 { 200 wrapped.addKeyEventPostProcessor(p); 201 } 202 203 /** 204 * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(PropertyChangeListener)}. 205 * 206 * @param l the property change listener 207 */ addPropertyChangeListener(PropertyChangeListener l)208 public void addPropertyChangeListener(PropertyChangeListener l) 209 { 210 wrapped.addPropertyChangeListener(l); 211 } 212 213 /** 214 * Wraps {@link KeyboardFocusManager#addPropertyChangeListener(String, PropertyChangeListener)}. 215 * 216 * @param p the property name 217 * @param l the property change listener 218 */ addPropertyChangeListener(String p, PropertyChangeListener l)219 public void addPropertyChangeListener(String p, PropertyChangeListener l) 220 { 221 wrapped.addPropertyChangeListener(p, l); 222 } 223 224 /** 225 * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(String, VetoableChangeListener)}. 226 * 227 * @param p the property name 228 * @param l the vetoable change listener 229 */ addVetoableChangeListener(String p, VetoableChangeListener l)230 public void addVetoableChangeListener(String p, VetoableChangeListener l) 231 { 232 wrapped.addVetoableChangeListener(p, l); 233 } 234 235 /** 236 * Wraps {@link KeyboardFocusManager#addVetoableChangeListener(VetoableChangeListener)}. 237 * 238 * @param l the vetoable change listener 239 */ addVetoableChangeListener(VetoableChangeListener l)240 public void addVetoableChangeListener(VetoableChangeListener l) 241 { 242 wrapped.addVetoableChangeListener(l); 243 } 244 245 /** 246 * Wraps {@link KeyboardFocusManager#clearGlobalFocusOwner()}. 247 */ clearGlobalFocusOwner()248 public void clearGlobalFocusOwner() 249 { 250 wrapped.clearGlobalFocusOwner(); 251 } 252 253 /** 254 * Wraps {@link KeyboardFocusManager#getActiveWindow()}. 255 * 256 * @return the active window 257 */ getActiveWindow()258 public Window getActiveWindow() 259 { 260 return wrapped.getActiveWindow(); 261 } 262 263 /** 264 * Wraps {@link KeyboardFocusManager#getCurrentFocusCycleRoot()}. 265 * 266 * @return the focus cycle root 267 */ getCurrentFocusCycleRoot()268 public Container getCurrentFocusCycleRoot() 269 { 270 return wrapped.getCurrentFocusCycleRoot(); 271 } 272 273 /** 274 * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalKeys(int)}. 275 * 276 * @param i the ID 277 * 278 * @return the focus traversal keys 279 */ getDefaultFocusTraversalKeys(int i)280 public Set getDefaultFocusTraversalKeys(int i) 281 { 282 return wrapped.getDefaultFocusTraversalKeys(i); 283 } 284 285 /** 286 * Wraps {@link KeyboardFocusManager#getDefaultFocusTraversalPolicy()}. 287 * 288 * @return the focus traversal policy 289 */ getDefaultFocusTraversalPolicy()290 public FocusTraversalPolicy getDefaultFocusTraversalPolicy() 291 { 292 return wrapped.getDefaultFocusTraversalPolicy(); 293 } 294 295 /** 296 * Wraps {@link KeyboardFocusManager#getFocusedWindow()}. 297 * 298 * @return the focused window 299 */ getFocusedWindow()300 public Window getFocusedWindow() 301 { 302 return wrapped.getFocusedWindow(); 303 } 304 305 /** 306 * Wraps {@link KeyboardFocusManager#getFocusOwner()}. 307 * 308 * @return the focus owner 309 */ getFocusOwner()310 public Component getFocusOwner() 311 { 312 return wrapped.getFocusOwner(); 313 } 314 315 /** 316 * Wraps {@link KeyboardFocusManager#getPermanentFocusOwner()}. 317 * 318 * @return the focus owner 319 */ getPermanentFocusOwner()320 public Component getPermanentFocusOwner() 321 { 322 return wrapped.getPermanentFocusOwner(); 323 } 324 325 /** 326 * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners()}. 327 * 328 * @return the property change listeners 329 */ getPropertyChangeListeners()330 public PropertyChangeListener[] getPropertyChangeListeners() 331 { 332 return wrapped.getPropertyChangeListeners(); 333 } 334 335 /** 336 * Wraps {@link KeyboardFocusManager#getPropertyChangeListeners(String)}. 337 * 338 * @param n the property name 339 * 340 * @return the property change listeners 341 */ getPropertyChangeListeners(String n)342 public PropertyChangeListener[] getPropertyChangeListeners(String n) 343 { 344 return wrapped.getPropertyChangeListeners(n); 345 } 346 347 /** 348 * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners()}. 349 * 350 * @return the vetoable change listeners 351 */ getVetoableChangeListeners()352 public VetoableChangeListener[] getVetoableChangeListeners() 353 { 354 return wrapped.getVetoableChangeListeners(); 355 } 356 357 /** 358 * Wraps {@link KeyboardFocusManager#getVetoableChangeListeners(String)}. 359 * 360 * @param n the property name 361 * 362 * @return the vetoable change listeners 363 */ getVetoableChangeListeners(String n)364 public VetoableChangeListener[] getVetoableChangeListeners(String n) 365 { 366 return wrapped.getVetoableChangeListeners(n); 367 } 368 369 370 /** 371 * Wraps 372 * {@link KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)}. 373 * 374 * @param d the key event dispatcher to remove 375 */ removeKeyEventDispatcher(KeyEventDispatcher d)376 public void removeKeyEventDispatcher(KeyEventDispatcher d) 377 { 378 wrapped.removeKeyEventDispatcher(d); 379 } 380 381 /** 382 * Wraps 383 * {@link KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)}. 384 * 385 * @param p the post processor 386 */ removeKeyEventPostProcessor(KeyEventPostProcessor p)387 public void removeKeyEventPostProcessor(KeyEventPostProcessor p) 388 { 389 wrapped.removeKeyEventPostProcessor(p); 390 } 391 392 /** 393 * Wraps 394 * {@link KeyboardFocusManager#removePropertyChangeListener(PropertyChangeListener)}. 395 * 396 * @param l the listener 397 */ removePropertyChangeListener(PropertyChangeListener l)398 public void removePropertyChangeListener(PropertyChangeListener l) 399 { 400 wrapped.removePropertyChangeListener(l); 401 } 402 403 /** 404 * Wraps 405 * {@link KeyboardFocusManager#removePropertyChangeListener(String, PropertyChangeListener)}. 406 * 407 * @param n the property name 408 * @param l the listener 409 */ removePropertyChangeListener(String n, PropertyChangeListener l)410 public void removePropertyChangeListener(String n, PropertyChangeListener l) 411 { 412 wrapped.removePropertyChangeListener(n, l); 413 } 414 415 /** 416 * Wraps 417 * {@link KeyboardFocusManager#removeVetoableChangeListener(VetoableChangeListener)}. 418 * 419 * @param l the listener 420 */ removeVetoableChangeListener(VetoableChangeListener l)421 public void removeVetoableChangeListener(VetoableChangeListener l) 422 { 423 wrapped.removeVetoableChangeListener(l); 424 } 425 426 /** 427 * Wraps 428 * {@link KeyboardFocusManager#removeVetoableChangeListener(String, VetoableChangeListener)}. 429 * 430 * @param n the property name 431 * @param l the listener 432 */ removeVetoableChangeListener(String n, VetoableChangeListener l)433 public void removeVetoableChangeListener(String n, VetoableChangeListener l) 434 { 435 wrapped.removeVetoableChangeListener(n, l); 436 } 437 438 /** 439 * Wraps 440 * {@link KeyboardFocusManager#setDefaultFocusTraversalKeys(int, Set)}. 441 * 442 * @param id the ID 443 * @param k the keystrokes 444 */ setDefaultFocusTraversalKeys(int id, Set k)445 public void setDefaultFocusTraversalKeys(int id, Set k) 446 { 447 wrapped.setDefaultFocusTraversalKeys(id, k); 448 } 449 450 /** 451 * Wraps {@link KeyboardFocusManager#setDefaultFocusTraversalPolicy(FocusTraversalPolicy)}. 452 * 453 * @param p the focus traversal policy 454 */ setDefaultFocusTraversalPolicy(FocusTraversalPolicy p)455 public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy p) 456 { 457 wrapped.setDefaultFocusTraversalPolicy(p); 458 } 459 460 /** 461 * Wraps 462 * {@link KeyboardFocusManager#setGlobalCurrentFocusCycleRoot(Container)}. 463 * 464 * @param r the focus cycle root 465 */ setGlobalCurrentFocusCycleRoot(Container r)466 public void setGlobalCurrentFocusCycleRoot(Container r) 467 { 468 wrapped.setGlobalCurrentFocusCycleRoot(r); 469 } 470 } 471 472 /** 473 * FOCUS_MANAGER_CLASS_PROPERTY 474 */ 475 public static final String FOCUS_MANAGER_CLASS_PROPERTY = 476 "FocusManagerClassName"; 477 478 /** 479 * Constructor FocusManager 480 */ FocusManager()481 public FocusManager() 482 { 483 super(); 484 } 485 486 /** 487 * getCurrentManager 488 * @returns FocusManager 489 */ getCurrentManager()490 public static FocusManager getCurrentManager() 491 { 492 KeyboardFocusManager m = 493 KeyboardFocusManager.getCurrentKeyboardFocusManager(); 494 return new WrappingFocusManager(m); 495 } 496 497 /** 498 * setCurrentManager 499 * @param manager TODO 500 */ setCurrentManager(FocusManager manager)501 public static void setCurrentManager(FocusManager manager) 502 { 503 KeyboardFocusManager.setCurrentKeyboardFocusManager(manager); 504 } 505 506 /** 507 * disableSwingFocusManager 508 * @deprecated 1.4 509 */ disableSwingFocusManager()510 public static void disableSwingFocusManager() 511 { 512 // TODO 513 } 514 515 /** 516 * isFocusManagerEnabled 517 * @return boolean 518 * @deprecated 1.4 519 */ isFocusManagerEnabled()520 public static boolean isFocusManagerEnabled() 521 { 522 return false; // TODO 523 } 524 } 525