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.

PlaceholderContainer.java 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.dcc;
  18. import com.dmdirc.FrameContainer;
  19. import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
  20. import com.dmdirc.interfaces.Connection;
  21. import com.dmdirc.interfaces.EventBus;
  22. import com.dmdirc.interfaces.WindowModel;
  23. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  24. import com.dmdirc.ui.WindowManager;
  25. import com.dmdirc.ui.messages.BackBufferFactory;
  26. import java.awt.Dialog.ModalityType;
  27. import java.awt.Window;
  28. import java.util.Collections;
  29. import java.util.Optional;
  30. /**
  31. * Creates a placeholder DCC Frame.
  32. */
  33. public class PlaceholderContainer extends FrameContainer {
  34. /** The plugin which owns this placeholder. */
  35. private final DCCManager plugin;
  36. /** Window that will own new dialogs. */
  37. private final Window parentWindow;
  38. private final WindowManager windowManager;
  39. /**
  40. * Creates a placeholder DCC frame.
  41. *
  42. * @param plugin The plugin which owns this placeholder
  43. * @param config Config manager
  44. * @param parentWindow Window that will parent new dialogs.
  45. * @param eventBus The bus to dispatch events on.
  46. */
  47. public PlaceholderContainer(
  48. final DCCManager plugin,
  49. final AggregateConfigProvider config,
  50. final BackBufferFactory backBufferFactory,
  51. final Window parentWindow,
  52. final WindowManager windowManager,
  53. final EventBus eventBus) {
  54. super("dcc", "DCCs", "DCCs", config, backBufferFactory, eventBus,
  55. Collections.singletonList("com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
  56. this.plugin = plugin;
  57. this.parentWindow = parentWindow;
  58. this.windowManager = windowManager;
  59. initBackBuffer();
  60. }
  61. @Override
  62. public void close() {
  63. int dccs = 0;
  64. for (WindowModel window : windowManager.getChildren(this)) {
  65. if (window instanceof TransferContainer
  66. && ((TransferContainer) window).getDCC().isActive()
  67. || window instanceof ChatContainer
  68. && ((ChatContainer) window).getDCC().isActive()) {
  69. dccs++;
  70. }
  71. }
  72. if (dccs > 0) {
  73. new StandardQuestionDialog(parentWindow, ModalityType.MODELESS,
  74. "Close confirmation",
  75. "Closing this window will cause all existing DCCs "
  76. + "to terminate, are you sure you want to do this?",
  77. () -> { close(); plugin.removeContainer();}).display();
  78. } else {
  79. super.close();
  80. plugin.removeContainer();
  81. }
  82. }
  83. @Override
  84. public Optional<Connection> getConnection() {
  85. return Optional.empty();
  86. }
  87. }