You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SwingController.java 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing;
  18. import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
  19. import com.dmdirc.addons.ui_swing.commands.Input;
  20. import com.dmdirc.addons.ui_swing.commands.PopInCommand;
  21. import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
  22. import com.dmdirc.addons.ui_swing.commands.ServerSettings;
  23. import com.dmdirc.addons.ui_swing.framemanager.FrameManagerProvider;
  24. import com.dmdirc.addons.ui_swing.injection.SwingModule;
  25. import com.dmdirc.interfaces.ui.UIController;
  26. import com.dmdirc.plugins.Exported;
  27. import com.dmdirc.plugins.PluginInfo;
  28. import com.dmdirc.plugins.implementations.BaseCommandPlugin;
  29. import java.awt.GraphicsEnvironment;
  30. import dagger.ObjectGraph;
  31. /**
  32. * Controls the main swing UI.
  33. */
  34. public class SwingController extends BaseCommandPlugin implements UIController {
  35. /** The manager we're using for dependencies. */
  36. private SwingManager swingManager;
  37. @Override
  38. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  39. super.load(pluginInfo, graph);
  40. setObjectGraph(graph.plus(new SwingModule(this, pluginInfo, pluginInfo.getDomain())));
  41. getObjectGraph().validate();
  42. swingManager = getObjectGraph().get(SwingManager.class);
  43. registerCommand(ServerSettings.class, ServerSettings.INFO);
  44. registerCommand(ChannelSettings.class, ChannelSettings.INFO);
  45. registerCommand(Input.class, Input.INFO);
  46. registerCommand(PopOutCommand.class, PopOutCommand.INFO);
  47. registerCommand(PopInCommand.class, PopInCommand.INFO);
  48. }
  49. @Override
  50. public void onLoad() {
  51. if (GraphicsEnvironment.isHeadless()) {
  52. throw new IllegalStateException(
  53. "Swing UI can't be run in a headless environment");
  54. }
  55. swingManager.load();
  56. super.onLoad();
  57. }
  58. @Override
  59. public void onUnload() {
  60. if (swingManager != null) {
  61. swingManager.unload();
  62. }
  63. super.onUnload();
  64. }
  65. /**
  66. * Returns an instance of SwingController. This method is exported for use in other plugins.
  67. *
  68. * @return A reference to this SwingController.
  69. */
  70. @Exported
  71. public UIController getController() {
  72. return this;
  73. }
  74. /**
  75. * Returns the exported tree manager provider.
  76. *
  77. * @return A tree manager provider.
  78. */
  79. @Exported
  80. public FrameManagerProvider getTreeManager() {
  81. return swingManager.getTreeProvider();
  82. }
  83. }