Example usage for com.vaadin.ui Image addClickListener

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

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Add a click listener to the component.

Usage

From source file:com.adonis.ui.menu.Menu.java

private void createViewButtonWithEditableImage(final String name, String caption, String nameImage) {
    Button button = new Button(caption, new ClickListener() {
        @Override/* ww  w  . j ava 2s . c  om*/
        public void buttonClick(ClickEvent event) {
            navigator.navigateTo(name);
        }

    });

    button.setPrimaryStyleName(ValoTheme.BUTTON_FRIENDLY);
    //        button.setWidth(50, Unit.PERCENTAGE);
    image.setWidth(90, Unit.PIXELS);
    image.setHeight(90, Unit.PIXELS);

    FileReader.createDirectoriesFromCurrent(getInitialPath());
    final Image image = new Image("", new ThemeResource("img/" + nameImage));
    try {
        FileReader.copyFile(VaadinUtils.getResourcePath(nameImage),
                VaadinUtils.getInitialPath() + File.separator + nameImage);
        image.setSource(new FileResource(new File(VaadinUtils.getInitialPath() + File.separator + nameImage)));
    } catch (IOException e) {
        e.printStackTrace();
        image.setSource(new ThemeResource("img/" + nameImage));
    }

    //        image.setWidth(50, Unit.PERCENTAGE);
    image.setWidth(90, Unit.PIXELS);
    image.setHeight(90, Unit.PIXELS);
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setPrimaryStyleName(ValoTheme.MENU_ITEM);
    horizontalLayout.addComponents(image, button);
    image.addClickListener(new MouseEvents.ClickListener() {
        @Override
        public void click(MouseEvents.ClickEvent event) {
            uploadFieldImage = new UploadField();
            uploadFieldImage.setAcceptFilter("image/*");
            uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.FailedListener() {
                @Override
                public void uploadFailed(com.vaadin.v7.ui.Upload.FailedEvent event) {
                    uploadFieldImage.clearDefaulLayout();
                    horizontalLayout.removeComponent(uploadFieldImage);
                }

                private static final long serialVersionUID = 1L;

            });
            horizontalLayout.addComponent(uploadFieldImage, 2);
            uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.SucceededListener() {

                @Override
                public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent event) {
                    File file = (File) uploadFieldImage.getValue();
                    try {
                        showUploadedImage(uploadFieldImage, image, file.getName(), nameImage);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    uploadFieldImage.clearDefaulLayout();
                    horizontalLayout.removeComponent(uploadFieldImage);

                }
            });
            uploadFieldImage.setFieldType(UploadField.FieldType.FILE);
            horizontalLayout.markAsDirty();
            //                image.setWidth(50, Unit.PERCENTAGE);
            image.setWidth(90, Unit.PIXELS);
            image.setHeight(90, Unit.PIXELS);
            image.setVisible(false);
            image.markAsDirty();
            horizontalLayout.addComponent(image, 0);
        }
    });
    button.setVisible(true);
    image.setVisible(true);
    menuItemsLayout.addComponents(horizontalLayout);
    viewButtons.put(name, button);
}

From source file:com.anphat.list.controller.CategoryListController.java

