PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/EnhancedButton.java

#
Java | 102 lines | 62 code | 12 blank | 28 comment | 6 complexity | b5119a53dad8f7a221b1b991dc23ff08 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, 2003 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.*;
 30//}}}
 31
 32public class EnhancedButton extends RolloverButton
 33{
 34	//{{{ EnhancedButton constructor
 35	public EnhancedButton(Icon icon, String toolTip, String action,
 36		ActionContext context)
 37	{
 38		super(icon);
 39
 40		this.action = action;
 41		this.context = context;
 42
 43		if(action != null)
 44		{
 45			setEnabled(true);
 46			addActionListener(new EditAction.Wrapper(context,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 ActionContext context;
 63	private String action;
 64	//}}}
 65
 66	//{{{ MouseHandler class
 67	class MouseHandler extends MouseAdapter
 68	{
 69		boolean msgSet = false;
 70
 71		public void mouseReleased(MouseEvent evt)
 72		{
 73			if(msgSet)
 74			{
 75				GUIUtilities.getView((Component)evt.getSource())
 76					.getStatus().setMessage(null);
 77				msgSet = false;
 78			}
 79		}
 80
 81		public void mouseEntered(MouseEvent evt)
 82		{
 83			String msg = jEdit.getProperty(action + ".mouse-over");
 84			if(msg != null)
 85			{
 86				GUIUtilities.getView((Component)evt.getSource())
 87					.getStatus().setMessage(msg);
 88				msgSet = true;
 89			}
 90		}
 91
 92		public void mouseExited(MouseEvent evt)
 93		{
 94			if(msgSet)
 95			{
 96				GUIUtilities.getView((Component)evt.getSource())
 97					.getStatus().setMessage(null);
 98				msgSet = false;
 99			}
100		}
101	} //}}}
102}