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.

HistoryWindow.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.addons.logging;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.IconManager;
  25. import com.dmdirc.Main;
  26. import com.dmdirc.Server;
  27. import com.dmdirc.config.ConfigManager;
  28. import com.dmdirc.config.IdentityManager;
  29. import com.dmdirc.ui.WindowManager;
  30. import com.dmdirc.ui.interfaces.Window;
  31. import java.util.Stack;
  32. /**
  33. * Displays an extended history of a window.
  34. *
  35. * @author Chris
  36. */
  37. public class HistoryWindow extends FrameContainer {
  38. /** The title of our window. */
  39. private final String title;
  40. /** The window we're using. */
  41. private Window window;
  42. /** Our parent window. */
  43. private Window parent;
  44. /**
  45. * Creates a new HistoryWindow.
  46. *
  47. * @param title The title of the window
  48. * @param reader The reader to use to get the history
  49. * @param parent The window this history window was opened from
  50. */
  51. public HistoryWindow(final String title, final ReverseFileReader reader, final Window parent) {
  52. super();
  53. this.title = title;
  54. this.parent = parent;
  55. icon = IconManager.getIconManager().getIcon("raw");
  56. window = Main.getUI().getWindow(this);
  57. WindowManager.addWindow(parent, window);
  58. window.setTitle(title);
  59. window.setFrameIcon(icon);
  60. window.setVisible(true);
  61. final Stack<String> lines = reader.getLines(
  62. IdentityManager.getGlobalConfig().getOptionInt("plugin-Logging",
  63. "history.lines", 50000));
  64. while (lines.size() > 0) {
  65. window.addLine(lines.pop(), false);
  66. }
  67. }
  68. /** {@inheritDoc} */
  69. @Override
  70. public Window getFrame() {
  71. return window;
  72. }
  73. /** {@inheritDoc} */
  74. @Override
  75. public String toString() {
  76. return title;
  77. }
  78. /** {@inheritDoc} */
  79. @Override
  80. public void windowClosing() {
  81. // 1: Make the window non-visible
  82. window.setVisible(false);
  83. // 2: Remove any callbacks or listeners
  84. // 3: Trigger any actions neccessary
  85. // 4: Trigger action for the window closing
  86. // 5: Inform any parents that the window is closing
  87. // 6: Remove the window from the window manager
  88. WindowManager.removeWindow(window);
  89. // 7: Remove any references to the window and parents
  90. window = null; // NOPMD
  91. parent = null; // NOPMD
  92. }
  93. /** {@inheritDoc} */
  94. @Override
  95. public Server getServer() {
  96. return parent.getContainer().getServer();
  97. }
  98. /** {@inheritDoc} */
  99. @Override
  100. public ConfigManager getConfigManager() {
  101. return parent.getConfigManager();
  102. }
  103. }