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