Search in sources :

Example 6 with WImage

use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.

the class LinkOptionsExample method applySettings.

/**
 * this is were the majority of the work is done for building the link. Note that it is in a container that is
 * reset, effectively creating a new link. this is only done to enable to dynamically change the link to a button
 * and back.
 */
private void applySettings() {
    linkContainer.reset();
    WLink exampleLink = new WLink();
    exampleLink.setText(tfLinkLabel.getText());
    final String url = tfUrlField.getValue();
    if ("".equals(url) || !isValidUrl(url)) {
        tfUrlField.setText(URL);
        exampleLink.setUrl(URL);
    } else {
        exampleLink.setUrl(url);
    }
    exampleLink.setRenderAsButton(cbRenderAsButton.isSelected());
    exampleLink.setText(tfLinkLabel.getText());
    if (cbSetImage.isSelected()) {
        WImage linkImage = new WImage("/image/attachment.png", "Add attachment");
        exampleLink.setImage(linkImage.getImage());
        exampleLink.setImagePosition((ImagePosition) ddImagePosition.getSelected());
    }
    exampleLink.setDisabled(cbDisabled.isSelected());
    if (tfAccesskey.getText() != null && tfAccesskey.getText().length() > 0) {
        exampleLink.setAccessKey(tfAccesskey.getText().toCharArray()[0]);
    }
    if (cbOpenNew.isSelected()) {
        exampleLink.setOpenNewWindow(true);
        exampleLink.setTargetWindowName("_blank");
    } else {
        exampleLink.setOpenNewWindow(false);
    }
    linkContainer.add(exampleLink);
}
Also used : WImage(com.github.bordertech.wcomponents.WImage) WLink(com.github.bordertech.wcomponents.WLink)

Example 7 with WImage

use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.

the class WButtonExample method addImageExamples.

/**
 * An example to cover the gamut of image buttons both with and without visible text and with both renderAsLink and
 * render as button.
 */
private void addImageExamples() {
    // Button rendered with an image only
    add(new WHeading(HeadingLevel.H2, "Image buttons"));
    add(new ExplanatoryText("This example shows how to use an image inside a WButton."));
    add(new WHeading(HeadingLevel.H3, "Just an image"));
    add(new ExplanatoryText("This example shows how to use an image as the only content of a WButton. " + "The button must still have text content to adequately explain the button's purpose."));
    add(new WHeading(HeadingLevel.H4, "Image in a button"));
    add(makeImageButton("Save", false));
    add(new WHeading(HeadingLevel.H4, "Image button without button style"));
    add(new ExplanatoryText("This example shows how to use an image as the only content of a WButton when styled to be without its button appearance. " + "If you are creating a button containing only an image you should be careful as it may not be obvious to the application user that the 'image' is actually a 'button'." + "The button must still have text content to adequately explain the button's purpose."));
    add(makeImageButton("Save", true));
    add(new ExplanatoryText("Button using a WImage description as the text equivalent."));
    WButton button = new WButton();
    WImage buttonImage = new WImage("/image/tick.png", "Mark as OK");
    button.setImage(buttonImage.getImage());
    add(button);
    add(new WHeading(HeadingLevel.H3, "Image and text"));
    add(new ExplanatoryText("This example shows how to use an image and text as the content of a button."));
    add(new WHeading(HeadingLevel.H4, "Rendered as a button"));
    WPanel buttonLayoutPanel = new WPanel(WPanel.Type.BOX);
    buttonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0, FlowLayout.ContentAlignment.BOTTOM));
    add(buttonLayoutPanel);
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the North", ImagePosition.NORTH));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the East", ImagePosition.EAST));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the South", ImagePosition.SOUTH));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the West", ImagePosition.WEST));
    add(new WHeading(HeadingLevel.H4, "Rendered as a link"));
    add(new ExplanatoryText("This example shows how to use an image and text as the content of a button without the button styling."));
    buttonLayoutPanel = new WPanel(WPanel.Type.BOX);
    buttonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0, FlowLayout.ContentAlignment.BOTTOM));
    add(buttonLayoutPanel);
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the North", ImagePosition.NORTH, true));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the East", ImagePosition.EAST, true));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the South", ImagePosition.SOUTH, true));
    buttonLayoutPanel.add(makeImageButtonWithPosition("Image on the West", ImagePosition.WEST, true));
    add(new WHeading(HeadingLevel.H4, "Using theme icons"));
    add(new ExplanatoryText("These examples show ways to add an icon to a button using 'HtmlClassUtil'."));
    // \u200b is a zero-width space.
    WButton iconButton = new WButton("\u200b");
    iconButton.setToolTip("Edit");
    iconButton.setHtmlClass(HtmlClassProperties.ICON_EDIT);
    add(iconButton);
    iconButton = new WButton("Save");
    iconButton.setHtmlClass(HtmlClassProperties.ICON_SAVE_BEFORE);
    add(iconButton);
    iconButton = new WButton("Search");
    iconButton.setHtmlClass(HtmlClassProperties.ICON_SEARCH_AFTER);
    add(iconButton);
    add(new ExplanatoryText("These examples show ways to add a Font-Awesome icon to a button using 'setHtmlClass'."));
    // \u200b is a zero-width space.
    iconButton = new WButton("\u200b");
    iconButton.setToolTip("Open Menu");
    iconButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-bars"));
    add(iconButton);
    iconButton = new WButton("With text content");
    iconButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-hand-o-left", HtmlIconUtil.IconPosition.BEFORE));
    add(iconButton);
    iconButton = new WButton("Right icon with text content");
    iconButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-hand-o-right", HtmlIconUtil.IconPosition.AFTER));
    add(iconButton);
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) WImage(com.github.bordertech.wcomponents.WImage) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 8 with WImage

