01: package salomeTMF_plug.helpgui.gui;
02:
03: /**
04: * This class is from jedit.org
05: * RolloverButton.java - Class for buttons that implement rollovers
06: * :tabSize=8:indentSize=8:noTabs=false:
07: * :folding=explicit:collapseFolds=1:
08: *
09: * Copyright (C) 2002 Kris Kopicki
10: *
11: * This program is free software; you can redistribute it and/or
12: * modify it under the terms of the GNU General Public License
13: * as published by the Free Software Foundation; either version 2
14: * of the License, or any later version.
15: *
16: * This program is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU General Public License for more details.
20: *
21: * You should have received a copy of the GNU General Public License
22: * along with this program; if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24: */
25:
26: import java.awt.*;
27: import java.awt.event.*;
28: import javax.swing.*;
29: import javax.swing.border.*;
30:
31: /**
32: * Special button for tests on TaskPropertiesBeans
33: */
34: public class TestRolloverButton extends JButton {
35: /**
36: * Setup the border (invisible initially)
37: */
38: public TestRolloverButton() {
39: setBorder(new EtchedBorder());
40: setBorderPainted(false);
41: setMargin(new Insets(0, 0, 0, 0));
42:
43: setRequestFocusEnabled(false);
44:
45: addMouseListener(new MouseOverHandler());
46: }
47:
48: /**
49: * Setup the border (invisible initially)
50: */
51: public TestRolloverButton(Icon icon) {
52: this ();
53:
54: setIcon(icon);
55: }
56:
57: public boolean isOpaque() {
58: return false;
59: }
60:
61: public void setEnabled(boolean b) {
62: super .setEnabled(b);
63: setBorderPainted(false);
64: repaint();
65: }
66:
67: public void paint(Graphics g) {
68: if (isEnabled()) {
69: super .paint(g);
70: } else {
71: Graphics2D g2 = (Graphics2D) g;
72: g2.setComposite(c);
73: super .paint(g2);
74: }
75: }
76:
77: private static AlphaComposite c = AlphaComposite.getInstance(
78: AlphaComposite.SRC_OVER, 0.5f);
79:
80: /**
81: * Make the border visible/invisible on rollovers
82: */
83: class MouseOverHandler extends MouseAdapter {
84: public void mouseEntered(MouseEvent e) {
85: if (isEnabled()) {
86: setBorderPainted(true);
87: }
88: }
89:
90: public void mouseExited(MouseEvent e) {
91: setBorderPainted(false);
92: }
93: }
94: }
|