PageRenderTime 143ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 96ms app.codeStats 0ms

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

#
Java | 114 lines | 69 code | 13 blank | 32 comment | 9 complexity | 32294fc885fa1976b034e78f93b5cc41 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
 42		if(action != null)
 43		{
 44			// set the name of this button :
 45			// for instance, if the action is 'vfs.browser.previous'
 46			// the name will be 'previous'
 47			// this helps greatly in testing the UI with Fest-Swing
 48			int iSuffix = action.lastIndexOf('.');
 49			if(iSuffix<0 || iSuffix == action.length()-1)
 50			{
 51				setName(action);
 52			}
 53			else
 54			{
 55				setName(action.substring(iSuffix+1));
 56			}
 57			
 58			setEnabled(true);
 59			addActionListener(new EditAction.Wrapper(context,action));
 60			addMouseListener(new MouseHandler());
 61		}
 62		else
 63			setEnabled(false);
 64
 65		setToolTipText(toolTip);
 66	} //}}}
 67
 68	//{{{ isFocusTraversable() method
 69	public boolean isFocusTraversable()
 70	{
 71		return false;
 72	} //}}}
 73
 74	//{{{ Private members
 75	private String action;
 76	//}}}
 77
 78	//{{{ MouseHandler class
 79	class MouseHandler extends MouseAdapter
 80	{
 81		boolean msgSet = false;
 82
 83		public void mouseReleased(MouseEvent evt)
 84		{
 85			if(msgSet)
 86			{
 87				GUIUtilities.getView((Component)evt.getSource())
 88					.getStatus().setMessage(null);
 89				msgSet = false;
 90			}
 91		}
 92
 93		public void mouseEntered(MouseEvent evt)
 94		{
 95			String msg = jEdit.getProperty(action + ".mouse-over");
 96			if(msg != null)
 97			{
 98				GUIUtilities.getView((Component)evt.getSource())
 99					.getStatus().setMessage(msg);
100				msgSet = true;
101			}
102		}
103
104		public void mouseExited(MouseEvent evt)
105		{
106			if(msgSet)
107			{
108				GUIUtilities.getView((Component)evt.getSource())
109					.getStatus().setMessage(null);
110				msgSet = false;
111			}
112		}
113	} //}}}
114}