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

KitchenSink

public class KitchenSink extends Object implements com.google.gwt.core.client.EntryPoint, com.google.gwt.user.client.HistoryListener
Application that demonstrates all of the built-in widgets.

Fields Summary
private static final Sink.Images
images
protected SinkList
list
private com.google.gwt.sample.kitchensink.client.Sink.SinkInfo
curInfo
private Sink
curSink
private com.google.gwt.user.client.ui.HTML
description
private com.google.gwt.user.client.ui.VerticalPanel
panel
Constructors Summary
Methods Summary
protected voidloadSinks()
Adds all sinks to the list. Note that this does not create actual instances of all sinks yet (they are created on-demand). This can make a significant difference in startup time.

    list.addSink(Info.init());
    list.addSink(Widgets.init(images));
    list.addSink(Panels.init(images));
    list.addSink(Lists.init(images));
    list.addSink(Text.init());
    list.addSink(Popups.init());
  
public voidonHistoryChanged(java.lang.String token)


      
    // Find the SinkInfo associated with the history context. If one is
    // found, show it (It may not be found, for example, when the user mis-
    // types a URL, or on startup, when the first context will be "").
    SinkInfo info = list.find(token);
    if (info == null) {
      showInfo();
      return;
    }
    show(info, false);
  
public voidonModuleLoad()

    // Load all the sinks.
    loadSinks();

    panel.add(list);
    panel.add(description);
    panel.setWidth("100%");

    description.setStyleName("ks-Info");

    History.addHistoryListener(this);
    RootPanel.get().add(panel);

    // Show the initial screen.
    String initToken = History.getToken();
    if (initToken.length() > 0) {
      onHistoryChanged(initToken);
    } else {
      showInfo();
    }
  
public voidshow(com.google.gwt.sample.kitchensink.client.Sink.SinkInfo info, boolean affectHistory)

    // Don't bother re-displaying the existing sink. This can be an issue
    // in practice, because when the history context is set, our
    // onHistoryChanged() handler will attempt to show the currently-visible
    // sink.
    if (info == curInfo) {
      return;
    }
    curInfo = info;

    // Remove the old sink from the display area.
    if (curSink != null) {
      curSink.onHide();
      panel.remove(curSink);
    }

    // Get the new sink instance, and display its description in the
    // sink list.
    curSink = info.getInstance();
    list.setSinkSelection(info.getName());
    description.setHTML(info.getDescription());

    // If affectHistory is set, create a new item on the history stack. This
    // will ultimately result in onHistoryChanged() being called. It will call
    // show() again, but nothing will happen because it will request the exact
    // same sink we're already showing.
    if (affectHistory) {
      History.newItem(info.getName());
    }

    // Change the description background color.
    DOM.setStyleAttribute(description.getElement(), "backgroundColor",
        info.getColor());

    // Display the new sink.
    curSink.setVisible(false);
    panel.add(curSink);
    panel.setCellHorizontalAlignment(curSink, VerticalPanel.ALIGN_CENTER);
    curSink.setVisible(true);
    curSink.onShow();
  
private voidshowInfo()

    show(list.find("Intro"), false);