Issue #2865 - fixed font memory leak

Change-Id: I0cfbd494924aadcb134c60313836cb9ab815253d

Former-commit-id: 2555d382f26278c5f972c17da778338142cdaaec
This commit is contained in:
Lee Venable 2014-03-11 08:54:07 -05:00
parent f3a6acaf48
commit 58d7f759b2

View file

@ -88,6 +88,8 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
* Feb 13, 2014 2751 bclement made generic
* Feb 18, 2014 2631 mpduff Add ability to play sounds on join actions
* Feb 24, 2014 2632 mpduff Moved sound generation code to CollaborationUtils
* Mar 06, 2014 #2865 lvenable Fixed font memory leaks added SWT dispose checks when
* running in an asynchronous thread.
*
* </pre>
*
@ -115,6 +117,9 @@ public abstract class AbstractSessionView<T extends IUser> extends
protected StyledText messagesText;
/** Font used with the messagesText control. */
private Font messagesTextFont;
private StyledText composeText;
protected SessionMsgArchive msgArchive;
@ -205,9 +210,10 @@ public abstract class AbstractSessionView<T extends IUser> extends
}
});
// here need to grab the font from preferences and use that font
messagesText.setFont(new Font(Display.getCurrent(), PreferenceConverter
.getFontData(Activator.getDefault().getPreferenceStore(),
"font")));
messagesTextFont = new Font(Display.getCurrent(),
PreferenceConverter.getFontData(Activator.getDefault()
.getPreferenceStore(), "font"));
messagesText.setFont(messagesTextFont);
searchComp.setSearchText(messagesText);
@ -341,18 +347,23 @@ public abstract class AbstractSessionView<T extends IUser> extends
}
StringBuilder sb = new StringBuilder();
if (messagesText.getCharCount() != 0) {
if (messagesText.isDisposed() == false
&& messagesText.getCharCount() != 0) {
sb.append("\n");
}
sb.append("(").append(time).append(") ");
int offset = sb.length();
sb.append(name).append(": ").append(body);
// here is the place to put the font and color changes for
// keywords
// read in localization file once and then don't read in again,
// per
// chat room?
if (messagesText.isDisposed() == false) {
List<AlertWord> alertWords = retrieveAlertWords();
List<StyleRange> ranges = new ArrayList<StyleRange>();
if (alertWords != null) {
@ -371,7 +382,8 @@ public abstract class AbstractSessionView<T extends IUser> extends
} else {
FontData fd = StringConverter
.asFontData(keyword.getFont());
font = new Font(Display.getCurrent(), fd);
font = new Font(Display.getCurrent(),
fd);
fonts.put(keyword.getFont(), font);
}
@ -382,18 +394,21 @@ public abstract class AbstractSessionView<T extends IUser> extends
if (colors.containsKey(rgb)) {
color = colors.get(rgb);
} else {
color = new Color(Display.getCurrent(), rgb);
color = new Color(Display.getCurrent(),
rgb);
colors.put(rgb, color);
}
TextStyle style = new TextStyle(font, color,
null);
StyleRange keywordRange = new StyleRange(style);
TextStyle style = new TextStyle(font,
color, null);
StyleRange keywordRange = new StyleRange(
style);
keywordRange.start = currentLength + index;
keywordRange.length = keyword.getText()
.length();
ranges.add(keywordRange);
// compare to see if this position is already
// compare to see if this position is
// already
// styled
List<StyleRange> rnges = new ArrayList<StyleRange>();
rnges.addAll(ranges);
@ -410,24 +425,34 @@ public abstract class AbstractSessionView<T extends IUser> extends
}
}
// only execute things if the same user didn't
// only execute things if the same user
// didn't
// type it
if (!myUser.equals(userId)) {
executeSightsSounds(keyword);
}
// need to handle all instances of the keyword
// need to handle all instances of the
// keyword
// within the chat
index = lowerCase.indexOf(text, text.length()
+ index);
index = lowerCase.indexOf(text,
text.length() + index);
}
}
}
}
styleAndAppendText(sb, offset, name, userId, subject, ranges);
styleAndAppendText(sb, offset, name, userId, subject,
ranges);
}
// Archive the message
msgArchive.archive(sb.toString());
// Append the text to the search control.
if (searchComp.isDisposed() == false) {
searchComp.appendText(sb.toString());
}
}
});
}
@ -500,6 +525,10 @@ public abstract class AbstractSessionView<T extends IUser> extends
@Override
public void dispose() {
if (messagesTextFont != null) {
messagesTextFont.dispose();
}
for (Image im : imageMap.values()) {
im.dispose();
}
@ -540,7 +569,11 @@ public abstract class AbstractSessionView<T extends IUser> extends
@Subscribe
public void changeFont(FontData data) {
messagesText.setFont(new Font(Display.getCurrent(), data));
if (messagesTextFont != null) {
messagesTextFont.dispose();
}
messagesTextFont = new Font(Display.getCurrent(), data);
messagesText.setFont(messagesTextFont);
}
public void setAlertWords(List<AlertWord> words) {
@ -582,22 +615,34 @@ public abstract class AbstractSessionView<T extends IUser> extends
VizApp.runAsync(new Runnable() {
@Override
public void run() {
Color color = Display.getCurrent().getSystemColor(swtColor);
Date date = new Date();
String time = dateFormatter.get().format(date);
builder.insert(0, "(" + time + ") : ");
// Update the messagesText with the StyleRange highlights
if (messagesText.isDisposed() == false) {
if (messagesText.getCharCount() != 0) {
builder.insert(0, "\n");
}
StyleRange range = new StyleRange(messagesText.getCharCount(),
builder.length(), color, null, SWT.BOLD);
Color color = Display.getCurrent().getSystemColor(swtColor);
StyleRange range = new StyleRange(messagesText
.getCharCount(), builder.length(), color, null,
SWT.BOLD);
List<StyleRange> ranges = new ArrayList<StyleRange>();
ranges.add(range);
styleAndAppendText(builder, 0, builder.toString(), null,
ranges, color);
}
// Archive the message
msgArchive.archiveLine(builder.toString());
// Append the text to the search control.
if (searchComp.isDisposed() == false) {
searchComp.appendText(builder.toString());
}
}
});
}