FileDocCategorySizeDatePackage
SinkList.javaAPI DocExample3632Mon Aug 27 20:12:26 BST 2007com.google.gwt.sample.kitchensink.client

SinkList

public class SinkList extends com.google.gwt.user.client.ui.Composite
The left panel that contains all of the sinks, along with a short description of each.

Fields Summary
private com.google.gwt.user.client.ui.HorizontalPanel
list
private ArrayList
sinks
private int
selectedSink
Constructors Summary
public SinkList(Sink.Images images)


     
    initWidget(list);
    list.add(images.gwtLogo().createImage());
    setStyleName("ks-List");
  
Methods Summary
public voidaddSink(com.google.gwt.sample.kitchensink.client.Sink.SinkInfo info)

    String name = info.getName();
    int index = list.getWidgetCount() - 1;

    MouseLink link = new MouseLink(name, index);
    list.add(link);
    sinks.add(info);

    list.setCellVerticalAlignment(link, HorizontalPanel.ALIGN_BOTTOM);
    styleSink(index, false);
  
private voidcolorSink(int index, boolean on)

    String color = "";
    if (on) {
      color = ((SinkInfo) sinks.get(index)).getColor();
    }

    Widget w = list.getWidget(index + 1);
    DOM.setStyleAttribute(w.getElement(), "backgroundColor", color);
  
public com.google.gwt.sample.kitchensink.client.Sink.SinkInfofind(java.lang.String sinkName)

    for (int i = 0; i < sinks.size(); ++i) {
      SinkInfo info = (SinkInfo) sinks.get(i);
      if (info.getName().equals(sinkName)) {
        return info;
      }
    }

    return null;
  
private voidmouseOut(int index)

    if (index != selectedSink) {
      colorSink(index, false);
    }
  
private voidmouseOver(int index)

    if (index != selectedSink) {
      colorSink(index, true);
    }
  
public voidsetSinkSelection(java.lang.String name)

    if (selectedSink != -1) {
      styleSink(selectedSink, false);
    }

    for (int i = 0; i < sinks.size(); ++i) {
      SinkInfo info = (SinkInfo) sinks.get(i);
      if (info.getName().equals(name)) {
        selectedSink = i;
        styleSink(selectedSink, true);
        return;
      }
    }
  
private voidstyleSink(int index, boolean selected)

    String style = (index == 0) ? "ks-FirstSinkItem" : "ks-SinkItem";
    if (selected) {
      style += "-selected";
    }

    Widget w = list.getWidget(index + 1);
    w.setStyleName(style);

    colorSink(index, selected);