Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PlaceholderContainer.java 3.9KB

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