www.pudn.com > mailserver.rar > AdminViewExam.java


package xiaobai.mailserver.admin;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import xiaobai.mailserver.util.DateFormate;
import xiaobai.mailserver.util.Log;
public class AdminViewExam
{

private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="-44,-222"
private JMenuBar jJMenuBar = null;
private JMenu jMenu_con = null;
private JMenu jMenu_discon = null;
private JSplitPane jSplitPane = null;
private JTree jTree = null;
private JScrollPane jScrollPane = null;
private JList jList = null;

public static Log adminLog=null;
protected JFrame getJFrame()
{
adminLog=new Log("xiaobai\\mailserver\\log\\admin.log");
adminLog.println("Admin server started on: "+DateFormate.msgDateFormat());
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"界面风格转换出现异常,将使用Swing组件默认的风格","系统提示",JOptionPane.ERROR_MESSAGE);
}

if (jFrame == null)
{
jFrame = new JFrame();
jFrame.setSize(new Dimension(727, 480));
jFrame.setPreferredSize(new Dimension(138, 75));
jFrame.setMinimumSize(new Dimension(186, 143));
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/xiaobai/mailserver/admin/images/admin.jpg")));
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setTitle("管理端工具 ");
jFrame.setContentPane(getJSplitPane());
jFrame.setVisible(true);
}
return jFrame;
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar()
{
if (jJMenuBar == null)
{
jJMenuBar = new JMenuBar();
jJMenuBar.setPreferredSize(new Dimension(0, 25));
jJMenuBar.add(getJMenu_con());
jJMenuBar.add(getJMenu_discon());
}
return jJMenuBar;
}
/**
* This method initializes jMenu_con
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu_con()
{
if (jMenu_con == null)
{
jMenu_con = new JMenu();
jMenu_con.setPreferredSize(new Dimension(35, 20));
jMenu_con.setSize(new Dimension(13, 32));
jMenu_con.setToolTipText("你好 ");
jMenu_con.setText("连接 ");
}
return jMenu_con;
}
/**
* This method initializes jMenu_discon
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu_discon()
{
if (jMenu_discon == null)
{
jMenu_discon = new JMenu();
jMenu_discon.setText("断开");
jMenu_discon.setLocation(new Point(40, 0));
}
return jMenu_discon;
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane()
{
if (jSplitPane == null)
{
jSplitPane = new JSplitPane();
jSplitPane.setOneTouchExpandable(true);
jSplitPane.setDividerSize(10);
jSplitPane.setDividerLocation(195);
jSplitPane.setEnabled(true);
jSplitPane.setResizeWeight(0.0D);
jSplitPane.setComponentOrientation(ComponentOrientation.UNKNOWN);
jSplitPane.setContinuousLayout(true);
jSplitPane.setLeftComponent(getJScrollPane());
//jSplitPane.setRightComponent(getJList());
jSplitPane.setRightComponent(getJTextPane());
jSplitPane.setPreferredSize(new Dimension(110, 20));
}
return jSplitPane;
}
/**
* This method initializes jTree
*
* @return javax.swing.JTree
*/
private JTree getJTree()
{
DefaultMutableTreeNode root=new DefaultMutableTreeNode("系统信息");
DefaultMutableTreeNode node1=new DefaultMutableTreeNode("系统设置");
DefaultMutableTreeNode node2=new DefaultMutableTreeNode("用户设置");
DefaultMutableTreeNode node3=new DefaultMutableTreeNode("系统日志");

node1.add(new DefaultMutableTreeNode("系统服务"));
node1.add(new DefaultMutableTreeNode("SMTP设置"));

node1.add(new DefaultMutableTreeNode("更改密码"));
node2.add(new DefaultMutableTreeNode("用户管理"));
node2.add(new DefaultMutableTreeNode("公共地址薄"));

node3.add(new DefaultMutableTreeNode("SMTP日志"));
node3.add(new DefaultMutableTreeNode("POP3日志"));
node3.add(new DefaultMutableTreeNode("ADMIN日志"));
node3.add(new DefaultMutableTreeNode("ERROR日志"));

root.add(node1);
root.add(node2);
root.add(node3);

if (jTree == null)
{
jTree = new JTree(root);
jTree.setBackground(Color.white);
jTree.setRootVisible(true);
jTree.setToggleClickCount(5);
jTree.setVisibleRowCount(25);
jTree.setSize(new Dimension(180, 420));
jTree.setPreferredSize(new Dimension(180, 20));
jTree.setComponentOrientation(ComponentOrientation.UNKNOWN);
jTree.setEditable(false);
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

MouseListener ml=new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
String strNodeContent=null;
int selectRow=jTree.getRowForLocation(e.getX(),e.getY());
TreePath selectPath=jTree.getPathForLocation(e.getX(),e.getY());
if(selectRow!=-1)
{
if(e.getClickCount()==1)
{
jSplitPane.setDividerLocation(195);
strNodeContent=selectPath.getLastPathComponent().toString();
//System.out.println(selectPath.getLastPathComponent().toString());

TreeNode node=(TreeNode)selectPath.getLastPathComponent();


if(strNodeContent.equals("系统信息"))
{
jSplitPane.setRightComponent(getJTextPane());

}
if(strNodeContent.equals("系统设置"))
{
jSplitPane.setRightComponent(getJList());
if(node.getChildCount()>0)
{
listModel.clear();
for(Enumeration en=node.children();en.hasMoreElements();)
{
TreeNode aNode=(TreeNode)en.nextElement();
System.out.println(aNode.toString());

listModel.addElement(aNode.toString());

}
}

}
else if(strNodeContent.equals("系统服务"))
{
SystemService systemServiceShow=new SystemService();

jSplitPane.setRightComponent(systemServiceShow.getJContentPane());

}
else if(strNodeContent.equals("SMTP设置"))
{
SystemSetting smtpShow=new SystemSetting();

jSplitPane.setRightComponent(smtpShow.getJContentPane());

}
else if(strNodeContent.equals("更改密码"))
{
ChangePassword chShow=new ChangePassword();
jSplitPane.setRightComponent(chShow.getJContentPane());
}
else if(strNodeContent.equals("用户设置"))
{

jSplitPane.setRightComponent(getJList());

if(node.getChildCount()>0)
{
listModel.clear();
for(Enumeration en=node.children();en.hasMoreElements();)
{
TreeNode aNode=(TreeNode)en.nextElement();
//System.out.println(aNode.toString());

if(aNode.toString().length()!=0 &amt;&amt; aNode.toString()!=null)
{

listModel.addElement(aNode.toString());
}
}
}


}
else if(strNodeContent.equals("用户管理"))
{
UserAdmin userAdminShow=new UserAdmin();
jSplitPane.setRightComponent(userAdminShow.getJContentPane());

}
else if(strNodeContent.equals("系统日志"))
{
jSplitPane.setRightComponent(getJList());

if(node.getChildCount()>0)
{
listModel.clear();
for(Enumeration en=node.children();en.hasMoreElements();)
{
TreeNode aNode=(TreeNode)en.nextElement();
//System.out.println(aNode.toString());

if(aNode.toString().length()!=0 &amt;&amt; aNode.toString()!=null)
{

listModel.addElement(aNode.toString());
}
}
}


}
else if(strNodeContent.equals("公共地址薄"))
{
AddressBook addressShow=new AddressBook();
jSplitPane.setRightComponent( addressShow.getJContentPane());

}
else if(strNodeContent.equals("SMTP日志"))
{
SMTPLog smtpLog=new SMTPLog();
jSplitPane.setRightComponent(smtpLog.getJContentPane());


}
else if(strNodeContent.equals("POP3日志"))
{
POP3Log pop3Log=new POP3Log();
jSplitPane.setRightComponent(pop3Log.getJContentPane());

}
else if(strNodeContent.equals("ADMIN日志"))

{
Admin adminLog=new Admin();
jSplitPane.setRightComponent(adminLog.getJContentPane());

}
else if(strNodeContent.equals("ERROR日志"))

{
ErrorLog errorLog=new ErrorLog();
jSplitPane.setRightComponent(errorLog.getJContentPane());


}

}
else
{
if(e.getClickCount()==2)
{
if(jTree.isCollapsed(selectRow))
{
jTree.expandRow(selectRow);

}
else
jTree.collapseRow(selectRow);
}
}

}
}
};
jTree.addMouseListener(ml);
}



