Skip to content

Replace usages of new Image(device, width, height) #2869

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

Merged
merged 2 commits into from
Apr 9, 2025
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
2 changes: 1 addition & 1 deletion bundles/org.eclipse.e4.ui.css.swt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.ui.css.swt;singleton:=true
Bundle-Version: 0.15.500.qualifier
Bundle-Version: 0.15.600.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
Expand Down Expand Up @@ -149,23 +150,23 @@ public void handleEvent(Event event) {
boolean verticalGradient = grad.getVerticalGradient();
int x = verticalGradient? 2 : size.x;
int y = verticalGradient ? size.y : 2;
gradientImage = new Image(control.getDisplay(), x, y);
GC gc = new GC(gradientImage);
List<Color> colors = new ArrayList<>();
for (Object rgbObj : grad.getRGBs()) {
if (rgbObj instanceof RGBA) {
RGBA rgba = (RGBA) rgbObj;
Color color = new Color(control.getDisplay(), rgba);
colors.add(color);
} else if (rgbObj instanceof RGB) {
RGB rgb = (RGB) rgbObj;
Color color = new Color(control.getDisplay(), rgb);
colors.add(color);
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
List<Color> colors = new ArrayList<>();
for (Object rgbObj : grad.getRGBs()) {
if (rgbObj instanceof RGBA) {
RGBA rgba = (RGBA) rgbObj;
Color color = new Color(control.getDisplay(), rgba);
colors.add(color);
} else if (rgbObj instanceof RGB) {
RGB rgb = (RGB) rgbObj;
Color color = new Color(control.getDisplay(), rgb);
colors.add(color);
}
}
}
fillGradient(gc, new Rectangle(0, 0, x, y), colors,
CSSSWTColorHelper.getPercents(grad), grad.getVerticalGradient());
gc.dispose();
fillGradient(gc, new Rectangle(0, 0, width, height), colors, CSSSWTColorHelper.getPercents(grad),
grad.getVerticalGradient());
};
gradientImage = new Image(control.getDisplay(), imageGcDrawer, x, y);
}
if (gradientImage != null) {
control.setBackgroundImage(gradientImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Rectangle;

Check warning on line 25 in bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/ResourceUtility.java

View check run for this annotation

Jenkins - Eclipse Platform / API Tools

ILLEGAL_IMPLEMENT

NORMAL: ResourceUtility illegally implements IResourceUtilities via ISWTResourceUtilities
public class ResourceUtility implements ISWTResourceUtilities {

public ResourceUtility() {
Expand All @@ -48,12 +48,12 @@
return toAdorn;
Rectangle adornmentSize = adornment.getBounds();

Image adornedImage = new Image(toAdorn.getDevice(), 16, 16);
GC gc = new GC(adornedImage);
gc.drawImage(toAdorn, 0, 0);
// For now assume top-right
gc.drawImage(adornment, 16 - adornmentSize.width, 0);
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.drawImage(toAdorn, 0, 0);
// For now assume top-right
gc.drawImage(adornment, 16 - adornmentSize.width, 0);
};
Image adornedImage = new Image(toAdorn.getDevice(), imageGcDrawer, 16, 16);

return adornedImage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
Expand Down Expand Up @@ -261,10 +262,8 @@ public void update(ViewerCell cell) {

private Image getBlankImage() {
if (blankImage==null) {
blankImage = new Image(Display.getDefault(), 1, 1);
// GC gc = new GC(blankImage);
// gc.fillRectangle(0, 0, 16, 16);
// gc.dispose();
final ImageGcDrawer noOp = (gc, width, height) -> {};
blankImage = new Image(Display.getDefault(), noOp, 1, 1);
}
return blankImage;
}
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.editors; singleton:=true
Bundle-Version: 3.19.100.qualifier
Bundle-Version: 3.19.200.qualifier
Bundle-Activator: org.eclipse.ui.internal.editors.text.EditorsPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -1121,16 +1121,16 @@ public Image getImage(Object element) {
RGB rgb= colorEntry.isSystemDefault() ? colorEntry.systemColorRGB : colorEntry.getRGB();
Color color= new Color(tableComposite.getParent().getDisplay(), rgb.red, rgb.green, rgb.blue);
int dimensions= 10;
Image image= new Image(tableComposite.getParent().getDisplay(), dimensions, dimensions);
GC gc= new GC(image);
// Draw color preview
gc.setBackground(color);
gc.fillRectangle(0, 0, dimensions, dimensions);
// Draw outline around color preview
gc.setBackground(new Color(tableComposite.getParent().getDisplay(), 0, 0, 0));
gc.setLineWidth(2);
gc.drawRectangle(0, 0, dimensions, dimensions);
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
// Draw color preview
gc.setBackground(color);
gc.fillRectangle(0, 0, width, height);
// Draw outline around color preview
gc.setBackground(new Color(tableComposite.getParent().getDisplay(), 0, 0, 0));
gc.setLineWidth(2);
gc.drawRectangle(0, 0, width, height);
};
Image image = new Image(tableComposite.getParent().getDisplay(), imageGcDrawer, dimensions, dimensions);
colorPreviewImages.add(image);
return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
Expand Down Expand Up @@ -1557,32 +1558,27 @@ private void paint(PaintEvent e) {
}

private void repaint(GC gc, int x, int y, int width, int height) {
Image textBuffer = new Image(getDisplay(), width, height);
Color bg = getBackground();
Color fg = getForeground();
if (!getEnabled()) {
bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
fg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
GC textGC = new GC(textBuffer, gc.getStyle());
textGC.setForeground(fg);
textGC.setBackground(bg);
textGC.setFont(getFont());
textGC.fillRectangle(0, 0, width, height);
Rectangle repaintRegion = new Rectangle(x, y, width, height);
Color bg = getEnabled() ? getBackground() : getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
Color fg = getEnabled() ? getForeground() : getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);

Paragraph[] paragraphs = model.getParagraphs();
IHyperlinkSegment selectedLink = getSelectedLink();
if (getDisplay().getFocusControl() != this)
selectedLink = null;
for (Paragraph p : paragraphs) {
p
.paint(textGC, repaintRegion, resourceTable, selectedLink,
selData);
}
if (hasFocus && !model.hasFocusSegments())
textGC.drawFocus(x, y, width, height);
textGC.dispose();
IHyperlinkSegment selectedLink = getDisplay().getFocusControl() != this ? null : getSelectedLink();

final ImageGcDrawer textDrawer = (textGC, iWidth, iHeight) -> {
textGC.setForeground(fg);
textGC.setBackground(bg);
textGC.setFont(getFont());
textGC.fillRectangle(0, 0, iWidth, iHeight);
Rectangle repaintRegion = new Rectangle(x, y, iWidth, iHeight);
for (Paragraph p : paragraphs) {
p.paint(textGC, repaintRegion, resourceTable, selectedLink, selData);
}
if (hasFocus && !model.hasFocusSegments()) {
textGC.drawFocus(x, y, iWidth, iHeight);
}
};
Image textBuffer = new Image(getDisplay(), textDrawer, width, height);

gc.drawImage(textBuffer, x, y);
textBuffer.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
Expand Down Expand Up @@ -852,38 +853,35 @@ private void onPaint(GC gc) {
if (carea.width == 0 || carea.height == 0) {
return;
}
Image buffer = new Image(getDisplay(), carea.width, carea.height);
buffer.setBackground(getBackground());
GC igc = new GC(buffer);
igc.setBackground(getBackground());
igc.fillRectangle(0, 0, carea.width, carea.height);
if (getBackgroundImage() != null) {
if (gradientInfo != null)
drawBackground(igc, carea.x, carea.y, carea.width, carea.height);
else {
Image bgImage = getBackgroundImage();
Rectangle ibounds = bgImage.getBounds();
drawBackground(igc, carea.x, carea.y, ibounds.width,
ibounds.height);
final ImageGcDrawer imageGcDrawer = (igc, width, height) -> {
igc.setBackground(getBackground());
igc.fillRectangle(0, 0, width, height);
if (getBackgroundImage() != null) {
if (gradientInfo != null)
drawBackground(igc, carea.x, carea.y, width, height);
else {
Image bgImage = getBackgroundImage();
Rectangle ibounds = bgImage.getBounds();
drawBackground(igc, carea.x, carea.y, ibounds.width, ibounds.height);
}
}
}

if (isSeparatorVisible()) {
// bg separator
if (hasColor(IFormColors.H_BOTTOM_KEYLINE1))
igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE1));
else
igc.setForeground(getBackground());
igc.drawLine(carea.x, carea.height - 2, carea.x + carea.width - 1,
carea.height - 2);
if (hasColor(IFormColors.H_BOTTOM_KEYLINE2))
igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE2));
else
igc.setForeground(getForeground());
igc.drawLine(carea.x, carea.height - 1, carea.x + carea.width - 1,
carea.height - 1);
}
igc.dispose();
if (isSeparatorVisible()) {
// bg separator
if (hasColor(IFormColors.H_BOTTOM_KEYLINE1))
igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE1));
else
igc.setForeground(getBackground());
igc.drawLine(carea.x, height - 2, carea.x + width - 1, height - 2);
if (hasColor(IFormColors.H_BOTTOM_KEYLINE2))
igc.setForeground(getColor(IFormColors.H_BOTTOM_KEYLINE2));
else
igc.setForeground(getForeground());
igc.drawLine(carea.x, height - 1, carea.x + width - 1, height - 1);
}
};
Image buffer = new Image(getDisplay(), imageGcDrawer, carea.width, carea.height);
buffer.setBackground(getBackground());
gc.drawImage(buffer, carea.x, carea.y);
buffer.dispose();
}
Expand All @@ -908,12 +906,12 @@ private void updateGradientImage() {
gradientImage = FormImages.getInstance().getGradient(gradientInfo.gradientColors, gradientInfo.percents,
gradientInfo.vertical ? rect.height : rect.width, gradientInfo.vertical, getColor(COLOR_BASE_BG), getDisplay());
} else if (backgroundImage != null && !isBackgroundImageTiled()) {
gradientImage = new Image(getDisplay(), Math.max(rect.width, 1),
final ImageGcDrawer imageGcDrawer = (gc, width, height) -> {
gc.drawImage(backgroundImage, 0, 0);
};
gradientImage = new Image(getDisplay(), imageGcDrawer, Math.max(rect.width, 1),
Math.max(rect.height, 1));
gradientImage.setBackground(getBackground());
GC gc = new GC(gradientImage);
gc.drawImage(backgroundImage, 0, 0);
gc.dispose();
}
if (oldGradientImage != null) {
FormImages.getInstance().markFinished(oldGradientImage, getDisplay());
Expand Down
Loading
Loading