Flex右键菜单扫盲
- 博客分类:
- 技术杂绘
怎么添加右键?在 Flex 中,只有应用程序中的顶层组件才能拥有上下文菜单。例如,如果 DataGrid 控件是 TabNavigator 或 VBox 容器的子级,则 DataGrid 控件不能拥有其自己的上下文菜单。组件一般都有个"contextMenu"属性,对通过实例化 ContextMenu 类,可以控制上下文菜单中显示的项。为了向 ContextMenu 对象中添加新项,可以创建一个 ContextMenuItem 对象,然后将该对象添加到ContextMenu.customItems数组。对该对象进行侦听可以响应单击事件,例如:pasteMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELEC T, applMenuItemPasteHandler); 使该对象不可见可以设置其visiable属性,使其不可用可使用enable属性;
separatorBefore指示指定的菜单项上方是否显示分隔条。
相关使用代码如下: diagramBox.contextMenu=popupMenuFactory.getPopupMe nu(); ////////////////////////////////////////////////// ///////////////////////////// // Licensed Materials - Property of IBM // 5724-Z78 // ?? Copyright IBM Corporation 2007, 2010. All Rights Reserved. // // Note to U.S. Government Users Restricted Rights: // Use, duplication or disclosure restricted by GSA ADP Schedule // Contract with IBM Corp. ////////////////////////////////////////////////// ///////////////////////////// package { import bpm.graphic.SubProcess; import bpm.graphic.Task; import com.ibm.ilog.elixir.diagram.Diagram; import com.ibm.ilog.elixir.diagram.Node; import com.ibm.ilog.elixir.diagram.Renderer; import com.ibm.ilog.elixir.diagram.Subgraph; import com.ibm.ilog.elixir.diagram.editor.DiagramEditor; import flash.events.ContextMenuEvent; import flash.events.MouseEvent; import flash.external.ExternalInterface; import flash.geom.Point; import flash.ui.ContextMenu; import flash.ui.ContextMenuItem; import mx.core.FlexGlobals; import mx.resources.IResourceManager; /** * Creates the popup menu for the Diagram. */ public class DiagramMenuFactory { private var diageditor:DiagramEditor; private var resourceManager:IResourceManager; private var diagramPopupMenu:ContextMenu; // Custom menu items private var selectAllMenuItem:ContextMenuItem; private var deleteMenuItem:ContextMenuItem; private var cutMenuItem:ContextMenuItem; private var copyMenuItem:ContextMenuItem; private var pasteMenuItem:ContextMenuItem; private var groupSubMenuItem:ContextMenuItem; private var ungroupMenuItem:ContextMenuItem; private var layoutMenuItem:ContextMenuItem; private var connectMenuItem:ContextMenuItem; private var renameMenuItem:ContextMenuItem; private var conneMenuItem:ContextMenuItem; private var enterConnectMenuItem:ContextMenuItem; // Cache for labels used in popup menu private var deleteSelectedObjectsLabel:String; private var deleteObjectLabel:String; private var cutSelectedObjectsLabel:String; private var cutObjectLabel:String; private var copySelectedObjectsLabel:String; private var copyObjectLabel:String; private var layoutAllLabel:String; private var layoutObjectLabel:String; private var conneObjectLabel:String; private var enterConnectObjectLabel:String; // Renderer that is currently with the mouse public var currentObject:Object; private var currentMouseLocationX:Number=NaN; private var currentMouseLocationY:Number=NaN; private var menuLocationX:Number=NaN; private var menuLocationY:Number=NaN; public var projectId:String=""; /** * Factory to create the Diagram popup menu */ public function DiagramMenuFactory(resourceMgr:IResourceManager, editor:DiagramEditor, diagram:Diagram) { diageditor=editor; resourceManager=resourceMgr; diagram.addEventListener(MouseEvent.MOUSE_MOVE, diagramMouseMoveHandler); } private function diagramMouseMoveHandler(event:MouseEvent):void { currentMouseLocationX=event.stageX; currentMouseLocationY=event.stageY; currentObject=diageditor.graph.getHitRenderer(even t.target); } // -------------------------------------------------- --- // Popup Menu for the Diagram // -------------------------------------------------- --- private function populatePopupMenu():void { diagramPopupMenu=new ContextMenu(); diagramPopupMenu.hideBuiltInItems(); addCustomItems(diagramPopupMenu); diagramPopupMenu.addEventListener(ContextMenuEvent .MENU_SELECT, popupMenu_menuSelect); } /** * Enables or disables the menu items according to * the number of selected objects. */ private function popupMenu_menuSelect(evt:ContextMenuEvent):void { // Store the position of the mouse at the moment when the menu is opened menuLocationX=currentMouseLocationX; menuLocationY=currentMouseLocationY; var selObjs:Vector.; if (currentObject != null) { // The popup menu has been opened for a specific object. selObjs=diageditor.getSelectedObjects(); if (selObjs.indexOf(currentObject) 0); deleteMenuItem.caption=deleteSelectedObjectsLabel; copyMenuItem.caption=copySelectedObjectsLabel; cutMenuItem.caption=cutSelectedObjectsLabel; layoutMenuItem.caption=layoutAllLabel; layoutMenuItem.visible=true; layoutMenuItem.enabled=((diageditor.graph.numEleme nts > 0) && ((diageditor.graph.nodeLayout != null) || (diageditor.graph.linkLayout != null))); conneMenuItem.visible=false; enterConnectMenuItem.visible=false; } // Connect objects is only available if two nodes are selected selObjs=diageditor.getSelectedObjects(); if (selObjs.length == 2) { if (selObjs[0] is Node && selObjs[1] is Node) { connectMenuItem.visible=true; } else { connectMenuItem.visible=false; } } else { connectMenuItem.visible=false; } var hasSelection:Boolean=diageditor.hasSelection; deleteMenuItem.enabled=hasSelection; cutMenuItem.enabled=diageditor.canCopy; copyMenuItem.enabled=diageditor.canCopy; pasteMenuItem.enabled=diageditor.canPaste; groupSubMenuItem.enabled=FlexGlobals.topLevelAppli cation.canGroup; ungroupMenuItem.visible=diageditor.canUngroup; copyApplicationCustomItems(); } // The first visible item of the diagran context menu, // used by copyApplicationCustomItems to set/clear the separator. private var firstVisibleItem:ContextMenuItem=null; /** * Copies the custom menu items from the toplevel application's context menu * (typically the View Source and About Elixir Enterprise... items) */ private function copyApplicationCustomItems():void { var appMenu:ContextMenu=FlexGlobals.topLevelApplicatio n.contextMenu; if (appMenu) { var index:int=-1; // scan custom items in the application context menu for each (var item:ContextMenuItem in appMenu.customItems) { // has the item already been copied to the diagram context menu? index=-1; for (var i:int=0; i = 0) { if (firstVisibleItem) firstVisibleItem.separatorBefore=false; for (var j:int=index + 1; j =diageditor.getSelect edObjects(); var pasted:Renderer=null; for each (pasted in pastedObjects) { if (pasted is Node) { minx=Math.min(minx, Number(pasted.x)); miny=Math.min(miny, Number(pasted.y)); maxx=Math.max(maxx, Number(pasted.x + pasted.width)); maxy=Math.max(maxy, Number(pasted.y + pasted.height)); } } if (pasted != null) { var p:Point=pasted.parent.globalToLocal(new Point(menuLocationX, menuLocationY)); var dx:Number=p.x - minx; var dy:Number=p.y - miny; diageditor.translateSelectionOfDelta(dx, dy); } } /** * Group selected objects as children of a subgraph. */ private function applMenuItemGroupSubgraphHandler(event:ContextMenu Event):void { var subgraph:Subgraph=new SubProcess(); subgraph.collapsed=false; subgraph.width=resourceManager.getNumber("bpmedito r", "bpmeditor.subprocess.default.width"); subgraph.height=resourceManager.getNumber("bpmedit or", "bpmeditor.subprocess.default.height"); subgraph.label=resourceManager.getString("bpmedito r", "bpmeditor.subprocess.default.label"); FlexGlobals.topLevelApplication.groupObjects(subgr aph); } /** * Ungroup any selected subgraphs. */ private function applMenuItemUngroupHandler(event:ContextMenuEvent) :void { diageditor.ungroup(); } /** * Perform layout on the whole diagram or on the selected subgraph. */ private function applMenuItemLayoutHandler(event:ContextMenuEvent): void { if (currentObject == null) { FlexGlobals.topLevelApplication.layoutAll(); } else { FlexGlobals.topLevelApplication.layoutSelectedSubg raph(); } } /** * Returns the menu displayed for the diagram. */ public function getPopupMenu():ContextMenu { if (diagramPopupMenu == null) populatePopupMenu(); return diagramPopupMenu; } } }
发表评论
-
解决Delphi截取字符串时遇到半个汉字
2012-07-06 09:52 2064演示程序中主要是用了 IsDBCSLeadByte 这个 ... -
js 学习笔记!
2012-07-06 09:46 6041.在ie 6 中 "//" 注释会 ... -
黑莓开发第三篇:常用UI组件
2012-07-03 13:44 826最低层次的UI 组件 可以处理自身的显示 用于显示各种 ... -
虚拟机随谈:解释器,树遍历解释器,基于栈与基于寄存器,大杂烩
2012-07-02 12:53 808虚拟机随谈:解释器,树遍历解释器,基于栈与基于寄存器, ... -
关于flexigrid一点用法
2012-07-02 12:52 585闲来无事在网上找了一个jquery的grid插件 flex ... -
如何使用registerClassAlias来解决module中使用RemoteObject---第一次访问正常、第二次出错
2012-07-02 12:52 586问题:今天我在Flex的module中使用RemoteOb ... -
超级面板皮肤及其使用
2012-07-02 12:52 670画出类似于遨游那样的最大化,最小化,关闭,还原按钮的皮肤。 ... -
flex 弹出的titleWindow 隐藏标题栏
2012-07-02 12:52 1777showTopPanelTitle.titleDispla ... -
Flex中调用FileReference.download()方法的限制【已解决】
2012-07-01 10:19 1970[2011-04-21 02:11:24] 问题解决。原因 ... -
Flex自定义鼠标右键
2012-07-01 10:19 794这里写了一个简单的自定义鼠标右键,代码不难,请看注释 ... -
整合Flash Builder4.0+MyEclipse 8.6+BlazeDS+Sping 3.0+Hibernate3.3+MySQL5.5+Tomcat+JDK1.6
2012-07-01 10:18 886,设置好环境变量。 Tomcat 6.0。 去官方下 ... -
走在网页游戏开发的路上(一)
2012-06-30 16:45 716走在网页游戏开发的路 ... -
2011-10-18
2012-06-30 16:45 6592011-10-18 2011年10月18日 ... -
文启领航教育:“内幕大公开”
2012-06-30 16:45 3文启领航教育:“内幕大 ... -
2011-11-24
2012-06-30 16:45 6972011-11-24 2011年11月24日 大型多人在 ... -
FLEX和Actionscript开发FLASH游戏 10-4
2012-06-30 16:45 590FLEX和Actionscript开发FLASH游戏 10-4 ...
相关推荐
Flex右键菜单 flex tree 右键菜单 导入eclipse可直接用。我使用的flex sdk 版本是flex4.5.1,更改为4.0可直接使用。
flex 自定义右键菜单 多级右键菜单flex 自定义右键菜单 多级右键菜单flex 自定义右键菜单 多级右键菜单
Flex自定义右键菜单
flex添加右键菜单实例。很经典的实例。
Flex添加右键菜单,只是文档,里边有描述性的代码
flex右键菜单代码,很不错的哦。分享给大家;
flex右键菜单完全屏蔽右键 可以自定义;导入后可以直接应用;绝对值; 非js屏蔽
NULL 博文链接:https://mirabelle1211.iteye.com/blog/961255
flex 右键菜单两种实现: 1.系统右键菜单,系统右键菜单项中添加菜单项 2.屏蔽系统右键菜单,自定义右键菜单
flex 右键菜单两种实现: 1.系统右键菜单,系统右键菜单项中添加菜单项 2.屏蔽系统右键菜单,自定义右键菜单
flex小实例-----menu菜单引出事件监听器注册.docflex小实例-----menu菜单引出事件监听器注册.docflex小实例-----menu菜单引出事件监听器注册.doc
flex两种右键菜单,RightClickManager修改后在非Application下也可以弹出来。
Flex屏蔽浏览器系统右键,实现自定义Menu的右键菜单,支持XML格式的多级菜单,以及支持菜单出现位置的自适应。欢迎大家修改,(能给出如何恢复浏览器右键菜单最好)。
自定义右键,屏蔽系统自带右键, 经测试可使用在opensacles地图上。解决地图开发时无法使用无法使用自定义右键及无法屏蔽系统右键问题。
实现右键点击事件,及完全屏闭系统右键菜单 并自定义右键菜单
完全屏蔽flex自带的右键菜单,实现自定义右键菜单,附件有完整可运行的例子。 这个问题折腾了一天多,在网上搜了很多资料,几乎都是一样的,转来转去,且讲的不明不白。这里我提供了可运行的全部代码,让你轻松搞定...
NULL 博文链接:https://lpyyn.iteye.com/blog/2054024
该代码是在Flex实现右键的具体实现方法。 如有不明可发信息咨询活留言。
flex右键例子