View Javadoc

1   package nl.tudelft.simulation.introspection.mapping;
2   
3   import java.awt.Color;
4   import java.awt.Font;
5   import java.util.HashSet;
6   import java.util.Set;
7   
8   import javax.swing.JComponent;
9   
10  import nl.tudelft.simulation.introspection.gui.ExpandButton;
11  
12  /***
13   * A default implementation of the {see CellPresentationConfiguration}
14   * interface. Editors and renders are provided for the JComponent, Color and
15   * Font classes. Furthermore, a special editor is provided for the ExpandButton
16   * class, to implement the pop-up behaviour of the {see
17   * nl.tudelft.simulation.introspection.gui.ExpandButton}.
18   * 
19   * @author (c) 2003 <a href="http://www.tudelft.nl">Delft University of
20   *         Technology </a>, Delft, the Netherlands <br>
21   *         <a href="http://www.tbm.tudelft.nl">Faculty of Technology, Policy and
22   *         Management </a> <br>
23   *         <a href="http://www.sk.tbm.tudelft.nl">Department of System
24   *         Engineering </a> <br>
25   *         Main researcher : <a
26   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/">Dr. Ir. A.
27   *         Verbraeck <a/><br>
28   *         Assistant researchers <a
29   *         href="http://www.tbm.tudelft.nl/webstaf/peterja">Ir. P.H.M. Jacobs
30   *         </a> and <a href="http://www.tbm.tudelft.nl/webstaf/nielsl">Ir. N.A.
31   *         Lang </a>
32   *  
33   */
34  public class DefaultConfiguration implements CellPresentationConfiguration
35  {
36  	/*** the defaultConfiguation */
37  	private static DefaultConfiguration defaultConfig;
38  	static
39  	{
40  		defaultConfig = new DefaultConfiguration();
41  		defaultConfig.addRenderer(JComponent.class, SwingCellRenderer.class);
42  		defaultConfig.addRenderer(Object.class, MyDefaultRenderer.class);
43  		defaultConfig.addRenderer(Color.class, MyColorRenderer.class);
44  		defaultConfig.addEditor(Color.class, MyColorEditor.class);
45  		defaultConfig.addEditor(JComponent.class, SwingCellEditor.class);
46  		defaultConfig.addEditor(Object.class, MyDefaultEditor.class);
47  		defaultConfig.addEditor(ExpandButton.class, ExpandButtonEditor.class);
48  		defaultConfig.addEditor(Font.class, MyFontEditor.class);
49  	}
50  
51  	/*** the renderers */
52  	private Set renderers = new HashSet();
53  
54  	/*** the editors */
55  	private Set editors = new HashSet();
56  
57  	/***
58  	 * @return Returns the defaultConfiguration
59  	 */
60  	public static CellPresentationConfiguration getDefaultConfiguration()
61  	{
62  		return defaultConfig;
63  	}
64  
65  	/***
66  	 * adds a renderer to the configuration
67  	 * 
68  	 * @param cellType the cellType
69  	 * @param renderingClass the renderingClass
70  	 */
71  	protected synchronized void addRenderer(final Class cellType,
72  			final Class renderingClass)
73  	{
74  		this.renderers.add(new Class[]{cellType, renderingClass});
75  	}
76  
77  	/***
78  	 * adds an editingClass to a cellType
79  	 * 
80  	 * @param cellType the cellType
81  	 * @param editingClass an editingClass
82  	 */
83  	protected void addEditor(final Class cellType, final Class editingClass)
84  	{
85  		this.editors.add(new Class[]{cellType, editingClass});
86  	}
87  
88  	/***
89  	 * @see nl.tudelft.simulation.introspection.mapping.CellPresentationConfiguration
90  	 *      #getRenderers()
91  	 */
92  	public Class[][] getRenderers()
93  	{
94  		return (Class[][]) this.renderers.toArray(new Class[0][0]);
95  	}
96  
97  	/***
98  	 * @see nl.tudelft.simulation.introspection.mapping.CellPresentationConfiguration
99  	 *      #getEditors()
100 	 */
101 	public Class[][] getEditors()
102 	{
103 		return (Class[][]) this.editors.toArray(new Class[0][0]);
104 	}
105 }