📄 mainframe.java
字号:
package com.cownew.PIS.framework.client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.Timer;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import com.cownew.PIS.base.msgCenter.client.MessageListenTask;
import com.cownew.PIS.framework.client.menu.MainMenuItemInfo;
import com.cownew.PIS.framework.client.menu.MainMenuManager;
import com.cownew.PIS.ui.base.UIFactory;
import com.cownew.PIS.ui.base.UIInternalFrameContainer;
import com.cownew.ctk.common.ExceptionUtils;
public class MainFrame extends AbstractMainFrame
{
private static MainFrame instance;
//一个应用内只能有一个主窗口,所以使用单例
public static MainFrame getMainFrame()
{
if (instance == null)
{
instance = new MainFrame();
}
return instance;
}
private MainFrame()
{
super();
MessageListenTask task = new MessageListenTask();
Timer msgListenTimer = new Timer();
//msgListenTimer.schedule(task,0,1000);
}
/**
* 得到菜单项item的菜单项
* @param item
* @return
*/
private JMenu getParentMenu(MainMenuItemInfo item)
{
MainMenuManager menuMgr = MainMenuManager.getManager();
JMenuItem parentMenuItem = menuMgr.queryMenuItem(item.getParentPath());
if (!(parentMenuItem instanceof JMenu))
{
throw new RuntimeException("父菜单不是JMenu!");
}
return (JMenu) parentMenuItem;
}
protected void initMainMenu()
{
MainMenuManager menuMgr = MainMenuManager.getManager();
MainMenuItemInfo[] allMenus = menuMgr.getAllMenuItem();
for (int i = 0, n = allMenus.length; i < n; i++)
{
MainMenuItemInfo item = allMenus[i];
if (item.isRoot())
{
JMenuBar mainMenu = getMainMenuBar();
JMenu rootMenu = new JMenu();
rootMenu.setText(item.getText());
mainMenu.add(rootMenu);
// 向菜单管理注册已经建立的菜单项
menuMgr.registerMenuItem(item.getPath(), rootMenu);
} else if (!item.isLeaf())
{
JMenu menu = new JMenu();
menu.setText(item.getText());
getParentMenu(item).add(menu);
// 向菜单管理注册已经建立的菜单项
menuMgr.registerMenuItem(item.getPath(), menu);
} else if (item.isLeaf())
{
JMenuItem menu = new JMenuItem();
menu.setText(item.getText());
menu.addActionListener(new MenuItemActionListener(item
.getUiClass()));
getParentMenu(item).add(menu);
// 向菜单管理注册已经建立的菜单项
menuMgr.registerMenuItem(item.getPath(), menu);
}
}
}
class MenuItemActionListener implements ActionListener
{
private String uiClass;
public MenuItemActionListener(String uiClass)
{
super();
this.uiClass = uiClass;
}
public void actionPerformed(ActionEvent e)
{
JInternalFrame cont = getInternalFrame(uiClass);
try
{
cont.setSelected(true);
cont.setMaximum(true);
} catch (PropertyVetoException pve)
{
throw ExceptionUtils.toRuntimeException(pve);
}
cont.setVisible(true);
cont.show();
}
//根据uiClass得到JInternalFrame容器
private JInternalFrame getInternalFrame(String uiClass)
{
JInternalFrame frame = null;
// 所有UI只能有一个实例,也就是一个UI只能打开一个窗口
JInternalFrame[] frames = getDesktopPane().getAllFrames();
for (int i = 0, n = frames.length; i < n; i++)
{
UIInternalFrameContainer f = (UIInternalFrameContainer) frames[i];
//如果有类名相同的就说明已经打开过了,返回这个已存在的实例
if (f.getUIPanel().getClass().getName().equals(uiClass))
{
frame = f;
break;
}
}
if (frame == null)
{
frame = UIFactory.getInternalFrameContainer(uiClass);
//加入DesktopPane以方便管理
MainFrame.this.getDesktopPane().add(frame);
}
return frame;
}
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -