List of usage examples for org.apache.wicket.markup.html.image NonCachingImage add
public Component add(final Behavior... behaviors)
From source file:com.evolveum.midpoint.web.component.menu.UserMenuPanel.java
License:Apache License
private void initLayout() { WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX); add(iconBox);//w ww .j av a 2 s . c om NonCachingImage img = new NonCachingImage(ID_PHOTO, new AbstractReadOnlyModel<AbstractResource>() { @Override public AbstractResource getObject() { if (jpegPhoto == null) { return null; } else { return new ByteArrayResource("image/jpeg", jpegPhoto); } } }); img.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (userModel != null && userModel.getObject() == null) { loadModel(null); } return jpegPhoto != null; } }); iconBox.add(img); ContextImage icon = new ContextImage(ID_ICON, "img/placeholder.png"); icon.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (userModel != null && userModel.getObject() == null) { loadModel(null); } return jpegPhoto == null; } }); iconBox.add(icon); Label usernameLink = new Label(ID_USERNAME_LINK, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return getShortUserName(); } }); add(usernameLink); WebMarkupContainer panelIconBox = new WebMarkupContainer(ID_PANEL_ICON_BOX); add(panelIconBox); NonCachingImage panelImg = new NonCachingImage(ID_PANEL_PHOTO, new AbstractReadOnlyModel<AbstractResource>() { @Override public AbstractResource getObject() { if (jpegPhoto == null) { return null; } else { return new ByteArrayResource("image/jpeg", jpegPhoto); } } }); panelImg.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (userModel != null && userModel.getObject() == null) { loadModel(null); } return jpegPhoto != null; } }); panelIconBox.add(panelImg); ContextImage panelIcon = new ContextImage(ID_PANEL_ICON, "img/placeholder.png"); panelIcon.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (userModel != null && userModel.getObject() == null) { loadModel(null); } return jpegPhoto == null; } }); panelIconBox.add(panelIcon); Label username = new Label(ID_USERNAME, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return getShortUserName(); } }); username.setRenderBodyOnly(true); add(username); ExternalLink logoutLink = new ExternalLink(ID_LOGOUT_LINK, new Model<>(RequestCycle.get().getRequest().getContextPath() + "/j_spring_security_logout"), createStringResource("UserMenuPanel.logout")); add(logoutLink); AjaxButton editPasswordQ = new AjaxButton(ID_PASSWORD_QUESTIONS, createStringResource("UserMenuPanel.editPasswordQuestions")) { @Override public void onClick(AjaxRequestTarget target) { PageMyPasswordQuestions myPasswordQuestions = new PageMyPasswordQuestions( passwordQuestionsDtoIModel); setResponsePage(myPasswordQuestions); } }; add(editPasswordQ); if (!isPasswordModelLoaded) { passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) { private static final long serialVersionUID = 1L; @Override protected PasswordQuestionsDto load() { return loadModel(null); } }; isPasswordModelLoaded = true; } securityPolicyQuestionsModel = new LoadableModel<List<SecurityQuestionDefinitionType>>(false) { @Override protected List<SecurityQuestionDefinitionType> load() { return loadSecurityPloicyQuestionsModel(); } }; editPasswordQ.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { if (securityPolicyQuestionsModel == null || securityPolicyQuestionsModel.getObject() == null) { loadSecurityPloicyQuestionsModel(); } return hasQuestions() || (securityPolicyQuestionsModel.getObject() != null && securityPolicyQuestionsModel.getObject().size() > 0); } }); }
From source file:com.userweave.components.imageUpload.IconUploadPanel.java
License:Open Source License
private NonCachingImage getImage(int width, int height) { NonCachingImage image = new NonCachingImage("image", new DynamicImageResource() { private static final long serialVersionUID = 1L; @Override/*from w ww . j av a 2s .co m*/ protected byte[] getImageData(Attributes attributes) { byte[] imageData = imageUpload.getImageData(); if (imageData != null) { return imageData; } else { return new byte[] {}; } } }); if ((height > 0) && (width > 0)) { image.add(new AttributeModifier("style", new Model<String>( "width: " + Integer.toString(width) + "px;" + "height: " + Integer.toString(height) + "px;"))); } image.setOutputMarkupId(true); return image; }
From source file:com.userweave.components.valueListPanel.imageValueListPanel.ImageDisplayPanel.java
License:Open Source License
/** * Default constructor/*www. j av a 2 s. co m*/ * * @param id * Component markup id. * @param byteArray * Image data. * @param width * If larger than 0, the image will be scaled on this width, * if the height value is also larger than 0. * @param height * If larger than 0, the image will be scaled on this height, * if the width value is also larger than 0. */ public ImageDisplayPanel(String id, final ByteArray byteArray, final int width, final int height) { super(id); NonCachingImage image = new NonCachingImage("image", new DynamicImageResource() { private static final long serialVersionUID = 1L; @Override protected byte[] getImageData(Attributes attributes) { return byteArray.getByteArray(); } }); add(image); // show image in original size if width and height equals 0 if (width != 0 && height != 0) { image.add(new AttributeAppender("style", new Model<String>( "width:" + Integer.toString(width) + "px;" + "height:" + Integer.toString(height) + "px;"), ";")); } }
From source file:org.projectforge.web.wicket.flowlayout.ImageUploadPanel.java
License:Open Source License
private NonCachingImage createImage() { NonCachingImage img = new NonCachingImage("image", new AbstractReadOnlyModel<DynamicImageResource>() { @Override//w w w. j ava2 s. c om public DynamicImageResource getObject() { final DynamicImageResource dir = new DynamicImageResource() { @Override protected byte[] getImageData(final Attributes attributes) { byte[] result = file.getObject(); if (result == null || result.length < 1) { try { result = IOUtils.toByteArray( getClass().getClassLoader().getResource("images/noImage.png").openStream()); } catch (final IOException ex) { log.error("Exception encountered " + ex, ex); } } return result; } }; dir.setFormat("image/png"); return dir; } }); img.setOutputMarkupId(true); img.add(new AttributeModifier("height", Integer.toString(200))); return img; }