KickJava   Java API By Example, From Geeks To Geeks.

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


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.BorderLayout JavaDoc;
10 import java.awt.Container JavaDoc;
11 import java.awt.event.WindowListener JavaDoc;
12 import java.beans.beancontext.BeanContextServices JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import javax.swing.ImageIcon JavaDoc;
17 import javax.swing.JFrame JavaDoc;
18 import javax.swing.JMenuBar JavaDoc;
19 import javax.swing.JScrollPane JavaDoc;
20
21 import org.apache.log4j.Logger;
22 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
23
24 /**
25  * Description of the Class
26  *
27  * @author Laurent Etiemble
28  * @version $Revision: 1.5 $
29  * @todo Javadoc to complete
30  */

31 public abstract class FrameServiceProvider extends CustomBeanContextServiceProvider implements FrameService
32 {
33    /** Description of the Field */
34    protected JFrame JavaDoc frame = new JFrame JavaDoc();
35    /** Description of the Field */
36    protected JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc();
37    /** Description of the Field */
38    protected FrameService service = null;
39    /** Description of the Field */
40    private static Logger logger = Logger.getLogger(FrameServiceProvider.class);
41
42
43    /**Constructor for the FrameServiceProvider object */
44    protected FrameServiceProvider()
45    {
46       this.service = this;
47    }
48
49
50    /**
51     * Adds a feature to the WindowListener attribute of the FrameServiceProvider object
52     *
53     * @param l The feature to be added to the WindowListener attribute
54     */

55    public void addWindowListener(WindowListener JavaDoc l)
56    {
57       this.frame.addWindowListener(l);
58    }
59
60
61
62    /**
63     * Gets the container attribute of the FrameServiceProvider object
64     *
65     * @return The container value
66     */

67    public Container JavaDoc getContainer()
68    {
69       return this.frame;
70    }
71
72
73
74    /**
75     * Gets the currentServiceSelectors attribute of the ApplicationServiceProvider object
76     *
77     * @param bcs Description of Parameter
78     * @param serviceClass Description of Parameter
79     * @return The currentServiceSelectors value
80     */

81    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, Class JavaDoc serviceClass)
82    {
83       return (new Vector JavaDoc().iterator());
84    }
85
86
87
88    /**
89     * Gets the service attribute of the ApplicationServiceProvider object
90     *
91     * @param bcs Description of Parameter
92     * @param requestor Description of Parameter
93     * @param serviceClass Description of Parameter
94     * @param serviceSelector Description of Parameter
95     * @return The service value
96     */

97    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Class JavaDoc serviceClass, Object JavaDoc serviceSelector)
98    {
99       return this.service;
100    }
101
102
103
104    /**
105     * Description of the Method
106     *
107     * @param bcs Description of Parameter
108     * @param requestor Description of Parameter
109     * @param service Description of Parameter
110     */

111    public void releaseService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Object JavaDoc service) { }
112
113
114
115    /**
116     * Description of the Method
117     *
118     * @param l Description of Parameter
119     */

120    public void removeWindowListener(WindowListener JavaDoc l)
121    {
122       this.frame.removeWindowListener(l);
123    }
124
125
126
127    /**
128     * Setter for the title attribute
129     *
130     * @param title The new value
131     */

132    public void setTitle(String JavaDoc title)
133    {
134       this.frame.setTitle(title);
135    }
136
137
138    /**
139     * Description of the Method
140     *
141     * @param menuBar Description of Parameter
142     */

143    public void update(JMenuBar JavaDoc menuBar)
144    {
145       this.frame.setJMenuBar(menuBar);
146       this.frame.setVisible(true);
147    }
148
149
150    /** Description of the Method */
151    protected void initializeBeanContextResources()
152    {
153       super.initializeBeanContextResources();
154
155       ImageIcon JavaDoc icon = new ImageIcon JavaDoc(this.getClass().getResource("/frameGraphics/ejtools.gif"));
156       if (icon != null)
157       {
158          this.frame.setIconImage(icon.getImage());
159       }
160    }
161
162
163    /** Description of the Method */
164    protected void releaseBeanContextResources()
165    {
166       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
167       this.frame.setVisible(false);
168       this.releaseServices(context);
169
170       super.releaseBeanContextResources();
171    }
172
173
174    /**
175     * Description of the Method
176     *
177     * @param context Description of Parameter
178     */

179    protected void releaseServices(BeanContextServices JavaDoc context) { }
180
181
182    /**
183     * Description of the Method
184     *
185     * @param context Description of Parameter
186     */

187    protected void useServices(BeanContextServices JavaDoc context)
188    {
189       // Set up MenuBar
190
if (context.hasService(MenuBarService.class))
191       {
192          logger.debug("Using service MenuBarService...");
193          try
194          {
195             MenuBarService service = (MenuBarService) context.getService(this, this, MenuBarService.class, this.frame, this);
196             service.addMenuBarListener(this);
197             frame.setJMenuBar((JMenuBar JavaDoc) service.getContainer());
198          }
199          catch (Exception JavaDoc e)
200          {
201             logger.error("Error during utilisation of service MenuBarService (" + e.getMessage() + ")");
202             e.printStackTrace();
203          }
204       }
205
206       // Set up ToolBar
207
if (context.hasService(ToolBarService.class))
208       {
209          logger.debug("Using service ToolBarService...");
210          try
211          {
212             ToolBarService service = (ToolBarService) context.getService(this, this, ToolBarService.class, this.frame, this);
213             frame.getContentPane().add(BorderLayout.NORTH, service.getContainer());
214          }
215          catch (Exception JavaDoc e)
216          {
217             logger.error("Error during utilisation of service ToolBarService (" + e.getMessage() + ")");
218             e.printStackTrace();
219          }
220       }
221
222       // Set up StatusBar
223
if (context.hasService(StatusBarService.class))
224       {
225          logger.debug("Using service StatusBarService...");
226          try
227          {
228             StatusBarService service = (StatusBarService) context.getService(this, this, StatusBarService.class, this.frame, this);
229             frame.getContentPane().add(BorderLayout.SOUTH, service.getContainer());
230          }
231          catch (Exception JavaDoc e)
232          {
233             logger.error("Error during utilisation of service StatusBarService (" + e.getMessage() + ")");
234             e.printStackTrace();
235          }
236       }
237    }
238 }
239
Popular Tags