Example usage for com.google.gwt.user.client.ui Image getWidth

List of usage examples for com.google.gwt.user.client.ui Image getWidth

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Gets the width of the image.

Usage

From source file:at.ait.dme.yuma.client.Application.java

License:EUPL

/**
 * show the header (search field and logo)
 *//*from w ww . j a va2s . c  om*/
private void showHeader() {
    if (Application.isInTileMode())
        return;

    final HorizontalPanel hPanel = new HorizontalPanel();

    // removed the search since it's not needed by europeana
    // show the search field      
    /*final TextBox searchTerm = new TextBox();
    searchTerm.setStyleName("imageAnnotation-search-term");
    searchTerm.addKeyDownHandler(new KeyDownHandler() {
       public void onKeyDown(KeyDownEvent event) {
    if(event.getNativeKeyCode()==KeyCodes.KEY_ENTER)
       startSearch(searchTerm.getText());
       }
    });
    hPanel.add(searchTerm);
            
    // show the search button
    Button search = new Button(getConstants().annotationSearch());
    search.setStyleName("imageAnnotation-search");
    search.addClickHandler(new ClickHandler() {
       public void onClick(ClickEvent event) {
    startSearch(searchTerm.getText());
       }   
    });
    hPanel.add(search);*/

    // show the logo
    String dbName = getDatabaseName();
    if (dbName == null)
        dbName = "ait";
    String logoPath = "images/" + dbName + ".gif";
    final Image logo = new Image(logoPath);
    // workaround for IE caching issue see 
    // http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/11851753ba99454d/6079e2e2b9aea4bf
    DOM.setElementAttribute(logo.getElement(), "src", logoPath);

    // see also http://code.google.com/p/google-web-toolkit/issues/detail?id=2149
    if (logo.getWidth() > 0) {
        RootPanel.get().add(hPanel, logo.getWidth() + 20, 50);
    } else {
        logo.addLoadHandler(new LoadHandler() {
            public void onLoad(LoadEvent event) {
                RootPanel.get().add(hPanel, logo.getWidth() + 20, 50);
            }
        });
    }
    RootPanel.get().add(logo, 10, 10);
}

From source file:com.data2semantics.yasgui.client.openid.OpenId.java

License:Open Source License

private VLayout getProviderCanvas(final OpenIdProvider provider) {
    //use core google img class to get size of image. then pass it on the smartgwt (blegh)
    com.google.gwt.user.client.ui.Image gwtImg = new com.google.gwt.user.client.ui.Image(
            "images/" + provider.getImageLocation());
    final VLayout providerContainer = new VLayout();

    if (gwtImg.getWidth() > 0 && gwtImg.getHeight() > 0) {
        //to avoid dividing by zero
        int width = provider.getMaxIconHeight() * (gwtImg.getWidth() / gwtImg.getHeight());
        int height = provider.getMaxIconHeight();
        providerContainer.setPadding(15);
        providerContainer.setMargin(10);
        providerContainer.setWidth(width + 5);
        providerContainer.setHeight(WINDOW_HEIGHT - 100);
        providerContainer.setAlign(Alignment.CENTER);
        providerContainer.setStyleName("providerContainer");
        Img providerImg = new Img(provider.getImageLocation(), width, height);
        if (provider.getUrl() == null) {

            providerContainer.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    if (providerContainer.getMembers().length == 2) {//might be added already
                        HLayout formLayout = new HLayout();
                        DynamicForm form = new DynamicForm();

                        final TextItem textItem = new TextItem();
                        textItem.setHint("http://openIdProvider.org");
                        textItem.setShowHintInField(true);
                        textItem.setWidth(150);
                        textItem.setShowTitle(false);
                        form.setTitleOrientation(TitleOrientation.TOP);
                        form.setItems(textItem);

                        Button authenticateButton = new Button("submit");
                        authenticateButton.setWidth(40);
                        authenticateButton.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event) {
                                view.getOpenId().login(textItem.getValueAsString());
                            }//from   www  . ja  v a  2  s . com
                        });
                        formLayout.addMember(form);
                        formLayout.addMember(authenticateButton);
                        providerContainer.addMember(formLayout);
                    }
                }
            });

        } else {
            providerImg.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    view.getOpenId().login(provider.getUrl());
                }
            });
        }
        providerImg.setCursor(Cursor.POINTER);
        providerContainer.setCursor(Cursor.POINTER);

        HTMLFlow text = new HTMLFlow("log in with");
        text.setCursor(Cursor.POINTER);
        providerContainer.addMember(text);
        providerContainer.addMember(providerImg);
    }
    return providerContainer;
}

