Search in sources :

Example 11 with WImage

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

the class ExampleSection method buildUI.

/**
 * Add the controls to the section in the right order.
 */
private void buildUI() {
    add(messages);
    add(tabset);
    // add(new AccessibilityWarningContainer());
    container.add(new WText("Select an example from the menu"));
    // Set a static ID on container and it becomes a de-facto naming context.
    container.setIdName("eg");
    tabset.addTab(container, "(no selection)", WTabSet.TAB_MODE_CLIENT);
    WImage srcImage = new WImage(new ImageResource("/image/text-x-source.png", "View Source"));
    srcImage.setCacheKey("srcTabImage");
    tabset.addTab(source, new WDecoratedLabel(srcImage), WTabSet.TAB_MODE_LAZY).setToolTip("View Source");
    // The refresh current view button.
    WButton refreshButton = new WButton("\u200b");
    refreshButton.setToolTip("Refresh");
    refreshButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-refresh"));
    // refreshButton.setImage("/image/refresh-w.png");
    refreshButton.setRenderAsLink(true);
    refreshButton.setAction(new ValidatingAction(messages.getValidationErrors(), refreshButton) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do Nothing
        }
    });
    // The reset example button.
    final WButton resetButton = new WButton("\u200b");
    resetButton.setToolTip("Reset");
    resetButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-times-circle"));
    // resetButton.setImage("/image/cancel-w.png");
    resetButton.setRenderAsLink(true);
    resetButton.setAction(new ValidatingAction(messages.getValidationErrors(), resetButton) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            resetExample();
        }
    });
    addToTail(refreshButton);
    addToTail(new WText("\u2002"));
    addToTail(resetButton);
}
Also used : ImageResource(com.github.bordertech.wcomponents.ImageResource) WText(com.github.bordertech.wcomponents.WText) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WImage(com.github.bordertech.wcomponents.WImage) WButton(com.github.bordertech.wcomponents.WButton) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 12 with WImage

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

the class WTabSetExample method constructExample.

/**
 * Helper to do the work of the constructor since we do not really want to call over-rideable methods in a
 * constructor.
 */
