I have been searched the gwt-related groups for the question, but it
seems that there are no related discussions, so I post the question
here.

The java source code in client folder generated by applicationCreator
script contains code segment:

......
Button button = new Button("Click me");
......
final DialogBox dialogBox = new DialogBox();
......
button.addClickListener(new ClickListener() {
   public void onClick(Widget sender) {
      dialogBox.center();
      dialogBox.show();
   }
});

when user clicks the "Click me" button, program logic will run
dialogBox.center(); and then dialogBox.show(); using Eclipse, we can
conveniently see the javadoc descriptions of these two methods:

void com.google.gwt.user.client.ui.PopupPanel.center()
Centers the popup in the browser window and shows it. If the popup was
already showing, then the popup is centered.

void com.google.gwt.user.client.ui.PopupPanel.show()
Shows the popup. It must have a child widget before this method is
called.

By the descriptions, the center() method has already included the
function of showing the popup. Also, examining the code of them:

public void center() {
    boolean initiallyShowing = showing;
    boolean initiallyAnimated = isAnimationEnabled;

    if (!initiallyShowing) {
      setVisible(false);
      setAnimationEnabled(false);
      show();
    }

    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
    int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
    setPopupPosition(Window.getScrollLeft() + left, Window.getScrollTop
() + top);

    if (!initiallyShowing) {
      hide();
      setVisible(true);
      setAnimationEnabled(initiallyAnimated);
      show();
    }
}

public void show() {
    if (showing) {
      return;
    }
    showing = true;
    DOM.addEventPreview(this);
    resizeAnimation.setState(true);
}

If 'showing' is false, the code in center() will call show(); if
'showing' is true, center() will not call show(), and further, in this
situation, the show() will return immediately and thus do nothing.
This means that the center() method has already included the function
of showing the popup by calling show(), and if 'showing' is true, the
final results are the same. I have tried deleting the line of code
dialogBox.show(); and run in hosted mode and web mode, the dialog
display results are the same as retain this line of code. I wonder
whether there are extra effects or special purposes to call show()
immediately after center() in the matter of showing a popup in the
center of browser window. The gwt version is 1.5.3.

Thanks in advance.

Austin

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to