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

Collapse All | Expand All

(-)src/org/eclipse/ecf/internal/presence/ui/Messages.java (-6 / +5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Composent, Inc. - initial API and implementation
9
 *    Composent, Inc. - initial API and implementation
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
 *****************************************************************************/
11
12
12
package org.eclipse.ecf.internal.presence.ui;
13
package org.eclipse.ecf.internal.presence.ui;
Lines 60-67 Link Here
60
61
61
	public static String ChatRoomManagerView_COPY_TOOLTIP;
62
	public static String ChatRoomManagerView_COPY_TOOLTIP;
62
63
63
	public static String ChatRoomManagerView_DATE_FORMAT;
64
65
	public static String ChatRoomManagerView_DEFAULT_HOST;
64
	public static String ChatRoomManagerView_DEFAULT_HOST;
66
65
67
	public static String ChatRoomManagerView_DEFAULT_USER;
66
	public static String ChatRoomManagerView_DEFAULT_USER;
Lines 73-80 Link Here
73
	public static String ChatRoomManagerView_JOIN_COMMAND;
72
	public static String ChatRoomManagerView_JOIN_COMMAND;
74
	
73
	
75
	public static String ChatRoomManagerView_MESSAGE;
74
	public static String ChatRoomManagerView_MESSAGE;
76
	
77
	public static String ChatRoomManagerView_MESSAGE_DATE;
78
75
79
	public static String ChatRoomManagerView_NOT_CONNECTED_MESSAGE;
76
	public static String ChatRoomManagerView_NOT_CONNECTED_MESSAGE;
80
77
Lines 88-95 Link Here
88
85
89
	public static String ChatRoomManagerView_SELECT_ALL_TOOLTIP;
86
	public static String ChatRoomManagerView_SELECT_ALL_TOOLTIP;
90
87
91
	public static String ChatRoomManagerView_TIME_FORMAT;
92
93
	public static String ChatRoomManagerView_VIEW_DISABLED_NAME;
88
	public static String ChatRoomManagerView_VIEW_DISABLED_NAME;
94
89
95
	public static String ChatRoomManagerView_VIEW_TITLE;
90
	public static String ChatRoomManagerView_VIEW_TITLE;
Lines 234-239 Link Here
234
	
229
	
235
	public static String ToggleOnlineOnlyAction_title;
230
	public static String ToggleOnlineOnlyAction_title;
236
231
232
	public static String MessageRenderer_DEFAULT_DATE_FORMAT;
233
	public static String MessageRenderer_DEFAULT_DATETIME_FORMAT;
234
	public static String MessageRenderer_DEFAULT_TIME_FORMAT;
235
	
237
	static {
236
	static {
238
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
237
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
239
	}
238
	}
(-)src/org/eclipse/ecf/internal/presence/ui/messages.properties (-7 / +9 lines)
Lines 7-12 Link Here
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#    Composent, Inc. - initial API and implementation
9
#    Composent, Inc. - initial API and implementation
10
#    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
################################################################################
11
################################################################################
11
12
12
##########################
13
##########################
Lines 84-91 Link Here
84
MultiRosterView_DISCONNECT_ACCOUNT_QUESTION_MESSAGE=Disconnect account {0}?
85
MultiRosterView_DISCONNECT_ACCOUNT_QUESTION_MESSAGE=Disconnect account {0}?
85
MultiRosterView_ROSTER_VIEW_EXT_POINT_ERROR_MESSAGE=Error in loading rosterViewerDropTargetExtension
86
MultiRosterView_ROSTER_VIEW_EXT_POINT_ERROR_MESSAGE=Error in loading rosterViewerDropTargetExtension
86
MultiRosterView_EXCEPTION_JOIN_ROOM_INVALID_ACCOUNT=Invalid account
87
MultiRosterView_EXCEPTION_JOIN_ROOM_INVALID_ACCOUNT=Invalid account
87
ChatRoomManagerView_TIME_FORMAT=HH:mm:ss
88
ChatRoomManagerView_DATE_FORMAT=yyyy-MM-dd
89
ChatRoomSelectionDialog_MESSAGE=Select a Chat Room to Enter
88
ChatRoomSelectionDialog_MESSAGE=Select a Chat Room to Enter
90
ChatRoomManagerView_DEFAULT_USER=<user>
89
ChatRoomManagerView_DEFAULT_USER=<user>
91
ChatRoomManagerView_DEFAULT_HOST=<host>
90
ChatRoomManagerView_DEFAULT_HOST=<host>
Lines 111-124 Link Here
111
ChatRoomManagerView_NOT_CONNECTED_TITLE=Not Connected
110
ChatRoomManagerView_NOT_CONNECTED_TITLE=Not Connected
112
ChatRoomManagerView_NOT_CONNECTED_MESSAGE=Not connected to chat room
111
ChatRoomManagerView_NOT_CONNECTED_MESSAGE=Not connected to chat room
113
ChatRoomManagerView_PART_COMMAND=PART
112
ChatRoomManagerView_PART_COMMAND=PART
114
ChatRoomManagerView_ENTERED_MESSAGE=({0}) {1} entered
113
ChatRoomManagerView_ENTERED_MESSAGE={0} entered
115
ChatRoomView_NOT_CONNECTED_MESSAGE=Not connected to chat room
114
ChatRoomView_NOT_CONNECTED_MESSAGE=Not connected to chat room
116
ChatRoomManagerView_LEFT_MESSAGE=({0}) {1} left
115
ChatRoomManagerView_LEFT_MESSAGE={0} left
117
ChangePasswordDialog_CHANGE_PASSWORD=Change Password
116
ChangePasswordDialog_CHANGE_PASSWORD=Change Password
118
ChatRoomManagerView_MESSAGE={0}: {1}\n
117
ChatRoomManagerView_MESSAGE={0}: {1}\n
119
ChatRoomView_TIME_FORMAT=HH:mm:ss
118
ChatRoomView_TIME_FORMAT=HH:mm:ss
120
ChatRoomView_DATE_FORMAT=yyyy-MM-dd
119
ChatRoomView_DATE_FORMAT=yyyy-MM-dd 
121
ChatRoomManagerView_MESSAGE_DATE=({0}) 
122
ChatRoomView_NOT_CONNECTED_TITLE=Not connect
120
ChatRoomView_NOT_CONNECTED_TITLE=Not connect
123
ChatRoomManagerView_CLEAR_CONFIRM_TITLE=Confirm Clear Output
121
ChatRoomManagerView_CLEAR_CONFIRM_TITLE=Confirm Clear Output
124
ChangePasswordDialog_NEW_PASSWORD_LABEL=New Password:
122
ChangePasswordDialog_NEW_PASSWORD_LABEL=New Password:
Lines 138-141 Link Here
138
BrowseDialog_title=Open Contact
136
BrowseDialog_title=Open Contact
139
BrowseDialog_message=Select a contact to message (*, ?, or camel case):
137
BrowseDialog_message=Select a contact to message (*, ?, or camel case):
140
BrowseDialog_scanning=Scanning contacts...
138
BrowseDialog_scanning=Scanning contacts...
141
ToggleOnlineOnlyAction_title=Show Online Only
139
ToggleOnlineOnlyAction_title=Show Online Only
140
141
MessageRenderer_DEFAULT_TIME_FORMAT=HH:mm:ss
142
MessageRenderer_DEFAULT_DATE_FORMAT=yyyy-MM-dd
143
MessageRenderer_DEFAULT_DATETIME_FORMAT=({0}) 
(-)src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java (-117 / +38 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Composent, Inc. - initial API and implementation
9
 *    Composent, Inc. - initial API and implementation
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 192762
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 192762, 197329
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.ecf.presence.ui.chatroom;
12
package org.eclipse.ecf.presence.ui.chatroom;
13
13
Lines 76-82 Link Here
76
import org.eclipse.swt.events.KeyListener;
76
import org.eclipse.swt.events.KeyListener;
77
import org.eclipse.swt.events.SelectionEvent;
77
import org.eclipse.swt.events.SelectionEvent;
78
import org.eclipse.swt.events.SelectionListener;
78
import org.eclipse.swt.events.SelectionListener;
79
import org.eclipse.swt.graphics.Color;
80
import org.eclipse.swt.graphics.Font;
79
import org.eclipse.swt.graphics.Font;
81
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.FontData;
82
import org.eclipse.swt.graphics.Point;
81
import org.eclipse.swt.graphics.Point;
Lines 120-144 Link Here
120
	private static final int RATIO_READ_WRITE_PANE = 85;
119
	private static final int RATIO_READ_WRITE_PANE = 85;
121
120
122
	private static final int RATIO_PRESENCE_PANE = 15;
121
	private static final int RATIO_PRESENCE_PANE = 15;
123
122
	
124
	protected static final String DEFAULT_ME_COLOR = "0,255,0"; //$NON-NLS-1$
125
126
	protected static final String DEFAULT_OTHER_COLOR = "0,0,0"; //$NON-NLS-1$
127
128
	protected static final String DEFAULT_SYSTEM_COLOR = "0,0,255"; //$NON-NLS-1$
129
130
	/**
131
	 * The default color used to highlight the string of text when the user's
132
	 * name is referred to in the chatroom. The default color is red.
133
	 */
134
	protected static final String DEFAULT_HIGHLIGHT_COLOR = "255,0,0"; //$NON-NLS-1$
135
136
	protected static final String DEFAULT_DATE_COLOR = "0,0,0"; //$NON-NLS-1$
137
138
	protected static final String DEFAULT_TIME_FORMAT = Messages.ChatRoomManagerView_TIME_FORMAT;
139
140
	protected static final String DEFAULT_DATE_FORMAT = Messages.ChatRoomManagerView_DATE_FORMAT;
141
142
	protected static final int DEFAULT_INPUT_HEIGHT = 25;
123
	protected static final int DEFAULT_INPUT_HEIGHT = 25;
143
124
144
	protected static final int DEFAULT_INPUT_SEPARATOR = 5;
125
	protected static final int DEFAULT_INPUT_SEPARATOR = 5;
Lines 150-163 Link Here
150
	private IChatRoomViewCloseListener rootCloseListener = null;
131
	private IChatRoomViewCloseListener rootCloseListener = null;
151
132
152
	private IChatRoomMessageSender rootMessageSender = null;
133
	private IChatRoomMessageSender rootMessageSender = null;
153
134
	
154
	private Color otherColor = null;
135
	/**
155
136
	 * UI independent renderer, that is aware of displaying any special fragments
156
	private Color systemColor = null;
137
	 * of message, like formatting, graphical attachments, emotional content, etc.
157
138
	 */
158
	private Color dateColor = null;
139
	private IMessageRenderer messageRenderer = null;
159
160
	private Color highlightColor = null;
161
140
162
	Action outputClear = null;
141
	Action outputClear = null;
163
142
Lines 467-476 Link Here
467
	}
446
	}
