[1097] | 1 | package org.expeditee.gio;
|
---|
| 2 |
|
---|
| 3 | import org.expeditee.core.Image;
|
---|
| 4 | import org.expeditee.core.TextLayout;
|
---|
[1161] | 5 | import org.expeditee.gio.gesture.ExpediteeKBMGestureTranslator;
|
---|
[1097] | 6 | import org.expeditee.gio.gesture.StandardGestureActions;
|
---|
| 7 | import org.expeditee.gio.input.StandardInputEventListeners;
|
---|
| 8 | import org.expeditee.gio.javafx.JavaFXEcosystemManager;
|
---|
| 9 | import org.expeditee.gio.swing.SwingEcosystemManager;
|
---|
| 10 | import org.expeditee.items.widgets.Widget;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Central access point for all Graphics/Input/Output managers.
|
---|
| 14 | *
|
---|
| 15 | * @author cts16
|
---|
| 16 | */
|
---|
| 17 | public 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
|
---|
[1161] | 74 | if (iw == null) {
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
[1097] | 77 |
|
---|
| 78 | // Only add the widget if it is designed for the current ecosystem
|
---|
[1161] | 79 | if (!iw.isSupportedOnCurrentEcosystem()) {
|
---|
| 80 | return;
|
---|
| 81 | }
|
---|
[1097] | 82 |
|
---|
| 83 | // Add the widget to the graphics and input managers
|
---|
| 84 | _graphicsManager.addInteractiveWidget(iw);
|
---|
| 85 | _inputManager.addInteractiveWidget(iw);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /** Removes an ecosystem-native interactive widget from the ecosystem. */
|
---|
| 89 | public static void removeInteractiveWidget(Widget iw)
|
---|
| 90 | {
|
---|
| 91 | // Can't remove nothing
|
---|
[1161] | 92 | if (iw == null) {
|
---|
| 93 | return;
|
---|
| 94 | }
|
---|
[1097] | 95 |
|
---|
| 96 | // Add the widget to the graphics and input managers
|
---|
| 97 | _graphicsManager.removeInteractiveWidget(iw);
|
---|
| 98 | _inputManager.removeInteractiveWidget(iw);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | /** Sets the clipboard manager for this session. Can only be done once. */
|
---|
| 102 | public static void setClipboardManager(ClipboardManager clipboardManager)
|
---|
| 103 | {
|
---|
| 104 | if (_clipboardManager == null) {
|
---|
| 105 | _clipboardManager = clipboardManager;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /** Gets the clipboard manager set for this session. */
|
---|
| 110 | public static ClipboardManager getClipboardManager()
|
---|
| 111 | {
|
---|
| 112 | return _clipboardManager;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /** Sets the image manager for this session. Can only be done once. */
|
---|
| 116 | public static void setImageManager(ImageManager imageManager)
|
---|
| 117 | {
|
---|
| 118 | if (_imageManager == null) {
|
---|
| 119 | _imageManager = imageManager;
|
---|
| 120 | Image.setManager(imageManager);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | /** Gets the image manager set for this session. */
|
---|
| 125 | public static ImageManager getImageManager()
|
---|
| 126 | {
|
---|
| 127 | return _imageManager;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /** Sets the graphics manager for this session. Can only be done once. */
|
---|
| 131 | public static void setGraphicsManager(GraphicsManager graphicsManager)
|
---|
| 132 | {
|
---|
| 133 | if (_graphicsManager == null) {
|
---|
| 134 | _graphicsManager = graphicsManager;
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | /** Gets the graphics manager set for this session. */
|
---|
| 139 | public static GraphicsManager getGraphicsManager()
|
---|
| 140 | {
|
---|
| 141 | return _graphicsManager;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /** Sets the font manager for this session. Can only be done once. */
|
---|
| 145 | public static void setFontManager(FontManager fontManager)
|
---|
| 146 | {
|
---|
| 147 | if (_fontManager == null) {
|
---|
| 148 | _fontManager = fontManager;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /** Gets the font manager set for this session. */
|
---|
| 153 | public static FontManager getFontManager()
|
---|
| 154 | {
|
---|
| 155 | return _fontManager;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | /** Sets the text-layout manager for this session. Can only be done once. */
|
---|
| 159 | public static void setTextLayoutManager(TextLayoutManager textLayoutManager)
|
---|
| 160 | {
|
---|
| 161 | if (_textLayoutManager == null) {
|
---|
| 162 | _textLayoutManager = textLayoutManager;
|
---|
| 163 | TextLayout.setManager(textLayoutManager);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | /** Gets the text-layout manager set for this session. */
|
---|
| 168 | public static TextLayoutManager getTextLayoutManager()
|
---|
| 169 | {
|
---|
| 170 | return _textLayoutManager;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /** Sets the input manager for this session. Can only be done once. */
|
---|
| 174 | public static void setInputManager(InputManager inputManager)
|
---|
| 175 | {
|
---|
| 176 | if (_inputManager == null) {
|
---|
| 177 | _inputManager = inputManager;
|
---|
| 178 | _inputManager.addInputEventToGestureTranslator(new ExpediteeKBMGestureTranslator());
|
---|
| 179 | _inputManager.registerGestureListener(StandardGestureActions.getInstance());
|
---|
| 180 | StandardInputEventListeners.registerWith(_inputManager);
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | /** Gets the input manager set for this session. */
|
---|
| 185 | public static InputManager getInputManager()
|
---|
| 186 | {
|
---|
| 187 | return _inputManager;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | /** Sets the misc. manager for this session. Can only be done once. */
|
---|
| 191 | public static void setMiscManager(MiscManager miscManager)
|
---|
| 192 | {
|
---|
| 193 | if (_miscManager == null) {
|
---|
| 194 | _miscManager = miscManager;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | /** Gets the misc. manager set for this session. */
|
---|
| 199 | public static MiscManager getMiscManager()
|
---|
| 200 | {
|
---|
| 201 | return _miscManager;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | /** Sets the drag-and-drop manager for this session. Can only be done once. */
|
---|
| 205 | public static void setDragAndDropManager(DragAndDropManager dndManager)
|
---|
| 206 | {
|
---|
| 207 | if (_dndManager == null) {
|
---|
| 208 | _dndManager = dndManager;
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /** Gets the drag-and-drop manager set for this session. */
|
---|
| 213 | public static DragAndDropManager getDragAndDropManager()
|
---|
| 214 | {
|
---|
| 215 | return _dndManager;
|
---|
| 216 | }
|
---|
[1106] | 217 |
|
---|
[1112] | 218 | // /** Returns true once all managers are instantiated. */
|
---|
| 219 | // public static boolean IsEcosystemReady() {
|
---|
| 220 | // return _type != null && _clipboardManager != null && _imageManager != null &&
|
---|
| 221 | // _graphicsManager != null && _fontManager != null && _textLayoutManager != null &&
|
---|
| 222 | // _inputManager != null && _miscManager != null && _dndManager != null;
|
---|
| 223 | // }
|
---|
[1097] | 224 | }
|
---|