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.KeyAdapter;
19  import java.awt.event.KeyEvent;
20  
21  import org.xulux.api.core.IPart;
22  import org.xulux.api.core.PartRequest;
23  import org.xulux.api.gui.IWidget;
24  import org.xulux.api.rules.IRuleEngine;
25  import org.xulux.core.XuluxContext;
26  import org.xulux.rules.impl.WidgetRequestImpl;
27  
28  /**
29   * The immidiate listeners fires events based on typed keys.
30   * For now only used for checkbox.
31   *
32   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
33   * @version $Id: ImmidiateListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $
34   */
35  public class ImmidiateListener extends KeyAdapter {
36      /**
37       * the widget
38       */
39      private IWidget widget;
40      /**
41       * the part
42       */
43      private IPart part;
44  
45      /**
46       * the constructor
47       */
48      public ImmidiateListener() {
49      }
50  
51      /**
52       * Constructor for ImmidiateListener.
53       * @param widget the widget
54       */
55      public ImmidiateListener(IWidget widget) {
56          this.widget = widget;
57          this.part = widget.getPart();
58      }
59  
60      /**
61       * @see java.awt.event.KeyListener#keyTyped(KeyEvent)
62       */
63      public void keyTyped(KeyEvent e) {
64          WidgetRequestImpl impl = new WidgetRequestImpl(widget, PartRequest.ACTION_VALUE_CHANGED);
65          XuluxContext.getRuleEngine().fireFieldRequests(impl, IRuleEngine.EXECUTE_REQUEST);
66      }
67  
68      /**
69       * Returns the widget.
70       * @return NyxWidget
71       */
72      public IWidget getWidget() {
73          return widget;
74      }
75  
76      /**
77       * Sets the widget.
78       * @param widget The widget to set
79       */
80      public void setWidget(IWidget widget) {
81          this.widget = widget;
82      }
83  
84  }