Example usage for com.google.gwt.resources.client ImageResource getSafeUri

List of usage examples for com.google.gwt.resources.client ImageResource getSafeUri

Introduction

In this page you can find the example usage for com.google.gwt.resources.client ImageResource getSafeUri.

Prototype

SafeUri getSafeUri();

Source Link

Document

Returns the URL for the composite image that contains the ImageResource.

Usage

From source file:bingo.client.Bingo.java

License:Open Source License

/**
 * This is the entry point method./*from   www .j  av a  2 s .  c  o  m*/
 */
public void onModuleLoad() {
    Label titleLabel = new Label();
    titleLabel.setText(strings.title());
    RootPanel.get("title").add(titleLabel);

    // This is the general notification text box
    RootPanel.get("message").add(message);

    // Cheking if the user has already an user id
    final String cookie = Cookies.getCookie(COOKIE_ID);

    // Validating the cookie
    bingoService.statusUserId(cookie, new AsyncCallback<Integer>() {
        @Override
        public void onFailure(Throwable caught) {
            message.setText(caught.getMessage());
            Cookies.removeCookie(COOKIE_ID);
        }

        @Override
        public void onSuccess(Integer status) {
            // TODO: Control the logged status (I should not get a user if s/he is already logged)
            if (status.intValue() == BingoService.NO_LOGGED || status.intValue() == BingoService.LOGGED) {
                bingoService.getUserId(new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(strings.errorUserCreation());
                    }

                    @Override
                    public void onSuccess(String result) {
                        userId = result;
                    }
                });

                message.setHTML("");

                // Showing image to enter
                ImageResource imageResource = BingoResources.INSTANCE.entry();
                Image entryImage = new Image(imageResource.getSafeUri());
                RootPanel.get("buttons").add(entryImage);

                // Selecting behavior (admin / voter) 
                HorizontalPanel entryPoint = new HorizontalPanel();

                entryPoint.setStyleName("mainSelectorPanel");
                entryPoint.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.setSpacing(50);

                // 
                // CREATING A BINGO
                //
                VerticalPanel leftPanel = new VerticalPanel();
                leftPanel.setStyleName("selectorPanel");

                Label leftPanelTitle = new Label();
                leftPanelTitle.setStyleName("selectorPanelTitle");
                leftPanelTitle.setText(strings.leftPanelTitle());
                leftPanel.add(leftPanelTitle);
                leftPanel.setCellHorizontalAlignment(leftPanelTitle, HasHorizontalAlignment.ALIGN_CENTER);

                Grid leftSubPanel = new Grid(2, 2);
                leftSubPanel.setWidget(0, 0, new Label(strings.createBingoName()));
                final TextBox bingoNameBox = new TextBox();
                leftSubPanel.setWidget(0, 1, bingoNameBox);

                leftSubPanel.setWidget(1, 0, new Label(strings.createBingoPassword()));
                final PasswordTextBox bingoPasswordBox = new PasswordTextBox();
                leftSubPanel.setWidget(1, 1, bingoPasswordBox);
                leftPanel.add(leftSubPanel);

                final Button createButton = new Button("Create");
                createButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        bingoService.createBingo(userId, bingoNameBox.getText(), bingoPasswordBox.getText(),
                                new AsyncCallback<String>() {
                                    @Override
                                    public void onFailure(Throwable caught) {
                                        message.setText(caught.getMessage());
                                    }

                                    @Override
                                    public void onSuccess(final String gameId) {
                                        final BingoGrid bingoGrid = new BingoGrid();
                                        initAdminGrid(userId, bingoGrid, false);
                                        RootPanel.get("bingoTable").clear();
                                        RootPanel.get("bingoTable").add(bingoGrid);
                                        message.setText(strings.welcomeMessageCreation());

                                        // Setting the cookie
                                        Date expirationDate = new Date();
                                        expirationDate.setHours(expirationDate.getHours() + EXPIRATION_VALUE);
                                        Cookies.setCookie(COOKIE_ID, userId, expirationDate);
                                    }
                                });
                    }
                });
                leftPanel.add(createButton);
                leftPanel.setCellHorizontalAlignment(createButton, HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.add(leftPanel);

                // 
                // JOINING
                //
                VerticalPanel rightPanel = new VerticalPanel();
                rightPanel.setStyleName("selectorPanel");

                Label rightPanelTitle = new Label();
                rightPanelTitle.setStyleName("selectorPanelTitle");
                rightPanelTitle.setText(strings.rightPanelTitle());
                rightPanel.add(rightPanelTitle);
                rightPanel.setCellHorizontalAlignment(rightPanelTitle, HasHorizontalAlignment.ALIGN_CENTER);

                Grid rightSubPanel = new Grid(2, 2);
                rightSubPanel.setWidget(0, 0, new Label(strings.joinToBingoName()));
                final ListBox joinExistingBingoBox = new ListBox();
                bingoService.getBingos(new AsyncCallback<String[][]>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        joinExistingBingoBox.addItem(strings.noBingos());
                    }

                    @Override
                    public void onSuccess(String[][] result) {
                        if (result == null) {
                            joinExistingBingoBox.addItem(strings.noBingos());
                        } else {
                            for (int i = 0; i < result.length; i++) {
                                String gameName = result[i][0];
                                String gameId = result[i][1];
                                joinExistingBingoBox.addItem(gameName, gameId);
                            }
                        }
                    }
                });
                rightSubPanel.setWidget(0, 1, joinExistingBingoBox);

                rightSubPanel.setWidget(1, 0, new Label(strings.joinToBingoPassword()));
                final PasswordTextBox joinBingoPasswordBox = new PasswordTextBox();
                rightSubPanel.setWidget(1, 1, joinBingoPasswordBox);
                rightPanel.add(rightSubPanel);

                final Button joinButton = new Button("Join");
                joinButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        int index = joinExistingBingoBox.getSelectedIndex();
                        if (index < 0)
                            message.setText(strings.noSelectedItem());
                        else {
                            final String gameId = joinExistingBingoBox.getValue(index);
                            if (gameId == null)
                                message.setText(strings.noSelectedItem());
                            else {
                                bingoService.joinBingo(userId, gameId, joinBingoPasswordBox.getText(),
                                        new AsyncCallback<Void>() {
                                            @Override
                                            public void onFailure(Throwable caught) {
                                                message.setText(caught.getMessage());
                                            }

                                            @Override
                                            public void onSuccess(Void result) {
                                                final BingoGrid bingoGrid = new BingoGrid();
                                                initUserGrid(bingoGrid);
                                                RootPanel.get("bingoTable").clear();
                                                RootPanel.get("bingoTable").add(bingoGrid);

                                                message.setText(strings.welcomeMessageJoin());

                                                // Setting the cookie
                                                Date expirationDate = new Date();
                                                expirationDate
                                                        .setHours(expirationDate.getHours() + EXPIRATION_VALUE);
                                                Cookies.setCookie(COOKIE_ID, userId, expirationDate);
                                            }
                                        });
                            }
                        }
                    }
                });
                rightPanel.add(joinButton);
                rightPanel.setCellHorizontalAlignment(joinButton, HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.add(rightPanel);

                RootPanel.get("bingoTable").add(entryPoint);

            } else if (status.intValue() == BingoService.ADMIN) {
                message.setText("Detected cookie: " + cookie + " as admin");
                userId = cookie;

                bingoService.statusBingo(userId, new AsyncCallback<Integer>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Integer result) {
                        int status = result.intValue();
                        final BingoGrid bingoGrid = new BingoGrid();
                        if (status == BingoService.RUNNING) {
                            initAdminGrid(userId, bingoGrid, false);
                            message.setText(strings.welcomeMessageCreation());
                        } else if (status == BingoService.FINISHED) {
                            initAdminGrid(userId, bingoGrid, true);
                            message.setText(strings.finishMessage());
                        }
                        RootPanel.get("bingoTable").clear();
                        RootPanel.get("bingoTable").add(bingoGrid);
                    }
                });

            } else if (status.intValue() == BingoService.PARTICIPANT) {
                message.setText("Detected cookie: " + cookie + " as participant");
                userId = cookie;

                final BingoGrid bingoGrid = new BingoGrid();
                initUserGrid(bingoGrid);
                updateUserGrid(bingoGrid, null);
                RootPanel.get("bingoTable").clear();
                RootPanel.get("bingoTable").add(bingoGrid);
            }
        }
    });
}

