James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
5e3521 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.wicket.panels;
17
18 import org.eclipse.jgit.lib.PersonIdent;
19
f790d5 20 import com.gitblit.AvatarGenerator;
5e3521 21 import com.gitblit.Keys;
JM 22 import com.gitblit.models.UserModel;
23 import com.gitblit.wicket.ExternalImage;
24 import com.gitblit.wicket.WicketUtils;
25
26 /**
27  * Represents a Gravatar image.
28  *
29  * @author James Moger
30  *
31  */
b57b9e 32 public class AvatarImage extends BasePanel {
5e3521 33
JM 34     private static final long serialVersionUID = 1L;
35
b57b9e 36     public AvatarImage(String id, PersonIdent person) {
5e3521 37         this(id, person, 0);
JM 38     }
39
b57b9e 40     public AvatarImage(String id, PersonIdent person, int width) {
5e3521 41         this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
JM 42     }
43
b57b9e 44     public AvatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
5e3521 45         this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
JM 46     }
47
b57b9e 48     public AvatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
5e3521 49         this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
JM 50     }
51
b57b9e 52     public AvatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
5e3521 53         super(id);
JM 54
f790d5 55         AvatarGenerator avatarGenerator = app().runtime().getInjector().getInstance(AvatarGenerator.class);
JM 56         String url = avatarGenerator.getURL(username, emailaddress, identicon, width);
5e3521 57         ExternalImage image = new ExternalImage("image", url);
JM 58         if (cssClass != null) {
59             WicketUtils.setCssClass(image, cssClass);
60         }
61         add(image);
62         WicketUtils.setHtmlTooltip(image, username);
63         setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
64     }
65
66     public void setTooltip(String tooltip) {
67         WicketUtils.setHtmlTooltip(get("image"), tooltip);
68     }
797322 69 }