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; } } }
发表评论
-
《算法之美》の字符串相关问题の壹
2012-07-06 09:52 697题目:编写一个单词逆序输出的算法,例如输入"SE ... -
WinForm下正则表达式的应用
2012-07-06 09:45 9211.引入命名空间:using System.Text.Re ... -
八个最常用的正则表达式
2012-07-06 09:38 697灵活的使用正则表达式,可以使得程序既简洁,又清晰。因为正则 ... -
基于表的Lua原生支持面向对象编程在GUI中的使用示例
2012-07-06 09:30 1127lua真的有很多神奇的用法,下面是一个基于表的形式实现的对 ... -
图片展示
2012-07-05 20:45 5825 ... -
Flex 4架构的组件开发
2012-07-03 13:44 588Flex 4架构的组件开发 作者:Michael Labr ... -
Flex利用自定义事件使用弹出窗口为DataGrid添加新数据
2012-07-02 12:27 619下面是TitleWindow所有代码: Xml代码 ... -
flex--LineChart
2012-07-02 12:27 607最近工作上用到了linechart,在网上查的资料还是非常 ... -
flex的mask处理
2012-07-02 12:26 745在做公司一个flash播放器时候,需要在一个swf中动态加 ... -
flex datechooser 日期小例子
2012-07-02 12:26 565在这个例子中,我们讲解的是DateChooser 控件,这 ... -
在应用中使用Ext Loader
2012-07-01 10:01 510原文:http://www.sencha.com/b ... -
广州工作2个月!差人的公司可以call我
2012-07-01 10:01 539网名:夜梦惊魂/夜枫设计 姓名:胡军 博客:http ... -
WebKit介绍及总结(一)
2012-07-01 10:01 637一. WebKit简介 ... -
基于push技术的web实时网络管理框架研究
2012-07-01 10:01 4251 引言 基于 web 的网络管理是web 功能和网 ... -
MyEclipse for Spring 8.6: Spring MVC Scaffolding
2012-07-01 10:01 765Scaffolding consists of singl ... -
FLEX和Actionscript开发FLASH游戏8-2-1
2012-06-30 16:28 601FLEX和Actionscript开发FLASH游戏8-2-1 ... -
flex安全沙箱
2012-06-30 16:27 1034flex安全沙箱 2011年02月2 ... -
flex 联机游戏开发 - 五子棋游戏:(二)人性化选择
2012-06-30 16:27 574flex 联机游戏开发 - 五子棋游戏:(二)人性化选择 2 ...
相关推荐
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右键例子