1 7 package org.ejtools.adwt.service; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Container ; 11 import java.awt.event.WindowListener ; 12 import java.beans.beancontext.BeanContextServices ; 13 import java.util.Iterator ; 14 import java.util.Vector ; 15 16 import javax.swing.ImageIcon ; 17 import javax.swing.JFrame ; 18 import javax.swing.JMenuBar ; 19 import javax.swing.JScrollPane ; 20 21 import org.apache.log4j.Logger; 22 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider; 23 24 31 public abstract class FrameServiceProvider extends CustomBeanContextServiceProvider implements FrameService 32 { 33 34 protected JFrame frame = new JFrame (); 35 36 protected JScrollPane scrollPane = new JScrollPane (); 37 38 protected FrameService service = null; 39 40 private static Logger logger = Logger.getLogger(FrameServiceProvider.class); 41 42 43 44 protected FrameServiceProvider() 45 { 46 this.service = this; 47 } 48 49 50 55 public void addWindowListener(WindowListener l) 56 { 57 this.frame.addWindowListener(l); 58 } 59 60 61 62 67 public Container getContainer() 68 { 69 return this.frame; 70 } 71 72 73 74 81 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) 82 { 83 return (new Vector ().iterator()); 84 } 85 86 87 88 97 public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) 98 { 99 return this.service; 100 } 101 102 103 104 111 public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } 112 113 114 115 120 public void removeWindowListener(WindowListener l) 121 { 122 this.frame.removeWindowListener(l); 123 } 124 125 126 127 132 public void setTitle(String title) 133 { 134 this.frame.setTitle(title); 135 } 136 137 138 143 public void update(JMenuBar menuBar) 144 { 145 this.frame.setJMenuBar(menuBar); 146 this.frame.setVisible(true); 147 } 148 149 150 151 protected void initializeBeanContextResources() 152 { 153 super.initializeBeanContextResources(); 154 155 ImageIcon icon = new ImageIcon (this.getClass().getResource("/frameGraphics/ejtools.gif")); 156 if (icon != null) 157 { 158 this.frame.setIconImage(icon.getImage()); 159 } 160 } 161 162 163 164 protected void releaseBeanContextResources() 165 { 166 BeanContextServices context = (BeanContextServices ) getBeanContext(); 167 this.frame.setVisible(false); 168 this.releaseServices(context); 169 170 super.releaseBeanContextResources(); 171 } 172 173 174 179 protected void releaseServices(BeanContextServices context) { } 180 181 182 187 protected void useServices(BeanContextServices context) 188 { 189 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 ) service.getContainer()); 198 } 199 catch (Exception e) 200 { 201 logger.error("Error during utilisation of service MenuBarService (" + e.getMessage() + ")"); 202 e.printStackTrace(); 203 } 204 } 205 206 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 e) 216 { 217 logger.error("Error during utilisation of service ToolBarService (" + e.getMessage() + ")"); 218 e.printStackTrace(); 219 } 220 } 221 222 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 e) 232 { 233 logger.error("Error during utilisation of service StatusBarService (" + e.getMessage() + ")"); 234 e.printStackTrace(); 235 } 236 } 237 } 238 } 239 | Popular Tags |