Mouse Event

From Documentation
⧼coll-notfound_msg⧽

Return to Documentation.




There are two kinds of mouse events. One is cell mouse events such as onCellClick, onCellDoubleClick and onCellRightClick

  • onCellClick
    This event is fired when a user left clicks on a cell. When a corresponding event listener is invoked, a CellMouseEvent object is passed as an argument.
  • onCellDoubleClick
    This event is fired when a user double clicks on a cell. When a corresponding event listener is invoked, a CellMouseEvent object is passed as an argument.
  • onCellRightClick
    This event is fired when a user right clicks on ZK Spreadsheet cell. When a corresponding event listener is invoked, a CellMouseEvent object is passed as an argument.


Another is header mouse events such as onHeaderClick, onHeaderDoubleClick and onHeaderRightClick.

  • onHeaderClick
    This event is fired when a user left clicks on Spreadsheet's header. When a corresponding event listener is invoked, a HeaderMouseEvent object is passed as an argument.
  • onHeaderDoubleClick
    This event is fired when a user double clicks on Spreadsheet header. When a corresponding event listener is invoked, a HeaderMouseEvent object is passed as an argument.
  • onHeaderRightClick
    This event is fired when a user right clicks on Spreadsheet header. When a corresponding event listener is invoked, a HeaderMouseEvent object is passed as an argument.
  • onHeaderUpdate
    This event is fired when a user resize a row (or column) header. When a corresponding event listener is invoked, a HeaderUpdateEvent object is passed as an argument.


Example

We still use previous "Event Monitor" application demonstrate event listening.

As you can see in the right panel, it shows messages when I click a cell or header and resize a column header. We also can achieve this in a controller very easily with @Listen. We omit lots of similar codes and leave those codes that are worth for your reference.


public class EventsComposer extends SelectorComposer<Component>{
	//omitted codes...

	@Listen("onCellClick = spreadsheet")
	public void onCellClick(CellMouseEvent event){
		StringBuilder info = new StringBuilder();
		info.append("Click on cell ")
		.append(Ranges.getCellReference(event.getRow(),event.getColumn()));
		
		if(isShowEventInfo(event.getName())){
			addInfo(info.toString());
		}
	}
	@Listen("onCellRightClick = spreadsheet")
	public void onCellRightClick(CellMouseEvent event){
		//show messages...
	}
	@Listen("onCellDoubleClick = spreadsheet")
	public void onCellDoubleClick(CellMouseEvent event){
		//show messages...
	}
	
	
	@Listen("onHeaderUpdate = spreadsheet")
	public void onHeaderUpdate(HeaderUpdateEvent event){
		StringBuilder info = new StringBuilder();
		info.append("Header ").append(event.getAction())
			.append(" on ").append(event.getType());
		switch(event.getType()){
		case COLUMN:
			info.append(" ").append(Ranges.getColumnReference(event.getIndex()));
			break;
		case ROW:
			info.append(" ").append(Ranges.toRowReference(event.getIndex()));
			break;
		}

		switch(event.getAction()){
		case RESIZE:
			if(event.isHidden()){
				info.append(" hides ");
			}else{
				info.append(" changes to ").append(event.getSize());
			}
			break;
		}
		
		//show messages...
	}
	
	
	@Listen("onHeaderClick = spreadsheet")
	public void onHeaderClick(HeaderMouseEvent event){
				StringBuilder info = new StringBuilder();
		info.append("Click on ").append(event.getType()).append(" ");
		
		switch(event.getType()){
		case COLUMN:
			info.append(Ranges.getColumnReference(event.getIndex()));
			break;
		case ROW:
			info.append(Ranges.toRowReference(event.getIndex()));
			break;
		}
		
		//show messages...
	}
	@Listen("onHeaderRightClick = spreadsheet")
	public void onHeaderRightClick(HeaderMouseEvent event){
		//show messages...
	}
	@Listen("onHeaderDoubleClick = spreadsheet")
	public void onHeaderDoubleClick(HeaderMouseEvent event){
		//show messages...
	}
}