Example usage for com.google.gwt.user.client.ui KeyboardListener MODIFIER_CTRL

List of usage examples for com.google.gwt.user.client.ui KeyboardListener MODIFIER_CTRL

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui KeyboardListener MODIFIER_CTRL.

Prototype

int MODIFIER_CTRL

To view the source code for com.google.gwt.user.client.ui KeyboardListener MODIFIER_CTRL.

Click Source Link

Usage

From source file:com.gwt.components.client.Canvas.java

License:Open Source License

public void onBrowserEvent(Event event) {
    switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    case Event.ONMOUSEUP:
    case Event.ONMOUSEMOVE:
    case Event.ONMOUSEOVER:
    case Event.ONMOUSEOUT: {
        if (mouseListeners != null) {
            modifiers = (DOM.eventGetShiftKey(event) ? KeyboardListener.MODIFIER_SHIFT : 0)
                    | (DOM.eventGetMetaKey(event) ? KeyboardListener.MODIFIER_META : 0)
                    | (DOM.eventGetCtrlKey(event) ? KeyboardListener.MODIFIER_CTRL : 0)
                    | (DOM.eventGetAltKey(event) ? KeyboardListener.MODIFIER_ALT : 0);
            mouseListeners.fireMouseEvent(this, event);
        }//w  w w.j  a  va 2  s .c  o  m
        break;
    }
    case Event.ONMOUSEWHEEL: {
        if (mouseWheelListeners != null) {
            modifiers = (DOM.eventGetShiftKey(event) ? KeyboardListener.MODIFIER_SHIFT : 0)
                    | (DOM.eventGetMetaKey(event) ? KeyboardListener.MODIFIER_META : 0)
                    | (DOM.eventGetCtrlKey(event) ? KeyboardListener.MODIFIER_CTRL : 0)
                    | (DOM.eventGetAltKey(event) ? KeyboardListener.MODIFIER_ALT : 0);
            mouseWheelListeners.fireMouseWheelEvent(this, event);
        }
        break;
    }
    case Event.ONKEYDOWN:
    case Event.ONKEYPRESS:
    case Event.ONKEYUP:
        super.onBrowserEvent(event);
    }
}

From source file:com.vaadin.client.ui.ShortcutActionHandler.java

License:Apache License

ShortcutKeyCombination(int kc, int[] modifiers) {
    keyCode = (char) kc;

    modifiersMask = 0;//w w  w .  j a va 2 s .c  om
    if (modifiers != null) {
        for (int i = 0; i < modifiers.length; i++) {
            switch (modifiers[i]) {
            case ALT:
                modifiersMask = modifiersMask | KeyboardListener.MODIFIER_ALT;
                break;
            case CTRL:
                modifiersMask = modifiersMask | KeyboardListener.MODIFIER_CTRL;
                break;
            case SHIFT:
                modifiersMask = modifiersMask | KeyboardListener.MODIFIER_SHIFT;
                break;
            case META:
                modifiersMask = modifiersMask | KeyboardListener.MODIFIER_META;
                break;
            default:
                break;
            }
        }
    }
}

From source file:org.gems.ajax.client.edit.tools.SelectionTool.java

License:Open Source License

public void onKeyPress(DiagramElement sender, char keyCode, int modifiers) {
    if (keyCode == KeyboardListener.KEY_CTRL) {
        hasCtrlModifier_ = false;//  w  w  w. j  a  va 2s.c  o m
    } else if (keyCode == KeyboardListener.KEY_SHIFT) {
        hasShiftModifier_ = false;
    } else if (keyCode == KeyboardListener.KEY_DELETE) {
        deleteSelectedElements();
    } else if (modifiers == KeyboardListener.MODIFIER_CTRL && (keyCode == 'Z' || keyCode == 'z')) {
        // Undo
        getCommandStack().undo();
    } else if (modifiers == KeyboardListener.MODIFIER_CTRL && (keyCode == 'Y' || keyCode == 'y')) {
        // Redo
        getCommandStack().redo();
    } else {
        super.onKeyPress(sender, keyCode, modifiers);
    }
}

From source file:org.gems.ajax.client.edit.tools.SelectionTool.java

License:Open Source License

public void onKeyUp(DiagramElement sender, char keyCode, int modifiers) {
    if (keyCode == KeyboardListener.KEY_CTRL) {
        hasCtrlModifier_ = false;//w  ww.  j a v a2  s  . com
    } else if (keyCode == KeyboardListener.KEY_SHIFT) {
        hasShiftModifier_ = false;
    } else if (keyCode == KeyboardListener.KEY_DELETE) {
        deleteSelectedElements();
    } else if ((modifiers == KeyboardListener.MODIFIER_CTRL || hasCtrlModifier_)
            && (keyCode == 'Z' || keyCode == 'z')) {
        // Undo
        getCommandStack().undo();
    } else if ((modifiers == KeyboardListener.MODIFIER_CTRL || hasCtrlModifier_)
            && (keyCode == 'Y' || keyCode == 'y')) {
        // Redo
        getCommandStack().redo();
    }
}

