-
Notifications
You must be signed in to change notification settings - Fork 162
Update Color constructors to use Device-less versions #2622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Device-less |
||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Device-less |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Device-less |
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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();) { | ||
|
|
@@ -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; | ||
|
|
@@ -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 | ||
|
|
@@ -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())); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -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; | ||
|
|
@@ -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 { | ||
|
|
@@ -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 | ||
|
|
@@ -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); | ||
| } | ||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Device-less |
||
| return c; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Device-less |
||
| setText(message); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device-less
Colorinstances (created without aDevice/Displayargument) 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