}
}
if (chatHistory == null) {
if (styledTextHistory == null) {
FormText text = tk.createFormText(historyForm.getBody(), true);
if (isMe(jid)) {
text.setColor("jidcolor", text.getDisplay().getSystemColor(
SWT.COLOR_RED));
} else {
text.setColor("jidcolor", text.getDisplay().getSystemColor(
SWT.COLOR_BLUE));
}
if (emoticons != null)
for (IconDef def : emoticons.getIcons()) {
for (String iconstr : def.text) {
if (msg.contains(iconstr)) {
msg = msg.replace(iconstr, "<img href=\""
+ def.image + "\" />");
text.setImage(def.image, def.getImage());
}
}
}
StringBuffer fullText = new StringBuffer("<form><p>");
fullText.append("<b>").append(
historyDateFormat.format(date == null ? new Date() : date))
.append("</b> ");
fullText.append("<span color=\"jidcolor\">");
if (prefix == null)
fullText.append(" <").append(jiddisplay).append("> ");
else
fullText.append(prefix).append(jiddisplay);
fullText.append("</span> ");
fullText.append(msg);
fullText.append("</p></form>");
System.out.println("Text: " + fullText.toString());
text.setText(fullText.toString(), true, false);
text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
historyForm.reflow(true);
historyForm.setOrigin(0, text.getLocation().y);
} else {
if(styledTextHistory.getText().length() > 0) {
styledTextHistory.append("\n");
}
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();