1 16 package com.google.gwt.sample.mail.client; 17 18 import com.google.gwt.user.client.DOM; 19 import com.google.gwt.user.client.Element; 20 import com.google.gwt.user.client.Event; 21 import com.google.gwt.user.client.ui.AbstractImagePrototype; 22 import com.google.gwt.user.client.ui.Composite; 23 import com.google.gwt.user.client.ui.StackPanel; 24 import com.google.gwt.user.client.ui.Widget; 25 26 33 public class Shortcuts extends Composite { 34 35 39 public interface Images extends Contacts.Images, Mailboxes.Images { 40 AbstractImagePrototype contactsgroup(); 41 42 AbstractImagePrototype leftCorner(); 43 44 AbstractImagePrototype mailgroup(); 45 46 AbstractImagePrototype rightCorner(); 47 48 AbstractImagePrototype tasksgroup(); 49 } 50 51 private int nextHeaderIndex = 0; 52 53 private StackPanel stackPanel = new StackPanel() { 54 public void onBrowserEvent(Event event) { 55 int oldIndex = getSelectedIndex(); 56 super.onBrowserEvent(event); 57 int newIndex = getSelectedIndex(); 58 if (oldIndex != newIndex) { 59 updateSelectedStyles(oldIndex, newIndex); 60 } 61 } 62 }; 63 64 69 public Shortcuts(Images images) { 70 add(images, new Mailboxes(images), images.mailgroup(), "Mail"); 72 add(images, new Tasks(), images.tasksgroup(), "Tasks"); 73 add(images, new Contacts(images), images.contactsgroup(), "Contacts"); 74 75 initWidget(stackPanel); 76 } 77 78 protected void onLoad() { 79 stackPanel.showStack(0); 81 updateSelectedStyles(-1, 0); 82 } 83 84 private void add(Images images, Widget widget, AbstractImagePrototype imageProto, 85 String caption) { 86 widget.addStyleName("mail-StackContent"); 87 stackPanel.add(widget, createHeaderHTML(images, imageProto, caption), true); 88 } 89 90 private String computeHeaderId(int index) { 91 return "header-" + this.hashCode() + "-" + index; 92 } 93 94 102 private String createHeaderHTML(Images images, 103 AbstractImagePrototype imageProto, String caption) { 104 105 boolean isTop = (nextHeaderIndex == 0); 106 String cssId = computeHeaderId(nextHeaderIndex); 107 nextHeaderIndex++; 108 109 String captionHTML = "<table class='caption' cellpadding='0' cellspacing='0'>" 110 + "<tr><td class='lcaption'>" + imageProto.getHTML() 111 + "</td><td class='rcaption'><b style='white-space:nowrap'>" + caption 112 + "</b></td></tr></table>"; 113 114 return "<table id='" + cssId + "' align='left' cellpadding='0' cellspacing='0'" 115 + (isTop ? " class='is-top'" : "" ) + "><tbody>" 116 + "<tr><td class='box-00'>" + images.leftCorner().getHTML() + "</td>" 117 + "<td class='box-10'> </td>" 118 + "<td class='box-20'>" + images.rightCorner().getHTML() + "</td>" 119 + "</tr><tr>" 120 + "<td class='box-01'> </td>" 121 + "<td class='box-11'>" + captionHTML + "</td>" 122 + "<td class='box-21'> </td>" 123 + "</tr></tbody></table>"; 124 } 125 126 131 private void updateSelectedStyles(int oldIndex, int newIndex) { 132 oldIndex++; 133 if (oldIndex > 0 && oldIndex < stackPanel.getWidgetCount()) { 134 Element elem = DOM.getElementById(computeHeaderId(oldIndex)); 135 DOM.setElementProperty(elem, "className", ""); 136 } 137 138 newIndex++; 139 if (newIndex > 0 && newIndex < stackPanel.getWidgetCount()) { 140 Element elem = DOM.getElementById(computeHeaderId(newIndex)); 141 DOM.setElementProperty(elem, "className", "is-beneath-selected"); 142 } 143 } 144 } 145 | Popular Tags |