View Javadoc

1   package ch.elca.el4j.services.gui.swing.mdi;
2   
3   import javax.swing.JMenu;
4   import javax.swing.JMenuItem;
5   import javax.swing.JSeparator;
6   
7   import org.jdesktop.application.Action;
8   import org.jdesktop.application.Application;
9   import org.jdesktop.application.ApplicationContext;
10  
11  
12  /**
13   * JMenu handling the Windows Menu for an MDI application.
14   *
15   * @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/mdi/WindowMenu.java $
16   *
17   * @author Stefan Wismer (SWI)
18   */
19  public class WindowMenu extends JMenu {
20  	/**
21  	 * The MDI window manager.
22  	 */
23  	private WindowManager m_windowManager;
24  
25  	/**
26  	 * A minimal 'Window' menu containing only 'Close All'.
27  	 */
28  	public WindowMenu() {
29  		this(new String[]{"closeAll"});
30  	}
31  	
32  	/**
33  	 * A 'Window' menu containing the specified actions.
34  	 *
35  	 * @param windowMenuActionNames   a list of actions as {@link String}s
36  	 */
37  	public WindowMenu(String[] windowMenuActionNames) {
38  		createMenu("windowMenu", windowMenuActionNames);
39  	}
40  
41  	
42  	/**
43  	 * Set the window manager.
44  	 *
45  	 * @param windowManager   the new window manager
46  	 */
47  	public void setWindowManager(WindowManager windowManager) {
48  		m_windowManager = windowManager;
49  	}
50  	
51  	/**
52  	 * @return    the current MDI window manager
53  	 */
54  	public WindowManager getWindowManager() {
55  		return m_windowManager;
56  	}
57  
58  	/**
59  	 * Create the 'Window' menu.
60  	 * @param menuName       the name of the menu
61  	 * @param actionNames    the actions to be inserted
62  	 */
63  	private void createMenu(String menuName, String[] actionNames) {
64  		setName(menuName);
65  		for (String actionName : actionNames) {
66  			if (actionName.equals("---")) {
67  				add(new JSeparator());
68  			} else {
69  				JMenuItem menuItem = new JMenuItem();
70  				menuItem.setAction(getAction(actionName));
71  				menuItem.setIcon(null);
72  				add(menuItem);
73  			}
74  		}
75  	}
76  
77  	/**
78  	 * @param actionName    the name of the action
79  	 * @return              the action as {@link Action}
80  	 */
81  	private javax.swing.Action getAction(String actionName) {
82  		ApplicationContext ac = Application.getInstance().getContext();
83  		return ac.getActionMap(this).get(actionName);
84  	}
85  
86  	// All major window functions
87  	// Remark: A simple reflection-approach would prevent resource injection,
88  	//         so this approach is a little bit verbose, but it works well.
89  	
90  	/** @see WindowManager */
91  	@Action
92  	public void close() {
93  		if (m_windowManager != null) {
94  			m_windowManager.close();
95  		}
96  	}
97  	
98  	/** @see WindowManager */
99  	@Action
100 	public void closeAll() {
101 		if (m_windowManager != null) {
102 			m_windowManager.closeAll();
103 		}
104 	}
105 	
106 	/** @see WindowManager */
107 	@Action
108 	public void minimize() {
109 		if (m_windowManager != null) {
110 			m_windowManager.minimize();
111 		}
112 	}
113 	
114 	/** @see WindowManager */
115 	@Action
116 	public void minimizeAll() {
117 		if (m_windowManager != null) {
118 			m_windowManager.minimizeAll();
119 		}
120 	}
121 	
122 	/** @see WindowManager */
123 	@Action
124 	public void maximize() {
125 		if (m_windowManager != null) {
126 			m_windowManager.maximize();
127 		}
128 	}
129 	
130 	/** @see WindowManager */
131 	@Action
132 	public void maximizeAll() {
133 		if (m_windowManager != null) {
134 			m_windowManager.maximizeAll();
135 		}
136 	}
137 	
138 	/** @see WindowManager */
139 	@Action
140 	public void restore() {
141 		if (m_windowManager != null) {
142 			m_windowManager.restore();
143 		}
144 	}
145 	
146 	/** @see WindowManager */
147 	@Action
148 	public void restoreAll() {
149 		if (m_windowManager != null) {
150 			m_windowManager.restoreAll();
151 		}
152 	}
153 	
154 	/** @see WindowManager */
155 	@Action
156 	public void hide() {
157 		if (m_windowManager != null) {
158 			m_windowManager.hide();
159 		}
160 	}
161 	
162 	/** @see WindowManager */
163 	@Action
164 	public void hideAll() {
165 		if (m_windowManager != null) {
166 			m_windowManager.hideAll();
167 		}
168 	}
169 	
170 	/** @see WindowManager */
171 	@Action
172 	public void selectNext() {
173 		if (m_windowManager != null) {
174 			m_windowManager.selectNext();
175 		}
176 	}
177 	
178 	/** @see WindowManager */
179 	@Action
180 	public void selectPrevious() {
181 		if (m_windowManager != null) {
182 			m_windowManager.selectPrevious();
183 		}
184 	}
185 	
186 	/** @see WindowManager */
187 	@Action
188 	public void reset() {
189 		if (m_windowManager != null) {
190 			m_windowManager.reset();
191 		}
192 	}
193 	
194 	/** @see WindowManager */
195 	@Action
196 	public void resetAll() {
197 		if (m_windowManager != null) {
198 			m_windowManager.resetAll();
199 		}
200 	}
201 	
202 	/** @see WindowManager */
203 	@Action
204 	public void tileHorizontally() {
205 		if (m_windowManager != null) {
206 			m_windowManager.tileHorizontally();
207 		}
208 	}
209 	
210 	/** @see WindowManager */
211 	@Action
212 	public void tileVertically() {
213 		if (m_windowManager != null) {
214 			m_windowManager.tileVertically();
215 		}
216 	}
217 	
218 	/** @see WindowManager */
219 	@Action
220 	public void tile() {
221 		if (m_windowManager != null) {
222 			m_windowManager.tile();
223 		}
224 	}
225 	
226 	/** @see WindowManager */
227 	@Action
228 	public void cascade() {
229 		if (m_windowManager != null) {
230 			m_windowManager.cascade();
231 		}
232 	}
233 }