KickJava   Java API By Example, From Geeks To Geeks.

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


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.Color JavaDoc;
11 import java.awt.Container JavaDoc;
12 import java.awt.GridLayout JavaDoc;
13 import java.beans.beancontext.BeanContextServices JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 import javax.swing.JFrame JavaDoc;
18 import javax.swing.JLabel JavaDoc;
19 import javax.swing.JOptionPane JavaDoc;
20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.SwingConstants JavaDoc;
22
23 import org.apache.log4j.Logger;
24 import org.ejtools.adwt.action.Command;
25 import org.ejtools.adwt.action.help.AboutAction;
26 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
27
28 /**
29  * Description of the Class
30  *
31  * @author Laurent Etiemble
32  * @version $Revision: 1.5 $
33  * @todo Javadoc to complete
34  * @todo I18N to complete
35  */

36 public class AboutServiceProvider extends CustomBeanContextServiceProvider implements AboutService
37 {
38    /** Description of the Field */
39    protected JPanel JavaDoc panel = null;
40    /** Description of the Field */
41    protected AboutService service = null;
42    /** Description of the Field */
43    private static Logger logger = Logger.getLogger(AboutServiceProvider.class);
44
45
46    /** Constructor for the AboutServiceProvider object */
47    public AboutServiceProvider()
48    {
49       this.service = this;
50    }
51
52
53    /**
54     * Constructor for the AboutServiceProvider object
55     *
56     * @param service Description of Parameter
57     */

58    public AboutServiceProvider(AboutService service)
59    {
60       this.service = service;
61    }
62
63
64    /**
65     * Gets the currentServiceSelectors attribute of the ApplicationServiceProvider object
66     *
67     * @param bcs Description of Parameter
68     * @param serviceClass Description of Parameter
69     * @return The currentServiceSelectors value
70     */

71    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, Class JavaDoc serviceClass)
72    {
73       return (new Vector JavaDoc().iterator());
74    }
75
76
77    /**
78     * Gets the panel attribute of the AboutServiceProvider object
79     *
80     * @return The panel value
81     */

82    public Container JavaDoc getPanel()
83    {
84       if (this.panel == null)
85       {
86          this.createPanel();
87       }
88       return this.panel;
89    }
90
91
92    /**
93     * Gets the service attribute of the ApplicationServiceProvider object
94     *
95     * @param bcs Description of Parameter
96     * @param requestor Description of Parameter
97     * @param serviceClass Description of Parameter
98     * @param serviceSelector Description of Parameter
99     * @return The service value
100     */

101    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Class JavaDoc serviceClass, Object JavaDoc serviceSelector)
102    {
103       return this.service;
104    }
105
106
107    /**
108     * Getter for the title attribute
109     *
110     * @return The value of title attribute
111     * @todo I18N
112     */

113    public String JavaDoc getTitle()
114    {
115       return "About Service";
116    }
117
118
119    /**
120     * Description of the Method
121     *
122     * @param bcs Description of Parameter
123     * @param requestor Description of Parameter
124     * @param service Description of Parameter
125     */

126    public void releaseService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Object JavaDoc service) { }
127
128
129    /**
130     * Description of the Method
131     *
132     * @todo I18N
133     */

134    protected void createPanel()
135    {
136       this.panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
137
138       // North part
139
this.panel.add("North", new JLabel JavaDoc("Insert your logo here"));
140
141       // Center part
142
this.panel.add("Center", new JLabel JavaDoc("This is the default AboutService"));
143
144       // South part
145
JPanel JavaDoc info = new JPanel JavaDoc(new GridLayout JavaDoc(2, 1));
146       JLabel JavaDoc java = new JLabel JavaDoc("Java version:" + System.getProperty("java.version"), SwingConstants.CENTER);
147       java.setForeground(Color.black);
148       info.add(java);
149       JLabel JavaDoc vm = new JLabel JavaDoc("VM:" + System.getProperty("java.vm.name") + ", " + System.getProperty("java.vm.version"), SwingConstants.CENTER);
150       vm.setForeground(Color.black);
151       info.add(vm);
152       this.panel.add("South", info);
153    }
154
155
156    /**
157     * @return The serviceClass value
158     */

159    protected Class JavaDoc[] getServiceClass()
160    {
161       return new Class JavaDoc[]{AboutService.class};
162    }
163
164
165    /** */
166    protected void initializeBeanContextResources()
167    {
168       super.initializeBeanContextResources();
169
170       // Add the About button
171
this.add(new AboutAction(
172          new Command()
173          {
174             public void execute()
175             {
176                AboutServiceProvider.this.show();
177             }
178          }
179          ));
180
181       logger.debug("AboutService added");
182    }
183
184
185    /** Description of the Method */
186    protected void show()
187    {
188       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
189
190       if (context.hasService(FrameService.class))
191       {
192          logger.debug("Using service FrameService...");
193          try
194          {
195             FrameService fservice = (FrameService) context.getService(this, this, FrameService.class, this, this);
196             JFrame JavaDoc frame = (JFrame JavaDoc) fservice.getContainer();
197             // I18N Todo
198
JOptionPane.showMessageDialog(frame, service.getPanel(), service.getTitle(), JOptionPane.PLAIN_MESSAGE);
199             context.releaseService(this, this, FrameService.class);
200          }
201          catch (Exception JavaDoc e)
202          {
203             logger.error("Error during utilisation ofgetBeanContext() service FrameService (" + e.getMessage() + ")");
204          }
205       }
206    }
207 }
208
209
Popular Tags