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.

SwingDebugPlugin.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.swingdebug;
  23. import com.dmdirc.addons.ui_swing.DMDircEventQueue;
  24. import com.dmdirc.addons.ui_swing.SwingController;
  25. import com.dmdirc.addons.ui_swing.components.CheckBoxMenuItem;
  26. import com.dmdirc.plugins.BasePlugin;
  27. import java.awt.Toolkit;
  28. import java.awt.event.ActionEvent;
  29. import java.awt.event.ActionListener;
  30. import javax.swing.JCheckBoxMenuItem;
  31. import javax.swing.JMenu;
  32. /**
  33. * Swing debug plugin. Provides long running EDT task violation detection and a
  34. * console for System.out and System.err.
  35. */
  36. public class SwingDebugPlugin extends BasePlugin implements ActionListener {
  37. /** Swing controller. */
  38. private final SwingController controller;
  39. /** Debug menu. */
  40. private JMenu debugMenu;
  41. /** Debug EDT menu item. */
  42. private JCheckBoxMenuItem debugEDT;
  43. /** Debug EDT menu item. */
  44. private JCheckBoxMenuItem showSysOut;
  45. /** Debug EDT menu item. */
  46. private JCheckBoxMenuItem showSysErr;
  47. /** System out window. */
  48. private SystemStreamContainer sysoutFrame;
  49. /** System error window. */
  50. private SystemStreamContainer syserrFrame;
  51. /**
  52. * Creates a new SwingDebugPlugin.
  53. *
  54. * @param controller The controller to add debug entries to
  55. */
  56. public SwingDebugPlugin(final SwingController controller) {
  57. this.controller = controller;
  58. }
  59. /** {@inheritDoc} */
  60. @Override
  61. public void onLoad() {
  62. debugMenu = new JMenu("Debug");
  63. debugEDT = new CheckBoxMenuItem("Check EDT task length");
  64. showSysOut = new CheckBoxMenuItem("Show System.out Console");
  65. showSysErr = new CheckBoxMenuItem("Show System.err Console");
  66. debugEDT.addActionListener(this);
  67. showSysErr.addActionListener(this);
  68. showSysOut.addActionListener(this);
  69. controller.getMainFrame().getJMenuBar().add(debugMenu);
  70. debugMenu.add(debugEDT);
  71. debugMenu.add(showSysOut);
  72. debugMenu.add(showSysErr);
  73. }
  74. /** {@inheritDoc} */
  75. @Override
  76. public void onUnload() {
  77. controller.getMainFrame().getJMenuBar().remove(debugMenu);
  78. }
  79. /**
  80. * {@inheritDoc}
  81. *
  82. * @param e Action event
  83. */
  84. @Override
  85. public void actionPerformed(final ActionEvent e) {
  86. if (e.getSource() == debugEDT) {
  87. if (debugEDT.getState()) {
  88. Toolkit.getDefaultToolkit().getSystemEventQueue().
  89. push(new TracingEventQueue(this, controller));
  90. } else {
  91. Toolkit.getDefaultToolkit().getSystemEventQueue().
  92. push(new DMDircEventQueue(controller));
  93. }
  94. }
  95. if (e.getSource() == showSysOut) {
  96. if (showSysOut.isSelected()) {
  97. sysoutFrame = new SystemStreamContainer(SystemStreamType.Out,
  98. controller.getGlobalConfig(), this);
  99. } else {
  100. sysoutFrame.close();
  101. }
  102. }
  103. if (e.getSource() == showSysErr) {
  104. if (showSysErr.isSelected()) {
  105. syserrFrame = new SystemStreamContainer(SystemStreamType.Error,
  106. controller.getGlobalConfig(), this);
  107. } else {
  108. syserrFrame.close();
  109. }
  110. }
  111. }
  112. /**
  113. * Notifies this plugin the specified container is closing.
  114. *
  115. * @param container Container that is closing
  116. */
  117. void windowClosing(final SystemStreamContainer container) {
  118. if (container == sysoutFrame) {
  119. showSysOut.setSelected(false);
  120. }
  121. if (container == syserrFrame) {
  122. showSysErr.setSelected(false);
  123. }
  124. }
  125. }