Skip to content

Commit 238dd93

Browse files
committed
Stop using Color constructors with Display
Simplifies the code and reduces chances for problems. Contributes to eclipse-platform/eclipse.platform.swt#3233 .
1 parent 620bbd0 commit 238dd93

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/TestMessageConsoleActionDelegate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 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
@@ -20,7 +20,6 @@
2020
import org.eclipse.jface.viewers.ISelection;
2121
import org.eclipse.swt.graphics.Color;
2222
import org.eclipse.swt.widgets.ColorDialog;
23-
import org.eclipse.swt.widgets.Display;
2423
import org.eclipse.swt.widgets.Event;
2524
import org.eclipse.ui.IActionDelegate2;
2625
import org.eclipse.ui.IWorkbenchWindow;
@@ -77,7 +76,7 @@ public void run(IAction action) {
7776
stream.println("two.... three....");
7877
ColorDialog dialog = new ColorDialog(DebugUIPlugin.getShell());
7978
dialog.open();
80-
Color color = new Color(Display.getCurrent(), dialog.getRGB());
79+
Color color = new Color(dialog.getRGB());
8180
stream.setColor(color);
8281
}
8382

org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/detailpane/SimpleDetailPane.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2015 IBM Corporation and others.
2+
* Copyright (c) 2007, 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
@@ -76,24 +76,24 @@ public Control createControl(Composite parent) {
7676
private Color getColor(int typeId){
7777
if (typeId == TYPE_PRIVATE){
7878
if (colorPrivate == null || colorPrivate.isDisposed()){
79-
colorPrivate = new Color(theLabel.getDisplay(),255,0,0);
79+
colorPrivate = new Color(255, 0, 0);
8080
}
8181
return colorPrivate;
8282
}
8383
if (typeId == TYPE_PROTECTED){
8484
if (colorProtected == null || colorProtected.isDisposed()){
85-
colorProtected = new Color(theLabel.getDisplay(),0,0,255);
85+
colorProtected = new Color(0, 0, 255);
8686
}
8787
return colorProtected;
8888
}
8989
if (typeId == TYPE_PUBLIC){
9090
if (colorPublic == null || colorPublic.isDisposed()){
91-
colorPublic = new Color(theLabel.getDisplay(),0,255,0);
91+
colorPublic = new Color(0, 255, 0);
9292
}
9393
return colorPublic;
9494
}
9595
if (colorOther == null || colorOther.isDisposed()){
96-
colorOther = new Color(theLabel.getDisplay(),0,0,0);
96+
colorOther = new Color(0, 0, 0);
9797
}
9898
return colorOther;
9999
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDISourceViewer.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 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
@@ -45,7 +45,6 @@
4545
import org.eclipse.swt.graphics.Point;
4646
import org.eclipse.swt.graphics.RGB;
4747
import org.eclipse.swt.widgets.Composite;
48-
import org.eclipse.swt.widgets.Display;
4948
import org.eclipse.ui.texteditor.AbstractTextEditor;
5049

5150
/**
@@ -166,15 +165,13 @@ public void updateViewerColors() {
166165
IPreferenceStore store= getPreferenceStore();
167166
if (store != null) {
168167
StyledText styledText= getTextWidget();
169-
Color color= store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT)
170-
? null
171-
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
168+
Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null
169+
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
172170
styledText.setForeground(color);
173171
setForegroundColor(color);
174172

175-
color= store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
176-
? null
177-
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
173+
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
174+
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
178175
styledText.setBackground(color);
179176
setBackgroundColor(color);
180177
}
@@ -184,7 +181,7 @@ public void updateViewerColors() {
184181
* Creates a color from the information stored in the given preference store.
185182
* Returns <code>null</code> if there is no such information available.
186183
*/
187-
private Color createColor(IPreferenceStore store, String key, Display display) {
184+
private Color createColor(IPreferenceStore store, String key) {
188185
RGB rgb= null;
189186
if (store.contains(key)) {
190187
if (store.isDefault(key)) {
@@ -193,7 +190,7 @@ private Color createColor(IPreferenceStore store, String key, Display display) {
193190
rgb= PreferenceConverter.getColor(store, key);
194191
}
195192
if (rgb != null) {
196-
return new Color(display, rgb);
193+
return new Color(rgb);
197194
}
198195
}
199196
return null;

0 commit comments

Comments
 (0)