1 7 package org.ejtools.adwt.service; 8 9 import java.awt.Component ; 10 import java.beans.beancontext.BeanContext ; 11 import java.beans.beancontext.BeanContextServices ; 12 13 import javax.swing.Action ; 14 import javax.swing.JInternalFrame ; 15 import javax.swing.event.InternalFrameEvent ; 16 import javax.swing.event.InternalFrameListener ; 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 31 public class BeanContextInternalFrame extends CustomBeanContextServicesSupport implements InternalFrameListener 32 { 33 34 protected CommandAction action; 35 36 protected JInternalFrame frame; 37 38 protected MDIFrameService service; 39 40 private static Logger logger = Logger.getLogger(BeanContextInternalFrame.class); 41 42 43 44 public BeanContextInternalFrame() 45 { 46 super(); 47 48 this.frame = new JInternalFrame ("", 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 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 e) 77 { 78 } 80 } 81 82 83 84 public void close() 85 { 86 this.frame.doDefaultCloseAction(); 87 } 88 89 90 95 public CommandAction getAction() 96 { 97 return this.action; 98 } 99 100 101 106 public Component getComponent() 107 { 108 return this.frame; 109 } 110 111 112 117 public String getTitle() 118 { 119 return this.frame.getTitle(); 120 } 121 122 123 126 public void internalFrameActivated(InternalFrameEvent event) 127 { 128 this.activate(); 129 } 130 131 132 135 public void internalFrameClosed(InternalFrameEvent event) 136 { 137 BeanContext context = this.getBeanContext(); 138 if (context != null) 139 { 140 context.remove(this); 141 } 142 } 143 144 145 148 public void internalFrameClosing(InternalFrameEvent event) { } 149 150 151 154 public void internalFrameDeactivated(InternalFrameEvent event) { } 155 156 157 160 public void internalFrameDeiconified(InternalFrameEvent event) { } 161 162 163 166 public void internalFrameIconified(InternalFrameEvent event) { } 167 168 169 172 public void internalFrameOpened(InternalFrameEvent event) { } 173 174 175 180 public void setTitle(String title) 181 { 182 this.frame.setTitle(title); 183 this.action.putValue(Action.NAME, title); 184 } 185 186 187 188 protected void initializeBeanContextResources() 189 { 190 super.initializeBeanContextResources(); 191 192 logger.debug("In initializeBeanContextResources"); 193 BeanContextServices context = (BeanContextServices ) 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 208 protected void releaseBeanContextResources() 209 { 210 logger.debug("In releaseBeanContextResources"); 211 BeanContextServices context = (BeanContextServices ) 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 230 protected void releaseServices(BeanContextServices 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 e) 240 { 241 logger.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")"); 242 e.printStackTrace(); 243 } 244 } 245 } 246 247 248 253 protected void useServices(BeanContextServices 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 e) 264 { 265 logger.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")"); 266 e.printStackTrace(); 267 } 268 } 269 } 270 271 } 272 | Popular Tags |