View | Details | Raw Unified | Return to bug 197329 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java (-53 / +22 lines)
Lines 150-155 Link Here
150
	private IChatRoomViewCloseListener rootCloseListener = null;
150
	private IChatRoomViewCloseListener rootCloseListener = null;
151
151
152
	private IChatRoomMessageSender rootMessageSender = null;
152
	private IChatRoomMessageSender rootMessageSender = null;
153
	
154
	/**
155
	 * UI independent renderer, that is aware of displaying any special fragments
156
	 * of message, like formatting, graphical attachments, emotional content, etc.
157
	 */
158
	private IMessageRenderer messageRenderer = null;
153
159
154
	private Color otherColor = null;
160
	private Color otherColor = null;
155
161
Lines 1373-1433 Link Here
1373
		
1379
		
1374
		boolean scrollToBottom = shouldScrollToEnd(st);
1380
		boolean scrollToBottom = shouldScrollToEnd(st);
1375
		
1381
		
1376
		int startRange = st.getText().length();
1382
		String output = messageRenderer.render(text, localUserName);
1377
		StringBuffer sb = new StringBuffer();
1383
		StyleRange[] ranges = messageRenderer.getStyleRanges();
1378
		// check to see if the message has the user's name contained within
1384
		
1379
		boolean nickContained = text.getText().indexOf(localUserName) != -1;
1385
		if (output == null) {
1380
		if (text.getOriginator() != null) {
1386
			return;
1381
			// check to make sure that the person referring to the user's name
1382
			// is not the user himself, no highlighting is required in this case
1383
			// as the user is already aware that his name is being referenced
1384
			nickContained = !text.getOriginator().getName().equals(
1385
					localUserName)
1386
					&& nickContained;
1387
			sb.append(NLS.bind(Messages.ChatRoomManagerView_MESSAGE_DATE,
1388
					getCurrentDate(DEFAULT_TIME_FORMAT)));
1389
			StyleRange dateStyle = new StyleRange();
1390
			dateStyle.start = startRange;
1391
			dateStyle.length = sb.length();
1392
			dateStyle.foreground = dateColor;
1393
			dateStyle.fontStyle = SWT.NORMAL;
1394
			st.append(sb.toString());
1395
			st.setStyleRange(dateStyle);
1396
			sb = new StringBuffer();
1397
			sb.append(text.getOriginator().getName()).append(": "); //$NON-NLS-1$
1398
			StyleRange sr = new StyleRange();
1399
			sr.start = startRange + dateStyle.length;
1400
			sr.length = sb.length();
1401
			sr.fontStyle = SWT.BOLD;
1402
			// check to see which color should be used
1403
			sr.foreground = nickContained ? highlightColor : otherColor;
1404
			st.append(sb.toString());
1405
			st.setStyleRange(sr);
1406
		}
1407
		int beforeMessageIndex = st.getText().length();
1408
		st.append(text.getText());
1409
		if (text.getOriginator() == null) {
1410
			StyleRange sr = new StyleRange();
1411
			sr.start = beforeMessageIndex;
1412
			sr.length = text.getText().length();
1413
			sr.foreground = systemColor;
1414
			sr.fontStyle = SWT.BOLD;
1415
			st.setStyleRange(sr);
1416
		} else if (nickContained) {
1417
			// highlight the message itself as necessary
1418
			StyleRange sr = new StyleRange();
1419
			sr.start = beforeMessageIndex;
1420
			sr.length = text.getText().length();
1421
			sr.foreground = highlightColor;
1422
			st.setStyleRange(sr);
1423
		}
1387
		}
1424
		if (!text.isNoCRLF()) {
1388
		
1425
			st.append("\n"); //$NON-NLS-1$
1389
		st.append(output);
1390
		if (ranges != null) {
1391
			// TODO: recalc StyleRanges start offsets to start begin with appended output 
1392
			st.setStyleRanges(ranges);
1426
		}
1393
		}
1427
		String t = st.getText();
1394
		
1428
		if (t == null)
1395
		if (scrollToBottom) st.setSelection(output.length());
1429
			return;
1430
		if (scrollToBottom) st.setSelection(t.length());
1431
		// Bold title if view is not visible.
1396
		// Bold title if view is not visible.
1432
		IWorkbenchSiteProgressService pservice = (IWorkbenchSiteProgressService) this
1397
		IWorkbenchSiteProgressService pservice = (IWorkbenchSiteProgressService) this
1433
				.getSite().getAdapter(IWorkbenchSiteProgressService.class);
1398
				.getSite().getAdapter(IWorkbenchSiteProgressService.class);