public void initTable() {
    beanItemContainerCategoryList = new BeanItemContainer<>(CategoryListDTO.class);

    tblCategoryList.addGeneratedColumn(lblDelete, new CustomTable.ColumnGenerator() {
        @Override//from   w  ww  . j a  v a2s . c  o  m
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final CategoryListDTO categoryListDTO = (CategoryListDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_delete.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("titleMessage"),
                            BundleUtils.getString("bodyMessage"), BundleUtils.getString("yes"),
                            BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        categoryListDTO.setEndDate(DateUtil.date2ddMMyyyyHHMMss(new Date()));
                                        String message = serviceCategoryList
                                                .updateCategoryList(categoryListDTO);
                                        if (message.equals(Constants.SUCCESS)) {
                                            Notification.show(BundleUtils.getString("delete.success"));
                                            tblCategoryList.removeItem(itemId);
                                        } else {
                                            Notification.show(BundleUtils.getString("delete.fail"));
                                        }
                                    } else {
                                        // User did not confirm
                                    }
                                }
                            });
                }
            });

            return image;
        }

    });
    tblCategoryList.addGeneratedColumn("custQuantityDetail", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final CategoryListDTO categoryListDTO = (CategoryListDTO) itemId;
            if (DataUtil.isStringNullOrEmpty(categoryListDTO.getCustQuantity())) {
                return "";
            }
            Button btnDetail = new Button(categoryListDTO.getCustQuantity());
            btnDetail.setStyleName(Constants.ICON.V_LINK);
            btnDetail.addStyleName("v-link-button-left");
            btnDetail.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    LinkedHashMap<String, CustomTable.Align> headerCustomerTable = BundleUtils
                            .getHeadersFilter("customer.status.detail");
                    String captionCustomerTable = BundleUtils.getString("customer.table.detail.caption");
                    String lang = "customer";
                    CustomerDialog customerDialog = new CustomerDialog(headerCustomerTable,
                            captionCustomerTable, lang);
                    customerDialog.initDialog(mapServices, mapCustServiceStatus, CustomerDTO.class);
                    List<CustomerDTO> lstCustomerOfMineName = WSCustomer
                            .getListCustomerOfMineName(categoryListDTO.getId());
                    customerDialog.setCustomerList2Table(lstCustomerOfMineName);
                    UI.getCurrent().addWindow(customerDialog);
                    event.getButton().setEnabled(true);
                }
            });
            return btnDetail;
        }

    });
    tblCategoryList.addGeneratedColumn("devidedQuantityDetail", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final CategoryListDTO categoryListDTO = (CategoryListDTO) itemId;
            if (DataUtil.isStringNullOrEmpty(categoryListDTO.getDividedQuantity())) {
                return "";
            }
            Button btnDetail = new Button(categoryListDTO.getDividedQuantity());
            btnDetail.setStyleName(Constants.ICON.V_LINK);
            btnDetail.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    LinkedHashMap<String, CustomTable.Align> headerCustomerTable = BundleUtils
                            .getHeadersFilter("devided.customer.status.detail");
                    String captionCustomerTable = BundleUtils
                            .getString("customer.devided.table.detail.caption");
                    String lang = "customer";
                    CustomerDialog customerDialog = new CustomerDialog(headerCustomerTable,
                            captionCustomerTable, lang);
                    customerDialog.initDialog(mapServices, mapCustServiceStatus, CustomerDTO.class);
                    List<CustomerDTO> lstCustomerOfMineName = WSCustomer
                            .getListDevidedCustomerOfMineName(categoryListDTO.getId());
                    customerDialog.setCustomerList2Table(lstCustomerOfMineName);
                    UI.getCurrent().addWindow(customerDialog);
                    event.getButton().setEnabled(true);
                }
            });
            return btnDetail;
        }

    });
    tblCategoryList.addGeneratedColumn(lblEdit, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final CategoryListDTO categoryListDTO = (CategoryListDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_edit.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    InsertOrUpdate(categoryListDTO, false);
                }
            });

            return image;
        }

    });
    //        tableUtils.generateColumn(tblCategoryList);
    CommonUtils.setVisibleBtnTablePanel(panelCategoryList, true, false, true, true);
    CommonFunctionTableFilter.initTable(panelCategoryList, headerData, beanItemContainerCategoryList,
            BundleUtils.getString("table.list.categoryList"), 10, "categoryList.header", true, true, false,
            false, false);
    tblCategoryList.setColumnExpandRatio("description", 2);
    tblCategoryList.setColumnExpandRatio("receivedDate", 1);
    tblCategoryList.setColumnExpandRatio("endDate", 1);
    tblCategoryList.setColumnExpandRatio("code", 1);
    tblCategoryList.setColumnExpandRatio("name", 1);
}

From source file:com.anphat.list.controller.ObjectsController.java

public void initTable() {
    beanItemContainerObjects = new BeanItemContainer<>(ObjectsDTO.class);
    tblObjects.setSortDisabled(true);//from  ww w  .  j av a  2  s.  c  om
    tblObjects.addGeneratedColumn(lblDelete, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final ObjectsDTO objectsDTO = (ObjectsDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_delete.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    ConfirmDialog.show(UI.getCurrent(), "Thng bo", "Bn c mun thc hin?", "C",
                            "Khng", new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        objectsDTO.setStatus(Constants.DEACTIVE);
                                        String message = serviceObjects.updateObjects(objectsDTO);
                                        if (message.equals(Constants.SUCCESS)) {
                                            CommonMessages.showMessageDeleteSuccess("function.object");
                                            tblObjects.removeItem(itemId);
                                        } else {
                                            CommonMessages.showDeleteFail("function.object");
                                        }
                                    }
                                }
                            });
                }
            });

            return image;
        }

    });
    tblObjects.addGeneratedColumn(lblEdit, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final ObjectsDTO objectsDTO = (ObjectsDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_edit.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    InsertOrUpdate(objectsDTO);
                }
            });

            return image;
        }

    });
    CommonUtils.setVisibleBtnTablePanel(panelObjects, true, true, false, true);
    CommonFunctionTableFilter.initTable(panelObjects, headerData, beanItemContainerObjects,
            BundleUtils.getString("table.list.objects"), 10, "objects.header", true, true, false, false, false);
    CommonUtils.convertFieldAppParamTable(tblObjects, "status", Constants.APP_PARAMS.COMMON_STATUS,
            mapCode2Name);
}