468
447
469
	public void createPartControl(Composite parent) {
448
	public void createPartControl(Composite parent) {
470
		otherColor = colorFromRGBString(DEFAULT_OTHER_COLOR);
471
		systemColor = colorFromRGBString(DEFAULT_SYSTEM_COLOR);
472
		highlightColor = colorFromRGBString(DEFAULT_HIGHLIGHT_COLOR);
473
		dateColor = colorFromRGBString(DEFAULT_DATE_COLOR);
474
		Composite rootComposite = new Composite(parent, SWT.NONE);
449
		Composite rootComposite = new Composite(parent, SWT.NONE);
475
		rootComposite.setLayout(new FillLayout());
450
		rootComposite.setLayout(new FillLayout());
476
		boolean useTraditionalTabFolder = PlatformUI
451
		boolean useTraditionalTabFolder = PlatformUI
Lines 1143-1149 Link Here
1143
				if (id != null) {
1118
				if (id != null) {
1144
					appendText(getOutputText(), new ChatLine(NLS.bind(
1119
					appendText(getOutputText(), new ChatLine(NLS.bind(
1145
							Messages.ChatRoomManagerView_ENTERED_MESSAGE,
1120
							Messages.ChatRoomManagerView_ENTERED_MESSAGE,
1146
							getDateTime(), getUsernameFromID(id)), null));
1121
							getUsernameFromID(id)), null));
1147
					chatRoomParticipantViewer.add(p);
1122
					chatRoomParticipantViewer.add(p);
1148
				}
1123
				}
1149
			}
1124
			}
