-
Notifications
You must be signed in to change notification settings - Fork 96
/
Win7PaletteProvider.java
241 lines (210 loc) · 5.79 KB
/
Win7PaletteProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package org.eclipse.nebula.widgets.grid.internal.win7;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
/**
* Palette provider to provide/maintain a set of palettes
* specifically used for Win7 looknfeel
*/
public class Win7PaletteProvider {
/**
*
*/
public static final Integer NORMAL_GRID_COLUMN_HEADER = new Integer(0);
private static final Object[] NORMAL_GRID_COLUMN_HEADER_RGB = new Object[]{
new Integer(SWT.COLOR_WHITE),
new Integer(SWT.COLOR_WHITE),
new Integer(SWT.COLOR_WHITE),
new Integer(SWT.COLOR_WHITE),
new RGB(242,242,242),
new RGB(239,239,239),
new RGB(251,251,252),
new RGB(247,248,249),
new RGB(247,248,250),
new RGB(241,242,244),
new RGB(252,252,253),
new RGB(251,251,252),
new RGB(231,232,234),
new RGB(222,223,225),
new RGB(213,213,213),
new RGB(251,251,251)
};
/**
*
*/
public static final Integer HOVER_GRID_COLUMN_HEADER = new Integer(1);
private static final Object[] HOVER_GRID_COLUMN_HEADER_RGB = new Object[]{
new Integer(SWT.COLOR_WHITE),
new RGB(136,203,235),
new RGB(227,247,255),
new RGB(227,247,255),
null,
new RGB(136,203,235),
null,
new RGB(105,187,227),
null,
new RGB(183,231,251),
null,
new RGB(183,231,251),
null,
new RGB(105,187,227),
new RGB(147,201,227),
new RGB(251,251,251)
};
/**
*
*/
public static final Integer MOUSEDOWN_GRID_COLUMN_HEADER = new Integer(3);
private static final Object[] MOUSEDOWN_GRID_COLUMN_HEADER_RGB = new Object[]{
new Integer(SWT.COLOR_WHITE),
new RGB(122,158,177),
new RGB(188,228,249),
new RGB(162,203,224),
null,
new RGB(122,158,177),
new RGB(80,145,175),
new RGB(77,141,173),
new RGB(141,214,247),
new RGB(138,209,245),
new RGB(114,188,223),
new RGB(110,184,220),
new RGB(80,145,175),
new RGB(77,141,173),
new RGB(147,201,227),
new RGB(251,251,251)
};
/**
*
*/
public static final Integer SELECTED_GRID_COLUMN_HEADER = new Integer(3);
private static final Object[] SELECTED_GRID_COLUMN_HEADER_RGB = new Object[]{
new Integer(SWT.COLOR_WHITE),
new RGB(150,217,249),
new RGB(242,249,252),
new RGB(242,249,252),
null,
new RGB(150,217,249),
null,
new RGB(150,217,249),
new RGB(225,241,249),
new RGB(216,236,246),
new RGB(225,241,249),
new RGB(216,236,246),
null,
new RGB(150,217,249),
new RGB(150,217,249),
new Integer(SWT.COLOR_WHITE)
};
/**
*
*/
public static final Integer SHADOW_GRID_COLUMN_HEADER = new Integer(4);
private static final Object[] SHADOW_GRID_COLUMN_HEADER_RGB = new Object[]{
new RGB(134,163,178),
new RGB(170,206,225)
};
/**
* Pool of palettes
*/
private Map<Integer, Palette> palettes = new HashMap<>();
/**
* Dispose the
*/
public void dispose(){
for ( Iterator<Palette> it = palettes.values().iterator() ; it.hasNext() ; ){
it.next().dispose();
}
}
/**
* @param display
* @param type
*/
public void initializePalette(Display display, Integer type){
getPalette(display, type);
}
/**
* Utility method to create/pool a Color
* @param display
* @param type
* @return Color
*/
public Palette getPalette(Display display, Integer type){
Palette palette = palettes.get(type);
if ( palette != null )
return palette;
//create the palette
if ( type == NORMAL_GRID_COLUMN_HEADER ){
return createPalette(display,type,NORMAL_GRID_COLUMN_HEADER_RGB);
} else if ( type == HOVER_GRID_COLUMN_HEADER ){
return createPalette(display,type,HOVER_GRID_COLUMN_HEADER_RGB);
} else if ( type == MOUSEDOWN_GRID_COLUMN_HEADER ){
return createPalette(display,type,MOUSEDOWN_GRID_COLUMN_HEADER_RGB);
} else if ( type == SHADOW_GRID_COLUMN_HEADER ){
return createPalette(display,type,SHADOW_GRID_COLUMN_HEADER_RGB);
} else if ( type == SELECTED_GRID_COLUMN_HEADER ){
return createPalette(display,type,SELECTED_GRID_COLUMN_HEADER_RGB);
}
return null;
}
/**
* @param display
* @param type
* @param def
* @return Palette
*/
protected Palette createPalette(Display display, Integer type, Object[] def){
Color[] colors = new Color[def.length];
for ( int i = 0 ; i < colors.length ; i++ ){
if ( def[i] == null ){
colors[i] = null;
} else if ( def[i] instanceof Integer ){
colors[i] = (display==null?Display.getCurrent():display).getSystemColor(((Integer)def[i]).intValue());
} else {
colors[i] = new Color(display, (RGB)def[i]);
}
}
return new Palette(type, colors);
}
/**
*
*/
public class Palette {
private Integer type;
private Color[] colors = new Color[]{};
/**
* @param type
* @param colors
*/
public Palette(Integer type, Color[] colors) {
this.type = type;
this.colors = colors;
}
/**
* @return int
*/
public Integer getType() {
return type;
}
/**
* @return Color[]
*/
public Color[] getColors(){
return colors;
}
/**
* Dispose colors
*/
public void dispose(){
if ( colors != null ){
for ( int i = 0 ; i < colors.length ; i++ ){
if ( colors[i] != null )
colors[i].dispose();
}
}
}
}
}