001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla.components.calendar.jdk14adapter;
014:
015: import java.awt.*;
016: import java.awt.event.*;
017: import java.awt.Component;
018: import java.util.Observable;
019: import javax.swing.*;
020:
021: /** This class will only compile with JDK >=1.4
022: You can safely exclude it if you build with JDK <1.4
023: */
024: class AWTAdapterFactoryImpl extends AWTAdapterFactory {
025: public Observable createMouseWheelObservable(Component component) {
026: return new MyWheelListener(component);
027: }
028:
029: public FocusAdapter createFocusAdapter(Container container) {
030: return new MyFocusAdapter(container);
031: }
032: }
033:
034: class MyWheelListener extends Observable implements MouseWheelListener {
035: MyWheelListener(Component component) {
036: component.addMouseWheelListener(this );
037: }
038:
039: public void mouseWheelMoved(MouseWheelEvent evt) {
040: setChanged();
041: notifyObservers(new Long(evt.getWheelRotation()));
042: }
043:
044: }
045:
046: class MyFocusAdapter implements FocusAdapter {
047: Container c;
048:
049: MyFocusAdapter(Container container) {
050: this .c = container;
051: }
052:
053: public boolean isFocusOwner() {
054: return c.isFocusOwner();
055: }
056:
057: public boolean isFocusable() {
058: return c.isFocusable();
059: }
060:
061: public void setFocusCycleRoot(boolean bEnable) {
062: c.setFocusCycleRoot(bEnable);
063: }
064:
065: public void setFocusable(boolean bFocusable) {
066: c.setFocusable(bFocusable);
067: }
068:
069: public void transferFocusUpCycle() {
070: c.transferFocusUpCycle();
071: }
072:
073: public void transferFocusBackward() {
074: c.transferFocusBackward();
075: }
076:
077: public boolean requestFocusInWindow() {
078: return c.requestFocusInWindow();
079: }
080:
081: public void ignoreFocusComponents(FocusTester focusTester) {
082: c.setFocusTraversalPolicy(new MyFocusTraversalPolicy(
083: focusTester));
084: }
085: }
086:
087: class MyFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
088: private static final long serialVersionUID = 1L;
089:
090: FocusTester focusTester;
091:
092: MyFocusTraversalPolicy(FocusTester focusTester) {
093: this .focusTester = focusTester;
094: }
095:
096: protected boolean accept(Component component) {
097: if (!focusTester.accept(component))
098: return false;
099: return super.accept(component);
100: }
101: }
|