|
|
@ -13,7 +13,10 @@ import javax.swing.*; |
|
|
|
import javax.swing.event.MenuEvent; |
|
|
|
import javax.swing.event.MenuEvent; |
|
|
|
import javax.swing.event.MenuListener; |
|
|
|
import javax.swing.event.MenuListener; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.event.*; |
|
|
|
import java.awt.event.ContainerListener; |
|
|
|
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
@ -22,7 +25,10 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MenuDef extends ShortCut { |
|
|
|
public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int MENU_DEFAULTWDITH = 156; |
|
|
|
protected String name; |
|
|
|
protected String name; |
|
|
|
|
|
|
|
//右侧属性表弹出框重绘
|
|
|
|
|
|
|
|
protected Boolean rePaint = false; |
|
|
|
protected char mnemonic; |
|
|
|
protected char mnemonic; |
|
|
|
protected String iconPath; |
|
|
|
protected String iconPath; |
|
|
|
protected String tooltip; |
|
|
|
protected String tooltip; |
|
|
@ -44,6 +50,10 @@ public class MenuDef extends ShortCut { |
|
|
|
this.setName(name); |
|
|
|
this.setName(name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MenuDef(Boolean rePaint) { |
|
|
|
|
|
|
|
this.setRePaint(rePaint); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public MenuDef(String name, char mnemonic) { |
|
|
|
public MenuDef(String name, char mnemonic) { |
|
|
|
this.setName(name); |
|
|
|
this.setName(name); |
|
|
|
this.setMnemonic(mnemonic); |
|
|
|
this.setMnemonic(mnemonic); |
|
|
@ -57,6 +67,14 @@ public class MenuDef extends ShortCut { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getRePaint() { |
|
|
|
|
|
|
|
return rePaint; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setRePaint(boolean rePaint) { |
|
|
|
|
|
|
|
this.rePaint = rePaint; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public char getMnemonic() { |
|
|
|
public char getMnemonic() { |
|
|
|
return mnemonic; |
|
|
|
return mnemonic; |
|
|
|
} |
|
|
|
} |
|
|
@ -99,6 +117,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 插入菜单项 |
|
|
|
* 插入菜单项 |
|
|
|
|
|
|
|
* |
|
|
|
* @param index 插入的位置 |
|
|
|
* @param index 插入的位置 |
|
|
|
* @param shortCut 菜单信息 |
|
|
|
* @param shortCut 菜单信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -110,6 +129,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 用可变参数,方便添加数组 |
|
|
|
* 用可变参数,方便添加数组 |
|
|
|
|
|
|
|
* |
|
|
|
* @param shortcut 参数 存储菜单项信息 |
|
|
|
* @param shortcut 参数 存储菜单项信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addShortCut(ShortCut... shortcut) { |
|
|
|
public void addShortCut(ShortCut... shortcut) { |
|
|
@ -132,6 +152,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 生成UIButton |
|
|
|
* 生成UIButton |
|
|
|
|
|
|
|
* |
|
|
|
* @return 菜单按钮 |
|
|
|
* @return 菜单按钮 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UIButton createUIButton() { |
|
|
|
public UIButton createUIButton() { |
|
|
@ -157,6 +178,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 生成JMenu |
|
|
|
* 生成JMenu |
|
|
|
|
|
|
|
* |
|
|
|
* @return 菜单 |
|
|
|
* @return 菜单 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UIMenu createJMenu() { |
|
|
|
public UIMenu createJMenu() { |
|
|
@ -183,8 +205,10 @@ public class MenuDef extends ShortCut { |
|
|
|
protected ContainerListener getContainerListener() { |
|
|
|
protected ContainerListener getContainerListener() { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 生成 JPopupMenu |
|
|
|
* 生成 JPopupMenu |
|
|
|
|
|
|
|
* |
|
|
|
* @return 弹出菜单 |
|
|
|
* @return 弹出菜单 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public JPopupMenu createJPopupMenu() { |
|
|
|
public JPopupMenu createJPopupMenu() { |
|
|
@ -195,6 +219,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置是否可用 |
|
|
|
* 设置是否可用 |
|
|
|
|
|
|
|
* |
|
|
|
* @param b 布尔型 |
|
|
|
* @param b 布尔型 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -212,6 +237,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 按钮状态 |
|
|
|
* 按钮状态 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 状态 |
|
|
|
* @return 状态 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -235,6 +261,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 更新菜单 |
|
|
|
* 更新菜单 |
|
|
|
|
|
|
|
* |
|
|
|
* @param popupMenu 菜单 |
|
|
|
* @param popupMenu 菜单 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void updatePopupMenu(JPopupMenu popupMenu) { |
|
|
|
protected void updatePopupMenu(JPopupMenu popupMenu) { |
|
|
@ -268,8 +295,44 @@ public class MenuDef extends ShortCut { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 更新右侧属性面板菜单 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param popupMenu 菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void updateEastPopupMenu(JPopupMenu popupMenu) { |
|
|
|
|
|
|
|
removeComponent(popupMenu); |
|
|
|
|
|
|
|
this.popupMenu = popupMenu; |
|
|
|
|
|
|
|
// 一开始是不能插入分隔符的
|
|
|
|
|
|
|
|
boolean nec_seperator = false; |
|
|
|
|
|
|
|
boolean isFirstItem = true; |
|
|
|
|
|
|
|
int actionCount = this.getShortCutCount(); |
|
|
|
|
|
|
|
for (int i = 0; i < actionCount; i++) { |
|
|
|
|
|
|
|
ShortCut shortcut = this.getShortCut(i); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果shortcut是SeparatorDef,先不加,先标记一下nec_seperator为true,等下一个shortcut需要加到PopupMenu时再加
|
|
|
|
|
|
|
|
if (shortcut instanceof SeparatorDef) { |
|
|
|
|
|
|
|
nec_seperator = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (nec_seperator) { |
|
|
|
|
|
|
|
if (!isFirstItem) { |
|
|
|
|
|
|
|
SeparatorDef.DEFAULT.intoJPopupMenu(popupMenu); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
nec_seperator = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
shortcut.intoJPopupMenu(popupMenu); |
|
|
|
|
|
|
|
isFirstItem = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (createdJMenu != null && createdJMenu.getPopupMenu() != null) { |
|
|
|
|
|
|
|
setEnabled(createdJMenu.getPopupMenu().getComponentCount() > 0 && enabled); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 删除所有组件 除了滚动条 |
|
|
|
* 删除所有组件 除了滚动条 |
|
|
|
|
|
|
|
* |
|
|
|
* @param popupMenu 菜单 |
|
|
|
* @param popupMenu 菜单 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void removeComponent(JPopupMenu popupMenu) { |
|
|
|
public void removeComponent(JPopupMenu popupMenu) { |
|
|
@ -289,6 +352,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 添加菜单项 |
|
|
|
* 添加菜单项 |
|
|
|
|
|
|
|
* |
|
|
|
* @param menu 菜单 |
|
|
|
* @param menu 菜单 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -300,6 +364,7 @@ public class MenuDef extends ShortCut { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 添加 |
|
|
|
* 添加 |
|
|
|
|
|
|
|
* |
|
|
|
* @param toolBar 菜单条 |
|
|
|
* @param toolBar 菜单条 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -336,13 +401,19 @@ public class MenuDef extends ShortCut { |
|
|
|
if (!button.isEnabled()) { |
|
|
|
if (!button.isEnabled()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (rePaint) { |
|
|
|
UIPopupMenu popupMenu = new UIPopupMenu(); |
|
|
|
popupMenu = new UIPopupMenu(rePaint); |
|
|
|
|
|
|
|
popupMenu.setInvoker(button); |
|
|
|
|
|
|
|
MenuDef.this.updateEastPopupMenu(popupMenu); |
|
|
|
|
|
|
|
popupMenu.setPopupSize(new Dimension(MENU_DEFAULTWDITH, popupMenu.getPreferredSize().height)); |
|
|
|
|
|
|
|
GUICoreUtils.showPopupMenu(popupMenu, button, 0, button.getSize().height); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
popupMenu = new UIPopupMenu(); |
|
|
|
popupMenu.setInvoker(button); |
|
|
|
popupMenu.setInvoker(button); |
|
|
|
MenuDef.this.updatePopupMenu(popupMenu); |
|
|
|
MenuDef.this.updatePopupMenu(popupMenu); |
|
|
|
|
|
|
|
|
|
|
|
GUICoreUtils.showPopupMenu(popupMenu, button, 0, button.getSize().height); |
|
|
|
GUICoreUtils.showPopupMenu(popupMenu, button, 0, button.getSize().height); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|