View Javadoc

1   /*
2      Copyright 2002-2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15  */
16  package org.xulux.guilayer.swing.listeners;
17  
18  import java.awt.event.FocusEvent;
19  import java.awt.event.FocusListener;
20  
21  import org.xulux.api.gui.IWidget;
22  import org.xulux.gui.XuluxListener;
23  import org.xulux.gui.utils.XuluxEventQueue;
24  
25  /**
26   * This adds a focuslistener for widgets that do not have a focus event by default
27   * or widgets that just need to release the eventqueue when focus is gained.
28   * (eg buttons have this behaviour)
29   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
30   * @version $Id: WidgetFocusListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $
31   */
32  public class WidgetFocusListener extends XuluxListener implements FocusListener {
33  
34    /**
35     * 
36     */
37    public WidgetFocusListener(IWidget widget) {
38      super(widget);
39    }
40  
41    /**
42     * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
43     */
44    public void focusGained(FocusEvent e) {
45        if (isProcessing()) {
46            return;
47        }
48        if (e.getID() != FocusEvent.FOCUS_GAINED || e.isTemporary()) {
49            return;
50        }
51        XuluxEventQueue q = XuluxEventQueue.getInstance();
52        // seems to happen when integrating with native widgets and xulux is 
53        // not yet initialized..
54        if (q != null) {
55            q.holdEvents(false);
56        }
57    }
58  
59    /**
60     * Free the event queue when the focus of a component is lost, so 
61     * processing of the field will take place.
62     *
63     * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
64     */
65    public void focusLost(FocusEvent e) {
66    }
67  
68  }