01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexander T. Simbirtsev
19: * @version $Revision$
20: */package javax.swing.plaf.metal;
21:
22: import java.awt.Color;
23: import java.awt.Component;
24: import java.awt.Graphics;
25: import java.io.Serializable;
26:
27: import javax.swing.AbstractButton;
28: import javax.swing.ButtonModel;
29: import javax.swing.Icon;
30: import javax.swing.plaf.UIResource;
31:
32: import org.apache.harmony.x.swing.ButtonCommons;
33:
34: public class MetalCheckBoxIcon implements Icon, UIResource,
35: Serializable {
36:
37: protected int getControlSize() {
38: return 13;
39: }
40:
41: protected void drawCheck(final Component c, final Graphics g,
42: final int x, final int y) {
43:
44: Color markColor = c.isEnabled() ? MetalLookAndFeel
45: .getControlTextColor() : MetalLookAndFeel
46: .getControlShadow();
47: ButtonCommons.drawCheck(g, markColor, x + 1, x + 2);
48: }
49:
50: public void paintIcon(final Component c, final Graphics g,
51: final int x, final int y) {
52: ButtonModel model = ((AbstractButton) c).getModel();
53: int height = getIconHeight() - 1;
54: int width = getIconWidth() - 1;
55: boolean enabled = c.isEnabled();
56:
57: Color oldColor = g.getColor();
58: if (enabled) {
59: g.setColor(MetalLookAndFeel.getControlHighlight());
60: g.drawRect(x + 1, y + 1, width - 1, height - 1);
61: g.drawRect(x, y + 2, width - 1, height - 1);
62:
63: if (model.isPressed()) {
64: g.setColor(MetalLookAndFeel.getControlShadow());
65: g.fillRect(x, y + 1, width, height);
66: }
67: }
68:
69: if (model.isSelected()) {
70: drawCheck(c, g, x, y);
71: }
72:
73: g.setColor(enabled ? MetalLookAndFeel.getControlDarkShadow()
74: : MetalLookAndFeel.getControlShadow());
75: g.drawRect(x, y + 1, width - 1, height - 1);
76:
77: g.setColor(oldColor);
78: }
79:
80: public int getIconWidth() {
81: return getControlSize();
82: }
83:
84: public int getIconHeight() {
85: return getControlSize();
86: }
87:
88: }
|