}
String historydate = historyDateFormat.format(date == null ? new Date() : date) + " ";
String prefixtext = (prefix == null ? "<" + jiddisplay + "> " : prefix + jiddisplay + " ");
StyleRange dateRange = new StyleRange();
dateRange.start = styledTextHistory.getText().length();
dateRange.length = historydate.length();
dateRange.fontStyle = SWT.BOLD;
int msgStart = styledTextHistory.getText().length() + historydate.length();
StyleRange range = new StyleRange();
range.start = dateRange.start + dateRange.length;
range.length = prefixtext.length();
if(isMe(jid)) {
range.foreground = styledTextHistory.getDisplay().getSystemColor(SWT.COLOR_RED);
} else {
range.foreground = styledTextHistory.getDisplay().getSystemColor(SWT.COLOR_BLUE);
}
range.fontStyle = SWT.BOLD;
styledTextHistory.append(historydate + prefixtext);
styledTextHistory.setStyleRange(dateRange);
styledTextHistory.setStyleRange(range);
if(usesXHTML) {
SAXParserFactory fac = SAXParserFactory.newInstance();
try {
SAXParser parser = fac.newSAXParser();
parser.parse(new InputSource(new StringReader("<body>"+msg+"</body>")),new ParseXHTMLForStyledText(styledTextHistory));
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
styledTextHistory.append(msg);
}
String text = styledTextHistory.getText();
text = text.substring(msgStart,text.length());
if (emoticons != null) {
for (IconDef def : emoticons.getIcons()) {
for (String iconstr : def.text) {
int index = text.indexOf(iconstr);
if (index >= 0) {
StyleRange iconRange = new StyleRange();
iconRange.start = msgStart + index;
iconRange.length = iconstr.length();
Image image = def.getImage();
Rectangle rect = image.getBounds();
iconRange.metrics = new GlyphMetrics(rect.height,0,rect.width / iconstr.length());