private void constructExample() {
    add(new WHeading(HeadingLevel.H2, "Examples showing TabSet Type property."));
    add(new WHeading(HeadingLevel.H3, "Tabs at the top"));
    WTabSet tabset0 = new SampleWTabset();
    add(tabset0);
    add(new WHeading(HeadingLevel.H3, "Tabs at the top with explicit TYPE"));
    /* Explicitly setting TYPE_TOP is superfluous */
    WTabSet tabset1 = new SampleWTabset(WTabSet.TYPE_TOP);
    add(tabset1);
    add(new WHeading(HeadingLevel.H3, "Tabs on the LEFT"));
    WTabSet tabset1a = new SampleWTabset(WTabSet.TYPE_LEFT);
    add(tabset1a);
    add(new WHeading(HeadingLevel.H3, "Tabs on the RIGHT"));
    WTabSet tabset1b = new SampleWTabset(WTabSet.TYPE_RIGHT);
    add(tabset1b);
    add(new WHeading(HeadingLevel.H3, "ACCORDION tabs"));
    WTabSet tabset1c = new SampleWTabset(TabSetType.ACCORDION);
    add(tabset1c);
    add(new WHorizontalRule());
    /* Content height */
    add(new WHeading(HeadingLevel.H2, "Examples showing content height property."));
    add(new WHeading(HeadingLevel.H3, "Tall content."));
    WTabSet htabset1 = new SampleWTabset();
    htabset1.setContentHeight(TALL_CONTENT);
    add(htabset1);
    WTabSet htabset1a = new SampleWTabset(WTabSet.TYPE_LEFT);
    htabset1a.setContentHeight(TALL_CONTENT);
    add(htabset1a);
    WTabSet htabset1b = new SampleWTabset(WTabSet.TYPE_RIGHT);
    htabset1b.setContentHeight(TALL_CONTENT);
    add(htabset1b);
    WTabSet htabset1c = new SampleWTabset(TabSetType.ACCORDION);
    htabset1c.setContentHeight(TALL_CONTENT);
    add(htabset1c);
    add(new WHeading(HeadingLevel.H3, "Short content."));
    WTabSet htabset1d = new SampleWTabset();
    htabset1d.setContentHeight(SHORT_CONTENT);
    add(htabset1d);
    WTabSet htabset1e = new SampleWTabset(WTabSet.TYPE_LEFT);
    htabset1e.setContentHeight(SHORT_CONTENT);
    add(htabset1e);
    WTabSet htabset1f = new SampleWTabset(WTabSet.TYPE_RIGHT);
    htabset1f.setContentHeight(SHORT_CONTENT);
    add(htabset1f);
    WTabSet htabset1g = new SampleWTabset(TabSetType.ACCORDION);
    htabset1g.setContentHeight(SHORT_CONTENT);
    add(htabset1g);
    add(new WHorizontalRule());
    add(new WHeading(HeadingLevel.H2, "Examples showing disabled property."));
    /* NOTE: WTabSet does not currently implement SubordinateTarget therefore one cannot create a subordinate
		 * control to disable/enable a WTabSet.
		 */
    WTabSet disabledTabset = new SampleWTabset();
    disabledTabset.setDisabled(true);
    add(disabledTabset);
    add(new WHeading(HeadingLevel.H2, "Examples showing accordion's single property."));
    WTabSet singleOpenAccordionabset = new SampleWTabset(WTabSet.TYPE_ACCORDION);
    singleOpenAccordionabset.setSingle(true);
    add(singleOpenAccordionabset);
    add(new WHorizontalRule());
    /* NOTE: no example of the hidden property because WTabSet is not a subordinate target. This is inconsistent
		 * with the schema. */
    add(new WHeading(HeadingLevel.H2, "Setting the initially active tab"));
    add(new WHeading(HeadingLevel.H3, "Server side with tabs on the left, with second tab initially active."));
    WTabSet tabset3 = new WTabSet(WTabSet.TYPE_LEFT);
    tabset3.setContentHeight("10em");
    tabset3.addTab(new WText("Some content should go in here."), "First tab", WTabSet.TAB_MODE_SERVER, 'i');
    WPanel largeContent2 = new WPanel();
    largeContent2.setLayout(new FlowLayout(Alignment.VERTICAL));
    largeContent2.add(new WText(LONG_TEXT));
    largeContent2.add(new WText(LONG_TEXT));
    largeContent2.add(new WText(LONG_TEXT));
    tabset3.addTab(largeContent2, "Second tab which is much longer", WTabSet.TAB_MODE_SERVER, 'e');
    WImage image = new WImage("/image/success.png", "success");
    image.setCacheKey("eg-image-tab");
    WDecoratedLabel tabLabel = new WDecoratedLabel(image, new WText("Third tab"), null);
    tabset3.addTab(new WText("The tab button for this tab has an image!"), tabLabel, WTabSet.TAB_MODE_SERVER, 'h');
    // Set 2nd tab active
    tabset3.setActiveIndex(1);
    add(tabset3);
    add(new WHeading(HeadingLevel.H3, "Client side with tabs on the right and the third tab initially active."));
    WText thirdContent = new WText("Some more content should go into here.");
    WTabSet tabset4 = new WTabSet(WTabSet.TYPE_RIGHT);
    tabset4.setContentHeight("10em");
    tabset4.addTab(new WText("Some content should go into here."), "First tab", WTabSet.TAB_MODE_CLIENT);
    tabset4.addTab(new WText(LONG_TEXT), "Second tab which is longer", WTabSet.TAB_MODE_CLIENT);
    tabset4.addTab(thirdContent, "Third tab", WTabSet.TAB_MODE_CLIENT);
    // Set 3rd tab active
    tabset4.setActiveTab(thirdContent);
    add(tabset4);
    add(new WHeading(HeadingLevel.H3, "Client side with showing lots of tabs."));
    add(new ExplanatoryText("This will effectively show what happens when tabs need to wrap. You should do everything possible to avoid this situation."));
    WTabSet tabset5 = new WTabSet();
    tabset5.addTab(new WText("Tab 1."), "First tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 2."), "Second tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 3."), "Third tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 4."), "Fourth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 5."), "Fifth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 6."), "Sixth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 7."), "Seventh tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 8."), "Eighth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 9."), "Nineth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 10."), "Tenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 11."), "Eleventh tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 12."), "Twelfth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 13."), "Thirteenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 14."), "Fourteenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 15."), "Fifteenth tab", WTabSet.TAB_MODE_CLIENT);
    add(tabset5);
    add(new WHorizontalRule());
    add(new WHeading(HeadingLevel.H2, "Using WSubordinateControl"));
    WTabSet targetTabset = new SampleWTabset();
    add(targetTabset);
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    add(layout);
    final WCheckBox disabledControllerCb = new WCheckBox();
    final WCheckBox hiddenControllerCb = new WCheckBox();
    layout.addField("disable tabset", disabledControllerCb);
    layout.addField("hide tabset", hiddenControllerCb);
    // Build & add the subordinate
    SubordinateBuilder builder = new SubordinateBuilder();
    builder.condition().equals(hiddenControllerCb, String.valueOf(true));
    builder.whenTrue().hide(targetTabset);
    builder.whenFalse().show(targetTabset);
    add(builder.build());
    builder = new SubordinateBuilder();
    builder.condition().equals(disabledControllerCb, String.valueOf(true));
    builder.whenTrue().disable(targetTabset);
    builder.whenFalse().enable(targetTabset);
    add(builder.build());
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) WImage(com.github.bordertech.wcomponents.WImage) SubordinateBuilder(com.github.bordertech.wcomponents.subordinate.builder.SubordinateBuilder) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WHeading(com.github.bordertech.wcomponents.WHeading) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTabSet(com.github.bordertech.wcomponents.WTabSet) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 13 with WImage

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

