Search in sources :

Example 1 with BorderLayout

use of com.github.bordertech.wcomponents.layout.BorderLayout in project wcomponents by BorderTech.

the class ObjectGraphDump_Test method testDump.

@Test
public void testDump() {
    WPanel component = new WPanel();
    component.setLayout(new BorderLayout());
    component.add(new WLabel(TEST_LABEL), BorderLayout.NORTH);
    ObjectGraphNode graphNode = ObjectGraphDump.dump(component);
    String result = graphNode.toXml();
    // ObjectGraphNode tested independently
    // for the input 'component' above - the dump result must at least contain the following
    // and have run without exceptions
    Assert.assertTrue("", result.indexOf("type=\"com.github.bordertech.wcomponents.WPanel\"") != -1);
    Assert.assertTrue("", result.indexOf("field=\"label\" type=\"com.github.bordertech.wcomponents.WLabel\"") != -1);
    Assert.assertTrue("", result.indexOf("field=\"text\" value=\""" + TEST_LABEL + ""\" type=\"java.io.Serializable\"") != -1);
    Assert.assertTrue("", result.indexOf("field=\"value\" type=\"com.github.bordertech.wcomponents.layout.BorderLayout$BorderLayoutConstraint\"") != -1);
}
Also used : BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) WPanel(com.github.bordertech.wcomponents.WPanel) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 2 with BorderLayout

use of com.github.bordertech.wcomponents.layout.BorderLayout in project wcomponents by BorderTech.

the class RepeaterExampleWithStaticIDs method createButtonBar.

/**
 * Create the UI artefacts for the update and reset buttons.
 */
private void createButtonBar() {
    // Update and reset controls for the repeater.
    WPanel buttonPanel = new WPanel(WPanel.Type.FEATURE);
    buttonPanel.setMargin(new Margin(Size.MEDIUM, null, Size.LARGE, null));
    buttonPanel.setLayout(new BorderLayout());
    WButton updateButton = new WButton("Update");
    updateButton.setImage("/image/document-save-5.png");
    updateButton.setImagePosition(WButton.ImagePosition.EAST);
    buttonPanel.add(updateButton, BorderLayout.EAST);
    WButton resetButton = new WButton("Reset");
    resetButton.setImage("/image/edit-undo-8.png");
    resetButton.setImagePosition(WButton.ImagePosition.WEST);
    resetButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            repeater.setData(fetchDataList());
        }
    });
    buttonPanel.add(resetButton, BorderLayout.WEST);
    add(buttonPanel);
    add(new WAjaxControl(updateButton, repeater));
    add(new WAjaxControl(resetButton, repeater));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) Margin(com.github.bordertech.wcomponents.Margin)

Example 3 with BorderLayout

use of com.github.bordertech.wcomponents.layout.BorderLayout in project wcomponents by BorderTech.

the class BorderLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    BorderLayout layout = (BorderLayout) panel.getLayout();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    xml.appendTagOpen("ui:borderlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Fetch the children and their constraints.
    final int childCount = panel.getChildCount();
    List<Duplet<WComponent, BorderLayoutConstraint>> children = new ArrayList<>(childCount);
    for (int i = 0; i < childCount; i++) {
        WComponent child = panel.getChildAt(i);
        children.add(new Duplet<>(child, getConstraints(panel, child)));
    }
    // Now paint them
    paintChildrenWithConstraint(children, renderContext, BorderLayout.NORTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.EAST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.SOUTH);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.WEST);
    paintChildrenWithConstraint(children, renderContext, BorderLayout.CENTER);
    xml.appendEndTag("ui:borderlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Duplet(com.github.bordertech.wcomponents.util.Duplet) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Example 4 with BorderLayout

use of com.github.bordertech.wcomponents.layout.BorderLayout in project wcomponents by BorderTech.

the class BorderLayoutRenderer_Test method testDoRenderWhenEmpty.

@Test
public void testDoRenderWhenEmpty() throws IOException, SAXException, XpathException {
    WPanel container = new WPanel();
    container.setLayout(new BorderLayout());
    assertSchemaMatch(container);
    assertXpathExists("//ui:panel/ui:borderlayout", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/@hgap", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/@vgap", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:north", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:south", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:east", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:west", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:center", container);
}
Also used : BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 5 with BorderLayout

use of com.github.bordertech.wcomponents.layout.BorderLayout in project wcomponents by BorderTech.

the class BorderLayoutRenderer_Test method testDoRender.

@Test
public void testDoRender() throws IOException, SAXException, XpathException {
    final String northText = "BorderRenderer_Test.testPaint.northText";
    final String westText = "BorderRenderer_Test.testPaint.westText";
    final String southText = "BorderRenderer_Test.testPaint.southText";
    final String eastText = "BorderRenderer_Test.testPaint.eastText";
    final String centerText = "BorderRenderer_Test.testPaint.centerText";
    WPanel container = new WPanel();
    container.setLayout(new BorderLayout(GAP, BIG_GAP));
    assertSchemaMatch(container);
    assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:borderlayout/@hgap", container);
    assertXpathEvaluatesTo(BIG_GAP.toString(), "//ui:panel/ui:borderlayout/@vgap", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:north", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:south", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:east", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:west", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:center", container);
    container.add(new WText(northText), BorderLayout.NORTH);
    container.add(new WText(westText), BorderLayout.WEST);
    assertXpathEvaluatesTo(northText, "normalize-space(//ui:panel/ui:borderlayout/ui:north)", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:south", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:east", container);
    assertXpathEvaluatesTo(westText, "normalize-space(//ui:panel/ui:borderlayout/ui:west)", container);
    assertXpathNotExists("//ui:panel/ui:borderlayout/ui:center", container);
    container.add(new WText(southText), BorderLayout.SOUTH);
    container.add(new WText(eastText), BorderLayout.EAST);
    container.add(new WText(centerText));
    assertXpathEvaluatesTo(northText, "normalize-space(//ui:panel/ui:borderlayout/ui:north)", container);
    assertXpathEvaluatesTo(westText, "normalize-space(//ui:panel/ui:borderlayout/ui:west)", container);
    assertXpathEvaluatesTo(southText, "normalize-space(//ui:panel/ui:borderlayout/ui:south)", container);
    assertXpathEvaluatesTo(eastText, "normalize-space(//ui:panel/ui:borderlayout/ui:east)", container);
    assertXpathEvaluatesTo(centerText, "normalize-space(//ui:panel/ui:borderlayout/ui:center)", container);
}
Also used : BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Aggregations

WPanel (com.github.bordertech.wcomponents.WPanel)5 BorderLayout (com.github.bordertech.wcomponents.layout.BorderLayout)5 Test (org.junit.Test)3 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 Margin (com.github.bordertech.wcomponents.Margin)1 Size (com.github.bordertech.wcomponents.Size)1 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WText (com.github.bordertech.wcomponents.WText)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 BorderLayoutConstraint (com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)1 Duplet (com.github.bordertech.wcomponents.util.Duplet)1 ArrayList (java.util.ArrayList)1