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.

CustomWindow.java 4.1KB

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