70 likes | 214 Views
CssResource. escribes CssResource and the compile-time processing of CSS. reference. http://code.google.com/p/google-web-toolkit/wiki/CssResource#External https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle. Resource C ategory.
E N D
CssResource escribesCssResource and the compile-time processing of CSS
reference • http://code.google.com/p/google-web-toolkit/wiki/CssResource#External • https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle
Resource Category • The resources in a deployed GWT application can be roughly categorized into resources to • never cache (.nocache.js), • cache forever (.cache.html), • and everything else (myapp.css). • TheClientBundle interface • moves entries from the everything-else category into the cache-forever category.
Processing of CSS • Write a CSS file, with or without GWT-specific extensions • If GWT-specific extensions are used, define a custom subtype of CssResource • Declare a method that returns CssResource or a subtype in an ClientBundle • When the bundle type is generated with GWT.create() a Java expression that evaluates to the contents of the stylesheets will be created • Except in the simplest case where the Java expression is a string literal, it is generally not the case that a CSS file could be generated into the module output • At runtime, call CssResource.ensureInjected() to inject the contents of the stylesheet • This method is safe to call multiple times, as subsequent invocations will be a no-op • The recommended pattern is to call ensureInjected() in the static initializer of your various widget types
Image Sprites 1 2 3
public static final Resources INSTANCE = GWT.create(MycssResources.class); 4 MycssResources.INSTANCE.css().ensureInjected(); 5 GWTWidgetsXXX.addStyleName(Resources.INSTANCE.methodOfRes().cssClass()); myButton.addStyleName(Resources.INSTANCE.css().classInmy.css ());
Using an external resource The "with" element declares a field holding a resource object whose methods can be called to fill in attribute values. In this case it will be instantiated via a call toGWT.create(Resources.class).