From source file:com.anphat.list.controller.RolesController.java

public void initTable() {

    tblRoles.setSortDisabled(true);/*from w  w  w.j a  v a  2s .  co  m*/
    tblRoles.addGeneratedColumn(lblDelete, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final RolesDTO rolesDTO = (RolesDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_delete.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("d"),
                            BundleUtils.getString("bodyMessage"), BundleUtils.getString("yes"),
                            BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        rolesDTO.setStatus(Constants.DEACTIVE);
                                        String message = serviceRoles.updateRoles(rolesDTO);
                                        if (message.equals(Constants.SUCCESS)) {
                                            Notification.show(BundleUtils.getString("delete.success"));
                                            tblRoles.removeItem(itemId);
                                        } else {
                                            Notification.show(BundleUtils.getString("delete.fail"));
                                        }
                                    } else {
                                        // User did not confirm
                                    }
                                }
                            });
                }
            });

            return image;
        }

    });
    tblRoles.addGeneratedColumn(lblEdit, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final RolesDTO rolesDTO = (RolesDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_edit.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    InsertOrUpdate(rolesDTO);
                }
            });

            return image;
        }

    });
    tableUtils.generateColumn(tblRoles);
    CommonUtils.setVisibleBtnTablePanel(panelRoles, true, true, false, true);
    initTable(headerData);
}

From source file:com.anphat.list.controller.ServicesController.java

public void initTable() {
    beanItemContainerServices = new BeanItemContainer<>(ServicesDTO.class);

    CommonFunctionTableFilter.initTable(panelServices, headerData, beanItemContainerServices,
            BundleUtils.getString("table.list.services"), 10, "services.header", true, true, false, false,
            false);//  w  ww.  ja v a  2  s  . co  m
    tblServices.setSortDisabled(true);
    tblServices.addGeneratedColumn(lblDelete, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final ServicesDTO servicesDTO = (ServicesDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_delete.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    ConfirmDialog.show(UI.getCurrent(), "Thng bo", "B?n c mu?n th?c hi?n?", "C",
                            "Khng", new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        servicesDTO.setStatus(Constants.DEACTIVE);
                                        String message = serviceServices.updateServices(servicesDTO);
                                        if (message.equals(Constants.SUCCESS)) {
                                            Notification.show(BundleUtils.getString("delete.success"));
                                            tblServices.removeItem(itemId);
                                        } else {
                                            Notification.show(BundleUtils.getString("delete.fail"));
                                        }
                                    } else {
                                        // User did not confirm
                                    }
                                }
                            });
                }
            });

            return image;
        }

    });
    tblServices.addGeneratedColumn(lblEdit, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final ServicesDTO servicesDTO = (ServicesDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_edit.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    InsertOrUpdate(servicesDTO);
                }
            });

            return image;
        }

    });
    tableUtils.generateColumn(tblServices);
    CommonUtils.setVisibleBtnTablePanel(panelServices, true, true, false, true);
    tblServices.setVisibleColumns(headerServices);

}

From source file:com.anphat.list.controller.TaxAuthorityController.java

public void initTable() {
    beanItemContainerTaxAuthority = new BeanItemContainer<>(TaxAuthorityDTO.class);

    tblTaxAuthority.setSortDisabled(true);
    tblTaxAuthority.addGeneratedColumn(lblDelete, new CustomTable.ColumnGenerator() {
        @Override//ww w . jav a 2 s  .  c  o m
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final TaxAuthorityDTO taxAuthorityDTO = (TaxAuthorityDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_delete.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("titleMessage"),
                            BundleUtils.getString("bodyMessage"), BundleUtils.getString("yes"),
                            BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        taxAuthorityDTO.setStatus(Constants.DEACTIVE);
                                        String message = serviceTaxAuthority
                                                .updateTaxAuthority(taxAuthorityDTO);
                                        if (message.equals(Constants.SUCCESS)) {
                                            Notification.show(BundleUtils.getString("delete.success"));
                                            tblTaxAuthority.removeItem(itemId);
                                        } else {
                                            Notification.show(BundleUtils.getString("delete.fail"));
                                        }
                                    } else {
                                        // User did not confirm
                                    }
                                }
                            });
                }
            });

            return image;
        }

    });
    tblTaxAuthority.addGeneratedColumn(lblEdit, new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, final Object itemId, Object columnId) {
            final TaxAuthorityDTO taxAuthorityDTO = (TaxAuthorityDTO) itemId;
            ThemeResource iconVi = new ThemeResource("img/icon_edit.png");
            Image image = new Image(null, iconVi);
            image.addClickListener(new MouseEvents.ClickListener() {
                @Override
                public void click(MouseEvents.ClickEvent event) {
                    InsertOrUpdate(taxAuthorityDTO, false);
                }
            });

            return image;
        }

    });
    //        tableUtils.generateColumn(tblTaxAuthority);
    CommonFunctionTableFilter.initTable(panelTaxAuthority, headerData, beanItemContainerTaxAuthority,
            BundleUtils.getString("table.list.taxAuthority"), 10, "taxAuthority.header", true, true, false,
            false, false);
    CommonUtils.setVisibleBtnTablePanel(panelTaxAuthority, true, false, true, true);
    CommonUtils.convertFieldAppParamTable(tblTaxAuthority, Constants.TAXAUTHORITY.STATUS,
            Constants.APP_PARAMS.COMMON_STATUS);
}

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

License:Open Source License

public static Component constructAttachmentRow(final Content attachment) {
    String docName = attachment.getPath();
    int lastIndex = docName.lastIndexOf("/");
    if (lastIndex != -1) {
        docName = docName.substring(lastIndex + 1, docName.length());
    }/* ww  w . ja v a  2s .  c om*/

    final AbsoluteLayout attachmentLayout = new AbsoluteLayout();
    attachmentLayout.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentLayout.setHeight(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_HEIGHT);
    attachmentLayout.setStyleName("attachment-block");

    CssLayout thumbnailWrap = new CssLayout();
    thumbnailWrap.setSizeFull();
    thumbnailWrap.setStyleName("thumbnail-wrap");

    Image thumbnail = new Image(null);
    if (org.apache.commons.lang3.StringUtils.isBlank(attachment.getThumbnail())) {
        thumbnail.setSource(DEFAULT_SOURCE);
    } else {
        thumbnail.setSource(VaadinResourceManager.getResourceManager()
                .getImagePreviewResource(attachment.getThumbnail(), DEFAULT_SOURCE));
    }
    thumbnail.setDescription(docName);
    thumbnail.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    thumbnailWrap.addComponent(thumbnail);

    attachmentLayout.addComponent(thumbnailWrap, "top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 0;");

    if (MimeTypesUtil.isImageType(docName)) {
        thumbnail.addClickListener(new MouseEvents.ClickListener() {
            private static final long serialVersionUID = -2853211588120500523L;

            @Override
            public void click(MouseEvents.ClickEvent event) {
                Resource previewResource = VaadinResourceManager.getResourceManager()
                        .getImagePreviewResource(attachment.getPath(), DEFAULT_SOURCE);
                UI.getCurrent().addWindow(new AttachmentPreviewWindow(previewResource));
            }
        });
    }

    CssLayout attachmentNameWrap = new CssLayout();
    attachmentNameWrap.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentNameWrap.setStyleName("attachment-name-wrap");

    Label attachmentName = new Label(StringUtils.trim(docName, 60, true));
    attachmentName.setStyleName("attachment-name");
    attachmentNameWrap.addComponent(attachmentName);
    attachmentLayout.addComponent(attachmentNameWrap, "bottom: 0px; left: 0px; right: 0px; z-index: 1;");

    Button trashBtn = new Button(null, new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            ConfirmDialogExt.show(UI.getCurrent(),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, SiteConfiguration.getSiteName()),
                    AppContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT),
                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                    AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                ResourceService attachmentService = ApplicationContextUtil
                                        .getSpringBean(ResourceService.class);
                                attachmentService.removeResource(attachment.getPath(), AppContext.getUsername(),
                                        AppContext.getAccountId());
                                ((ComponentContainer) attachmentLayout.getParent())
                                        .removeComponent(attachmentLayout);
                            }
                        }
                    });

        }
    });
    trashBtn.setIcon(FontAwesome.TRASH_O);
    trashBtn.setStyleName("attachment-control");
    attachmentLayout.addComponent(trashBtn, "top: 9px; left: 9px; z-index: 1;");

    Button downloadBtn = new Button();
    FileDownloader fileDownloader = new FileDownloader(
            VaadinResourceManager.getResourceManager().getStreamResource(attachment.getPath()));
    fileDownloader.extend(downloadBtn);

    downloadBtn.setIcon(FontAwesome.DOWNLOAD);
    downloadBtn.setStyleName("attachment-control");
    attachmentLayout.addComponent(downloadBtn, "right: 9px; top: 9px; z-index: 1;");
    return attachmentLayout;
}

