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:com.esofthead.mycollab.module.user.accountsettings.customize.view.GeneralSettingViewImpl.java

License:Open Source License

private void buildShortcutIconPanel() {
    FormContainer formContainer = new FormContainer();
    MHorizontalLayout layout = new MHorizontalLayout().withFullWidth().withMargin(new MarginInfo(true));
    MVerticalLayout leftPanel = new MVerticalLayout().withMargin(false);
    Label logoDesc = new Label(AppContext.getMessage(FileI18nEnum.OPT_FAVICON_FORMAT_DESCRIPTION));
    leftPanel.with(logoDesc).withWidth("250px");
    MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false);
    final Image favIconRes = new Image("", new ExternalResource(StorageFactory.getInstance()
            .getFavIconPath(billingAccount.getId(), billingAccount.getFaviconpath())));

    MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(true, false, false, false));
    buttonControls.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT);
    final UploadField favIconUploadField = new UploadField() {
        private static final long serialVersionUID = 1L;

        @Override//from ww  w .  ja v  a  2  s  .  co m
        protected void updateDisplay() {
            byte[] imageData = (byte[]) this.getValue();
            String mimeType = this.getLastMimeType();
            if (mimeType.equals("image/jpeg")) {
                imageData = ImageUtil.convertJpgToPngFormat(imageData);
                if (imageData == null) {
                    throw new UserInvalidInputException(
                            AppContext.getMessage(FileI18nEnum.ERROR_INVALID_SUPPORTED_IMAGE_FORMAT));
                } else {
                    mimeType = "image/png";
                }
            }

            if (mimeType.equals("image/png")) {
                try {
                    AccountFavIconService favIconService = AppContextUtil
                            .getSpringBean(AccountFavIconService.class);
                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
                    String newFavIconPath = favIconService.upload(AppContext.getUsername(), image,
                            AppContext.getAccountId());
                    favIconRes.setSource(new ExternalResource(StorageFactory.getInstance()
                            .getFavIconPath(billingAccount.getId(), newFavIconPath)));
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                } catch (IOException e) {
                    throw new MyCollabException(e);
                }
            } else {
                throw new UserInvalidInputException(
                        AppContext.getMessage(FileI18nEnum.ERROR_UPLOAD_INVALID_SUPPORTED_IMAGE_FORMAT));
            }
        }
    };
    favIconUploadField.setButtonCaption(AppContext.getMessage(GenericI18Enum.ACTION_CHANGE));
    favIconUploadField.addStyleName("upload-field");
    favIconUploadField.setSizeUndefined();
    favIconUploadField.setFieldType(UploadField.FieldType.BYTE_ARRAY);
    favIconUploadField.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));

    Button resetButton = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_RESET),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    BillingAccountService billingAccountService = AppContextUtil
                            .getSpringBean(BillingAccountService.class);
                    billingAccount.setFaviconpath(null);
                    billingAccountService.updateWithSession(billingAccount, AppContext.getUsername());
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                }
            });
    resetButton.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));
    resetButton.setStyleName(UIConstants.BUTTON_OPTION);

    buttonControls.with(favIconUploadField, resetButton);
    rightPanel.with(favIconRes, buttonControls);
    layout.with(leftPanel, rightPanel).expand(rightPanel);
    formContainer.addSection("Favicon", layout);
    this.with(formContainer);
}

From source file:com.esofthead.mycollab.vaadin.ui.AttachmentPreviewWindow.java

License:Open Source License

private void initUI() {
    Image previewImage = new Image(null, this.previewResource);
    previewImage.setSizeUndefined();//from  w  ww. j  av a  2  s. c  o  m
    this.setContent(previewImage);
    this.setResizable(false);
}

From source file:com.esofthead.mycollab.vaadin.ui.UserAvatarControlFactory.java

License:Open Source License

public static Image createUserAvatarEmbeddedComponent(String avatarId, int size) {
    Image embedded = new Image(null, createAvatarResource(avatarId, size));
    return embedded;
}

From source file:com.esofthead.mycollab.vaadin.ui.UserAvatarControlFactory.java

License:Open Source License

public static Image createUserAvatarEmbeddedComponent(String avatarId, int size, String tooltip) {
    Image embedded = new Image(null, createAvatarResource(avatarId, size));
    embedded.setDescription(tooltip);//from w w  w.j a v  a 2s.  com
    return embedded;
}

From source file:com.foc.vaadin.gui.components.chart.JFreeChartWrapper_Modified.java

License:Apache License

@Override
public void attach() {
    //      super.attach();
    //      AbstractWebApplicationContext context = (AbstractWebApplicationContext) getUI().getContext();
    ServletContext context = VaadinServlet.getCurrent().getServletContext();
    if (mode == RenderingMode.AUTO) {
        WebBrowser webBrowser = getWebBrowser();
        if (webBrowser.isIE() && webBrowser.getBrowserMajorVersion() < 9) {
            setRenderingMode(RenderingMode.PNG);
        } else {//from  ww  w. ja  v  a 2 s . c o  m
            // all decent browsers support SVG
            setRenderingMode(RenderingMode.SVG);
        }
    }
    ;
    Image image = new Image("", getSource());

    chartLayout.addComponent(image);
    //VAADIN 7
    //      getApplication().addResource((ConnectorResource) getSource());

    setResource("src", getSource());//Antoine See Workarround from https://vaadin.com/forum#!/thread/8366526
    markAsDirtyRecursive();
}

