List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment
@Override public void setComponentAlignment(Component childComponent, Alignment alignment)
From source file:com.esofthead.mycollab.module.project.view.page.PageFormLayoutFactory.java
License:Open Source License
@Override public ComponentContainer getLayout() { final VerticalLayout layout = new VerticalLayout(); this.informationLayout = new GridFormLayoutHelper(2, 3, "100%", "167px", Alignment.TOP_LEFT); this.informationLayout.getLayout().setWidth("100%"); this.informationLayout.getLayout().setMargin(false); this.informationLayout.getLayout().addStyleName("colored-gridlayout"); layout.addComponent(this.informationLayout.getLayout()); layout.setComponentAlignment(this.informationLayout.getLayout(), Alignment.BOTTOM_CENTER); return layout; }
From source file:com.esofthead.mycollab.module.project.view.settings.ProjectMemberListViewImpl.java
License:Open Source License
private Component generateMemberBlock(final SimpleProjectMember member) { CssLayout memberBlock = new CssLayout(); memberBlock.addStyleName("member-block"); VerticalLayout blockContent = new VerticalLayout(); MHorizontalLayout blockTop = new MHorizontalLayout(); Image memberAvatar = UserAvatarControlFactory.createUserAvatarEmbeddedComponent(member.getMemberAvatarId(), 100);/*ww w .j a v a 2 s .co m*/ blockTop.addComponent(memberAvatar); VerticalLayout memberInfo = new VerticalLayout(); Button deleteBtn = new Button("", FontAwesome.TRASH_O); deleteBtn.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { ConfirmDialogExt.show(UI.getCurrent(), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, SiteConfiguration.getSiteName()), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE), 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()) { ProjectMemberService prjMemberService = ApplicationContextUtil .getSpringBean(ProjectMemberService.class); member.setStatus(ProjectMemberStatusConstants.INACTIVE); prjMemberService.updateWithSession(member, AppContext.getUsername()); EventBusFactory.getInstance().post( new ProjectMemberEvent.GotoList(ProjectMemberListViewImpl.this, null)); } } }); } }); deleteBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY); blockContent.addComponent(deleteBtn); deleteBtn.setVisible(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.USERS)); blockContent.setComponentAlignment(deleteBtn, Alignment.TOP_RIGHT); LabelLink memberLink = new LabelLink(member.getMemberFullName(), ProjectLinkBuilder.generateProjectMemberFullLink(member.getProjectid(), member.getUsername())); memberLink.setWidth("100%"); memberLink.addStyleName("member-name"); memberInfo.addComponent(memberLink); String roleLink = "<a href=\"" + AppContext.getSiteUrl() + GenericLinkUtils.URL_PREFIX_PARAM + ProjectLinkGenerator.generateRolePreviewLink(member.getProjectid(), member.getProjectRoleId()) + "\""; Label memberRole = new Label(); memberRole.setContentMode(ContentMode.HTML); memberRole.setStyleName("member-role"); if (member.isAdmin()) { memberRole.setValue(roleLink + "style=\"color: #B00000;\">" + "Project Admin" + "</a>"); } else { memberRole.setValue(roleLink + "style=\"color:gray;font-size:12px;\">" + member.getRoleName() + "</a>"); } memberRole.setSizeUndefined(); memberInfo.addComponent(memberRole); Label memberEmailLabel = new Label( "<a href='mailto:" + member.getUsername() + "'>" + member.getUsername() + "</a>", ContentMode.HTML); memberEmailLabel.addStyleName("member-email"); memberEmailLabel.setWidth("100%"); memberInfo.addComponent(memberEmailLabel); Label memberSinceLabel = new Label("Member since: " + AppContext.formatDate(member.getJoindate())); memberSinceLabel.addStyleName("member-email"); memberSinceLabel.setWidth("100%"); memberInfo.addComponent(memberSinceLabel); if (RegisterStatusConstants.SENT_VERIFICATION_EMAIL.equals(member.getStatus())) { final VerticalLayout waitingNotLayout = new VerticalLayout(); Label infoStatus = new Label(AppContext.getMessage(ProjectMemberI18nEnum.WAITING_ACCEPT_INVITATION)); infoStatus.addStyleName("member-email"); waitingNotLayout.addComponent(infoStatus); ButtonLink resendInvitationLink = new ButtonLink( AppContext.getMessage(ProjectMemberI18nEnum.BUTTON_RESEND_INVITATION), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { ProjectMemberMapper projectMemberMapper = ApplicationContextUtil .getSpringBean(ProjectMemberMapper.class); member.setStatus(RegisterStatusConstants.VERIFICATING); projectMemberMapper.updateByPrimaryKeySelective(member); waitingNotLayout.removeAllComponents(); Label statusEmail = new Label( AppContext.getMessage(ProjectMemberI18nEnum.SENDING_EMAIL_INVITATION)); statusEmail.addStyleName("member-email"); waitingNotLayout.addComponent(statusEmail); } }); resendInvitationLink.setStyleName("link"); resendInvitationLink.addStyleName("member-email"); waitingNotLayout.addComponent(resendInvitationLink); memberInfo.addComponent(waitingNotLayout); } else if (RegisterStatusConstants.ACTIVE.equals(member.getStatus())) { Label lastAccessTimeLbl = new Label("Logged in " + DateTimeUtils.getPrettyDateValue(member.getLastAccessTime(), AppContext.getUserLocale())); lastAccessTimeLbl.addStyleName("member-email"); memberInfo.addComponent(lastAccessTimeLbl); } else if (RegisterStatusConstants.VERIFICATING.equals(member.getStatus())) { Label infoStatus = new Label(AppContext.getMessage(ProjectMemberI18nEnum.SENDING_EMAIL_INVITATION)); infoStatus.addStyleName("member-email"); memberInfo.addComponent(infoStatus); } String bugStatus = member.getNumOpenBugs() + " open bug"; if (member.getNumOpenBugs() > 1) { bugStatus += "s"; } String taskStatus = member.getNumOpenTasks() + " open task"; if (member.getNumOpenTasks() > 1) { taskStatus += "s"; } Label memberWorkStatus = new Label(bugStatus + " - " + taskStatus); memberInfo.addComponent(memberWorkStatus); memberInfo.setWidth("100%"); blockTop.addComponent(memberInfo); blockTop.setExpandRatio(memberInfo, 1.0f); blockTop.setWidth("100%"); blockContent.addComponent(blockTop); blockContent.setWidth("100%"); memberBlock.addComponent(blockContent); return memberBlock; }
From source file:com.esofthead.mycollab.module.project.view.settings.ProjectNotificationSettingViewComponent.java
License:Open Source License
public ProjectNotificationSettingViewComponent(final ProjectNotificationSetting bean) { super(AppContext.getMessage(ProjectSettingI18nEnum.VIEW_TITLE)); VerticalLayout bodyWrapper = new VerticalLayout(); bodyWrapper.setSpacing(true);/*from w w w .ja v a2 s .c o m*/ bodyWrapper.setMargin(true); bodyWrapper.setSizeFull(); HorizontalLayout notificationLabelWrapper = new HorizontalLayout(); notificationLabelWrapper.setSizeFull(); notificationLabelWrapper.setMargin(true); notificationLabelWrapper.setStyleName("notification-label"); Label notificationLabel = new Label(AppContext.getMessage(ProjectSettingI18nEnum.EXT_LEVEL)); notificationLabel.addStyleName("h2"); notificationLabel.setHeightUndefined(); notificationLabelWrapper.addComponent(notificationLabel); bodyWrapper.addComponent(notificationLabelWrapper); VerticalLayout body = new VerticalLayout(); body.setSpacing(true); body.setMargin(new MarginInfo(true, false, false, false)); final OptionGroup optionGroup = new OptionGroup(null); optionGroup.setItemCaptionMode(ItemCaptionMode.EXPLICIT); optionGroup.addItem(NotificationType.Default.name()); optionGroup.setItemCaption(NotificationType.Default.name(), AppContext.getMessage(ProjectSettingI18nEnum.OPT_DEFAULT_SETTING)); optionGroup.addItem(NotificationType.None.name()); optionGroup.setItemCaption(NotificationType.None.name(), AppContext.getMessage(ProjectSettingI18nEnum.OPT_NONE_SETTING)); optionGroup.addItem(NotificationType.Minimal.name()); optionGroup.setItemCaption(NotificationType.Minimal.name(), AppContext.getMessage(ProjectSettingI18nEnum.OPT_MINIMUM_SETTING)); optionGroup.addItem(NotificationType.Full.name()); optionGroup.setItemCaption(NotificationType.Full.name(), AppContext.getMessage(ProjectSettingI18nEnum.OPT_MAXIMUM_SETTING)); optionGroup.setHeight("100%"); body.addComponent(optionGroup); body.setExpandRatio(optionGroup, 1.0f); body.setComponentAlignment(optionGroup, Alignment.MIDDLE_LEFT); String levelVal = bean.getLevel(); if (levelVal == null) { optionGroup.select(NotificationType.Default.name()); } else { optionGroup.select(levelVal); } Button updateBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_UPDATE_LABEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { try { bean.setLevel((String) optionGroup.getValue()); ProjectNotificationSettingService projectNotificationSettingService = ApplicationContextUtil .getSpringBean(ProjectNotificationSettingService.class); if (bean.getId() == null) { projectNotificationSettingService.saveWithSession(bean, AppContext.getUsername()); } else { projectNotificationSettingService.updateWithSession(bean, AppContext.getUsername()); } NotificationUtil.showNotification( AppContext.getMessage(ProjectSettingI18nEnum.DIALOG_UPDATE_SUCCESS)); } catch (Exception e) { throw new MyCollabException(e); } } }); updateBtn.addStyleName(UIConstants.THEME_GREEN_LINK); updateBtn.setIcon(FontAwesome.REFRESH); body.addComponent(updateBtn); body.setComponentAlignment(updateBtn, Alignment.BOTTOM_LEFT); bodyWrapper.addComponent(body); this.addComponent(bodyWrapper); }
From source file:com.esofthead.mycollab.module.project.view.task.TaskAddPopup.java
License:Open Source License
public TaskAddPopup(final TaskDisplayComponent taskDisplayComp, final TaskList taskList) { final VerticalLayout taskLayout = new VerticalLayout(); taskLayout.addStyleName("taskadd-popup"); final VerticalLayout popupHeader = new VerticalLayout(); popupHeader.setWidth("100%"); popupHeader.setMargin(true);/*from w w w.j a v a 2 s. c o m*/ popupHeader.addStyleName("popup-header"); final Label titleLbl = new Label(AppContext.getMessage(TaskI18nEnum.DIALOG_NEW_TASK_TITLE)); titleLbl.addStyleName("bold"); popupHeader.addComponent(titleLbl); taskLayout.addComponent(popupHeader); this.task = new SimpleTask(); TabSheet taskContainer = new TabSheet(); final TaskInputForm taskInputForm = new TaskInputForm(); taskInputForm.setWidth("100%"); taskContainer.addTab(taskInputForm, AppContext.getMessage(GenericI18Enum.WINDOW_INFORMATION_TITLE)); this.taskNoteComponent = new TaskNoteLayout(); taskContainer.addTab(this.taskNoteComponent, AppContext.getMessage(TaskI18nEnum.FORM_NOTES_ATTACHMENT)); taskLayout.addComponent(taskContainer); final MHorizontalLayout controlsLayout = new MHorizontalLayout().withMargin(true); controlsLayout.addStyleName("popup-footer"); final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { taskDisplayComp.closeTaskAdd(); } }); cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK); final Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { if (taskInputForm.validateForm()) { final ProjectTaskService taskService = ApplicationContextUtil .getSpringBean(ProjectTaskService.class); task.setTasklistid(taskList.getId()); task.setProjectid(CurrentProjectVariables.getProjectId()); task.setSaccountid(AppContext.getAccountId()); task.setNotes(taskNoteComponent.getNote()); taskService.saveWithSession(task, AppContext.getUsername()); taskNoteComponent.saveContentsToRepo(task.getId()); taskDisplayComp.saveTaskSuccess(task); taskDisplayComp.closeTaskAdd(); } } }); saveBtn.setIcon(FontAwesome.SAVE); saveBtn.setStyleName(UIConstants.THEME_GREEN_LINK); controlsLayout.with(saveBtn, cancelBtn).alignAll(Alignment.MIDDLE_CENTER); taskLayout.addComponent(controlsLayout); taskLayout.setComponentAlignment(controlsLayout, Alignment.MIDDLE_RIGHT); this.setCompositionRoot(taskLayout); }
From source file:com.esofthead.mycollab.module.project.view.task.TaskDisplayComponent.java
License:Open Source License
private void showTaskGroupInfo() { if (this.isDisplayTaskListInfo) { AdvancedPreviewBeanForm<SimpleTaskList> previewForm = new AdvancedPreviewBeanForm<>(); previewForm.setWidth("100%"); previewForm.setFormLayoutFactory(new IFormLayoutFactory() { private static final long serialVersionUID = 1L; private GridFormLayoutHelper layoutHelper; @Override//from w w w. j av a 2 s . c o m public ComponentContainer getLayout() { this.layoutHelper = new GridFormLayoutHelper(2, 3, "100%", "180px", Alignment.TOP_LEFT); this.layoutHelper.getLayout().setWidth("100%"); this.layoutHelper.getLayout().addStyleName("colored-gridlayout"); this.layoutHelper.getLayout().setMargin(false); return this.layoutHelper.getLayout(); } @Override public void attachField(Object propertyId, Field<?> field) { if ("description".equals(propertyId)) { layoutHelper.addComponent(field, AppContext.getMessage(GenericI18Enum.FORM_DESCRIPTION), 0, 0, 2, "100%"); } else if ("owner".equals(propertyId)) { layoutHelper.addComponent(field, AppContext.getMessage(GenericI18Enum.FORM_ASSIGNEE), 0, 1); } else if ("milestoneid".equals(propertyId)) { layoutHelper.addComponent(field, AppContext.getMessage(TaskGroupI18nEnum.FORM_PHASE_FIELD), 1, 1); } } }); previewForm.setBeanFormFieldFactory( new AbstractBeanFieldGroupViewFieldFactory<SimpleTaskList>(previewForm) { private static final long serialVersionUID = 1L; @Override protected Field<?> onCreateField(Object propertyId) { if ("description".equals(propertyId)) { return new DefaultViewField(taskList.getDescription(), ContentMode.HTML); } else if ("owner".equals(propertyId)) { return new ProjectUserFormLinkField(taskList.getOwner(), taskList.getOwnerAvatarId(), taskList.getOwnerFullName()); } else if ("milestoneid".equals(propertyId)) { return new LinkViewField(taskList.getMilestoneName(), ProjectLinkBuilder.generateMilestonePreviewFullLink(taskList.getProjectid(), taskList.getMilestoneid()), ProjectAssetsManager.getAsset(ProjectTypeConstants.MILESTONE)); } return null; } }); this.addComponent(previewForm); previewForm.setBean(this.taskList); } this.taskDisplay = new TaskTableDisplay(TaskTableFieldDef.id, Arrays.asList(TaskTableFieldDef.taskname, TaskTableFieldDef.startdate, TaskTableFieldDef.duedate, TaskTableFieldDef.assignee, TaskTableFieldDef.percentagecomplete)); this.addComponent(this.taskDisplay); this.taskDisplay.addTableListener(new TableClickListener() { private static final long serialVersionUID = 1L; @Override public void itemClick(final TableClickEvent event) { final SimpleTask task = (SimpleTask) event.getData(); if ("taskname".equals(event.getFieldName())) { EventBusFactory.getInstance() .post(new TaskEvent.GotoRead(TaskDisplayComponent.this, task.getId())); } else if ("closeTask".equals(event.getFieldName()) || "reopenTask".equals(event.getFieldName()) || "pendingTask".equals(event.getFieldName()) || "deleteTask".equals(event.getFieldName())) { TaskDisplayComponent.this.removeAllComponents(); final ProjectTaskListService taskListService = ApplicationContextUtil .getSpringBean(ProjectTaskListService.class); TaskDisplayComponent.this.taskList = taskListService .findById(TaskDisplayComponent.this.taskList.getId(), AppContext.getAccountId()); TaskDisplayComponent.this.showTaskGroupInfo(); } } }); this.createTaskBtn = new Button(AppContext.getMessage(TaskI18nEnum.BUTTON_NEW_TASK), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final Button.ClickEvent event) { TaskDisplayComponent.this .removeComponent(TaskDisplayComponent.this.createTaskBtn.getParent()); TaskAddPopup taskAddView = new TaskAddPopup(TaskDisplayComponent.this, TaskDisplayComponent.this.taskList); TaskDisplayComponent.this.addComponent(taskAddView); } }); this.createTaskBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)); this.createTaskBtn.setIcon(FontAwesome.PLUS); this.createTaskBtn.setStyleName(UIConstants.THEME_GREEN_LINK); final VerticalLayout taskGroupFooter = new VerticalLayout(); taskGroupFooter.setMargin(true); taskGroupFooter.addStyleName("task-list-footer"); taskGroupFooter.addComponent(this.createTaskBtn); taskGroupFooter.setComponentAlignment(this.createTaskBtn, Alignment.MIDDLE_RIGHT); this.addComponent(taskGroupFooter); if (CollectionUtils.isNotEmpty(taskList.getSubTasks())) { taskDisplay.setCurrentDataList(taskList.getSubTasks()); } else { taskDisplay.setCurrentDataList(new ArrayList<SimpleTask>()); } }
From source file:com.esofthead.mycollab.module.project.view.task.TaskDisplayComponent.java
License:Open Source License
public void closeTaskAdd() { final VerticalLayout taskGroupFooter = new VerticalLayout(); taskGroupFooter.setMargin(true);//from w w w.j av a 2 s .c o m taskGroupFooter.addStyleName("task-list-footer"); taskGroupFooter.addComponent(this.createTaskBtn); taskGroupFooter.setComponentAlignment(this.createTaskBtn, Alignment.MIDDLE_RIGHT); this.addComponent(taskGroupFooter); Iterator<Component> comps = this.iterator(); while (comps.hasNext()) { Component component = comps.next(); if (component instanceof TaskAddPopup) { this.removeComponent(component); return; } } }
From source file:com.esofthead.mycollab.module.project.view.task.TaskFormLayoutFactory.java
License:Open Source License
@Override public Layout getLayout() { this.informationLayout = new GridFormLayoutHelper(2, 8, "100%", "180px", Alignment.TOP_LEFT); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(false);//from w w w. j av a 2 s. c o m this.informationLayout.getLayout().setMargin(false); this.informationLayout.getLayout().setWidth("100%"); this.informationLayout.getLayout().addStyleName("colored-gridlayout"); layout.addComponent(this.informationLayout.getLayout()); layout.setComponentAlignment(this.informationLayout.getLayout(), Alignment.BOTTOM_CENTER); return layout; }
From source file:com.esofthead.mycollab.module.project.view.task.TaskGroupFormLayoutFactory.java
License:Open Source License
@Override public Layout getLayout() { this.informationLayout = new GridFormLayoutHelper(2, 4, "100%", "180px", Alignment.TOP_LEFT); this.informationLayout.getLayout().addStyleName("colored-gridlayout"); this.informationLayout.getLayout().setMargin(false); this.informationLayout.getLayout().setWidth("100%"); final VerticalLayout layout = new VerticalLayout(); layout.addComponent(this.informationLayout.getLayout()); layout.setComponentAlignment(this.informationLayout.getLayout(), Alignment.BOTTOM_CENTER); return layout; }
From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfilePhotoUploadViewImpl.java
License:Open Source License
@SuppressWarnings("serial") @Override// w w w . j a v a2s. co m public void editPhoto(final byte[] imageData) { this.removeAllComponents(); LOG.debug("Receive avatar upload with size: " + imageData.length); try { originalImage = ImageIO.read(new ByteArrayInputStream(imageData)); } catch (IOException e) { throw new UserInvalidInputException("Invalid image type"); } originalImage = ImageUtil.scaleImage(originalImage, 650, 650); MHorizontalLayout previewBox = new MHorizontalLayout().withSpacing(true) .withMargin(new MarginInfo(false, true, true, false)).withWidth("100%"); Resource defaultPhoto = UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100); previewImage = new Embedded(null, defaultPhoto); previewImage.setWidth("100px"); previewBox.addComponent(previewImage); previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT); VerticalLayout previewBoxRight = new VerticalLayout(); previewBoxRight.setMargin(new MarginInfo(false, true, false, true)); Label lbPreview = new Label( "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p><p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. When you are happy with your photo, click the “Accept“ button.</p>", ContentMode.HTML); previewBoxRight.addComponent(lbPreview); MHorizontalLayout controlBtns = new MHorizontalLayout(); controlBtns.setSizeUndefined(); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { EventBusFactory.getInstance() .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null)); } }); cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK); Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); UserAvatarService userAvatarService = ApplicationContextUtil .getSpringBean(UserAvatarService.class); userAvatarService.uploadAvatar(image, AppContext.getUsername(), AppContext.getUserAvatarId()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException("Error when saving user avatar", e); } } } }); acceptBtn.setStyleName(UIConstants.THEME_GREEN_LINK); acceptBtn.setIcon(FontAwesome.CHECK); controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT); previewBoxRight.addComponent(controlBtns); previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT); previewBox.addComponent(previewBoxRight); previewBox.setExpandRatio(previewBoxRight, 1.0f); this.addComponent(previewBox); CssLayout cropBox = new CssLayout(); cropBox.addStyleName(UIConstants.PHOTO_CROPBOX); cropBox.setWidth("100%"); VerticalLayout currentPhotoBox = new VerticalLayout(); Resource resource = new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage), "image/png"); CropField cropField = new CropField(resource); cropField.setImmediate(true); cropField.setSelectionAspectRatio(1.0f); cropField.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { VCropSelection newSelection = (VCropSelection) event.getProperty().getValue(); int x1 = newSelection.getXTopLeft(); int y1 = newSelection.getYTopLeft(); int x2 = newSelection.getXBottomRight(); int y2 = newSelection.getYBottomRight(); if (x2 > x1 && y2 > y1) { BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { ImageIO.write(subImage, "png", outStream); scaleImageData = outStream.toByteArray(); displayPreviewImage(); } catch (IOException e) { LOG.error("Error while scale image: ", e); } } } }); currentPhotoBox.setWidth("650px"); currentPhotoBox.setHeight("650px"); currentPhotoBox.addComponent(cropField); cropBox.addComponent(currentPhotoBox); this.addComponent(previewBox); this.addComponent(cropBox); this.setExpandRatio(cropBox, 1.0f); }
From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfileReadViewImpl.java
License:Open Source License
private void displayUserAvatar() { this.userAvatar.removeAllComponents(); final Image cropField = UserAvatarControlFactory .createUserAvatarEmbeddedComponent(AppContext.getUserAvatarId(), 100); userAvatar.addComponent(cropField);//from w ww . j a v a 2 s . co m this.avatarAndPass.removeAllComponents(); avatarAndPass.addComponent(userAvatar); User user = formItem.getUser(); final VerticalLayout basicLayout = new VerticalLayout(); basicLayout.setSpacing(true); final HorizontalLayout userWrapper = new HorizontalLayout(); final Label userName = new Label(AppContext.getSession().getDisplayName()); userName.setStyleName("h1"); userWrapper.addComponent(userName); final Button btnChangeBasicInfo = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { UI.getCurrent().addWindow(new BasicInfoChangeWindow(formItem.getUser())); } }); btnChangeBasicInfo.setStyleName("link"); HorizontalLayout btnChangeBasicInfoWrapper = new HorizontalLayout(); btnChangeBasicInfoWrapper.setWidth("40px"); btnChangeBasicInfoWrapper.addComponent(btnChangeBasicInfo); btnChangeBasicInfoWrapper.setComponentAlignment(btnChangeBasicInfo, Alignment.MIDDLE_RIGHT); userWrapper.addComponent(btnChangeBasicInfoWrapper); basicLayout.addComponent(userWrapper); basicLayout.setComponentAlignment(userWrapper, Alignment.MIDDLE_LEFT); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_BIRTHDAY) + ": " + AppContext.formatDate(user.getDateofbirth()))); basicLayout.addComponent( new MHorizontalLayout(new Label(AppContext.getMessage(UserI18nEnum.FORM_EMAIL) + ": "), new LabelLink(user.getEmail(), "mailto:" + user.getEmail()))); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_TIMEZONE) + ": " + TimezoneMapper.getTimezone(user.getTimezone()).getDisplayName())); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_LANGUAGE) + ": " + AppContext.getMessage(LangI18Enum.class, user.getLanguage()))); HorizontalLayout passwordWrapper = new HorizontalLayout(); passwordWrapper .addComponent(new Label(AppContext.getMessage(ShellI18nEnum.FORM_PASSWORD) + ": ***********")); final Button btnChangePassword = new Button("Change", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { UI.getCurrent().addWindow(new PasswordChangeWindow(formItem.user)); } }); btnChangePassword.setStyleName("link"); HorizontalLayout btnChangePasswordWrapper = new HorizontalLayout(); btnChangePasswordWrapper.setWidth("50px"); btnChangePasswordWrapper.addComponent(btnChangePassword); btnChangePasswordWrapper.setComponentAlignment(btnChangePassword, Alignment.MIDDLE_RIGHT); passwordWrapper.addComponent(btnChangePasswordWrapper); basicLayout.addComponent(passwordWrapper); basicLayout.setComponentAlignment(passwordWrapper, Alignment.MIDDLE_LEFT); avatarAndPass.addComponent(basicLayout); avatarAndPass.setComponentAlignment(basicLayout, Alignment.TOP_LEFT); avatarAndPass.setExpandRatio(basicLayout, 1.0f); final UploadField avatarUploadField = new UploadField() { private static final long serialVersionUID = 1L; @Override 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("Do not support image format for avatar"); } else { mimeType = "image/png"; } } if (mimeType.equals("image/png")) { EventBusFactory.getInstance() .post(new ProfileEvent.GotoUploadPhoto(ProfileReadViewImpl.this, imageData)); } else { throw new UserInvalidInputException( "Upload file does not have valid image format. The supported formats are jpg/png"); } } }; avatarUploadField.addStyleName("upload-field"); avatarUploadField.setButtonCaption(AppContext.getMessage(UserI18nEnum.BUTTON_CHANGE_AVATAR)); avatarUploadField.setSizeUndefined(); avatarUploadField.setFieldType(FieldType.BYTE_ARRAY); this.userAvatar.addComponent(avatarUploadField); }