📄 sy02000a.java
字号:
package jm.form.gui.swing.game.sy.sy02;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import jm.entity.command.SystemCommandKeys;
import jm.form.gui.swing.game.sc.sc00.MailFrame;
import jm.form.gui.swing.game.sy.command.SYCommandKeys;
import jm.form.gui.swing.game.sy.sy0z.SY0Z0100;
import jm.form.gui.swing.game.util.UserInfo;
import jm.framework.gui.Chat;
import jm.framework.gui.PanelCtrlHandler;
import jm.framework.gui.module.JMList;
import jm.framework.gui.module.JMListModel;
import jm.framework.gui.module.JMScrollPane;
import jm.util.JMVector;
/**
* <p>Title: JM 整合Swing控件,使用配置信息</p>
* <p>聊天窗口 JPanel</p>
* <p>Copyright: Copyright (c) 2004-2006</p>
*
* <p>Company: 1SHome</p>
*
* <p>@author Spook</p>
*
* @since 1.3
* @see JDK 1.5.0.6
*/
public class SY02000A extends JPanel implements SystemCommandKeys, PanelCtrlHandler , Chat{
public static final String TYPE = "CHAT";
//////////////////////////////////////
private int SplitDividerSize = 6;
////////////////////////////////////////////////////////////////////
private BorderLayout borderLayout = new BorderLayout();
private JSplitPane FormSplitPane = new JSplitPane();
private JSplitPane TopMessageSplitPane = new JSplitPane();
private JPanel ButtomCommandPanel = new JPanel();
private JTextArea SendTextArea = new JTextArea();
private GridLayout gridLayout = new GridLayout();
private JButton SendButton = new JButton();
private JTextArea MessageListTextArea = new JTextArea();
private JMList PeopleList = new JMList();
private JSplitPane CommandSplitPane = new JSplitPane();
private JMScrollPane PeopleListScrollPane = new JMScrollPane();
private JMScrollPane LeftMessageListScrollPane = new JMScrollPane();
private JMScrollPane SendScrollPane = new JMScrollPane();
private SY02000B RightMenu = new SY02000B(this);
private JMenuItem InviteOther_ = new JMenuItem(SYCommandKeys.TEXT_INVITE_OTHER);
private JPanel RightPeopleCommandPanel = new JPanel();
private BorderLayout borderLayout1 = new BorderLayout();
private JPanel RightButtomCommandPanel = new JPanel();
private SY02000C SendFilePanel = null;
private SY02000D SendSoundPanel = null;
private GridLayout gridLayout1 = new GridLayout();
public SY02000A (UserInfo userInfo) {
try {
jbInit();
addPeople(userInfo);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit () throws Exception {
this.setLayout(borderLayout);
FormSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
SendTextArea.setText("发送信息");
SendTextArea.addKeyListener(new KeyAdapter() {
public void keyPressed (KeyEvent e) {
if ((e.getKeyCode() == 10)
&& (e.isControlDown()))
doSendMessage(null);
}
});
ButtomCommandPanel.setLayout(gridLayout);
SendButton.setText("发送");
SendButton.setContentAreaFilled(false);
SendButton.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
doSendMessage(null);
}
});
MessageListTextArea.setText("获得信息");
RightPeopleCommandPanel.setLayout(borderLayout1);
RightButtomCommandPanel.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setRows(0);
ButtomCommandPanel.add(CommandSplitPane);
TopMessageSplitPane.add(LeftMessageListScrollPane, JSplitPane.LEFT);
TopMessageSplitPane.add(RightPeopleCommandPanel, JSplitPane.RIGHT);
PeopleListScrollPane.getViewport().add(PeopleList);
LeftMessageListScrollPane.getViewport().add(MessageListTextArea);
PeopleList.addMouseListener(new MouseAdapter() {
public void mouseClicked (MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3 &&
((JMListModel) PeopleList.getModel()).size() > 0) {
RightMenu.setMouseEvent(e);
if (((JMListModel) PeopleList.getModel()).size() > 1) {
//选择数量判断
if (PeopleList.getSelectedIndices().length > 1) {
RightMenu.setRightMenu(RightMenu.PART, ""); ;
} else {
int index = PeopleList.locationToIndex(e.getPoint());
PeopleList.setSelectedIndex(index);
if (index < 0)
return;
RightMenu.setRightMenu(RightMenu.ALL, ""); ;
}
} else if (((JMListModel) PeopleList.getModel()).size() > 0) {
PeopleList.setSelectedIndex(0);
RightMenu.setRightMenu(RightMenu.PART, "");
}
//邀请加入
RightMenu.add(InviteOther_);
//显示弹出菜单
RightMenu.showPopupMenu();
}
}
}
);
InviteOther_.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed (MouseEvent e) {
doViste(e);
}
});
CommandSplitPane.add(SendScrollPane, JSplitPane.LEFT);
SendScrollPane.getViewport().add(SendTextArea);
CommandSplitPane.add(SendButton, JSplitPane.RIGHT);
FormSplitPane.add(TopMessageSplitPane, JSplitPane.TOP);
FormSplitPane.add(ButtomCommandPanel, JSplitPane.BOTTOM);
//上部信息
TopMessageSplitPane.setContinuousLayout(true);
TopMessageSplitPane.setOneTouchExpandable(true);
TopMessageSplitPane.setDividerLocation(300);
TopMessageSplitPane.setDividerSize(SplitDividerSize);
//下部信息
CommandSplitPane.setContinuousLayout(true);
CommandSplitPane.setOneTouchExpandable(true);
CommandSplitPane.setDividerLocation(300);
CommandSplitPane.setDividerSize(SplitDividerSize);
//背景
FormSplitPane.setContinuousLayout(true);
FormSplitPane.setOneTouchExpandable(true);
FormSplitPane.setDividerLocation(245);
FormSplitPane.setDividerSize(SplitDividerSize);
this.add(FormSplitPane, java.awt.BorderLayout.CENTER);
RightPeopleCommandPanel.add(PeopleListScrollPane, java.awt.BorderLayout.CENTER);
RightPeopleCommandPanel.add(RightButtomCommandPanel, java.awt.BorderLayout.SOUTH);
}
/**
* 邀请加入
* @param e MouseEvent
*/
private void doViste (MouseEvent e) {
try {
SY0Z0100 onlinePeopleDialog = new SY0Z0100(SY020000.getInstance(false), "邀请加入", true);
onlinePeopleDialog.setHavePeople(UserInfos_);
onlinePeopleDialog.load();
onlinePeopleDialog.setLocationRelativeTo(SY020000.getInstance(false));
onlinePeopleDialog.setVisible(true);
//多人聊天
JMVector<UserInfo> returnDate = onlinePeopleDialog.getReturnDate();
for (UserInfo userInfo : returnDate) {
addPeople(userInfo);
}
} catch (Exception ex) {
}
}
////////////////////////////////////////////////////////////////////////////
JMVector<UserInfo> UserInfos_ = new JMVector<UserInfo>();
public JMVector<UserInfo> getUserInfos () {
return UserInfos_;
}
public void addPeople (UserInfo userInfo) {
((JMListModel) PeopleList.getModel()).addElement(userInfo.getLName());
UserInfos_.add(userInfo);;
}
public void removePeople (int index) {
((JMListModel) PeopleList.getModel()).removeElementAt(index);
UserInfos_.remove(index);
}
public void removePeople (String peopleName) {
((JMListModel) PeopleList.getModel()).removeElement(peopleName);
for (UserInfo userInfo : UserInfos_) {
if(peopleName.equals(userInfo.getLName())){
UserInfos_.remove(userInfo);
}
}
}
public void removePeople () {
((JMListModel) PeopleList.getModel()).removeAllElements();
UserInfos_.clear();
}
/**
* 关闭
* @param type String
*/
public void doClose (String type) {
if (SY02000C.TYPE.equals(type)) {
RightButtomCommandPanel.remove(SendFilePanel);
SendFilePanel = null;
setRightButtomCommandPanelSize(false);
} else if (SY02000D.TYPE.equals(type)) {
RightButtomCommandPanel.remove(SendSoundPanel);
SendSoundPanel = null;
setRightButtomCommandPanelSize(false);
} else if (SY02000A.TYPE.equals(type)) {
this.setVisible(false);
}
}
private int RightButtomCommandPanelSize = 0;
private void setRightButtomCommandPanelSize (boolean add){
if(add){
RightButtomCommandPanelSize++;
}else{
RightButtomCommandPanelSize--;
}
setRightButtomCommandPanelSize ();
}
private void setRightButtomCommandPanelSize () {
switch (RightButtomCommandPanelSize) {
case 1:
RightButtomCommandPanel.setPreferredSize(new Dimension(15, 15));
break;
case 2:
RightButtomCommandPanel.setPreferredSize(new Dimension(30, 30));
break;
default:
RightButtomCommandPanel.setPreferredSize(new Dimension(0, 0));
break;
}
}
/**
* 发送文件
* @param e MouseEvent
*/
public void doSendFile (MouseEvent e) {
if(SendFilePanel==null){
SendFilePanel = new SY02000C(this);
RightButtomCommandPanel.add(SendFilePanel, null);
setRightButtomCommandPanelSize(true);
}
}
/**
* 语音电话
* @param e MouseEvent
*/
public void doSendSound (MouseEvent e) {
if(SendSoundPanel==null){
SendSoundPanel = new SY02000D(this);
RightButtomCommandPanel.add(SendSoundPanel, null);
setRightButtomCommandPanelSize(true);
}
}
public boolean getClose () {
return false;
}
/**
* 发送信息
* @param e MouseEvent
*/
public void doSendMessage (MouseEvent e) {
if(e ==null){
// SendMessage send = new SendMessage();
MessageListTextArea.setText(MessageListTextArea.getText() + SendTextArea.getText());
}else{
SY020000.getInstance(true).doSendMessage(UserInfos_.get(PeopleList.getSelectedIndex()));
}
}
/**
* 发送邮件
* @param e MouseEvent
*/
public void doSendMail (MouseEvent e) {
MailFrame.getInstance(true).doSendMail(UserInfos_);
}
public Component getPopupMenuParent () {
return PeopleList;
}
/**
* 弹出菜单在其空间中显示的组件
* @param e MouseEvent
*/
public Component getCtrlComponent () {
return this;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -