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.wrapper;
18  
19  import javax.swing.JComponent;
20  import javax.swing.JFrame;
21  
22  import org.noos.xing.mydoggy.ContentManager;
23  
24  import ch.elca.el4j.services.gui.swing.DockingApplication;
25  import ch.elca.el4j.services.gui.swing.GUIApplication;
26  import ch.elca.el4j.services.gui.swing.frames.ContentApplicationFrame;
27  import ch.elca.el4j.services.gui.swing.frames.ContentConfiguration;
28  
29  /**
30   * This factory wraps components into {@link ContentApplicationFrame}s.
31   *
32   * @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/wrapper/ContentWrapperFactory.java $
33   *
34   * @author Stefan Wismer (SWI)
35   */
36  public class ContentWrapperFactory extends AbstractWrapperFactory<ContentApplicationFrame> {
37  	/**
38  	 * The abstract factory.
39  	 */
40  	private static AbstractWrapperFactory<ContentApplicationFrame> s_factory = null;
41  	
42  	/**
43  	 * Wraps a GUI component into a {@link JFrame}.
44  	 *
45  	 * @param component    the component to wrap
46  	 * @return             the wrapper
47  	 */
48  	public static ContentApplicationFrame wrap(JComponent component) {
49  		if (s_factory == null) {
50  			s_factory = new ContentWrapperFactory();
51  		}
52  		return s_factory.wrapComponent(component);
53  	}
54  	
55  	/** {@inheritDoc} */
56  	@Override
57  	protected ContentApplicationFrame createApplicationFrame(String name, String title, JComponent component) {
58  		DockingApplication application = (DockingApplication) GUIApplication.getInstance();
59  		
60  		ContentManager contentManager = application.getToolWindowManager().getContentManager();
61  		
62  		// Does a content already have this name? (names must be unique)
63  		String uniqueName = title;
64  		if (contentManager.getContent(uniqueName) != null) {
65  			int index = 1;
66  			while (contentManager.getContent(uniqueName + " (" + index + ")") != null) {
67  				index++;
68  			}
69  			uniqueName = uniqueName + " (" + index + ")";
70  		}
71  		
72  		ContentConfiguration contentDescriptor = new ContentConfiguration(uniqueName, title, null, component);
73  		
74  		return new ContentApplicationFrame(contentDescriptor);
75  	}
76  }