Debian Codegraph @

src/com/jidesoft/plaf/windows/WindowsIconFactory.java

raw
1 /*
2 * @(#)WindowsIconFactoryEx.java 5/17/2011
3 *
4 * Copyright 2002 - 2011 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.windows;
8
9 import com.jidesoft.swing.TristateButtonModel;
10 import com.jidesoft.swing.TristateCheckBox;
11
12 import javax.swing.*;
13 import javax.swing.plaf.UIResource;
14 import java.awt.*;
15 import java.io.Serializable;
16
17 public class WindowsIconFactory {
18 private static Icon checkBoxIcon;
19
20 private static class CheckBoxIcon implements Icon, Serializable, UIResource {
21 final static int csize = 13;
22 static int cw = -1;
23 static int ch = -1;
24
25 public void paintIcon(Component c, Graphics g, int x, int y) {
26 JCheckBox cb = (JCheckBox) c;
27 ButtonModel model = cb.getModel();
28 XPStyle xp = XPStyle.getXP();
29
30 if (xp != null) {
31 TMSchema.State state;
32
33 // the following statement added for LegacyTristateCheckBox
34 if (model instanceof TristateButtonModel && ((TristateButtonModel) model).isMixed()) {
35 state = TMSchema.State.MIXEDNORMAL;
36 if (!model.isEnabled()) {
37 state = TMSchema.State.MIXEDDISABLED;
38 }
39 else if (model.isPressed() && model.isArmed()) {
40 state = TMSchema.State.MIXEDPRESSED;
41 }
42 else if (model.isRollover()) {
43 state = TMSchema.State.MIXEDHOT;
44 }
45 }
46 else {
47 if (model.isSelected()) {
48 state = TMSchema.State.CHECKEDNORMAL;
49 if (!model.isEnabled()) {
50 state = TMSchema.State.CHECKEDDISABLED;
51 }
52 else if (model.isPressed() && model.isArmed()) {
53 state = TMSchema.State.CHECKEDPRESSED;
54 }
55 else if (model.isRollover()) {
56 state = TMSchema.State.CHECKEDHOT;
57 }
58 }
59 else {
60 state = TMSchema.State.UNCHECKEDNORMAL;
61 if (!model.isEnabled()) {
62 state = TMSchema.State.UNCHECKEDDISABLED;
63 }
64 else if (model.isPressed() && model.isArmed()) {
65 state = TMSchema.State.UNCHECKEDPRESSED;
66 }
67 else if (model.isRollover()) {
68 state = TMSchema.State.UNCHECKEDHOT;
69 }
70 }
71 }
72 TMSchema.Part part = TMSchema.Part.BP_CHECKBOX;
73 xp.getSkin(c, part).paintSkin(g, x, y, state);
74 }
75 else {
76 // outer bevel
77 if (!cb.isBorderPaintedFlat()) {
78 // Outer top/left
79 g.setColor(UIManager.getColor("CheckBox.shadow"));
80 g.drawLine(x, y, x + 11, y);
81 g.drawLine(x, y + 1, x, y + 11);
82
83 // Outer bottom/right
84 g.setColor(UIManager.getColor("CheckBox.highlight"));
85 g.drawLine(x + 12, y, x + 12, y + 12);
86 g.drawLine(x, y + 12, x + 11, y + 12);
87
88 // Inner top.left
89 g.setColor(UIManager.getColor("CheckBox.darkShadow"));
90 g.drawLine(x + 1, y + 1, x + 10, y + 1);
91 g.drawLine(x + 1, y + 2, x + 1, y + 10);
92
93 // Inner bottom/right
94 g.setColor(UIManager.getColor("CheckBox.light"));
95 g.drawLine(x + 1, y + 11, x + 11, y + 11);
96 g.drawLine(x + 11, y + 1, x + 11, y + 10);
97
98 // inside box
99 if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
100 g.setColor(UIManager.getColor("CheckBox.background"));
101 }
102 else {
103 g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
104 }
105 g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
106 }
107 else {
108 g.setColor(UIManager.getColor("CheckBox.shadow"));
109 g.drawRect(x + 1, y + 1, csize - 3, csize - 3);
110
111 if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
112 g.setColor(UIManager.getColor("CheckBox.background"));
113 }
114 else {
115 g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
116 }
117 g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
118 }
119
120 if (model.isEnabled()) {
121 g.setColor(UIManager.getColor("CheckBox.foreground"));
122 }
123 else {
124 g.setColor(UIManager.getColor("CheckBox.shadow"));
125 }
126
127 if (c instanceof TristateCheckBox && ((TristateCheckBox) c).getModel() instanceof TristateButtonModel && ((TristateButtonModel) ((TristateCheckBox) c).getModel()).isMixed()) {
128 drawSquare(c, g, x, y);
129 }
130 else
131 // paint check
132 if (model.isSelected()) {
133 g.drawLine(x + 9, y + 3, x + 9, y + 3);
134 g.drawLine(x + 8, y + 4, x + 9, y + 4);
135 g.drawLine(x + 7, y + 5, x + 9, y + 5);
136 g.drawLine(x + 6, y + 6, x + 8, y + 6);
137 g.drawLine(x + 3, y + 7, x + 7, y + 7);
138 g.drawLine(x + 4, y + 8, x + 6, y + 8);
139 g.drawLine(x + 5, y + 9, x + 5, y + 9);
140 g.drawLine(x + 3, y + 5, x + 3, y + 5);
141 g.drawLine(x + 3, y + 6, x + 4, y + 6);
142 }
143 }
144 }
145
146 // the following method added for LegacyTristateCheckBox
147 protected void drawSquare(Component c, Graphics g, int x, int y) {
148 final int w = getIconWidth();
149 final int h = getIconHeight();
150 int margin = w / 3;
151 g.fillRect(x + margin, y + margin, w - margin * 2, h - margin * 2);
152 }
153
154 public int getIconWidth() {
155 XPStyle xp = XPStyle.getXP();
156 if (xp != null) {
157 if (cw == -1) {
158 cw = xp.getSkin(null, TMSchema.Part.BP_CHECKBOX).getWidth();
159 }
160 return cw;
161 }
162 else {
163 return csize;
164 }
165 }
166
167 public int getIconHeight() {
168 XPStyle xp = XPStyle.getXP();
169 if (xp != null) {
170 if (ch == -1) {
171 ch = xp.getSkin(null, TMSchema.Part.BP_CHECKBOX).getHeight();
172 }
173 return ch;
174 }
175 else {
176 return csize;
177 }
178 }
179 }
180
181 public static Icon getCheckBoxIcon() {
182 if (checkBoxIcon == null) {
183 checkBoxIcon = new CheckBoxIcon();
184 }
185 return checkBoxIcon;
186 }
187 }