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

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