View Javadoc

1   /*
2      Copyright 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.natives;
17  
18  import java.awt.Container;
19  
20  import javax.swing.JFrame;
21  import javax.swing.JMenuBar;
22  
23  import org.xulux.api.gui.IWidget;
24  import org.xulux.api.gui.IWidgetInitializer;
25  
26  /**
27   * The menubar widget.
28   *
29   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
30   * @version $Id: $
31   */
32  public class NativeMenuBar implements IWidgetInitializer {
33  
34      JMenuBar menuBar;
35  
36      /**
37       * 
38       */
39      public NativeMenuBar() {
40          super();
41      }
42  
43      public void initialize(IWidget widget) {
44          this.menuBar = new JMenuBar();
45      }
46  
47      public void destroy(IWidget widget) {
48          menuBar.removeAll();
49          Container container = menuBar.getParent();
50          if (container != null) {
51              container.remove(menuBar);
52          }
53          menuBar = null;
54      }
55  
56      public Object getNativeWidget() {
57          return this.menuBar;
58      }
59  
60      /**
61       * @see org.xulux.api.gui.IWidgetInitializer#addToParent(org.xulux.api.gui.IWidget)
62       */
63      public boolean addToParent(IWidget widget) {
64          Object nativeParent = widget.getParent().getNativeWidget();
65          if (nativeParent instanceof JFrame) {
66              // we can only be added to a JFrame
67              ((JFrame) nativeParent).setJMenuBar(this.menuBar);
68              return true;
69          }
70          return false;
71      }
72  
73      public void setNativeWidget(Object object) {
74      }
75  
76  }