Skip to content

Commit c4e0d3c

Browse files
committed
Add the HTML color to the "System" tab of the SWT Controls Example
The format is #RRGGBB (no alpha channel). Also rename method.
1 parent 4fad027 commit c4e0d3c

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

examples/org.eclipse.swt.examples/src/examples_control.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ WebKitNotFound = Cannot use SWT.WEBKIT style: {0}\nSee http://www.eclipse.org/
274274
ColorTitle_0 = Name
275275
ColorTitle_1 = Type
276276
ColorTitle_2 = RGBA
277-
ColorTitle_3 = Color
278-
ColorTitle_4 = Image
277+
ColorTitle_3 = HTML
278+
ColorTitle_4 = Color
279+
ColorTitle_5 = Image
279280
Header_Foreground_Color = Header Foreground Color
280281
Header_Background_Color = Header Background Color
281282
Tab_Height = Tab Height

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SystemTab.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class SystemTab extends Tab {
4343
static String [] columnTitles = {ControlExample.getResourceString("ColorTitle_0"),
4444
ControlExample.getResourceString("ColorTitle_1"),
4545
ControlExample.getResourceString("ColorTitle_2"),
46-
ControlExample.getResourceString("ColorTitle_3")};
46+
ControlExample.getResourceString("ColorTitle_3"),
47+
ControlExample.getResourceString("ColorTitle_4")};
4748
static String [] columnTitles2 = {ControlExample.getResourceString("ColorTitle_0"),
48-
ControlExample.getResourceString("ColorTitle_4")};
49+
ControlExample.getResourceString("ColorTitle_5")};
4950

5051
/* Size widgets added to the "Size" group */
5152
Button packColumnsButton;
@@ -180,10 +181,11 @@ void createExampleWidgets () {
180181
item.setText(value);
181182
item.setText(0, value);
182183
item.setText(1, "Named");
183-
item.setText(2, getRGBcolor(key));
184+
item.setText(2, getRGBAColor(key));
184185
// the spaces will help the color cell be large enough to see
185-
item.setText(3, " ");
186-
item.setBackground(3, display.getSystemColor(key));
186+
item.setText(3, getHTMLColor(key) + " ");
187+
item.setText(4, " ");
188+
item.setBackground(4, display.getSystemColor(key));
187189
if (key == namedColorEnd) {
188190
TableItem emptyItem = new TableItem(colors, SWT.NONE);
189191
emptyItem.setText("");
@@ -194,10 +196,11 @@ void createExampleWidgets () {
194196
item.setText(value);
195197
item.setText(0, value + " ");
196198
item.setText(1, "System ");
197-
item.setText(2, getRGBcolor(key) + " ");
199+
item.setText(2, getRGBAColor(key) + " ");
200+
item.setText(3, getHTMLColor(key) + " ");
198201
// the spaces will help the color cell be large enough to see
199-
item.setText(3, " ");
200-
item.setBackground(3, display.getSystemColor(key));
202+
item.setText(4, " ");
203+
item.setBackground(4, display.getSystemColor(key));
201204
}
202205
}
203206
for (int i = 0; i < columnTitles.length; i++) {
@@ -289,12 +292,19 @@ void packColumns () {
289292
}
290293
}
291294

292-
String getRGBcolor(int id){
295+
String getRGBAColor(int id){
293296
Color color = display.getSystemColor(id);
294297
return String.format("(%d,%d,%d,%d)", color.getRed(), color.getGreen(),
295298
color.getBlue(), color.getAlpha());
296299
}
297300

301+
String getHTMLColor(int id){
302+
Color color = display.getSystemColor(id);
303+
// #RRGGBB format (does not include alpha)
304+
return String.format("#%02X%02X%02X", color.getRed(), color.getGreen(),
305+
color.getBlue());
306+
}
307+
298308
@Override
299309
boolean rtlSupport() {
300310
return false;

0 commit comments

Comments
 (0)