From source file:com.fullmetalgalaxy.client.game.board.WgtBoardLayerBase.java

License:Open Source License

/**
 * set position of a widget as the widget is centered on the given position.
 * @param p_w//w  w w .j a v  a2 s . c  om
 * @param p_wgtPixPosition position in pixel
 */
public void setWidgetPixPosition(Image p_w, AnPair p_wgtPixPosition) {
    super.setWidgetPosition(p_w, p_wgtPixPosition.getX() - p_w.getWidth() / 2,
            p_wgtPixPosition.getY() - p_w.getHeight() / 2);
    // p_w.setVisible( true );
}

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

License:Open Source License

public void redraw() {
    assert GameEngine.model() != null;
    EventsPlayBuilder actionBuilder = GameEngine.model().getActionBuilder();
    if (actionBuilder.getLastUpdate().getTime() != m_actionLastUpdate) {
        assert GameEngine.model() != null;
        m_panel.clear();/*from  w ww  .  ja  va 2  s.com*/
        m_actionLastUpdate = actionBuilder.getLastUpdate().getTime();

        Image wgtToken = new Image(TokenImages.getTokenImage(actionBuilder.getSelectedToken(), EnuZoom.Medium));
        /*wgtToken.setUrl( FmpConstant.getTokenUrl( selectedToken, new EnuZoom( EnuZoom.Medium ) ) );
        wgtToken.setPixelSize( 70, 70 );*/
        wgtToken.setTitle(Messages.getTokenString(0, actionBuilder.getSelectedToken()));

        // m_vPanel.add( new HTML( "<center>" ) );
        AbsolutePanel absPanel = new AbsolutePanel();
        m_panel.add(absPanel);
        absPanel.setSize("100%", "100%");
        absPanel.add(wgtToken, absPanel.getOffsetWidth() / 2 - wgtToken.getWidth() / 2,
                absPanel.getOffsetHeight() / 2 - wgtToken.getHeight() / 2 + 30);
        absPanel.add(new HTML("<b>" + Messages.getTokenString(0, actionBuilder.getSelectedToken()) + "</b>"), 0,
                0);
        if (actionBuilder.getSelectedToken().getColor() != EnuColor.None) {
            EbRegistration player = GameEngine.model().getGame()
                    .getRegistrationByColor(actionBuilder.getSelectedToken().getColor());
            if (player != null && player.haveAccount()) {
                absPanel.add(new HTML(player.getAccount().getPseudo()), 0, 20);
            }
        }

        // display land under token
        AnBoardPosition position = GameEngine.model().getActionBuilder().getSelectedPosition();
        if (position != null) {
            String landStr = Messages.getLandString(0, GameEngine.model().getGame().getLand(position));
            if (GameEngine.model().getGame().getToken(position, TokenType.Pontoon) != null) {
                landStr += " & " + Messages.getTokenString(0, TokenType.Pontoon);
            }
            if (GameEngine.model().getGame().getToken(position, TokenType.Sluice) != null) {
                landStr += " & " + Messages.getTokenString(0, TokenType.Sluice);
            }
            absPanel.add(new HTML(landStr), 0, 40);

        }

        // display ore count for freither
        EbToken token = GameEngine.model().getActionBuilder().getSelectedToken();
        if (token != null && token.getType() == TokenType.Freighter) {
            absPanel.add(new HTML(Messages.getTokenString(0, TokenType.Ore) + " : " + token.getContainOre()),
                    150, 0);
            if (token.getBulletCount() > 0) {
                absPanel.add(new HTML(MAppBoard.s_messages.repairTurret() + " : " + token.getBulletCount()),
                        150, 30);
            }
        } else if (token != null && token.getType().isDestroyer()) {
            absPanel.add(new HTML(MAppBoard.s_messages.bullet() + " : " + token.getBulletCount()), 150, 0);
        } else if (token != null && token.getType() == TokenType.WeatherHen) {
            absPanel.add(new HTML(MAppBoard.s_messages.construct() + " : " + token.getBulletCount()), 150, 0);
        } else if (token != null
                && (token.getType() == TokenType.Ore2Generator || token.getType() == TokenType.Ore3Generator)) {
            float percentage = 0;
            if (GameEngine.model().getGame().getEbConfigGameTime().isParallel()) {
                percentage = token.getBulletCount() / (2 * FmpConstant.oreGenerationInTurn + 1);
            } else {
                percentage = token.getBulletCount()
                        / (GameEngine.model().getGame().countTeamOnBoard() * FmpConstant.oreGenerationInTurn
                                + 1);
            }
            absPanel.add(new HTML((int) (percentage * 100) + "%"), 200, 0);
        }
        // m_vPanel.add( new HTML( "</center>" ) );
    }
}

