use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.
the class MenuBarExample method buildMenuBar.
/**
* Builds up a menu bar for inclusion in the example.
*
* @param selectedMenuText the WText to display the selected menu item.
* @return a menu bar for the example.
*/
private WMenu buildMenuBar(final WText selectedMenuText) {
WMenu menu = new WMenu();
// The Colours menu just shows simple text
WSubMenu colourMenu = new WSubMenu("Colours");
colourMenu.setMode(WSubMenu.MenuMode.LAZY);
colourMenu.setAccessKey('C');
addMenuItem(colourMenu, "Red", selectedMenuText);
addMenuItem(colourMenu, "Green", selectedMenuText);
addMenuItem(colourMenu, "Blue", selectedMenuText);
colourMenu.addSeparator();
colourMenu.add(new WMenuItem("Disable colour menu", new ToggleDisabledAction(colourMenu)));
menu.add(colourMenu);
// The Shapes menu shows grouping of items
WSubMenu shapeMenu = new WSubMenu("Shapes");
shapeMenu.setAccessKey('S');
addMenuItem(shapeMenu, "Circle", selectedMenuText);
WMenuItemGroup triangleGroup = new WMenuItemGroup("Triangles");
shapeMenu.add(triangleGroup);
shapeMenu.setMode(WSubMenu.MenuMode.DYNAMIC);
addMenuItem(triangleGroup, "Equilateral", selectedMenuText);
addMenuItem(triangleGroup, "Isosceles", selectedMenuText);
addMenuItem(triangleGroup, "Scalene", selectedMenuText);
addMenuItem(triangleGroup, "Right-angled", selectedMenuText);
addMenuItem(triangleGroup, "Obtuse", selectedMenuText);
WMenuItemGroup quadGroup = new WMenuItemGroup("Quadrilaterals");
shapeMenu.add(quadGroup);
addMenuItem(quadGroup, "Square", selectedMenuText);
addMenuItem(quadGroup, "Rectangle", selectedMenuText);
addMenuItem(quadGroup, "Rhombus", selectedMenuText);
addMenuItem(quadGroup, "Trapezoid", selectedMenuText);
addMenuItem(quadGroup, "Parallelogram", selectedMenuText);
shapeMenu.addSeparator();
shapeMenu.add(new WMenuItem("Disable shape menu", new ToggleDisabledAction(shapeMenu)));
menu.add(shapeMenu);
// The Image menu shows use of decorated labels and images
WDecoratedLabel imageLabel = new WDecoratedLabel(new WImage("/image/wrench.png", "spanner"), new WText("Images"), null);
WSubMenu imageMenu = new WSubMenu(imageLabel);
imageMenu.add(createImageMenuItem("/image/flag.png", "Flag", "eg-menu-image-1", selectedMenuText));
imageMenu.add(createImageMenuItem("/image/attachment.png", "Attachment", "eg-menu-image-2", selectedMenuText));
imageMenu.add(createImageMenuItem("/image/settings.png", "Settings", "eg-menu-image-3", selectedMenuText));
imageMenu.addSeparator();
imageMenu.add(new WMenuItem("Disable image menu", new ToggleDisabledAction(imageMenu)));
menu.add(imageMenu);
WSubMenu sitesMenu = new WSubMenu("External apps");
sitesMenu.add(new WMenuItem("External website", "http://www.example.com/"));
WMenuItem google = new WMenuItem("Example (new window)", "http://www.example.com/");
google.setTargetWindow("exampleWindow");
sitesMenu.add(google);
menu.add(sitesMenu);
// Add an item to toggle the states of all the menus
menu.add(new WMenuItem("Toggle top-level menus", new ToggleDisabledAction(colourMenu, shapeMenu, imageMenu, sitesMenu)));
menu.add(new WMenuItem("Link", "http://www.example.com"));
menu.add(new WMenuItem("No Action"));
WMenuItem itemWithIcon = new WMenuItem("Help");
itemWithIcon.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
// do something
}
});
itemWithIcon.setHtmlClass(HtmlClassProperties.ICON_HELP_BEFORE);
menu.add(itemWithIcon);
WMenuItem itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/home.png", "home"), new WText("Home"), null));
menu.add(itemWithImage);
menu.add(new WMenuItem(new WDecoratedLabel(new WImage("/image/settings.png", "settings"), new WText("Settings Menu"), null)));
itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/flag.png", "flag")));
itemWithImage.setAccessibleText("flag this view");
menu.add(itemWithImage);
return menu;
}
use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.
the class WLabelExample method addNullLabelExample.
/**
* Example of when and how to use a null WLabel.
*/
private void addNullLabelExample() {
add(new WHeading(HeadingLevel.H2, "How to use accessible null WLabels"));
add(new ExplanatoryText("These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"."));
// We want to add a WFieldSet to a WFieldLayout but without an extra label.
WFieldLayout fieldsFlat = new WFieldLayout();
fieldsFlat.setMargin(new Margin(null, null, Size.XL, null));
add(fieldsFlat);
WFieldSet fs = new WFieldSet("Do you like Bananas?");
fieldsFlat.addField((WLabel) null, fs);
// now add the WRadioButtons to the WFieldSet using an inner WFieldLayout
WFieldLayout innerLayout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
// The content will be a group of WRadioButtons
RadioButtonGroup group1 = new RadioButtonGroup();
WRadioButton rb1 = group1.addRadioButton(1);
WRadioButton rb2 = group1.addRadioButton(2);
// make the labels for the radio buttons
WLabel rb1Label = new WLabel("", rb1);
WImage labelImage = new WImage("/image/success.png", "I still like bananas");
labelImage.setHtmlClass("wc-valign-bottom");
rb1Label.add(labelImage);
WLabel rb2Label = new WLabel("", rb2);
labelImage = new WImage("/image/error.png", "I still dislike bananas");
labelImage.setHtmlClass("wc-valign-bottom");
rb2Label.add(labelImage);
innerLayout.addField(rb1Label, rb1);
innerLayout.addField(rb2Label, rb2);
// add the content to the WFieldLayout - the order really doesn't matter.
fs.add(group1);
fs.add(innerLayout);
}
use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.
the class WImageRenderer method doRender.
/**
* Paints the given {@link WImage}.
*
* @param component the WImage to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WImage imageComponent = (WImage) component;
XmlStringBuilder xml = renderContext.getWriter();
// No image set
if (imageComponent.getImage() == null && imageComponent.getImageUrl() == null) {
return;
}
renderTagOpen(imageComponent, xml);
xml.appendEnd();
}
use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.
the class WLinkRenderer method doRender.
/**
* Paints the given {@link WLink}.
*
* @param component the WLink to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WLink link = (WLink) component;
XmlStringBuilder xml = renderContext.getWriter();
String text = link.getText();
String targetWindowName = link.getOpenNewWindow() ? link.getTargetWindowName() : null;
String imageUrl = link.getImageUrl();
xml.appendTagOpen("ui:link");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("disabled", link.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
xml.appendOptionalAttribute("toolTip", link.getToolTip());
xml.appendOptionalAttribute("accessibleText", link.getAccessibleText());
xml.appendUrlAttribute("url", link.getUrl());
xml.appendOptionalAttribute("rel", link.getRel());
xml.appendOptionalAttribute("accessKey", Util.upperCase(link.getAccessKeyAsString()));
if (imageUrl != null) {
xml.appendUrlAttribute("imageUrl", imageUrl);
ImagePosition imagePosition = link.getImagePosition();
if (imagePosition != null) {
switch(imagePosition) {
case NORTH:
xml.appendAttribute("imagePosition", "n");
break;
case EAST:
xml.appendAttribute("imagePosition", "e");
break;
case SOUTH:
xml.appendAttribute("imagePosition", "s");
break;
case WEST:
xml.appendAttribute("imagePosition", "w");
break;
default:
throw new SystemException("Unknown image position: " + imagePosition);
}
}
// we have an image. We must have a text equivalent
if (Util.empty(text) && Util.empty(link.getToolTip()) && Util.empty(link.getAccessibleText())) {
// If the link has an umageUrl but no text equivalent get the text equivalent off of the image
WImage linkImage = link.getImageHolder();
if (null != linkImage) {
xml.appendOptionalAttribute("toolTip", linkImage.getAlternativeText());
}
}
}
if (link.isRenderAsButton()) {
xml.appendAttribute("type", "button");
}
xml.appendClose();
if (targetWindowName != null) {
xml.appendTagOpen("ui:windowAttributes");
xml.appendAttribute("name", targetWindowName);
WLink.WindowAttributes attributes = link.getWindowAttrs();
if (attributes != null) {
xml.appendOptionalAttribute("top", attributes.getTop() >= 0, attributes.getTop());
xml.appendOptionalAttribute("left", attributes.getLeft() >= 0, attributes.getLeft());
xml.appendOptionalAttribute("width", attributes.getWidth() > 0, attributes.getWidth());
xml.appendOptionalAttribute("height", attributes.getHeight() > 0, attributes.getHeight());
xml.appendOptionalAttribute("resizable", attributes.isResizable(), "true");
xml.appendOptionalAttribute("showMenubar", attributes.isMenubar(), "true");
xml.appendOptionalAttribute("showToolbar", attributes.isToolbars(), "true");
xml.appendOptionalAttribute("showLocation", attributes.isLocation(), "true");
xml.appendOptionalAttribute("showStatus", attributes.isStatus(), "true");
xml.appendOptionalAttribute("showScrollbars", attributes.isScrollbars(), "true");
xml.appendOptionalAttribute("showDirectories", attributes.isDirectories(), "true");
}
xml.appendEnd();
}
if (text != null) {
xml.appendEscaped(text);
}
xml.appendEndTag("ui:link");
// Paint the AJAX trigger if the link has an action
if (link.getAction() != null) {
paintAjaxTrigger(link, xml);
}
}
use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.
the class WLinkRenderer_Test method testButtonImageToolTipRender.
@Test
public void testButtonImageToolTipRender() throws IOException, SAXException, XpathException {
WLink link = new WLink();
String expected = "alt text";
WImage buttonImage = new WImage("http://localhost/image.png", expected);
link.setImage(buttonImage.getImage());
assertXpathEvaluatesTo(expected, "//ui:link/@toolTip", link);
}
Aggregations