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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2006-2010 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 title. */
  33. private final String title;
  34. /** The window used by this container. */
  35. private Window window;
  36. /** This window's parent window. */
  37. private Window parent;
  38. /**
  39. * Creates a new custom window as a child of the specified window.
  40. *
  41. * @param name The name of this custom window
  42. * @param title The title of this custom window
  43. * @param parent The parent of this custom window
  44. */
  45. public CustomWindow(final String name, final String title,
  46. final Window parent) {
  47. super("custom", name, parent.getConfigManager());
  48. this.title = title;
  49. this.parent = parent;
  50. window = Main.getUI().getWindow(this);
  51. window.setTitle(title);
  52. WindowManager.addWindow(parent, window);
  53. window.open();
  54. }
  55. /**
  56. * Creates a new custom window as a top-level window.
  57. *
  58. * @param name The name of this custom window
  59. * @param title The parent of this custom window
  60. */
  61. public CustomWindow(final String name, final String title) {
  62. super("custom", name, IdentityManager.getGlobalConfig());
  63. this.title = title;
  64. window = Main.getUI().getWindow(this);
  65. window.setTitle(title);
  66. WindowManager.addWindow(window);
  67. window.open();
  68. }
  69. /** {@inheritDoc} */
  70. @Override
  71. public Window getFrame() {
  72. return window;
  73. }
  74. /** {@inheritDoc} */
  75. @Override
  76. public void windowClosing() {
  77. // 1: Make the window non-visible
  78. window.setVisible(false);
  79. // 2: Remove any callbacks or listeners
  80. // 3: Trigger any actions neccessary
  81. // 4: Trigger action for the window closing
  82. // 5: Inform any parents that the window is closing
  83. // 6: Remove the window from the window manager
  84. WindowManager.removeWindow(window);
  85. // 7: Remove any references to the window and parents
  86. window = null; // NOPMD
  87. parent = null; // NOPMD
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public Server getServer() {
  92. return parent == null ? null : parent.getContainer().getServer();
  93. }
  94. /**
  95. * Retrieves this custom window's title.
  96. *
  97. * @return This custom window's title
  98. */
  99. public String getTitle() {
  100. return title;
  101. }
  102. }