From source file:org.gems.ajax.client.event.GlobalKeyboardListener.java

License:Open Source License

private static int getModifiers(Event event) {
    int modifiers = 0;

    if (DOM.eventGetCtrlKey(event))
        modifiers = modifiers | KeyboardListener.MODIFIER_CTRL;
    if (DOM.eventGetAltKey(event))
        modifiers = modifiers | KeyboardListener.MODIFIER_ALT;
    if (DOM.eventGetShiftKey(event))
        modifiers = modifiers | KeyboardListener.MODIFIER_SHIFT;

    return modifiers;
}

From source file:org.vectomatic.client.rep.controller.EditPolylineController.java

License:Open Source License

@Override
public void mouseDown(DrawingView view, Point p, int modifiers) {
    view.toModelCoordinates(p);//from w w  w  . j  av a 2s.  co  m
    if (_polyline == null) {
        Shape shape = view.getPicker().pick(p, _app.getModel().reverseIterator());
        if (shape instanceof Polyline) {
            selectPolyline((Polyline) shape, new HashSet<Integer>());
        }
    } else {
        _pickedVertex = pickVertex(p);
        if (_pickedVertex == -1) {
            Shape shape = view.getPicker().pick(p, _app.getModel().reverseIterator());
            if (shape instanceof Polyline) {
                selectPolyline((Polyline) shape, new HashSet<Integer>());
            } else {
                selectPolyline(null, new HashSet<Integer>());
            }
        } else {
            Integer vertex = new Integer(_pickedVertex);
            boolean ctrlPressed = (modifiers & KeyboardListener.MODIFIER_CTRL) != 0;
            if (ctrlPressed) {
                if (_vertexIndices.contains(vertex)) {
                    _vertexIndices.remove(vertex);
                } else {
                    _vertexIndices.add(vertex);
                }
            } else {
                _vertexIndices.add(vertex);
            }
        }
    }
}

From source file:org.vectomatic.client.rep.controller.SelectShapeController.java

License:Open Source License

@Override
public void mouseDown(DrawingView view, Point p, int modifiers) {
    p.copyTo(_p1);/*  ww w.j av  a 2  s.c  o  m*/
    view.toModelCoordinates(p);
    Event event = DOM.eventGetCurrentEvent();
    if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
        MenuBar bar = null;
        if (view.getPicker().pick(p, _app.getSelection().iterator()) == null) {
            Shape shape = view.getPicker().pick(p, _app.getModel().reverseIterator());
            if (shape != null) {
                List<Shape> newSelection = new ArrayList<Shape>();
                newSelection.add(shape);
                _app.getSelection().select(newSelection);
                bar = _contextVisitor.getContextualMenu(_app.getSelection());
            }
        } else {
            bar = _contextVisitor.getContextualMenu(_app.getSelection());
        }
        if (bar != null) {
            ControllerContextItem.popup.setWidget(bar);
            ControllerContextItem.popup.setPopupPosition(DOM.eventGetClientX(event),
                    DOM.eventGetClientY(event));
            ControllerContextItem.popup.show();
        }
    } else {
        boolean ctrlPressed = (modifiers & KeyboardListener.MODIFIER_CTRL) != 0;
        Shape rootShape = _app.getSelection().getRootShape();

        _handle = getHandle(view, p);
        switch (_handle) {
        case BoundingBox.PT_NW:
        case BoundingBox.PT_SW:
        case BoundingBox.PT_SE:
        case BoundingBox.PT_NE:
        case BoundingBox.PT_N:
        case BoundingBox.PT_W:
        case BoundingBox.PT_S:
        case BoundingBox.PT_E:
            _mode = MODE_SCALE;
            rootShape.getTransform().copyTo(_mOld);
            // Store the first point clicked
            rootShape.getScaling(_p1);
            rootShape.getTransform().invert(_mInv);
            break;

        case BoundingBox.PT_R:
            _mode = MODE_ROTATE;
            rootShape.getTransform().copyTo(_mOld);

            // Store the shape original rotation and the original transform matrix
            _r1 = rootShape.getRotation();
            rootShape.getTransform().invert(_mInv);

            // Compute the vector from the selection bounding box center
            // to the mousedown point
            p.transform(_mInv).subtract(rootShape.getBoundingBox().getPoint(BoundingBox.PT_C, _p0));

            // Compute the angle (PT_R, PT_C, p)
            _r2 = (float) (Math.acos(p.x / p.length()));
            if (p.y < 0) {
                _r2 = -_r2;
            }
            _r3 = _r2;
            break;
        case HANDLE_MOVE:
            if (ctrlPressed) {
                List<Shape> oldSelection = _app.getSelection().getSelectedShapes();
                List<Shape> newSelection = new ArrayList<Shape>(oldSelection);
                newSelection.remove(view.getPicker().pick(p, _app.getSelection().iterator()));
                _app.getSelection().select(newSelection);
                _mode = MODE_HOVER;
            } else {
                _mode = MODE_TRANSLATE;
                rootShape.getTransform().copyTo(_mOld);
                // Store the first point clicked
                p.copyTo(_p1);
                // Store the vector from the clicked point to the
                // bounding box center
                p.subtract(rootShape.getTranslation(_p2), _p2);
            }
            break;
        case HANDLE_NONE: {
            Shape shape = view.getPicker().pick(p, _app.getModel().reverseIterator());
            if (shape == null) {
                RepApplication.app.debugPrint("rect");
                if (!ctrlPressed) {
                    _app.getSelection().select(new ArrayList<Shape>());
                }
                _mode = MODE_RECT;
                _rect.setTranslation(p);
                _rect.setRotation(-view.getRotation());
                _rect.setScaling(Point.UNIT);
                view.getScaling(_p3);
            } else {
                RepApplication.app.debugPrint("select");
                if (!ctrlPressed) {
                    _app.getSelection().select(new ArrayList<Shape>());
                }
                List<Shape> oldSelection = _app.getSelection().getSelectedShapes();
                List<Shape> newSelection = new ArrayList<Shape>(oldSelection);
                newSelection.add(shape);
                rootShape = _app.getSelection().select(newSelection);
                _mode = MODE_TRANSLATE;
                rootShape.getTransform().copyTo(_mOld);
                // Store the first point clicked
                p.copyTo(_p1);
                // Store the vector from the clicked point to the
                // bounding box center
                p.subtract(rootShape.getTranslation(_p2), _p2);
            }

        }
            break;
        }
    }
}

