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  
21  import org.bushe.swing.event.annotation.AnnotationProcessor;
22  import org.noos.xing.mydoggy.ToolWindowTab;
23  
24  import ch.elca.el4j.services.gui.swing.wrapper.AbstractWrapperFactory;
25  
26  /**
27   * This class represents a tool window tab in a docking environment.
28   *
29   * @svnLink $Revision: 3884 $;$Date: 2009-08-04 15:48:31 +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/ToolWindowTabApplicationFrame.java $
30   *
31   * @author Stefan Wismer (SWI)
32   */
33  public class ToolWindowTabApplicationFrame implements ApplicationFrame {
34  	/**
35  	 * The representation of a frame in a docking environment.
36  	 */
37  	protected ToolWindowTab m_toolWindowTab;
38  	
39  	/**
40  	 * A descriptor of the content which allows to use the frame (in a limited way) before it's visible.
41  	 */
42  	protected ToolWindowTabConfiguration m_configuration;
43  	
44  	/**
45  	 * @param configuration    A descriptor of the content which allows to use the frame (in a limited way)
46  	 *                         before it's visible.
47  	 */
48  	public ToolWindowTabApplicationFrame(ToolWindowTabConfiguration configuration) {
49  		m_configuration = configuration;
50  	}
51  	
52  	/** {@inheritDoc} */
53  	public JComponent getContent() {
54  		if (m_toolWindowTab == null) {
55  			return m_configuration.getComponent();
56  		} else {
57  			return (JComponent) m_toolWindowTab.getComponent();
58  		}
59  	}
60  	
61  	/** {@inheritDoc} */
62  	public void setContent(JComponent component) {
63  		checkFrame();
64  		m_toolWindowTab.setComponent(component);
65  		
66  		if (component instanceof ApplicationFrameAware) {
67  			ApplicationFrameAware awareComponent = (ApplicationFrameAware) component;
68  			awareComponent.setApplicationFrame(this);
69  		}
70  	}
71  	
72  	/** {@inheritDoc} */
73  	public Object getFrame() {
74  		if (m_toolWindowTab != null && m_toolWindowTab.getDockableManager() == null) {
75  			m_toolWindowTab = null;
76  		}
77  		return m_toolWindowTab;
78  	}
79  	
80  	/** {@inheritDoc} */
81  	public void setFrame(Object frame) {
82  		m_toolWindowTab = (ToolWindowTab) frame;
83  	}
84  	
85  	/** {@inheritDoc} */
86  	public void setName(String name) {
87  		if (m_toolWindowTab == null) {
88  			m_configuration.setId(name);
89  		}
90  		// not supported
91  	}
92  	
93  	/** {@inheritDoc} */
94  	public void setTitle(String title) {
95  		if (m_toolWindowTab == null) {
96  			m_configuration.setTitle(title);
97  		} else {
98  			m_toolWindowTab.setTitle(title);
99  		}
100 	}
101 	
102 	/** {@inheritDoc} */
103 	public void setMinimizable(boolean minimizable) {
104 		checkFrame();
105 		// not supported
106 	}
107 	
108 	/** {@inheritDoc} */
109 	public void setMaximizable(boolean maximizable) {
110 		checkFrame();
111 		// not supported
112 	}
113 	
114 	/** {@inheritDoc} */
115 	public void setClosable(boolean closable) {
116 		checkFrame();
117 		// not supported
118 	}
119 	
120 	/** {@inheritDoc} */
121 	public void setMinimized(boolean minimized) {
122 		checkFrame();
123 		m_toolWindowTab.setMinimized(minimized);
124 	}
125 	
126 	/** {@inheritDoc} */
127 	public void setMaximized(boolean maximized) {
128 		checkFrame();
129 		m_toolWindowTab.setMaximized(maximized);
130 	}
131 	
132 	/** {@inheritDoc} */
133 	public void show() {
134 		// register all event subscribers
135 		AnnotationProcessor.process(getContent());
136 
137 		// not supported
138 	}
139 	
140 	/** {@inheritDoc} */
141 	public void setSelected(boolean selected) {
142 		checkFrame();
143 		m_toolWindowTab.setSelected(selected);
144 	}
145 	
146 	/** {@inheritDoc} */
147 	public void close() {
148 		checkFrame();
149 		if (getContent() != null) {
150 			// unregister all event subscribers
151 			AnnotationProcessor.unsubscribe(getContent());
152 		}
153 		AbstractWrapperFactory.removeWrapper(getContent());
154 		
155 		m_toolWindowTab.getDockableManager().removeToolWindowTab(m_toolWindowTab);
156 		m_toolWindowTab = null;
157 	}
158 	
159 	/**
160 	 * @return    the configuration of the tool window
161 	 */
162 	public ToolWindowTabConfiguration getConfiguration() {
163 		return m_configuration;
164 	}
165 	
166 	/**
167 	 * @param configuration    the configuration of the tool window
168 	 */
169 	public void setConfiguration(ToolWindowTabConfiguration configuration) {
170 		m_configuration = configuration;
171 	}
172 	
173 	/**
174 	 * Check if frame is already set.
175 	 */
176 	private void checkFrame() {
177 		if (m_toolWindowTab == null) {
178 			throw new IllegalStateException("Frame is not yet set.");
179 		}
180 	}
181 }