Chapter 11: Using Menu-Based Controls--Menu-based control events

User interaction with a Menu or menu-based control is event-driven; that is, applications typically handle events
generated when the user opens, closes, or selects within a menu, or submenu or rolls over or out of menu items. 
The Menu and MenuBar controls dispatch an identical set of menu-specific events. Event handling with PopUp-
MenuButton controls differs from the other two controls, but shares many elements in common with the others.


Menu控件事件

Menu控件在MenuEvent类中定义了以下和菜单相关的事件类型:
change (MenuEvent.CHANGE) Dispatched when a user changes current menu selection by using the keyboard
or mouse.
itemClick (MenuEvent.ITEM_CLICK) Dispatched when a user selects an enabled menu item of type normal,
check, or radio. This event is not dispatched when a user selects a menu item of type separator, a menu item
that opens a submenu, or a disabled menu item.
itemRollOut (MenuEvent.ITEM_ROLL_OUT) Dispatched when the mouse pointer rolls off of a Menu item.
itemRollOver (MenuEvent.ITEM_ROLL_OVER) Dispatched when the mouse pointer rolls onto a Menu item.
menuHide (MenuEvent.MENU_HIDE) Dispatched when the entire menu or a submenu closes.
menuShow  (MenuEvent.MENU_SHOW) Dispatched when the entire menu or a submenu opens.

传递到事件监听器的event对象类型是MenuEvent,它包含一个或多个以下属性:

Property

Description

item

The item in the data provider for the menu item associated with the event.

index

The index of the item in the menu or submenu that contains it.

label

The label of the item.

menu

A reference to the Menu control where the event occurred.

menuBar

The MenuBar control instance that is the parent of the menu, or undefined when the menu does not belong 

MenuBar control on pa 365.

to a MenuBar. For more information, see 

访问一个基于对象的菜单项中的property和field时,采用如下方式:
ta1.text = event.item.label
To access attributes of an E4X XML-based menu item, you specify the menu item attribute name in E4X syntax,

访问E4X XML-based 的菜单项的attribu的时候,如下方式访问:
ta1.text = event.item.@label

 

注意:如果你在一个菜单控件的子菜单上添加了一个事件监听器,当data provider发生结构改变时(比如:一个element被remove了),那么这个监听器可能就跟着消失了,为了确保当dataprovider发生变化时,事件监听器还好用,要么把事件监听器加在菜单控件上,而不是子菜单上,要么当data provider的结构改变时都重新注册一次。
The following example shows a menu with a simple event listener. 
 


MenuBar事件
The following figure shows a MenuBar control:

MenuBar的事件,比Menu少一个itemclick事件。

change (MenuEvent.CHANGE) Dispatched when a user changes current menu bar selection by using the
keyboard or mouse. This event is also dispatched when the user changes the current menu selection in a pop-up
submenu. When the event occurs on the menu bar, the
menu property of the MenuEvent object is null.
itemRollOut (MenuEvent.ITEM_ROLL_OUT) Dispatched when the mouse pointer rolls off of a menu bar
item.
itemRollOver (MenuEvent.ITEM_ROLL_OVER) Dispatched when the mouse pointer rolls onto a menu bar
item.
menuHide (MenuEvent.MENU_HIDE) Dispatched when a pop-up submenu closes.
menuShow (MenuEvent.MENU_SHOW) Dispatched when a pop-up submenu opens, or the user selects a menu
bar item with no drop-down menu.

Note:当你选择menu bar上的一个item时,MenuBar控件不派发itemClick事件,只有当你选择的是弹出的子菜单中的item时才会派发itemClick事件。 For more information, see Menu control events– on page 354.

对于每个弹出的子菜单,MenuBar控件派发change, itemClick, itemRollOut, itemRollOver, menuShow, and menuHide事件,和Menu控件是一样的,所以Handle events triggered by the pop-up menus as you would handle events from Menu controls.
The following example handles events for the menu bar and for the pop-up submenus.


 

 例子:使用Menu控件事件

     下面的例子是关于Menu控件的事件,它展示了两个菜单,一个data provider是XML,一个是Array。当用户打开菜单,移动鼠标,选择菜单项时,TextArea控件显示了关于每个事件的信息,It shows some of the differences in how you handle XML and object-based menus, and indicates some of the types of information that are available about each Menu event.

 

 


PopUpMenuButton控件事件

      PopUpMenuButton 控件可创建一个 PopUpButton 控件,带有一个主子按钮和一个辅助子按钮。单击辅助(右)子按钮会下拉一个菜单。

      因为PopUpMenuButtonPopUpButton控件的子类,它支持PopUpButton控件的所有事件,当用户单击主子按钮时时,PopUpMenuButton控件派发出一个click (MouseEvent.CLICK)事件。

      当用户单击PopUpMenuButton的主子按钮时,它还派发出一个itemClick(MenuEvent.ITEM_CLICK)事件,该事件包含关于所选菜单项的信息,因此,当用户单击主子按钮或者从下拉菜单中选择一项时都会派发itemClick事件。因为两种情况都会派发同一个事件,所以单击主子按钮产生的行为和在下拉框最后选择的行为是一样的,所以主子按钮扮演着经常被使用的菜单项。

The following example shows how the PopUpMenuButton generates events and how an application can handle
them.
     当用户从弹出的菜单中选择一项时,发生下列事件顺序: The PopUpMenuButton dispatches an itemClick event. The applicationsitemClickHandler() event listener function handles the itemClick event and displays the information about the event in an Alert control.
     当用户单击主子按钮,发生下列事件顺序: The PopUpMenuButton control dispatches a click event. The PopUpMenuButton control dispatches an itemClick event. The applicationsitemClickHandler() event listener function handles the itemClick event and displays information about the selected Menu item in an Alert control. The applicationsclickHandler() event listener function also handles the MouseEvent.CLICK event, and displays the Button label in an Alert control.
 

资源下载链接为: https://pan.quark.cn/s/140386800631 通用大模型文本分类实践的基本原理是,借助大模型自身较强的理解和推理能力,在使用时需在prompt中明确分类任务目标,并详细解释每个类目概念,尤其要突出类目间的差别。 结合in-context learning思想,有效的prompt应包含分类任务介绍及细节、类目概念解释、每个类目对应的例子和待分类文本。但实际应用中,类目和样本较多易导致prompt过长,影响大模型推理效果,因此可先通过向量检索缩小范围,再由大模型做最终决策。 具体方案为:离线时提前配置好每个类目的概念及对应样本;在线时先对给定query进行向量召回,再将召回结果交给大模型决策。 该方法不更新任何模型参数,直接使用开源模型参数。其架构参考GPT-RE并结合相关实践改写,加入上下文学习以提高准确度,还使用BGE作为向量模型,K-BERT提取文本关键词,拼接召回的相似例子作为上下文输入大模型。 代码实现上,大模型用Qwen2-7B-Instruct,Embedding采用bge-base-zh-v1.5,向量库选择milvus。分类主函数的作用是在向量库中召回相似案例,拼接prompt后输入大模型。 结果方面,使用ICL时accuracy达0.94,比bert文本分类的0.98低0.04,错误类别6个,处理时添加“家居”类别,影响不大;不使用ICL时accuracy为0.88,错误58项,可能与未修改prompt有关。 优点是无需训练即可有较好结果,例子优质、类目界限清晰时效果更佳,适合围绕通用大模型api打造工具;缺点是上限不高,仅针对一个分类任务部署大模型不划算,推理速度慢,icl的token使用多,用收费api会有额外开销。 后续可优化的点是利用key-bert提取的关键词,因为核心词语有时比语意更重要。 参考资料包括
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值