Example usage for com.google.gwt.dom.client ImageElement as

List of usage examples for com.google.gwt.dom.client ImageElement as

Introduction

In this page you can find the example usage for com.google.gwt.dom.client ImageElement as.

Prototype

public static ImageElement as(Element elem) 

Source Link

Document

Assert that the given Element is compatible with this class and automatically typecast it.

Usage

From source file:com.ait.lienzo.client.core.image.ImageLoader.java

License:Open Source License

public ImageLoader(final String url) {
    m_image = new Image();

    m_image.setVisible(false);/*from  w w w  . jav  a2 s .  c  om*/

    RootPanel.get().add(m_image);

    if (isValidDataURL(url)) {
        RootPanel.get().remove(m_image);

        ImageElement.as(m_image.getElement()).setSrc(url);

        onLoad(ImageElement.as(m_image.getElement()));
    } else {
        if (url.startsWith("http:") || (url.startsWith("https:"))) {
            setCrossOrigin(ImageElement.as(m_image.getElement()), "anonymous");
        }
        m_image.addLoadHandler(new LoadHandler() {
            @Override
            public void onLoad(LoadEvent event) {
                RootPanel.get().remove(m_image);

                ImageLoader.this.onLoad(ImageElement.as(m_image.getElement()));
            }
        });
        m_image.addErrorHandler(new ErrorHandler() {
            @Override
            public void onError(ErrorEvent event) {
                RootPanel.get().remove(m_image);

                ImageLoader.this.onError("Image " + url + " failed to load");
            }
        });
        m_image.setUrl(url);
    }
}

From source file:com.ait.lienzo.client.core.image.ImageLoader.java

License:Open Source License

public ImageLoader(final ImageResource resource) {
    m_image = new Image();

    m_image.setVisible(false);//  w w w.j a  v  a  2  s  . c o m

    RootPanel.get().add(m_image);

    m_image.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            RootPanel.get().remove(m_image);

            ImageLoader.this.onLoad(ImageElement.as(m_image.getElement()));
        }
    });
    m_image.addErrorHandler(new ErrorHandler() {
        @Override
        public void onError(ErrorEvent event) {
            RootPanel.get().remove(m_image);

            ImageLoader.this.onError("Resource " + resource.getName() + " failed to load");
        }
    });
    m_image.setResource(resource);
}

From source file:com.akjava.gwt.threetest.client.CanvasDemo.java

License:Apache License

@Override
public void start(final WebGLRenderer renderer, final int width, final int height, FocusPanel panel) {
    super.start(renderer, width, height, panel);
    canvas = Canvas.createIfSupported();
    canvas.setCoordinateSpaceWidth(100);
    canvas.setCoordinateSpaceHeight(100);
    canvas.getContext2d().setFillStyle("#cccccc");
    canvas.getContext2d().fillRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());
    canvas.getContext2d().strokeText("Hello World", 25, 25);
    String url = canvas.toDataUrl();
    Image img = new Image(url);
    ImageElement imageElement = ImageElement.as(img.getElement());
    Texture texture = THREE.Texture(imageElement);
    texture.setNeedsUpdate(true);/*from w ww  .j av  a  2 s.c  om*/

    final Scene scene = THREE.Scene();
    final Camera camera = THREE.PerspectiveCamera(35, (double) width / height, .1, 10000);
    scene.add(camera);
    cameraControle.setPositionZ(20);

    final Mesh mesh = THREE.Mesh(THREE.CubeGeometry(5, 5, 5), THREE.MeshLambertMaterial().map(texture).build());
    scene.add(mesh);

    final Light light = THREE.PointLight(0xffffff);
    light.setPosition(10, 0, 10);
    scene.add(light);

    Timer timer = new Timer() {
        public void run() {
            MainWidget.stats.update();
            camera.setPosition(cameraControle.getPositionX(), cameraControle.getPositionY(),
                    cameraControle.getPositionZ());

            mesh.setRotation(cameraControle.getRadiantRotationX(), cameraControle.getRadiantRotationY(),
                    cameraControle.getRadiantRotationZ());

            renderer.render(scene, camera);
        }
    };

    startTimer(timer);
}

From source file:com.anzsoft.client.ui.ChatWindow.java

License:Open Source License

