diff options
| author | Lars Vogel | 2020-08-14 07:36:39 +0000 |
|---|---|---|
| committer | Lars Vogel | 2020-08-14 08:54:37 +0000 |
| commit | 07b18ab8c1a59aa7fddc2a1adacf964ab9df3df0 (patch) | |
| tree | a6486417fa9853d0e52299a1b7dbd04cc01e9711 | |
| parent | 1dc73fb2effeb705a1a411c4d4b0a71de5a5230a (diff) | |
| download | eclipse.platform.swt-07b18ab8c1a59aa7fddc2a1adacf964ab9df3df0.tar.gz eclipse.platform.swt-07b18ab8c1a59aa7fddc2a1adacf964ab9df3df0.tar.xz eclipse.platform.swt-07b18ab8c1a59aa7fddc2a1adacf964ab9df3df0.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
Change-Id: I42b957c9321fb1b40e5447f787f120715e31876c
Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
15 files changed, 6 insertions, 81 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java index 4a291150d6..e2deed9bd4 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java @@ -145,10 +145,8 @@ class CTabFolderTab extends Tab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = selectionForegroundColor; selectionForegroundColor = new Color (rgb); setSelectionForeground (); - if (oldColor != null) oldColor.dispose (); } break; case SELECTION_BACKGROUND_COLOR: { @@ -157,10 +155,8 @@ class CTabFolderTab extends Tab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = selectionBackgroundColor; selectionBackgroundColor = new Color (rgb); setSelectionBackground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_FONT: { @@ -182,10 +178,8 @@ class CTabFolderTab extends Tab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemForegroundColor; itemForegroundColor = new Color (rgb); setItemForeground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_BACKGROUND_COLOR: { @@ -194,10 +188,8 @@ class CTabFolderTab extends Tab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemBackgroundColor; itemBackgroundColor = new Color (rgb); setItemBackground (); - if (oldColor != null) oldColor.dispose (); } break; default: diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java index 65e70a1825..91100d8ba6 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java @@ -105,10 +105,8 @@ class LinkTab extends Tab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = linkForegroundColor; linkForegroundColor = new Color (rgb); setLinkForeground (); - if (oldColor != null) oldColor.dispose (); } break; default: diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java index e7bc6a69bb..c585afd0c3 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java @@ -460,10 +460,8 @@ abstract class Tab { if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = foregroundColor; // save old foreground color to dispose when done foregroundColor = new Color (rgb); setExampleWidgetForeground (); - if (oldColor != null) oldColor.dispose (); } break; case BACKGROUND_COLOR: { @@ -475,10 +473,8 @@ abstract class Tab { if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = backgroundColor; // save old background color to dispose when done backgroundColor = new Color (rgb); setExampleWidgetBackground (); - if (oldColor != null) oldColor.dispose (); } break; case FONT: { diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java index 1a85041d50..6c4cab1325 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TableTab.java @@ -144,10 +144,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemForegroundColor; itemForegroundColor = new Color (rgb); setItemForeground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_BACKGROUND_COLOR: { @@ -156,10 +154,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemBackgroundColor; itemBackgroundColor = new Color (rgb); setItemBackground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_FONT: { @@ -181,10 +177,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = cellForegroundColor; cellForegroundColor = new Color (rgb); setCellForeground (); - if (oldColor != null) oldColor.dispose (); } break; case CELL_BACKGROUND_COLOR: { @@ -193,10 +187,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = cellBackgroundColor; cellBackgroundColor = new Color (rgb); setCellBackground (); - if (oldColor != null) oldColor.dispose (); } break; case CELL_FONT: { @@ -218,10 +210,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = headerForegroundColor; headerForegroundColor = new Color (rgb); setHeaderForeground (); - if (oldColor != null) oldColor.dispose (); } break; case HEADER_BACKGROUND_COLOR: { @@ -230,10 +220,8 @@ class TableTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = headerBackgroundColor; headerBackgroundColor = new Color (rgb); setHeaderBackground (); - if (oldColor != null) oldColor.dispose (); } break; default: diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java index 95c3c06be8..893ab7c828 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TreeTab.java @@ -146,10 +146,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemForegroundColor; itemForegroundColor = new Color (rgb); setItemForeground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_BACKGROUND_COLOR: { @@ -158,10 +156,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = itemBackgroundColor; itemBackgroundColor = new Color (rgb); setItemBackground (); - if (oldColor != null) oldColor.dispose (); } break; case ITEM_FONT: { @@ -183,10 +179,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = cellForegroundColor; cellForegroundColor = new Color (rgb); setCellForeground (); - if (oldColor != null) oldColor.dispose (); } break; case CELL_BACKGROUND_COLOR: { @@ -195,10 +189,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = cellBackgroundColor; cellBackgroundColor = new Color (rgb); setCellBackground (); - if (oldColor != null) oldColor.dispose (); } break; case CELL_FONT: { @@ -220,10 +212,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = headerForegroundColor; headerForegroundColor = new Color (rgb); setHeaderForeground (); - if (oldColor != null) oldColor.dispose (); } break; case HEADER_BACKGROUND_COLOR: { @@ -232,10 +222,8 @@ class TreeTab extends ScrollableTab { colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; - oldColor = headerBackgroundColor; headerBackgroundColor = new Color (rgb); setHeaderBackground (); - if (oldColor != null) oldColor.dispose (); } default: super.changeFontOrColor(index); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java index 494c930555..14dec54fee 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java @@ -152,8 +152,6 @@ public class GradientDialog extends Dialog { e.gc.drawImage (preview, 0, 0); } preview.dispose(); - color1.dispose(); - color2.dispose(); }); // composite used for both color buttons @@ -176,7 +174,6 @@ public class GradientDialog extends Dialog { colorButton1.setText(GraphicsExample.getResourceString("GradientDlgButton1")); Color color1 = new Color(rgb1); Image img1 = GraphicsExample.createImage(display, color1); - color1.dispose(); colorButton1.setImage(img1); resources.add(img1); menu1 = colorMenu.createMenu(parent.getParent(), gb -> { @@ -198,7 +195,6 @@ public class GradientDialog extends Dialog { colorButton2.setText(GraphicsExample.getResourceString("GradientDlgButton2")); Color color2 = new Color(rgb2); Image img2 = GraphicsExample.createImage(display, color2); - color2.dispose(); colorButton2.setImage(img2); resources.add(img2); menu2 = colorMenu.createMenu(parent.getParent(), gb -> { diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java index 782233c039..174140583a 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java @@ -1488,16 +1488,12 @@ public class ImageAnalyzer { RGB backgroundRGB = imageData.palette.getRGB(backgroundPixel); bgColor = new Color(backgroundRGB); } - try { - offScreenImageGC.setBackground(bgColor != null ? bgColor : canvasBackground); - offScreenImageGC.fillRectangle( - imageData.x, - imageData.y, - imageData.width, - imageData.height); - } finally { - if (bgColor != null) bgColor.dispose(); - } + offScreenImageGC.setBackground(bgColor != null ? bgColor : canvasBackground); + offScreenImageGC.fillRectangle( + imageData.x, + imageData.y, + imageData.width, + imageData.height); } else if (imageData.disposalMethod == SWT.DM_FILL_PREVIOUS) { // Restore the previous image before drawing. offScreenImageGC.drawImage( @@ -1857,7 +1853,6 @@ public class ImageAnalyzer { Color color = new Color(rgbs[i]); gc.setBackground(color); gc.fillRectangle(xTab2, y+2, 10, 10); - color.dispose(); } } } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaLineStyler.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaLineStyler.java index 98970b0905..49adf36e57 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaLineStyler.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaLineStyler.java @@ -88,12 +88,6 @@ void initializeColors() { tokenColors[NUMBER]= 0; } -void disposeColors() { - for (Color color : colors) { - color.dispose(); - } -} - /** * Event.detail line start offset (input) * Event.text line text (input) diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java index b1bb978568..64ec400e27 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java @@ -80,7 +80,6 @@ void createShell (Display display) { layout.numColumns = 1; shell.setLayout(layout); shell.addShellListener(ShellListener.shellClosedAdapter(e -> { - lineStyler.disposeColors(); text.removeLineStyleListener(lineStyler); })); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java index 2810d0faf9..625984985d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java @@ -344,11 +344,6 @@ public class PaintExample { */ public void dispose() { if (paintSurface != null) paintSurface.dispose(); - if (paintColors != null) { - for (final Color color : paintColors) { - if (color != null) color.dispose(); - } - } paintDefaultFont = null; paintColors = null; paintSurface = null; diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java index 589430eeb3..ee7c34162c 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java @@ -97,8 +97,6 @@ public class Snippet133 { if (!display.readAndDispatch()) display.sleep(); } if (font != null) font.dispose(); - if (foregroundColor != null) foregroundColor.dispose(); - if (backgroundColor != null) backgroundColor.dispose(); display.dispose(); } @@ -152,7 +150,6 @@ public class Snippet133 { colorDialog.setRGB(text.getForeground().getRGB()); RGB rgb = colorDialog.open(); if (rgb != null) { - if (foregroundColor != null) foregroundColor.dispose(); foregroundColor = new Color(rgb); text.setForeground(foregroundColor); } @@ -163,7 +160,6 @@ public class Snippet133 { colorDialog.setRGB(text.getBackground().getRGB()); RGB rgb = colorDialog.open(); if (rgb != null) { - if (backgroundColor != null) backgroundColor.dispose(); backgroundColor = new Color(rgb); text.setBackground(backgroundColor); } @@ -231,8 +227,6 @@ public class Snippet133 { /* Cleanup graphics resources used in printing */ printerFont.dispose(); - printerForegroundColor.dispose(); - printerBackgroundColor.dispose(); gc.dispose(); } } diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet280.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet280.java index 488be41e5a..3554aaf0b3 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet280.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet280.java @@ -39,15 +39,11 @@ public static void main (String [] args) { gc.setForeground(color1); gc.setBackground(color2); gc.fillGradientRectangle (rect.x, rect.y, rect.width, rect.height / 2, true); - color1.dispose (); - color2.dispose (); Color color3 = new Color (190, 230, 253); Color color4 = new Color (167, 217, 245); gc.setForeground(color3); gc.setBackground(color4); gc.fillGradientRectangle (rect.x, rect.y + (rect.height / 2), rect.width, rect.height / 2 + 1, true); - color3.dispose (); - color4.dispose (); }); shell.setSize (200, 64); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet281.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet281.java index 2c003c2c4d..16491a41dc 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet281.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet281.java @@ -46,10 +46,6 @@ public static void main (String [] args) { gc.fillRectangle (rect.x, rect.y + (rect.height / 2), rect.width, rect.height / 2 + 1); p1.dispose (); p2.dispose (); - color1.dispose (); - color2.dispose (); - color3.dispose (); - color4.dispose (); }); shell.setSize (200, 64); shell.open (); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.java index 20ba6d96ee..622a0bccf8 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.java @@ -115,7 +115,6 @@ public class Snippet288 { } gc.setBackground(bgColor != null ? bgColor : shellBackground); gc.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); - if (bgColor != null) bgColor.dispose(); break; default: /* Restore the previous image before drawing. */ diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet316.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet316.java index a291cf440f..96af96bcdc 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet316.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet316.java @@ -49,7 +49,6 @@ public class Snippet316 { if (!display.readAndDispatch ()) display.sleep (); } font.dispose(); - color.dispose(); display.dispose (); } } |
