KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > EnhancedButton


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
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 public class EnhancedButton extends RolloverButton
33 {
34     //{{{ EnhancedButton constructor
35
public EnhancedButton(Icon icon, String JavaDoc toolTip, String JavaDoc action,
36         ActionContext context)
37     {
38         super(icon);
39
40         this.action = action;
41
42         if(action != null)
43         {
44             setEnabled(true);
45             addActionListener(new EditAction.Wrapper(context,action));
46             addMouseListener(new MouseHandler());
47         }
48         else
49             setEnabled(false);
50
51         setToolTipText(toolTip);
52     } //}}}
53

54     //{{{ isFocusTraversable() method
55
public boolean isFocusTraversable()
56     {
57         return false;
58     } //}}}
59

60     //{{{ Private members
61
private String JavaDoc action;
62     //}}}
63

64     //{{{ MouseHandler class
65
class MouseHandler extends MouseAdapter
66     {
67         boolean msgSet = false;
68
69         public void mouseReleased(MouseEvent evt)
70         {
71             if(msgSet)
72             {
73                 GUIUtilities.getView((Component)evt.getSource())
74                     .getStatus().setMessage(null);
75                 msgSet = false;
76             }
77         }
78
79         public void mouseEntered(MouseEvent evt)
80         {
81             String JavaDoc msg = jEdit.getProperty(action + ".mouse-over");
82             if(msg != null)
83             {
84                 GUIUtilities.getView((Component)evt.getSource())
85                     .getStatus().setMessage(msg);
86                 msgSet = true;
87             }
88         }
89
90         public void mouseExited(MouseEvent evt)
91         {
92             if(msgSet)
93             {
94                 GUIUtilities.getView((Component)evt.getSource())
95                     .getStatus().setMessage(null);
96                 msgSet = false;
97             }
98         }
99     } //}}}
100
}
101
Popular Tags