Form Editor: Source Context
Overview
At it's heart, EchoStudio is an advanced code generation tool. As developers use the Design Context, EchoStudio generates the source code for the form's Java class. Consequently, developers are never locked-in to EchoStudio -- the source code can be edited and compiled anywhere! Within EchoStudio, developers can customize a form's code within the Source Context.
Component Initialization
The majority of EchoStudio-generated code goes into the initComponents() method. This method is called from the form's constructor and it is responsible for instantiating all of the component classes, setting all of their properties, and hooking up all of the component event callbacks to necessary create the screen.
When you first access the Source Context, the initComponents() method will be collapsed. There are two reasons for this. First, the method tends to be very long and the class becomes unwieldy for editing when it is not collapsed. Second, EchoStudio will regenerate the contents of this method as the form is updates in the Design Context. When the method is regenerated, any changes to it by the developer are wiped out. Keeping the method collapsed reminds the developer to add her custom code elsewhere in the class.
Conditional Manipulation of Components
On occassion, developers may want to change a component's properties or add event listeners beyond what EchoStudio performs in the initComponents() method. For example, the form may need to conditionally highlight a grid cell by setting its background color based. Since EchoStudio regenerates the initComponents() method, the conditional manipulation must occur elsewhere in the class:
- Use the Design Context to set the the Field Visibility of the target components to Private. Be sure to provide a good variable name for the component.
- Define a new method, updateComponents(), that manipulates the target components as desired by using the new instance variables.
- Update the form's constructor to call updateComponents() after the call to initComponents().
Event Callbacks
EchoStudio will generate stubs of the methods defined by the Echo developer in the Component Editor. EchoStudio generates code in the initComponents() method to bridge from the event's listener interface to the specified method in the form class. Echo developers will need to update these method stubs appropriately.
|