01: /*
02: * EnhancedButton.java - Tool bar button
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 1999, 2003 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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:
23: package org.gjt.sp.jedit.gui;
24:
25: //{{{ Imports
26: import javax.swing.*;
27: import java.awt.event.*;
28: import java.awt.*;
29: import org.gjt.sp.jedit.*;
30:
31: //}}}
32:
33: public class EnhancedButton extends RolloverButton {
34: //{{{ EnhancedButton constructor
35: public EnhancedButton(Icon icon, String toolTip, String action,
36: ActionContext context) {
37: super (icon);
38:
39: this .action = action;
40:
41: if (action != null) {
42: setEnabled(true);
43: addActionListener(new EditAction.Wrapper(context, action));
44: addMouseListener(new MouseHandler());
45: } else
46: setEnabled(false);
47:
48: setToolTipText(toolTip);
49: } //}}}
50:
51: //{{{ isFocusTraversable() method
52: public boolean isFocusTraversable() {
53: return false;
54: } //}}}
55:
56: //{{{ Private members
57: private String action;
58:
59: //}}}
60:
61: //{{{ MouseHandler class
62: class MouseHandler extends MouseAdapter {
63: boolean msgSet = false;
64:
65: public void mouseReleased(MouseEvent evt) {
66: if (msgSet) {
67: GUIUtilities.getView((Component) evt.getSource())
68: .getStatus().setMessage(null);
69: msgSet = false;
70: }
71: }
72:
73: public void mouseEntered(MouseEvent evt) {
74: String msg = jEdit.getProperty(action + ".mouse-over");
75: if (msg != null) {
76: GUIUtilities.getView((Component) evt.getSource())
77: .getStatus().setMessage(msg);
78: msgSet = true;
79: }
80: }
81:
82: public void mouseExited(MouseEvent evt) {
83: if (msgSet) {
84: GUIUtilities.getView((Component) evt.getSource())
85: .getStatus().setMessage(null);
86: msgSet = false;
87: }
88: }
89: } //}}}
90: }
|