PageRenderTime 75ms CodeModel.GetById 68ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/EnhancedButton.java

#
Java | 84 lines | 46 code | 10 blank | 28 comment | 4 complexity | d70afcabefc90643e41e14344111dee4 MD5 | raw file
 1/*
 2 * EnhancedButton.java - Tool bar button
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 1999, 2001, 2002 Slava Pestov
 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 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22
23package org.gjt.sp.jedit.gui;
24
25//{{{ Imports
26import javax.swing.*;
27import java.awt.event.*;
28import java.awt.*;
29import org.gjt.sp.jedit.textarea.JEditTextArea;
30import org.gjt.sp.jedit.EditAction;
31import org.gjt.sp.jedit.GUIUtilities;
32//}}}
33
34public class EnhancedButton extends RolloverButton
35{
36	//{{{ EnhancedButton constructor
37	public EnhancedButton(Icon icon, String toolTip, EditAction action)
38	{
39		super(icon);
40
41		this.action = action;
42
43		if(action != null)
44		{
45			setEnabled(true);
46			addActionListener(new EditAction.Wrapper(action));
47			addMouseListener(new MouseHandler());
48		}
49		else
50			setEnabled(false);
51
52		setToolTipText(toolTip);
53	} //}}}
54
55	//{{{ isFocusTraversable() method
56	public boolean isFocusTraversable()
57	{
58		return false;
59	} //}}}
60
61	//{{{ Private members
62	private EditAction action;
63	//}}}
64
65	//{{{ MouseHandler class
66	class MouseHandler extends MouseAdapter
67	{
68		public void mouseEntered(MouseEvent evt)
69		{
70			String msg = action.getMouseOverText();
71			if(msg != null)
72			{
73				GUIUtilities.getView((Component)evt.getSource())
74					.getStatus().setMessage(msg);
75			}
76		}
77
78		public void mouseExited(MouseEvent evt)
79		{
80			GUIUtilities.getView((Component)evt.getSource())
81				.getStatus().setMessage(null);
82		}
83	} //}}}
84}