@Test public void testConstructor3() { WStyledText text = new WStyledText(TEST_STRING, Type.EMPHASISED); Assert. assertEquals("Constructor 3 - text returned wrong value", TEST_STRING, text. getText()); Assert.assertEquals("Constructor 3 - type returned wrong value", Type.EMPHASISED, text. getType()); Assert.assertEquals("Constructor 3 - whitspace mode should default to DEFAULT", WhitespaceMode.DEFAULT, text.getWhitespaceMode()); }
@Override public void execute(final ActionEvent event) { styled.reset(); styled.setType((WStyledText.Type) type.getSelected()); styled.setWhitespaceMode((WStyledText.WhitespaceMode) mode.getSelected()); styled.setText(text.getText()); styled.setHtmlClass(useBigTextClass.isSelected() ? "bigText" : null); styled.setEncodeText(cbEncodeText.isSelected()); // text.setRichTextArea(cbEncodeText.isSelected()); } });
/** * @return Returns the type. */ public Type getType() { return getComponentModel().type; }
/** * Creates a transfer panel. */ private TransferPanel() { super(WPanel.Type.BLOCK); setLayout(new FlowLayout(Alignment.VERTICAL, 0, 10)); add(new WHeading(WHeading.SECTION, "Transfer details")); WStyledText text = new WStyledText( "If paying by electronic transfer:" + "\n \u00b7 Payments must be received within seven days of submitting the order." + "\n \u00b7 If payment is not received within seven days, the order will be discarded." + "\n \u00b7 Use only your invoice number as the lodgement reference." + "\n\nAccount details\nBank: example bank\nAcct No.: 0123456789\nAcct Name: example name" ); text.setWhitespaceMode(WStyledText.WhitespaceMode.PARAGRAPHS); add(text); } }
/** * Builds a panel for the subordinate control, including the rule for that particular option. * * @param dropdown the subordinate trigger. * @param value the dropdown option to be added * @param group the group * @param control the subordinate control */ private void buildSubordinatePanel(final WDropdown dropdown, final String value, final WComponentGroup<SubordinateTarget> group, final WSubordinateControl control) { // create the panel. WPanel panel = new WPanel(); WStyledText subordinateInfo = new WStyledText(); subordinateInfo.setWhitespaceMode(WhitespaceMode.PRESERVE); subordinateInfo.setText(value + " - Subordinate"); panel.add(subordinateInfo); // add the panel to the screen and group. infoPanel.add(panel); group.addToGroup(panel); // create the rule Rule rule = new Rule(); control.addRule(rule); rule.setCondition(new Equal(dropdown, value)); rule.addActionOnTrue(new ShowInGroup(panel, group)); }
WStyledText text = (WStyledText) component; XmlStringBuilder xml = renderContext.getWriter(); String textString = text.getText(); switch (text.getType()) { case EMPHASISED: xml.appendAttribute("type", "emphasised"); switch (text.getWhitespaceMode()) { case PARAGRAPHS: xml.appendAttribute("space", "paragraphs"); getWhitespaceMode()); if (WStyledText.WhitespaceMode.PARAGRAPHS.equals(text.getWhitespaceMode())) { textString = text.isEncodeText() ? WebUtilities.encode(textString) : HtmlToXMLUtil.unescapeToXML(textString); writeParagraphs(textString, xml); } else { xml.append(textString, text.isEncodeText());
/** * @param text the label text * @param statusText the status text * @return the decorated label */ private WDecoratedLabel makeHeadingLabel(final String text, final String statusText) { return new WDecoratedLabel(new WImage("/image/information.png", "Informative heading"), new WText(text), new WStyledText(statusText, WStyledText.Type.EMPHASISED)); }
@Test public void testXssEscaping() throws IOException, SAXException, XpathException { WStyledText styledText = new WStyledText(getMaliciousContent()); assertSafeContent(styledText); styledText.setToolTip(getMaliciousAttribute("ui:textfield")); assertSafeContent(styledText); styledText.setAccessibleText(getMaliciousAttribute("ui:textfield")); assertSafeContent(styledText); styledText.setWhitespaceMode(WStyledText.WhitespaceMode.PRESERVE); assertSafeContent(styledText); styledText.setWhitespaceMode(WStyledText.WhitespaceMode.PARAGRAPHS); assertSafeContent(styledText); }
dataOutput.setWhitespaceMode(WStyledText.WhitespaceMode.PRESERVE);
WStyledText text = new WStyledText("Fort Awesome"); add(text); text.setHtmlClass("fa fa-fort-awesome"); text = new WStyledText("Large"); add(text); text.setHtmlClass("fa fa-fort-awesome fa-lg"); text = new WStyledText("2x"); add(text); text.setHtmlClass("fa fa-fort-awesome fa-2x"); text = new WStyledText("3x"); add(text); text.setHtmlClass("fa fa-fort-awesome fa-3x"); text = new WStyledText("4x"); add(text); text.setHtmlClass("fa fa-fort-awesome fa-4x"); text = new WStyledText("5x"); add(text); text.setHtmlClass("fa fa-fort-awesome fa-500px fa-5x"); text = new WStyledText(" "); wrapper.add(text); text.setHtmlClass("fa fa-cog fa-spin"); wrapper.add(new WText("Spin"));
WStyledText msg = new WStyledText(" these notes are important"); msg.setType(WStyledText.Type.HIGH_PRIORITY); theLabel.add(msg); fieldsFlat.addField(theLabel, new WTextArea()).setInputWidth(100);
@Override public void execute(final ActionEvent event) { String selectedOption = (String) dropdown.getSelected(); info.setText(selectedOption); } });
/** * @param mode The mode to set. */ public void setWhitespaceMode(final WhitespaceMode mode) { getOrCreateComponentModel().whitespaceMode = mode; }
/** * Generate some content for the tabs. * @param dateText some text to include in the content * @return a WContainer with content. */ private WContainer sampleTabContent(final String dateText) { WContainer container = new WContainer(); WStyledText txt = new WStyledText((new DateText(dateText)).getText()); txt.setWhitespaceMode(WStyledText.WhitespaceMode.PARAGRAPHS); container.add(txt); WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_FLAT); layout.setLabelWidth(25); container.add(layout); layout.addField("Who are you?", new WTextField()); layout.addField("I like bananas", new WCheckBox()); layout.addField(new WButton("Save")); return container; } }
@Test public void testParagraphText() throws IOException, SAXException, XpathException { WStyledText styledText = new WStyledText("abc def"); styledText.setWhitespaceMode(WStyledText.WhitespaceMode.PARAGRAPHS); assertSchemaMatch(styledText); assertXpathEvaluatesTo("abc def", "//ui:text[@type='plain']", styledText); assertXpathEvaluatesTo("paragraphs", "//ui:text/@space", styledText); styledText.setText("abc\ndef"); assertSchemaMatch(styledText); assertInnerTextEquals("abc<ui:nl/>def", styledText); styledText.setText("abc\rdef"); assertSchemaMatch(styledText); assertInnerTextEquals("abc<ui:nl/>def", styledText); styledText.setText("abc\r\ndef"); assertSchemaMatch(styledText); assertInnerTextEquals("abc<ui:nl/>def", styledText); styledText.setText("abc\n\rdef"); assertSchemaMatch(styledText); assertInnerTextEquals("abc<ui:nl/>def", styledText); styledText.setText("abc\n\ndef"); assertSchemaMatch(styledText); assertInnerTextEquals("abc<ui:nl/>def", styledText); styledText.setText("abc\r\rdef"); assertSchemaMatch(styledText);
@Test public void testRendererCorrectlyConfigured() { WStyledText component = new WStyledText(); Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WStyledTextRenderer); }
dataOutput.setWhitespaceMode(WStyledText.WhitespaceMode.PRESERVE);
WStyledText iconText = new WStyledText("\u200b"); iconText.setHtmlClass(HtmlClassProperties.ICON_EDIT); WDecoratedLabel collLabel = new WDecoratedLabel(iconText, new WText("Edit inside this collapsible"), new WImage("/image/tick.png", "Checked")); WCollapsible collWithWDL = new WCollapsible(new WText("Placeholder"), collLabel);
WStyledText msg = new WStyledText(" these notes are important"); msg.setType(WStyledText.Type.HIGH_PRIORITY); theLabel.add(msg); fieldsFlat.addField(theLabel, new WTextArea()).setInputWidth(100);
@Override public void execute(final ActionEvent event) { StringBuffer buf = new StringBuffer(preface); buf.append("\n"); for (Object selected : table.getSelectedRows()) { // The Model uses the "bean" as the key PersonBean person = (PersonBean) selected; buf.append(person.toString()).append('\n'); } selectionText.setText(buf.toString()); } };