Issue #2293 - fixed memory leaks

Change-Id: I36b48ba91243a74a3695b95cc485c0f68bfcbbc7

Former-commit-id: ad6bdec9abf6c2a24476ebf0a23e9f4ad74356ba
This commit is contained in:
Lee Venable 2013-08-26 14:52:53 -05:00
parent e214710122
commit a30da2febe
3 changed files with 154 additions and 92 deletions

View file

@ -95,6 +95,7 @@ import com.raytheon.uf.viz.alertviz.ui.audio.IAudioAction;
* May 2, 2011 9067 cjeanbap Preserve text component text on relayout().
* 27 May 2011 9575 cjeanbap Moved moveLabel to first image in list.
* 31 May 2011 8058 cjeanbap Kill sound based on TextMsgBox id.
* 26 Aug 2013 #2293 lvenable Fixed color memory leaks.
* </pre>
*
* @author lvenable
@ -207,6 +208,11 @@ public class AlertMessageDlg implements MouseMoveListener, MouseListener,
private Button errorBtn;
/**
* Error button background color.
*/
private Color errorBtnBgColor = null;
private TabControlDlg tabControlDlg;
private static final String ERROR_FILE_IMAGE = "alertVizErrorLog.png";
@ -267,6 +273,15 @@ public class AlertMessageDlg implements MouseMoveListener, MouseListener,
Shell shell1 = new Shell(parentShell, SWT.NO_TRIM);
shell = new Shell(shell1, SWT.ON_TOP);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (errorBtnBgColor != null) {
errorBtnBgColor.dispose();
}
}
});
// Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(1, false);
mainLayout.marginHeight = 0;
@ -287,11 +302,6 @@ public class AlertMessageDlg implements MouseMoveListener, MouseListener,
enabled = true;
}
// if (!(configData.getGlobalConfiguration().getMode() ==
// TrayConfiguration.TrayMode.MO)) {
// setInitialDialogLocation();
// }
return returnValue;
}
@ -1074,8 +1084,11 @@ public class AlertMessageDlg implements MouseMoveListener, MouseListener,
private void errorButtonAction() {
opened = !opened;
RGB background = new RGB(237, 233, 227);
errorBtn.setBackground(new Color(display, background));
if (errorBtnBgColor != null) {
errorBtnBgColor.dispose();
}
errorBtnBgColor = new Color(display, 237, 233, 227);
errorBtn.setBackground(errorBtnBgColor);
if (tabControlDlg == null || tabControlDlg.isDisposed()) {
tabControlDlg = TabControlDlg.getInstance(shell);
@ -1116,7 +1129,13 @@ public class AlertMessageDlg implements MouseMoveListener, MouseListener,
}
public void setErrorLogBtnBackground(RGB background) {
errorBtn.setBackground(new Color(this.display, background));
if (errorBtnBgColor != null) {
errorBtnBgColor.dispose();
}
errorBtnBgColor = new Color(this.display, background);
errorBtn.setBackground(errorBtnBgColor);
}
/**

View file

@ -48,15 +48,24 @@ import com.raytheon.uf.viz.alertviz.config.Source;
import com.raytheon.uf.viz.alertviz.ui.Activator;
/**
*
* Manage monitor icon and label in Alert viz toolbar.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 26, 2013 #2293 lvenable Fixed color memory leak.
*
* </pre>
*
* @author lvenable
* @version 1.0
*/
public class AlertMonitor {
public static final RGB WHITE = new RGB(255, 255, 255);
public static final RGB BLACK = new RGB(0, 0, 0);
private Label label;
private MonitorToolTip toolTip;
@ -75,9 +84,9 @@ public class AlertMonitor {
private Priority priority;
private RGB background;
private Color backgroundColor;
private RGB foreground;
private Color foregroundColor;
public AlertMonitor(String name, String imageName) {
this.name = name;
@ -113,10 +122,23 @@ public class AlertMonitor {
return name;
}
/**
* Dispose resources.
*/
public void dispose() {
if (this.image != null) {
if (image != null) {
this.image.dispose();
}
if (backgroundColor != null) {
this.backgroundColor.dispose();
}
if (foregroundColor != null) {
this.backgroundColor.dispose();
}
}
public void updateImage(StatusMessage statusMessage, Configuration config,
@ -146,8 +168,8 @@ public class AlertMonitor {
if (pd.colors == null) {
pd.colors = new RGB[2];
}
pd.colors[0] = this.foreground;
pd.colors[1] = this.background;
pd.colors[0] = this.foregroundColor.getRGB();
pd.colors[1] = this.backgroundColor.getRGB();
}
this.image = new Image(display, this.imageData);
if (this.label != null && !this.label.isDisposed()) {
@ -168,11 +190,11 @@ public class AlertMonitor {
AlertMetadata alertMeta = configItem.lookup(this.priority);
if (alertMeta == null) {
this.background = WHITE;
this.foreground = BLACK;
setFgBgColors(display, display.getSystemColor(SWT.COLOR_BLACK)
.getRGB(), display.getSystemColor(SWT.COLOR_WHITE).getRGB());
} else {
this.background = alertMeta.getBackground();
this.foreground = alertMeta.getForeground();
setFgBgColors(display, alertMeta.getForeground(),
alertMeta.getBackground());
}
if (this.imageName == null) {
@ -186,6 +208,27 @@ public class AlertMonitor {
updateImageData(display);
}
/**
* Set the foreground and background colors.
*
* @param foreground
* Foreground color.
* @param background
* Background color.
*/
private void setFgBgColors(Display display, RGB foreground, RGB background) {
if (foregroundColor != null) {
foregroundColor.dispose();
}
if (backgroundColor != null) {
backgroundColor.dispose();
}
foregroundColor = new Color(display, foreground);
backgroundColor = new Color(display, background);
}
private void setMonitorMessage(String message, Configuration config,
Display display) {
this.monitorMessage = message;
@ -196,8 +239,8 @@ public class AlertMonitor {
this.label.setData(MonitorToolTip.tooltipTextKey, this.monitorMessage);
this.loadConfig(config, display);
this.label.setBackground(new Color(display, background));
this.label.setForeground(new Color(display, foreground));
this.label.setBackground(backgroundColor);
this.label.setForeground(foregroundColor);
}
public void init(Composite comp, final Configuration config,

View file

@ -96,6 +96,7 @@ import com.raytheon.uf.viz.alertviz.ui.dialogs.ConfigurationFileDlg.Function;
* 07 Feb 2013 15292 Xiaochuan Confirmation message is not necessary when source
* item update;
* 07 Feb 2013 15490 Xiaochuan Past this object to LayoutControlsComp.
* 26 Aug 2013 #2293 lvenable Fixed color memory leak and cleaned up some code.
*
* </pre>
*
@ -106,17 +107,15 @@ import com.raytheon.uf.viz.alertviz.ui.dialogs.ConfigurationFileDlg.Function;
public class AlertVisConfigDlg extends Dialog implements
IConfigurationChangedListener, INeedsSaveListener {
private static final String TITLE = "Alert Visualization Configuration";
private final String CONFIG_LABEL = "Current Config: ";
private static final String CONFIG_LABEL = "Current Config: ";
private Color omittedColor = null;
private static final RGB OMITTED_RGB = new RGB(255, 255, 100);
private Color includedColor = null;
private static final RGB INCLUDED_RGB = new RGB(175, 238, 238);
private Color notmonitorColor = null;
private static final RGB NOTMONITOR_RGB = new RGB(190, 190, 190);
private static final RGB RED_RGB = new RGB(155, 0, 0);
private Color redColor = null;
/**
* Dialog shell.
@ -220,9 +219,9 @@ public class AlertVisConfigDlg extends Dialog implements
/** Configuration list dialog */
private ConfigurationFileDlg configurationDialog;
private boolean fetchLog;
/**
* Label default configuration.
*/
@ -308,7 +307,7 @@ public class AlertVisConfigDlg extends Dialog implements
display = parent.getDisplay();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.MIN | SWT.RESIZE
| SWT.MAX);
shell.setText(TITLE);
shell.setText("Alert Visualization Configuration");
// Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(2, false);
@ -333,6 +332,10 @@ public class AlertVisConfigDlg extends Dialog implements
controlFont.dispose();
ConfigurationManager.getInstance().removeListener(
AlertVisConfigDlg.this);
omittedColor.dispose();
includedColor.dispose();
notmonitorColor.dispose();
redColor.dispose();
}
});
shell.pack();
@ -345,6 +348,14 @@ public class AlertVisConfigDlg extends Dialog implements
* Initialize the data.
*/
private void initalizeData() {
// Colors
omittedColor = new Color(shell.getDisplay(), new RGB(255, 255, 100));
includedColor = new Color(shell.getDisplay(), new RGB(175, 238, 238));
notmonitorColor = new Color(shell.getDisplay(), new RGB(190, 190, 190));
redColor = new Color(shell.getDisplay(), new RGB(155, 0, 0));
// Fonts
controlFont = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL);
labelFont = new Font(shell.getDisplay(), "Monospace", 14, SWT.NORMAL);
@ -379,7 +390,8 @@ public class AlertVisConfigDlg extends Dialog implements
getLayoutToolTipText());
mttLayout = new MonitorToolTip(layoutGroup, true);
layoutControls = new LayoutControlsComp(layoutGroup, configData, this, this);
layoutControls = new LayoutControlsComp(layoutGroup, configData, this,
this);
}
/**
@ -397,12 +409,6 @@ public class AlertVisConfigDlg extends Dialog implements
mttCommonSetting = new MonitorToolTip(commonSettingsGroup, true);
// commonSettingsGroup.addMouseTrackListener(new MouseTrackAdapter() {
// public void mouseHover(MouseEvent e) {
// mttCommonSetting.open();
// }
// });
createCommonSettingsControls(commonSettingsGroup);
}
@ -428,8 +434,8 @@ public class AlertVisConfigDlg extends Dialog implements
showPriorityChk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -438,9 +444,9 @@ public class AlertVisConfigDlg extends Dialog implements
showSourceKeyChk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -449,9 +455,9 @@ public class AlertVisConfigDlg extends Dialog implements
showCategoryChk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -469,9 +475,9 @@ public class AlertVisConfigDlg extends Dialog implements
expandPopupChk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -492,9 +498,9 @@ public class AlertVisConfigDlg extends Dialog implements
msgLengthSpnr.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -515,9 +521,9 @@ public class AlertVisConfigDlg extends Dialog implements
blinkDurSpnr.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -538,9 +544,8 @@ public class AlertVisConfigDlg extends Dialog implements
audioDurSpnr.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setNewConfig();
saveNeeded(true);
setNewConfig();
saveNeeded(true);
}
});
@ -583,17 +588,17 @@ public class AlertVisConfigDlg extends Dialog implements
Label label = new Label(comp, SWT.LEFT);
label.setLayoutData(gd);
label.setText("Regular");
label.setBackground(new Color(display, NOTMONITOR_RGB));
label.setBackground(notmonitorColor);
label = new Label(comp, SWT.LEFT);
label.setLayoutData(gd);
label.setText("Monitor");
label.setBackground(new Color(display, INCLUDED_RGB));
label.setBackground(includedColor);
label = new Label(comp, SWT.LEFT);
label.setLayoutData(gd);
label.setText("Omitted Monitor");
label.setBackground(new Color(display, OMITTED_RGB));
label.setBackground(omittedColor);
}
/**
@ -613,12 +618,6 @@ public class AlertVisConfigDlg extends Dialog implements
mttSource = new MonitorToolTip(sourcesLbl, true);
// sourcesLbl.addMouseTrackListener(new MouseTrackAdapter() {
// public void mouseHover(MouseEvent e) {
// mttSource.open();
// }
// });
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 125;
gd.heightHint = 225;
@ -634,7 +633,7 @@ public class AlertVisConfigDlg extends Dialog implements
sourcesList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handleSourceSelection();
handleSourceSelection();
}
});
@ -680,7 +679,7 @@ public class AlertVisConfigDlg extends Dialog implements
@Override
public void widgetSelected(SelectionEvent ev) {
try {
save();
save();
} catch (Exception e) {
Container
.logInternal(
@ -737,7 +736,7 @@ public class AlertVisConfigDlg extends Dialog implements
setSourceColor(s, item);
sourcesList.update();
setNewConfig();
} catch (Exception e) {
Container
.logInternal(
@ -791,14 +790,14 @@ public class AlertVisConfigDlg extends Dialog implements
.getMonitorMetadata();
if (mm.getOmit()) {
// lighter yellow
item.setBackground(new Color(display, OMITTED_RGB));
item.setBackground(omittedColor);
} else {
// lighter blue
item.setBackground(new Color(display, INCLUDED_RGB));
item.setBackground(includedColor);
}
} else {
// gray
item.setBackground(new Color(display, NOTMONITOR_RGB));
item.setBackground(notmonitorColor);
}
}
@ -874,7 +873,7 @@ public class AlertVisConfigDlg extends Dialog implements
textLbl.setLayoutData(gd);
for (int i = 0; i < 6; i++) {
priorityControls.get(i).createTextCheckbox();
priorityControls.get(i).createTextCheckbox();
}
addSeparator(prioritiesComp);
@ -888,8 +887,8 @@ public class AlertVisConfigDlg extends Dialog implements
blinkLbl.setLayoutData(gd);
for (int i = 0; i < 6; i++) {
priorityControls.get(i).createBlinkCheckbox();
priorityControls.get(i).createBlinkCheckbox();
}
addSeparator(prioritiesComp);
@ -1036,8 +1035,8 @@ public class AlertVisConfigDlg extends Dialog implements
closeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
close();
close();
}
});
@ -1065,7 +1064,7 @@ public class AlertVisConfigDlg extends Dialog implements
saveLbl = new Label(buttonComp, SWT.BOLD);
gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.widthHint = 10;
saveLbl.setForeground(new Color(display, RED_RGB));
saveLbl.setForeground(redColor);
saveLbl.setText("");
saveLbl.setLayoutData(gd);
@ -1259,7 +1258,7 @@ public class AlertVisConfigDlg extends Dialog implements
uci = selectedSource.getConfigurationItem();
for (Priority pri : Priority.values()) {
amd = uci.lookup(pri);
amd = uci.lookup(pri);
priorityControls.get(pri.ordinal()).setAlertMetadata(amd);
}
}
@ -1276,7 +1275,7 @@ public class AlertVisConfigDlg extends Dialog implements
} else {
selectedItem = sourcesList.getItem(index);
}
sourcesList.removeAll();
java.util.List<String> keys = new ArrayList<String>(sourceMap.keySet());
Collections.sort(keys);
@ -1289,7 +1288,7 @@ public class AlertVisConfigDlg extends Dialog implements
}
if (selectedItem != null) {
sourcesList.select(index);
sourcesList.select(index);
} else {
sourcesList.select(0);
}
@ -1339,10 +1338,12 @@ public class AlertVisConfigDlg extends Dialog implements
*
*/
public void setNewConfig() {
updateGlobalConfiguration();
ConfigurationManager.getInstance().setNewConfiguration(configContext, configData);
updateGlobalConfiguration();
ConfigurationManager.getInstance().setNewConfiguration(configContext,
configData);
}
/**
* Get the source key associated with the selected source in the source list
* control.
@ -1447,9 +1448,9 @@ public class AlertVisConfigDlg extends Dialog implements
@Override
public void configurationChanged() {
configData = ConfigurationManager.getInstance()
.getCurrentConfiguration();
configContext = ConfigurationManager.getInstance().getCurrentContext();
configData = ConfigurationManager.getInstance()
.getCurrentConfiguration();
configContext = ConfigurationManager.getInstance().getCurrentContext();
sourceMap = configData.getSources();
layoutControls.reloadConfig(configData);
@ -1460,7 +1461,6 @@ public class AlertVisConfigDlg extends Dialog implements
populateSourceList();
populatePriorityControls();
shell.setText(TITLE);
defaultConLbl.setText(CONFIG_LABEL + configContext);
save.setEnabled(!this.configContext.isBaseOrConfiguredLevel());
saveNeeded(false);