Example usage for com.vaadin.ui Image Image

List of usage examples for com.vaadin.ui Image Image

Introduction

In this page you can find the example usage for com.vaadin.ui Image Image.

Prototype

public Image(String caption, Resource source) 

Source Link

Document

Creates a new Image whose contents is loaded from given resource.

Usage

From source file:org.inakirj.imagerulette.screens.DiceGallerySetupView.java

License:Open Source License

/**
 * Adds the row.// www.  java 2  s .  c o m
 */
public void addRow(String urlEntry) {
    DiceItem itemCreated = new DiceItem();
    Button validateButton = new Button();
    validateButton.setIcon(FontAwesome.CHECK_CIRCLE_O);
    validateButton.addClickListener(e -> validateUrl(itemCreated));
    itemCreated.setValidateImg(validateButton);
    Image imgRow = null;
    String url = null;
    if (urlEntry != null) {
        StringTokenizer urlEntryTokenizer = new StringTokenizer(urlEntry, " ");
        url = urlEntryTokenizer.nextToken();
        ExternalResource resource = new ExternalResource(url);
        imgRow = new Image("", resource);
        itemCreated.setId(getNextId());
    } else {
        imgRow = new Image("", null);
    }
    imgRow.addStyleName("dice-image");
    imgRow.addStyleName("dice-align-center");
    itemCreated.setImg(imgRow);
    TextField textRow = new TextField();
    textRow.addStyleName("url-style");
    if (url != null) {
        textRow.setValue(url);
        validateButton.setIcon(FontAwesome.CHECK_CIRCLE);
    }
    itemCreated.setUrl(textRow);
    if (urlEntry != null) {
        itemCreated.getUrl().setEnabled(false);
    }
    itemCreated.setValid(imgRow != null);

    Button deleteButton = new Button();
    deleteButton.setIcon(FontAwesome.TRASH);
    itemCreated.setDeleteImg(deleteButton);
    deleteButton.addClickListener(e -> deleteUrl(itemCreated));

    newDataSource.addBean(itemCreated);
    hasReachLimitImages = newDataSource.size() == TOTAL_URL_LIMIT;
}

From source file:org.inakirj.imagerulette.screens.DiceGallerySetupView.java

License:Open Source License

/**
 * Validate url.//from   ww  w . jav a 2s  .c om
 *
 * @param itemCreated
 *            the item created
 */
private void validateUrl(DiceItem item) {
    boolean isValid = false;
    String urlInput = item.getUrl().getValue();
    if (urlInput != null && ImageUtils.isValidImageURI(urlInput)) {
        Image imgRow = null;
        if (urlInput != null) {
            ExternalResource resource = new ExternalResource(urlInput);
            imgRow = new Image("", resource);
            imgRow.addStyleName("dice-image");
            isValid = true;
            CookieManager cm = new CookieManager();
            cm.saveAllURLs(newDataSource.getItemIds().stream().map(di -> di.getUrl().getValue())
                    .collect(Collectors.toList()));
        }
        item.setImg(imgRow);
    }
    item.setValid(isValid);
    if (isValid) {
        item.getUrl().setEnabled(false);
    }
    newDataSource.sort(propertyIds, ascendingIds);
}

From source file:org.inakirj.imagerulette.screens.DicePlayView.java

License:Open Source License

/**
 * Sets the layout.//  w  ww.java  2 s .c  om
 */
private void setLayout() {
    mainLayout = new VerticalLayout();
    mainLayout.setWidth(100, Unit.PERCENTAGE);
    FileResource resource = new FileResource(new File(
            VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/WEB-INF/image/nope.png"));
    Image none = new Image("", resource);
    randomImgToBeReplaced = none;
    randomImgToBeReplaced.setWidth(78, Unit.PIXELS);
    randomImgToBeReplaced.setHeight(81, Unit.PIXELS);
    randomImgToBeReplaced.addStyleName("random-image");

    imageLayout = new HorizontalLayout();
    imageLayout.addComponent(randomImgToBeReplaced);
    imageLayout.setWidth(100, Unit.PERCENTAGE);
    imageLayout.setComponentAlignment(randomImgToBeReplaced, Alignment.TOP_CENTER);

    Button rollBtn = new Button();
    rollBtn.addClickListener(e -> onPickABallClick());
    rollBtn.setWidth(25, Unit.PERCENTAGE);
    rollBtn.setHeight(50, Unit.PIXELS);
    rollBtn.setIcon(FontAwesome.CUBE);
    rollBtn.addStyleName("dice-button-roll");

    mainLayout.addComponent(imageLayout);
    mainLayout.addComponent(rollBtn);
    mainLayout.setComponentAlignment(rollBtn, Alignment.BOTTOM_CENTER);

    calculateStats();
    addComponent(mainLayout);
}

From source file:org.inakirj.imagerulette.screens.DicePlayView.java

License:Open Source License

/**
 * Calculate stats./*ww w . j  a va 2s . c  om*/
 */
@SuppressWarnings("unchecked")
private void calculateStats() {
    long totalImagesRendered = statsImageIdOcurrencesMap.values().stream().reduce(0, Integer::sum);
    Map<Image, Double> statsRowsMap = new HashMap<Image, Double>();
    Iterator<Entry<String, Integer>> iterator = statsImageIdOcurrencesMap.entrySet().iterator();
    while (iterator.hasNext()) {
        // Left fake column
        Entry<String, Integer> entry = iterator.next();
        // @formatter:off
        Image img = lotteryList.stream().map(i -> (Image) i).filter(i -> entry.getKey().equals((i.getData())))
                .findFirst().orElse(null);
        // @formatter:on
        Image imgCopy = new Image("", img.getSource());
        imgCopy.addStyleName("dice-image-stats");
        double label = getCalculation(entry.getValue(), totalImagesRendered);
        statsRowsMap.put(imgCopy, label);
    }
    Table popupContent;
    if (statsLayout == null) {
        popupContent = new Table() {

            /** The Constant serialVersionUID. */
            private static final long serialVersionUID = -7151527404141301908L;

            @Override
            protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
                if (colId.equals(oddCol)) {
                    return super.formatPropertyValue(rowId, colId, property) + " %";
                }
                return super.formatPropertyValue(rowId, colId, property);
            }

        };
        popupContent.setSortEnabled(false);
        popupContent.addStyleName("stats-table");
        popupContent.setWidth(100, Unit.PERCENTAGE);
        popupContent.addContainerProperty(imageCol, Image.class, null);
        popupContent.addContainerProperty(oddCol, BigDecimal.class, null);
        popupContent.setColumnExpandRatio(imageCol, 3);
        popupContent.setColumnExpandRatio(oddCol, 7);
    } else {
        popupContent = statsLayout;
        popupContent.removeAllItems();
    }
    statsRowsMap.entrySet().stream().forEach(entry -> {
        Item row1 = popupContent.getItem(popupContent.addItem());
        row1.getItemProperty(imageCol).setValue(entry.getKey());
        BigDecimal bg = BigDecimal.valueOf(entry.getValue());
        row1.getItemProperty(oddCol).setValue(bg);
    });
    popupContent.setPageLength(statsRowsMap.size());
    popupContent.sort(new String[] { oddCol }, new boolean[] { false });
    if (statsLayout == null) {
        mainLayout.addComponent(popupContent);
    } else {
        mainLayout.replaceComponent(statsLayout, popupContent);
    }
    statsLayout = popupContent;
}

From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java

License:Open Source License

/**
 * Sets the layout.//  w  w w.  ja  v  a  2  s.  c o m
 */
private void setLayout() {
    imagesLayout = new VerticalComponentGroup();
    imagesLayout.setWidth(100, Unit.PERCENTAGE);

    ImageUtils.getAllImageURL().stream().forEach(i -> {
        HorizontalLayout sliderLAyout = new HorizontalLayout();
        if (imagesLayout.getComponentCount() % 2 == 0) {
            sliderLAyout.addStyleName("dice-banner-1");
        } else {
            sliderLAyout.addStyleName("dice-banner-2");
        }
        sliderLAyout.setWidth(100, Unit.PERCENTAGE);
        Image img = new Image("", i.getSource());
        img.addStyleName("dice-image");
        img.setData(i.getData());
        Slider slider = new Slider();
        slider.addStyleName("dice-slider");
        Label total = new Label();
        total.addStyleName("size-24");// TODO is not working
        // Adding image
        sliderLAyout.addComponent(img);
        // Adding slider
        slider.setMin(0);
        slider.setMax(5);
        slider.setWidth(80, Unit.PERCENTAGE);
        slider.addValueChangeListener(s -> {
            total.setValue("x " + slider.getValue().intValue());
            enableDiceTabOrNot();
        });
        sliderLAyout.addComponent(slider);
        // Adding label
        total.setValue("x 0");
        sliderLAyout.addComponent(total);
        sliderLAyout.setExpandRatio(img, 2);
        sliderLAyout.setExpandRatio(slider, 7);
        sliderLAyout.setExpandRatio(total, 1);
        sliderLAyout.setComponentAlignment(img, Alignment.BOTTOM_LEFT);
        sliderLAyout.setComponentAlignment(slider, Alignment.BOTTOM_LEFT);
        sliderLAyout.setComponentAlignment(total, Alignment.BOTTOM_LEFT);
        // Adding layout
        imagesLayout.addComponent(sliderLAyout);
    });
    addComponent(imagesLayout);
}

From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java

License:Open Source License

/**
 * Generate lottery list./*from   ww w .  j  a  v a  2 s  . c o  m*/
 *
 * @return the list
 */
private List<Object> generateLotteryList() {
    List<Object> randomList = new ArrayList<>();
    Iterator<Component> iterator = imagesLayout.iterator();
    while (iterator.hasNext()) {
        HorizontalLayout hl = (HorizontalLayout) iterator.next();
        Image imageSelected = (Image) hl.getComponent(0);
        Image img = new Image("", imageSelected.getSource());
        img.setData(imageSelected.getData());
        Slider slider = (Slider) hl.getComponent(1);
        int rep = slider.getValue().intValue();
        while (rep > 0) {
            randomList.add(img);
            rep--;
        }
    }
    return randomList;
}

From source file:org.inakirj.imagerulette.utils.ImageUtils.java

License:Open Source License

/**
 * Gets the image URL./*from   www  . ja v  a  2  s.  c o  m*/
 *
 * @return the image URL
 */
public static List<Image> getAllImageURL() {
    List<Image> result = new ArrayList<>();
    CookieManager sm = new CookieManager();
    Image img;
    for (String url : sm.getAllURLs()) {
        ExternalResource resource = new ExternalResource(url);
        img = new Image("", resource);
        img.setData(url);
        result.add(img);
    }
    return result;
}

From source file:org.investovator.ui.main.components.GameDetailsView.java

License:Open Source License

public Image getImage() {
    String iconName = "game_icon.jpg";
    GameModes imageMode = null;/*from w w w .jav  a2 s .  c o  m*/

    if (gameInstance != null) {
        imageMode = controller.getGameMode(gameInstance);
    } else if (gameMode != null) {
        imageMode = gameMode;
    }

    if (imageMode != null) {
        switch (imageMode) {
        case AGENT_GAME:
            iconName = "agent2.jpg";
            break;
        case NN_GAME:
            iconName = "prediction_based.jpg";
            break;
        case PAYBACK_ENG:
            iconName = "game_icon.jpg";
            break;
        }
    }

    FileResource resource = new FileResource(new File(ConfigHelper.getImagePath() + iconName));
    Image img = new Image(null, resource);
    img.setHeight("50px");
    img.setWidth("50px");
    return img;
}

From source file:org.jdal.vaadin.auth.LoginView.java

License:Apache License

@Override
protected Component buildPanel() {
    Label greeting = new Label(getMessage("loginView.greeting"));
    greeting.addStyleName("jd-login-greeting");
    greeting.addStyleName(Reindeer.LABEL_H2);
    Label applicationNameLabel = new Label(getMessage(applicationName));
    applicationNameLabel.addStyleName("jd-login-appname");
    applicationNameLabel.addStyleName(Reindeer.LABEL_H2);
    applicationNameLabel.setSizeUndefined();

    loginButton.addClickListener(this);
    loginButton.setCaption(getMessage("loginView.loginButtonCaption"));
    loginButton.addStyleName("jd-login-button");

    // add shortcut listener for enter key
    loginButton.addShortcutListener(new ShortcutListener("Sign In", KeyCode.ENTER, null) {
        @Override/*from   w w  w  .ja v a2s  . co  m*/
        public void handleAction(Object sender, Object target) {
            loginButton.click();
        }
    });

    Image image = null;
    HorizontalLayout imageWrapper = null;

    if (applicationIcon != null) {
        image = new Image(null, applicationIcon);
        image.setSizeUndefined();
        image.setStyleName("jd-login-icon");
        imageWrapper = new HorizontalLayout();
        imageWrapper.setMargin(false);
        imageWrapper.addComponent(image);
        imageWrapper.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
    }

    BoxFormBuilder fb = new BoxFormBuilder();
    fb.setDefaultWidth(BoxFormBuilder.SIZE_FULL);
    fb.row();
    fb.startBox();
    fb.setFixedHeight();
    fb.row(false);
    fb.add(greeting, Alignment.TOP_LEFT);
    fb.add(applicationNameLabel, Alignment.TOP_RIGHT);
    fb.endBox();
    // add application icon
    if (image != null) {
        fb.row(BoxFormBuilder.SIZE_FULL);
        fb.add(imageWrapper, BoxFormBuilder.SIZE_FULL, Alignment.MIDDLE_CENTER);
    }
    fb.row();
    fb.startBox();
    fb.row(30);
    fb.add(errorLabel, BoxFormBuilder.SIZE_FULL, Alignment.BOTTOM_CENTER);
    fb.endBox();
    fb.row();
    fb.startBox();
    fb.setFixedHeight();
    fb.row();
    fb.add(username, getMessage("loginView.username"), Alignment.BOTTOM_CENTER);
    fb.add(password, getMessage("loginView.password"), Alignment.BOTTOM_CENTER);
    fb.add(loginButton, 100, Alignment.BOTTOM_CENTER);
    fb.endBox();

    Component form = fb.getForm();
    form.setWidth(this.getWidth(), Unit.PIXELS);
    form.setHeight(getHeight(), Unit.PIXELS);
    form.setStyleName("jd-login");

    return form;
}

From source file:org.lucidj.search.SearchView.java

License:Apache License

private void buildView() {
    setMargin(true);/*  w  w w.  ja  v  a  2s.com*/
    Node document = parser.parse("## This is *Markdown*!");
    addComponent(new Label(renderer.render(document), ContentMode.HTML));
    addComponent(new Image(null, new ExternalResource("vaadin://~/search/cool-image.jpg")));
    addComponent(new Label("DigestRandomGenerator: " + generator.toString()));
    addComponent(new Label("No results to show."));
}