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