diff --git a/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java index 8f20a15773..80ce315255 100644 --- a/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java +++ b/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java @@ -36,7 +36,7 @@ public class ChartFloatAction extends ElementCaseAction { public ChartFloatAction(ElementCasePane t) { super(t); this.setMenuKeySet(FLOAT_INSERT_CHART); - this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/chart.png")); } diff --git a/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java index de7cbe582c..82536e887a 100644 --- a/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java +++ b/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java @@ -27,7 +27,7 @@ public class FormulaFloatAction extends AbstractShapeAction { public FormulaFloatAction(ElementCasePane t) { super(t); this.setMenuKeySet(FLOAT_INSERT_FORMULA); - this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); } diff --git a/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java index 8814936cde..78b408347f 100644 --- a/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java +++ b/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java @@ -34,7 +34,7 @@ public class ImageFloatAction extends ElementCaseAction { public ImageFloatAction(ElementCasePane t) { super(t); this.setMenuKeySet(FLOAT_INSERT_IMAGE); - this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/image.png")); } diff --git a/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java index 3f0be1c56d..9548db51c3 100644 --- a/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java +++ b/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java @@ -26,7 +26,7 @@ public class TextBoxFloatAction extends AbstractShapeAction { public TextBoxFloatAction(ElementCasePane t) { super(t); this.setMenuKeySet(FLOAT_INSERT_TEXT); - this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/text.png")); } diff --git a/designer/src/com/fr/design/mainframe/ReportFloatPane.java b/designer/src/com/fr/design/mainframe/ReportFloatPane.java index 227378b715..b7fead91aa 100644 --- a/designer/src/com/fr/design/mainframe/ReportFloatPane.java +++ b/designer/src/com/fr/design/mainframe/ReportFloatPane.java @@ -67,7 +67,7 @@ public class ReportFloatPane extends JPanel { } private MenuDef createInsertToolBar() { - MenuDef insertFloatMenu = new MenuDef(); + MenuDef insertFloatMenu = new MenuDef(true); insertFloatMenu.setName(KeySetUtils.INSERT_FLOAT.getMenuKeySetName()); insertFloatMenu.setTooltip(Inter.getLocText("FR-Designer_T_Insert_Float")); insertFloatMenu.setIconPath("com/fr/design/images/control/addPopup.png"); diff --git a/designer_base/src/com/fr/design/actions/UpdateAction.java b/designer_base/src/com/fr/design/actions/UpdateAction.java index b716da73b1..ecb6c95af7 100644 --- a/designer_base/src/com/fr/design/actions/UpdateAction.java +++ b/designer_base/src/com/fr/design/actions/UpdateAction.java @@ -11,6 +11,7 @@ import com.fr.design.constants.UIConstants; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UICheckBoxMenuItem; import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.menu.ShortCut; import com.fr.design.selection.SelectionListener; import com.fr.general.ComparatorUtils; @@ -48,6 +49,11 @@ public abstract class UpdateAction extends ShortCut implements Action { */ private boolean enabled = true; + /** + * Specifies whether action is rePaint; the default is false. + */ + private boolean rePaint = false; + /** * Contains the array of key bindings. * august:关键词key,是Action里面的final常量,如:Action.NAME、Action.SMALL_ICON等等 @@ -249,7 +255,7 @@ public abstract class UpdateAction extends ShortCut implements Action { this.putValue(UIMenuItem.class.getName(), object); } - + ((UIMenuItem) object).setRePaint(this.rePaint); return (UIMenuItem) object; } @@ -317,7 +323,9 @@ public abstract class UpdateAction extends ShortCut implements Action { @Override public void intoJPopupMenu(JPopupMenu menu) { update(); - + if (menu instanceof UIPopupMenu){ + this.rePaint = ((UIPopupMenu) menu).getRePaint(); + } menu.add(this.createMenuItem()); } diff --git a/designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java b/designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java index e5370d3223..3b3064042b 100644 --- a/designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java +++ b/designer_base/src/com/fr/design/gui/imenu/UIMenuItem.java @@ -1,20 +1,22 @@ package com.fr.design.gui.imenu; -import java.awt.*; - -import javax.swing.*; -import javax.swing.plaf.basic.BasicMenuItemUI; - import com.fr.design.constants.UIConstants; +import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.stable.Constants; import com.fr.stable.StringUtils; -import com.fr.design.utils.gui.GUIPaintUtils; import sun.swing.SwingUtilities2; -public class UIMenuItem extends JMenuItem{ - public UIMenuItem() { - this(StringUtils.BLANK); - } +import javax.swing.*; +import javax.swing.plaf.basic.BasicMenuItemUI; +import java.awt.*; + +public class UIMenuItem extends JMenuItem { + + private boolean rePaint = false; + + public UIMenuItem() { + this(StringUtils.BLANK); + } public UIMenuItem(String string) { this(string, null); @@ -37,7 +39,11 @@ public class UIMenuItem extends JMenuItem{ this(); setAction(action); } - + + public void setRePaint(boolean rePaint){ + this.rePaint = rePaint; + } + @Override public String getText() { return StringUtils.BLANK + super.getText(); @@ -47,21 +53,34 @@ public class UIMenuItem extends JMenuItem{ @Override protected void paintBackground(Graphics g, JMenuItem menuItem,Color bgColor) { if(menuItem.getIcon() == null) { - super.paintBackground(g, menuItem, bgColor); - return; + if (!rePaint){ + super.paintBackground(g, menuItem, bgColor); + return; + } + } + if (rePaint){ + menuItem.setIcon(null); } ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); - g.setColor(UIConstants.NORMAL_BACKGROUND); g.fillRect(0, 0, menuWidth, menuHeight); - if(menuItem.isOpaque()) { - if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) { - GUIPaintUtils.fillPaint((Graphics2D)g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); + + if (menuItem.isOpaque()) { + if (!rePaint) { + if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { + GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); + } else { + GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); + } } else { - GUIPaintUtils.fillPaint((Graphics2D)g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); + if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { + GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0); + } else { + GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.TOOLBARUI_BACKGROUND, 0); + } } g.setColor(oldColor); } @@ -92,6 +111,9 @@ public class UIMenuItem extends JMenuItem{ -1, textRect.x - 1, textRect.y + fm.getAscent() - 1); } + } else if (rePaint) { + SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, + -1, 0, textRect.y + fm.getAscent()); } else { // *** paint the text normally if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) { @@ -102,6 +124,6 @@ public class UIMenuItem extends JMenuItem{ } } - } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java b/designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java index 9555689f6e..10a223c52a 100644 --- a/designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java +++ b/designer_base/src/com/fr/design/gui/imenu/UIPopupMenu.java @@ -7,28 +7,49 @@ import javax.swing.JPopupMenu; import com.fr.design.constants.UIConstants; -public class UIPopupMenu extends JPopupMenu{ - private boolean onlyText = false; - public UIPopupMenu() { - super(); - setBackground(UIConstants.NORMAL_BACKGROUND); - } - - @Override - protected void paintBorder(Graphics g) { - g.setColor(UIConstants.LINE_COLOR); - g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); - } - - @Override - public Insets getInsets() { - if(onlyText) { - return super.getInsets(); - } - return new Insets(10, 2, 10, 10); - } - - public void setOnlyText(boolean onlyText) { - this.onlyText = onlyText; - } +public class UIPopupMenu extends JPopupMenu { + private boolean onlyText = false; + private boolean rePaint = false; + + public UIPopupMenu() { + super(); + setBackground(UIConstants.NORMAL_BACKGROUND); + } + + public UIPopupMenu(boolean rePaint) { + super(); + this.rePaint = rePaint; + setBackground(UIConstants.TOOLBARUI_BACKGROUND); + } + + public boolean getRePaint() { + return this.rePaint; + } + + @Override + protected void paintBorder(Graphics g) { + if (rePaint) { + g.setColor(UIConstants.POP_DIALOG_BORDER); + g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); + } else { + g.setColor(UIConstants.LINE_COLOR); + g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); + } + } + + @Override + public Insets getInsets() { + if (onlyText) { + return super.getInsets(); + } + if (rePaint) { + return new Insets(0, 1, 1, 1); + } else { + return new Insets(10, 2, 10, 10); + } + } + + public void setOnlyText(boolean onlyText) { + this.onlyText = onlyText; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/menu/MenuDef.java b/designer_base/src/com/fr/design/menu/MenuDef.java index 319b94f2e4..385c4461f0 100644 --- a/designer_base/src/com/fr/design/menu/MenuDef.java +++ b/designer_base/src/com/fr/design/menu/MenuDef.java @@ -13,7 +13,10 @@ import javax.swing.*; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; 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.List; @@ -22,338 +25,406 @@ import java.util.List; */ public class MenuDef extends ShortCut { - protected String name; - protected char mnemonic; - protected String iconPath; - protected String tooltip; - //item List. - private List shortcutList = new ArrayList(); - // peter:产生的JMenu, UIButton以及enabled变量都是为由MenuDef产生的控件所用的 - protected boolean enabled = true; - protected UIMenu createdJMenu; - protected UIButton createdButton; - protected JPopupMenu popupMenu; - private boolean hasScrollSubMenu; - - private String anchor; - - public MenuDef() { - } - - public MenuDef(String name) { - this.setName(name); - } - - public MenuDef(String name, char mnemonic) { - this.setName(name); - this.setMnemonic(mnemonic); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public char getMnemonic() { - return mnemonic; - } - - public void setMnemonic(char mnemonic) { - this.mnemonic = mnemonic; - } - - public void setHasScrollSubMenu(boolean scrollSubMenu) { - this.hasScrollSubMenu = scrollSubMenu; - } - - public String getIconPath() { - return iconPath; - } - - public void setIconPath(String iconPath) { - this.iconPath = iconPath; - } - - public int getShortCutCount() { - return this.shortcutList.size(); - } - - public ShortCut getShortCut(int index) { - return this.shortcutList.get(index); - } - - public String getAnchor() { - return anchor == null ? StringUtils.EMPTY : anchor; - } - - public void setAnchor(String anchor) { - this.anchor = anchor; - } - - public List getShortcutList() { - return this.shortcutList; - } - - /** - * 插入菜单项 - * @param index 插入的位置 - * @param shortCut 菜单信息 - */ - public void insertShortCut(int index, ShortCut shortCut) { - int size = this.shortcutList.size(); - index = Math.min(index, size); - this.shortcutList.add(index, shortCut); - } - - /** - * 用可变参数,方便添加数组 - * @param shortcut 参数 存储菜单项信息 - */ - public void addShortCut(ShortCut... shortcut) { - for (ShortCut i : shortcut) { - this.shortcutList.add(i); - } - } - + private static final int MENU_DEFAULTWDITH = 156; + protected String name; + //右侧属性表弹出框重绘 + protected Boolean rePaint = false; + protected char mnemonic; + protected String iconPath; + protected String tooltip; + //item List. + private List shortcutList = new ArrayList(); + // peter:产生的JMenu, UIButton以及enabled变量都是为由MenuDef产生的控件所用的 + protected boolean enabled = true; + protected UIMenu createdJMenu; + protected UIButton createdButton; + protected JPopupMenu popupMenu; + private boolean hasScrollSubMenu; + + private String anchor; + + public MenuDef() { + } + + public MenuDef(String name) { + this.setName(name); + } + + public MenuDef(Boolean rePaint) { + this.setRePaint(rePaint); + } + + public MenuDef(String name, char mnemonic) { + this.setName(name); + this.setMnemonic(mnemonic); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean getRePaint() { + return rePaint; + } + + public void setRePaint(boolean rePaint) { + this.rePaint = rePaint; + } + + public char getMnemonic() { + return mnemonic; + } + + public void setMnemonic(char mnemonic) { + this.mnemonic = mnemonic; + } + + public void setHasScrollSubMenu(boolean scrollSubMenu) { + this.hasScrollSubMenu = scrollSubMenu; + } + + public String getIconPath() { + return iconPath; + } + + public void setIconPath(String iconPath) { + this.iconPath = iconPath; + } + + public int getShortCutCount() { + return this.shortcutList.size(); + } + + public ShortCut getShortCut(int index) { + return this.shortcutList.get(index); + } + + public String getAnchor() { + return anchor == null ? StringUtils.EMPTY : anchor; + } + + public void setAnchor(String anchor) { + this.anchor = anchor; + } + + public List getShortcutList() { + return this.shortcutList; + } + + /** + * 插入菜单项 + * + * @param index 插入的位置 + * @param shortCut 菜单信息 + */ + public void insertShortCut(int index, ShortCut shortCut) { + int size = this.shortcutList.size(); + index = Math.min(index, size); + this.shortcutList.add(index, shortCut); + } + + /** + * 用可变参数,方便添加数组 + * + * @param shortcut 参数 存储菜单项信息 + */ + public void addShortCut(ShortCut... shortcut) { + for (ShortCut i : shortcut) { + this.shortcutList.add(i); + } + } + public void removeShortCut(ShortCut shortCut) { - + this.shortcutList.remove(shortCut); } - /** - * 清理 - */ - public void clearShortCuts() { - this.shortcutList.clear(); - } - - /** - * 生成UIButton - * @return 菜单按钮 - */ - public UIButton createUIButton() { - if (createdButton == null) { - if (iconPath != null) { - createdButton = new UIButton(BaseUtils.readIcon(iconPath)); - createdButton.set4ToolbarButton(); - } else { - createdButton = new UIButton(name); - } - // 添加名字以作自动化测试 - createdButton.setName(name); - createdButton.setToolTipText(tooltip); - createdButton.addMouseListener(mouseListener); - } - - return createdButton; - } - - public void setTooltip(String text) { - this.tooltip = text; - } - - /** - * 生成JMenu - * @return 菜单 - */ - public UIMenu createJMenu() { - if (createdJMenu == null) { - if (hasScrollSubMenu) { - createdJMenu = new UIScrollMenu(this.getName()); - } else { - createdJMenu = new UIMenu(this.getName()); - } - createdJMenu.setMnemonic(this.getMnemonic()); - if (this.iconPath != null) { - createdJMenu.setIcon(BaseUtils.readIcon(this.iconPath)); - } - createdJMenu.addMenuListener(menuDefListener); - ContainerListener listener = getContainerListener(); - if(listener != null){ - createdJMenu.getPopupMenu().addContainerListener(listener); - } - } - - return createdJMenu; - } - - protected ContainerListener getContainerListener() { - return null; - } - /** - * 生成 JPopupMenu - * @return 弹出菜单 - */ - public JPopupMenu createJPopupMenu() { - UIMenu menu = createJMenu(); - updateMenu(); - return menu.getPopupMenu(); - } - - /** - * 设置是否可用 - * @param b 布尔型 - */ - @Override - public void setEnabled(boolean b) { - this.enabled = b; - - if (createdButton != null) { - createdButton.setEnabled(enabled); - } - - if (createdJMenu != null) { - createdJMenu.setEnabled(enabled); - } - } - - /** - * 按钮状态 - * @return 状态 - */ - @Override - public boolean isEnabled() { - return enabled; - } - - /** - * 更新菜单 - */ - public void updateMenu() { - //peter:这个方法用来产生JMenu的孩子控件,但是不update,action. - this.updatePopupMenu(this.createJMenu().getPopupMenu()); - - //peter:需要设置JMenu的enabled属性. - if (createdJMenu != null) { - createdJMenu.setEnabled(createdJMenu.getPopupMenu().getComponentCount() > 0 && enabled); - createdJMenu.repaint(10); - } - } - - /** - * 更新菜单 - * @param popupMenu 菜单 - */ - protected void updatePopupMenu(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 菜单 - */ - public void removeComponent(JPopupMenu popupMenu){ - UIScrollBar uiScrollBar = new UIScrollBar(); - if(hasScrollSubMenu){ - for(Component comp : popupMenu.getComponents()){ - if(comp instanceof UIScrollBar){ - uiScrollBar =(UIScrollBar) comp; - } - } - } - popupMenu.removeAll(); - if(hasScrollSubMenu){ - popupMenu.add(uiScrollBar); - } - } - - /** - * 添加菜单项 - * @param menu 菜单 - */ - @Override - public void intoJPopupMenu(JPopupMenu menu) { - updateMenu(); - - menu.add(this.createJMenu()); - } - - /** - * 添加 - * @param toolBar 菜单条 - */ - @Override - public void intoJToolBar(JToolBar toolBar) { - toolBar.add(this.createUIButton()); - } - - private MenuListener menuDefListener = new MenuListener() { - - @Override - public void menuCanceled(MenuEvent evt) { - } - - @Override - public void menuDeselected(MenuEvent evt) { - } - - @Override - public void menuSelected(MenuEvent evt) { - Object source = evt.getSource(); - if (!(source instanceof JMenu)) { - return; - } - - MenuDef.this.updateMenu(); - } - }; - private MouseListener mouseListener = new MouseAdapter() { - - @Override - public void mouseReleased(MouseEvent evt) { - Object source = evt.getSource(); - UIButton button = (UIButton) source; - if (!button.isEnabled()) { - return; - } - - UIPopupMenu popupMenu = new UIPopupMenu(); - popupMenu.setInvoker(button); - MenuDef.this.updatePopupMenu(popupMenu); - - GUICoreUtils.showPopupMenu(popupMenu, button, 0, button.getSize().height); - } - }; - - - //ben: for ui test - public JPopupMenu getPopupMenu() { - return popupMenu; - } - - public void setPopupMenu(JPopupMenu popupMenu) { - this.popupMenu = popupMenu; - } - - + /** + * 清理 + */ + public void clearShortCuts() { + this.shortcutList.clear(); + } + + /** + * 生成UIButton + * + * @return 菜单按钮 + */ + public UIButton createUIButton() { + if (createdButton == null) { + if (iconPath != null) { + createdButton = new UIButton(BaseUtils.readIcon(iconPath)); + createdButton.set4ToolbarButton(); + } else { + createdButton = new UIButton(name); + } + // 添加名字以作自动化测试 + createdButton.setName(name); + createdButton.setToolTipText(tooltip); + createdButton.addMouseListener(mouseListener); + } + + return createdButton; + } + + public void setTooltip(String text) { + this.tooltip = text; + } + + /** + * 生成JMenu + * + * @return 菜单 + */ + public UIMenu createJMenu() { + if (createdJMenu == null) { + if (hasScrollSubMenu) { + createdJMenu = new UIScrollMenu(this.getName()); + } else { + createdJMenu = new UIMenu(this.getName()); + } + createdJMenu.setMnemonic(this.getMnemonic()); + if (this.iconPath != null) { + createdJMenu.setIcon(BaseUtils.readIcon(this.iconPath)); + } + createdJMenu.addMenuListener(menuDefListener); + ContainerListener listener = getContainerListener(); + if (listener != null) { + createdJMenu.getPopupMenu().addContainerListener(listener); + } + } + + return createdJMenu; + } + + protected ContainerListener getContainerListener() { + return null; + } + + /** + * 生成 JPopupMenu + * + * @return 弹出菜单 + */ + public JPopupMenu createJPopupMenu() { + UIMenu menu = createJMenu(); + updateMenu(); + return menu.getPopupMenu(); + } + + /** + * 设置是否可用 + * + * @param b 布尔型 + */ + @Override + public void setEnabled(boolean b) { + this.enabled = b; + + if (createdButton != null) { + createdButton.setEnabled(enabled); + } + + if (createdJMenu != null) { + createdJMenu.setEnabled(enabled); + } + } + + /** + * 按钮状态 + * + * @return 状态 + */ + @Override + public boolean isEnabled() { + return enabled; + } + + /** + * 更新菜单 + */ + public void updateMenu() { + //peter:这个方法用来产生JMenu的孩子控件,但是不update,action. + this.updatePopupMenu(this.createJMenu().getPopupMenu()); + + //peter:需要设置JMenu的enabled属性. + if (createdJMenu != null) { + createdJMenu.setEnabled(createdJMenu.getPopupMenu().getComponentCount() > 0 && enabled); + createdJMenu.repaint(10); + } + } + + /** + * 更新菜单 + * + * @param popupMenu 菜单 + */ + protected void updatePopupMenu(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 菜单 + */ + 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 菜单 + */ + public void removeComponent(JPopupMenu popupMenu) { + UIScrollBar uiScrollBar = new UIScrollBar(); + if (hasScrollSubMenu) { + for (Component comp : popupMenu.getComponents()) { + if (comp instanceof UIScrollBar) { + uiScrollBar = (UIScrollBar) comp; + } + } + } + popupMenu.removeAll(); + if (hasScrollSubMenu) { + popupMenu.add(uiScrollBar); + } + } + + /** + * 添加菜单项 + * + * @param menu 菜单 + */ + @Override + public void intoJPopupMenu(JPopupMenu menu) { + updateMenu(); + + menu.add(this.createJMenu()); + } + + /** + * 添加 + * + * @param toolBar 菜单条 + */ + @Override + public void intoJToolBar(JToolBar toolBar) { + toolBar.add(this.createUIButton()); + } + + private MenuListener menuDefListener = new MenuListener() { + + @Override + public void menuCanceled(MenuEvent evt) { + } + + @Override + public void menuDeselected(MenuEvent evt) { + } + + @Override + public void menuSelected(MenuEvent evt) { + Object source = evt.getSource(); + if (!(source instanceof JMenu)) { + return; + } + + MenuDef.this.updateMenu(); + } + }; + private MouseListener mouseListener = new MouseAdapter() { + + @Override + public void mouseReleased(MouseEvent evt) { + Object source = evt.getSource(); + UIButton button = (UIButton) source; + if (!button.isEnabled()) { + return; + } + if (rePaint) { + 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); + MenuDef.this.updatePopupMenu(popupMenu); + GUICoreUtils.showPopupMenu(popupMenu, button, 0, button.getSize().height); + } + } + }; + + + //ben: for ui test + public JPopupMenu getPopupMenu() { + return popupMenu; + } + + public void setPopupMenu(JPopupMenu popupMenu) { + this.popupMenu = popupMenu; + } + + } \ No newline at end of file