Lines 1174-1180 Link Here
1174
				if (id != null) {
1149
				if (id != null) {
1175
					appendText(getOutputText(), new ChatLine(NLS.bind(
1150
					appendText(getOutputText(), new ChatLine(NLS.bind(
1176
							Messages.ChatRoomManagerView_LEFT_MESSAGE,
1151
							Messages.ChatRoomManagerView_LEFT_MESSAGE,
1177
							getDateTime(), getUsernameFromID(id)), null));
1152
							getUsernameFromID(id)), null));
1178
					chatRoomParticipantViewer.remove(p);
1153
					chatRoomParticipantViewer.remove(p);
1179
				}
1154
				}
1180
			}
1155
			}
Lines 1365-1383 Link Here
1365
		}
1340
		}
1366
	}
1341
	}
1367
1342
1368
	protected String getCurrentDate(String format) {
1369
		SimpleDateFormat sdf = new SimpleDateFormat(format);
1370
		String res = sdf.format(new Date());
1371
		return res;
1372
	}
1373
1374
	protected String getDateTime() {
1375
		StringBuffer buf = new StringBuffer();
1376
		buf.append(getCurrentDate(DEFAULT_DATE_FORMAT)).append(" ").append( //$NON-NLS-1$
1377
				getCurrentDate(DEFAULT_TIME_FORMAT));
1378
		return buf.toString();
1379
	}
