PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/statusbar/TaskMonitorWidgetFactory.java

#
Java | 147 lines | 101 code | 16 blank | 30 comment | 3 complexity | 25487c500b12fccc9409ef91577b0a60 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * jEdit - Programmer's Text Editor
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright Š 2011 Matthieu Casanova
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package org.gjt.sp.jedit.gui.statusbar;
  22. //{{{ Imports
  23. import org.gjt.sp.jedit.*;
  24. import org.gjt.sp.jedit.gui.DockableWindowManager;
  25. import org.gjt.sp.util.Task;
  26. import org.gjt.sp.util.TaskListener;
  27. import org.gjt.sp.util.TaskManager;
  28. import javax.swing.*;
  29. import java.awt.event.MouseAdapter;
  30. import java.awt.event.MouseEvent;
  31. //}}}
  32. /**
  33. * A Statusbar widget that monitor the task manager.
  34. *
  35. * @author Matthieu Casanova
  36. * @since jEdit 4.5pre1
  37. */
  38. public class TaskMonitorWidgetFactory implements StatusWidgetFactory
  39. {
  40. //{{{ getWidget() method
  41. @Override
  42. public Widget getWidget(View view)
  43. {
  44. Widget widget = new TaskMonitorWidget(view);
  45. widget.getComponent().setToolTipText(jEdit.getProperty("statusbar.task-monitor.tooltip"));
  46. return widget;
  47. } //}}}
  48. //{{{ TaskMonitorWidget class
  49. private static class TaskMonitorWidget extends JLabel implements Widget, TaskListener
  50. {
  51. private TaskMonitorWidget(final View view)
  52. {
  53. addMouseListener(new MouseAdapter()
  54. {
  55. @Override
  56. public void mouseClicked(MouseEvent e)
  57. {
  58. if (SwingUtilities.isLeftMouseButton(e))
  59. {
  60. view.getDockableWindowManager().showDockableWindow("task-monitor");
  61. }
  62. }
  63. });
  64. }
  65. @Override
  66. public void addNotify()
  67. {
  68. super.addNotify();
  69. TaskManager.instance.addTaskListener(this);
  70. update();
  71. }
  72. @Override
  73. public void removeNotify()
  74. {
  75. super.removeNotify();
  76. TaskManager.instance.removeTaskListener(this);
  77. }
  78. @Override
  79. public JComponent getComponent()
  80. {
  81. return this;
  82. }
  83. @Override
  84. public void propertiesChanged()
  85. {
  86. }
  87. @Override
  88. public void update()
  89. {
  90. int count = TaskManager.instance.countTasks();
  91. if (count == 0)
  92. {
  93. setText(null);
  94. }
  95. else
  96. {
  97. setText(jEdit.getProperty("statusbar.task-monitor.template", new Object[]{Integer.toString(count)}));
  98. }
  99. }
  100. @Override
  101. public void waiting(Task task)
  102. {
  103. update();
  104. }
  105. @Override
  106. public void running(Task task)
  107. {
  108. update();
  109. }
  110. @Override
  111. public void done(Task task)
  112. {
  113. update();
  114. }
  115. @Override
  116. public void statusUpdated(Task task)
  117. {
  118. update();
  119. }
  120. @Override
  121. public void maximumUpdated(Task task)
  122. {
  123. update();
  124. }
  125. @Override
  126. public void valueUpdated(Task task)
  127. {
  128. update();
  129. }
  130. } //}}}
  131. }