From source file:com.m4gik.views.component.LibraryScreen.java

/**
 * @param audioFile/* w  w w .ja  v  a  2s . c o  m*/
 * @param cover
 * @return
 */
private Component createPlayImage(final AudioFile audioFile, ExternalResource cover) {

    AbsoluteLayout absoluteLayout = new AbsoluteLayout();
    absoluteLayout.setWidth("120px");
    absoluteLayout.setHeight("120px");
    absoluteLayout.addComponent(createImageCover(cover));

    final Image play = createImageCover(
            new ExternalResource("http://www.gelab.com.tr/interfaces/gelab/images/PlayButton.png"));
    play.setWidth("50px");
    play.setHeight("50px");
    play.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -5184601350921707969L;

        @Override
        public void click(ClickEvent event) {
            MusicPlayerPanel musicPanel = MusicPlayerPanel.getInstance(getPlayerLayout());

            watched.addObserver(musicPanel);

            MusicPlayerPanel.setAudio(audioFile);
            MusicPlayerPanel.runDefaultSetup();

            if (isPlay.equals(false)) {
                watched.setValue(isPlay = true);
                play.setSource(new ExternalResource(
                        "http://icons.iconarchive.com/icons/icons-land/play-stop-pause/256/Pause-Disabled-icon.png"));
            } else {
                watched.setValue(isPlay = false);
                play.setSource(
                        new ExternalResource("http://www.gelab.com.tr/interfaces/gelab/images/PlayButton.png"));
            }

        }
    });

    absoluteLayout.addComponent(play, "top: 30px; left: 30px;");

    return absoluteLayout;
}

From source file:de.symeda.sormas.ui.Menu.java

License:Open Source License

