package org.expeditee.gio; import org.expeditee.core.Image; import org.expeditee.core.TextLayout; import org.expeditee.gio.gesture.ExpediteeKBMGestureTranslator; import org.expeditee.gio.gesture.StandardGestureActions; import org.expeditee.gio.input.StandardInputEventListeners; import org.expeditee.gio.javafx.JavaFXEcosystemManager; import org.expeditee.gio.swing.SwingEcosystemManager; import org.expeditee.items.widgets.Widget; /** * Central access point for all Graphics/Input/Output managers. * * @author cts16 */ public abstract class EcosystemManager { /** Enumeration of the available types of ecosystem. */ public static enum Ecosystem { Swing, JavaFX } /** The type of GIO ecosystem running in this session. */ private static Ecosystem _type; /** The clipboard manager in use for this session. */ private static ClipboardManager _clipboardManager; /** The image manager in use for this session. */ private static ImageManager _imageManager; /** The graphics manager in use for this session. */ private static GraphicsManager _graphicsManager; /** The font manager in use for this session. */ private static FontManager _fontManager; /** The text-layout manager in use for this session. */ private static TextLayoutManager _textLayoutManager; /** The input manager in use for this session. */ private static InputManager _inputManager; /** The misc. manager in use for this session. */ private static MiscManager _miscManager; /** The drag-and-drop manager in use for this session. */ private static DragAndDropManager _dndManager; /** Shouldn't be instantiated, static class only. */ protected EcosystemManager() { } /** Creates an ecosystem for the given ecosystem-type. */ public static void createEcosystem(Ecosystem type) { // Remember the ecosystem type for future reference _type = type; // Create the ecosystem for the given type if (type == Ecosystem.Swing) { SwingEcosystemManager.createSwingEcosystem(); } else if (type == Ecosystem.JavaFX) { JavaFXEcosystemManager.createJavaFXEcosystem(); } } /** Gets the type of GIO ecosystem running for this session. */ public static Ecosystem getType() { return _type; } /** Adds an ecosystem-native interactive widget to the ecosystem. */ public static void addInteractiveWidget(Widget iw) { // Can't add nothing if (iw == null) { return; } // Only add the widget if it is designed for the current ecosystem if (!iw.isSupportedOnCurrentEcosystem()) { return; } // Add the widget to the graphics and input managers _graphicsManager.addInteractiveWidget(iw); _inputManager.addInteractiveWidget(iw); } /** Removes an ecosystem-native interactive widget from the ecosystem. */ public static void removeInteractiveWidget(Widget iw) { // Can't remove nothing if (iw == null) { return; } // Add the widget to the graphics and input managers _graphicsManager.removeInteractiveWidget(iw); _inputManager.removeInteractiveWidget(iw); } /** Sets the clipboard manager for this session. Can only be done once. */ public static void setClipboardManager(ClipboardManager clipboardManager) { if (_clipboardManager == null) { _clipboardManager = clipboardManager; } } /** Gets the clipboard manager set for this session. */ public static ClipboardManager getClipboardManager() { return _clipboardManager; } /** Sets the image manager for this session. Can only be done once. */ public static void setImageManager(ImageManager imageManager) { if (_imageManager == null) { _imageManager = imageManager; Image.setManager(imageManager); } } /** Gets the image manager set for this session. */ public static ImageManager getImageManager() { return _imageManager; } /** Sets the graphics manager for this session. Can only be done once. */ public static void setGraphicsManager(GraphicsManager graphicsManager) { if (_graphicsManager == null) { _graphicsManager = graphicsManager; } } /** Gets the graphics manager set for this session. */ public static GraphicsManager getGraphicsManager() { return _graphicsManager; } /** Sets the font manager for this session. Can only be done once. */ public static void setFontManager(FontManager fontManager) { if (_fontManager == null) { _fontManager = fontManager; } } /** Gets the font manager set for this session. */ public static FontManager getFontManager() { return _fontManager; } /** Sets the text-layout manager for this session. Can only be done once. */ public static void setTextLayoutManager(TextLayoutManager textLayoutManager) { if (_textLayoutManager == null) { _textLayoutManager = textLayoutManager; TextLayout.setManager(textLayoutManager); } } /** Gets the text-layout manager set for this session. */ public static TextLayoutManager getTextLayoutManager() { return _textLayoutManager; } /** Sets the input manager for this session. Can only be done once. */ public static void setInputManager(InputManager inputManager) { if (_inputManager == null) { _inputManager = inputManager; _inputManager.addInputEventToGestureTranslator(new ExpediteeKBMGestureTranslator()); _inputManager.registerGestureListener(StandardGestureActions.getInstance()); StandardInputEventListeners.registerWith(_inputManager); } } /** Gets the input manager set for this session. */ public static InputManager getInputManager() { return _inputManager; } /** Sets the misc. manager for this session. Can only be done once. */ public static void setMiscManager(MiscManager miscManager) { if (_miscManager == null) { _miscManager = miscManager; } } /** Gets the misc. manager set for this session. */ public static MiscManager getMiscManager() { return _miscManager; } /** Sets the drag-and-drop manager for this session. Can only be done once. */ public static void setDragAndDropManager(DragAndDropManager dndManager) { if (_dndManager == null) { _dndManager = dndManager; } } /** Gets the drag-and-drop manager set for this session. */ public static DragAndDropManager getDragAndDropManager() { return _dndManager; } // /** Returns true once all managers are instantiated. */ // public static boolean IsEcosystemReady() { // return _type != null && _clipboardManager != null && _imageManager != null && // _graphicsManager != null && _fontManager != null && _textLayoutManager != null && // _inputManager != null && _miscManager != null && _dndManager != null; // } }