Example usage for com.google.gwt.user.client.ui HorizontalPanel setSpacing

List of usage examples for com.google.gwt.user.client.ui HorizontalPanel setSpacing

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HorizontalPanel setSpacing.

Prototype

public void setSpacing(int spacing) 

Source Link

Document

Sets the amount of spacing between this panel's cells.

Usage

From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackPanel.java

License:Apache License

/**
 * Create the list of Contacts.//from  w  w w . j a v  a 2 s  .c o  m
 *
 * @param images the {@link Images} used in the Contacts
 * @return the list of contacts
 */
@ShowcaseSource
private VerticalPanel createContactsItem(Images images) {
    // Create a popup to show the contact info when a contact is clicked
    HorizontalPanel contactPopupContainer = new HorizontalPanel();
    contactPopupContainer.setSpacing(5);
    contactPopupContainer.add(new Image(images.defaultContact()));
    final HTML contactInfo = new HTML();
    contactPopupContainer.add(contactInfo);
    final PopupPanel contactPopup = new PopupPanel(true, false);
    contactPopup.setWidget(contactPopupContainer);

    // Create the list of contacts
    VerticalPanel contactsPanel = new VerticalPanel();
    contactsPanel.setSpacing(4);
    String[] contactNames = constants.cwStackPanelContacts();
    String[] contactEmails = constants.cwStackPanelContactsEmails();
    for (int i = 0; i < contactNames.length; i++) {
        final String contactName = contactNames[i];
        final String contactEmail = contactEmails[i];
        final Anchor contactLink = new Anchor(contactName);
        contactsPanel.add(contactLink);

        // Open the contact info popup when the user clicks a contact
        contactLink.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // Set the info about the contact
                contactInfo.setHTML(contactName + "<br><i>" + contactEmail + "</i>");

                // Show the popup of contact info
                int left = contactLink.getAbsoluteLeft() + 14;
                int top = contactLink.getAbsoluteTop() + 14;
                contactPopup.setPopupPosition(left, top);
                contactPopup.show();
            }
        });
    }
    return contactsPanel;
}

From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackPanel.java

License:Apache License

/**
 * Get a string representation of the header that includes an image and some
 * text.//from w ww  . j  ava2s  .  co m
 *
 * @param text the header text
 * @param image the {@link ImageResource} to add next to the header
 * @return the header as a string
 */
@ShowcaseSource
private String getHeaderString(String text, ImageResource image) {
    // Add the image and text to a horizontal panel
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(0);
    hPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    hPanel.add(new Image(image));
    HTML headerText = new HTML(text);
    headerText.setStyleName("cw-StackPanelHeader");
    hPanel.add(headerText);

    // Return the HTML string for the panel
    return hPanel.getElement().getString();
}

From source file:com.google.gwt.sample.showcase.client.content.other.CwAnimation.java

License:Apache License