return jTree;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane.setPreferredSize(new Dimension(85, 500));
jScrollPane.setBackground(Color.white);
jScrollPane.setViewportView(getJTree());
}
return jScrollPane;
}

/**
* This method initializes jList
*
* @return javax.swing.JList
*/
DefaultListModel listModel=new DefaultListModel();
private JTextPane jTextPane = null;
private JList getJList()
{

if (jList == null)
{
jList = new JList();

jList.setModel(listModel);
MouseListener mouseListener=new MouseAdapter(){

public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==2)
{
jSplitPane.setDividerLocation(195);
String strJListContent=jList.getSelectedValue().toString();
if(strJListContent.equals("系统服务"))
{
SystemService systemServiceShow=new SystemService();

jSplitPane.setRightComponent(systemServiceShow.getJContentPane());

}
else if(strJListContent.equals("SMTP设置"))
{
SystemSetting smtpShow=new SystemSetting();

jSplitPane.setRightComponent(smtpShow.getJContentPane());

}
else if(strJListContent.equals("更改密码"))
{
ChangePassword chShow=new ChangePassword();
jSplitPane.setRightComponent(chShow.getJContentPane());
}
else if(strJListContent.equals("用户管理"))
{
UserAdmin userAdminShow=new UserAdmin();
jSplitPane.setRightComponent(userAdminShow.getJContentPane());

}

else if(strJListContent.equals("公共地址薄"))
{
AddressBook addressShow=new AddressBook();
jSplitPane.setRightComponent( addressShow.getJContentPane());

}
else if(strJListContent.equals("SMTP日志"))
{
SMTPLog smtpLog=new SMTPLog();
jSplitPane.setRightComponent(smtpLog.getJContentPane());

}
else if(strJListContent.equals("POP3日志"))
{
POP3Log pop3Log=new POP3Log();
jSplitPane.setRightComponent(pop3Log.getJContentPane());

}
else if(strJListContent.equals("ADMIN日志"))
{
Admin adminLog=new Admin();
jSplitPane.setRightComponent(adminLog.getJContentPane());
}
else if(strJListContent.equals("ERROR日志"))
{
ErrorLog errorLog=new ErrorLog();
jSplitPane.setRightComponent(errorLog.getJContentPane());

}
}
}
};

jList.addMouseListener(mouseListener);
}
return jList;
}
/**
* This method initializes jTextPane
*
* @return javax.swing.JTextPane
*/
FileInputStream fileStream;
private JTextPane getJTextPane()
{
try
{
fileStream=new FileInputStream("xiaobai\\mailserver\\admin\\mailintro.txt");

}
catch(FileNotFoundException e)
{
//System.out.println(e.toString());
adminLog.println("read mailinto.txt is error");
}



if (jTextPane == null)
{
jTextPane = new JTextPane();
jTextPane.setText("邮件服务器简介");
jTextPane.setBackground(Color.white);
jTextPane.setEditable(false);
try
{
jTextPane.read(fileStream,null);

}
catch(IOException e)
{
adminLog.println(" read mailinto.txt is error");
}

}
return jTextPane;
}

}