public GravatarPanel(final String idParam, final String emailParam) {
   super(idParam);
   if (emailParam == null) {
     LOGGER.debug(new StringResourceModel("nullEmailParamLogMessage", this, null).getString());
     addDefaultGravatarImage();
   } else {
     try {
       final byte[] hash = MessageDigest.getInstance(MD5).digest(emailParam.getBytes());
       final StringBuilder hashString = new StringBuilder();
       for (final byte elementLocal : hash) {
         final String hex = Integer.toHexString(elementLocal);
         if (hex.length() == 1) {
           hashString.append(ZERO);
           hashString.append(hex.charAt(hex.length() - 1));
         } else {
           hashString.append(hex.substring(hex.length() - 2));
         }
       }
       final Image imgLocal = new Image(WICKET_ID_GRAVATAR_IMG, (IResource) null);
       imgLocal.add(
           AttributeModifierFactory.newAttributeAppenderForSrc(
               "http://www.gravatar.com/avatar/" + hashString.toString() + DOT_JPG));
       imgLocal.add(
           AttributeModifierFactory.newAttributeAppenderForAlt(
               new StringResourceModel("gravatarAlt", this, null) + emailParam + DOT));
       add(imgLocal);
     } catch (final NoSuchAlgorithmException ex) {
       LOGGER.info(
           new StringResourceModel("md5HashAlgoNotFoundLogMessage", this, null).getString(), ex);
       addDefaultGravatarImage();
     }
   }
 }
 private void addDefaultGravatarImage() {
   final Image imgLocal = new Image(WICKET_ID_GRAVATAR_IMG, (IResource) null);
   imgLocal.add(
       AttributeModifierFactory.newAttributeAppenderForSrc(
           new StringResourceModel("defaultGravatarImageHref", this, null).getString()));
   imgLocal.add(
       AttributeModifierFactory.newAttributeAppenderForAlt(
           new StringResourceModel("defaultGravatarImageAlt", this, null).getString()));
   add(imgLocal);
 }
 @Override
 protected Link<T> createPageLink(MenuLinkItem menuLink) {
   String imageSrc = menuLink.getIcon();
   // default nebo ikonu
   Image image = new Image("icon", "");
   AttributeModifier attributeModifier =
       new AttributeModifier(
           "src", new Model<String>(imageSrc == null ? "/grass/img/tags/label_16.png" : imageSrc));
   image.add(attributeModifier);
   Link<T> link = super.createPageLink(menuLink);
   link.add(image);
   return link;
 }
示例#4
0
  protected Component getLoadingComponent(final String markupId) {
    Image image = new Image(markupId, PRELOADER);
    image.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return isLoadingVisible();
          }
        });

    return image;
  }
示例#5
0
 public ButtonFragment(String id, IModel<Button> model) {
   super(id, "buttonFragment", SortableList.this, model);
   final Button button = model.getObject();
   AjaxLink<Void> ajaxLink =
       new AjaxLink<Void>("button") {
         @Override
         public void onClick(AjaxRequestTarget target) {
           button.callback(target);
         }
       };
   Image image = new Image("buttonImg", button.getImage());
   image.setVisible(button.getImage() != null);
   ajaxLink.add(image);
   ajaxLink.add(new Label("buttonLabel", button.getTitle()));
   add(ajaxLink);
 }
  public UserPicturePanel(final String id, final User usr) {
    super(id);
    this.user = usr;

    // Form for uploading profile images
    fileUploadForm = new Form<>("fileUploadForm");
    fileUploadForm.setOutputMarkupId(true);

    // User image
    userPhoto =
        new NonCachingImage("userImage", user.getProfilePicture(User.PictureDimensions.Large));
    userPhoto.setOutputMarkupId(true);
    fileUploadForm.add(userPhoto);
    uploadField = new FileUploadField("fileUploadField");
    fileUploadForm.add(uploadField.setOutputMarkupId(true));
    fileUploadForm.setMaxSize(Bytes.kilobytes(MAX_SIZE));
    fileUploadForm.add(new Label("max", Model.of(Bytes.kilobytes(MAX_SIZE))));
    fileUploadForm.add(
        new AjaxSubmitLink("submit") {

          private static final long serialVersionUID = 1L;

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // Check whether an image has been provided to be uploaded
            FileUpload fileUpload = uploadField.getFileUpload();

            if (fileUpload != null) {
              try {
                uploadHelper.processUserFileUpload(fileUpload, user);
                userPhoto.setImageResource(user.getProfilePicture(User.PictureDimensions.Large));
                uploadField.clearInput();
                target.add(uploadField);
                target.add(userPhoto);
              } catch (IOException e) {
                getPage().error(e.getLocalizedMessage());
                target.add(((BasePage) getPage()).getFeedbackPanel());
              }
            }
          }
        });

    fileUploadForm.add(
        new AjaxSubmitLink("clear") {

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            uploadHelper.removeUserPictures(user);
            target.add(userPhoto);
          }
        });
    fileUploadForm.add(new UploadProgressBar("progress", fileUploadForm, uploadField));
    add(fileUploadForm);

    fileUploadForm.add(
        new AjaxSubmitLink("uploadGravatar") {

          /** */
          private static final long serialVersionUID = 1L;

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            // Attempt to download image from gravatar
            try {
              byte[] rawImage = gv.download(user.getMail());
              if (rawImage != null) {
                uploadHelper.processUserFileUpload(rawImage, user);
                userPhoto.setImageResource(user.getProfilePicture(User.PictureDimensions.Large));
                uploadField.clearInput();
                target.add(uploadField);
                target.add(userPhoto);
              }
            } catch (IOException e) {
              uploadHelper.removeUserPictures(user);
              target.add(userPhoto);
            }
          }
        });
  }
 @Override
 public void visible(boolean viewable) {
   image.setVisible(viewable);
 }
 @Override
 public void addBehavior(Behavior behavior) {
   image.add(behavior);
 }