use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.

the class MenuBarExample method createImageMenuItem.

/**
 * Creates an example menu item using an image.
 *
 * @param resource the name of the image resource
 * @param desc the description for the image
 * @param cacheKey the cache key for this image
 * @param selectedMenuText the WText to display the selected menu item.
 * @return a menu item using an image
 */
private WMenuItem createImageMenuItem(final String resource, final String desc, final String cacheKey, final WText selectedMenuText) {
    WImage image = new WImage(resource, desc);
    image.setCacheKey(cacheKey);
    WDecoratedLabel label = new WDecoratedLabel(image, new WText(desc), null);
    WMenuItem menuItem = new WMenuItem(label, new ExampleMenuAction(selectedMenuText));
    menuItem.setActionObject(desc);
    return menuItem;
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 9 with WImage

use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.

the class MenuFlyoutExample method createImageMenuItem.

/**
 * Creates an example menu item using an image.
 *
 * @param resource the name of the image resource
 * @param desc the description for the image
 * @param cacheKey the cache key for this image
 * @param selectedMenuText the WText to display the selected menu item.
 * @return a menu item using an image
 */
private WMenuItem createImageMenuItem(final String resource, final String desc, final String cacheKey, final WText selectedMenuText) {
    WImage image = new WImage(resource, desc);
    image.setCacheKey(cacheKey);
    WDecoratedLabel label = new WDecoratedLabel(image, new WText(desc), null);
    WMenuItem menuItem = new WMenuItem(label, new ExampleMenuAction(selectedMenuText));
    menuItem.setActionObject(desc);
    return menuItem;
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 10 with WImage

use of com.github.bordertech.wcomponents.WImage in project wcomponents by BorderTech.

the class TreeMenuExample method buildTreeMenuWithDecoratedLabel.

/**
 * Tree menu containing image in the items. This example demonstrates creating {@link WSubMenu} and
 * {@link WMenuItem} components with {@link WDecoratedLabel}.
 *
 * @return menu with a decorated label
 */
private WMenu buildTreeMenuWithDecoratedLabel() {
    WMenu menu = new WMenu(WMenu.MenuType.TREE);
    WDecoratedLabel dLabel = new WDecoratedLabel(null, new WText("Settings Menu"), new WImage("/image/settings.png", "settings"));
    WSubMenu settings = new WSubMenu(dLabel);
    settings.setMode(WSubMenu.MenuMode.LAZY);
    settings.setAccessKey('S');
    menu.add(settings);
    settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Account Settings"), new WImage("/image/user-properties.png", "user properties"))));
    settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Personal Details"), new WImage("/image/user.png", "user"))));
    WSubMenu addressSub = new WSubMenu(new WDecoratedLabel(null, new WText("Address Details"), new WImage("/image/address-book-open.png", "address book")));
    addressSub.setMode(WSubMenu.MenuMode.LAZY);
    settings.add(addressSub);
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Home Address"), new WImage("/image/home.png", "home"))));
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Work Address"), new WImage("/image/wrench.png", "work"))));
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Postal Address"), new WImage("/image/mail-post.png", "postal"))));
    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);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Aggregations

WImage (com.github.bordertech.wcomponents.WImage)18 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)6 WText (com.github.bordertech.wcomponents.WText)6 Test (org.junit.Test)5 WButton (com.github.bordertech.wcomponents.WButton)4 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)4 Action (com.github.bordertech.wcomponents.Action)3 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)3 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLink (com.github.bordertech.wcomponents.WLink)3 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)3 MockImage (com.github.bordertech.wcomponents.MockImage)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)2 WMenu (com.github.bordertech.wcomponents.WMenu)2 WPanel (com.github.bordertech.wcomponents.WPanel)2 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)2 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2