the class WButtonRenderer method doRender.

/**
 * Paints the given WButton.
 *
 * @param component the WButton to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    WButton button = (WButton) component;
    String text = button.getText();
    String imageUrl = button.getImageUrl();
    String accessibleText = button.getAccessibleText();
    String toolTip = button.getToolTip();
    if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
        throw new SystemException("WButton text or imageUrl must be specified");
    }
    xml.appendTagOpen(getTagName(button));
    String buttonId = button.getId();
    ImagePosition pos = button.getImagePosition();
    if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
        // If the button has an imageUrl but no text equivalent get the text equivalent off of the image
        WImage imgHolder = button.getImageHolder();
        if (null != imgHolder) {
            toolTip = imgHolder.getAlternativeText();
        }
    }
    xml.appendAttribute("id", buttonId);
    xml.appendAttribute("name", buttonId);
    xml.appendAttribute("value", "x");
    xml.appendAttribute("type", getButtonType(button));
    xml.appendAttribute("class", geHtmlClassName(button));
    xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
    xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
    xml.appendOptionalAttribute("title", toolTip);
    xml.appendOptionalAttribute("aria-label", accessibleText);
    xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
    xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
    xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
    if (button.isCancel()) {
        xml.appendAttribute("formnovalidate", "formnovalidate");
    } else {
        Action action = button.getAction();
        if (action instanceof ValidatingAction) {
            WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
            xml.appendAttribute("data-wc-validate", validationTarget.getId());
        }
    }
    xml.appendClose();
    if (imageUrl != null) {
        xml.appendTagOpen("span");
        String imageHolderClass = "wc_nti";
        if (pos != null) {
            StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
            switch(pos) {
                case NORTH:
                    imageHolderClassBuffer.append("n");
                    break;
                case EAST:
                    imageHolderClassBuffer.append("e");
                    break;
                case SOUTH:
                    imageHolderClassBuffer.append("s");
                    break;
                case WEST:
                    imageHolderClassBuffer.append("w");
                    break;
                default:
                    throw new SystemException("Unknown image position: " + pos);
            }
            imageHolderClass = imageHolderClassBuffer.toString();
        }
        xml.appendAttribute("class", imageHolderClass);
        xml.appendClose();
        if (pos != null && text != null) {
            xml.appendTag("span");
            xml.appendEscaped(text);
            xml.appendEndTag("span");
        }
        xml.appendTagOpen("img");
        xml.appendUrlAttribute("src", imageUrl);
        String alternateText = pos == null ? text : "";
        xml.appendAttribute("alt", alternateText);
        xml.appendEnd();
        xml.appendEndTag("span");
    } else if (text != null) {
        xml.appendEscaped(text);
    }
    xml.appendEndTag(getTagName(button));
    if (button.isAjax()) {
        paintAjax(button, xml);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) SystemException(com.github.bordertech.wcomponents.util.SystemException) ImagePosition(com.github.bordertech.wcomponents.WButton.ImagePosition) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WImage(com.github.bordertech.wcomponents.WImage) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 14 with WImage

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

the class StepCountUtil method isCachedContentRequest.

/**
 * Check if the request is for cached content.
 *
 * @param request the request being processed
 * @return true if content is cached, otherwise false
 */
public static boolean isCachedContentRequest(final Request request) {
    // Get target id on request
    String targetId = request.getParameter(Environment.TARGET_ID);
    if (targetId == null) {
        return false;
    }
    // Get target
    ComponentWithContext targetWithContext = WebUtilities.getComponentById(targetId, true);
    if (targetWithContext == null) {
        return false;
    }
    // Check for caching key
    WComponent target = targetWithContext.getComponent();
    UIContextHolder.pushContext(targetWithContext.getContext());
    try {
        // TODO Look at implementing CacheableTarget interface
        String key = null;
        if (target instanceof WContent) {
            key = ((WContent) target).getCacheKey();
        } else if (target instanceof WImage) {
            key = ((WImage) target).getCacheKey();
        } else if (target instanceof WVideo) {
            key = ((WVideo) target).getCacheKey();
        } else if (target instanceof WAudio) {
            key = ((WAudio) target).getCacheKey();
        }
        return !Util.empty(key);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContent(com.github.bordertech.wcomponents.WContent) WVideo(com.github.bordertech.wcomponents.WVideo) WImage(com.github.bordertech.wcomponents.WImage) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext) WAudio(com.github.bordertech.wcomponents.WAudio)

Example 15 with WImage

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

the class WButtonRenderer_Test method testButtonImageToolTipRender.

@Test
public void testButtonImageToolTipRender() throws IOException, SAXException, XpathException {
    WButton button = new WButton();
    String expected = "alt text";
    WImage buttonImage = new WImage("http://localhost/image.png", expected);
    button.setImage(buttonImage.getImage());
    assertXpathEvaluatesTo(expected, "//html:button/@title", button);
}
Also used : WImage(com.github.bordertech.wcomponents.WImage) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

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