Issue #2342 - fixed color memory leak and NPE

Change-Id: I34c6bf75f3901f7304ef392a4549f51f599752ff

Former-commit-id: 52667faab5 [formerly b71b2c4208] [formerly 508757bce6 [formerly 68411a30159f8251937f78d77f561c20a4822e48]]
Former-commit-id: 508757bce6
Former-commit-id: 74d23f7948
This commit is contained in:
Lee Venable 2013-09-06 13:47:07 -05:00
parent c9db55561e
commit 9f3666fbbe

View file

@ -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.
* </pre>
*
* @author lvenable
@ -125,6 +126,11 @@ public class ColorScaleMgrDlg extends CaveSWTDialog {
*/
private java.util.List<ColorValueLabels> usedColorValLblArray;
/**
* Browse Color/Value array of color and value labels.
*/
private java.util.List<ColorValueLabels> browseColorValLblArray;
/**
* Source combo box.
*/
@ -236,8 +242,6 @@ public class ColorScaleMgrDlg extends CaveSWTDialog {
*/
private Combo browseDurationCbo;
private java.util.List<ColorValueLabels> 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<ColorValueLabels> 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);
}
}
}