1 16 package com.google.gwt.sample.mail.client; 17 18 import com.google.gwt.user.client.ui.AbstractImagePrototype; 19 import com.google.gwt.user.client.ui.ClickListener; 20 import com.google.gwt.user.client.ui.Composite; 21 import com.google.gwt.user.client.ui.HTML; 22 import com.google.gwt.user.client.ui.HorizontalPanel; 23 import com.google.gwt.user.client.ui.ImageBundle; 24 import com.google.gwt.user.client.ui.Label; 25 import com.google.gwt.user.client.ui.PopupPanel; 26 import com.google.gwt.user.client.ui.SimplePanel; 27 import com.google.gwt.user.client.ui.VerticalPanel; 28 import com.google.gwt.user.client.ui.Widget; 29 30 33 public class Contacts extends Composite { 34 35 38 public interface Images extends ImageBundle { 39 42 AbstractImagePrototype defaultPhoto(); 43 } 44 45 48 private class Contact { 49 public String email; 50 public String name; 51 52 public Contact(String name, String email) { 53 this.name = name; 54 this.email = email; 55 } 56 } 57 58 61 private class ContactPopup extends PopupPanel { 62 63 public ContactPopup(Contact contact) { 64 super(true); 67 68 VerticalPanel inner = new VerticalPanel(); 69 Label nameLabel = new Label(contact.name); 70 Label emailLabel = new Label(contact.email); 71 inner.add(nameLabel); 72 inner.add(emailLabel); 73 74 HorizontalPanel hp = new HorizontalPanel(); 75 hp.setSpacing(4); 76 hp.add(images.defaultPhoto().createImage()); 77 hp.add(inner); 78 79 add(hp); 80 setStyleName("mail-ContactPopup"); 81 nameLabel.setStyleName("mail-ContactPopupName"); 82 emailLabel.setStyleName("mail-ContactPopupEmail"); 83 } 84 } 85 86 private Contact[] contacts = new Contact[] { 87 new Contact("Benoit Mandelbrot", "benoit@example.com"), 88 new Contact("Albert Einstein", "albert@example.com"), 89 new Contact("Rene Descartes", "rene@example.com"), 90 new Contact("Bob Saget", "bob@example.com"), 91 new Contact("Ludwig von Beethoven", "ludwig@example.com"), 92 new Contact("Richard Feynman", "richard@example.com"), 93 new Contact("Alan Turing", "alan@example.com"), 94 new Contact("John von Neumann", "john@example.com")}; 95 96 private VerticalPanel panel = new VerticalPanel(); 97 private final Images images; 98 99 public Contacts(Images images) { 100 SimplePanel outer = new SimplePanel(); 101 outer.setWidget(panel); 102 103 this.images = images; 104 for (int i = 0; i < contacts.length; ++i) { 106 addContact(contacts[i]); 107 } 108 109 initWidget(outer); 110 setStyleName("mail-Contacts"); 111 } 112 113 private void addContact(final Contact contact) { 114 final HTML link = new HTML("<a HREF='javascript:;'>" + contact.name 115 + "</a>"); 116 panel.add(link); 117 118 link.addClickListener(new ClickListener() { 120 public void onClick(Widget sender) { 121 ContactPopup popup = new ContactPopup(contact); 122 int left = link.getAbsoluteLeft() + 14; 123 int top = link.getAbsoluteTop() + 14; 124 popup.setPopupPosition(left, top); 125 popup.show(); 126 } 127 }); 128 } 129 } 130 | Popular Tags |