01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.util.gui.resource;
20:
21: import java.awt.Insets;
22: import java.awt.event.MouseAdapter;
23: import java.awt.event.MouseEvent;
24:
25: import javax.swing.JButton;
26:
27: /**
28: * This class represents the buttons used in toolbars.
29: *
30: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
31: * @version $Id: JToolbarButton.java 498555 2007-01-22 08:09:33Z cam $
32: */
33: public class JToolbarButton extends JButton {
34: /**
35: * Creates a new toolbar button.
36: */
37: public JToolbarButton() {
38: initialize();
39: }
40:
41: /**
42: * Creates a new toolbar button.
43: * @param txt The button text.
44: */
45: public JToolbarButton(String txt) {
46: super (txt);
47: initialize();
48: }
49:
50: /**
51: * Initializes the button.
52: */
53: protected void initialize() {
54: if (!System.getProperty("java.version").startsWith("1.3")) {
55: setOpaque(false);
56: setBackground(new java.awt.Color(0, 0, 0, 0));
57: }
58: setBorderPainted(false);
59: setMargin(new Insets(2, 2, 2, 2));
60: addMouseListener(new MouseListener());
61: }
62:
63: /**
64: * To manage the mouse interactions.
65: */
66: protected class MouseListener extends MouseAdapter {
67: public void mouseEntered(MouseEvent ev) {
68: setBorderPainted(true);
69: }
70:
71: public void mouseExited(MouseEvent ev) {
72: setBorderPainted(false);
73: }
74: }
75: }
|