### Eclipse Workspace Patch 1.0 #P org.eclipse.ecf.presence.ui Index: src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ecf/plugins/org.eclipse.ecf.presence.ui/src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java,v retrieving revision 1.16 diff -u -r1.16 ChatRoomManagerView.java --- src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java 26 Jul 2007 18:40:14 -0000 1.16 +++ src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java 26 Jul 2007 18:53:13 -0000 @@ -150,6 +150,12 @@ private IChatRoomViewCloseListener rootCloseListener = null; private IChatRoomMessageSender rootMessageSender = null; + + /** + * UI independent renderer, that is aware of displaying any special fragments + * of message, like formatting, graphical attachments, emotional content, etc. + */ + private IMessageRenderer messageRenderer = null; private Color otherColor = null; @@ -1373,61 +1379,20 @@ boolean scrollToBottom = shouldScrollToEnd(st); - int startRange = st.getText().length(); - StringBuffer sb = new StringBuffer(); - // check to see if the message has the user's name contained within - boolean nickContained = text.getText().indexOf(localUserName) != -1; - if (text.getOriginator() != null) { - // check to make sure that the person referring to the user's name - // is not the user himself, no highlighting is required in this case - // as the user is already aware that his name is being referenced - nickContained = !text.getOriginator().getName().equals( - localUserName) - && nickContained; - sb.append(NLS.bind(Messages.ChatRoomManagerView_MESSAGE_DATE, - getCurrentDate(DEFAULT_TIME_FORMAT))); - StyleRange dateStyle = new StyleRange(); - dateStyle.start = startRange; - dateStyle.length = sb.length(); - dateStyle.foreground = dateColor; - dateStyle.fontStyle = SWT.NORMAL; - st.append(sb.toString()); - st.setStyleRange(dateStyle); - sb = new StringBuffer(); - sb.append(text.getOriginator().getName()).append(": "); //$NON-NLS-1$ - StyleRange sr = new StyleRange(); - sr.start = startRange + dateStyle.length; - sr.length = sb.length(); - sr.fontStyle = SWT.BOLD; - // check to see which color should be used - sr.foreground = nickContained ? highlightColor : otherColor; - st.append(sb.toString()); - st.setStyleRange(sr); - } - int beforeMessageIndex = st.getText().length(); - st.append(text.getText()); - if (text.getOriginator() == null) { - StyleRange sr = new StyleRange(); - sr.start = beforeMessageIndex; - sr.length = text.getText().length(); - sr.foreground = systemColor; - sr.fontStyle = SWT.BOLD; - st.setStyleRange(sr); - } else if (nickContained) { - // highlight the message itself as necessary - StyleRange sr = new StyleRange(); - sr.start = beforeMessageIndex; - sr.length = text.getText().length(); - sr.foreground = highlightColor; - st.setStyleRange(sr); + String output = messageRenderer.render(text, localUserName); + StyleRange[] ranges = messageRenderer.getStyleRanges(); + + if (output == null) { + return; } - if (!text.isNoCRLF()) { - st.append("\n"); //$NON-NLS-1$ + + st.append(output); + if (ranges != null) { + // TODO: recalc StyleRanges start offsets to start begin with appended output + st.setStyleRanges(ranges); } - String t = st.getText(); - if (t == null) - return; - if (scrollToBottom) st.setSelection(t.length()); + + if (scrollToBottom) st.setSelection(output.length()); // Bold title if view is not visible. IWorkbenchSiteProgressService pservice = (IWorkbenchSiteProgressService) this .getSite().getAdapter(IWorkbenchSiteProgressService.class); @@ -1566,4 +1531,8 @@ .parseInt(vals[2])); return color; } + + public void setMessageRenderer(IMessageRenderer defaultMessageRenderer) { + this.messageRenderer = defaultMessageRenderer; + } } \ No newline at end of file Index: src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ecf/plugins/org.eclipse.ecf.presence.ui/src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java,v retrieving revision 1.9 diff -u -r1.9 ChatRoomManagerUI.java --- src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java 2 May 2007 04:58:38 -0000 1.9 +++ src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java 26 Jul 2007 18:53:10 -0000 @@ -106,6 +106,7 @@ chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID), ChatRoomManagerView.getHostnameFromID(targetID), managerChatRoom, this, createChatRoomViewCloseListener()); + chatroomview.setMessageRenderer(getDefaultMessageRenderer()); // Add listener for container, so that if the container is spontaneously // disconnected, // then we will be able to have the UI respond by making itself inactive @@ -150,6 +151,10 @@ }); } + protected IMessageRenderer getDefaultMessageRenderer() { + return new GenericMessageRenderer(); + } + protected String getPasswordForChatRoomConnect(IChatRoomInfo info) { return null; } Index: src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java =================================================================== RCS file: src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java diff -N src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +package org.eclipse.ecf.presence.ui.chatroom; + +import org.eclipse.ecf.internal.presence.ui.ChatLine; +import org.eclipse.swt.custom.StyleRange; + +/** + * Renders chat line, by arranging text content to be finally printed to + * Chat room output together with it's formatting. + * + */ +public interface IMessageRenderer { + + /** + * Returns text content to be finally printed to chat room output. + * @param chatLine chat line to be processed + * @param String local user name + * @return text to be printed to output, nothing will be printed if null + */ + String render(ChatLine chatLine, String localUser); + + /** + * Returns formatting to be applied to rendered final output, returned by {@link #render(ChatLine, boolean)}. + * @return formatting to be applied to output, or null if no formatting + */ + StyleRange[] getStyleRanges(); + +} Index: src/org/eclipse/ecf/presence/ui/chatroom/GenericMessageRenderer.java =================================================================== RCS file: src/org/eclipse/ecf/presence/ui/chatroom/GenericMessageRenderer.java diff -N src/org/eclipse/ecf/presence/ui/chatroom/GenericMessageRenderer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ecf/presence/ui/chatroom/GenericMessageRenderer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +package org.eclipse.ecf.presence.ui.chatroom; + +import org.eclipse.ecf.internal.presence.ui.ChatLine; +import org.eclipse.swt.custom.StyleRange; + +public class GenericMessageRenderer implements IMessageRenderer { + + public StyleRange[] getStyleRanges() { + // TODO Auto-generated method stub + return null; + } + + public String render(ChatLine chatLine, String localUser) { + // TODO Auto-generated method stub + return null; + } + +} #P org.eclipse.ecf.provider.irc.ui Index: src/org/eclipse/ecf/internal/irc/ui/IRCUI.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.ecf/plugins/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/IRCUI.java,v retrieving revision 1.4 diff -u -r1.4 IRCUI.java --- src/org/eclipse/ecf/internal/irc/ui/IRCUI.java 2 May 2007 04:58:23 -0000 1.4 +++ src/org/eclipse/ecf/internal/irc/ui/IRCUI.java 26 Jul 2007 18:53:14 -0000 @@ -21,6 +21,7 @@ import org.eclipse.ecf.presence.chatroom.IChatRoomContainer; import org.eclipse.ecf.presence.chatroom.IChatRoomManager; import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI; +import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; @@ -120,5 +121,8 @@ return inputLine; } - + + protected IMessageRenderer getDefaultMessageRenderer() { + return new IRCMessageRenderer(); + } } Index: src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java =================================================================== RCS file: src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java diff -N src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,19 @@ +package org.eclipse.ecf.internal.irc.ui; + +import org.eclipse.ecf.internal.presence.ui.ChatLine; +import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer; +import org.eclipse.swt.custom.StyleRange; + +public class IRCMessageRenderer implements IMessageRenderer { + + public StyleRange[] getStyleRanges() { + // TODO Auto-generated method stub + return null; + } + + public String render(ChatLine chatLine, String localUser) { + // TODO Auto-generated method stub + return null; + } + +}