Code Search for Developers
 
 
  

SWTMouseWithKeyInput.java from MASE: Agile Software Engineering at Krugle


Show SWTMouseWithKeyInput.java syntax highlighted

/**
 * 
 */
package ucalgary.ebe.ci.gestures.input.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.widgets.Control;

import ucalgary.ebe.ci.ICIInputProvider;
import ucalgary.ebe.ci.gestures.input.AbstractTimedInput;
import ucalgary.ebe.ci.gestures.input.GestureInput;

/**
 * @author hkolenda
 * 
 */
public class SWTMouseWithKeyInput extends AbstractTimedInput implements GestureInput, ICIInputProvider {

    private int keyCode = SWT.CTRL;

    private Control control = null;

    private InputHandler inputHandler = null;

    public SWTMouseWithKeyInput(Control control) {
        inputHandler = new InputHandler();
        control.addKeyListener(inputHandler);
        control.addMouseMoveListener(inputHandler);
        this.control = control;
        setGestureTimeout(3000);
    }

    private class InputHandler implements KeyListener, MouseMoveListener {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
         */
        public void keyPressed(KeyEvent e) {
            if (e.character == keyCode) {
                if (!isGestureRunning()) {
                    fireStartGesture();
                }
            }
            else {
                fireCancelGesture();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
         */
        public void keyReleased(KeyEvent e) {

            if (e.character == keyCode) {
                fireStopGesture();
            }
            else {
                fireCancelGesture();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
         */
        public void mouseMove(MouseEvent e) {
            if (isGestureRunning()) {
                fireCoordInput(e.x, e.y);
            }
        }

    }

    /**
     * @param button
     *            the button to set
     */
    public void setKeyCode(int keyCode) {
        this.keyCode = keyCode;
    }

    /*
     * (non-Javadoc)
     * 
     * @see ucalgary.ebe.ci.ICIInputProvider#stop()
     */
    public void stop() {
        if (control != null) {
            control.removeKeyListener(inputHandler);
            control.removeMouseMoveListener(inputHandler);
        }

    }

}




See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  SWTMouseInput.java
  SWTMouseWithKeyComboInput.java
  SWTMouseWithKeyInput.java