chatTextArea = new HistoryTextField();
chatTextArea.setMaximumSize(new Dimension(Integer.MAX_VALUE, textHeight));
// Enable tab character
chatTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, EMPTY_SET);
chatTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, EMPTY_SET);
chatTextArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {}
@Override
public void keyTyped(KeyEvent e) {
switch(e.getKeyChar()) {
case '\n': {
e.consume();
try {
for(String element : chatTextArea.getText().split("\n")) {
if(element.trim().length() > 0)
getFirstConnection().sendChatInternal(element);
}
chatTextArea.setText(null);
return;
} catch(Exception ex) {
Out.exception(ex);
}
break;
}
case '\t': {
e.consume();
if(GlobalSettings.enableTabCompleteUser) {
tabComplete = true;
tcUserSearch = true;
}
break;
}
case ' ': {
if(lastWhisperFrom != null) {
String txt = chatTextArea.getText().trim();
if("/r".equals(txt))
chatTextArea.setText(lastWhisperFrom.getWhisperCommand().trim());
}
if(lastWhisperTo != null) {
String txt = chatTextArea.getText().trim();
if("/rw".equals(txt))
chatTextArea.setText(lastWhisperTo.getWhisperCommand().trim());
}
if("/cmd".equals(chatTextArea.getText()) && GlobalSettings.enableTabCompleteCommand) {
tabComplete = true;
tcUserSearch = false;
}
break;
}
case '/': {
if("/".equals(chatTextArea.getText()) && GlobalSettings.enableTabCompleteCommand) {
tabComplete = true;
tcUserSearch = false;
}
break;
}
default:
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
if(!tabComplete)
return;
try {
if(tcUserSearch) {
int end = chatTextArea.getCaretPosition();
tcSearch = chatTextArea.getText(0, end);
int start = tcSearch.lastIndexOf(' ') + 1;
if(start != 0)
tcSearch = tcSearch.substring(start);
tcBefore = chatTextArea.getText(0, start);
tcAfter = chatTextArea.getText(end, chatTextArea.getText().length() - end);
} else {
tcSearch = "";
tcBefore = chatTextArea.getText();
tcAfter = "";
}
tcUpdate();
} catch(Exception ex) {
Out.exception(ex);
}
}
});
// Channel text box (above userlist)
channelTextPane = new ColoredTextField();
channelTextPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, textHeight));
channelTextPane.setHorizontalAlignment(JTextField.CENTER);
channelTextPane.setEditable(false);
// The userlist
userList = new UserList(this);
// Friends list
friendList = new FriendList();
// Clan list
clanList = new ClanList();
// BotNet list
if(getFirstConnection().getConnectionSettings().enableBotNet)
botNetList = new BotNetList(this);
JTabbedPane allLists = new JTabbedPane(JTabbedPane.BOTTOM);
allLists.addTab("Channel", new JScrollPane(userList));
allLists.addTab("Friends", new JScrollPane(friendList));
allLists.addTab("Clan", new JScrollPane(clanList));
if(botNetList != null)
allLists.addTab("BotNet", new JScrollPane(botNetList));
Box leftSide = new Box(BoxLayout.Y_AXIS);
leftSide.add(mainTextArea);
leftSide.add(Box.createVerticalStrut(paddingHeight));
leftSide.add(chatTextArea);
Box rightSide = new Box(BoxLayout.Y_AXIS);
rightSide.add(channelTextPane);
rightSide.add(Box.createVerticalStrut(paddingHeight));
rightSide.add(allLists);
jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, leftSide, rightSide);
jsp.setDividerSize(8);
jsp.setResizeWeight(1); // Make the left side expand when resizing
// Add a listener for when the divider moves
((BasicSplitPaneUI)jsp.getUI()).getDivider().addComponentListener(new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
// If the window is maximized, skip this
if(GuiDesktop.getInstance().getExtendedState() == Frame.MAXIMIZED_BOTH)
return;
// Save the divider location
Settings.getSection("GuiDesktop").write("dividerLocation", jsp.getDividerLocation());
Settings.store();
}
});
// Add them to the frame
frame.add(jsp);
// Initialize the TC popup window
tcPopupWindow = new JDialog();
tcPopupWindow.setUndecorated(true);
tcPopupWindow.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Set location relative to chatTextArea
Point location = chatTextArea.getLocation();
SwingUtilities.convertPointToScreen(location, chatTextArea.getParent());
location.translate(0, chatTextArea.getHeight()
+ (chatTextArea.getBorder() == null ? 0
: chatTextArea.getBorder().getBorderInsets(chatTextArea).bottom));
tcPopupWindow.setLocation(location);
}
});
}
@Override
public void windowLostFocus(WindowEvent e) {
tcPopupWindow.setVisible(tabComplete = false);
}
});
tcPopupWindow.getContentPane().setLayout(new BorderLayout());
((JComponent)tcPopupWindow.getContentPane()).setBorder(BorderFactory.createEtchedBorder());
tcPopupWindow.getContentPane().add(tcList);
// Initialize TC list
tcList.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {}
@Override
public void keyTyped(KeyEvent e) {}
@Override