1380
1381
	public void disconnect() {
1343
	public void disconnect() {
1382
		if (rootCloseListener != null) {
1344
		if (rootCloseListener != null) {
1383
			rootCloseListener.chatRoomViewClosing();
1345
			rootCloseListener.chatRoomViewClosing();
Lines 1411-1418 Link Here
1411
	private boolean shouldScrollToEnd(StyledText chatText) {
1373
	private boolean shouldScrollToEnd(StyledText chatText) {
1412
		Point locAtEnd = chatText.getLocationAtOffset(chatText.getText().length());
1374
		Point locAtEnd = chatText.getLocationAtOffset(chatText.getText().length());
1413
		Rectangle bounds = chatText.getBounds();
1375
		Rectangle bounds = chatText.getBounds();
1414
		if (locAtEnd.y > bounds.height + 5) return false;
1376
		return (locAtEnd.y > bounds.height + 5);
1415
		return true;
1416
	}
1377
	}
1417
1378
1418
	protected void appendText(StyledText st, ChatLine text) {
1379
	protected void appendText(StyledText st, ChatLine text) {
Lines 1420-1482 Link Here
1420
			return;
1381
			return;
1421
		}
1382
		}
1422
		
1383
		
1423
		boolean scrollToBottom = shouldScrollToEnd(st);
1384
		String originator = null;
1424
		
1425
		int startRange = st.getText().length();
1426
		StringBuffer sb = new StringBuffer();
1427
		// check to see if the message has the user's name contained within
1428
		boolean nickContained = text.getText().indexOf(localUserName) != -1;
1429
		if (text.getOriginator() != null) {
1385
		if (text.getOriginator() != null) {
1430
			// check to make sure that the person referring to the user's name
1386
			originator = text.getOriginator().getNickname(); 
1431
			// is not the user himself, no highlighting is required in this case
1387
		}
1432
			// as the user is already aware that his name is being referenced
1388
		
1433
			nickContained = !text.getOriginator().getName().equals(
1389
		String output = messageRenderer.render(text.getText(), originator, localUserName);
1434
					localUserName)
1390
		StyleRange[] ranges = messageRenderer.getStyleRanges();
1435
					&& nickContained;
1391
		
1436
			sb.append(NLS.bind(Messages.ChatRoomManagerView_MESSAGE_DATE,
1392
		if (output == null) {
1437
					getCurrentDate(DEFAULT_TIME_FORMAT)));
1393
			return;
1438
			StyleRange dateStyle = new StyleRange();
1439
			dateStyle.start = startRange;
1440
			dateStyle.length = sb.length();
1441
			dateStyle.foreground = dateColor;
1442
			dateStyle.fontStyle = SWT.NORMAL;
1443
			st.append(sb.toString());
1444
			st.setStyleRange(dateStyle);
1445
			sb = new StringBuffer();
1446
			sb.append(text.getOriginator().getName()).append(": "); //$NON-NLS-1$
1447
			StyleRange sr = new StyleRange();
1448
			sr.start = startRange + dateStyle.length;
1449
			sr.length = sb.length();
1450
			sr.fontStyle = SWT.BOLD;
1451
			// check to see which color should be used
1452
			sr.foreground = nickContained ? highlightColor : otherColor;
1453
			st.append(sb.toString());
1454
			st.setStyleRange(sr);
1455
		}
1456
		int beforeMessageIndex = st.getText().length();
1457
		st.append(text.getText());
1458
		if (text.getOriginator() == null) {
1459
			StyleRange sr = new StyleRange();
1460
			sr.start = beforeMessageIndex;
1461
			sr.length = text.getText().length();
1462
			sr.foreground = systemColor;
1463
			sr.fontStyle = SWT.BOLD;
1464
			st.setStyleRange(sr);
1465
		} else if (nickContained) {
1466
			// highlight the message itself as necessary
1467
			StyleRange sr = new StyleRange();
1468
			sr.start = beforeMessageIndex;
1469
			sr.length = text.getText().length();
1470
			sr.foreground = highlightColor;
1471
			st.setStyleRange(sr);
1472
		}
1394
		}
1395
		
1396
		int startRange = st.getText().length();
1397
			
1473
		if (!text.isNoCRLF()) {
1398
		if (!text.isNoCRLF()) {
1474
			st.append("\n"); //$NON-NLS-1$
1399
			output += "\n"; //$NON-NLS-1$
1475
		}
1400
		}
1476
		String t = st.getText();
1401
		
1477
		if (t == null)
1402
		st.append(output);
1478
			return;
1403
		if (ranges != null) {
1479
		if (scrollToBottom) st.setSelection(t.length());
1404
1405
			// set all ranges to start as message line starts
1406
			for (int i = 0; i < ranges.length; i++) {
1407
				ranges[i].start += startRange;
1408
				st.setStyleRange(ranges[i]);
1409
			} 	
1410
		}
1411
		
1412
		if (shouldScrollToEnd(st)) st.setSelection(startRange + output.length());
1480
		// Bold title if view is not visible.
1413
		// Bold title if view is not visible.
1481
		IWorkbenchSiteProgressService pservice = (IWorkbenchSiteProgressService) this
1414
		IWorkbenchSiteProgressService pservice = (IWorkbenchSiteProgressService) this
1482
				.getSite().getAdapter(IWorkbenchSiteProgressService.class);
1415
				.getSite().getAdapter(IWorkbenchSiteProgressService.class);
Lines 1600-1618 Link Here
1600
		getSite().registerContextMenu(menuMgr, selectionProvider);
1533
		getSite().registerContextMenu(menuMgr, selectionProvider);
1601
	}
1534
	}
1602
1535
1603
	private Color colorFromRGBString(String rgb) {
1536
	public void setMessageRenderer(IMessageRenderer defaultMessageRenderer) {
1604
		Color color = null;
1537
		this.messageRenderer = defaultMessageRenderer;
1605
		if (rgb == null || rgb.equals("")) { //$NON-NLS-1$
1606
			color = new Color(getViewSite().getShell().getDisplay(), 0, 0, 0);
1607
			return color;
1608
		}
1609
		if (color != null) {
1610
			color.dispose();
1611
		}
1612
		String[] vals = rgb.split(","); //$NON-NLS-1$
1613
		color = new Color(getViewSite().getShell().getDisplay(), Integer
1614
				.parseInt(vals[0]), Integer.parseInt(vals[1]), Integer
1615
				.parseInt(vals[2]));
1616
		return color;
1617
	}
1538
	}
1618
}
1539
}
(-)src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerUI.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/****************************************************************************
1
/****************************************************************************
2
 * Copyright (c) 2004 Composent, Inc. and others.
2
 * Copyright (c) 2004, 2007 Composent, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Composent, Inc. - initial API and implementation
9
 *    Composent, Inc. - initial API and implementation
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
 *****************************************************************************/
