您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PlaceholderContainer.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2006-2013 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.FrameContainer;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.addons.ui_swing.SwingController;
  26. import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
  27. import com.dmdirc.config.ConfigManager;
  28. import java.awt.Dialog.ModalityType;
  29. import java.util.Arrays;
  30. /**
  31. * Creates a placeholder DCC Frame.
  32. */
  33. public class PlaceholderContainer extends FrameContainer {
  34. /** The plugin which owns this placeholder. */
  35. private final DCCPlugin plugin;
  36. /** Parent swing controller. */
  37. private final SwingController controller;
  38. /**
  39. * Creates a placeholder DCC frame.
  40. *
  41. * @param plugin The plugin which owns this placeholder
  42. * @param config Config manager
  43. * @param controller Swing controller
  44. */
  45. public PlaceholderContainer(final DCCPlugin plugin,
  46. final ConfigManager config, final SwingController controller) {
  47. super("dcc", "DCCs", "DCCs", config, Arrays.asList(
  48. "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
  49. this.plugin = plugin;
  50. this.controller = controller;
  51. }
  52. /** {@inheritDoc} */
  53. @Override
  54. public void close() {
  55. int dccs = 0;
  56. for (FrameContainer window : getChildren()) {
  57. if ((window instanceof TransferContainer
  58. && ((TransferContainer) window).getDCC().isActive())
  59. || (window instanceof ChatContainer
  60. && ((ChatContainer) window).getDCC().isActive())) {
  61. dccs++;
  62. }
  63. }
  64. if (dccs > 0) {
  65. new StandardQuestionDialog(controller, ModalityType.MODELESS,
  66. "Close confirmation",
  67. "Closing this window will cause all existing DCCs "
  68. + "to terminate, are you sure you want to do this?") {
  69. /**
  70. * A version number for this class. It should be changed
  71. * whenever the class structure is changed (or anything else
  72. * that would prevent serialized objects being unserialized
  73. * with the new class).
  74. */
  75. private static final long serialVersionUID = 1;
  76. /** {@inheritDoc} */
  77. @Override
  78. public boolean save() {
  79. PlaceholderContainer.super.close();
  80. return true;
  81. }
  82. /** {@inheritDoc} */
  83. @Override
  84. public void cancelled() {
  85. // Don't close!
  86. }
  87. }.display();
  88. } else {
  89. super.close();
  90. }
  91. }
  92. /** {@inheritDoc} */
  93. @Override
  94. public Server getServer() {
  95. return null;
  96. }
  97. /** {@inheritDoc} */
  98. @Override
  99. public void windowClosing() {
  100. // 2: Remove any callbacks or listeners
  101. // 3: Trigger any actions neccessary
  102. // 4: Trigger action for the window closing
  103. // 5: Inform any parents that the window is closing
  104. plugin.removeContainer();
  105. }
  106. /** {@inheritDoc} */
  107. @Override
  108. public void windowClosed() {
  109. // 7: Remove any references to the window and parents
  110. }
  111. /** {@inheritDoc} */
  112. @Override
  113. public void removeChild(final FrameContainer child) {
  114. super.removeChild(child);
  115. if (getChildren().isEmpty()) {
  116. close();
  117. }
  118. }
  119. }