if ((layout & TOPIC) != 0) {
topicBox = new StyledText(this, SWT.BORDER | SWT.WRAP);
topicBox.setEditable(true);
topicBox.setWordWrap(false);
topicBox.addVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent e) {
// on pressing Enter, attempt to set the topic
if (e.character == SWT.CR) {
bot.setTopic(Room.this.getCChannel().getChannel(),
topicBox.getText());
e.doit = false;
}
// or add control codes
if (e.stateMask == SWT.CTRL) {
switch (e.keyCode) {
// Key combinations
case 'O':
case 'o': // Insert Normal (kills all formatting)
insertCode("\u000f");
break;
case 'B':
case 'b': // Insert Bold
insertCode("\u0002");
break;
case 'U':
case 'u': // Insert Underlin
insertCode("\u001f");
break;
case 'I':
case 'i': // Insert Italic
insertCode("\u0016");
break;
case 'K':
case 'k': // Insert Color
insertCode("\u0003");
break;
case 'A':
case 'a': // Select all
input.selectAll();
break;
}
}
}
private void insertCode(String insertCode) {
int insertPos = topicBox.getCaretOffset();
topicBox.replaceTextRange(insertPos, 0, insertCode);
topicBox.setCaretOffset(insertPos + 1);
}
});
topicBox.addWordMovementListener(linkClickListener);
}
if ((layout & IO) != 0) {
// set up the output window
output = new StyledText(this, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP
| SWT.MULTI);
output.setFont(SWTResourceManager.getFont("Courier New", 9,
SWT.NORMAL));
output.setForeground(customs.colors.get(Settings.getSettings()
.getOutputColors().get(Message.MSG)));
output.setBackground(customs.colors.get(Settings.getSettings()
.getOutputColors().get(Settings.BACKGROUND)));
output.setEditable(false);
output.addWordMovementListener(linkClickListener);
// if key pressed while output box selected, move to input box
output.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
// TODO: Make this accept more than letters and digits,
// without letting it put weird characters in
if (e.stateMask != SWT.CTRL && e.stateMask != SWT.ALT
&& e.character != 0 && e.character != SWT.CR) {
input.append("" + e.character);
input.setSelection(input.getText().length());
input.setFocus();
}
}
});
// set up the input box and it's enter-key listener
input = new StyledText(this, SWT.BORDER);
input.setFont(SWTResourceManager.getFont("Courier New", 9,
SWT.NORMAL));
input.setForeground(customs.colors.get(Settings.getSettings()
.getOutputColors().get(Message.MSG)));
input.setBackground(customs.colors.get(Settings.getSettings()
.getOutputColors().get(Settings.BACKGROUND)));
input.addVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent e) {
if (e.stateMask == SWT.CTRL && // Ignore adding an indent when hitting
(e.keyCode == 'I' || e.keyCode == 'i')) // Ctrl + I
e.doit = false;