Package org.wicketstuff.gchart
Class ChartLibLoaderBehavior
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.wicketstuff.gchart.ChartLibLoaderBehavior
-
- All Implemented Interfaces:
Serializable,IComponentAwareEventSink,IComponentAwareHeaderContributor,IClusterable,ChartLibLoader,JavaScriptable
public class ChartLibLoaderBehavior extends Behavior implements JavaScriptable, ChartLibLoader
Behavior to bundle the Google chart lib loading and package declaration for multiple charts on one page. All needed packages are merged in a set, so the loading is done only once as the docs request. To use add this behavior to the page (not the chart) and give the instance as param to every constructor of a chart component of the page. The Charts will register in the loader byChartLibLoader.addChart(org.wicketstuff.gchart.Chart)and lib loading is done centralized. Use this behavior at page when you display multiple charts on the page (Since Google Charts version 45 this is mandatory, but still recommended.)- Author:
- Dieter Tremel
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOADER_SCRIPT_ID
-
Constructor Summary
Constructors Constructor Description ChartLibLoaderBehavior()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddChart(Chart chart)Add a chart to the loader, so it's package is loaded to.voidbind(Component component)List<Chart>getCharts()HeaderItemgetHeaderItem()Get the HeaderItem the loader adds, only to make dependencies to.StringgetLoaderUrl()Get Google loader URL.LocalegetLocale()The Locale is used to render alanguage = "de"in the load statement like in the example:booleanisRenderLocale()booleanremoveChart(Chart chart)Remove a previous added chart.voidrenderHead(Component component, IHeaderResponse response)voidsetLocale(Locale locale)voidsetRenderLocale(boolean renderLocale)StringtoJavaScript()Return the JavaScript part.-
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onComponentTag, onConfigure, onEvent, onException, onRemove, onTag, unbind
-
-
-
-
Field Detail
-
LOADER_SCRIPT_ID
public static final String LOADER_SCRIPT_ID
-
-
Method Detail
-
addChart
public boolean addChart(Chart chart)
Description copied from interface:ChartLibLoaderAdd a chart to the loader, so it's package is loaded to.- Specified by:
addChartin interfaceChartLibLoader- Parameters:
chart- Chart to add.- Returns:
- True if Chart is added.
-
removeChart
public boolean removeChart(Chart chart)
Description copied from interface:ChartLibLoaderRemove a previous added chart.- Specified by:
removeChartin interfaceChartLibLoader- Parameters:
chart- Chart to remove.- Returns:
- True if the Chart was managed and is removed now, false otherwise.
-
getLocale
public Locale getLocale()
The Locale is used to render alanguage = "de"in the load statement like in the example:
If this behavior is attached to the Page, Locale is set from the Page which normally is identical to// Load Google Charts for the Japanese locale. google.charts.load('current', {'packages':['corechart'], 'language': 'ja'});Session.getLocale(). To override usesetLocale(java.util.Locale).- Returns:
- Locale used for the package language option.
-
setLocale
public void setLocale(Locale locale)
-
isRenderLocale
public boolean isRenderLocale()
-
setRenderLocale
public void setRenderLocale(boolean renderLocale)
-
getLoaderUrl
public String getLoaderUrl()
Get Google loader URL. Can be overwritten, if Google changes URL in future.- Returns:
- Returns
Chart.LOADER_URL.
-
toJavaScript
public String toJavaScript()
Description copied from interface:JavaScriptableReturn the JavaScript part.- Specified by:
toJavaScriptin interfaceJavaScriptable- Returns:
- JavaScript String for use as part of chart declaration.
-
getHeaderItem
public HeaderItem getHeaderItem()
Description copied from interface:ChartLibLoaderGet the HeaderItem the loader adds, only to make dependencies to.- Specified by:
getHeaderItemin interfaceChartLibLoader- Returns:
- HeaderItem that the loader contributes.
-
renderHead
public void renderHead(Component component, IHeaderResponse response)
- Specified by:
renderHeadin interfaceIComponentAwareHeaderContributor- Overrides:
renderHeadin classBehavior
-
-