Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PlaceholderContainer.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.dcc;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
  26. import com.dmdirc.interfaces.Connection;
  27. import com.dmdirc.interfaces.WindowModel;
  28. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  29. import com.dmdirc.ui.WindowManager;
  30. import com.dmdirc.ui.messages.BackBufferFactory;
  31. import java.awt.Dialog.ModalityType;
  32. import java.awt.Window;
  33. import java.util.Collections;
  34. import java.util.Optional;
  35. /**
  36. * Creates a placeholder DCC Frame.
  37. */
  38. public class PlaceholderContainer extends FrameContainer {
  39. /** The plugin which owns this placeholder. */
  40. private final DCCManager plugin;
  41. /** Window that will own new dialogs. */
  42. private final Window parentWindow;
  43. private final WindowManager windowManager;
  44. /**
  45. * Creates a placeholder DCC frame.
  46. *
  47. * @param plugin The plugin which owns this placeholder
  48. * @param config Config manager
  49. * @param parentWindow Window that will parent new dialogs.
  50. * @param eventBus The bus to dispatch events on.
  51. */
  52. public PlaceholderContainer(
  53. final DCCManager plugin,
  54. final AggregateConfigProvider config,
  55. final BackBufferFactory backBufferFactory,
  56. final Window parentWindow,
  57. final WindowManager windowManager,
  58. final DMDircMBassador eventBus) {
  59. super("dcc", "DCCs", "DCCs", config, backBufferFactory, eventBus,
  60. Collections.singletonList("com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
  61. this.plugin = plugin;
  62. this.parentWindow = parentWindow;
  63. this.windowManager = windowManager;
  64. initBackBuffer();
  65. }
  66. @Override
  67. public void close() {
  68. int dccs = 0;
  69. for (WindowModel window : windowManager.getChildren(this)) {
  70. if (window instanceof TransferContainer
  71. && ((TransferContainer) window).getDCC().isActive()
  72. || window instanceof ChatContainer
  73. && ((ChatContainer) window).getDCC().isActive()) {
  74. dccs++;
  75. }
  76. }
  77. if (dccs > 0) {
  78. new StandardQuestionDialog(parentWindow, ModalityType.MODELESS,
  79. "Close confirmation",
  80. "Closing this window will cause all existing DCCs "
  81. + "to terminate, are you sure you want to do this?",
  82. () -> { close(); plugin.removeContainer();}).display();
  83. } else {
  84. super.close();
  85. plugin.removeContainer();
  86. }
  87. }
  88. @Override
  89. public Optional<Connection> getConnection() {
  90. return Optional.empty();
  91. }
  92. }