/**
 * Initialize this example.//w ww .  j a va2 s  . com
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a new panel
    absolutePanel = new AbsolutePanel();
    absolutePanel.setSize("250px", "250px");
    absolutePanel.ensureDebugId("cwAbsolutePanel");

    // Add a widget that we will animate
    animateeTop = new Image(Showcase.images.gwtLogoThumb());
    animateeBottom = new Image(Showcase.images.gwtLogoThumb());
    animateeLeft = new Image(Showcase.images.gwtLogoThumb());
    animateeRight = new Image(Showcase.images.gwtLogoThumb());
    absolutePanel.add(animateeTop);
    absolutePanel.add(animateeBottom);
    absolutePanel.add(animateeLeft);
    absolutePanel.add(animateeRight);

    // Wrap the absolute panel in a DecoratorPanel
    DecoratorPanel absolutePanelWrapper = new DecoratorPanel();
    absolutePanelWrapper.setWidget(absolutePanel);

    // Create the options bar
    DecoratorPanel optionsWrapper = new DecoratorPanel();
    optionsWrapper.setWidget(createOptionsBar());

    // Add the components to a panel and return it
    HorizontalPanel mainLayout = new HorizontalPanel();
    mainLayout.setSpacing(10);
    mainLayout.add(optionsWrapper);
    mainLayout.add(absolutePanelWrapper);

    // Create the custom animation
    animation = new CustomAnimation();

    // Set the start position of the widgets
    animation.onComplete();

    // Return the layout
    return mainLayout;
}

From source file:com.google.gwt.sample.showcase.client.content.other.CwFrame.java

License:Apache License

/**
 * Initialize this example./* www. j  a v a 2s  .  c  o m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a new frame
    String url = GWT.getModuleBaseURL();
    final Frame frame = new Frame(url);
    frame.setSize("700px", "300px");
    frame.ensureDebugId("cwFrame");

    // Create a form to set the location of the frame
    final TextBox locationBox = new TextBox();
    locationBox.setText(url);
    Button setLocationButton = new Button(constants.cwFrameSetLocation());
    HorizontalPanel optionsPanel = new HorizontalPanel();
    optionsPanel.setSpacing(8);
    optionsPanel.add(locationBox);
    optionsPanel.add(setLocationButton);

    // Change the location when the user clicks the button
    setLocationButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            frame.setUrl(locationBox.getText());
        }
    });

    // Change the location when the user presses enter
    locationBox.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                frame.setUrl(locationBox.getText());
            }
        }

    });

    // Add everything to a panel and return it
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(optionsPanel);
    vPanel.add(frame);
    return vPanel;
}

From source file:com.google.gwt.sample.showcase.client.content.panels.CwAbsolutePanel.java

License:Apache License

/**
 * Initialize this example./*from   w  w  w . j  av  a 2s .  c o  m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a new panel
    widgetMap = new LinkedHashMap<String, Widget>();
    absolutePanel = new AbsolutePanel();
    absolutePanel.setSize("250px", "250px");
    absolutePanel.ensureDebugId("cwAbsolutePanel");

    // Add an HTML widget to the panel
    String[] widgetNames = constants.cwAbsolutePanelWidgetNames();
    HTML text = new HTML(constants.cwAbsolutePanelHelloWorld());
    absolutePanel.add(text, 10, 20);
    widgetMap.put(widgetNames[0], text);

    // Add a Button to the panel
    Button button = new Button(constants.cwAbsolutePanelClickMe());
    absolutePanel.add(button, 80, 45);
    widgetMap.put(widgetNames[1], button);

    // Add a Button to the panel
    Grid grid = new Grid(2, 3);
    grid.setBorderWidth(1);
    for (int i = 0; i < 3; i++) {
        grid.setHTML(0, i, i + "");
        grid.setWidget(1, i, new Image(Showcase.images.gwtLogoThumb()));
    }
    absolutePanel.add(grid, 60, 100);
    widgetMap.put(widgetNames[2], grid);

    // Wrap the absolute panel in a DecoratorPanel
    DecoratorPanel absolutePanelWrapper = new DecoratorPanel();
    absolutePanelWrapper.setWidget(absolutePanel);

    // Create the options bar
    DecoratorPanel optionsWrapper = new DecoratorPanel();
    optionsWrapper.setWidget(createOptionsBar());

    // Add the components to a panel and return it
    HorizontalPanel mainLayout = new HorizontalPanel();
    mainLayout.setSpacing(10);
    mainLayout.add(optionsWrapper);
    mainLayout.add(absolutePanelWrapper);

    return mainLayout;
}

From source file:com.google.gwt.sample.showcase.client.content.panels.CwHorizontalPanel.java

License:Apache License

/**
 * Initialize this example.// w w w.j av a  2s  .  c  o  m
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a Horizontal Panel
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(5);

    // Add some content to the panel
    for (int i = 1; i < 5; i++) {
        hPanel.add(new Button(constants.cwHorizontalPanelButton() + " " + i));
    }

    // Return the content
    hPanel.ensureDebugId("cwHorizontalPanel");
    return hPanel;
}

From source file:com.google.gwt.sample.showcase.client.content.text.CwBasicText.java

License:Apache License

/**
 * Create a TextBox example that includes the text box and an optional handler
 * that updates a Label with the currently selected text.
 *
 * @param textBox the text box to handle
 * @param addSelection add handlers to update label
 * @return the Label that will be updated
 *//*from www  .j  a v a 2  s .co m*/
