source: trunk/src/org/expeditee/gio/EcosystemManager.java@ 1097

Last change on this file since 1097 was 1097, checked in by davidb, 6 years ago

Newly structured files from Corey's work on logic/graphics separation

File size: 6.0 KB
Line 
1package org.expeditee.gio;
2
3import org.expeditee.core.Image;
4import org.expeditee.core.TextLayout;
5import org.expeditee.gio.gesture.StandardGestureActions;
6import org.expeditee.gio.gesture.ExpediteeKBMGestureTranslator;
7import org.expeditee.gio.input.StandardInputEventListeners;
8import org.expeditee.gio.javafx.JavaFXEcosystemManager;
9import org.expeditee.gio.swing.SwingEcosystemManager;
10import org.expeditee.items.widgets.Widget;
11
12/**
13 * Central access point for all Graphics/Input/Output managers.
14 *
15 * @author cts16
16 */
17public abstract class EcosystemManager {
18
19 /** Enumeration of the available types of ecosystem. */
20 public static enum Ecosystem {
21 Swing,
22 JavaFX
23 }
24
25 /** The type of GIO ecosystem running in this session. */
26 private static Ecosystem _type;
27
28 /** The clipboard manager in use for this session. */
29 private static ClipboardManager _clipboardManager;
30 /** The image manager in use for this session. */
31 private static ImageManager _imageManager;
32 /** The graphics manager in use for this session. */
33 private static GraphicsManager _graphicsManager;
34 /** The font manager in use for this session. */
35 private static FontManager _fontManager;
36 /** The text-layout manager in use for this session. */
37 private static TextLayoutManager _textLayoutManager;
38 /** The input manager in use for this session. */
39 private static InputManager _inputManager;
40 /** The misc. manager in use for this session. */
41 private static MiscManager _miscManager;
42 /** The drag-and-drop manager in use for this session. */
43 private static DragAndDropManager _dndManager;
44
45 /** Shouldn't be instantiated, static class only. */
46 protected EcosystemManager()
47 {
48 }
49
50 /** Creates an ecosystem for the given ecosystem-type. */
51 public static void createEcosystem(Ecosystem type)
52 {
53 // Remember the ecosystem type for future reference
54 _type = type;
55
56 // Create the ecosystem for the given type
57 if (type == Ecosystem.Swing) {
58 SwingEcosystemManager.createSwingEcosystem();
59 } else if (type == Ecosystem.JavaFX) {
60 JavaFXEcosystemManager.createJavaFXEcosystem();
61 }
62 }
63
64 /** Gets the type of GIO ecosystem running for this session. */
65 public static Ecosystem getType()
66 {
67 return _type;
68 }
69
70 /** Adds an ecosystem-native interactive widget to the ecosystem. */
71 public static void addInteractiveWidget(Widget iw)
72 {
73 // Can't add nothing
74 if (iw == null) return;
75
76 // Only add the widget if it is designed for the current ecosystem
77 if (iw.isSupportedOnCurrentEcosystem()) return;
78
79 // Add the widget to the graphics and input managers
80 _graphicsManager.addInteractiveWidget(iw);
81 _inputManager.addInteractiveWidget(iw);
82 }
83
84 /** Removes an ecosystem-native interactive widget from the ecosystem. */
85 public static void removeInteractiveWidget(Widget iw)
86 {
87 // Can't remove nothing
88 if (iw == null) return;
89
90 // Add the widget to the graphics and input managers
91 _graphicsManager.removeInteractiveWidget(iw);
92 _inputManager.removeInteractiveWidget(iw);
93 }
94
95 /** Sets the clipboard manager for this session. Can only be done once. */
96 public static void setClipboardManager(ClipboardManager clipboardManager)
97 {
98 if (_clipboardManager == null) {
99 _clipboardManager = clipboardManager;
100 }
101 }
102
103 /** Gets the clipboard manager set for this session. */
104 public static ClipboardManager getClipboardManager()
105 {
106 return _clipboardManager;
107 }
108
109 /** Sets the image manager for this session. Can only be done once. */
110 public static void setImageManager(ImageManager imageManager)
111 {
112 if (_imageManager == null) {
113 _imageManager = imageManager;
114 Image.setManager(imageManager);
115 }
116 }
117
118 /** Gets the image manager set for this session. */
119 public static ImageManager getImageManager()
120 {
121 return _imageManager;
122 }
123
124 /** Sets the graphics manager for this session. Can only be done once. */
125 public static void setGraphicsManager(GraphicsManager graphicsManager)
126 {
127 if (_graphicsManager == null) {
128 _graphicsManager = graphicsManager;
129 }
130 }
131
132 /** Gets the graphics manager set for this session. */
133 public static GraphicsManager getGraphicsManager()
134 {
135 return _graphicsManager;
136 }
137
138 /** Sets the font manager for this session. Can only be done once. */
139 public static void setFontManager(FontManager fontManager)
140 {
141 if (_fontManager == null) {
142 _fontManager = fontManager;
143 }
144 }
145
146 /** Gets the font manager set for this session. */
147 public static FontManager getFontManager()
148 {
149 return _fontManager;
150 }
151
152 /** Sets the text-layout manager for this session. Can only be done once. */
153 public static void setTextLayoutManager(TextLayoutManager textLayoutManager)
154 {
155 if (_textLayoutManager == null) {
156 _textLayoutManager = textLayoutManager;
157 TextLayout.setManager(textLayoutManager);
158 }
159 }
160
161 /** Gets the text-layout manager set for this session. */
162 public static TextLayoutManager getTextLayoutManager()
163 {
164 return _textLayoutManager;
165 }
166
167 /** Sets the input manager for this session. Can only be done once. */
168 public static void setInputManager(InputManager inputManager)
169 {
170 if (_inputManager == null) {
171 _inputManager = inputManager;
172 _inputManager.addInputEventToGestureTranslator(new ExpediteeKBMGestureTranslator());
173 _inputManager.registerGestureListener(StandardGestureActions.getInstance());
174 StandardInputEventListeners.registerWith(_inputManager);
175 }
176 }
177
178 /** Gets the input manager set for this session. */
179 public static InputManager getInputManager()
180 {
181 return _inputManager;
182 }
183
184 /** Sets the misc. manager for this session. Can only be done once. */
185 public static void setMiscManager(MiscManager miscManager)
186 {
187 if (_miscManager == null) {
188 _miscManager = miscManager;
189 }
190 }
191
192 /** Gets the misc. manager set for this session. */
193 public static MiscManager getMiscManager()
194 {
195 return _miscManager;
196 }
197
198 /** Sets the drag-and-drop manager for this session. Can only be done once. */
199 public static void setDragAndDropManager(DragAndDropManager dndManager)
200 {
201 if (_dndManager == null) {
202 _dndManager = dndManager;
203 }
204 }
205
206 /** Gets the drag-and-drop manager set for this session. */
207 public static DragAndDropManager getDragAndDropManager()
208 {
209 return _dndManager;
210 }
211}
Note: See TracBrowser for help on using the repository browser.