From source file:com.google.appinventor.client.editor.simple.components.Mockmicomponente.java

License:Open Source License

private void setPictureProperty(String text) {
    picturePropValue = text;//from www .j  a v  a 2s .c om
    String url = convertImagePropertyValueToUrl(text);
    if (url == null) {
        // text was not recognized as an asset. Just display the icon for this type of component.
        Image iconImage = getIconImage();
        image.setUrlAndVisibleRect(iconImage.getUrl(), iconImage.getOriginLeft(), iconImage.getOriginTop(),
                iconImage.getWidth(), iconImage.getHeight());
    } else {
        image.setUrl(url);
    }
}

From source file:com.google.code.gwt.crop.client.GWTCropper.java

License:Apache License

/**
 * Adds a canvas with background image./*from  ww  w .ja v  a 2 s.  c  om*/
 * 
 * @param src - image URL
 */
private void addCanvas(final String src) {

    super.setStyleName(bundleResources.css().base());

    final Image image = new Image(src);
    image.setStyleName(bundleResources.css().imageCanvas());
    image.addLoadHandler(new LoadHandler() {

        public void onLoad(LoadEvent event) {

            //this is a bug in IE since v.8 - maxWidth collapse image 
            //and you cannot read its width - in some cases depends from CSS image extensions
            image.getElement().getStyle().setProperty("maxWidth", "none");

            // get original image size
            if (nOuterWidth == -1)
                nOuterWidth = image.getWidth();
            if (nOuterHeight == -1)
                nOuterHeight = image.getHeight();

            DOM.setElementProperty(image.getElement(), "width", nOuterWidth + "");
            DOM.setElementProperty(image.getElement(), "height", nOuterHeight + "");
            image.getElement().getStyle().setPropertyPx("maxWidth", nOuterWidth);
            image.getElement().getStyle().setPropertyPx("maxHeight", nOuterHeight);

            _container.setWidth(nOuterWidth + "px");
            _container.setHeight(nOuterHeight + "px");
            addSelection(src);

            setSize(nOuterWidth, nOuterHeight);

            if (null != onCanvasLoadHandler)
                onCanvasLoadHandler.onLoad(event);

            if (null != previewWidget) {
                previewWidget.init(src, nOuterWidth, nOuterHeight, aspectRatio);
            }

            updatePreviewWidget();
        }

    });
    this._container.add(image, 0, 0);
    this.add(this._container);
}

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

private void drawThumbToScreen(Image image) {

    int size = 75;

    int width = image.getWidth();
    int height = image.getHeight();

    double scaleToRatio = 0.50D; // TODO oops, getting image loading problem. event loading, fix later...

    ImageData imageDataForThumb = ImageUtils.scaleImage(image, scaleToRatio);

    // for debugging
    Canvas canvasTmp = Canvas.createIfSupported();
    canvasTmp.setCoordinateSpaceHeight((int) imageDataForThumb.getHeight());
    canvasTmp.setCoordinateSpaceWidth((int) imageDataForThumb.getWidth());
    Context2d context = canvasTmp.getContext2d();
    context.putImageData(imageDataForThumb, 0, 0);
    pThumb.add(canvasTmp);//  www .ja  va  2  s .  c om

    canvasTmp.addStyleName("test2");
}

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 w w . ja va2  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 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//from  www  . j  a v  a 2s  .  co m
 * 
  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;
}