@ShowcaseSource
private HorizontalPanel createTextExample(final TextBoxBase textBox, boolean addSelection) {
    // Add the text box and label to a panel
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(4);
    hPanel.add(textBox);

    // Add handlers
    if (addSelection) {
        // Create the new label
        final Label label = new Label(constants.cwBasicTextSelected() + ": 0, 0");

        // Add a KeyUpHandler
        textBox.addKeyUpHandler(new KeyUpHandler() {
            public void onKeyUp(KeyUpEvent event) {
                updateSelectionLabel(textBox, label);
            }
        });

        // Add a ClickHandler
        textBox.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                updateSelectionLabel(textBox, label);
            }
        });

        // Add the label to the box
        hPanel.add(label);
    }

    // Return the panel
    return hPanel;
}

From source file:com.google.gwt.sample.showcase.client.content.widgets.CwBasicButton.java

License:Apache License

/**
 * Initialize this example.// w  ww.j  a v  a 2s  .  c o m
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a panel to align the widgets
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(10);

    // Add a normal button
    Button normalButton = new Button(constants.cwBasicButtonNormal(), new ClickHandler() {
        public void onClick(ClickEvent event) {
            Window.alert(constants.cwBasicButtonClickMessage());
        }
    });
    normalButton.ensureDebugId("cwBasicButton-normal");
    hPanel.add(normalButton);

    // Add a disabled button
    Button disabledButton = new Button(constants.cwBasicButtonDisabled());
    disabledButton.ensureDebugId("cwBasicButton-disabled");
    disabledButton.setEnabled(false);
    hPanel.add(disabledButton);

    // Return the panel
    return hPanel;
}

From source file:com.google.gwt.sample.showcase.client.content.widgets.CwCustomButton.java

License:Apache License

/**
 * Initialize this example./*  ww w.j  av a2s . c  o  m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a panel to layout the widgets
    VerticalPanel vpanel = new VerticalPanel();
    HorizontalPanel pushPanel = new HorizontalPanel();
    pushPanel.setSpacing(10);
    HorizontalPanel togglePanel = new HorizontalPanel();
    togglePanel.setSpacing(10);

    // Combine all the panels
    vpanel.add(new HTML(constants.cwCustomButtonPush()));
    vpanel.add(pushPanel);
    vpanel.add(new HTML("<br><br>" + constants.cwCustomButtonToggle()));
    vpanel.add(togglePanel);

    // Add a normal PushButton
    PushButton normalPushButton = new PushButton(new Image(Showcase.images.gwtLogo()));
    normalPushButton.ensureDebugId("cwCustomButton-push-normal");
    pushPanel.add(normalPushButton);

    // Add a disabled PushButton
    PushButton disabledPushButton = new PushButton(new Image(Showcase.images.gwtLogo()));
    disabledPushButton.ensureDebugId("cwCustomButton-push-disabled");
    disabledPushButton.setEnabled(false);
    pushPanel.add(disabledPushButton);

    // Add a normal ToggleButton
    ToggleButton normalToggleButton = new ToggleButton(new Image(Showcase.images.gwtLogo()));
    normalToggleButton.ensureDebugId("cwCustomButton-toggle-normal");
    togglePanel.add(normalToggleButton);

    // Add a disabled ToggleButton
    ToggleButton disabledToggleButton = new ToggleButton(new Image(Showcase.images.gwtLogo()));
    disabledToggleButton.ensureDebugId("cwCustomButton-toggle-disabled");
    disabledToggleButton.setEnabled(false);
    togglePanel.add(disabledToggleButton);

    // Return the panel
    return vpanel;
}

From source file:com.google.gwt.sample.stockwatcher.client.Cells.java

private void loadLinks() {
    RootPanel links = RootPanel.get("navigationLinks");
    links.clear();/* w  w  w .  j  ava 2s  .  c  om*/

    cellListLink.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            loadContent(createCellList());
        }
    });

    cellTableLink.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            loadContent(createCellTable());
        }
    });

    cellTreeLink.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            loadContent(createCellTree());
        }
    });

    cellBrowserLink.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            loadContent(createCellBrowser());
        }
    });

    HorizontalPanel linksPanel = new HorizontalPanel();
    linksPanel.setSpacing(5);

    linksPanel.add(cellListLink);
    linksPanel.add(cellTableLink);
    linksPanel.add(cellTreeLink);
    linksPanel.add(cellBrowserLink);

    links.add(linksPanel);
}