PageRenderTime 108ms CodeModel.GetById 96ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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
 22package org.gjt.sp.jedit.gui.statusbar;
 23
 24//{{{ Imports
 25import org.gjt.sp.jedit.*;
 26import org.gjt.sp.jedit.gui.DockableWindowManager;
 27import org.gjt.sp.util.Task;
 28import org.gjt.sp.util.TaskListener;
 29import org.gjt.sp.util.TaskManager;
 30
 31import javax.swing.*;
 32import java.awt.event.MouseAdapter;
 33import java.awt.event.MouseEvent;
 34//}}}
 35
 36/**
 37 * A Statusbar widget that monitor the task manager.
 38 *
 39 * @author Matthieu Casanova
 40 * @since jEdit 4.5pre1
 41 */
 42public class TaskMonitorWidgetFactory implements StatusWidgetFactory
 43{
 44	//{{{ getWidget() method
 45	@Override
 46    public Widget getWidget(View view)
 47	{
 48		Widget widget = new TaskMonitorWidget(view);
 49		widget.getComponent().setToolTipText(jEdit.getProperty("statusbar.task-monitor.tooltip"));
 50		return widget;
 51	} //}}}
 52
 53    //{{{ TaskMonitorWidget class
 54    private static class TaskMonitorWidget extends JLabel implements Widget, TaskListener
 55    {
 56        private TaskMonitorWidget(final View view)
 57        {
 58            addMouseListener(new MouseAdapter()
 59            {
 60                @Override
 61                public void mouseClicked(MouseEvent e)
 62                {
 63                    if (SwingUtilities.isLeftMouseButton(e))
 64                    {
 65                        view.getDockableWindowManager().showDockableWindow("task-monitor");
 66                    }
 67                }
 68            });
 69        }
 70
 71        @Override
 72        public void addNotify()
 73        {
 74            super.addNotify();
 75            TaskManager.instance.addTaskListener(this);
 76            update();
 77        }
 78
 79        @Override
 80        public void removeNotify()
 81        {
 82            super.removeNotify();
 83            TaskManager.instance.removeTaskListener(this);
 84        }
 85
 86        @Override
 87        public JComponent getComponent()
 88        {
 89            return this;
 90        }
 91
 92        @Override
 93        public void propertiesChanged()
 94        {
 95        }
 96
 97        @Override
 98        public void update()
 99        {
100            int count = TaskManager.instance.countTasks();
101            if (count == 0)
102            {
103                setText(null);
104            }
105            else
106            {
107                setText(jEdit.getProperty("statusbar.task-monitor.template", new Object[]{Integer.toString(count)}));
108            }
109        }
110
111        @Override
112        public void waiting(Task task)
113        {
114            update();
115        }
116
117        @Override
118        public void running(Task task)
119        {
120            update();
121        }
122
123        @Override
124        public void done(Task task)
125        {
126            update();
127        }
128
129        @Override
130        public void statusUpdated(Task task)
131        {
132            update();
133        }
134
135        @Override
136        public void maximumUpdated(Task task)
137        {
138            update();
139        }
140
141        @Override
142        public void valueUpdated(Task task)
143        {
144            update();
145        }
146	} //}}}
147}