📄 chatwindowdialog.java
字号:
} catch (IOException ioe){}
}
else if (evt.getSource().equals(quitChatroom)){
try {
MessageAdapter.partChatroom(chatroomName);
userListVector.removeAllElements();
usersList.setListData(userListVector);
chatroomName = "";
tabbedChatFrame.setTitleAt(0, "");
} catch (IOException ioe){}
}
else if (evt.getSource().equals(sendIM)){
String imUser;
imUser = JOptionPane.showInputDialog(this, locale.printLocale("Username"), locale.printLocale("Send IM"),
JOptionPane.OK_CANCEL_OPTION);
if (imUser != null && imUser != ""){
InstantMessageWindow.getInstance(imUser);
}
}
else if (evt.getSource().equals(openChatroomList)){
ChatroomListingWindow.getInstance().show();
}
else if (evt.getSource().equals(aboutWindow)){
DialogManager.SuccessDialog("GTADS " + DSChatClient.VERSION_NAME + " " + DSChatClient.VERSION_NUMBER + " By\n" +
"Steven Day\n\n" + "Website: http://gtads.blogspot.com\n");
}
}
public void keyPressed (KeyEvent key){
if (key.getKeyCode() == KeyEvent.VK_ENTER){
sendChatToRoom();
}
else if (inputChatBox.getText().length() >= 255){
key.setKeyCode(0);
inputChatBox.setText(inputChatBox.getText().substring(0,254));
}
}
public void keyTyped(KeyEvent key){}
public void keyReleased(KeyEvent key){}
private void sendChatToRoom(){
if (processCommand() == true)
return;
MetaData sendHeader = new MetaData(username, MetaData.CHATROOM, chatroomName);
try {
String newChatMessage = inputChatBox.getText();
if (newChatMessage.length() > 255){
newChatMessage = newChatMessage.substring(0,254);
}
ClientListenHandler.sendChatMessage(sendHeader, newChatMessage);
inputChatBox.setText("");
inputChatBox.requestFocus();
} catch (IOException ioe){
return;
}
}
private boolean isCommandClearScreen(String command){
boolean isClearScreen = false;
String CLEAR_SCREEN = "clear";
if (command.length() >= 1 + CLEAR_SCREEN.length() && command.substring(1,1 + CLEAR_SCREEN.length()).equalsIgnoreCase(CLEAR_SCREEN)){
isClearScreen = true;
}
return isClearScreen;
}
private boolean processCommand(){
String JOIN_COMMAND = "Join";
String PART_COMMAND = "Part";
String QUIT_COMMAND = "Quit";
String S_KICK_COMMAND = "skick";
String UPTIME_COMMAND = "uptime";
String REFRESH_MOTD = "rmotd";
String READ_MOTD = "motd";
String SET_CONFIG = "setconfig";
String SHOW_CONFIG = "showconfig";
String SET_BAN_USER = "banuser";
String REMOVE_BAN_USER = "unbanuser";
String SET_BAN_IP = "banip";
String REMOVE_BAN_IP = "unbanip";
String GET_PING = "pingtime";
String newChatroom = new String();
String userToKick = new String();
String command = inputChatBox.getText();
if (command.startsWith("/")){
inputChatBox.setText("");
inputChatBox.requestFocus();
if (command.length() >= 1 + JOIN_COMMAND.length() && command.substring(1,1 + JOIN_COMMAND.length()).equalsIgnoreCase(JOIN_COMMAND)){
newChatroom = command.substring(("/" + JOIN_COMMAND).length() + 1, command.length());
try {
joinChatroom(newChatroom, chatroomName);
} catch (IOException ioe) {
DialogManager.ErrorDialog("Could not Join " + newChatroom);
}
return true;
}
else if (command.length() >= 1 + PART_COMMAND.length() && command.substring(1,1 + PART_COMMAND.length()).equalsIgnoreCase(PART_COMMAND)){
try {
MessageAdapter.partChatroom(chatroomName);
userListVector.removeAllElements();
usersList.setListData(userListVector);
chatroomName = "";
tabbedChatFrame.setTitleAt(0, "");
} catch (IOException ioe) {
DialogManager.ErrorDialog("Could not Part " + chatroomName);
}
return true;
}
else if (command.length() >= 1 + QUIT_COMMAND.length() && command.substring(1,1 + QUIT_COMMAND.length()).equalsIgnoreCase(QUIT_COMMAND)) {
//newChatroom = command.substring(("/" + PART_COMMAND).length(), command.length());
try {
MessageAdapter.quitServer(chatroomName);
chatroomName = "";
} catch (IOException ioe) {
}
return true;
}
else if (command.length() >= 1 + S_KICK_COMMAND.length() && command.substring(1,1 + S_KICK_COMMAND.length()).equalsIgnoreCase(S_KICK_COMMAND)){
userToKick = command.substring(("/" + S_KICK_COMMAND).length() + 1, command.length());
try {
MessageAdapter.serverKickUser(userToKick);
} catch (IOException ioe){}
}
else if (command.length() >= 1 + UPTIME_COMMAND.length() && command.substring(1,1 + UPTIME_COMMAND.length()).equalsIgnoreCase(UPTIME_COMMAND)){
if (command.length() <= ("/" + UPTIME_COMMAND).length()){
getUptime(MetaData.SYSTEM_VAR);
}
else if (command.length() >= ("/" + UPTIME_COMMAND).length() + 1){
String userUptime = command.substring(("/" + UPTIME_COMMAND).length() + 1, command.length());
getUptime(userUptime);
}
return true;
}
// Admin Command: refresh Motd
else if (command.length() >= 1 + REFRESH_MOTD.length() && command.substring(1,1 + REFRESH_MOTD.length()).equalsIgnoreCase(REFRESH_MOTD)){
try {
MetaData motdRefreshHeader = new MetaData(username, MetaData.GENERIC, MetaData.REFRESH_MOTD);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,motdRefreshHeader,"NULL");
} catch (IOException ioe){
// do nothing
}
}
else if (command.length() >= 1 + READ_MOTD.length() && command.substring(1,1 + READ_MOTD.length()).equalsIgnoreCase(READ_MOTD)){
try {
MetaData motdGetHeader = new MetaData(username, MetaData.GENERIC, MetaData.GET_MOTD);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,motdGetHeader,"NULL");
} catch (IOException ioe){
}
return true;
}
else if (command.length() >= 1 + SET_CONFIG.length() && command.substring(1,1 + SET_CONFIG.length()).equalsIgnoreCase(SET_CONFIG)){
if (command.length() >= ("/" + SET_CONFIG).length() + 1){
String[] keyValue = new String[2];
String configParameters = command.substring(("/" + SET_CONFIG).length() + 1, command.length());
if (configParameters != null){
keyValue = configParameters.split(",");
if (keyValue.length > 1){
MetaData requestConfigChangeHeader = new MetaData(
username, MetaData.GENERIC,MetaData.SET_CONFIG);
try {
MessageAdapter.sendData(null,DSChatClient.ClientSocket,
requestConfigChangeHeader,keyValue[0] + "," + keyValue[1]);
} catch (IOException ioe){
}
}
else {
this.appendToChatroom(0, "Invalid parameters:");
this.appendToChatroom(0, "Correct Use: /setconfig key,value");
}
}
}
return true;
}
else if (command.length() >= 1 + SHOW_CONFIG.length() && command.substring(1,1 + SHOW_CONFIG.length()).equalsIgnoreCase(SHOW_CONFIG)){
try {
MetaData displayConfigOptions = new MetaData(
username, MetaData.GENERIC,MetaData.SET_CONFIG);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,displayConfigOptions,MetaData.SHOW_CONFIG);
} catch (IOException ioe){
}
return true;
}
else if (command.length() >= 1 + SET_BAN_USER.length() && command.substring(1,1 + SET_BAN_USER.length()).equalsIgnoreCase(SET_BAN_USER)){
String argString = command.substring(("/" + SET_BAN_USER).length() + 1, command.length());
String[] banned = argString.split(",");
String duration = "";
if (banned.length > 1){
duration = banned[1];
}
MetaData banUserHeader = new MetaData(username, MetaData.GENERIC,MetaData.BAN_USER);
try {
MessageAdapter.sendData(null,DSChatClient.ClientSocket,banUserHeader,banned[0] + "," + duration);
} catch (IOException ioe){
}
}
else if (command.length() >= 1 + REMOVE_BAN_USER.length() && command.substring(1,1 + REMOVE_BAN_USER.length()).equalsIgnoreCase(REMOVE_BAN_USER)){
String banned = command.substring(("/" + REMOVE_BAN_USER).length() + 1, command.length());
MetaData banUserHeader = new MetaData(username, MetaData.GENERIC,MetaData.UNBAN_USER);
try {
MessageAdapter.sendData(null,DSChatClient.ClientSocket,banUserHeader,banned);
} catch (IOException ioe){
}
}
else if (command.length() >= 1 + SET_BAN_IP.length() && command.substring(1,1 + SET_BAN_IP.length()).equalsIgnoreCase(SET_BAN_IP)){
String argString = command.substring(("/" + SET_BAN_IP).length() + 1, command.length());
String[] banned = argString.split(",");
String duration = "";
if (banned.length > 1){
duration = banned[1];
}
MetaData banUserHeader = new MetaData(username, MetaData.GENERIC,MetaData.BAN_IP);
try {
MessageAdapter.sendData(null,DSChatClient.ClientSocket,banUserHeader,banned[0] + "," + duration);
} catch (IOException ioe){
}
}
else if (command.length() >= 1 + REMOVE_BAN_IP.length() && command.substring(1,1 + REMOVE_BAN_IP.length()).equalsIgnoreCase(REMOVE_BAN_IP)){
String banned = command.substring(("/" + REMOVE_BAN_IP).length() + 1, command.length());
MetaData banUserHeader = new MetaData(username, MetaData.GENERIC,MetaData.UNBAN_IP);
try {
MessageAdapter.sendData(null,DSChatClient.ClientSocket,banUserHeader,banned);
} catch (IOException ioe){
}
}
else if (command.length() >= 1 + GET_PING.length() && command.substring(1,1 + GET_PING.length()).equalsIgnoreCase(GET_PING)){
String userName = command.substring(("/" + GET_PING).length() + 1, command.length());
try {
if (userName != null){
MetaData getPingTimeHeader = new MetaData(username, MetaData.GENERIC,MetaData.GET_PING);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,getPingTimeHeader,userName);
}
} catch (IOException ioe){
}
}
else if (isCommandClearScreen(command)){
messageChatBox.setText(new String());
}
}
return false;
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
if (e.getSource() == usersList){
if (e.getClickCount() == 2){
InstantMessageWindow.getInstance((String)usersList.getSelectedValue()).show();
}
}
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void getUptime(String user){
MetaData requestUptimeHeader;
try {
if (user == null){
user = MetaData.SYSTEM_VAR;
}
requestUptimeHeader = new MetaData(this.username, MetaData.GENERIC, MetaData.UPTIME);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,requestUptimeHeader,user);
} catch (IOException ioe) {}
}
public void joinChatroom(String newChatroom, String oldChatroom) throws IOException{
MessageAdapter.partChatroom(oldChatroom);
userListVector.removeAllElements();
usersList.setListData(userListVector);
chatroomName = newChatroom;
MessageAdapter.joinChatroom(newChatroom);
chatroomName = newChatroom;
tabbedChatFrame.setTitleAt(0, chatroomName);
}
public DashboardArea getDashboardPanel(){
return dashboard;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -