Search in sources :

Example 26 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent in project drools-wb by kiegroup.

the class KeyDownHandlerDatePickerTest method tabKeyCanvasActions.

@Test
public void tabKeyCanvasActions() {
    final KeyDownEvent e = mockKeyDownEvent(Optional.of(KeyCodes.KEY_TAB), Optional.of(false), Optional.of(false));
    handler.onKeyDown(e);
    verify(gridCell, never()).flush();
    verify(gridCell).destroyResources();
    verifyCommonActions();
}
Also used : KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) Test(org.junit.Test)

Example 27 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent in project drools-wb by kiegroup.

the class KeyDownHandlerDatePickerTest method escapeKeyCanvasActions.

@Test
public void escapeKeyCanvasActions() {
    final KeyDownEvent e = mockKeyDownEvent(Optional.of(KeyCodes.KEY_ESCAPE), Optional.of(false), Optional.of(false));
    handler.onKeyDown(e);
    verify(gridCell, never()).flush();
    verify(gridCell).destroyResources();
    verifyCommonActions();
}
Also used : KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) Test(org.junit.Test)

Example 28 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent in project gwt-cs by iSergio.

the class HeadingPitchRoll method buildPanel.

@Override
public void buildPanel() {
    ViewerPanel csVPanel = new ViewerPanel();
    pathPosition = new SampledPositionProperty();
    PathGraphicsOptions pathGraphicsOptions = new PathGraphicsOptions();
    pathGraphicsOptions.show = new ConstantProperty<>(true);
    pathGraphicsOptions.leadTime = new ConstantProperty<>(0);
    pathGraphicsOptions.trailTime = new ConstantProperty<>(60);
    pathGraphicsOptions.width = new ConstantProperty<>(10);
    pathGraphicsOptions.resolution = new ConstantProperty<>(1);
    pathGraphicsOptions.material = PolylineGlowMaterialProperty.create(Color.PALEGOLDENROD(), 0.3);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = pathPosition;
    entityOptions.name = "path";
    entityOptions.path = new PathGraphics(pathGraphicsOptions);
    Entity entityPath = csVPanel.getViewer().entities().add(entityOptions);
    final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
    final ScreenSpaceCameraController controller = csVPanel.getViewer().scene().screenSpaceCameraController();
    final Cartesian3 center = new Cartesian3();
    final org.cesiumjs.cs.core.HeadingPitchRoll hpRoll = new org.cesiumjs.cs.core.HeadingPitchRoll();
    final HeadingPitchRange hpRange = new HeadingPitchRange();
    position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
    speedVector = new Cartesian3();
    final Transforms.LocalFrameToFixedFrame fixedFrameTransform = Transforms.localFrameToFixedFrameGenerator("north", "west");
    FromGltfOptions fromGltfOptions = new FromGltfOptions();
    fromGltfOptions.url = GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb";
    // , fixedFrameTransform);
    fromGltfOptions.modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpRoll, Ellipsoid.WGS84());
    fromGltfOptions.minimumPixelSize = 128;
    planePrimitive = (Model) csVPanel.getViewer().scene().primitives().add(Model.fromGltf(fromGltfOptions));
    planePrimitive.readyPromise().then(new Fulfill<Model>() {

        @Override
        public void onFulfilled(Model model) {
            ModelAnimationOptions modelAnimationOptions = new ModelAnimationOptions();
            modelAnimationOptions.speedup = 0.5;
            modelAnimationOptions.loop = ModelAnimationLoop.REPEAT();
            model.activeAnimations.addAll(modelAnimationOptions);
            // Zoom to model
            r = 2.0 * max(model.boundingSphere().radius, ((PerspectiveFrustum) camera.frustum).near);
            controller.minimumZoomDistance = r * 0.5;
            Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere().center, center);
            double heading = Math.toRadians(230.0);
            double pitch = Math.toRadians(-20.0);
            hpRange.heading = heading;
            hpRange.pitch = pitch;
            hpRange.range = r * 50.0;
            camera.lookAt(center, hpRange);
        }
    });
    fromBehind = new CheckBox();
    fromBehind.getElement().getStyle().setColor("white");
    fromBehind.setWidth("100px");
    fromBehind.setValue(false);
    final com.google.gwt.user.client.ui.Label headingLabel = new Label();
    headingLabel.getElement().getStyle().setColor("white");
    headingLabel.setText("Heading:°");
    final com.google.gwt.user.client.ui.Label pitchLabel = new Label();
    pitchLabel.getElement().getStyle().setColor("white");
    pitchLabel.setText("Pitch:°");
    final com.google.gwt.user.client.ui.Label rollLabel = new Label();
    rollLabel.getElement().getStyle().setColor("white");
    rollLabel.setText("Roll:°");
    final com.google.gwt.user.client.ui.Label speedLabel = new Label();
    speedLabel.getElement().getStyle().setColor("white");
    speedLabel.setText("Speed:m/s");
    FlexTable flexTable = new FlexTable();
    flexTable.setWidget(0, 0, headingLabel);
    flexTable.setHTML(1, 0, "<font color=\"white\">← to left/→ to right</font>");
    flexTable.setWidget(2, 0, pitchLabel);
    flexTable.setHTML(3, 0, "<font color=\"white\">↑ to up/↓ to down</font>");
    flexTable.setWidget(4, 0, rollLabel);
    flexTable.setHTML(5, 0, "<font color=\"white\">← + ⇧ left/→ + ⇧ right</font>");
    flexTable.setWidget(6, 0, speedLabel);
    flexTable.setHTML(7, 0, "<font color=\"white\">↑ + ⇧ to speed up/↓ + ⇧ to speed down</font>");
    flexTable.setHTML(8, 0, "<font color=\"white\">Following aircraft</font>");
    flexTable.setWidget(8, 1, fromBehind);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);
    contentPanel.add(new HTML("<p>Click on the 3D window then use the keyboard to change settings.</p>"));
    contentPanel.add(aPanel);
    csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {

        @Override
        public void function(Scene scene, JulianDate time) {
            headingLabel.setText("Heading:" + Math.toDegrees(hpRoll.heading) + "°");
            pitchLabel.setText("Pitch:" + Math.toDegrees(hpRoll.pitch) + "°");
            rollLabel.setText("Roll:" + Math.toDegrees(hpRoll.roll) + "°");
            speedLabel.setText("Speed:" + speed + "m/s");
            speedVector = Cartesian3.multiplyByScalar(Cartesian3.UNIT_X(), speed / 10, speedVector);
            position = Matrix4.multiplyByPoint(planePrimitive.modelMatrix, speedVector, position);
            pathPosition.addSample(JulianDate.now(), position);
            Transforms.headingPitchRollToFixedFrame(position, hpRoll, Ellipsoid.WGS84(), fixedFrameTransform, planePrimitive.modelMatrix);
            if (fromBehind.getValue()) {
                // Zoom to model
                Matrix4.multiplyByPoint(planePrimitive.modelMatrix, planePrimitive.boundingSphere().center, center);
                hpRange.heading = hpRoll.heading;
                hpRange.pitch = hpRoll.pitch;
                camera.lookAt(center, hpRange);
            }
        }
    });
    RootPanel.get().addDomHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent keyDownEvent) {
            switch(keyDownEvent.getNativeKeyCode()) {
                case 40:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        speed = max(--speed, 1);
                    } else {
                        hpRoll.pitch -= deltaRadians;
                        if (hpRoll.pitch < -Math.TWO_PI()) {
                            hpRoll.pitch += Math.TWO_PI();
                        }
                    }
                    break;
                case 38:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // speed up
                        speed = min(++speed, 100);
                    } else {
                        // pitch up
                        hpRoll.pitch += deltaRadians;
                        if (hpRoll.pitch > Math.TWO_PI()) {
                            hpRoll.pitch -= Math.TWO_PI();
                        }
                    }
                    break;
                case 39:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // roll right
                        hpRoll.roll += deltaRadians;
                        if (hpRoll.roll > Math.TWO_PI()) {
                            hpRoll.roll -= Math.TWO_PI();
                        }
                    } else {
                        // turn right
                        hpRoll.heading += deltaRadians;
                        if (hpRoll.heading > Math.TWO_PI()) {
                            hpRoll.heading -= Math.TWO_PI();
                        }
                    }
                    break;
                case 37:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // roll left until
                        hpRoll.roll -= deltaRadians;
                        if (hpRoll.roll < 0.0) {
                            hpRoll.roll += Math.TWO_PI();
                        }
                    } else {
                        // turn left
                        hpRoll.heading -= deltaRadians;
                        if (hpRoll.heading < 0.0) {
                            hpRoll.heading += Math.TWO_PI();
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }, KeyDownEvent.getType());
    initWidget(contentPanel);
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) FromGltfOptions(org.cesiumjs.cs.scene.options.FromGltfOptions) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) com.google.gwt.user.client.ui(com.google.gwt.user.client.ui) SampledPositionProperty(org.cesiumjs.cs.datasources.properties.SampledPositionProperty) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ModelAnimationOptions(org.cesiumjs.cs.scene.options.ModelAnimationOptions) PathGraphics(org.cesiumjs.cs.datasources.graphics.PathGraphics) Scene(org.cesiumjs.cs.scene.Scene) PathGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PathGraphicsOptions) PathGraphics(org.cesiumjs.cs.datasources.graphics.PathGraphics) org.cesiumjs.cs.core(org.cesiumjs.cs.core) Model(org.cesiumjs.cs.scene.Model) ScreenSpaceCameraController(org.cesiumjs.cs.scene.ScreenSpaceCameraController)

