1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package fr.ove.openmath.jome.ctrlview.bidim;
30
31 import java.awt.*;
32
33 import org.util.activemath.JomeConstants;
34
35 import com.sun.naming.internal.ResourceManager;
36
37 import fr.ove.openmath.jome.model.*;
38
39 /***
40 * This class instanciates the right display according to the specified formula
41 * tree sturcture.
42 * This is an abstract class. It must be inherited to be specialized.
43 *
44 * @author © 1999 DIRAT Laurent
45 * @version 2.0 01/07/1999
46 */
47
48 public class BidimDisplayAllocator extends DisplayAllocator {
49 /***
50 * The display layout allocator.
51 */
52 private static BidimLayoutAllocator layoutAllocator = new BidimLayoutAllocator();
53
54 /***
55 * The resources manager for the displays
56 */
57 static BidimResourcesManager resourcesManager = new BidimResourcesManager("fr.ove.openmath.jome.ctrlview.bidim.resources");
58
59 /***
60 * Instanciates and creates the right display according to the specified
61 * formula tree structure.
62 * @param fts the formula tree structure which need a display.
63 */
64 public Display allocateDisplay(GraphicContext graphicContext, FormulaTreeStructure fts) {
65 Display display = null;
66
67 String ftsId = fts.getResourceIdentifier();
68 String idDisplay = resourcesManager.getIdDisplay(ftsId);
69
70
71 idDisplay = (idDisplay == null) ? "default" : idDisplay;
72
73
74
75 if (idDisplay.equals("constant")) {
76
77 String value = ((Constant) fts).getValue();
78
79 Object value2 = JomeConstants.SYMBOLS.get(value);
80 if(value2 != null)
81 value = value2.toString();
82
83 display = new StringDisplay(graphicContext, value, false);
84
85
86 display.addControlListener(fts);
87
88 fts.addModelListener(display);
89 }
90 else if (idDisplay.equals("symbol")) {
91
92 display = new SymbolDisplay(graphicContext);
93
94 ImageSymbol symbol = new ImageSymbol(
95
96 ((SymbolDisplay) display).setSymbol(symbol);
97
98
99 display.addControlListener(fts);
100
101 fts.addModelListener(display);
102 }
103 else if (idDisplay.equals("icon")) {
104 if (((Icon) fts).isSubstitution()) {
105
106 display = new SubstitutionDisplay(graphicContext, ((Icon) fts).getIconName());
107 }
108 else {
109
110 display = new IconDisplay(graphicContext);
111
112 ImageSymbol icon = new ImageSymbol(fts.getIconName(), display);
113
114 ((SymbolDisplay) display).setSymbol(icon);
115 }
116
117
118 display.addControlListener(fts);
119
120 fts.addModelListener(display);
121 }
122 else {
123
124 display = new BidimDisplay(graphicContext);
125
126
127 display.addControlListener(fts);
128
129 fts.addModelListener(display);
130
131
132 String layoutName = resourcesManager.getLayoutManager(ftsId);
133 layoutName = (layoutName == null) ? resourcesManager.getLayoutManager("defaultLM") : layoutName;
134
135
136
137 DisplayLayout layout = layoutAllocator.allocateLayout(layoutName);
138 display.setLayout(layout);
139 layout.initDisplay(display);
140 }
141
142 return display;
143 }
144 }