1 | // Module : $RCSfile: GUIModelFactory.java,v $ |
---|
2 | // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 13.05.2012 $ |
---|
3 | // Project : JavaInteractionParser |
---|
4 | // Creation : 2012 by patrick |
---|
5 | // Copyright : Patrick Harms, 2012 |
---|
6 | |
---|
7 | package de.ugoe.cs.quest.plugin.jfc.guimodel; |
---|
8 | |
---|
9 | import java.util.logging.Logger; |
---|
10 | |
---|
11 | import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElementFactory; |
---|
12 | import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; |
---|
13 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModelConfigurationException; |
---|
14 | import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; |
---|
15 | |
---|
16 | /** |
---|
17 | * TODO comment |
---|
18 | * |
---|
19 | * @version $Revision: $ $Date: 13.05.2012$ |
---|
20 | * @author 2012, last modified by $Author: patrick$ |
---|
21 | */ |
---|
22 | public class JFCGUIElementFactory extends AbstractDefaultGUIElementFactory { |
---|
23 | |
---|
24 | /** */ |
---|
25 | private static JFCGUIElementFactory instance = new JFCGUIElementFactory(); |
---|
26 | |
---|
27 | /** |
---|
28 | * TODO: comment |
---|
29 | * |
---|
30 | */ |
---|
31 | private JFCGUIElementFactory() { |
---|
32 | super(); |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * TODO: comment |
---|
37 | * |
---|
38 | * @return |
---|
39 | */ |
---|
40 | public static synchronized JFCGUIElementFactory getInstance() { |
---|
41 | return instance; |
---|
42 | } |
---|
43 | |
---|
44 | /* (non-Javadoc) |
---|
45 | * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementFactory#instantiateGUIElement(IGUIElementSpec) |
---|
46 | */ |
---|
47 | @Override |
---|
48 | public IGUIElement instantiateGUIElement(IGUIElementSpec specification) { |
---|
49 | if (!(specification instanceof JFCGUIElementSpec)) { |
---|
50 | throw new IllegalArgumentException |
---|
51 | ("can only process gui element specifications of type JFCHGUIElementSpec"); |
---|
52 | } |
---|
53 | |
---|
54 | JFCGUIElementSpec jfcGuiElemSpec = (JFCGUIElementSpec) specification; |
---|
55 | |
---|
56 | return createNewGUIElementInternal(jfcGuiElemSpec); |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * TODO: comment |
---|
61 | * |
---|
62 | * @param name |
---|
63 | * @param type |
---|
64 | * @param icon |
---|
65 | * @param index |
---|
66 | * @param hash |
---|
67 | * @return |
---|
68 | */ |
---|
69 | private synchronized JFCGUIElement createNewGUIElementInternal(JFCGUIElementSpec specification) |
---|
70 | { |
---|
71 | JFCGUIElement retVal = null; |
---|
72 | |
---|
73 | IGUIElement guiElement = null; |
---|
74 | try { |
---|
75 | guiElement = super.instantiateGUIElementFromConfiguredMappings(specification); |
---|
76 | } |
---|
77 | catch (GUIModelConfigurationException e) { |
---|
78 | throw new IllegalArgumentException |
---|
79 | ("detected a configuration error in the GUI element mapping", e); |
---|
80 | } |
---|
81 | |
---|
82 | if ((guiElement != null) && (!(guiElement instanceof JFCGUIElement))) { |
---|
83 | Logger.getLogger(this.getClass().getName()).warning |
---|
84 | ("configured GUI element representing class " + |
---|
85 | guiElement.getClass().getName() + " is no valid GUIElement derivate."); |
---|
86 | } |
---|
87 | else { |
---|
88 | retVal = (JFCGUIElement) guiElement; |
---|
89 | } |
---|
90 | |
---|
91 | String type = specification.getType(); |
---|
92 | |
---|
93 | if (retVal == null) { |
---|
94 | if ("javax.swing.JPanel".equals(type)) { |
---|
95 | retVal = new JFCPanel(specification); |
---|
96 | } |
---|
97 | else if ("javax.swing.JRootPane".equals(type)) { |
---|
98 | retVal = new JFCPanel(specification); |
---|
99 | } |
---|
100 | else if ("javax.swing.JLayeredPane".equals(type)) { |
---|
101 | retVal = new JFCPanel(specification); |
---|
102 | } |
---|
103 | else if ("javax.swing.JTabbedPane".equals(type)) { |
---|
104 | retVal = new JFCTabbedPane(specification); |
---|
105 | } |
---|
106 | else if ("javax.swing.JScrollPane".equals(type)) { |
---|
107 | retVal = new JFCScrollPane(specification); |
---|
108 | } |
---|
109 | else if ("javax.swing.JViewport".equals(type)) { |
---|
110 | retVal = new JFCPanel(specification); |
---|
111 | } |
---|
112 | else if ("javax.swing.JScrollPane$ScrollBar".equals(type)) { |
---|
113 | retVal = new JFCScrollBar(specification); |
---|
114 | } |
---|
115 | else if ("javax.swing.JMenu".equals(type)) { |
---|
116 | retVal = new JFCMenu(specification); |
---|
117 | } |
---|
118 | else if ("javax.swing.JMenu$1".equals(type)) { |
---|
119 | retVal = new JFCMenu(specification); |
---|
120 | } |
---|
121 | else if ("javax.swing.JDialog".equals(type)) { |
---|
122 | retVal = new JFCDialog(specification); |
---|
123 | } |
---|
124 | else if ("javax.swing.JFileChooser".equals(type)) { |
---|
125 | retVal = new JFCDialog(specification); |
---|
126 | } |
---|
127 | else if ("javax.swing.plaf.metal.MetalFileChooserUI$3".equals(type)) { |
---|
128 | retVal = new JFCPanel(specification); |
---|
129 | } |
---|
130 | else { |
---|
131 | throw new IllegalArgumentException |
---|
132 | ("could not find a GUIElement representation for type specification " + type); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | return retVal; |
---|
137 | } |
---|
138 | |
---|
139 | } |
---|