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

CustomWindow.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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;
  23. import com.dmdirc.config.ConfigManager;
  24. import com.dmdirc.config.IdentityManager;
  25. import com.dmdirc.ui.WindowManager;
  26. import com.dmdirc.ui.interfaces.Window;
  27. /**
  28. * A generic custom window implementation.
  29. *
  30. * @author chris
  31. */
  32. public class CustomWindow extends FrameContainer {
  33. /** This custom window's name. */
  34. private final String name;
  35. /** This custom window's title. */
  36. private final String title;
  37. /** The window used by this container. */
  38. private Window window;
  39. /** This window's parent window. */
  40. private Window parent = null;
  41. /**
  42. * Creates a new custom window as a child of the specified window.
  43. *
  44. * @param name The name of this custom window
  45. * @param title The title of this custom window
  46. * @param parent The parent of this custom window
  47. */
  48. public CustomWindow(final String name, final String title,
  49. final Window parent) {
  50. super();
  51. this.name = name;
  52. this.title = title;
  53. this.parent = parent;
  54. icon = IconManager.getIconManager().getIcon("custom");
  55. window = Main.getUI().getWindow(this);
  56. window.setTitle(title);
  57. window.setFrameIcon(icon);
  58. WindowManager.addWindow(parent, window);
  59. window.setVisible(true);
  60. }
  61. /**
  62. * Creates a new custom window as a top-level window.
  63. *
  64. * @param name The name of this custom window
  65. * @param title The parent of this custom window
  66. */
  67. public CustomWindow(final String name, final String title) {
  68. super();
  69. this.name = name;
  70. this.title = title;
  71. icon = IconManager.getIconManager().getIcon("custom");
  72. window = Main.getUI().getWindow(this);
  73. window.setTitle(title);
  74. window.setFrameIcon(icon);
  75. WindowManager.addWindow(window);
  76. window.setVisible(true);
  77. }
  78. /** {@inheritDoc} */
  79. @Override
  80. public Window getFrame() {
  81. return window;
  82. }
  83. /** {@inheritDoc} */
  84. @Override
  85. public String toString() {
  86. return name;
  87. }
  88. /** {@inheritDoc} */
  89. @Override
  90. public void windowClosing() {
  91. // 1: Make the window non-visible
  92. window.setVisible(false);
  93. // 2: Remove any callbacks or listeners
  94. // 3: Trigger any actions neccessary
  95. // 4: Trigger action for the window closing
  96. // 5: Inform any parents that the window is closing
  97. // 6: Remove the window from the window manager
  98. WindowManager.removeWindow(window);
  99. // 7: Remove any references to the window and parents
  100. window = null; // NOPMD
  101. parent = null; // NOPMD
  102. }
  103. /** {@inheritDoc} */
  104. @Override
  105. public Server getServer() {
  106. return parent == null ? null : parent.getContainer().getServer();
  107. }
  108. /**
  109. * Retrieves this custom window's name.
  110. *
  111. * @return This custom window's name
  112. */
  113. public String getName() {
  114. return name;
  115. }
  116. /**
  117. * Retrieves this custom window's title.
  118. *
  119. * @return This custom window's title
  120. */
  121. public String getTitle() {
  122. return title;
  123. }
  124. /** {@inheritDoc} */
  125. @Override
  126. public ConfigManager getConfigManager() {
  127. return parent == null ? IdentityManager.getGlobalConfig() : parent
  128. .getConfigManager();
  129. }
  130. }