Class WBootstrapTheme
public class WBootstrapTheme extends WTheme
This theme implements support for building a JWt web application that uses Twitter Bootstrap as a theme for its (layout and) styling. The theme comes with CSS from Bootstrap version 2.2.2 or version 3.1. Only the CSS components of twitter bootstrap are used, but not the JavaScript (i.e. the functional parts), since the functionality is already built-in to the widgets from the library.
Using this theme, various widgets provided by the library are rendered using markup that is compatible with Twitter Bootstrap. The bootstrap theme is also extended with a proper (compatible) styling of widgets for which bootstrap does not provide styling (table views, tree views, sliders, etc...).
By default, the theme will use CSS resources that are shipped together with the JWt
distribution, but since the Twitter Bootstrap CSS API is a popular API for custom themes, you can
easily replace the CSS with custom-built CSS (by reimplementing getStyleSheets()
).
Although this theme facilitates the use of Twitter Bootstrap with JWt, it is still important to understand how Bootstrap expects markup to be, especially related to layout using its grid system, for which we refer to the official bootstrap documentation, see http://getbootstrap.com
- See Also:
WApplication.setTheme(WTheme theme)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WBootstrapTheme.Version
Enumeration to select a bootstrap version.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WBootstrapTheme()
Constructor.WBootstrapTheme(WObject parent)
Constructor. -
Method Summary
Modifier and Type Method Description void
apply(WWidget widget, DomElement element, int elementRole)
Applies the theme to a DOM element that renders a widget.void
apply(WWidget widget, WWidget child, int widgetRole)
Applies the theme to a child of a composite widget.void
applyValidationStyle(WWidget widget, WValidator.Result validation, java.util.EnumSet<ValidationStyleFlag> styles)
Applies a style that indicates the result of validation.boolean
canBorderBoxElement(DomElement element)
java.lang.String
getActiveClass()
Returns a generic CSS class name for an active element.java.lang.String
getDisabledClass()
Returns a generic CSS class name for a disabled element.java.lang.String
getName()
Returns a theme name.java.util.List<WCssStyleSheet>
getStyleSheets()
Returns a vector with stylesheets for the theme.WBootstrapTheme.Version
getVersion()
Returns the bootstrap version.boolean
isCanStyleAnchorAsButton()
Returns whether the theme allows for an anchor to be styled as a button.boolean
isResponsive()
Returns whether responsive features are enabled.void
setFormControlStyleEnabled(boolean enabled)
Enables form-control on all applicable form widgets.void
setResponsive(boolean enabled)
Enables responsive features.void
setVersion(WBootstrapTheme.Version version)
Sets the bootstrap version.java.lang.String
utilityCssClass(int utilityCssClassRole)
Returns a generic CSS class name for the chosen role.Methods inherited from class eu.webtoolkit.jwt.WTheme
applyValidationStyle, getResourcesUrl, serveCss
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WBootstrapTheme
Constructor. -
WBootstrapTheme
public WBootstrapTheme()Constructor.Calls
this((WObject)null)
-
-
Method Details
-
setResponsive
public void setResponsive(boolean enabled)Enables responsive features.Responsive features can be enabled only at application startup. For bootstrap 3, you need to use the progressive bootstrap feature of JWt as it requires setting HTML meta flags.
Responsive features are disabled by default.
-
isResponsive
public boolean isResponsive()Returns whether responsive features are enabled.- See Also:
setResponsive(boolean enabled)
-
setVersion
Sets the bootstrap version.The default bootstrap version is 2 (but this may change in the future and thus we recommend setting the version).
Since Twitter Bootstrap breaks its API with a major version change, the version has a big impact on how how the markup is done for various widgets.
Note that the two Bootstrap versions have a different license: Apache 2.0 for Bootstrap version 2.2.2, and MIT for version 3.1. See these licenses for details.
-
getVersion
Returns the bootstrap version. -
setFormControlStyleEnabled
public void setFormControlStyleEnabled(boolean enabled)Enables form-control on all applicable form widgets.This is relevant only for bootstrap 3.
By applying "form-control" on form widgets, they will become block level elements that take the size of the parent (which is in bootstrap's philosphy a grid layout).
The default value is
true
. -
getName
public java.lang.String getName()Description copied from class:WTheme
Returns a theme name.Returns a unique name for the theme. This name is used by the default implementation of
getResourcesUrl()
to compute a location for the theme's resources. -
getStyleSheets
Description copied from class:WTheme
Returns a vector with stylesheets for the theme.This should return a vector with stylesheets that implement the theme. This list may be tailored to the current user agent, which is read from the application environment.
- Specified by:
getStyleSheets
in classWTheme
-
apply
Description copied from class:WTheme
Applies the theme to a child of a composite widget.The
widgetRole
indicates the role thatchild
has within the implementation of thewidget
. -
apply
Description copied from class:WTheme
Applies the theme to a DOM element that renders a widget.The
element
is a rendered representation of thewidget
, and may be further customized to reflect the theme. -
getDisabledClass
public java.lang.String getDisabledClass()Description copied from class:WTheme
Returns a generic CSS class name for a disabled element.- Specified by:
getDisabledClass
in classWTheme
-
getActiveClass
public java.lang.String getActiveClass()Description copied from class:WTheme
Returns a generic CSS class name for an active element.- Specified by:
getActiveClass
in classWTheme
-
utilityCssClass
public java.lang.String utilityCssClass(int utilityCssClassRole)Description copied from class:WTheme
Returns a generic CSS class name for the chosen role.- Specified by:
utilityCssClass
in classWTheme
-
isCanStyleAnchorAsButton
public boolean isCanStyleAnchorAsButton()Description copied from class:WTheme
Returns whether the theme allows for an anchor to be styled as a button.- Specified by:
isCanStyleAnchorAsButton
in classWTheme
-
applyValidationStyle
public void applyValidationStyle(WWidget widget, WValidator.Result validation, java.util.EnumSet<ValidationStyleFlag> styles)Description copied from class:WTheme
Applies a style that indicates the result of validation.- Specified by:
applyValidationStyle
in classWTheme
-
canBorderBoxElement
- Specified by:
canBorderBoxElement
in classWTheme
-