Skip to content

Commit 0bb0acd

Browse files
committed
Show "system images" in ControlExample
Includes renaming the "Color" tab to "System" . It was incorrect with cursors there but adding "images" made it yell for renaming.
1 parent 6014e1b commit 0bb0acd

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ColorTitle_0 = Name
275275
ColorTitle_1 = Type
276276
ColorTitle_2 = RGBA
277277
ColorTitle_3 = Color
278+
ColorTitle_4 = Image
278279
Header_Foreground_Color = Header Foreground Color
279280
Header_Background_Color = Header Background Color
280281
Tab_Height = Tab Height

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ Tab[] createTabs() {
104104
return new Tab [] {
105105
new ButtonTab (this),
106106
new CanvasTab (this),
107-
new ColorTab(this),
108107
new ComboTab (this),
109108
new CoolBarTab (this),
110109
new DateTimeTab (this),
@@ -121,6 +120,7 @@ Tab[] createTabs() {
121120
shellTab = new ShellTab(this),
122121
new SliderTab (this),
123122
new SpinnerTab (this),
123+
new SystemTab(this),
124124
new TabFolderTab (this),
125125
new TableTab (this),
126126
new TextTab (this),
Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 Red Hat, Inc. and others.
2+
* Copyright (c) 2000, 2025 Red Hat, Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,6 @@
1414
*******************************************************************************/
1515
package org.eclipse.swt.examples.controlexample;
1616

17-
1817
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
1918

2019
import java.util.HashMap;
@@ -34,24 +33,27 @@
3433
import org.eclipse.swt.widgets.TableItem;
3534
import org.eclipse.swt.widgets.Widget;
3635

37-
class ColorTab extends Tab {
38-
Table colors, cursors;
39-
Group colorsGroup, cursorsGroup;
36+
class SystemTab extends Tab {
37+
Table colors, cursors, images;
38+
Group colorsGroup, cursorsGroup, imagesGroup;
4039
HashMap <Integer, String> hmap = new HashMap <> ();
4140
HashMap <Integer, String> cmap = new HashMap <> ();
41+
HashMap <Integer, String> imap = new HashMap <> ();
4242
static final int namedColorEnd = 8;
4343
static String [] columnTitles = {ControlExample.getResourceString("ColorTitle_0"),
4444
ControlExample.getResourceString("ColorTitle_1"),
4545
ControlExample.getResourceString("ColorTitle_2"),
4646
ControlExample.getResourceString("ColorTitle_3")};
47+
static String [] columnTitles2 = {ControlExample.getResourceString("ColorTitle_0"),
48+
ControlExample.getResourceString("ColorTitle_4")};
4749

4850
/* Size widgets added to the "Size" group */
4951
Button packColumnsButton;
5052

5153
/**
5254
* Creates the color tab within a given instance of ControlExample.
5355
*/
54-
ColorTab(ControlExample instance) {
56+
SystemTab(ControlExample instance) {
5557
super(instance);
5658
addTableElements();
5759
}
@@ -110,6 +112,12 @@ void addTableElements () {
110112
cmap.put(SWT.CURSOR_UPARROW, "CURSOR_UPARROW");
111113
cmap.put(SWT.CURSOR_IBEAM, "CURSOR_IBEAM");
112114
cmap.put(SWT.CURSOR_NO, "CURSOR_NO");
115+
116+
imap.put(SWT.ICON_ERROR, "ICON_ERROR");
117+
imap.put(SWT.ICON_INFORMATION, "ICON_INFORMATION");
118+
imap.put(SWT.ICON_QUESTION, "ICON_QUESTION");
119+
imap.put(SWT.ICON_WARNING, "ICON_WARNING");
120+
imap.put(SWT.ICON_WORKING, "ICON_WORKING");
113121
}
114122

115123
/**
@@ -118,7 +126,7 @@ void addTableElements () {
118126
@Override
119127
void createExampleGroup () {
120128
super.createExampleGroup ();
121-
exampleGroup.setLayout(new GridLayout(2, false));
129+
exampleGroup.setLayout(new GridLayout(3, false));
122130

123131
colorsGroup = new Group (exampleGroup, SWT.NONE);
124132
colorsGroup.setLayout (new GridLayout ());
@@ -129,6 +137,11 @@ void createExampleGroup () {
129137
cursorsGroup.setLayout (new GridLayout ());
130138
cursorsGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, true));
131139
cursorsGroup.setText ("Cursors");
140+
141+
imagesGroup = new Group (exampleGroup, SWT.NONE);
142+
imagesGroup.setLayout (new GridLayout ());
143+
imagesGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, true));
144+
imagesGroup.setText ("Images");
132145
}
133146

134147
/**
@@ -205,22 +218,44 @@ void createExampleWidgets () {
205218
Cursor cursor = (item != null) ? (Cursor) item.getData() : null;
206219
cursors.setCursor(cursor);
207220
});
221+
222+
/* Create the images table widget */
223+
images = new Table (imagesGroup, style | SWT.V_SCROLL);
224+
images.setLayoutData(new GridData (SWT.FILL, SWT.FILL, false, true));
225+
images.setHeaderVisible(true);
226+
// fill in the table.
227+
for (String columnTitle : columnTitles2) {
228+
TableColumn tableColumn1 = new TableColumn(images, SWT.NONE);
229+
tableColumn1.setText(columnTitle);
230+
tableColumn1.setToolTipText(ControlExample.getResourceString("Tooltip", columnTitle));
231+
}
232+
for (Entry<Integer, String> entry : imap.entrySet()) {
233+
Integer key = entry.getKey();
234+
String value = entry.getValue();
235+
TableItem item = new TableItem(images, SWT.NONE);
236+
item.setText(value);
237+
item.setText(0, value);
238+
item.setImage(1, display.getSystemImage(key));
239+
}
240+
for (int i = 0; i < columnTitles2.length; i++) {
241+
images.getColumn(i).pack();
242+
}
208243
}
209244

210245
/**
211246
* Gets the "Example" widget children.
212247
*/
213248
@Override
214249
Widget [] getExampleWidgets () {
215-
return new Widget [] {colors, cursors};
250+
return new Widget [] {colors, cursors, images};
216251
}
217252

218253
/**
219254
* Gets the Tab name.
220255
*/
221256
@Override
222257
String getTabText () {
223-
return "Color";
258+
return "System";
224259
}
225260

226261
/**

0 commit comments

Comments
 (0)