11
package org.eclipse.ecf.presence.ui.chatroom;
12
package org.eclipse.ecf.presence.ui.chatroom;
12
13
Lines 106-111 Link Here
106
		chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID),
107
		chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID),
107
				ChatRoomManagerView.getHostnameFromID(targetID),
108
				ChatRoomManagerView.getHostnameFromID(targetID),
108
				managerChatRoom, this, createChatRoomViewCloseListener());
109
				managerChatRoom, this, createChatRoomViewCloseListener());
110
		chatroomview.setMessageRenderer(getDefaultMessageRenderer());
109
		// Add listener for container, so that if the container is spontaneously
111
		// Add listener for container, so that if the container is spontaneously
110
		// disconnected,
112
		// disconnected,
111
		// then we will be able to have the UI respond by making itself inactive
113
		// then we will be able to have the UI respond by making itself inactive
Lines 150-155 Link Here
150
		});
152
		});
151
	}
153
	}
152
154
155
	protected IMessageRenderer getDefaultMessageRenderer() {
156
		return new MessageRenderer();
157
	}
158
153
	protected String getPasswordForChatRoomConnect(IChatRoomInfo info) {
159
	protected String getPasswordForChatRoomConnect(IChatRoomInfo info) {
154
		return null;
160
		return null;
155
	}
161
	}
(-)src/org/eclipse/ecf/presence/ui/chatroom/IMessageRenderer.java (+38 lines)
Added Link Here
1
/****************************************************************************
2
 * Copyright (c) 2007 Composent, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
package org.eclipse.ecf.presence.ui.chatroom;
12
13
import org.eclipse.ecf.internal.presence.ui.ChatLine;
14
import org.eclipse.swt.custom.StyleRange;
15
16
/**
17
 * Renders chat line, by arranging text content to be finally printed to 
18
 * Chat room output together with it's formatting.
19
 *
20
 */