From source file:org.vectomatic.client.rep.view.DrawingView.java

License:Open Source License

public DrawingView(RepresentationController repController, DrawingModel model, int width, int height) {
    super(width, height);
    saveContext();/*  ww  w  .  j a  v a2  s  . co m*/
    _t = new Point();
    _s = new Point(Point.UNIT);
    _m = new TransformMatrix();

    _repController = repController;
    _model = model;
    _mInv = new TransformMatrix();
    _compass = new Compass(this);
    _compass.setPosition(new Point(width - 70, 50));
    _compass.setRadius(45);
    _renderer = new RenderVisitor(this);
    _picker = new PickVisitor(this);
    addMouseListener(new MouseListenerAdapter() {
        Point p = new Point();

        @Override
        public void onMouseDown(Widget sender, int x, int y) {
            p.x = x;
            p.y = y;
            //RepApplication.app.debugArea.setText(toModelCoordinates(p, new Point()).toString());
            if (_compass.pick(p) != Compass.NONE) {
                _compassMode = true;
                _compass.mouseDown(p);
            } else {
                _compassMode = false;
                //p.transform(_mInv);
                RepApplication.app.debugPrint("x=" + p.x + " y=" + p.y);
                _controller.mouseDown(DrawingView.this, p, modifiers);
            }
        }

        @Override
        public void onMouseMove(Widget sender, int x, int y) {
            p.x = x;
            p.y = y;
            if (_compassMode) {
                _compass.mouseMove(p);
            } else {
                _compass.pick(p);
                //p.transform(_mInv);
                _controller.mouseMove(DrawingView.this, p, modifiers);
            }
        }

        @Override
        public void onMouseUp(Widget sender, int x, int y) {
            p.x = x;
            p.y = y;
            if (_compassMode) {
                _compass.mouseUp();
                _compassMode = false;
            } else {
                //p.transform(_mInv);
                _controller.mouseUp(DrawingView.this, p, modifiers);
            }
        }
    });
    addKeyboardListener(new KeyboardListener() {
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            _controller.keyDown(DrawingView.this, keyCode, modifiers);
        }

        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            _controller.keyPress(DrawingView.this, keyCode, modifiers);
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            _controller.keyUp(DrawingView.this, keyCode, modifiers);
        }
    });
    addMouseWheelListener(new MouseWheelListener() {
        Point p = new Point();

        public void onMouseWheel(Widget sender, MouseWheelVelocity velocity) {
            int delta = 10 * velocity.getDeltaY();
            if ((modifiers & KeyboardListener.MODIFIER_CTRL) != 0) {
                if (delta > 0) {
                    float s = _compass.getScaling();
                    _compass.setScaling(s + 0.1f * (1 - s));
                } else {
                    float s = _compass.getScaling();
                    _compass.setScaling(s - 0.1f * s);
                }
            } else {
                if ((modifiers & KeyboardListener.MODIFIER_ALT) != 0) {
                    p.x = delta;
                    p.y = 0f;
                } else {
                    p.x = 0f;
                    p.y = delta;
                }
                _compass.translate(p);
            }
        }
    });
}