PageRenderTime 68ms CodeModel.GetById 59ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Java | 89 lines | 50 code | 8 blank | 31 comment | 3 complexity | 2003e68bd2694ec2a09c37031d221460 MD5 | raw file
 1/*
 2 * EncodingWidgetFactory.java - The encoding 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 EncodingWidgetFactory implements StatusWidgetFactory
43{
44	//{{{ getWidget() method
45	public Widget getWidget(View view) 
46	{
47		EncodingWidget mode = new EncodingWidget(view);
48		return mode;
49	} //}}}
50
51	//{{{ EncodingWidget class
52	private static class EncodingWidget implements Widget
53	{
54		private final JLabel encoding;
55		private final View view;
56		public EncodingWidget(final View view) 
57		{
58			encoding = new ToolTipLabel();
59			this.view = view;
60			encoding.setToolTipText(jEdit.getProperty("view.status.mode-tooltip"));
61			encoding.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 encoding;
75		}
76		
77		public void update() 
78		{
79			Buffer buffer = view.getBuffer();
80			if (buffer.isLoaded())
81				encoding.setText(buffer.getStringProperty("encoding"));
82		}
83		
84		public void propertiesChanged()
85		{
86		}
87		
88	} //}}}
89}