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  
22  import org.xulux.api.gui.IPropertyHandler;
23  import org.xulux.api.gui.IWidget;
24  import org.xulux.api.gui.IWidgetInitializer;
25  import org.xulux.gui.Widget;
26  
27  /**
28   * Initializes the native window
29   *
30   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
31   * @version $Id: $
32   */
33  public class NativeWindow implements IWidgetInitializer {
34  
35      protected JFrame frame;
36      /**
37       * 
38       */
39      public NativeWindow() {
40          super();
41  
42      }
43  
44      /**
45       * @see org.xulux.api.gui.IWidgetInitializer#initialize(org.xulux.api.gui.IWidget)
46       */
47      public void initialize(IWidget widget) {
48          // get a list of init properties..
49          // make this easier!
50          frame = new JFrame();
51  //        List list = ((Widget)widget).getProperties("init");
52          ((Widget) widget).handleProperties(IPropertyHandler.INIT);
53  //        frame.setSize(300,300);
54          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
55          frame.setVisible(true);
56      }
57  
58      /**
59       * @see org.xulux.api.gui.IWidgetInitializer#destroy(org.xulux.api.gui.IWidget)
60       */
61      public void destroy(IWidget widget) {
62          if (frame != null) {
63              frame.removeAll();
64  //            frame.removeWindowListener(windowListener);
65  //            windowListener = null;
66              frame.setVisible(false);
67              Container container = frame.getParent();
68              if (container != null) {
69                  container.remove(frame);
70              }
71              frame.dispose();
72              frame = null;
73            }
74      }
75      
76      public Object getNativeWidget() {
77          return this.frame;
78      }
79  
80      public boolean addToParent(IWidget widget) {
81          return false;
82      }
83  
84      public void setNativeWidget(Object object) {
85      }
86      
87  }