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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.util.URLBuilder;
  29. import java.awt.Dialog.ModalityType;
  30. import java.awt.Window;
  31. import java.util.Arrays;
  32. /**
  33. * Creates a placeholder DCC Frame.
  34. */
  35. public class PlaceholderContainer extends FrameContainer {
  36. /** The plugin which owns this placeholder. */
  37. private final DCCManager plugin;
  38. /** Window that will own new dialogs. */
  39. private final Window parentWindow;
  40. /**
  41. * Creates a placeholder DCC frame.
  42. *
  43. * @param plugin The plugin which owns this placeholder
  44. * @param config Config manager
  45. * @param parentWindow Window that will parent new dialogs.
  46. * @param urlBuilder The URL builder to use when finding icons.
  47. * @param eventBus The bus to dispatch events on.
  48. */
  49. public PlaceholderContainer(
  50. final DCCManager plugin,
  51. final AggregateConfigProvider config,
  52. final Window parentWindow,
  53. final URLBuilder urlBuilder,
  54. final DMDircMBassador eventBus) {
  55. super(null, "dcc", "DCCs", "DCCs", config, urlBuilder, eventBus,
  56. Arrays.asList("com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
  57. this.plugin = plugin;
  58. this.parentWindow = parentWindow;
  59. }
  60. @Override
  61. public void close() {
  62. int dccs = 0;
  63. for (FrameContainer window : getChildren()) {
  64. if ((window instanceof TransferContainer
  65. && ((TransferContainer) window).getDCC().isActive())
  66. || (window instanceof ChatContainer
  67. && ((ChatContainer) window).getDCC().isActive())) {
  68. dccs++;
  69. }
  70. }
  71. if (dccs > 0) {
  72. new StandardQuestionDialog(parentWindow, ModalityType.MODELESS,
  73. "Close confirmation",
  74. "Closing this window will cause all existing DCCs "
  75. + "to terminate, are you sure you want to do this?") {
  76. /**
  77. * A version number for this class. It should be changed whenever the class
  78. * structure is changed (or anything else that would prevent serialized
  79. * objects being unserialized with the new class).
  80. */
  81. private static final long serialVersionUID = 1;
  82. @Override
  83. public boolean save() {
  84. PlaceholderContainer.super.close();
  85. plugin.removeContainer();
  86. return true;
  87. }
  88. @Override
  89. public void cancelled() {
  90. // Don't close!
  91. }
  92. }.display();
  93. } else {
  94. super.close();
  95. plugin.removeContainer();
  96. }
  97. }
  98. @Override
  99. public Connection getConnection() {
  100. return null;
  101. }
  102. @Override
  103. public void removeChild(final FrameContainer child) {
  104. super.removeChild(child);
  105. if (getChildren().isEmpty()) {
  106. close();
  107. }
  108. }
  109. }