private DivElement createMessage(final String user, final String message, boolean local) {
    Element element = DOM.createDiv();
    DivElement messageDiv = DivElement.as(element);
    lastMsgID = DOM.createUniqueId();//from w ww  .  ja va2 s  .co  m
    messageDiv.setId(lastMsgID);
    messageDiv.setClassName("selected-article");

    //create the avatar table
    element = DOM.createTable();
    TableElement avatarTable = TableElement.as(element);
    messageDiv.appendChild(avatarTable);
    avatarTable.setAttribute("hspace", "4");
    avatarTable.setAttribute("cellspacing", "0");
    avatarTable.setAttribute("vspace", "2");
    avatarTable.setAttribute("border", "0");
    avatarTable.setAttribute("align", "left");

    Element tbodyElement = DOM.createTBody();
    avatarTable.appendChild(tbodyElement);

    Element trElement = DOM.createTR();
    tbodyElement.appendChild(trElement);

    Element tdElement = DOM.createTD();
    trElement.appendChild(tdElement);
    tdElement.setAttribute("height", "45");
    tdElement.setAttribute("width", "45");
    tdElement.setAttribute("align", "middle");
    Style style = tdElement.getStyle();
    style.setProperty("border", "1px solid black");
    style.setProperty("background-color", "white");

    Element imgElement = DOM.createImg();
    ImageElement imageElement = ImageElement.as(imgElement);
    tdElement.appendChild(imageElement);
    imageElement.setAttribute("height", "45");
    imageElement.setAttribute("widht", "45");
    XmppVCard vc = null;
    if (local)
        vc = JabberApp.instance().getSelfVCard();
    else
        vc = vcard;
    if (!GXT.isIE && vc != null && !vc.photo().isEmpty())
        imageElement.setSrc("data:image;base64," + vc.photo());
    else
        imageElement.setSrc(JabberApp.instance().getAvatarUrl(jid));

    tdElement = DOM.createTD();
    tdElement.setInnerHTML("&nbsp&nbsp");
    trElement.appendChild(tdElement);

    //create the div for timestamp and nick
    element = DOM.createDiv();
    DivElement tnDiv = DivElement.as(element);
    tnDiv.setClassName("msg_header");
    messageDiv.appendChild(tnDiv);
    //style = tnDiv.getStyle();
    //style.setProperty("border-bottom", "1px solid black");

    element = DOM.createTable();
    TableElement tnTableElement = TableElement.as(element);
    tnDiv.appendChild(tnTableElement);
    tnTableElement.setAttribute("cellspacing", "0");
    tnTableElement.setAttribute("cellpadding", "0");
    tnTableElement.setAttribute("width", "80%");
    tnTableElement.setAttribute("border", "0");

    tbodyElement = DOM.createTBody();
    tnTableElement.appendChild(tbodyElement);

    trElement = DOM.createTR();
    tbodyElement.appendChild(trElement);

    Element nickElement = DOM.createTD();
    trElement.appendChild(nickElement);
    nickElement.setClassName("msg-nick");
    nickElement.setAttribute("valign", "bottom");
    nickElement.setAttribute("align", "left");
    nickElement.setInnerHTML("<b>" + user + "</b>");

    Element timeElement = DOM.createTD();
    trElement.appendChild(timeElement);
    timeElement.setClassName("msg-nick");
    timeElement.setAttribute("valign", "bottom");
    timeElement.setAttribute("align", "right");
    DateTimeFormat timeFormat = DateTimeFormat.getMediumTimeFormat();
    String datetime = timeFormat.format(new java.util.Date());
    timeElement.setInnerHTML("<small>" + datetime + "</small>");

    Element messageElement = DOM.createSpan();
    messageElement.setInnerHTML(ChatTextFormatter.format(message == null ? "" : message).getHTML());

    messageDiv.appendChild(messageElement);
    return messageDiv;
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findImages() {
    mImages = new ArrayList<MarkupParser.Image>();

    NodeList<Element> allImages = mRoot.getElementsByTagName("IMG");
    for (int i = 0; i < allImages.getLength(); i++) {
        ImageElement imgElem = ImageElement.as(allImages.getItem(i));

        // As long as the image has a caption, it's relevant regardless of size;
        // otherwise, it's relevant if its size is good.
        String caption = getCaption(imgElem);
        if ((caption != null && !caption.isEmpty()) || isImageRelevantBySize(imgElem)) {
            // Add relevant image to list.
            MarkupParser.Image image = new MarkupParser.Image();
            image.url = imgElem.getSrc();
            image.caption = caption;//from  w ww . j a v  a  2  s  .  c  om
            image.width = imgElem.getWidth();
            image.height = imgElem.getHeight();
            mImages.add(image);
        }
    }
}

From source file:com.fullmetalgalaxy.client.game.context.WgtContextMinimap.java

License:Open Source License

public void redraw() {
    assert GameEngine.model() != null;
    Game game = GameEngine.model().getGame();

    // if( m_lastResfreshTurn != game.getCurrentTimeStep() ||
    // m_lastResfreshGameId != game.getId() )
    {//from   w  w w. j ava2s  .c  o m
        m_lastResfreshTurn = game.getCurrentTimeStep();
        m_lastResfreshGameId = game.getId();

        canvas.setCoordinateSpaceWidth(game.getLandWidth() * 8);
        canvas.setCoordinateSpaceHeight(game.getLandHeight() * 8 + 4);

        Context2d gc = canvas.getContext2d();
        gc.clearRect(0, 0, game.getLandWidth(), game.getLandHeight());

        // draw lands
        ImageElement[] images = new ImageElement[LandType.values().length];
        for (int iLand = 0; iLand < LandType.values().length; iLand++) {
            LandType land = LandType.values()[iLand];
            Image img = new Image("/images/board/" + game.getPlanetType().getFolderName() + "/minimap/"
                    + land.getImageName(game.getCurrentTide()));
            img.addLoadHandler(new LoadHandler() {
                @Override
                public void onLoad(LoadEvent event) {
                    m_lastResfreshTurn = -1;
                    m_lastResfreshGameId = -1;
                }
            });
            images[iLand] = ImageElement.as(img.getElement());
            Image.prefetch(img.getUrl());
        }
        for (int ix = 0; ix < game.getLandWidth(); ix++) {
            for (int iy = 0; iy < game.getLandHeight(); iy++) {
                if (game.getLand(ix, iy) == LandType.Montain) {
                    gc.drawImage(images[game.getLand(ix, iy).ordinal()], ix * 8, iy * 8 + (ix % 2) * 4, 8, 8);
                } else {
                    gc.drawImage(images[game.getLand(ix, iy).ordinal()], ix * 8, iy * 8 + (ix % 2) * 4, 8, 8);
                }
            }
        }

        // draw units
        for (EbToken token : game.getSetToken()) {
            if (token.getLocation() == Location.Board && token.getColor() != EnuColor.None) {
                gc.drawImage(tokenImages[token.getColor()], token.getPosition().getX() * 8,
                        token.getPosition().getY() * 8 + (token.getPosition().getX() % 2) * 4, 8, 8);
                for (AnBoardPosition position : token.getExtraPositions(game.getCoordinateSystem())) {
                    gc.drawImage(tokenImages[token.getColor()], position.getX() * 8,
                            position.getY() * 8 + (position.getX() % 2) * 4, 8, 8);
                }
            }
        }
    }

    if (game.getStatus() == GameStatus.Open || game.getStatus() == GameStatus.Pause) {
        m_panel.add(new Image(Icons.s_instance.pause32()), FmpConstant.miniMapWidth / 2 - 16,
                FmpConstant.miniMapHeight / 2 - 16);
        m_panel.add(new Label("En Pause"), 0, FmpConstant.miniMapHeight / 2 + 30);
    } else if (game.isFinished()) {
        m_panel.add(new Label("Partie termine"), 0, FmpConstant.miniMapHeight / 2 - 40);
        m_panel.add(new Image(Icons.s_instance.winner32()), FmpConstant.miniMapWidth / 2 - 16,
                FmpConstant.miniMapHeight / 2 - 16);
        String strWinner = "";
        EbTeam winnerTeam = game.getWinnerTeam();
        if ((winnerTeam != null)) {
            strWinner += winnerTeam.getCompany().getFullName() + ":\n";
            for (EbRegistration registration : winnerTeam.getPlayers(game.getPreview()))
                if (registration.haveAccount()) {
                    strWinner += registration.getAccount().getPseudo() + "\n";
                }
        }
        m_panel.add(new Label(strWinner), 0, FmpConstant.miniMapHeight / 2 + 30);
    }

}

From source file:com.google.gwt.sample.userwatcher.client.FileUploaderWidget_v2.java

private void upload(final Image image) {

    Canvas canvasTmp = Canvas.createIfSupported();
    canvasTmp.setCoordinateSpaceHeight((int) image.getHeight());
    canvasTmp.setCoordinateSpaceWidth((int) image.getWidth());
    Context2d context = canvasTmp.getContext2d();
    ImageElement imageElement = ImageElement.as(image.getElement());
    context.drawImage(imageElement, 0, 0);

    String contentType = "image/jpeg";

    String fileBase64 = canvasTmp.toDataUrl(contentType);

    UploadImage iu = new UploadImage(cp);
    iu.setFile(1234568759L, fileName, contentType, fileBase64);

    // TODO enable this if your testing it!!!!!!!!!!
    iu.upload();//  w  ww . j  av  a 2  s . c  o m

    iu.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            UploadImage u = (UploadImage) event.getSource();
            int e = u.getChangeEvent();
            fireChange(e);
        }
    });
}