public Menu(Navigator navigator) {
    this.navigator = navigator;
    setPrimaryStyleName(ValoTheme.MENU_ROOT);
    menuPart = new CssLayout();
    menuPart.addStyleName(ValoTheme.MENU_PART);

    // header of the menu
    final HorizontalLayout top = new HorizontalLayout();
    top.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    top.addStyleName(ValoTheme.MENU_TITLE);
    top.setSpacing(true);// ww w.  j a va  2  s.c om
    Label title = new Label("SORMAS");
    title.setSizeUndefined();
    Image image = new Image(null, new ThemeResource("img/sormas-logo.png"));
    CssStyles.style(image, ValoTheme.MENU_LOGO, ValoTheme.BUTTON_LINK);
    image.addClickListener(new MouseEvents.ClickListener() {
        @Override
        public void click(MouseEvents.ClickEvent event) {
            SormasUI.get().getNavigator().navigateTo(SurveillanceDashboardView.VIEW_NAME);
        }
    });
    top.addComponent(image);
    top.addComponent(title);
    menuPart.addComponent(top);

    // logout menu item
    MenuBar logoutMenu = new MenuBar();
    logoutMenu.addItem(I18nProperties.getCaption(Captions.actionLogout) + " ("
            + UserProvider.getCurrent().getUserName() + ")", VaadinIcons.SIGN_OUT, new Command() {
                @Override
                public void menuSelected(MenuItem selectedItem) {
                    LoginHelper.logout();
                }
            });

    logoutMenu.addStyleName("user-menu");
    menuPart.addComponent(logoutMenu);

    // button for toggling the visibility of the menu when on a small screen
    final Button showMenu = new Button(I18nProperties.getCaption(Captions.menu), new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            if (menuPart.getStyleName().contains(VALO_MENU_VISIBLE)) {
                menuPart.removeStyleName(VALO_MENU_VISIBLE);
            } else {
                menuPart.addStyleName(VALO_MENU_VISIBLE);
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(VALO_MENU_TOGGLE);
    showMenu.setIcon(VaadinIcons.MENU);
    menuPart.addComponent(showMenu);

    // container for the navigation buttons, which are added by addView()
    menuItemsLayout = new CssLayout();
    menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS);
    menuPart.addComponent(menuItemsLayout);

    addComponent(menuPart);
}

From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java

public Component getSources(InterestProfile profile) {
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setWidth("100%");
    VerticalLayout sourcesLayout = new VerticalLayout();
    sourcesLayout.setWidth("100%");
    Panel sourcesPanel = new Panel(sourcesLayout);

    List<CheckBox> checkBoxes = new ArrayList<>();
    HashMap<String, GridLayout> sourceLayouts = new HashMap<>();
    profile.getSources().entrySet().stream()
            .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> {
                Source source = e.getKey();
                boolean enabled = e.getValue();
                GridLayout sourceLayout = new GridLayout(5, 1);
                sourceLayout.setSizeFull();

                CheckBox sourceSelected = new CheckBox();
                sourceSelected.setValue(enabled);
                sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE);
                sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue()));
                checkBoxes.add(sourceSelected);

                Image sourceLogo = new Image();
                sourceLogo.addStyleName("logosmall");
                sourceLogo.setSource(new ExternalResource(source.getLogo()));
                sourceLogo.addClickListener(c -> {
                    sourceSelected.setValue(!sourceSelected.getValue());
                    profile.getSources().replace(source, sourceSelected.getValue());
                });/*from ww w.ja v a2 s.  c o  m*/
                VerticalLayout layoutLogo = new VerticalLayout(sourceLogo);
                layoutLogo.setWidth("150px");
                layoutLogo.setHeight("50px");
                layoutLogo.setMargin(false);
                layoutLogo.setSpacing(false);
                layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT);

                Label labelHeadLine = new Label(
                        source.getCategory().getIcon().getHtml() + "  " + source.getName(), ContentMode.HTML);
                labelHeadLine.addStyleName(ValoTheme.LABEL_H3);

                Label labelDescription = new Label(source.getDescription(), ContentMode.HTML);
                labelDescription.setWidth("300px");
                PopupView popup = new PopupView(null, labelDescription);

                Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O);
                buttonDescription.addClickListener(ce -> {
                    popup.setPopupVisible(true);
                });

                sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription);
                sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER);
                sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER);
                sourceLayout.setColumnExpandRatio(2, 5);
                sourceLayout.setSpacing(true);

                sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "")
                        .replaceAll("_", ""), sourceLayout);
                sourcesLayout.addComponent(sourceLayout);
            });

    sourcesPanel.setContent(sourcesLayout);
    sourcesPanel.setHeight("100%");
    sourcesPanel.setCaption(Language.get(Word.SOURCES));
    Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s));
    windowLayout.addComponent(sourcesPanel);
    windowLayout.setExpandRatio(sourcesPanel, 1);
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);

    CheckBox checkBoxSelectAll = new CheckBox();
    Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s));
    checkBoxSelectAll.setWidth("100%");
    checkBoxSelectAll.addValueChangeListener(e -> {
        profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue());
        checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue()));
    });

    TextField textFieldSearch = new TextField();
    Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s));
    textFieldSearch.setWidth("100%");
    textFieldSearch.setMaxLength(255);
    textFieldSearch.setPlaceholder(Language.get(Word.SEARCH));
    textFieldSearch.addValueChangeListener(searchValue -> {
        sourceLayouts.forEach((sourceName, sourceLayout) -> {
            if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "")
                    .replaceAll("-", "").replaceAll("_", ""))) {
                sourcesLayout.removeComponent(sourceLayout);
            } else {
                sourcesLayout.addComponent(sourceLayout);
            }
        });
    });

    Label placeholder = new Label();
    placeholder.setWidth("100%");

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.setMargin(new MarginInfo(true, false, false, false));
    footer.addStyleName("menubar");
    footer.setWidth("100%");
    footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder);
    footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT);
    footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(footer);
    windowLayout.setHeight("350px");
    return windowLayout;
}