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.WindowEvent;
19  import java.awt.event.WindowListener;
20  
21  import org.xulux.api.gui.IWidget;
22  import org.xulux.gui.GuiUtils;
23  import org.xulux.gui.XuluxListener;
24  
25  /**
26   * A WindowListener to make sure we pass control
27   * back to the main application when someone hits
28   * the X button.
29   *
30   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
31   * @version $Id: XuluxWindowListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $
32   */
33  public class XuluxWindowListener extends XuluxListener implements WindowListener {
34  
35      /**
36       * Specifies if the window should be destroyed when
37       * the window is deactived
38       */
39      private boolean shouldDestroy = false;
40  
41      /**
42       * Constructor for XuluxWindowListener.
43       */
44      public XuluxWindowListener() {
45          super();
46      }
47  
48      /**
49       * Constructor for XuluxWindowListener.
50       * @param widget the widget
51       */
52      public XuluxWindowListener(IWidget widget) {
53          super(widget);
54          System.err.println("window listener constructor called");
55      }
56  
57      /**
58       * @see java.awt.event.WindowListener#windowActivated(WindowEvent)
59       */
60      public void windowActivated(WindowEvent e) {
61          System.out.println("Window activated : " + e);
62      }
63  
64      /**
65       * @see java.awt.event.WindowListener#windowClosed(WindowEvent)
66       */
67      public void windowClosed(WindowEvent e) {
68          System.err.println("Window closed : " + e);
69      }
70  
71      /**
72       * Specifies that the window should be destroyed, if followed
73       * by a windowDeactivated event.
74       *
75       * @see java.awt.event.WindowListener#windowClosing(WindowEvent)
76       */
77      public void windowClosing(WindowEvent e) {
78          System.out.println("Window closing : " + e);
79          shouldDestroy = true;
80      }
81  
82      /**
83       * If the window was previously closing, complete and destroy
84       * the widget
85       *
86       * @see java.awt.event.WindowListener#windowDeactivated(WindowEvent)
87       */
88      public void windowDeactivated(WindowEvent e) {
89          if (!shouldDestroy) {
90              return;
91          }
92          GuiUtils.processCancel(widget);
93          completed();
94          getWidget().destroy();
95          this.widget = null;
96      }
97  
98      /**
99       * @see java.awt.event.WindowListener#windowDeiconified(WindowEvent)
100      */
101     public void windowDeiconified(WindowEvent e) {
102         System.out.println("Window deIconified : " + e);
103     }
104 
105     /**
106      * @see java.awt.event.WindowListener#windowIconified(WindowEvent)
107      */
108     public void windowIconified(WindowEvent e) {
109         System.out.println("Window iconified: " + e);
110     }
111 
112     /**
113      * @see java.awt.event.WindowListener#windowOpened(WindowEvent)
114      */
115     public void windowOpened(WindowEvent e) {
116         System.out.println("Window opened : " + e);
117     }
118 
119 }