Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

/**
Expand Down Expand Up @@ -48,7 +47,7 @@ public Color getColor(RGB rgb) {
synchronized (fColorTable) {
color = fColorTable.get(rgb);
if (color == null) {
PlatformUI.getWorkbench().getDisplay().syncExec(() -> fColorTable.put(rgb, new Color(Display.getCurrent(), rgb)));
PlatformUI.getWorkbench().getDisplay().syncExec(() -> fColorTable.put(rgb, new Color(rgb)));
color = fColorTable.get(rgb);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.texteditor.AbstractTextEditor;

/**
Expand Down Expand Up @@ -114,22 +113,22 @@ protected void initializeViewerColors(ISourceViewer viewer, IPreferenceStore sto

// ----------- foreground color --------------------
Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
styledText.setForeground(color);

// ---------- background color ----------------------
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
styledText.setBackground(color);

// ----------- selection foreground color --------------------
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay());
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND);
styledText.setSelectionForeground(color);

// ---------- selection background color ----------------------
color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay());
: createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND);
styledText.setSelectionBackground(color);
}

Expand All @@ -140,12 +139,10 @@ protected void initializeViewerColors(ISourceViewer viewer, IPreferenceStore sto
* the store to read from
* @param key
* the key used for the lookup in the preference store
* @param display
* the display used create the color
* @return the created color according to the specification in the preference store
* @since 2.0
*/
private Color createColor(IPreferenceStore store, String key, Display display) {
private Color createColor(IPreferenceStore store, String key) {

RGB rgb = null;

Expand All @@ -158,7 +155,7 @@ private Color createColor(IPreferenceStore store, String key, Display display) {
}

if (rgb != null) {
return new Color(display, rgb);
return new Color(rgb);
}
Comment on lines 155 to 159
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setErrorStatus(IStatus status) {
setText(message);
setImage(findImage(status));
if (fErrorMsgAreaBackground == null) {
fErrorMsgAreaBackground = new Color(getDisplay(), ERROR_BACKGROUND_RGB);
fErrorMsgAreaBackground = new Color(ERROR_BACKGROUND_RGB);
}
setBackground(fErrorMsgAreaBackground);
Comment on lines 75 to 78
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -194,7 +193,7 @@ private void declareImage(String key, String path) {
public Color getColor(RGB rgb) {
Color color = fColors.get(rgb);
if (color == null) {
color= new Color(Display.getCurrent(), rgb);
color= new Color(rgb);
fColors.put(rgb, color);
}
return color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public void testStyleOverride() throws Throwable {
assertTrue(Modifier.isStatic(method.getModifiers()), "Required method <\" + method + \"> is not static.\"");

final List<StyleRange> styles = new ArrayList<>();
colorR = new Color(null, 255, 0, 0);
colorG = new Color(null, 0, 255, 0);
colorB = new Color(null, 0, 0, 255);
colorK = new Color(null, 0, 0, 0);
colorW = new Color(null, 255, 255, 255);
colorR = new Color(255, 0, 0);
colorG = new Color(0, 255, 0);
colorB = new Color(0, 0, 255);
colorK = new Color(0, 0, 0);
colorW = new Color(255, 255, 255);

// overwrite in empty list
method.invoke(null, styles, new StyleRange(5, 5, colorR, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

/**
* Generic color manager.
Expand All @@ -43,7 +42,7 @@ public static ColorManager getDefault() {
public Color getColor(RGB rgb) {
Color color= fColorTable.get(rgb);
if (color == null) {
color= new Color(Display.getCurrent(), rgb);
color= new Color(rgb);
fColorTable.put(rgb, color);
}
return color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ protected Color getColor(RGB rgb) {
}
Color color = fColorCache.get(rgb);
if (color == null) {
color = new Color(getControl().getDisplay(), rgb);
color = new Color(rgb);
fColorCache.put(rgb, color);
}
return color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private Color createColor(int color1, int color2, int ratio, Display display) {

RGB blend= BreadcrumbViewer.blend(rgb2, rgb1, ratio);

return new Color(display, blend);
return new Color(blend);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public Color getColor(RGB rgb) {
}
Color color = fColorCache.get(rgb);
if (color == null) {
color = new Color(getDisplay(), rgb);
color = new Color(rgb);
fColorCache.put(rgb, color);
}
return color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ private ColorCache() {
}

public static Color get(RGB rgb) {
return CACHE.computeIfAbsent(rgb, color -> new Color(null, color));
return CACHE.computeIfAbsent(rgb, color -> new Color(color));
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ public void controlResized(ControlEvent e) {
}
});
addPaintListener(this::paint);
Display display = parent.getDisplay();
fFailureColor = new Color(display, 159, 63, 63);
fOKColor = new Color(display, 95, 191, 95);
fStoppedColor = new Color(display, 120, 120, 120);
fFailureColor = new Color(159, 63, 63);
fOKColor = new Color(95, 191, 95);
fStoppedColor = new Color(120, 120, 120);
}

Comment on lines +62 to 64
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ public void paintControl(PaintEvent e) {

if (fIndicatorColor != null) {
Display d= fSummaryHeader.getDisplay();
e.gc.setBackground(getColor(d, fIndicatorColor));
e.gc.setBackground(getColor(fIndicatorColor));
int min= Math.min(s.x, s.y)-2*INSET;
Rectangle r= new Rectangle((s.x-min)/2, (s.y-min)/2, min, min);
e.gc.fillRectangle(r);
Expand Down Expand Up @@ -1366,8 +1366,8 @@ public void applyTextPresentation(TextPresentation textPresentation) {
}

private StyleRange getStyleRange(Diff diff, IRegion region, boolean showAdditionRemoval) {
//Color cText = getColor(null, getTextColor());
Color cTextFill = getColor(null, getTextFillColor(diff, showAdditionRemoval));
//Color cText = getColor(getTextColor());
Color cTextFill = getColor(getTextFillColor(diff, showAdditionRemoval));
if (cTextFill == null) {
return null;
}
Expand Down Expand Up @@ -1842,7 +1842,7 @@ private void updateColors(Display display) {

Color bgColor = null;
if (fBackground != null) {
bgColor = getColor(display, fBackground);
bgColor = getColor(fBackground);
}

if (fAncestor != null) {
Expand All @@ -1857,7 +1857,7 @@ private void updateColors(Display display) {

Color fgColor = null;
if (fForeground != null) {
fgColor = getColor(display, fForeground);
fgColor = getColor(fForeground);
}

if (fAncestor != null) {
Expand Down Expand Up @@ -2435,7 +2435,6 @@ private void paintBirdsEyeView(Canvas canvas, GC gc) {
return;
}

Display display= canvas.getDisplay();
int y= 0;
boolean allOutgoing = allOutgoing();
for (Iterator<Diff> iterator = fMerger.rangesIterator(); iterator.hasNext();) {
Expand All @@ -2451,12 +2450,12 @@ private void paintBirdsEyeView(Canvas canvas, GC gc) {
hh= 3;
}

c = getColor(display, getFillColor(diff, allOutgoing));
c = getColor(getFillColor(diff, allOutgoing));
if (c != null) {
gc.setBackground(c);
gc.fillRectangle(BIRDS_EYE_VIEW_INSET, yy, size.x-(2*BIRDS_EYE_VIEW_INSET),hh);
}
c = getColor(display, getStrokeColor(diff, allOutgoing));
c = getColor(getStrokeColor(diff, allOutgoing));
if (c != null) {
gc.setForeground(c);
r.x= BIRDS_EYE_VIEW_INSET;
Expand Down Expand Up @@ -2785,7 +2784,7 @@ public void focusLost(FocusEvent fe) {
}

if (fBackground != null) { // not default
te.setBackground(getColor(parent.getDisplay(), fBackground));
te.setBackground(getColor(fBackground));
}

// Add the find action to the popup menu of the viewer
Expand Down Expand Up @@ -2863,8 +2862,7 @@ private void contributeDiffBackgroundListener(final MergeSourceViewer viewer) {
if (diff != null && updateDiffBackground(diff)) {
// highlights only the event line, not the
// whole diff
event.lineBackground = getColor(fComposite
.getDisplay(), getFillColor(diff, allOutgoing()));
event.lineBackground = getColor(getFillColor(diff, allOutgoing()));
}
}
}
Expand Down Expand Up @@ -4542,8 +4540,8 @@ private void paintCenter(Canvas canvas, GC g) {
fPts[0]= x; fPts[1]= ly; fPts[2]= w; fPts[3]= ry;
fPts[6]= x; fPts[7]= ly+lh; fPts[4]= w; fPts[5]= ry+rh;

Color fillColor = getColor(display, getFillColor(diff, allOutgoing));
Color strokeColor = getColor(display, getStrokeColor(diff, allOutgoing));
Color fillColor = getColor(getFillColor(diff, allOutgoing));
Color strokeColor = getColor(getStrokeColor(diff, allOutgoing));

if (fUseSingleLine) {
int w2= 3;
Expand Down Expand Up @@ -4672,15 +4670,15 @@ private void paintSides(GC g, MergeSourceViewer tp, Canvas canvas, boolean right
break;
}

g.setBackground(getColor(display, getFillColor(diff, allOutgoing)));
g.setBackground(getColor(getFillColor(diff, allOutgoing)));
if (right) {
g.fillRectangle(x, y, w2, h);
} else {
g.fillRectangle(x+w2, y, w2, h);
}

g.setLineWidth(0 /* LW */);
g.setForeground(getColor(display, getStrokeColor(diff, allOutgoing)));
g.setForeground(getColor(getStrokeColor(diff, allOutgoing)));
if (right) {
g.drawRectangle(x-1, y-1, w2, h);
} else {
Expand Down Expand Up @@ -4712,8 +4710,6 @@ private void paint(PaintEvent event, MergeSourceViewer tp) {
Control canvas= (Control) event.widget;
GC g= event.gc;

Display display= canvas.getDisplay();

int w= canvas.getSize().x;
int shift = calculateShift(tp) + (2 - LW);
int maxh= event.y+event.height; // visibleHeight
Expand Down Expand Up @@ -4742,7 +4738,7 @@ private void paint(PaintEvent event, MergeSourceViewer tp) {
break;
}

g.setBackground(getColor(display, getStrokeColor(diff, allOutgoing)));
g.setBackground(getColor(getStrokeColor(diff, allOutgoing)));
g.fillRectangle(0, y-1, w, LW);
g.fillRectangle(0, y+h-1, w, LW);
}
Expand Down Expand Up @@ -4807,7 +4803,7 @@ private RGB getStrokeColor(Diff diff, boolean showAdditionRemoval) {
return selected ? palette.selected : palette.normal;
}

private Color getColor(Display display, RGB rgb) {
private Color getColor(RGB rgb) {
if (rgb == null) {
return null;
}
Expand All @@ -4816,7 +4812,7 @@ private Color getColor(Display display, RGB rgb) {
}
Color c= fColors.get(rgb);
if (c == null) {
c= new Color(display, rgb);
c= new Color(rgb);
fColors.put(rgb, c);
}
Comment on lines 4813 to 4817
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

return c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void setErrorMessage(String message) {
setMessage(fMessageText);
} else {
if (fErrorColor == null) {
fErrorColor= new Color(getDisplay(), fErrorRGB);
fErrorColor= new Color(fErrorRGB);
}
setForeground(fErrorColor);
Comment on lines 116 to 119
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

setText(message);
Expand Down
Loading
Loading