PageRenderTime 123ms CodeModel.GetById 100ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 0ms

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

#
Java | 90 lines | 50 code | 9 blank | 31 comment | 3 complexity | aedb949171cdfd2b3444174bba8ebdbc MD5 | raw file
 1/*
 2 * ModeWidgetFactory.java - The mode widget service
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2008 Matthieu Casanova
 7 * Portions Copyright (C) 2001, 2004 Slava Pestov
 8 * Portions copyright (C) 2001 Mike Dillon
 9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24
25package org.gjt.sp.jedit.gui.statusbar;
26
27//{{{ Imports
28import java.awt.event.MouseAdapter;
29import java.awt.event.MouseEvent;
30import javax.swing.JComponent;
31import javax.swing.JLabel;
32import org.gjt.sp.jedit.Buffer;
33import org.gjt.sp.jedit.View;
34import org.gjt.sp.jedit.gui.BufferOptions;
35import org.gjt.sp.jedit.jEdit;
36//}}}
37
38/**
39 * @author Matthieu Casanova
40 * @since jEdit 4.3pre14 
41 */
42public class ModeWidgetFactory implements StatusWidgetFactory
43{
44    //{{{ getWidget() method
45    public Widget getWidget(View view) 
46    {
47	ModeWidget mode = new ModeWidget(view);
48	return mode;
49    } //}}}
50
51    //{{{ ModeWidget class
52    private static class ModeWidget implements Widget
53    {
54	    private final JLabel mode;
55	    private final View view;
56	    public ModeWidget(final View view) 
57	    {
58		    mode = new ToolTipLabel();
59		    this.view = view;
60		    mode.setToolTipText(jEdit.getProperty("view.status.mode-tooltip"));
61		    mode.addMouseListener(new MouseAdapter() 
62					  {
63						  @Override
64						  public void mouseClicked(MouseEvent evt)
65						  {
66							  if(evt.getClickCount() == 2)
67								  new BufferOptions(view,view.getBuffer());
68						  }
69					  });
70	    }
71	    
72	    public JComponent getComponent() 
73	    {
74		    return mode;
75	    }
76	    
77	    public void update() 
78	    {
79		    Buffer buffer = view.getBuffer();
80		    if (buffer.isLoaded())
81			    mode.setText(buffer.getMode().toString());
82	    }
83	    
84	    public void propertiesChanged()
85	    {
86	    }
87	    
88    } //}}}
89
90}