Lines 1566-1569 Link Here
1566
				.parseInt(vals[2]));
1531
				.parseInt(vals[2]));
1567
		return color;
1532
		return color;
1568
	}
1533
	}
1534
1535
	public void setMessageRenderer(IMessageRenderer defaultMessageRenderer) {
1536
		this.messageRenderer = defaultMessageRenderer;
1537
	}
1569
}
1538
}
(-)src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java (+5 lines)
Lines 106-111 Link Here
106
		chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID),
106
		chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID),
107
				ChatRoomManagerView.getHostnameFromID(targetID),
107
				ChatRoomManagerView.getHostnameFromID(targetID),
108
				managerChatRoom, this, createChatRoomViewCloseListener());
108
				managerChatRoom, this, createChatRoomViewCloseListener());
109
		chatroomview.setMessageRenderer(getDefaultMessageRenderer());
109
		// Add listener for container, so that if the container is spontaneously
110
		// Add listener for container, so that if the container is spontaneously
110
		// disconnected,
111
		// disconnected,
111
		// then we will be able to have the UI respond by making itself inactive
112
		// then we will be able to have the UI respond by making itself inactive
Lines 150-155 Link Here
150
		});
151
		});
151
	}
152
	}
152
153
154
	protected IMessageRenderer getDefaultMessageRenderer() {
155
		return new GenericMessageRenderer();
156
	}
157
153
	protected String getPasswordForChatRoomConnect(IChatRoomInfo info) {
158
	protected String getPasswordForChatRoomConnect(IChatRoomInfo info) {
154
		return null;
159
		return null;
155
	}
160
	}
(-)src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java (+27 lines)
Added Link Here
1
package org.eclipse.ecf.presence.ui.chatroom;
2
3
import org.eclipse.ecf.internal.presence.ui.ChatLine;
4
import org.eclipse.swt.custom.StyleRange;
5
6
/**
7
 * Renders chat line, by arranging text content to be finally printed to 
8
 * Chat room output together with it's formatting.
9
 *
10
 */
11
public interface IMessageRenderer {
12
13
	/**
14
	 * Returns text content to be finally printed to chat room output.
15
	 * @param chatLine chat line to be processed
16
	 * @param String local user name
17
	 * @return text to be printed to output, nothing will be printed if null
18
	 */
19
	String render(ChatLine chatLine, String localUser);
20
	
21
	/**
22
	 * Returns formatting to be applied to rendered final output, returned by {@link #render(ChatLine, boolean)}.
23
	 * @return formatting to be applied to output, or null if no formatting
24
	 */
25
	StyleRange[] getStyleRanges();
26
	
27
}
(-)src/org/eclipse/ecf/presence/ui/chatroom/GenericMessageRenderer.java (+18 lines)
Added Link Here
1
package org.eclipse.ecf.presence.ui.chatroom;
2
3
import org.eclipse.ecf.internal.presence.ui.ChatLine;
4
import org.eclipse.swt.custom.StyleRange;
5
6
public class GenericMessageRenderer implements IMessageRenderer {
7
8
	public StyleRange[] getStyleRanges() {
9
		// TODO Auto-generated method stub
10
		return null;
11
	}
12
13
	public String render(ChatLine chatLine, String localUser) {
14
		// TODO Auto-generated method stub
15
		return null;
16
	}
17
18
}
(-)src/org/eclipse/ecf/internal/irc/ui/IRCUI.java (-1 / +5 lines)
Lines 21-26 Link Here
21
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
21
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
22
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
22
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
23
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI;
23
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI;
24
import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.osgi.util.NLS;
26
27
Lines 120-124 Link Here
120
		return inputLine;
121
		return inputLine;
121
122
122
	}
123
	}
123
124
	
125
	protected IMessageRenderer getDefaultMessageRenderer() {
126
		return new IRCMessageRenderer();
127
	}
124
}
128
}
(-)src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java (+19 lines)
Added Link Here
1
package org.eclipse.ecf.internal.irc.ui;
2
3
import org.eclipse.ecf.internal.presence.ui.ChatLine;
4
import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer;
5
import org.eclipse.swt.custom.StyleRange;
6
7
public class IRCMessageRenderer implements IMessageRenderer {
8
9
	public StyleRange[] getStyleRanges() {
10
		// TODO Auto-generated method stub
11
		return null;
12
	}
13
14
	public String render(ChatLine chatLine, String localUser) {
15
		// TODO Auto-generated method stub
16
		return null;
17
	}
18
19
}

Return to bug 197329