21
public interface IMessageRenderer {
22
23
	/**
24
	 * Returns text content to be finally printed to chat room output.
25
	 * @param message chat message to be processed
26
	 * @param originator name of message sender
27
	 * @param localUserName local user name 
28
	 * @return text to be printed to output, nothing will be printed if null
29
	 */
30
	String render(String message, String originator, String localUserName);
31
	
32
	/**
33
	 * Returns formatting to be applied to rendered final output, returned by {@link #render(ChatLine, boolean)}.
34
	 * @return formatting to be applied to output, or null if no formatting
35
	 */
36
	StyleRange[] getStyleRanges();
37
	
38
}
(-)src/org/eclipse/ecf/presence/ui/chatroom/MessageRenderer.java (+176 lines)
Added Link Here
1
/****************************************************************************
2
 * Copyright (c) 2007 Composent, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
package org.eclipse.ecf.presence.ui.chatroom;
12
13
import java.text.SimpleDateFormat;
14
import java.util.ArrayList;
15
import java.util.Date;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.ecf.internal.presence.ui.Messages;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.custom.StyleRange;
23
import org.eclipse.swt.graphics.Color;
24
import org.eclipse.swt.widgets.Display;
25
26
/**
27
 * Default implementation of {@link IMessageRenderer}.
28
 *
29
 */
