List of usage examples for com.google.gwt.user.client.ui HorizontalPanel add
@Override public void add(Widget w)
From source file:com.google.gwt.sample.showcase.client.content.i18n.CwPluralFormsExample.java
License:Apache License
/** * Initialize this example.//from w w w.j ava2 s .com */ @ShowcaseSource @Override public Widget onInitialize() { // Create the internationalized error messages pluralMessages = GWT.create(PluralMessages.class); // Use a FlexTable to layout the content FlexTable layout = new FlexTable(); FlexCellFormatter formatter = layout.getFlexCellFormatter(); layout.setCellSpacing(5); // Add a link to the source code of the Interface final String rawFile = getSimpleName(PluralMessages.class); Anchor link = new Anchor(rawFile); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { fireRawSourceRequest(rawFile + ".java"); } }); HorizontalPanel linkPanel = new HorizontalPanel(); linkPanel.setSpacing(3); linkPanel.add(new HTML(constants.cwPluralFormsExampleLinkText())); linkPanel.add(link); layout.setWidget(0, 0, linkPanel); formatter.setColSpan(0, 0, 2); // Add argument 0 arg0Box = new TextBox(); arg0Box.setText("13"); layout.setHTML(2, 0, constants.cwPluralFormsExampleArg0Label()); layout.setWidget(2, 1, arg0Box); // Add the formatted message formattedMessage = new Label(); layout.setHTML(5, 0, constants.cwPluralFormsExampleFormattedLabel()); layout.setWidget(5, 1, formattedMessage); formatter.setVerticalAlignment(5, 0, HasVerticalAlignment.ALIGN_TOP); // Add handlers to all of the argument boxes KeyUpHandler keyUpHandler = new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateMessage(); } }; arg0Box.addKeyUpHandler(keyUpHandler); // Return the layout Widget updateMessage(); return layout; }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwListBox.java
License:Apache License
/** * Initialize this example.// ww w.java2s.c o m */ @ShowcaseSource @Override public Widget onInitialize() { // Create a panel to align the Widgets HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setSpacing(20); // Add a drop box with the list types final ListBox dropBox = new ListBox(false); String[] listTypes = constants.cwListBoxCategories(); for (int i = 0; i < listTypes.length; i++) { dropBox.addItem(listTypes[i]); } dropBox.ensureDebugId("cwListBox-dropBox"); VerticalPanel dropBoxPanel = new VerticalPanel(); dropBoxPanel.setSpacing(4); dropBoxPanel.add(new HTML(constants.cwListBoxSelectCategory())); dropBoxPanel.add(dropBox); hPanel.add(dropBoxPanel); // Add a list box with multiple selection enabled final ListBox multiBox = new ListBox(true); multiBox.ensureDebugId("cwListBox-multiBox"); multiBox.setWidth("11em"); multiBox.setVisibleItemCount(10); VerticalPanel multiBoxPanel = new VerticalPanel(); multiBoxPanel.setSpacing(4); multiBoxPanel.add(new HTML(constants.cwListBoxSelectAll())); multiBoxPanel.add(multiBox); hPanel.add(multiBoxPanel); // Add a handler to handle drop box events dropBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { showCategory(multiBox, dropBox.getSelectedIndex()); multiBox.ensureDebugId("cwListBox-multiBox"); } }); // Show default category showCategory(multiBox, 0); multiBox.ensureDebugId("cwListBox-multiBox"); // Return the panel return hPanel; }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java
License:Apache License
/** * Create the list of Contacts.// w w w.j a v a 2 s.c om * * @param images the {@link Images} used in the Contacts * @return the list of contacts */ @ShowcaseSource private Widget 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.cwStackLayoutPanelContacts(); String[] contactEmails = constants.cwStackLayoutPanelContactsEmails(); 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 SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendEscaped(contactName); sb.appendHtmlConstant("<br><i>"); sb.appendEscaped(contactEmail); sb.appendHtmlConstant("</i>"); contactInfo.setHTML(sb.toSafeHtml()); // Show the popup of contact info int left = contactLink.getAbsoluteLeft() + 14; int top = contactLink.getAbsoluteTop() + 14; contactPopup.setPopupPosition(left, top); contactPopup.show(); } }); } return new SimplePanel(contactsPanel); }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java
License:Apache License
/** * Create a widget to display in the header that includes an image and some * text./* w ww. j av a2 s .c o m*/ * * @param text the header text * @param image the {@link ImageResource} to add next to the header * @return the header widget */ @ShowcaseSource private Widget createHeaderWidget(String text, ImageResource image) { // Add the image and text to a horizontal panel HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setHeight("100%"); 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 new SimplePanel(hPanel); }
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 a2 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.//www. ja v a 2 s . c om * * @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.//from w w w .ja v a 2 s . c om */ @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./* w w w.j a va 2 s .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 ww w. j a v a 2 s . 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.CwDisclosurePanel.java
License:Apache License
/** * Create a form that contains undisclosed advanced options. *///from w w w . j a v a 2 s. c om @ShowcaseSource private Widget createAdvancedForm() { // Create a table to layout the form options FlexTable layout = new FlexTable(); layout.setCellSpacing(6); layout.setWidth("300px"); FlexCellFormatter cellFormatter = layout.getFlexCellFormatter(); // Add a title to the form layout.setHTML(0, 0, constants.cwDisclosurePanelFormTitle()); cellFormatter.setColSpan(0, 0, 2); cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); // Add some standard form options layout.setHTML(1, 0, constants.cwDisclosurePanelFormName()); layout.setWidget(1, 1, new TextBox()); layout.setHTML(2, 0, constants.cwDisclosurePanelFormDescription()); layout.setWidget(2, 1, new TextBox()); // Create some advanced options HorizontalPanel genderPanel = new HorizontalPanel(); String[] genderOptions = constants.cwDisclosurePanelFormGenderOptions(); for (int i = 0; i < genderOptions.length; i++) { genderPanel.add(new RadioButton("gender", genderOptions[i])); } Grid advancedOptions = new Grid(2, 2); advancedOptions.setCellSpacing(6); advancedOptions.setHTML(0, 0, constants.cwDisclosurePanelFormLocation()); advancedOptions.setWidget(0, 1, new TextBox()); advancedOptions.setHTML(1, 0, constants.cwDisclosurePanelFormGender()); advancedOptions.setWidget(1, 1, genderPanel); // Add advanced options to form in a disclosure panel DisclosurePanel advancedDisclosure = new DisclosurePanel(constants.cwDisclosurePanelFormAdvancedCriteria()); advancedDisclosure.setAnimationEnabled(true); advancedDisclosure.ensureDebugId("cwDisclosurePanel"); advancedDisclosure.setContent(advancedOptions); layout.setWidget(3, 0, advancedDisclosure); cellFormatter.setColSpan(3, 0, 2); // Wrap the contents in a DecoratorPanel DecoratorPanel decPanel = new DecoratorPanel(); decPanel.setWidget(layout); return decPanel; }