Example 29 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent in project perun by CESNET.

the class SuggestBox method addEventsToTextBox.

private void addEventsToTextBox() {
    class TextBoxEvents extends HandlesAllKeyEvents implements ValueChangeHandler<String> {

        public void onKeyDown(KeyDownEvent event) {
            switch(event.getNativeKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    display.moveSelectionDown();
                    break;
                case KeyCodes.KEY_UP:
                    display.moveSelectionUp();
                    break;
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_TAB:
                    Suggestion suggestion = display.getCurrentSelection();
                    if (suggestion == null) {
                        display.hideSuggestions();
                    } else {
                        setNewSelection(suggestion);
                    }
                    break;
            }
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyPress(KeyPressEvent event) {
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyUp(KeyUpEvent event) {
            // After every user key input, refresh the popup's suggestions.
            refreshSuggestions();
            delegateEvent(SuggestBox.this, event);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            delegateEvent(SuggestBox.this, event);
        }
    }
    TextBoxEvents events = new TextBoxEvents();
    events.addKeyHandlersTo(box);
    box.addValueChangeHandler(events);
}
Also used : Suggestion(com.google.gwt.user.client.ui.SuggestOracle.Suggestion) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) HandlesAllKeyEvents(com.google.gwt.event.dom.client.HandlesAllKeyEvents) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)

Aggregations

KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)29 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)15 Test (org.junit.Test)12 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)3 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 CanFocus (org.rstudio.core.client.widget.CanFocus)3 FindTextBox (org.rstudio.core.client.widget.FindTextBox)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)2 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)2 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)2 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)2 PostConstruct (javax.annotation.PostConstruct)2 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)2 ToolbarLabel (org.rstudio.core.client.widget.ToolbarLabel)2 RSConnectPublishButton (org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton)2 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)2 AccountInfo (com.google.gerrit.client.info.AccountInfo)1