30
public class MessageRenderer implements IMessageRenderer {
31
32
	private Color otherColor = null;
33
	private Color systemColor = null;
34
	private Color dateColor = null;
35
	private Color highlightColor = null;
36
	
37
	private StringBuffer buffer;
38
	
39
	private List styleRanges = new ArrayList();
40
	
41
	protected static final String DEFAULT_ME_COLOR = "0,255,0"; //$NON-NLS-1$
42
	protected static final String DEFAULT_OTHER_COLOR = "0,0,0"; //$NON-NLS-1$
43
	protected static final String DEFAULT_SYSTEM_COLOR = "0,0,255"; //$NON-NLS-1$
44
45
	/**
46
	 * The default color used to highlight the string of text when the user's
47
	 * name is referred to in the chatroom. The default color is red.
48
	 */
49
	protected static final String DEFAULT_HIGHLIGHT_COLOR = "255,0,0"; //$NON-NLS-1$
50
	protected static final String DEFAULT_DATE_COLOR = "0,0,0"; //$NON-NLS-1$
51
	
52
	protected static final String DEFAULT_TIME_FORMAT = Messages.MessageRenderer_DEFAULT_TIME_FORMAT;
53
54
	protected static final String DEFAULT_DATE_FORMAT = Messages.MessageRenderer_DEFAULT_DATE_FORMAT;
55
	
56
	protected boolean nickContained;
57
	protected String message;
58
	protected String originator;
59
	
60
	public MessageRenderer() {
61
		otherColor = colorFromRGBString(DEFAULT_OTHER_COLOR);
62
		systemColor = colorFromRGBString(DEFAULT_SYSTEM_COLOR);
63
		highlightColor = colorFromRGBString(DEFAULT_HIGHLIGHT_COLOR);
64
		dateColor = colorFromRGBString(DEFAULT_DATE_COLOR);
65
	}
66
	
67
	public StyleRange[] getStyleRanges() {
68
		return (StyleRange[]) styleRanges.toArray(new StyleRange[styleRanges.size()]);
69
	}
70
	
71
	public String render(String message, String originator, String localUserName) {
72
		Assert.isNotNull(localUserName);
73
		
74
		styleRanges.clear();
75
		
76
		if (message == null) {
77
			return null;
78
		}
79
		
80
		buffer = new StringBuffer();
81
		
82
		
83
		this.message = message;
84
		this.originator = originator;
85
		
86
		// check to see if the message has the user's name contained within
87
		// and make sure that the person referring to the user's name
88
		// is not the user himself, no highlighting is required in this case
89
		// as the user is already aware that his name is being referenced
90
		nickContained = (message.indexOf(localUserName) != -1) && (! localUserName.equals(originator));
91
		
92
		doRender();
93
		
94
		return buffer.toString();
95
	}
96
	
97
	protected void doRender() {
98
		
99
		appendDateTime();
100
		if (originator != null) {
101
			appendNickname();
102
		}
103
		appendMessage();
104
	}
105
	
106
	protected void appendDateTime() {
107
		String message = NLS.bind(Messages.MessageRenderer_DEFAULT_DATETIME_FORMAT, getCurrentDate(DEFAULT_TIME_FORMAT));
108
		append(message, dateColor, null, SWT.NORMAL);
109
	}
110
111
	protected void appendNickname() {
112
		String message = originator + ": "; //$NON-NLS-1$
113
		// check to see which color should be used
114
		Color foreground = nickContained ? highlightColor : otherColor;
115
		append(message, foreground, null, SWT.BOLD);
116
	}
117
	
118
	protected void appendMessage() {
119
		Color color = null;
120
		int style = SWT.NONE;
121
		if (originator == null) {
122
			color = systemColor;
123
			style = SWT.BOLD;
124
		} else if (nickContained) {
125
			// highlight the message itself as necessary			
126
			color = highlightColor;
127
		}
128
		append(message, color, null, style);
129
	}
130
	
131
	protected void append(String message, Color foreground, Color background, int style) {
132
		if (message == null) {
133
			return;
134
		}
135
		
136
		int start = buffer.length();
137
		
138
		buffer.append(message);
139
		
140
		if (foreground == null && background == null && style == SWT.NONE) {
141
			return;
142
		}
143
		
144
		StyleRange styleRange = new StyleRange(start, message.length(), foreground, background, style);
145
		styleRanges.add(styleRange);
146
	}
147
	
148
	private Color colorFromRGBString(String rgb) {
149
		Color color = null;
150
		if (rgb == null || rgb.equals("")) { //$NON-NLS-1$
151
			color = new Color(Display.getCurrent(), 0, 0, 0);
152
			return color;
153
		}
154
		if (color != null) {
155
			color.dispose();
156
		}
157
		String[] vals = rgb.split(","); //$NON-NLS-1$
158
		color = new Color(Display.getCurrent(), Integer
159
				.parseInt(vals[0]), Integer.parseInt(vals[1]), Integer
160
				.parseInt(vals[2]));
161
		return color;
162
	}
163
	
164
	protected String getCurrentDate(String format) {
165
		SimpleDateFormat sdf = new SimpleDateFormat(format);
166
		String res = sdf.format(new Date());
167
		return res;
168
	}
169
170
	protected String getDateTime() {
171
		StringBuffer buf = new StringBuffer();
172
		buf.append(getCurrentDate(DEFAULT_DATE_FORMAT)).append(" ").append( //$NON-NLS-1$
173
				getCurrentDate(DEFAULT_TIME_FORMAT));
174
		return buf.toString();
175
	}
176
}
(-)src/org/eclipse/ecf/internal/provider/irc/container/IRCRootContainer.java (-5 / +14 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Composent, Inc. - initial API and implementation
9
 *    Composent, Inc. - initial API and implementation
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197604
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197604, 197329
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.ecf.internal.provider.irc.container;
12
package org.eclipse.ecf.internal.provider.irc.container;
13
13
Lines 135-141 Link Here
135
		connection.addIRCEventListener(getIRCEventListener());
135
		connection.addIRCEventListener(getIRCEventListener());
136
		connection.setPong(true);
136
		connection.setPong(true);
137
		connection.setDaemon(false);
137
		connection.setDaemon(false);
138
		connection.setColors(false);
138
		connection.setColors(true);
139
		if (encoding != null)
139
		if (encoding != null)
140
			connection.setEncoding(encoding);
140
			connection.setEncoding(encoding);
141
		trace(Messages.IRCRootContainer_Connecting_To + targetID);
141
		trace(Messages.IRCRootContainer_Connecting_To + targetID);
Lines 518-524 Link Here
518
		return new IChatRoomMessageSender() {
518
		return new IChatRoomMessageSender() {
519
			public void sendMessage(String message) throws ECFException {
519
			public void sendMessage(String message) throws ECFException {
520
				if (isCommand(message))
520
				if (isCommand(message))
521
					parseCommandAndSend(message, null);
521
					parseCommandAndSend(message, null, null);
522
				else
522
				else
523
					showErrorMessage(null, NLS.bind(
523
					showErrorMessage(null, NLS.bind(
524
							Messages.IRCRootContainer_Command_Error, message,
524
							Messages.IRCRootContainer_Command_Error, message,
Lines 565-571 Link Here
565
		return token;
565
		return token;
566
	}
566
	}
567
	
567
	
568
	protected void parseCommandAndSend(String commandMessage, String channelName) {
568
	protected void parseCommandAndSend(String commandMessage, String channelName, String ircUser) {
569
		synchronized (this) {
569
		synchronized (this) {
570
			if (connection != null) {
570
			if (connection != null) {
571
				try {
571
				try {
Lines 645-650 Link Here
645
						if (index != -1) {
645
						if (index != -1) {
646
							connection.doMode(channelName, commandMessage);
646
							connection.doMode(channelName, commandMessage);
647
						}
647
						}
648
					} else if (lowerCase.startsWith("/me ")) { //$NON-NLS-1$
649
						nextToken(command); // skip command
650
						
651
						String message = command.toString();
652
						if (message.length() > 0) {
653
							message = "\01ACTION "+message+"\01"; //$NON-NLS-1$ //$NON-NLS-2$
654
							connection.doPrivmsg(channelName, message);
655
							showMessage(channelName, ircUser, message);
656
						}
648
					} else {
657
					} else {
649
						String[] tokens = parseCommandTokens(commandMessage);
658
						String[] tokens = parseCommandTokens(commandMessage);
650
						handleCommandMessage(tokens, channelName);
659
						handleCommandMessage(tokens, channelName);
Lines 909-915 Link Here
909
		if (connection != null) {
918
		if (connection != null) {
910
			// If it's a command,
919
			// If it's a command,
911
			if (isCommand(msg)) {
920
			if (isCommand(msg)) {
912
				parseCommandAndSend(msg, channelName);
921
				parseCommandAndSend(msg, channelName, ircUser);
913
			} else {
922
			} else {
914
				connection.doPrivmsg(channelName, msg);
923
				connection.doPrivmsg(channelName, msg);
915
				showMessage(channelName, ircUser, msg);
924
				showMessage(channelName, ircUser, msg);
(-)src/org/eclipse/ecf/internal/irc/ui/IRCUI.java (-2 / +7 lines)
Lines 1-5 Link Here
1
/****************************************************************************
1
/****************************************************************************
2
 * Copyright (c) 2004 Composent, Inc. and others.
2
 * Copyright (c) 2004, 2007 Composent, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Composent, Inc. - initial API and implementation
9
 *    Composent, Inc. - initial API and implementation
10
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
 *****************************************************************************/
11
12
12
package org.eclipse.ecf.internal.irc.ui;
13
package org.eclipse.ecf.internal.irc.ui;
Lines 21-26 Link Here
21
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
22
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
22
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
23
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
23
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI;
24
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI;
25
import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer;
24
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.osgi.util.NLS;
26
28
Lines 120-124 Link Here
120
		return inputLine;
122
		return inputLine;
121
123
122
	}
124
	}
123
125
	
126
	protected IMessageRenderer getDefaultMessageRenderer() {
127
		return new IRCMessageRenderer();
128
	}
124
}
129
}
(-)src/org/eclipse/ecf/internal/irc/ui/IRCMessageRenderer.java (+60 lines)
Added Link Here
1
/****************************************************************************
2
 * Copyright (c) 2007 Composent, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329
10
 *****************************************************************************/
11
package org.eclipse.ecf.internal.irc.ui;
12
13
import org.eclipse.ecf.presence.ui.chatroom.MessageRenderer;
14
import org.eclipse.swt.SWT;
15
16
public class IRCMessageRenderer extends MessageRenderer {
17
18
	private final static String ME_PREFIX = "\01ACTION "; //$NON-NLS-1$
19
	private final static String ME_SUFFIX = "\01"; //$NON-NLS-1$
20
21
	private boolean isActionMessage;
22
	
23
	protected void doRender() {
24
		String actionMessage = getActionMessage(message);
25
		isActionMessage = (actionMessage != null);
26
		
27
		if (isActionMessage) {
28
			message = actionMessage;
29
		}
30
		
31
		super.doRender();
32
	}
33
34
	protected void appendNickname() {
35
		if (isActionMessage) {
36
			String message = originator + " "; //$NON-NLS-1$
37
			append(message, null, null, SWT.ITALIC);
38
		} else {
39
			super.appendNickname();
40
		}
41
	}
42
	
43
	protected void appendMessage() {
44
		if (isActionMessage) {
45
			append(message, null, null, SWT.ITALIC);
46
		} else {
47
			super.appendMessage();
48
		}
49
	}
50
	
51
	private String getActionMessage(String message) {
52
		if (message.startsWith(ME_PREFIX) && message.endsWith(ME_SUFFIX)) {
53
			return message.substring(ME_PREFIX.length(), message.length() - ME_SUFFIX.length());
54
		} else {
55
			return null;
56
		}
57
	}
58
59
	
60
}

Return to bug 197329