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;
17  
18  import javax.swing.JComponent;
19  
20  import org.xulux.api.gui.IWidgetInitializer;
21  import org.xulux.gui.XuluxWidget;
22  
23  /**
24   * A convenience class for swing widgets to override..
25   *
26   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
27   * @version $Id: Widget.java,v 1.1 2005/12/18 12:58:25 mvdb Exp $
28   */
29  public abstract class SwingWidget extends XuluxWidget {
30  
31      /**
32       * @param name the swingwidget name
33       */
34      public SwingWidget(String name) {
35          super(name);
36      }
37  
38      /**
39       * @see org.xulux.api.gui.IWidget#focus()
40       */
41      public void focus() {
42          JComponent j = (JComponent) getNativeWidget();
43          isRefreshing = true;
44          j.requestFocus();
45          isRefreshing = false;
46          // if widget is not showing we have
47          // to make it showing..
48          if (!j.isShowing() && getParent() != null) {
49              // set the session variable, so controls
50              // can look who requested focus..
51              getPart().getSession().setValue("nyx.focusrequest", this);
52              getParent().focus();
53              // remove session variable again.
54              getPart().getSession().remove("nyx.focusrequest");
55              j.requestFocus();
56          }
57      }
58  
59      /**
60       * @see org.xulux.api.gui.IWidget#getWidgetInitializer()
61       */
62      public IWidgetInitializer getWidgetInitializer() {
63          return null;
64      }
65  
66  }