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.

ServerFrameFactory.java 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.components.frames;
  18. import com.dmdirc.addons.ui_swing.SwingWindowFactory;
  19. import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputField;
  20. import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
  21. import com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialogFactory;
  22. import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
  23. import com.dmdirc.interfaces.Connection;
  24. import com.dmdirc.events.eventbus.EventBus;
  25. import com.dmdirc.interfaces.WindowModel;
  26. import com.dmdirc.ui.core.components.WindowComponent;
  27. import java.util.Arrays;
  28. import java.util.HashSet;
  29. import java.util.Set;
  30. import javax.inject.Inject;
  31. import javax.inject.Provider;
  32. import javax.inject.Singleton;
  33. import static com.dmdirc.addons.ui_swing.components.frames.TextFrame.TextFrameDependencies;
  34. /**
  35. * Factory for {@link ServerFrame}s
  36. */
  37. @Singleton
  38. public class ServerFrameFactory implements SwingWindowFactory.WindowProvider {
  39. private final Provider<TextFrameDependencies> dependencies;
  40. private final Provider<SwingInputField> inputFieldProvider;
  41. private final Provider<KeyedDialogProvider<Connection, ServerSettingsDialog>> dialogProvider;
  42. private final EventBus eventBus;
  43. private final InputTextFramePasteActionFactory inputTextFramePasteActionFactory;
  44. private final SSLCertificateDialogFactory sslCertificateDialogFactory;
  45. @Inject
  46. public ServerFrameFactory(
  47. final EventBus eventBus,
  48. final Provider<TextFrameDependencies> dependencies,
  49. final Provider<SwingInputField> inputFieldProvider,
  50. final InputTextFramePasteActionFactory inputTextFramePasteActionFactory,
  51. final Provider<KeyedDialogProvider<Connection, ServerSettingsDialog>> dialogProvider,
  52. final SSLCertificateDialogFactory sslCertificateDialogFactory) {
  53. this.eventBus = eventBus;
  54. this.dependencies = dependencies;
  55. this.inputFieldProvider = inputFieldProvider;
  56. this.dialogProvider = dialogProvider;
  57. this.inputTextFramePasteActionFactory = inputTextFramePasteActionFactory;
  58. this.sslCertificateDialogFactory = sslCertificateDialogFactory;
  59. }
  60. @Override
  61. public TextFrame getWindow(final WindowModel container) {
  62. final ServerFrame frame = new ServerFrame(dependencies.get(), inputFieldProvider,
  63. inputTextFramePasteActionFactory, dialogProvider.get(),
  64. sslCertificateDialogFactory, container.getConnection().get());
  65. eventBus.subscribe(frame);
  66. return frame;
  67. }
  68. @Override
  69. public Set<String> getComponents() {
  70. return new HashSet<>(Arrays.asList(
  71. WindowComponent.TEXTAREA.getIdentifier(),
  72. WindowComponent.INPUTFIELD.getIdentifier(),
  73. WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
  74. }
  75. }