01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: FocusBorder.java,v 1.14 2005/12/04 13:46:03 jesper Exp $
23: package net.infonode.gui.border;
24:
25: import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
26: import net.infonode.gui.UIManagerUtil;
27:
28: import javax.swing.*;
29: import javax.swing.border.Border;
30: import javax.swing.plaf.basic.BasicGraphicsUtils;
31: import java.awt.*;
32: import java.awt.event.FocusEvent;
33: import java.awt.event.FocusListener;
34: import java.io.Serializable;
35:
36: /**
37: * @author $Author: jesper $
38: * @version $Revision: 1.14 $
39: */
40: public class FocusBorder implements Border, Serializable {
41: private static final long serialVersionUID = 1;
42:
43: private static final Insets INSETS = new Insets(1, 1, 1, 1);
44:
45: private Component component;
46:
47: private boolean enabled = true;
48:
49: public FocusBorder(final Component focusComponent) {
50: this .component = focusComponent;
51: focusComponent.addFocusListener(new FocusListener() {
52: public void focusGained(FocusEvent e) {
53: if (enabled)
54: focusComponent.repaint();
55: }
56:
57: public void focusLost(FocusEvent e) {
58: if (enabled)
59: focusComponent.repaint();
60: }
61: });
62: }
63:
64: public Insets getBorderInsets(Component c) {
65: return INSETS;
66: }
67:
68: public boolean isBorderOpaque() {
69: return false;
70: }
71:
72: public boolean isEnabled() {
73: return enabled;
74: }
75:
76: public void setEnabled(boolean enabled) {
77: if (enabled != this .enabled) {
78: this .enabled = enabled;
79: }
80: }
81:
82: public void paintBorder(Component c, Graphics g, int x, int y,
83: int width, int height) {
84: if (enabled && component.hasFocus()) {
85: g.setColor(UIManagerUtil.getColor("Button.focus",
86: "TabbedPane.focus"));
87:
88: if (UIManager.getLookAndFeel().getClass() == WindowsLookAndFeel.class)
89: BasicGraphicsUtils.drawDashedRect(g, x, y, width,
90: height);
91: else
92: g.drawRect(x, y, width - 1, height - 1);
93: }
94: }
95: }
|