KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > service > BeanContextInternalFrame


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.adwt.service;
8
9 import java.awt.Component JavaDoc;
10 import java.beans.beancontext.BeanContext JavaDoc;
11 import java.beans.beancontext.BeanContextServices JavaDoc;
12
13 import javax.swing.Action JavaDoc;
14 import javax.swing.JInternalFrame JavaDoc;
15 import javax.swing.event.InternalFrameEvent JavaDoc;
16 import javax.swing.event.InternalFrameListener JavaDoc;
17
18 import org.apache.log4j.Logger;
19 import org.ejtools.adwt.action.Command;
20 import org.ejtools.adwt.action.CommandAction;
21 import org.ejtools.adwt.action.window.InternalFrameAction;
22 import org.ejtools.beans.beancontext.CustomBeanContextServicesSupport;
23
24 /**
25  * Description of the Class
26  *
27  * @author Laurent Etiemble
28  * @version $Revision: 1.6 $
29  * @todo Javadoc to complete
30  */

31 public class BeanContextInternalFrame extends CustomBeanContextServicesSupport implements InternalFrameListener JavaDoc
32 {
33    /** Description of the Field */
34    protected CommandAction action;
35    /** Description of the Field */
36    protected JInternalFrame JavaDoc frame;
37    /** Description of the Field */
38    protected MDIFrameService service;
39    /** Description of the Field */
40    private static Logger logger = Logger.getLogger(BeanContextInternalFrame.class);
41
42
43    /** Constructor for the BeanContextInternalFrame object */
44    public BeanContextInternalFrame()
45    {
46       super();
47
48       this.frame = new JInternalFrame JavaDoc("", true, true, true, true);
49       this.frame.addInternalFrameListener(this);
50
51       this.action = new InternalFrameAction(
52          new Command()
53          {
54             public void execute()
55             {
56                BeanContextInternalFrame.this.activate();
57             }
58          });
59    }
60
61
62    /** Description of the Method */
63    public void activate()
64    {
65       try
66       {
67          if (this.service != null)
68          {
69             this.service.activate(this);
70          }
71          if (this.action != null)
72          {
73             this.action.getMenuItem().setSelected(true);
74          }
75       }
76       catch (Exception JavaDoc e)
77       {
78          // Do nothing
79
}
80    }
81
82
83    /** Description of the Method */
84    public void close()
85    {
86       this.frame.doDefaultCloseAction();
87    }
88
89
90    /**
91     * Gets the action attribute of the BeanContextInternalFrame object
92     *
93     * @return The action value
94     */

95    public CommandAction getAction()
96    {
97       return this.action;
98    }
99
100
101    /**
102     * Gets the component attribute of the BeanContextInternalFrame object
103     *
104     * @return The component value
105     */

106    public Component JavaDoc getComponent()
107    {
108       return this.frame;
109    }
110
111
112    /**
113     * Gets the title attribute of the BeanContextInternalFrame object
114     *
115     * @return The title value
116     */

117    public String JavaDoc getTitle()
118    {
119       return this.frame.getTitle();
120    }
121
122
123    /**
124     * @param event Description of the Parameter
125     */

126    public void internalFrameActivated(InternalFrameEvent JavaDoc event)
127    {
128       this.activate();
129    }
130
131
132    /**
133     * @param event Description of the Parameter
134     */

135    public void internalFrameClosed(InternalFrameEvent JavaDoc event)
136    {
137       BeanContext JavaDoc context = this.getBeanContext();
138       if (context != null)
139       {
140          context.remove(this);
141       }
142    }
143
144
145    /**
146     * @param event Description of the Parameter
147     */

148    public void internalFrameClosing(InternalFrameEvent JavaDoc event) { }
149
150
151    /**
152     * @param event Description of the Parameter
153     */

154    public void internalFrameDeactivated(InternalFrameEvent JavaDoc event) { }
155
156
157    /**
158     * @param event Description of the Parameter
159     */

160    public void internalFrameDeiconified(InternalFrameEvent JavaDoc event) { }
161
162
163    /**
164     * @param event Description of the Parameter
165     */

166    public void internalFrameIconified(InternalFrameEvent JavaDoc event) { }
167
168
169    /**
170     * @param event Description of the Parameter
171     */

172    public void internalFrameOpened(InternalFrameEvent JavaDoc event) { }
173
174
175    /**
176     * Sets the title attribute of the BeanContextInternalFrame object
177     *
178     * @param title The new title value
179     */

180    public void setTitle(String JavaDoc title)
181    {
182       this.frame.setTitle(title);
183       this.action.putValue(Action.NAME, title);
184    }
185
186
187    /** Description of the Method */
188    protected void initializeBeanContextResources()
189    {
190       super.initializeBeanContextResources();
191
192       logger.debug("In initializeBeanContextResources");
193       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
194       this.useServices(context);
195
196       if (this.service != null)
197       {
198          this.service.register(this);
199       }
200
201       context.add(action);
202
203       this.activate();
204    }
205
206
207    /** Description of the Method */
208    protected void releaseBeanContextResources()
209    {
210       logger.debug("In releaseBeanContextResources");
211       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
212
213       if (this.service != null)
214       {
215          this.service.unregister(this);
216       }
217
218       context.remove(action);
219       this.releaseServices(context);
220
221       super.releaseBeanContextResources();
222    }
223
224
225    /**
226     * Description of the Method
227     *
228     * @param context Description of the Parameter
229     */

230    protected void releaseServices(BeanContextServices JavaDoc context)
231    {
232       if (context.hasService(MDIFrameService.class))
233       {
234          logger.debug("Using service MDIFrameService...");
235          try
236          {
237             context.releaseService(this, this, MDIFrameService.class);
238          }
239          catch (Exception JavaDoc e)
240          {
241             logger.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")");
242             e.printStackTrace();
243          }
244       }
245    }
246
247
248    /**
249     * Description of the Method
250     *
251     * @param context Description of the Parameter
252     */

253    protected void useServices(BeanContextServices JavaDoc context)
254    {
255       if (context.hasService(MDIFrameService.class))
256       {
257          logger.debug("Using service MDIFrameService...");
258          try
259          {
260             this.service = (MDIFrameService) context.getService(this, this, MDIFrameService.class, this.frame, this);
261             logger.debug("Service MDIFrameService registered");
262          }
263          catch (Exception JavaDoc e)
264          {
265             logger.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")");
266             e.printStackTrace();
267          }
268       }
269    }
270
271 }
272
Popular Tags