From source file:bingo.client.BingoGrid.java

License:Open Source License

private void initGrid() {
    cells = new BingoCell[ROW][COL];

    this.setCellPadding(5);

    String cellKey = "";
    for (int row = 0; row < ROW; ++row)
        for (int col = 0; col < COL; ++col) {
            cellKey = "cell" + row + col;

            // Getting the picture
            ImageResource imageResource = getImageResource(row, col);

            // Getting the text
            String cellString = strings.map().get(cellKey);

            BingoCell bingoCell = new BingoCell(imageResource.getSafeUri(), cellString, "");

            // Building the panel
            this.setWidget(row, col, bingoCell);
            cells[row][col] = bingoCell;

            this.getCellFormatter().setStyleName(row, col, "cell-noselected");
            this.getCellFormatter().setHorizontalAlignment(row, col, HasHorizontalAlignment.ALIGN_CENTER);
            this.getCellFormatter().setVerticalAlignment(row, col, HasVerticalAlignment.ALIGN_MIDDLE);
            this.getCellFormatter().setWidth(row, col, CELL_WIDTH);
            this.getCellFormatter().setHeight(row, col, CELL_HEIGHT);
        }/*  w  w w . jav  a  2 s .c o  m*/
}

From source file:cc.kune.polymer.client.actions.ui.AbstractPoAllButtonGui.java

