Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2020-08-14 03:37:24 -0400
committerAlexander Kurtakov2020-08-16 02:16:46 -0400
commit17c9f5f5a8e007248fbbedd85a2a3803b29e8b14 (patch)
tree0840e2bc2e373252ffb70286e974d9f1745329ce /examples
parent0381397e333dfda624b113a1720b86531eaf29ad (diff)
downloadeclipse.platform.swt-17c9f5f5a8e007248fbbedd85a2a3803b29e8b14.tar.gz
eclipse.platform.swt-17c9f5f5a8e007248fbbedd85a2a3803b29e8b14.tar.xz
eclipse.platform.swt-17c9f5f5a8e007248fbbedd85a2a3803b29e8b14.zip
Bug 565208: Remove calls to Color.dispose
As these calls are no longer needed, remove the calls and related code around such dispose that is also now redundant. Snippets and examples from Jonahs original change which are not trivial deletions. Change-Id: I7ed3eef25a00badbc0b264342a0e9ba436f1e9fe Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorMenu.java33
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java36
2 files changed, 18 insertions, 51 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorMenu.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorMenu.java
index 2dcfe05cfd..185e95880a 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorMenu.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorMenu.java
@@ -21,7 +21,6 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Resource;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
@@ -132,7 +131,7 @@ public class ColorMenu {
/** Adds the colors items to the menu. */
private void addColorItems(Menu menu, MenuItemListener menuListener,
- List<Resource> menuResources) {
+ List<Image> menuResources) {
Display display = menu.getDisplay();
if (menu.getItemCount() != 0) {
@@ -187,7 +186,7 @@ public class ColorMenu {
/** Adds the pattern items to the menu. */
private void addPatternItems(Menu menu, MenuItemListener menuListener,
- List<Resource> menuResources) {
+ List<Image> menuResources) {
Display display = menu.getDisplay();
if (menu.getItemCount() != 0) {
@@ -256,7 +255,7 @@ public class ColorMenu {
* @param resources
* The list of resources of the menu
*/
- private Image loadImage(Display display, String name, List<Resource> resources) {
+ private Image loadImage(Display display, String name, List<Image> resources) {
Image image = GraphicsExample.loadImage(display, GraphicsExample.class, name);
if (image != null) resources.add(image);
return image;
@@ -272,11 +271,11 @@ public class ColorMenu {
Color customColor;
GraphicsBackground background; // used to store information about the background
ColorListener colorListener;
- List<Resource> resources;
+ List<Image> resourceImages;
public MenuItemListener(Control parent){
this.parent = parent;
- resources = new ArrayList<>();
+ resourceImages = new ArrayList<>();
}
/**
* Method used to set the ColorListener
@@ -289,8 +288,8 @@ public class ColorMenu {
this.colorListener = cl;
}
- public List<Resource> getMenuResources() {
- return resources;
+ public List<Image> getMenuResources() {
+ return resourceImages;
}
@Override
@@ -298,10 +297,10 @@ public class ColorMenu {
switch (event.type) {
case SWT.Dispose:
- for (Resource resource : resources) {
- resource.dispose();
+ for (Image image : resourceImages) {
+ image.dispose();
}
- resources = new ArrayList<>();
+ resourceImages = new ArrayList<>();
break;
case SWT.Selection:
Display display = event.display;
@@ -313,7 +312,6 @@ public class ColorMenu {
}
RGB rgb = dialog.open();
if (rgb == null) return;
- if (customColor != null) customColor.dispose();
customColor = new Color(rgb);
if (customPatternMI != null) customPatternMI.setImage(null);
if (customGradientMI != null) customGradientMI.setImage(null);
@@ -325,8 +323,7 @@ public class ColorMenu {
gb.setBgColor1(customColor);
item.setData(gb);
item.setImage(customImage);
- resources.add(customColor);
- resources.add(customImage);
+ resourceImages.add(customImage);
} else if (customPatternMI == item) {
FileDialog dialog = new FileDialog(parent.getShell());
dialog.setFilterExtensions(new String[] { "*.jpg", "*.gif", "*.*" });
@@ -334,7 +331,6 @@ public class ColorMenu {
if (name == null) return;
if (customColorMI != null) customColorMI.setImage(null);
if (customGradientMI != null) customGradientMI.setImage(null);
- if (customColor != null) customColor.dispose();
if (customImage != null) customImage.dispose();
if (customImageThumb != null) customImageThumb.dispose();
customImage = new Image(display, name);
@@ -344,7 +340,7 @@ public class ColorMenu {
gb.setThumbNail(customImageThumb);
item.setData(gb);
item.setImage(customImageThumb);
- resources.add(customImageThumb);
+ resourceImages.add(customImageThumb);
} else if (customGradientMI == item) {
GradientDialog dialog = new GradientDialog(parent.getShell());
if (background != null) {
@@ -359,7 +355,6 @@ public class ColorMenu {
if (colorA == null || colorB == null) return;
if (customColorMI != null) customColorMI.setImage(null);
if (customPatternMI != null) customPatternMI.setImage(null);
- if (customColor != null) customColor.dispose();
if (customImage != null) customImage.dispose();
customImage = GraphicsExample.createImage(display, colorA,
colorB, 16, 16);
@@ -370,9 +365,7 @@ public class ColorMenu {
gb.setBgColor2(colorB);
item.setData(gb);
item.setImage(customImage);
- resources.add(colorA);
- resources.add(colorB);
- resources.add(customImage);
+ resourceImages.add(customImage);
} else {
if (customColorMI != null) customColorMI.setImage(null);
if (customPatternMI != null) customPatternMI.setImage(null);
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
index 0b0a067193..0d499fe0d0 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
@@ -50,7 +50,6 @@ import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Resource;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -557,7 +556,6 @@ public class TextEditor {
RGB newRgb = dialog.open();
if (newRgb != null) {
if (!newRgb.equals(rgb)) {
- disposeResource(underlineColor);
underlineColor = new Color(newRgb);
}
if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE);
@@ -595,7 +593,6 @@ public class TextEditor {
RGB newRgb = dialog.open();
if (newRgb == null) return;
if (!newRgb.equals(rgb)) {
- disposeResource(strikeoutColor);
strikeoutColor = new Color(newRgb);
}
}
@@ -637,7 +634,6 @@ public class TextEditor {
RGB newRgb = dialog.open();
if (newRgb != null) {
if (!newRgb.equals(rgb)) {
- disposeResource(borderColor);
borderColor = new Color(newRgb);
}
if (borderDashItem.getSelection()) setStyle(BORDER_DASH);
@@ -673,7 +669,6 @@ public class TextEditor {
RGB newRgb = dialog.open();
if (newRgb == null) return;
if (!newRgb.equals(rgb)) {
- disposeResource(textForeground);
textForeground = new Color(newRgb);
}
}
@@ -691,7 +686,6 @@ public class TextEditor {
RGB newRgb = dialog.open();
if (newRgb == null) return;
if (!newRgb.equals(rgb)) {
- disposeResource(textBackground);
textBackground = new Color(newRgb);
}
}
@@ -864,21 +858,11 @@ public class TextEditor {
void disposeRanges(StyleRange[] ranges) {
StyleRange[] allRanges = styledText.getStyleRanges(0, styledText.getCharCount(), false);
for (StyleRange rangeToDispose : ranges) {
- boolean disposeFg = true, disposeBg = true, disposeStrike= true, disposeUnder= true, disposeBorder = true, disposeFont = true;
+ boolean disposeFont = true;
for (StyleRange range : allRanges) {
if (disposeFont && rangeToDispose.font == range.font) disposeFont = false;
- if (disposeFg && rangeToDispose.foreground == range.foreground) disposeFg = false;
- if (disposeBg && rangeToDispose.background == range.background) disposeBg = false;
- if (disposeStrike && rangeToDispose.strikeoutColor == range.strikeoutColor) disposeStrike = false;
- if (disposeUnder && rangeToDispose.underlineColor == range.underlineColor) disposeUnder = false;
- if (disposeBorder && rangeToDispose.borderColor == range.borderColor) disposeBorder = false;
}
if (disposeFont && rangeToDispose.font != textFont && rangeToDispose.font != null) rangeToDispose.font.dispose();
- if (disposeFg && rangeToDispose.foreground != textForeground && rangeToDispose.foreground != null) rangeToDispose.foreground.dispose();
- if (disposeBg && rangeToDispose.background != textBackground && rangeToDispose.background != null) rangeToDispose.background.dispose();
- if (disposeStrike && rangeToDispose.strikeoutColor != strikeoutColor && rangeToDispose.strikeoutColor != null) rangeToDispose.strikeoutColor.dispose();
- if (disposeUnder && rangeToDispose.underlineColor != underlineColor && rangeToDispose.underlineColor != null) rangeToDispose.underlineColor.dispose();
- if (disposeBorder && rangeToDispose.borderColor != borderColor && rangeToDispose.borderColor != null) rangeToDispose.borderColor.dispose();
Object data = rangeToDispose.data;
if (data != null) {
@@ -888,20 +872,15 @@ public class TextEditor {
}
}
- void disposeResource(Resource resource) {
- if (resource == null) return;
+ void disposeResource(Font font) {
+ if (font == null) return;
StyleRange[] styles = styledText.getStyleRanges(0, styledText.getCharCount(), false);
int index = 0;
while (index < styles.length) {
- if (styles[index].font == resource) break;
- if (styles[index].foreground == resource) break;
- if (styles[index].background == resource) break;
- if (styles[index].strikeoutColor == resource) break;
- if (styles[index].underlineColor == resource) break;
- if (styles[index].borderColor == resource) break;
+ if (styles[index].font == font) break;
index++;
}
- if (index == styles.length) resource.dispose();
+ if (index == styles.length) font.dispose();
}
String[] getFontNames() {
@@ -1542,14 +1521,12 @@ public class TextEditor {
if (range.foreground != null) {
styleState |= FOREGROUND;
if (textForeground != range.foreground) {
- disposeResource(textForeground);
textForeground = range.foreground;
}
}
if (range.background != null) {
styleState |= BACKGROUND;
if (textBackground != range.background) {
- disposeResource(textBackground);
textBackground = range.background;
}
}
@@ -1569,13 +1546,11 @@ public class TextEditor {
underlineDoubleItem.setSelection((styleState & UNDERLINE_DOUBLE) != 0);
underlineErrorItem.setSelection((styleState & UNDERLINE_ERROR) != 0);
underlineSquiggleItem.setSelection((styleState & UNDERLINE_SQUIGGLE) != 0);
- disposeResource(underlineColor);
underlineColor = range.underlineColor;
}
}
if (range.strikeout) {
styleState |= STRIKEOUT;
- disposeResource(strikeoutColor);
strikeoutColor = range.strikeoutColor;
}
if (range.borderStyle != SWT.NONE) {
@@ -1587,7 +1562,6 @@ public class TextEditor {
borderSolidItem.setSelection((styleState & BORDER_SOLID) != 0);
borderDashItem.setSelection((styleState & BORDER_DASH) != 0);
borderDotItem.setSelection((styleState & BORDER_DOT) != 0);
- disposeResource(borderColor);
borderColor = range.borderColor;
}
}

Back to the top