01: /*
02: * ToolBarButton.java
03: *
04: * Copyright (C) 2000-2002 Peter Graves
05: * $Id: ToolBarButton.java,v 1.2 2002/10/02 18:22:47 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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;
25: import java.awt.event.ActionEvent;
26: import java.awt.event.ActionListener;
27: import java.awt.event.MouseEvent;
28: import java.awt.event.MouseListener;
29: import java.net.URL;
30: import javax.swing.ImageIcon;
31: import javax.swing.JButton;
32:
33: public final class ToolBarButton extends JButton implements
34: ActionListener, MouseListener {
35: private Frame frame;
36:
37: public ToolBarButton(Frame frame, String actionCommand,
38: ActionListener listener) {
39: super ();
40: this .frame = frame;
41: addMouseListener(this );
42: setActionCommand(actionCommand);
43: addActionListener(listener);
44: // We want our listener called first, so add it last.
45: addActionListener(this );
46: setRequestFocusEnabled(false);
47: }
48:
49: public void setIconFromFile(String filename) {
50: if (Utilities.isFilenameAbsolute(filename))
51: setIcon(new ImageIcon(filename));
52: else {
53: URL url = Editor.class.getResource("images/" + filename);
54: if (url != null)
55: setIcon(new ImageIcon(url));
56: }
57: }
58:
59: protected void paintBorder(Graphics g) {
60: if (!isRolloverEnabled() || model.isRollover())
61: super .paintBorder(g);
62: }
63:
64: public void actionPerformed(ActionEvent e) {
65: model.setPressed(false);
66: model.setArmed(false);
67: model.setRollover(false);
68: }
69:
70: public void mouseClicked(MouseEvent e) {
71: }
72:
73: public void mousePressed(MouseEvent e) {
74: }
75:
76: public void mouseReleased(MouseEvent e) {
77: }
78:
79: public void mouseEntered(MouseEvent e) {
80: frame.setStatusText(this .getToolTipText());
81: }
82:
83: public void mouseExited(MouseEvent e) {
84: frame.setStatusText("");
85: }
86: }
|