📄 clientui.1
字号:
});
howToUseMenuItem = new JMenuItem("How To Use");
howToUseMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
HowToUseAction();
}
});
helpMenu.add(aboutMenuItem);
helpMenu.add(howToUseMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
client.logoutUser(myName);
System.exit(0);
}
}
);
//****************** TEXT CHAT DISPLAY ***********
chatDisplay = new ChatDisplay(myName, myCategory);
chatDisplay.addPropertyChangeListener(this);
chatFrame = new JFrame("Text Chat");
chatFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
chatFrame.setVisible(false);
}
});
chatMenuBar = new JMenuBar();
chatFrame.setJMenuBar(chatMenuBar);
chatMenu = new JMenu("Chat");
chatMenuBar.add(chatMenu);
saveMenuItem = new JMenuItem("Save");
saveMenuItem.addActionListener(this);
chatMenu.add(saveMenuItem);
clearPublicMenuItem = new JMenuItem("Clear Public");
clearPublicMenuItem.addActionListener(this);
chatMenu.add(clearPublicMenuItem);
clearPrivateMenuItem = new JMenuItem("Clear Private");
clearPrivateMenuItem.addActionListener(this);
chatMenu.add(clearPrivateMenuItem);
refreshMenuItem = new JMenuItem("Refresh");
refreshMenuItem.addActionListener(this);
chatMenu.add(refreshMenuItem);
chatFrame.getContentPane().add(chatDisplay, BorderLayout.CENTER);
chatFrame.pack();
chatFrame.setSize(new Dimension(400, 300));
//*******************************end of TEXT CHAT DISPLAY***************
//***************************User List Display *************************************
userListDisplay = new UserListDisplay(client.getUsersConfig(), myName);
userListDisplay.setSize(new Dimension(100,200));
//System.out.println("call in ClientUI init");
//*************************** Tool bar *************************************
mytoolBar = new myToolBar(myCategory);
feedbackButton = mytoolBar.feedbackButton;
feedbackButton.addActionListener(this);
stepInButton = mytoolBar.stepInButton;
stepInButton.addActionListener(this);
logoutButton = mytoolBar.logoutButton;
logoutButton.addActionListener(this);
textChatButton = mytoolBar.textChatButton;
textChatButton.addActionListener(this);
voiceChatButton = mytoolBar.voiceChatButton;
voiceChatButton.addActionListener(this);
//LINLIN
speakerButton = new JButton();
speakerButton.setBorder(new javax.swing.border.CompoundBorder());
String speaker = client.getMicLocker();
setSpeaker(speaker);
mytoolBar.add(speakerButton);
//LINLIN
if ((myCategory == Constants.PRESENTER) || (userListDisplay.getMicAvailable())) {
voiceChatButton.setIcon(new javax.swing.ImageIcon(
Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon/voice.gif"))));
}
else {
voiceChatButton.setIcon(new javax.swing.ImageIcon(
Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon/voice_gray.gif"))));
}
//*****************************************************************
switch (myCategory) {
//student
case Constants.USER:
this.handButton = mytoolBar.handButton;
this.handButton.addActionListener(this);
this.yesButton = mytoolBar.yesButton;
this.yesButton.addActionListener(this);
this.noButton = mytoolBar.noButton;
this.noButton.addActionListener(this);
break;
//presenter
case Constants.PRESENTER:
this.lowHandButton = mytoolBar.lowHandButton;
this.lowHandButton.addActionListener(this);
this.clearYesNoButton = mytoolBar.clearYesNoButton;
this.clearYesNoButton.addActionListener(this);
this.giveMicToNextButton = mytoolBar.giveMicToNextButton;
this.giveMicToNextButton.addActionListener(this);
this.sessionInButton = mytoolBar.inSessionButton;
this.sessionInButton.addActionListener(this);
break;
}
splitPaneContent = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPaneContent.setRightComponent(contentDisplay);
leftSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
leftSplitPane.setBottomComponent(contentManager);
leftSplitPane.setTopComponent(userListDisplay);
splitPaneContent.setLeftComponent(leftSplitPane);
contentManager.enableContentManager(true, myCategory);
sessionStatusPanel = new JPanel();
sessionStatusPanel.setLayout(new BorderLayout());
inOutSession = new JLabel("Out of Session");
sessionStatusPanel.add(inOutSession, BorderLayout.WEST);
getContentPane().add(splitPaneContent, BorderLayout.CENTER);
getContentPane().add(mytoolBar, BorderLayout.NORTH);
getContentPane().add(sessionStatusPanel, BorderLayout.SOUTH);
}
//--------------------Main method of ClientUI-----------------------------
/**
* main method for client
*
* @param host name and port number
*/
public static void main (String args[])
{
ClientUI f=new ClientUI("127.0.0.1","1099");
f.loginUser();
f.show();
}
//---------------------------------------------------------
/**
* setCurrentUsers sets the list of current users in the system
*/
private void setCurrentUsers() {
Hashtable userList = client.getUsersConfig();
if (userList == null) return;
Enumeration e = userList.elements();
while (e.hasMoreElements()) {
UserConfig uConfig = (UserConfig) e.nextElement();
if (!uConfig.getUserName().equals(myName)) {
chatDisplay.addUser(uConfig.getUserName(), uConfig.getUserCategory());
}
}
}
//-----------------------------------------------------
/**
* setContentDisplay sets the list of documents
*/
private void setContentDisplay() {
Hashtable contentManagerList = client.getURLTable();
Enumeration e = contentManagerList.elements();
while (e.hasMoreElements()) {
String strURL = (String) e.nextElement();
contentManager.addURL(strURL);
}
}
//-------------------------------------------------------
/**
* setDisplay sets the list of users and content
*/
private void setDisplay() {
setCurrentUsers();
setContentDisplay();
}
//-----------------------------------actionPerformed-----------------------------------
/**
* actionPerformed handle all cases of actions
*/
public void actionPerformed(ActionEvent e)
{
//*************************TEXT CHAT DISPLAY**************************
if (e.getSource() == textChatButton)
{
TextChatAction();
}
else if (e.getSource() == saveMenuItem)
{
this.saveChat();
}
else if (e.getSource() == clearPublicMenuItem)
{
chatDisplay.clearPublicChat();
}
else if (e.getSource() == refreshMenuItem)
{
chatDisplay.refresh(client.getChatMessages());
}
else if (e.getSource() == clearPrivateMenuItem)
{
chatDisplay.clearPrivateChat();
}
//**************************** end of TEXT CHAT DISPLAY*********//YTIAN
else if (e.getSource() == yesButton)
{
YesAction();
}
else if (e.getSource() == noButton)
{
NoAction();
}
else if (e.getSource() == handButton)
{
RaiseHandAction();
}
else if (e.getSource() == lowHandButton)
{
LowerAllHandAction();
}
else if (e.getSource() == feedbackButton)
{
SendFeedbackAction();
}
else if (e.getSource() == sessionInButton)
{
SessionInAction();
}
else if (e.getSource() == stepInButton)
{
StepOutAction();
}
else if (e.getSource() == voiceChatButton)
{
if(!stepInButton.isSelected())
{//when step in
boolean ifStart = false;
if (voiceChatButton.isSelected()) {
if (userListDisplay.getMicAvailable()) {
ifStart = true;
}
if (ifStart) {
voiceChatButton.setBorder(new javax.swing.border.CompoundBorder(null, new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)));
client.startSpeaking();
userListDisplay.displayUserPanel(client.getUsersConfig());
String speaker = client.getMicLocker();
setSpeaker(speaker);
}
else {
voiceChatButton.setIcon(new javax.swing.ImageIcon(
Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon/voice_gray.gif"))));
voiceChatButton.setSelected(false);
voiceChatButton.setBorder(new javax.swing.border.CompoundBorder());
}
}
else {
boolean ifStop = false;
if (userListDisplay.getMicAvailable()) {
ifStop = true;
}
if (ifStop) {
voiceChatButton.setBorder(new javax.swing.border.CompoundBorder());
client.stopSpeaking();
userListDisplay.displayUserPanel(client.getUsersConfig());
if (!userListDisplay.getMicAvailable()) {
voiceChatButton.setIcon(new javax.swing.ImageIcon(
Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon/voice_gray.gif"))));
}
String speaker = client.getMicLocker();
setSpeaker(speaker);
}
else {
voiceChatButton.setSelected(true);
voiceChatButton.setBorder(new javax.swing.border.CompoundBorder(null, new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)));
voiceChatButton.setIcon(new javax.swing.ImageIcon(
Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon/voice_gray.gif"))));
}
}
}
}
else if (e.getSource() == giveMicToNextButton) //this is for presenter**********
{
GiveMicToNextAction();
}
else if (e.getSource() == clearYesNoButton) //this is for presenter***********
{
ClearYesNoAction();
}
else if (e.getSource() == logoutButton)
{
LogoutAction();
}
}
//--------------------------------------All action functions -----------------
/**
* YesAction takes action when user click on Yes button
*/
private void YesAction()
{
if(!stepInButton.isSelected())
{
if (noButton.isSelected() == true)
{
noButton.setBorder(new javax.swing.border.CompoundBorder());
noButton.setSelected(false);
noButton.setToolTipText("Say No");
sayNoMenuItem.setText("Say No");
}
if (yesButton.isSelected())
{
yesButton.setBorder(new javax.swing.border.CompoundBorder(null, new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)));
yesButton.setToolTipText("Delete Say Yes");
sayYesMenuItem.setText("Delete Say Yes");
}
else
{
yesButton.setBorder(new javax.swing.border.CompoundBorder());
yesButton.setToolTipText("Say Yes");
sayYesMenuItem.setText("Say Yes");
}
client.sayYes();
//refresh self's userList
Hashtable userTable = client.getUsersConfig();
handleSayYes(userTable);
//refresh self's userList
}
else
{
if (yesButton.isSelected())
{
yesButton.setSelected(false);
yesButton.setBorder(new javax.swing.border.CompoundBorder());
}
else
{
yesButton.setSelected(true);
yesButton.setBorder(new javax.swing.border.CompoundBorder(null, new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)));
}
}
}
//----------------------------------------------------------------------------------------
/**
* NoAction takes action when user click on No button
*/
private void NoAction()
{
if(!stepInButton.isSelected())
{
if (yesButton.isSelected() == true)
{
yesButton.setSelected(false);
yesButton.setBorder(new javax.swing.border.CompoundBorder());
yesButton.setToolTipText("Say Yes");
sayYesMenuItem.setText("Say Yes");
}
if (noButton.isSelected())
{
noButton.setBorder(new javax.swing.border.CompoundBorder(null, new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)));
noButton.setToolTipText("Delete Say No");
sayNoMenuItem.setText("Delete Say No");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -