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) 2008 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.frames;
18  
19  import java.beans.PropertyVetoException;
20  
21  import javax.swing.JComponent;
22  import javax.swing.JInternalFrame;
23  
24  import org.bushe.swing.event.annotation.AnnotationProcessor;
25  
26  import ch.elca.el4j.services.gui.swing.wrapper.AbstractWrapperFactory;
27  
28  /**
29   * This class represents a frame in a MDI environment.
30   *
31   * @svnLink $Revision: 3878 $;$Date: 2009-08-04 15:06:35 +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/frames/InternalApplicationFrame.java $
32   *
33   * @author Stefan Wismer (SWI)
34   */
35  public class InternalApplicationFrame implements ApplicationFrame {
36  	/**
37  	 * The actual internal frame.
38  	 */
39  	private JInternalFrame m_internalFrame;
40  	
41  	/**
42  	 * @param internalFrame    the internal frame
43  	 */
44  	public InternalApplicationFrame(JInternalFrame internalFrame) {
45  		m_internalFrame = internalFrame;
46  	}
47  	
48  	/** {@inheritDoc} */
49  	public JComponent getContent() {
50  		return (JComponent) m_internalFrame.getContentPane();
51  	}
52  	
53  	/** {@inheritDoc} */
54  	public Object getFrame() {
55  		return m_internalFrame;
56  	}
57  	
58  	/** {@inheritDoc} */
59  	public void setFrame(Object frame) {
60  		m_internalFrame = (JInternalFrame) frame;
61  	}
62  	
63  	/** {@inheritDoc} */
64  	public void setName(String name) {
65  		m_internalFrame.setName(name);
66  	}
67  	
68  	/** {@inheritDoc} */
69  	public void setContent(JComponent component) {
70  		m_internalFrame.setContentPane(component);
71  		
72  		if (component instanceof ApplicationFrameAware) {
73  			ApplicationFrameAware awareComponent = (ApplicationFrameAware) component;
74  			awareComponent.setApplicationFrame(this);
75  		}
76  		
77  		m_internalFrame.setClosable(true);
78  		m_internalFrame.setResizable(true);
79  		m_internalFrame.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
80  		m_internalFrame.pack();
81  	}
82  	
83  	/** {@inheritDoc} */
84  	public void setMinimizable(boolean minimizable) {
85  		m_internalFrame.setIconifiable(minimizable);
86  	}
87  	
88  	/** {@inheritDoc} */
89  	public void setMaximizable(boolean maximizable) {
90  		m_internalFrame.setMaximizable(maximizable);
91  	}
92  	
93  	/** {@inheritDoc} */
94  	public void setClosable(boolean closable) {
95  		m_internalFrame.setClosable(closable);
96  	}
97  	
98  	/** {@inheritDoc} */
99  	public void setTitle(String title) {
100 		m_internalFrame.setTitle(title);
101 	}
102 	
103 	/** {@inheritDoc} */
104 	public void setMinimized(boolean minimized) {
105 		try {
106 			m_internalFrame.setIcon(minimized);
107 		} catch (PropertyVetoException e) {
108 			return;
109 		}
110 	}
111 	
112 	/** {@inheritDoc} */
113 	public void setMaximized(boolean maximized) {
114 		try {
115 			m_internalFrame.setMaximum(maximized);
116 		} catch (PropertyVetoException e) {
117 			return;
118 		}
119 	}
120 	
121 	/** {@inheritDoc} */
122 	public void show() {
123 		// register all event subscribers
124 		AnnotationProcessor.process(getContent());
125 		
126 		m_internalFrame.show();
127 	}
128 	
129 	/** {@inheritDoc} */
130 	public void setSelected(boolean selected) {
131 		try {
132 			m_internalFrame.setSelected(selected);
133 		} catch (PropertyVetoException e) {
134 			return;
135 		}
136 	}
137 	
138 	/** {@inheritDoc} */
139 	public void close() {
140 		if (getContent() != null) {
141 			// unregister all event subscribers
142 			AnnotationProcessor.unsubscribe(getContent());
143 		}
144 		
145 		AbstractWrapperFactory.removeWrapper(getContent());
146 		m_internalFrame.dispose();
147 	}
148 }