1 7 package org.ejtools.adwt.service; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Color ; 11 import java.awt.Container ; 12 import java.awt.GridLayout ; 13 import java.beans.beancontext.BeanContextServices ; 14 import java.util.Iterator ; 15 import java.util.Vector ; 16 17 import javax.swing.JFrame ; 18 import javax.swing.JLabel ; 19 import javax.swing.JOptionPane ; 20 import javax.swing.JPanel ; 21 import javax.swing.SwingConstants ; 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 36 public class AboutServiceProvider extends CustomBeanContextServiceProvider implements AboutService 37 { 38 39 protected JPanel panel = null; 40 41 protected AboutService service = null; 42 43 private static Logger logger = Logger.getLogger(AboutServiceProvider.class); 44 45 46 47 public AboutServiceProvider() 48 { 49 this.service = this; 50 } 51 52 53 58 public AboutServiceProvider(AboutService service) 59 { 60 this.service = service; 61 } 62 63 64 71 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) 72 { 73 return (new Vector ().iterator()); 74 } 75 76 77 82 public Container getPanel() 83 { 84 if (this.panel == null) 85 { 86 this.createPanel(); 87 } 88 return this.panel; 89 } 90 91 92 101 public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) 102 { 103 return this.service; 104 } 105 106 107 113 public String getTitle() 114 { 115 return "About Service"; 116 } 117 118 119 126 public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } 127 128 129 134 protected void createPanel() 135 { 136 this.panel = new JPanel (new BorderLayout ()); 137 138 this.panel.add("North", new JLabel ("Insert your logo here")); 140 141 this.panel.add("Center", new JLabel ("This is the default AboutService")); 143 144 JPanel info = new JPanel (new GridLayout (2, 1)); 146 JLabel java = new JLabel ("Java version:" + System.getProperty("java.version"), SwingConstants.CENTER); 147 java.setForeground(Color.black); 148 info.add(java); 149 JLabel vm = new JLabel ("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 159 protected Class [] getServiceClass() 160 { 161 return new Class []{AboutService.class}; 162 } 163 164 165 166 protected void initializeBeanContextResources() 167 { 168 super.initializeBeanContextResources(); 169 170 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 186 protected void show() 187 { 188 BeanContextServices context = (BeanContextServices ) 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 frame = (JFrame ) fservice.getContainer(); 197 JOptionPane.showMessageDialog(frame, service.getPanel(), service.getTitle(), JOptionPane.PLAIN_MESSAGE); 199 context.releaseService(this, this, FrameService.class); 200 } 201 catch (Exception e) 202 { 203 logger.error("Error during utilisation ofgetBeanContext() service FrameService (" + e.getMessage() + ")"); 204 } 205 } 206 } 207 } 208 209 | Popular Tags |