From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java

public static ImageData cropImage(Image image, double sx, double sy, double sw, double sh) {

    Canvas canvasTmp = Canvas.createIfSupported();
    Context2d context = canvasTmp.getContext2d();

    canvasTmp.setCoordinateSpaceHeight((int) sh + 10);
    canvasTmp.setCoordinateSpaceWidth((int) sw + 10);

    ImageElement imageElement = ImageElement.as(image.getElement());

    double dx = 0;
    double dy = 0;
    double dw = sw;
    double dh = sh;

    // draw image to canvas
    context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh);

    // get image data
    double w = sw;
    double h = sh;
    ImageData imageData = context.getImageData(0, 0, w, h);

    canvasTmp.removeFromParent();//from  ww  w . j  ava 2  s . c  o  m

    return imageData;
}

From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java

public static ImageData scaleAndCropImage(Image image, double scaleToRatio, double sx, double sy, double sw,
        double sh) {

    Canvas canvasTmp = Canvas.createIfSupported();
    //RootPanel.get().add(canvasTmp);
    Context2d context = canvasTmp.getContext2d();

    double ch = (image.getHeight() * scaleToRatio) + 100;
    double cw = (image.getWidth() * scaleToRatio) + 100;

    canvasTmp.setCoordinateSpaceHeight((int) ch);
    canvasTmp.setCoordinateSpaceWidth((int) cw);

    ImageElement imageElement = ImageElement.as(image.getElement());

    // tell it to scale image
    context.scale(scaleToRatio, scaleToRatio);

    // draw image to canvas
    // s = source
    // d = destination     
    double dx = 0;
    double dy = 0;
    context.drawImage(imageElement, dx, dy);

    // get image data - if you go greater than the scaled image nothing will show up
    ImageData imageData = context.getImageData(sx, sy, sw, sh);

    return imageData;
}

