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 |
} |