Font extends AbstractCssProperty<Font> implements StateChangeInformer<CssProperty> { public Font setFontSize(final FontSize fontSize) { final StringBuilder cssValueBuilder = new StringBuilder(); if (fontStyle != null) { cssValueBuilder.append(fontStyle.getCssValue()).append(' '); } if (fontVariant != null) { cssValueBuilder.append(fontVariant.getCssValue()).append(' '); } if (fontWeight != null) { cssValueBuilder.append(fontWeight.getCssValue()).append(' '); } if (fontSize != null) { final String fontSizeCssValue = fontSize.getCssValue(); if (FontSize.INITIAL.equals(fontSizeCssValue) || FontSize.INHERIT.equals(fontSizeCssValue)) { throw new InvalidValueException( "fontSize cannot have initial/inherit as its cssValue"); } cssValueBuilder.append(fontSizeCssValue); if (lineHeight == null) { cssValueBuilder.append(' '); } } if (lineHeight != null) { if (fontSize != null) { cssValueBuilder.append('/'); } final String lineHeightCssValue = lineHeight.getCssValue(); cssValueBuilder.append(lineHeightCssValue).append(' '); } if (fontFamily != null) { final String fontFamilyCssValue = fontFamily.getCssValue(); cssValueBuilder.append(fontFamilyCssValue).append(' '); } final String trimmedCssValue = StringBuilderUtil .getTrimmedString(cssValueBuilder).toString(); cssValue = trimmedCssValue.isEmpty() ? INHERIT : trimmedCssValue; if (fontSize != null && fontSize.isAlreadyInUse() && this.fontSize != fontSize) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given fontSize is already used by another object so a new object or the previous object (if it exists) of FontSize will be used"); } return setCssValue(cssValue); } if (this.fontSize != null) { this.fontSize.setAlreadyInUse(false); } this.fontSize = fontSize; if (this.fontSize != null) { this.fontSize.setStateChangeInformer(this); this.fontSize.setAlreadyInUse(true); } if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } return this; } Font();  Font(final String cssValue);  Font(final Font font); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); @Override Font setCssValue(final String cssValue); static boolean isValid(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsCaption(); void setAsIcon(); void setAsMenu(); void setAsMessageBox(); void setAsSmallCaption(); void setAsStatusBar(); FontSize getFontSize(); LineHeight getLineHeight(); FontFamily getFontFamily(); FontVariant getFontVariant(); FontWeight getFontWeight(); FontStyle getFontStyle(); Font setFontStyle(final FontStyle fontStyle); Font setFontVariant(final FontVariant fontVariant); Font setFontWeight(final FontWeight fontWeight); Font setFontSize(final FontSize fontSize); Font setLineHeight(final LineHeight lineHeight); Font setFontFamily(final FontFamily fontFamily); @Override void stateChanged(final CssProperty stateChangedObject); static final String INITIAL; static final String INHERIT; static final String CAPTION; static final String ICON; static final String MENU; static final String MESSAGE_BOX; static final String SMALL_CAPTION; static final String STATUS_BAR; }
@Test public void testSetFontSize() { try { Font font = new Font(); font.setCssValue("italic small-caps 55.0px"); font.setFontSize(new FontSize().setCssValue("25px")); assertEquals("italic small-caps 25px", font.getCssValue()); assertNotNull(font.getFontSize()); assertEquals("25px", font.getFontSize().getCssValue()); } catch (Exception e) { e.printStackTrace(); fail("testSetCssValueString failed"); } }