From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java

/**
 * image - an ImageElement object/*  w  w w .j  a  va2  s.c om*/
 * 
  sx - the x coordinate of the upper-left corner of the source rectangle
  sy - the y coordinate of the upper-left corner of the source rectangle
  sw - the width of the source rectangle
  sh - the width of the source rectangle
  dx - the x coordinate of the upper-left corner of the destination rectangle
  dy - the y coordinate of the upper-left corner of the destination rectangle
  dw - the width of the destination rectangle
  dh - the height of the destination rectangle
        
 */
public static ImageData scaleImage(Image image, double scaleToRatio) {

    //System.out.println("PanoTiler.scaleImag()e: scaleToRatio=" + scaleToRatio + " width=" + width + " x height=" + height);

    Canvas canvasTmp = Canvas.createIfSupported();
    Context2d context = canvasTmp.getContext2d();

    double ch = (image.getHeight() * scaleToRatio) + 100; // 100 is offset so it doesn't throw
    double cw = (image.getWidth() * scaleToRatio) + 100;

    canvasTmp.setCoordinateSpaceHeight((int) ch);
    canvasTmp.setCoordinateSpaceWidth((int) cw);

    ImageElement imageElement = ImageElement.as(image.getElement());

    // s = source
    // d = destination 
    double sx = 0;
    double sy = 0;
    double sw = imageElement.getWidth();
    double sh = imageElement.getHeight();

    double dx = 0;
    double dy = 0;
    double dw = imageElement.getWidth();
    double dh = imageElement.getHeight();

    // tell it to scale image
    context.scale(scaleToRatio, scaleToRatio);

    // draw image to canvas
    context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh);

    // get image data
    double w = dw * scaleToRatio;
    double h = dh * scaleToRatio;
    ImageData imageData = context.getImageData(0, 0, w, h); // this won't get the extra 100

    return imageData;
}