01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * 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: */package com.l2fprod.common.swing.border;
18:
19: import java.awt.Component;
20: import java.awt.Graphics;
21: import java.awt.Insets;
22:
23: import javax.swing.AbstractButton;
24: import javax.swing.ButtonModel;
25: import javax.swing.border.AbstractBorder;
26:
27: /**
28: * ButtonBorder. <br>
29: *
30: */
31: public class ButtonBorder extends AbstractBorder {
32:
33: public void paintBorder(Component c, Graphics g, int x, int y,
34: int width, int height) {
35: if (c instanceof AbstractButton) {
36: AbstractButton b = (AbstractButton) c;
37: ButtonModel model = b.getModel();
38:
39: boolean isPressed;
40: boolean isRollover;
41: boolean isEnabled;
42:
43: isPressed = model.isPressed() && model.isArmed();
44: isRollover = b.isRolloverEnabled() && model.isRollover();
45: isEnabled = b.isEnabled();
46:
47: if (!isEnabled) {
48: paintDisabled(b, g, x, y, width, height);
49: } else {
50: if (isPressed) {
51: paintPressed(b, g, x, y, width, height);
52: } else if (isRollover) {
53: paintRollover(b, g, x, y, width, height);
54: } else {
55: paintNormal(b, g, x, y, width, height);
56: }
57: }
58: }
59: }
60:
61: protected void paintNormal(AbstractButton b, Graphics g, int x,
62: int y, int width, int height) {
63: }
64:
65: protected void paintDisabled(AbstractButton b, Graphics g, int x,
66: int y, int width, int height) {
67: }
68:
69: protected void paintRollover(AbstractButton b, Graphics g, int x,
70: int y, int width, int height) {
71: }
72:
73: protected void paintPressed(AbstractButton b, Graphics g, int x,
74: int y, int width, int height) {
75: }
76:
77: public Insets getBorderInsets(Component c) {
78: return getBorderInsets(c, new Insets(0, 0, 0, 0));
79: }
80:
81: public Insets getBorderInsets(Component c, Insets insets) {
82: return insets;
83: }
84:
85: }
|