From source file:com.freebox.engeneering.application.web.layout.LeftSideBarController.java

License:Apache License

private void createFooterSideBar() {
    VerticalLayout verticalLayout = super.getView();

    sideBarFooter.setSizeUndefined();//  w  w w . ja v a  2s  .  c o  m
    sideBarFooter.addStyleName("user");
    Image profilePic = new Image(null, new ThemeResource("img/profile-pic.png"));
    profilePic.setWidth("34px");
    sideBarFooter.addComponent(profilePic);
    Label userName = new Label("MOHELLEBI ATAF");
    userName.setSizeUndefined();
    sideBarFooter.addComponent(userName);

    Command cmd = new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            Notification.show("Not implemented in this demo");
        }
    };
    MenuBar settings = new MenuBar();
    MenuItem settingsMenu = settings.addItem("", null);
    settingsMenu.setStyleName("icon-cog");
    settingsMenu.addItem("Settings", cmd);
    settingsMenu.addItem("Preferences", cmd);
    settingsMenu.addSeparator();
    settingsMenu.addItem("My Account", cmd);
    sideBarFooter.addComponent(settings);

    Button exit = new NativeButton("Exit");
    exit.addStyleName("icon-cancel");
    exit.setDescription("Sign Out");
    sideBarFooter.addComponent(exit);
    exit.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
        }
    });

    verticalLayout.addComponent(sideBarFooter);
}

From source file:com.github.carljmosca.ui.FramesView.java

private void displayFrame() {
    imageLayout = new HorizontalLayout(
            new Image(null, new FileResource(new File("/Users/moscac/Downloads/GetMedia.jpeg"))));
}

From source file:com.github.daytron.twaattin.ui.tabledecorator.ProfileImageColumnGenerator.java

License:Open Source License

/**
 * @return Profile image of the underlying {@link User} as an {@link Image}
 * component/* ww  w.j av a 2s. c  o m*/
 */
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    User user = getUser(source, itemId);

    String url = user.getMiniProfileImageURL();

    if (url != null) {

        ExternalResource resource = new ExternalResource(url);

        return new Image("", resource);
    }

    return null;
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.AbstractView.java

License:Apache License

/**
 * Creates the basic layout with panel and footer.
 *
 * @param panelName/*from w w  w. j  a va2s.  c o m*/
 *            the panel name
 */
protected final void createBasicLayoutWithPanelAndFooter(final String panelName) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(100, Unit.PERCENTAGE);

    final VerticalLayout pageModeContent = new VerticalLayout();
    pageModeContent.setMargin(true);
    pageModeContent.setSpacing(true);
    pageModeContent.setWidth(100, Unit.PERCENTAGE);
    pageModeContent.setHeight(100, Unit.PERCENTAGE);

    layout.addComponent(pageModeContent);

    final ThemeResource ciaLogoResource = new ThemeResource("cia-logo.png");

    final Image ciaLogoImage = new Image(null, ciaLogoResource);

    final HorizontalLayout topHeader = new HorizontalLayout();

    topHeader.addComponent(ciaLogoImage);
    ciaLogoImage.setWidth("75px");
    ciaLogoImage.setHeight("75px");
    topHeader.setComponentAlignment(ciaLogoImage, Alignment.MIDDLE_LEFT);
    topHeader.setExpandRatio(ciaLogoImage, ContentRatio.SMALL);

    final HorizontalLayout topTitleHeadertPanel = new HorizontalLayout();

    final Label titleLabel = new Label("Citizen Intelligence Agency");
    titleLabel.setStyleName("Header");
    topTitleHeadertPanel.addComponent(titleLabel);
    topTitleHeadertPanel.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT);

    final Label sloganLabel = new Label("// Tracking politicians like bugs!");
    sloganLabel.setStyleName("HeaderSlogan");
    topTitleHeadertPanel.addComponent(sloganLabel);
    topTitleHeadertPanel.setComponentAlignment(sloganLabel, Alignment.MIDDLE_RIGHT);

    topHeader.addComponent(topTitleHeadertPanel);
    topHeader.setComponentAlignment(topTitleHeadertPanel, Alignment.MIDDLE_LEFT);
    topHeader.setExpandRatio(topTitleHeadertPanel, ContentRatio.GRID);

    topHeaderRightPanel.removeAllComponents();
    topHeader.addComponent(topHeaderRightPanel);
    topHeader.setComponentAlignment(topHeaderRightPanel, Alignment.MIDDLE_RIGHT);
    topHeader.setExpandRatio(topHeaderRightPanel, ContentRatio.LARGE);

    if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN)
            || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {

        final Link userHomePageLink = pageLinkFactory.createUserHomeViewPageLink();
        topHeaderRightPanel.addComponent(userHomePageLink);
        topHeaderRightPanel.setComponentAlignment(userHomePageLink, Alignment.MIDDLE_RIGHT);

        final Button logoutButton = new Button(LOGOUT, FontAwesome.SIGN_OUT);

        final LogoutRequest logoutRequest = new LogoutRequest();
        logoutRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
        logoutButton.addClickListener(new LogoutClickListener(logoutRequest, applicationManager));

        topHeaderRightPanel.addComponent(logoutButton);
        topHeaderRightPanel.setComponentAlignment(logoutButton, Alignment.MIDDLE_RIGHT);

    } else {
        final Link createRegisterPageLink = pageLinkFactory.createRegisterPageLink();
        topHeaderRightPanel.addComponent(createRegisterPageLink);
        topHeaderRightPanel.setComponentAlignment(createRegisterPageLink, Alignment.MIDDLE_RIGHT);

        final Link createLoginPageLink = pageLinkFactory.createLoginPageLink();
        topHeaderRightPanel.addComponent(createLoginPageLink);
        topHeaderRightPanel.setComponentAlignment(createLoginPageLink, Alignment.MIDDLE_RIGHT);
    }

    topHeaderRightPanel.setWidth("100%");
    topHeaderRightPanel.setHeight("60px");

    topHeader.setWidth("100%");
    topHeader.setHeight("60px");

    pageModeContent.addComponent(topHeader);
    pageModeContent.setComponentAlignment(topHeader, Alignment.TOP_CENTER);

    pageModeContent.addComponent(getBarmenu());
    pageModeContent.setComponentAlignment(getBarmenu(), Alignment.TOP_CENTER);

    panel = new Panel(panelName);

    panel.setSizeFull();
    pageModeContent.addComponent(panel);
    pageModeContent.setExpandRatio(panel, ContentRatio.FULL_SIZE);

    pageModeContent.addComponent(pageLinkFactory.createMainViewPageLink());
    setContent(layout);

    setWidth(100, Unit.PERCENTAGE);
    setHeight(100, Unit.PERCENTAGE);
    setSizeFull();

}