License:GNU Affero Public License

@Override
public void setIconResource(final ImageResource image) {
    ((HasIcon) icon).setIconSrc(image.getSafeUri().asString());
}

From source file:cc.kune.polymer.client.actions.ui.AbstractPoButtonGui.java

License:GNU Affero Public License

@Override
public void setIconResource(final ImageResource image) {
    if (hasIcon) {
        icon.setIconSrc(image.getSafeUri().asString());
    }/*from  w ww  . ja  v a 2  s .c  o  m*/
}

From source file:co.fxl.gui.gwt.GWTDisplay.java

License:Open Source License

private void declareConstants() {

    // TODO replace with Env.is(...) declarations in the respective widgets

    Constants.put("TableViewTemplate.CORRECT_HEIGHT", !isInternetExplorer);
    // if (isInternetExplorer()) {
    // Constants.put("DashboardPagePage.HEIGHT_DECREMENT", 3);
    // Constants.put("DashboardPagePage.HEIGHT_CONTENT_DECREMENT", 30);
    // }// w w w.  j av a  2 s  .co m
    if (isFirefox) {
        Constants.put("ScrollTableWidgetImpl.ADD_TOP_PANEL_TOP_PADDING", true);
        if (isFirefox3) {
            Constants.put("FormWidgetImpl.FIXED_WIDTH", true);
            Constants.put("NavigationItemImpl.USE_TEMP_FLIP", false);
        }
    }
    if (isOpera)
        Constants.put("ScrollTableWidgetImpl.ADD_TOP_PANEL_SPACING", true);
    // if (isFirefox() || isOpera()) {
    // Constants.put("MiniFilterPanel.MODIFIED_TITLE_ADD", true);
    // }
    final boolean isChrome15Plus = isChrome && getBrowserVersion() >= 15;
    final String imagePath = Constants.get("GWTLazyTreeWidget.IMAGE_PATH",
            (isChrome15Plus ? "" : GWT.getModuleBaseURL()) + "images/");
    Constants.put("ImagePathResolver", new ImagePathResolver() {
        @Override
        public String resolve(String resource) {
            if (isChrome15Plus) {
                ImageResource ir = GWTImage.resolve(resource);
                if (ir != null)
                    return ir.getSafeUri().asString();
            }
            return imagePath + resource;
        }
    });
}

From source file:com.ait.lienzo.client.core.shape.AbstractImageShape.java

License:Open Source License

protected AbstractImageShape(final ShapeType type, final ImageResource resource, final boolean listening,
        final ImageSelectionMode mode) {
    this(type, resource.getSafeUri().asString(), listening, mode);
}

From source file:com.ait.lienzo.client.core.shape.Sprite.java

License:Open Source License

public Sprite(final ImageResource resource, double rate, SpriteBehaviorMap bmap, String behavior) {
    super(ShapeType.SPRITE);

    setURL(resource.getSafeUri().asString()).setTickRate(rate).setSpriteBehaviorMap(bmap)
            .setSpriteBehavior(behavior);

    new ImageLoader(resource) {
        @Override/* w  w  w. j a  v a 2s . c  o m*/
        public void onLoad(ImageElement sprite) {
            m_sprite = sprite;

            if (null != m_loaded) {
                m_loaded.onSpriteLoaded(Sprite.this);
            }
        }

        @Override
        public void onError(String message) {
            LienzoCore.get().log("Sprite could not load resource " + resource.getName() + " " + message);
        }
    };
}

From source file:com.brazoft.foundation.gwt.client.ui.Image.java

License:Apache License

public Image src(ImageResource resource) {
    return this.src(resource.getSafeUri().asString());
}

From source file:com.emitrom.lienzo.client.core.shape.json.ResourceResolver.java

License:Open Source License

protected String getURL(ImageResource resource) {
    return resource.getSafeUri().asString();
}

From source file:com.emitrom.lienzo.client.core.shape.Picture.java

License:Open Source License

protected Picture(ImageResource resource, boolean load, boolean listening, String pictureCategory) {
    this(resource.getSafeUri().asString(), load, listening, pictureCategory);
    // resource.getSafeUri().asString() is the same as resource.getURL() - which is deprecated
}