package com.lzw;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Scanner;
import java.util.Stack;
import java.util.prefs.Preferences;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.InternationalFormatter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import com.lzw.dao.Dao;
import com.lzw.frame.TelFrame;
import com.lzw.system.Resource;
import com.lzw.userList.ChatTree;
import com.lzw.userList.User;
public class EQ extends Dialog {
private JTextField ipEndTField;
private JTextField ipStartTField;
private JTextField userNameTField;
private JPasswordField passwordTField;
private JTextField placardPathTField;
private JTextField updatePathTField;
private JTextField pubPathTField;
public static EQ frame = null;
private ChatTree chatTree;
private JPopupMenu popupMenu;
private JTabbedPane tabbedPane;
private JToggleButton searchUserButton;
private JProgressBar progressBar;
private JList faceList;
private JButton selectInterfaceOKButton;
private DatagramSocket ss;
private final JLabel stateLabel;
private static String user_dir;
private static File localFile;
private static File netFile;
private String netFilePath;
private JButton messageAlertButton;
private Stack<String> messageStack;//公告信息栈
private ImageIcon messageAlertIcon;
private ImageIcon messageAlertNullIcon;
private Rectangle location;
public static TrayIcon trayicon;
private Dao dao;
public final static Preferences preferences = Preferences.systemRoot();;
private JButton userInfoButton;
public static void main(String args[]) {
try {
String laf = preferences.get("lookAndFeel", "java默认");
if (laf.indexOf("当前系统")>-1)
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EQ frame = new EQ();
frame.setVisible(true);
frame.SystemTrayInitial();// 初始化系统栏
frame.server();
frame.checkPlacard();
} catch (Exception e) {
e.printStackTrace();
}
}
public EQ() {
super(new Frame());//初始化窗体对象
frame = this;//初始化dao对象
dao = Dao.getDao();//初始化窗体位置对象//对数据库的操作
location = dao.getLocation();
setTitle("小峰通讯");
setBounds(location);
progressBar = new JProgressBar();//初始化搜索用户进度条
progressBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
tabbedPane = new JTabbedPane(); //初始化选项卡
popupMenu = new JPopupMenu();//初始化弹出菜单
chatTree = new ChatTree(this);
user_dir = System.getProperty("user.dir"); // 程序执行路径用于系统更新
localFile = new File(user_dir + File.separator + "EQ.jar");// 本地EQ文件
stateLabel = new JLabel(); // 状态栏标签
addWindowListener(new FrameWindowListener());// 添加窗体监视器
addComponentListener(new ComponentAdapter() { //面板监听器
public void componentResized(final ComponentEvent e) {
saveLocation();
}
public void componentMoved(final ComponentEvent e) {
saveLocation();
}
});
try {// 启动通讯服务端口
ss = new DatagramSocket(1111);
} catch (SocketException e2) {
if (e2.getMessage().startsWith("Address already in use"))
showMessageDialog("服务端口被占用,或者本软件已经运行。");
System.exit(0);
}
{ // 初始化公共信息按钮
messageAlertIcon = new ImageIcon(EQ.class
.getResource("/image/messageAlert.gif")); //公告信息喇叭状的小图标
messageAlertNullIcon = new ImageIcon(EQ.class
.getResource("/image/messageAlertNull20.gif")); //公告信息空白图标
messageStack = new Stack<String>();//公告信息栈
messageAlertButton = new JButton();
messageAlertButton.setHorizontalAlignment(SwingConstants.RIGHT);
messageAlertButton.setContentAreaFilled(false);
final JPanel BannerPanel = new JPanel();
BannerPanel.setLayout(new BorderLayout());
add(BannerPanel, BorderLayout.NORTH);
userInfoButton = new JButton();
BannerPanel.add(userInfoButton, BorderLayout.WEST);
userInfoButton.setMargin(new Insets(0, 0, 0, 10));
initUserInfoButton();// 初始化本地用户头像按钮
BannerPanel.add(messageAlertButton, BorderLayout.CENTER);
messageAlertButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if (!messageStack.empty()) {
showMessageDialog(messageStack.pop());
}
}
});
messageAlertButton.setIcon(messageAlertIcon);
showMessageBar();
}
add(tabbedPane, BorderLayout.CENTER);
tabbedPane.setTabPlacement(SwingConstants.LEFT);
ImageIcon userTicon = new ImageIcon(EQ.class
.getResource("/image/tabIcon/tabLeft.PNG")); //UserList pic
tabbedPane.addTab(null, userTicon, createUserList(), "用户列表");
ImageIcon sysOTicon = new ImageIcon(EQ.class
.getResource("/image/tabIcon/tabLeft2.PNG")); //SysTool pic
tabbedPane.addTab(null, sysOTicon, createSysToolPanel(), "系统操作");
ImageIcon sysSTicon = new ImageIcon(EQ.class
.getResource("/image/tabIcon/tabLeft3.png")); //SysSet pic
tabbedPane.addTab(null, sysSTicon, createSysSetPanel(), "系统设置");
setAlwaysOnTop(true);
}
private JScrollPane createSysSetPanel() {
final JPanel sysSetPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane(sysSetPanel);
sysSetPanel.setLayout(new BoxLayout(sysSetPanel, BoxLayout.Y_AXIS));
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
final JPanel sysPathPanel = new JPanel();
sysPathPanel.setMaximumSize(new Dimension(600, 200));
sysPathPanel.setBorder(new TitledBorder("系统路径"));
sysPathPanel.setLayout(new GridLayout(0, 1));
sysSetPanel.add(sysPathPanel);
sysPathPanel.add(new JLabel("程序升级路径:"));
updatePathTField = new JTextField(preferences
.get("updatePath", "请输入路径"));
sysPathPanel.add(up