KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > ToolBarButton


1 /*
2  * ToolBarButton.java
3  *
4  * Copyright (C) 2000-2002 Peter Graves
5  * $Id: ToolBarButton.java,v 1.2 2002/10/02 18:22:47 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.awt.Graphics JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.MouseEvent JavaDoc;
28 import java.awt.event.MouseListener JavaDoc;
29 import java.net.URL JavaDoc;
30 import javax.swing.ImageIcon JavaDoc;
31 import javax.swing.JButton JavaDoc;
32
33 public final class ToolBarButton extends JButton JavaDoc implements ActionListener JavaDoc,
34     MouseListener JavaDoc
35 {
36     private Frame frame;
37
38     public ToolBarButton(Frame frame, String JavaDoc actionCommand,
39         ActionListener JavaDoc listener)
40     {
41         super();
42         this.frame = frame;
43         addMouseListener(this);
44         setActionCommand(actionCommand);
45         addActionListener(listener);
46         // We want our listener called first, so add it last.
47
addActionListener(this);
48         setRequestFocusEnabled(false);
49     }
50
51     public void setIconFromFile(String JavaDoc filename)
52     {
53         if (Utilities.isFilenameAbsolute(filename))
54             setIcon(new ImageIcon JavaDoc(filename));
55         else {
56             URL JavaDoc url = Editor.class.getResource("images/" + filename);
57             if (url != null)
58                 setIcon(new ImageIcon JavaDoc(url));
59         }
60     }
61
62     protected void paintBorder(Graphics JavaDoc g)
63     {
64         if (!isRolloverEnabled() || model.isRollover())
65             super.paintBorder(g);
66     }
67
68     public void actionPerformed(ActionEvent JavaDoc e)
69     {
70         model.setPressed(false);
71         model.setArmed(false);
72         model.setRollover(false);
73     }
74
75     public void mouseClicked(MouseEvent JavaDoc e) {}
76
77     public void mousePressed(MouseEvent JavaDoc e) {}
78
79     public void mouseReleased(MouseEvent JavaDoc e) {}
80
81     public void mouseEntered(MouseEvent JavaDoc e)
82     {
83         frame.setStatusText(this.getToolTipText());
84     }
85
86     public void mouseExited(MouseEvent JavaDoc e)
87     {
88         frame.setStatusText("");
89     }
90 }
91
Popular Tags