View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.services.gui.swing;
18  
19  import javax.swing.JComponent;
20  import javax.swing.JDesktopPane;
21  import javax.swing.JInternalFrame;
22  import javax.swing.JLayeredPane;
23  import javax.swing.event.InternalFrameEvent;
24  import javax.swing.event.InternalFrameListener;
25  
26  import org.apache.commons.lang.ArrayUtils;
27  import org.bushe.swing.event.EventBus;
28  
29  import ch.elca.el4j.services.gui.swing.frames.ApplicationFrame;
30  import ch.elca.el4j.services.gui.swing.wrapper.JInteralFrameWrapperFactory;
31  
32  /**
33   * Parent class for new MDI applications using an XML GUI description.
34   * Programmatically written GUI should use {@link MDIApplication}.
35   *
36   *  Additional features:
37   *   * allows adding internal frames (for the Documents of MDI) to the application
38   *      Internal frames can (optionally) minimize themselves
39   *       { @link JInternalFrame#setIconifiable(boolean) }
40   *
41   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/ch/elca/el4j/services/gui/swing/AbstractMDIApplication.java $
42   *
43   * @author Stefan Wismer (SWI)
44   * @author Philipp Oser (POS)
45   */
46  public abstract class AbstractMDIApplication extends GUIApplication {
47  
48  	/**
49  	 * @return    the desktop pane of this MDIApplication
50  	 */
51  	protected abstract JDesktopPane getDesktopPane();
52  	
53  	/**
54  	 * @param component    the panel to show as MDI child window
55  	 */
56  	@Override
57  	public void show(JComponent component) {
58  		show(JInteralFrameWrapperFactory.wrap(component));
59  	}
60  
61  	
62  	/** {@inheritDoc} */
63  	@Override
64  	public void show(ApplicationFrame frame) {
65  		JInternalFrame jiframe = (JInternalFrame) frame.getFrame();
66  		
67  		// (resources are already injected in frame)
68  		/*if (jiframe.getClass().getClassLoader() != null) {
69  			ApplicationContext appContext = Application.getInstance().getContext();
70  			ResourceMap map = appContext.getResourceMap(jiframe.getClass());
71  			
72  			// inject values from properties file
73  			map.injectComponents(jiframe);
74  		}*/
75  		
76  		if (!ArrayUtils.contains(getDesktopPane().getComponents(), jiframe)) {
77  			jiframe.addInternalFrameListener(new ListenerToEvent());
78  		
79  			getDesktopPane().add(jiframe, JLayeredPane.DEFAULT_LAYER);
80  			super.show(frame);
81  		}
82  		
83  		frame.setSelected(true);
84  	}
85  	
86  	/**
87  	 * Helper that listens to events of the internal frames.
88  	 */
89  	protected final class ListenerToEvent implements InternalFrameListener {
90  		/** {@inheritDoc} */
91  		public void internalFrameClosing(InternalFrameEvent e) {
92  			EventBus.publish(e);
93  		}
94  
95  		/** {@inheritDoc} */
96  		public void internalFrameClosed(InternalFrameEvent e) {
97  			EventBus.publish(e);
98  		}
99  
100 		/** {@inheritDoc} */
101 		public void internalFrameOpened(InternalFrameEvent e) {
102 			EventBus.publish(e);
103 		}
104 
105 		/** {@inheritDoc} */
106 		public void internalFrameIconified(InternalFrameEvent e) {
107 			EventBus.publish(e);
108 		}
109 
110 		/** {@inheritDoc} */
111 		public void internalFrameDeiconified(InternalFrameEvent e) {
112 			EventBus.publish(e);
113 		}
114 
115 		/** {@inheritDoc} */
116 		public void internalFrameActivated(InternalFrameEvent e) {
117 			EventBus.publish(e);
118 		}
119 
120 		/** {@inheritDoc} */
121 		public void internalFrameDeactivated(InternalFrameEvent e) {
122 			EventBus.publish(e);
123 		}
124 	}
125 
126 }