From source file:com.hack23.cia.web.impl.ui.application.views.user.politician.pagemode.PoliticianOverviewPageModContentFactoryImpl.java

License:Apache License

/**
 * Creates the overview content.//www  .  ja  va2  s .c om
 *
 * @param panelContent
 *            the panel content
 * @param personData
 *            the person data
 * @param viewRiksdagenPolitician
 *            the view riksdagen politician
 * @param pageId
 */
private void createOverviewContent(final VerticalLayout panelContent, final PersonData personData,
        final ViewRiksdagenPolitician viewRiksdagenPolitician, final String pageId) {
    LabelFactory.createHeader2Label(panelContent, OVERVIEW);

    final VerticalLayout overviewLayout = new VerticalLayout();
    overviewLayout.setSizeFull();

    panelContent.addComponent(overviewLayout);
    panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

    getPoliticianMenuItemFactory().createOverviewPage(overviewLayout, pageId);

    final Link createPoliticianPageLink = getPageLinkFactory().createPoliticianPageLink(personData);
    panelContent.addComponent(createPoliticianPageLink);

    final Image image = new Image("",
            new ExternalResource(personData.getImageUrl192().replace("http://", "https://")));

    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeFull();

    panelContent.addComponent(horizontalLayout);

    horizontalLayout.addComponent(image);

    getFormFactory().addFormPanelTextFields(horizontalLayout, new BeanItem<>(viewRiksdagenPolitician),
            ViewRiksdagenPolitician.class,
            Arrays.asList(new String[] { "firstName", "lastName", "gender", "bornYear", "party", "active",
                    "firstAssignmentDate", "lastAssignmentDate", "currentAssignments",
                    "currentMinistryAssignments", "currentSpeakerAssignments", "currentCommitteeAssignments",
                    "currentPartyAssignments", "totalMinistryAssignments", "totalCommitteeAssignments",
                    "totalSpeakerAssignments", "totalPartyAssignments", "totalAssignments", "totalDaysServed",
                    "activeEu", "totalDaysServedEu", "activeGovernment", "totalDaysServedGovernment",
                    "activeSpeaker", "totalDaysServedSpeaker", "activeCommittee", "totalDaysServedCommittee",
                    "activeParliament", "totalDaysServedParliament", "activeParty", "totalDaysServedParty" }));

    getGridFactory().createBasicBeanItemGrid(panelContent,
            new BeanItemContainer<>(DetailData.class, personData.getPersonDetailData().getDetailList()),
            "Detail", new String[] { "code", "detail" }, new String[] { "hjid", "intressentId", "detailType" },
            null, null, null);

    panelContent.setExpandRatio(createPoliticianPageLink, ContentRatio.SMALL);
    panelContent.setExpandRatio(horizontalLayout, ContentRatio.GRID);

}