Package com.googlecode.mcvaadin.helpers

Source Code of com.googlecode.mcvaadin.helpers.KeyboardHandlerImpl

package com.googlecode.mcvaadin.helpers;

import java.io.Serializable;

import com.googlecode.mcvaadin.McEvent;
import com.googlecode.mcvaadin.McListener;
import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.Action.Handler;

public class KeyboardHandlerImpl implements Handler, Serializable {

    private static final long serialVersionUID = 1867655708565732838L;
    private Action[] acts;
    private int key;
    private int[] mods;
    private McListener listener;

    public KeyboardHandlerImpl(int key, int[] modifiers, McListener listener) {
        this.key = key;
        this.listener = listener;
        mods = modifiers;
        acts = new Action[] { new ShortcutAction("", key, modifiers) };
    }

    public Action[] getActions(Object target, Object sender) {
        return acts;
    }

    public void handleAction(Action action, Object sender, Object target) {
        if (action == acts[0]) {
            try {
                listener.exec(new McEvent(key, mods));
            } catch (Throwable t) {
                listener.unhandledError("Unhandled exception", t);
            }
        }
    }
}
TOP

Related Classes of com.googlecode.mcvaadin.helpers.KeyboardHandlerImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.