From b71b2c4208c1f2074f928e893857a908273b1769 Mon Sep 17 00:00:00 2001 From: Lee Venable Date: Fri, 6 Sep 2013 13:47:07 -0500 Subject: [PATCH] Issue #2342 - fixed color memory leak and NPE Change-Id: I34c6bf75f3901f7304ef392a4549f51f599752ff Former-commit-id: 68411a30159f8251937f78d77f561c20a4822e48 --- .../colorscalemgr/ColorScaleMgrDlg.java | 86 ++++++++++++------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/colorscalemgr/ColorScaleMgrDlg.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/colorscalemgr/ColorScaleMgrDlg.java index 8918829b33..7f5b029bfe 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/colorscalemgr/ColorScaleMgrDlg.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/colorscalemgr/ColorScaleMgrDlg.java @@ -72,6 +72,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * 11 Mar 2013 15065 lbousaidi fixed issue with both color legend * disappearing after save * 01 Jul 2013 2088 rferrel Changes for non-blocking dialogs. + * 06 Sep 2013 #2342 lvenable Fixed color memory leaks and a null point exception. * * * @author lvenable @@ -125,6 +126,11 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { */ private java.util.List usedColorValLblArray; + /** + * Browse Color/Value array of color and value labels. + */ + private java.util.List browseColorValLblArray; + /** * Source combo box. */ @@ -236,8 +242,6 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { */ private Combo browseDurationCbo; - private java.util.List browseColorValLblArray; - private Composite browseLabelComp; private Integer selectedDurationInSeconds = 0; @@ -248,21 +252,6 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { private Button saveAsUserBtn, saveAsOfficeBtn; - /** - * Common mouse listener for labels in the Color Value Label Bar. - */ - private final MouseListener lableMouseListener = new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - Label lbl = (Label) e.getSource(); - ColorValueLabels cvl = (ColorValueLabels) lbl.getData(); - updateEditControlsValueSelected(cvl); - updateEditControlsColorSelected(cvl); - String source = getSource(); - changeColor(cvl.getRgbColor(), source); - } - }; - /** * Constructor. * @@ -300,6 +289,17 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { updateButtons(); } + @Override + protected void disposed() { + if (currentColor != null) { + currentColor.dispose(); + } + + disposeLabelsInArray(colorValLblArray); + disposeLabelsInArray(usedColorValLblArray); + disposeLabelsInArray(browseColorValLblArray); + } + /** * Create the tab folder container. */ @@ -900,6 +900,21 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { } + /** + * Common mouse listener for labels in the Color Value Label Bar. + */ + private final MouseListener lableMouseListener = new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + Label lbl = (Label) e.getSource(); + ColorValueLabels cvl = (ColorValueLabels) lbl.getData(); + updateEditControlsValueSelected(cvl); + updateEditControlsColorSelected(cvl); + String source = getSource(); + changeColor(cvl.getRgbColor(), source); + } + }; + /** * Update the color label on the display * @@ -1443,11 +1458,8 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { * adding/updating/deleting color/value pairs or when the data type changes. */ private void updateColorValueLabelBar() { - for (int i = 0; i < colorValLblArray.size(); i++) { - colorValLblArray.get(i).disposeLabels(); - } - colorValLblArray.clear(); + disposeLabelsInArray(colorValLblArray); String source = getSource(); @@ -1492,11 +1504,8 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { * same as updateColorValueLabelBar but for Browse Color Sets tab */ private void updateBrowseColorValueLabelBar() { - for (int i = 0; i < browseColorValLblArray.size(); i++) { - browseColorValLblArray.get(i).disposeLabels(); - } - browseColorValLblArray.clear(); + disposeLabelsInArray(browseColorValLblArray); String source = getSource(); @@ -1537,11 +1546,8 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { * adding/updating/deleting color/value pairs or when the data type changes. */ private void updateUsedColorValueLabelBar() { - for (int i = 0; i < usedColorValLblArray.size(); i++) { - usedColorValLblArray.get(i).disposeLabels(); - } - usedColorValLblArray.clear(); + disposeLabelsInArray(usedColorValLblArray); String source = getSource(); @@ -1610,6 +1616,22 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { } } + /** + * Dispose of the labels/colors in the specified array. + * + * @param array + * Array of color value labels. + */ + private void disposeLabelsInArray(java.util.List array) { + if (array != null) { + for (ColorValueLabels cvl : array) { + cvl.disposeLabels(); + } + + array.clear(); + } + } + /** * Update to user's selected color value. * @@ -1901,7 +1923,11 @@ public class ColorScaleMgrDlg extends CaveSWTDialog { // add a check in case there is a typo in dataType the it will be // null if (!dt.contains("null")) { - dataTypeCbo.add(colorManager.getDescription(dt)); + String description = colorManager.getDescription(dt); + + if (description != null) { + dataTypeCbo.add(description); + } } }