01: /*
02: * WbCheckBoxLabel.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Component;
15: import java.awt.event.FocusEvent;
16: import java.awt.event.FocusListener;
17: import java.awt.event.MouseEvent;
18: import java.awt.event.MouseListener;
19: import javax.swing.JCheckBox;
20: import javax.swing.JLabel;
21:
22: /**
23: * @author support@sql-workbench.net
24: */
25: public class WbCheckBoxLabel extends JLabel implements MouseListener,
26: FocusListener {
27: // private Border oldBorder = new EmptyBorder(1,1,1,1);
28: // private Border focusBorder = new LineBorder(Color.GRAY, 1);
29:
30: public WbCheckBoxLabel() {
31: super ();
32: this .addMouseListener(this );
33: }
34:
35: public WbCheckBoxLabel(String label) {
36: super (label);
37: this .addMouseListener(this );
38: }
39:
40: @Override
41: public void setLabelFor(Component c) {
42: super .setLabelFor(c);
43: // if (c instanceof JCheckBox)
44: // {
45: // JCheckBox check = (JCheckBox)c;
46: // check.addFocusListener(this);
47: // }
48: }
49:
50: public void mouseClicked(MouseEvent e) {
51: Component c = this .getLabelFor();
52: if (c instanceof JCheckBox) {
53: JCheckBox cbx = (JCheckBox) c;
54: cbx.setSelected(!cbx.isSelected());
55: }
56: }
57:
58: public void mousePressed(MouseEvent e) {
59: }
60:
61: public void mouseReleased(MouseEvent e) {
62: }
63:
64: public void mouseEntered(MouseEvent e) {
65: }
66:
67: public void mouseExited(MouseEvent e) {
68: }
69:
70: public void focusGained(FocusEvent e) {
71: // the checkbox gained focus, create an indicator around the label
72: // this.setBorder(focusBorder);
73: }
74:
75: public void focusLost(FocusEvent e) {
76: // this.setBorder(oldBorder);
77: }
78:
79: }
|