Widget Event

From Documentation

Overview

Here the "widget" we mention refers to charts and pictures floating on a sheet. The following events are related to widget (chart and pictures).

  • onWidgetUpdate
    This event is fired when a user moves or resize a picture (or a chart). When a corresponding event listener is invoked, a WidgetUpdateEvent object is passed as an argument.
  • onWidgetCtrlKey
    This event is fired after a user presses combined keys, e.g. ctrl+c when selecting a picture (or a chart) . When a corresponding event listener is invoked, a WidgetKeyEvent object is passed as an argument.


Event Monitor Example

Let's get back to our event monitor example. We upload a picture of ZK logo, move it, resize it and press ctrl+C after selecting it. The panel on right hand side displays corresponding messages to our actions.

Zss-essentials-events-widget.png


public class EventsComposer extends SelectorComposer<Component>{

	@Listen("onWidgetUpdate = #ss")
	public void onWidgetUpdate(WidgetUpdateEvent event){
		StringBuilder info = new StringBuilder();
		SheetAnchor anchor = event.getSheetAnchor();
		
		info.append("Widget ")
				.append(event.getWidgetData())
				.append(" ")
				.append(event.getAction())
				.append(" to ")
				.append(Ranges.getAreaRefString(anchor.getRow(),
						anchor.getColumn(), anchor.getLastRow(),
						anchor.getLastColumn()));
		
		//show messages
	}
	
	@Listen("onWidgetCtrlKey = #ss")
	public void onWidgetCtrlKey(WidgetKeyEvent event){
		StringBuilder info = new StringBuilder();
		
		info.append("Widget ").append(event.getWidgetData())
			.append(" Key : ").append(event.getKeyCode())
			.append(", Ctrl:").append(event.isCtrlKey())
			.append(", Alt:").append(event.isAltKey())
			.append(", Shift:").append(event.isShiftKey());
		
		//show messages
	}

}