package mainFrame;
import java.awt.Desktop;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.plaf.DesktopPaneUI;
import com.hui.iFrame.BackupAndRestore;
import com.hui.iFrame.GengGaiMiMa;
import com.hui.iFrame.GuanYu;
import com.hui.iFrame.GysGuanLi;
import com.hui.iFrame.JiaGeTiaoZheng;
import com.hui.iFrame.JinHuoDan_IFrame;
import com.hui.iFrame.Jinhuo_Tuihuo_IFrame;
import com.hui.iFrame.JsrGL;
import com.hui.iFrame.KeHuGuanLi;
import com.hui.iFrame.KuCunPanDian;
import com.hui.iFrame.ShangPinChaXun;
import com.hui.iFrame.ShangPinGuanLi;
import com.hui.iFrame.XiaoShouChaXun;
import com.hui.iFrame.XiaoShouDan;
import com.hui.iFrame.XiaoShouPaiHang;
public class MenuBar extends JMenuBar {
private JMenu jinhuo_Menu = null ;
private JMenuItem jinhuoItem = null;
private JMenuItem jinhuo_tuihuoItem = null;
private JMenu xiaoshou_Menu = null;
private Map<JMenuItem, JInternalFrame> iFrames = null;
private JLabel stateLabel = null;
private int nextFrameX, nextFrameY;
private JMenu kucun_Menu = null;
private JMenu xinxi_chaxunMenu = null;
private JMenu jiben_ziliaoMenu = null;
private JMenu xitong_weihuMenu = null;
private JMenu chuang_kouMenu = null;
private JMenu bang_zhuMenu = null;
private JMenuItem guanyu_Item = null;
private JMenuItem bugItem = null;
private JMenuItem fangwen_wangzhanItem = null;
private JMenuItem xiaoshou_danItem = null;
private JMenuItem xiaoshou_tuihuoItem = null;
private JMenuItem kucun_pandianItem = null;
private JMenuItem jiage_tiaozhengItem = null;
private JMenuItem xiaoshou_chaxunItem = null;
private JMenuItem shangpin_chaxunItem = null;
private JMenuItem xiaoshou_paihangItem = null;
private JMenuItem shangpin_guanliItem = null;
private JMenuItem kehu_guanliItem = null;
private JMenuItem gys_guanliItem = null;
private JMenuItem jsr_guanliItem = null;
private JMenuItem mima_xiugaiItem = null;
private JMenuItem shuju_beifenItem = null;
private JMenuItem exitItem = null;
private JMenuItem pingpuItem = null ;
private JMenuItem closeAllItem = null ;
private JMenuItem allIconItem = null ;
private JMenuItem allResumeItem = null ;
private JDesktopPane desktopPanel = null;
public MenuBar(JDesktopPane desktopPanel , JLabel stateLabel){
super();
iFrames = new HashMap<JMenuItem,JInternalFrame>();
this.stateLabel = stateLabel ;
this.desktopPanel = desktopPanel ;
initialize();
}
private void initialize() {
this.setSize(600, 25);
this.add(getJinhuoMenu());
add(getXiaoshou_Menu());
add(getKucun_Menu());
add(getXinxi_chaxunMenu());
add(getJiben_ziliaoMenu());
add(getXitong_weihuMenu());
add(getChuang_kouMenu());
add(getBang_zhuMenu());
}
private JMenu getChuang_kouMenu() {
if(chuang_kouMenu == null ){
chuang_kouMenu = new JMenu("窗口");
chuang_kouMenu.setMnemonic(KeyEvent.VK_W);
chuang_kouMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
chuang_kouMenu.removeAll();
chuang_kouMenu.add(getPingpuItem());
chuang_kouMenu.add(getClassAllItem());
chuang_kouMenu.add(getAllIconItem());
chuang_kouMenu.add(getAllResumeItem());
chuang_kouMenu.addSeparator();
int count = 0 ;
JInternalFrame[] frames = desktopPanel.getAllFrames();
for(JInternalFrame frame : frames){
String frameTitle = frame.getTitle();
JMenuItem item =new JMenuItem();
item.setText(count+"."+frameTitle);
item.setIcon(frame.getFrameIcon());
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(true);
try {
frame.setSelected(true);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
}
});
chuang_kouMenu.add(item);
count++ ;
}
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
}
return chuang_kouMenu;
}
protected JMenuItem getAllResumeItem() {
if(allResumeItem == null){
allResumeItem = new JMenuItem("全部恢复");
allResumeItem.setIcon(new ImageIcon(this.getClass().getResource(
"/res/icon/quanbu_huanyuan.png")));
allResumeItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JInternalFrame[] frames = desktopPanel.getAllFrames();
for(JInternalFrame frame : frames ){
try {
frame.setIcon(false);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
}
}
});
}
return allResumeItem;
}
protected JMenuItem getAllIconItem() {
if(allIconItem == null){
allIconItem = new JMenuItem("图标化");
allIconItem.setIcon(new ImageIcon(getClass().getResource(
"/res/icon/quanbu_zuixiaohua.png")));
allIconItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JInternalFrame[] frames = desktopPanel.getAllFrames();
for(JInternalFrame frame : frames ){
//desktopPanel.getDesktopManager().iconifyFrame(frame);
try {
frame.setIcon(true);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
}
}
});
}
return allIconItem;
}
protected JMenuItem getClassAllItem() {
if(closeAllItem == null){
closeAllItem = new JMenuItem("全部关闭");
closeAllItem.setIcon(new ImageIcon(getClass().getResource(
"/res/icon/quanbu_guanbi.png")));
closeAllItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JInternalFrame[] allFrames = desktopPanel.getAllFrames();
for(JInternalFrame frame : allFrames){
frame.doDefaultCloseAction();
}
}
});
}
return closeAllItem;
}
protected JMenuItem getPingpuItem() {
if(pingpuItem == null){
pingpuItem = new JMenuItem("平铺");
pingpuItem.setIcon(new ImageIcon(getClass().getResource(
"/res/icon/chuangkou_pingpu.png")));
pingpuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JInternalFrame[] allFrames = desktopPanel.getAllFrames();
int x = 0 ;
int y = 0 ;
for(JInternalFrame frame : allFrames){
frame.setLocation(x, y);
try {
frame.setSelected(true);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
int frameH = frame.getPreferredSize().height ;
int panelH = frame.getContentPane().getHeight();
int fSpace = frameH - panelH ;
x += fSpace ;
y += fSpace ;
if(x + getWidth()/2 > desktopPanel.getWidth())
x = 0 ;
if(y + getHeight()/2 > desktopPanel.getHeight())
y = 0 ;
}
}
});
}
return pingpuItem;
}
public JMenu getBang_zhuMenu() {
if (bang_zhuMenu == null) {
bang_zhuMenu = new JMenu();
bang_zhuMenu.setText("帮助(H)");
bang_zhuMenu.setMnemonic(KeyEvent.VK_H);
bang_zhuMenu.add(getGuanyu_Item());
bang_zhuMenu.