use of com.github.bordertech.wcomponents.layout.FlowLayout in project wcomponents by BorderTech.
the class FlowLayoutExample method addBoxesWithDiffContent.
/**
* Adds a set of boxes to the given panel.
*
* @param panel the panel to add the boxes to.
* @param amount the number of boxes to add.
*/
private static void addBoxesWithDiffContent(final WPanel panel, final int amount) {
for (int i = 1; i <= amount; i++) {
WPanel content = new WPanel(WPanel.Type.BOX);
content.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.SMALL));
for (int j = 1; j <= i; j++) {
content.add(new WText(Integer.toString(i)));
}
panel.add(content);
}
}
use of com.github.bordertech.wcomponents.layout.FlowLayout in project wcomponents by BorderTech.
the class WButtonExample method addDisabledExamples.
/**
* Examples of disabled buttons in various guises.
*/
private void addDisabledExamples() {
add(new WHeading(HeadingLevel.H2, "Examples of disabled buttons"));
WPanel disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, Size.MEDIUM, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
WButton button = new WButton("Disabled button");
button.setDisabled(true);
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
disabledButtonLayoutPanel.add(button);
add(new WHeading(HeadingLevel.H3, "Examples of disabled buttons displaying only an image"));
disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, Size.MEDIUM, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
button = new WButton("Disabled button");
button.setDisabled(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
disabledButtonLayoutPanel.add(button);
add(new WHeading(HeadingLevel.H3, "Examples of disabled buttons displaying an image with imagePosition EAST"));
disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, Size.MEDIUM, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
button = new WButton("Disabled button");
button.setDisabled(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
button.setImagePosition(ImagePosition.EAST);
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
button.setImagePosition(ImagePosition.EAST);
disabledButtonLayoutPanel.add(button);
}
use of com.github.bordertech.wcomponents.layout.FlowLayout in project wcomponents by BorderTech.
the class WLabelExample method addAntiPatternExamples.
/**
* Add examples you should never follow. DO NOT use the following as examples of what to do: these are examples of what NOT to do.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WLabel anti-patterns"));
add(new ExplanatoryText("These are here for testing purposes and must not be used as examples to follow.\n" + "Turn on debugging (bordertech.wcomponents.debug.enabled=true) to get much more information."));
add(new WHeading(HeadingLevel.H3, "Poor but not erroneous uses of WLabel"));
WPanel errorLayoutPanel = new WPanel();
errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
add(errorLayoutPanel);
// label not for anything should not be a WLabel
errorLayoutPanel.add(new WLabel("I am not 'for' anything"));
// WLabel for something which is not labellable
errorLayoutPanel.add(new WLabel("I am for a component which should not be labelled", errorLayoutPanel));
// If the WLabel is 'for' something that is not in the tree it becomes 'for' the WApplication. This is not necessarily a good thing!!!
WCheckBox notHere = new WCheckBox();
errorLayoutPanel.add(new WLabel("My component wasn't added", notHere));
/*
* The examples which follow MUST NEVER BE USED! They cause ERRORS.
* They are here purely for framework testing.
*/
add(new WHeading(HeadingLevel.H3, "Very bad uses of WLabel"));
errorLayoutPanel = new WPanel();
errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
add(errorLayoutPanel);
/*
* Nested WLabels: very bad
*/
errorLayoutPanel.add(new ExplanatoryText("This example shows nested WLabels. This is a contravention of the HTML specification."));
WPanel nestingErrorPanel = new WPanel();
nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
errorLayoutPanel.add(nestingErrorPanel);
WTextField outerField = new WTextField();
WLabel outerLabel = new WLabel("I am an outer label", outerField);
nestingErrorPanel.add(outerLabel);
WTextField innerField = new WTextField();
WLabel innerLabel = new WLabel("Inner label", innerField);
// add the inner label to the outer label: this is the ERROR
outerLabel.add(innerLabel);
nestingErrorPanel.add(innerField);
nestingErrorPanel.add(outerField);
/*
* It is permissible to place certain simple form control components into
* a WLabel under the following conditions:
* there must be no more than one such component in the WLabel;
* the component MUST be one which outputs a simple HTML form control
* (and I am not going to tell you which they are);
* The WLabel must be 'for' the nested component or not 'for' anything.
*/
errorLayoutPanel.add(new ExplanatoryText("This example shows a WLabel with a nested simple form control WTextField but the WLabel is not " + "'for' the WTextField. This is a contravention of the HTML specification."));
WTextField notMyField = new WTextField();
notMyField.setToolTip("This field should not be in the label it is in");
WTextField myField = new WTextField();
WLabel myFieldLabel = new WLabel("I am not the label for my nested text field", myField);
nestingErrorPanel = new WPanel();
nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
errorLayoutPanel.add(nestingErrorPanel);
nestingErrorPanel.add(myFieldLabel);
nestingErrorPanel.add(myField);
// adding the 'wrong' WTextField to a WLabel is what causes this error
myFieldLabel.add(notMyField);
add(new ExplanatoryText("The next field has a label explicitly set to only white space."));
WTextField emptyLabelTextField = new WTextField();
WLabel emptyLabel = new WLabel(" ", emptyLabelTextField);
add(emptyLabel);
add(emptyLabelTextField);
add(new WHeading(HeadingLevel.H2, "Unlabelled controls"));
add(new ExplanatoryText("These controls must be labelled but are not."));
WFieldLayout fieldsFlat = new WFieldLayout();
add(fieldsFlat);
fieldsFlat.addField((WLabel) null, new WTextField());
fieldsFlat.addField((WLabel) null, new WTextArea());
fieldsFlat.addField((WLabel) null, new WDateField());
fieldsFlat.addField((WLabel) null, new WCheckBox());
fieldsFlat.addField((WLabel) null, new WCheckBoxSelect(new String[] { "Apple", "Cherry", "Orange", "Pineapple" }));
}
use of com.github.bordertech.wcomponents.layout.FlowLayout in project wcomponents by BorderTech.
the class FlowLayoutRenderer_Test method testDoRenderWithContent.
@Test
public void testDoRenderWithContent() throws IOException, SAXException, XpathException {
final String text1 = "FlowRenderer_Test.testPaint.text1";
final String text2 = "FlowRenderer_Test.testPaint.text2";
WPanel panel = new WPanel();
panel.setLayout(new FlowLayout());
assertSchemaMatch(panel);
panel.add(new WText(text1));
panel.add(new WText(text2));
assertSchemaMatch(panel);
assertXpathEvaluatesTo("2", "count(//ui:panel/ui:flowlayout/ui:cell)", panel);
assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[1])", panel);
assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[2])", panel);
}
use of com.github.bordertech.wcomponents.layout.FlowLayout in project wcomponents by BorderTech.
the class FlowLayoutRenderer_Test method testRenderAlignment.
@Test
public void testRenderAlignment() throws IOException, SAXException, XpathException {
WPanel panel = new WPanel();
String expected;
for (FlowLayout.Alignment a : FlowLayout.Alignment.values()) {
panel.setLayout(new FlowLayout(a));
assertSchemaMatch(panel);
assertXpathExists("//ui:panel/ui:flowlayout", panel);
expected = a.toString().toLowerCase();
assertXpathEvaluatesTo(expected, "//ui:panel/ui:flowlayout/@align", panel);
}
}
Aggregations