11.4 Automatically Injected Resources - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
11.4 Automatically Injected Resources
Resources may be automatically injected to any instance created using the application's facilities (by callingnewInstance()
on the application instance or any Griffon artifact instance). Injection points must be annotated with @griffon.core.resources.InjectedResource
which can only be set on properties (Groovy) or fields (Java and Groovy). @InjectedResource is a perfect companion to models as the following example showsresources.properties
sample.SampleModel.griffonLogo = /griffon-logo-48x48.png logo = /griffon-logo-{0}x{0}.png
package sampleimport griffon.core.resources.InjectedResource import javax.swing.Iconclass SampleModel { @InjectedResource Icon griffonLogo @InjectedResource(key='logo', args=['16']) Icon smallGriffonLogo @InjectedResource(key='logo', args=['64']) Icon largeGriffonLogo }
@InjectedResource
assumes a naming convention in order to determine the resource key to use. These are the rules applied by the default ResourcesInjector
:
- If a value is specified for the
key
argument then use it as is - otherwise construct a key based in the field name prefixed with the full qualified class name of the field's owner