|
|
|
@ -3,11 +3,24 @@ package com.fr.design.gui.imenu;
|
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.Action; |
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
import javax.swing.JMenu; |
|
|
|
|
import javax.swing.JMenuItem; |
|
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
|
import javax.swing.MenuElement; |
|
|
|
|
import javax.swing.border.Border; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
import java.awt.Insets; |
|
|
|
|
import java.awt.RenderingHints; |
|
|
|
|
import java.awt.Shape; |
|
|
|
|
import java.awt.geom.RoundRectangle2D; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author null |
|
|
|
|
*/ |
|
|
|
|
public class UIMenu extends JMenu { |
|
|
|
|
private static final float REC = 8f; |
|
|
|
|
private JPopupMenu popupMenu; |
|
|
|
@ -27,6 +40,7 @@ public class UIMenu extends JMenu {
|
|
|
|
|
return " " + super.getText(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public JPopupMenu getPopupMenu() { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
popupMenu.setOpaque(false); |
|
|
|
@ -38,7 +52,7 @@ public class UIMenu extends JMenu {
|
|
|
|
|
int rec = (int) REC; |
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
|
|
g2d.setColor(UIConstants.UIPOPUPMENU_LINE_COLOR); |
|
|
|
|
g2d.drawRoundRect(x, y, width - 1, height - 1,rec, rec); |
|
|
|
|
g2d.drawRoundRect(x, y, width - 1, height - 1, rec, rec); |
|
|
|
|
if (!(UIMenu.this.getParent() instanceof JPopupMenu)) { |
|
|
|
|
g.setColor(UIConstants.NORMAL_BACKGROUND); |
|
|
|
|
g.drawLine(1, 0, UIMenu.this.getWidth() - 2, 0); |
|
|
|
@ -81,7 +95,7 @@ public class UIMenu extends JMenu {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
*画界面 |
|
|
|
|
* 画界面 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void updateUI() { |
|
|
|
@ -90,8 +104,10 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 判断popupmeu是否隐藏 |
|
|
|
|
* |
|
|
|
|
* @return 如果隐藏 返回true |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean isPopupMenuVisible() { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
return popupMenu.isVisible(); |
|
|
|
@ -100,9 +116,11 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置popupmenu位置 |
|
|
|
|
* @param x |
|
|
|
|
* @param y |
|
|
|
|
* |
|
|
|
|
* @param x x |
|
|
|
|
* @param y y |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void setMenuLocation(int x, int y) { |
|
|
|
|
super.setMenuLocation(x, y); |
|
|
|
|
if (popupMenu != null) { |
|
|
|
@ -112,9 +130,11 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 向popupmenu添加 JMenuItem |
|
|
|
|
* |
|
|
|
|
* @param menuItem 菜单项 |
|
|
|
|
* @return 菜单项 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public JMenuItem add(JMenuItem menuItem) { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
return popupMenu.add(menuItem); |
|
|
|
@ -122,9 +142,11 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加组件 |
|
|
|
|
* |
|
|
|
|
* @param c 组件 |
|
|
|
|
* @return 组件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Component add(Component c) { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
popupMenu.add(c); |
|
|
|
@ -133,10 +155,12 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 向指定位置添加组件 |
|
|
|
|
* |
|
|
|
|
* @param c 组件 |
|
|
|
|
* @param index 位置 |
|
|
|
|
* @return 组件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Component add(Component c, int index) { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
popupMenu.add(c, index); |
|
|
|
@ -147,6 +171,7 @@ public class UIMenu extends JMenu {
|
|
|
|
|
/** |
|
|
|
|
* 添加分隔符 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void addSeparator() { |
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
popupMenu.addSeparator(); |
|
|
|
@ -154,9 +179,11 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加menuitem到指定位置 |
|
|
|
|
* |
|
|
|
|
* @param s 字符 |
|
|
|
|
* @param pos 位置 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void insert(String s, int pos) { |
|
|
|
|
if (pos < 0) { |
|
|
|
|
throw new IllegalArgumentException("index less than zero."); |
|
|
|
@ -168,10 +195,12 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加么会特么到指定位置 |
|
|
|
|
* |
|
|
|
|
* @param mi 菜单项 |
|
|
|
|
* @param pos 位置 |
|
|
|
|
* @return 菜单项 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public JMenuItem insert(JMenuItem mi, int pos) { |
|
|
|
|
if (pos < 0) { |
|
|
|
|
throw new IllegalArgumentException("index less than zero."); |
|
|
|
@ -183,15 +212,16 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加到指定位置 |
|
|
|
|
* |
|
|
|
|
* @param a 事件 |
|
|
|
|
* @param pos 位置 |
|
|
|
|
* @return 菜单项 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public JMenuItem insert(Action a, int pos) { |
|
|
|
|
if (pos < 0) { |
|
|
|
|
throw new IllegalArgumentException("index less than zero."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ensurePopupMenuCreated(); |
|
|
|
|
JMenuItem mi = new JMenuItem(a); |
|
|
|
|
mi.setHorizontalTextPosition(JButton.TRAILING); |
|
|
|
@ -202,8 +232,10 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加分隔符到指定位置 |
|
|
|
|
* |
|
|
|
|
* @param index 指定位置 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void insertSeparator(int index) { |
|
|
|
|
if (index < 0) { |
|
|
|
|
throw new IllegalArgumentException("index less than zero."); |
|
|
|
@ -216,8 +248,10 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移除 |
|
|
|
|
* |
|
|
|
|
* @param item 菜单项 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void remove(JMenuItem item) { |
|
|
|
|
if (popupMenu != null) { |
|
|
|
|
popupMenu.remove(item); |
|
|
|
@ -226,8 +260,10 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移除指定位置菜单项 |
|
|
|
|
* |
|
|
|
|
* @param pos 指定位置 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void remove(int pos) { |
|
|
|
|
if (pos < 0) { |
|
|
|
|
throw new IllegalArgumentException("index less than zero."); |
|
|
|
@ -242,8 +278,10 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 移除组件 |
|
|
|
|
* |
|
|
|
|
* @param c 组件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void remove(Component c) { |
|
|
|
|
if (popupMenu != null) { |
|
|
|
|
popupMenu.remove(c); |
|
|
|
@ -253,6 +291,7 @@ public class UIMenu extends JMenu {
|
|
|
|
|
/** |
|
|
|
|
* 移除所有 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void removeAll() { |
|
|
|
|
if (popupMenu != null) { |
|
|
|
|
popupMenu.removeAll(); |
|
|
|
@ -261,27 +300,44 @@ public class UIMenu extends JMenu {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 组件总数 |
|
|
|
|
* |
|
|
|
|
* @return 组件总数 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int getMenuComponentCount() { |
|
|
|
|
return (popupMenu == null) ? 0 : popupMenu.getComponentCount(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 指定位置组件 |
|
|
|
|
* |
|
|
|
|
* @param n 指定位置 |
|
|
|
|
* @return 组件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Component getMenuComponent(int n) { |
|
|
|
|
return (popupMenu == null) ? null : popupMenu.getComponent(n); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 所有组件 |
|
|
|
|
* |
|
|
|
|
* @return 所有组件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Component[] getMenuComponents() { |
|
|
|
|
return (popupMenu == null) ? new Component[0] : popupMenu.getComponents(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public MenuElement[] getSubElements() { |
|
|
|
|
if (popupMenu == null) { |
|
|
|
|
return new MenuElement[0]; |
|
|
|
|
} else { |
|
|
|
|
MenuElement[] result = new MenuElement[1]; |
|
|
|
|
result[0] = popupMenu; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |