Example usage for com.vaadin.ui Image addStyleName

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

Introduction

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

Prototype

@Override
    public void addStyleName(String style) 

Source Link

Usage

From source file:info.magnolia.ui.form.field.component.AbstractBaseItemContentPreviewComponent.java

License:Open Source License

@Override
public Component refreshContentPreview(Item item) {
    Image thumbnail = new Image();
    String path = imageProvider.getPortraitPath(((JcrItemAdapter) item).getItemId());
    if (StringUtils.isNotBlank(path)) {
        thumbnail = new Image("", new ExternalResource(path));
        thumbnail.addStyleName("file-preview-area");
    }//w  w  w. jav a 2  s  .  c  o m
    return thumbnail;
}

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

License:Open Source License

/**
 * Adds the row.//ww w  . ja  va  2 s  .  c om
 */
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   w ww .  j  av 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

/**
 * Calculate stats./* ww  w.  ja v a2 s .c o  m*/
 */
@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.DicePlayView.java

License:Open Source License

/**
 * Loop thread.//from   ww w. ja  va 2  s .c om
 */
private void onPickABallClick() {
    int value = randomizer.nextInt(lotteryList.size());
    Image img = (Image) lotteryList.get(value);
    img.setWidth(78, Unit.PIXELS);
    img.setHeight(81, Unit.PIXELS);
    img.addStyleName("random-image");
    imageLayout.replaceComponent(randomImgToBeReplaced, img);
    randomImgToBeReplaced = img;
    String imgUrlToIncrease = (String) img.getData();
    Integer currentValue = statsImageIdOcurrencesMap.get(imgUrlToIncrease);
    currentValue++;
    statsImageIdOcurrencesMap.put(imgUrlToIncrease, new Integer(currentValue));
    calculateStats();
}

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

License:Open Source License

/**
 * Sets the layout.//ww w  .  ja va2 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.opencms.ui.dataview.CmsColumnValueConverter.java

License:Open Source License

/**
 * Gets the actual column value for the given data value.<p>
 *
 * @param value the data value/*  w w  w. j a  v a 2s .c  om*/
 * @param type the column type enum
 *
 * @return the actual column value to use
 */
public static Object getColumnValue(Object value, CmsDataViewColumn.Type type) {

    if (type == Type.imageType) {
        Image image = new Image("", new ExternalResource((String) value));
        image.addStyleName("o-table-image");
        return image;
    } else {
        return value;
    }
}

From source file:org.plukh.fluffymeow.ui.i18n.LocaleChooserComponent.java

License:Open Source License

@Inject
public LocaleChooserComponent() {
    log.trace("Creating LocaleChooserComponent...");
    setSizeUndefined();/*  w w w  .j  a  va2 s  .com*/

    HorizontalLayout layout = new HorizontalLayout();

    flags = new ArrayList<>();

    languages.forEach(language -> {
        Resource flagResource = new ThemeResource(language.getFlagFile());
        Image flag = new Image(null, flagResource);
        flag.addStyleName("pointer");
        flag.addClickListener(event -> onLanguageChange(language.getLocale()));
        flag.setData(language.getMessage());

        log.debug("Created flag for locale " + language.getLocale());

        flags.add(flag);
        layout.addComponent(flag);
    });

    setCompositionRoot(layout);

    log.debug("LocaleChooserComponent created");
}

From source file:org.vaadin.alump.fancylayouts.demo.PanelDemo.java

License:Apache License

/**
 * Sample content with simple table (disabled as table is so broken in
 * Vaadin 7). To get table work you probably need some special timer.
 * /*from  w  ww .  j av  a  2  s.  c  om*/
 * @return
 */
// private ComponentContainer createPanelContentC() {
// VerticalLayout layout = new VerticalLayout();
// layout.setWidth("100%");
// layout.setMargin(true);
// layout.setSpacing(true);
//
// Label label = new Label ("Table is quite broken in Vaadin 7?");
// layout.addComponent(label);
//
// Table table = new Table();
// table.setWidth("400px");
// table.setHeight("500px");
// table.addContainerProperty("Name", String.class, "");
// table.addContainerProperty("Phone Number", String.class, "");
// table.addItem(new Object[] { "Matti Meiklinen", "555 234 2344" },
// "Matti");
// table.addItem(new Object[] { "Donald Duck", "555 332 7782" }, "Donald");
//
// layout.addComponent(table);
//
// return layout;
// }

private ComponentContainer createPanelContentD() {
    CssLayout layout = new CssLayout();
    layout.addStyleName("demo-panel-d");
    layout.setWidth("100%");
    layout.setHeight("100%");

    Image image = new Image();
    image.setSource(new ThemeResource("images/meme.jpg"));
    image.addStyleName("demo-meme");
    layout.addComponent(image);

    return layout;
}

From source file:org.vaadin.alump.offlinebuilder.demo.DemoUI.java

License:Open Source License

@Override
protected void init(VaadinRequest vaadinRequest) {

    OfflineUIExtension offlineExtension = OfflineUIExtension.get(this);

    // As Panel is half legacy component, using OfflineCssLayout to make content scrollable
    OfflineCssLayout panel = new OfflineCssLayout();
    panel.addStyleName("scrollable-wrapper");
    panel.setSizeFull();//from   w  w w. ja v  a2s  .c  o  m
    setContent(panel);
    offlineExtension.setOfflineRoot(panel);

    VerticalLayout layout = new OfflineVerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addStyleName("main-layout");
    panel.addComponent(layout);

    Label header = new OfflineLabel("OfflineBuilder");
    header.addStyleName("header-label");
    layout.addComponent(header);

    Label info = new OfflineLabel("OfflineBuilder allows to define offline UI without need of writing GWT"
            + " code. Add-on offers offline extended versions of basic Vaadin UI components and layouts. This way"
            + " your server defined UI can be used on offline mode too.");
    info.addStyleName("info-label");
    layout.addComponent(info);

    info = new OfflineLabel(
            "To test offline functionality. Turn on flight mode on your device or just disconnect"
                    + " from your network connection. Offline UI should look identical with online UI.");
    info.addStyleName("info-label");
    layout.addComponent(info);

    Image image = new OfflineImage();
    image.setWidth("300px");
    image.addStyleName("extra-stylename-image");
    image.setSource(new ThemeResource("img/offline.png"));
    image.setDescription("Example image");
    layout.addComponent(image);

    HorizontalLayout buttonLayout = new OfflineHorizontalLayout();
    buttonLayout.setSpacing(true);
    layout.addComponent(buttonLayout);

    OfflineButton pingButton = new OfflineButton("Ping server");
    pingButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            Notification.show("Server says pong!");
        }
    });
    pingButton.setDescription("Button that will be automatically disabled on offline mode");
    buttonLayout.addComponent(pingButton);

    OfflineButton writeButton = new OfflineButton("Store value (TODO)");
    writeButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            Notification.show("No need to store, in online mode.");
        }
    });
    buttonLayout.addComponent(writeButton);

    /*
    OfflineFormLayout formTest = new OfflineFormLayout();
    OfflineCheckBox checkbox = new OfflineCheckBox("Flag me");
    checkbox.setOfflineValueKey("flag");
    formTest.addComponent(checkbox);
    layout.addComponent(formTest);
    */

    Link link = new OfflineLink("Open project's GitHub page",
            new ExternalResource("https://github.com/alump/OfflineBuilder"));
    link.addStyleName("github-link");
    layout.addComponent(link);
}