Example usage for com.google.gwt.core.client JsArray shift

List of usage examples for com.google.gwt.core.client JsArray shift

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArray shift.

Prototype

public final native T shift() ;

Source Link

Document

Shifts the first value off the array.

Usage

From source file:com.akjava.gwt.html5.client.file.FileUtils.java

License:Apache License

public static FileUploadForm createMultiFileUploadForm(final DataURLsListener listener, final boolean reset) {
    final FileUploadForm form = new FileUploadForm();
    form.setMultiple(true);//  ww  w  . ja v  a 2  s.  c  o m
    form.getFileUpload().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            final FileReader reader = FileReader.createFileReader();
            final JsArray<File> tmp = FileUtils.toFile(event.getNativeEvent());
            @SuppressWarnings("unchecked")
            final JsArray<File> files = (JsArray<File>) JsArray.createArray();
            for (int i = 0; i < tmp.length(); i++) {
                files.push(tmp.get(i));
            }

            final List<File> dataFiles = new ArrayList<File>();
            final List<String> values = new ArrayList<String>();
            if (files.length() > 0) {
                reader.setOnLoad(new FileHandler() {
                    @Override
                    public void onLoad() {
                        dataFiles.add(files.get(0));
                        values.add(reader.getResultAsString());

                        files.shift();
                        if (files.length() == 0) {
                            listener.uploaded(dataFiles, values);
                            if (reset) {
                                form.reset();
                            }
                        } else {
                            reader.readAsDataURL(files.get(0));
                        }

                    }
                });
                reader.readAsDataURL(files.get(0));
            }

        }
    });
    return form;
}

From source file:com.github.gwtcannonjs.demo.client.impl.PileDemo.java

License:Open Source License

@Override
public void run() {
    final Demo demo = CANNON.newDemo();
    final double size = 1;

    // Spheres//  w w w .j  a  v a2s . co m
    demo.addScene("Pile", new AddSceneCallback() {
        @Override
        public void execute() {
            if (interval != null)
                interval.cancel();

            final World world = demo.getWorld();

            world.getGravity().set(0, 0, -50);
            world.setBroadphase(CANNON.newNaiveBroadphase());
            ((GSSolver) world.getSolver().cast()).setIterations(5);

            world.getDefaultContactMaterial().setContactEquationStiffness(5e6);
            world.getDefaultContactMaterial().setContactEquationRelaxation(10);

            // Since we have many bodies and they don't move very much, we can use the less accurate quaternion normalization
            world.setQuatNormalizeFast(true);
            world.setQuatNormalizeSkip(4); // ...and we do not have to normalize every step.

            // ground plane
            Shape groundShape = CANNON.newPlane();
            Body groundBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            groundBody.addShape(groundShape);
            groundBody.getPosition().set(0, 0, 0);
            world.addBody(groundBody);
            demo.addVisual(groundBody);

            // plane -x
            Shape planeShapeXmin = CANNON.newPlane();
            Body planeXmin = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeXmin.addShape(planeShapeXmin);
            planeXmin.getQuaternion().setFromAxisAngle(CANNON.newVec3(0, 1, 0), Math.PI / 2);
            planeXmin.getPosition().set(-5, 0, 0);
            world.addBody(planeXmin);

            // Plane +x
            Shape planeShapeXmax = CANNON.newPlane();
            Body planeXmax = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeXmax.addShape(planeShapeXmax);
            planeXmax.getQuaternion().setFromAxisAngle(CANNON.newVec3(0, 1, 0), -Math.PI / 2);
            planeXmax.getPosition().set(5, 0, 0);
            world.addBody(planeXmax);

            // Plane -y
            Shape planeShapeYmin = CANNON.newPlane();
            Body planeYmin = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeYmin.addShape(planeShapeYmin);
            planeYmin.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), -Math.PI / 2);
            planeYmin.getPosition().set(0, -5, 0);
            world.addBody(planeYmin);

            // Plane +y
            Shape planeShapeYmax = CANNON.newPlane();
            Body planeYmax = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            planeYmax.addShape(planeShapeYmax);
            planeYmax.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), Math.PI / 2);
            planeYmax.getPosition().set(0, 5, 0);
            world.addBody(planeYmax);

            final JsArray<Body> bodies = JsArray.createArray().cast();
            i = 0;
            interval = new Timer() {
                @Override
                public void run() {
                    // Sphere
                    i++;
                    Shape sphereShape = CANNON.newSphere(size);
                    Body b1 = CANNON.newBody(CANNON.newBodyOptions().withMass(5));
                    b1.addShape(sphereShape);
                    b1.getPosition().set(2 * size * Math.sin(i), 2 * size * Math.cos(i), 7 * 2 * size);
                    world.addBody(b1);
                    demo.addVisual(b1);
                    bodies.push(b1);

                    if (bodies.length() > 80) {
                        Body b = bodies.shift();
                        demo.removeVisual(b);
                        world.remove(b);
                    }
                }
            };
            interval.scheduleRepeating(100);
        }
    });

    demo.start();
}

From source file:org.dataconservancy.dcs.access.client.Util.java

License:Apache License

/**
 * Remove element at index from array preserving order.
 * /*from   w w w  .j a v a2  s .  c om*/
 * @param array
 * @param index
 */
// TODO Duplicate code because of generics issues...

//    public static void remove(JsArray<JavaScriptObject> array, int index) {
//        JavaScriptObject[] jarray = new JavaScriptObject[array.length()];
//
//        for (int i = 0; i < jarray.length; i++) {
//            jarray[i++] = array.shift();
//        }
//        
//        for (int i = 0; i < jarray.length; i++) {
//            if (i != index) {
//                array.push(jarray[i]);
//            }
//        }
//    }

public static void removeCollection(JsArray<JsCollection> array, int index) {
    JsCollection[] jarray = new JsCollection[array.length()];

    for (int i = 0; i < jarray.length; i++) {
        jarray[i++] = array.shift();
    }

    for (int i = 0; i < jarray.length; i++) {
        if (i != index) {
            array.push(jarray[i]);
        }
    }
}

From source file:org.dataconservancy.dcs.access.client.Util.java

License:Apache License

public static void removeDeliverableUnit(JsArray<JsDeliverableUnit> array, int index) {
    JsDeliverableUnit[] jarray = new JsDeliverableUnit[array.length()];

    for (int i = 0; i < jarray.length; i++) {
        jarray[i++] = array.shift();
    }//from   w  ww.j  a va2 s. c o m

    for (int i = 0; i < jarray.length; i++) {
        if (i != index) {
            array.push(jarray[i]);
        }
    }
}