Skip to content

Commit 05159bc

Browse files
committed
Minor readability improvements to ControlExample
1 parent 3e1cc4f commit 05159bc

9 files changed

Lines changed: 27 additions & 36 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -210,11 +210,11 @@ void disposeExampleWidgets () {
210210
/* store the state of the Browser if applicable */
211211
if (browser != null) {
212212
String url = browser.getUrl();
213-
if (url.length() > 0 && !url.equals("about:blank")) { //$NON-NLS-1$
213+
if (!url.isEmpty() && !url.equals("about:blank")) { //$NON-NLS-1$
214214
lastUrl = url;
215215
} else {
216216
String text = browser.getText();
217-
if (text.length() > 0) {
217+
if (!text.isEmpty()) {
218218
lastText = text;
219219
}
220220
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -448,7 +448,7 @@ void setSingleTabs () {
448448
*/
449449
void setImages () {
450450
boolean setImage = imageButton.getSelection ();
451-
CTabItem items[] = tabFolder1.getItems ();
451+
CTabItem[] items = tabFolder1.getItems ();
452452
for (CTabItem item : items) {
453453
if (setImage) {
454454
item.setImage (instance.images[ControlExample.ciClosedFolder]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -35,7 +35,7 @@
3535
import org.eclipse.swt.widgets.Widget;
3636

3737
class CanvasTab extends Tab {
38-
static final int colors [] = {
38+
static final int[] colors = {
3939
SWT.COLOR_RED,
4040
SWT.COLOR_GREEN,
4141
SWT.COLOR_BLUE,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void widgetSelected(SelectionEvent event) {
350350
menu.addMenuListener(menuHiddenAdapter(e -> visible = false));
351351
for (int i = 0; i < 9; ++i) {
352352
final String text = ControlExample.getResourceString("DropDownData_" + i);
353-
if (text.length() != 0) {
353+
if (!text.isEmpty()) {
354354
MenuItem menuItem = new MenuItem(menu, SWT.NONE);
355355
menuItem.setText(text);
356356
/*
@@ -469,7 +469,7 @@ public void widgetSelected(SelectionEvent event) {
469469
menuItem.setMenu(m);
470470
for (int k = 0; k < 9; ++k) {
471471
text = ControlExample.getResourceString("DropDownData_" + k);
472-
if (text.length() != 0) {
472+
if (!text.isEmpty()) {
473473
MenuItem mi = new MenuItem(m, SWT.NONE);
474474
mi.setText(text);
475475
/* Application code to perform the action for the submenu item would go here. */

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2014 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -90,9 +90,7 @@ void createColorAndFontGroup () {
9090
TableItem item = new TableItem(colorAndFontTable, SWT.None);
9191
item.setText(ControlExample.getResourceString ("Link_Foreground_Color"));
9292

93-
shell.addDisposeListener(event -> {
94-
linkForegroundColor = null;
95-
});
93+
shell.addDisposeListener(event -> linkForegroundColor = null);
9694
}
9795

9896
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -52,7 +52,7 @@ class ShellTab extends Tab {
5252
*/
5353
void closeAllShells() {
5454
for (int i = 0; i<shellCount; i++) {
55-
if (shells [i] != null & !shells [i].isDisposed ()) {
55+
if (shells [i] != null && !shells [i].isDisposed ()) {
5656
shells [i].dispose();
5757
shells [i] = null;
5858
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -579,7 +579,7 @@ void createEditEventDialog(Shell parent, int x, int y, final int index) {
579579
doitCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
580580
doitCombo.addSelectionListener(widgetSelectedAdapter(e -> {
581581
String newValue = doitCombo.getText();
582-
if (newValue.length() == 0) {
582+
if (newValue.isEmpty()) {
583583
setFieldsMask &= ~DOIT;
584584
} else {
585585
setFieldsEvent.type = eventType;
@@ -600,7 +600,7 @@ void createEditEventDialog(Shell parent, int x, int y, final int index) {
600600
detailCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
601601
detailCombo.addSelectionListener(widgetSelectedAdapter(e -> {
602602
String newValue = detailCombo.getText();
603-
if (newValue.length() == 0) {
603+
if (newValue.isEmpty()) {
604604
setFieldsMask &= ~DETAIL;
605605
} else {
606606
setFieldsEvent.type = eventType;
@@ -622,7 +622,7 @@ void createEditEventDialog(Shell parent, int x, int y, final int index) {
622622
textText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
623623
textText.addModifyListener(e -> {
624624
String newValue = textText.getText();
625-
if (newValue.length() == 0) {
625+
if (newValue.isEmpty()) {
626626
setFieldsMask &= ~TEXT;
627627
} else {
628628
setFieldsEvent.type = eventType;
@@ -1097,20 +1097,20 @@ void setValue() {
10971097
} else if (typeName.equals("java.lang.String")) {
10981098
parameter = new Object[] {value};
10991099
} else if (typeName.equals("org.eclipse.swt.graphics.Point")) {
1100-
String xy[] = split(value, ',');
1100+
String[] xy = split(value, ',');
11011101
parameter = new Object[] {new Point(Integer.parseInt(xy[0]),Integer.parseInt(xy[1]))};
11021102
} else if (typeName.equals("org.eclipse.swt.graphics.Rectangle")) {
1103-
String xywh[] = split(value, ',');
1103+
String[] xywh = split(value, ',');
11041104
parameter = new Object[] {new Rectangle(Integer.parseInt(xywh[0]),Integer.parseInt(xywh[1]),Integer.parseInt(xywh[2]),Integer.parseInt(xywh[3]))};
11051105
} else if (typeName.equals("[I")) {
1106-
String strings[] = split(value, ',');
1106+
String[] strings = split(value, ',');
11071107
int[] ints = new int[strings.length];
11081108
for (int j = 0; j < strings.length; j++) {
11091109
ints[j] = Integer.parseInt(strings[j]);
11101110
}
11111111
parameter = new Object[] {ints};
11121112
} else if (typeName.equals("[C")) {
1113-
String strings[] = split(value, ',');
1113+
String[] strings = split(value, ',');
11141114
char[] chars = new char[strings.length];
11151115
for (int j = 0; j < strings.length; j++) {
11161116
chars[j] = strings[j].charAt(0);
@@ -1333,7 +1333,7 @@ public void drawOn(GC gc, int iwidth, int iheight) {
13331333
gc.fillRectangle(0, 0, iwidth - 1, iheight - 1);
13341334
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
13351335
gc.drawRectangle(0, 0, iwidth - 1, iheight- 1);
1336-
FontData data[] = font.getFontData();
1336+
FontData[] data = font.getFontData();
13371337
int style = data[0].getStyle();
13381338
switch (style) {
13391339
case SWT.NORMAL:
@@ -1418,11 +1418,11 @@ int getDefaultStyle () {
14181418
Widget [] widgets = getExampleWidgets ();
14191419
Control [] controls = new Control [0];
14201420
for (Widget widget : widgets) {
1421-
if (widget instanceof Control) {
1421+
if (widget instanceof Control control) {
14221422
Control[] newControls = new Control[controls.length + 1];
14231423
System.arraycopy(controls, 0, newControls, 0, controls.length);
14241424
controls = newControls;
1425-
controls[controls.length - 1] = (Control)widget;
1425+
controls[controls.length - 1] = control;
14261426
}
14271427
}
14281428
return controls;

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,6 @@ void createStyleGroup() {
268268
borderButton.setText ("SWT.BORDER");
269269
}
270270

271-
@Override
272-
void disposeExampleWidgets () {
273-
super.disposeExampleWidgets ();
274-
}
275-
276271
/**
277272
* Gets the "Example" widget children's items, if any.
278273
*
@@ -355,7 +350,7 @@ public void widgetSelected(SelectionEvent event) {
355350
menu = new Menu(shell, style | SWT.POP_UP);
356351
for (int i = 0; i < 9; ++i) {
357352
final String text = ControlExample.getResourceString("DropDownData_" + i);
358-
if (text.length() != 0) {
353+
if (!text.isEmpty()) {
359354
MenuItem menuItem = new MenuItem(menu, SWT.NONE);
360355
menuItem.setText(text);
361356
} else {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ private void makeTreeEditable(Tree tree) {
275275
editor.horizontalAlignment = SWT.LEFT;
276276
editor.grabHorizontal = true;
277277

278-
tree.addListener(SWT.MouseDoubleClick, event -> {
279-
treeDoubleClickListener(tree, editor, event);
280-
});
278+
tree.addListener(SWT.MouseDoubleClick, event -> treeDoubleClickListener(tree, editor, event));
281279
}
282280

283281
private void treeDoubleClickListener(Tree tree, final TreeEditor editor, Event event) {
@@ -371,7 +369,7 @@ void createExampleWidgets () {
371369
setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));
372370
}
373371
}
374-
TreeItem treeRoots[] = tree1.getItems ();
372+
TreeItem[] treeRoots = tree1.getItems ();
375373
TreeItem item = new TreeItem (treeRoots[1], SWT.NONE);
376374
setItemText(item, 1, ControlExample.getResourceString("Node_2_2"));
377375
item = new TreeItem (item, SWT.NONE);

0 commit comments

Comments
 (0)