1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/***************************************************************************
* Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
package org.eclipse.net4j.buddies.chat.internal.ui;
import org.eclipse.net4j.buddies.chat.IChat;
import org.eclipse.net4j.buddies.chat.IComment;
import org.eclipse.net4j.buddies.internal.chat.CommentEvent;
import org.eclipse.net4j.buddies.internal.ui.views.CollaborationsPane;
import org.eclipse.net4j.buddies.internal.ui.views.FacilityPane;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.ui.actions.SafeAction;
import org.eclipse.net4j.util.ui.widgets.SashComposite;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
/**
* @author Eike Stepper
*/
public class ChatPane extends FacilityPane
{
private SashComposite sashComposite;
private Text input;
private Text output;
public ChatPane(CollaborationsPane collaborationsPane, int style)
{
super(collaborationsPane, style);
}
@Override
protected void handleEvent(IEvent event) throws Exception
{
if (event instanceof CommentEvent)
{
CommentEvent e = (CommentEvent)event;
IComment comment = e.getComment();
String text = comment.getText();
output.append(comment.getSenderID() + ": " + text + StringUtil.NL);
}
}
@Override
protected Control createUI(Composite parent)
{
sashComposite = new SashComposite(parent, SWT.NONE, 16, 80)
{
@Override
protected Control createControl1(Composite parent)
{
output = new Text(parent, SWT.MULTI);
return output;
}
@Override
protected Control createControl2(Composite parent)
{
input = new Text(parent, SWT.MULTI);
input.addKeyListener(new KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
{
if ((e.character == SWT.CR || e.character == SWT.LF) && e.stateMask == 0)
{
((IChat)getFacility()).sendComment(input.getText());
input.setText("");
e.doit = false;
}
}
});
return input;
}
};
sashComposite.setVertical(true);
return sashComposite;
}
@Override
protected void fillCoolBar(IContributionManager manager)
{
manager.add(new SafeAction("Vertical Layout", "Vertical Layout", SharedIcons
.getDescriptor(SharedIcons.ETOOL_VERTICAL))
{
@Override
protected void safeRun() throws Exception
{
sashComposite.setVertical(true);
}
});
manager.add(new SafeAction("Horizontal Layout", "Horizontal Layout", SharedIcons
.getDescriptor(SharedIcons.ETOOL_HORIZONTAL))
{
@Override
protected void safeRun() throws Exception
{
sashComposite.setVertical(false);
}
});
}
}
|