Connections

When you make a connection in the Visual Composition Editor, you define the interaction between components. For example, if you want a data value to change when an event occurs, you would make an event-to-property connection. The following table summarizes the types of connections that the Visual Composition Editor provides. The return value is supplied by the connection's normalResult event.

Table 1. Connection Type Summary
If you want to... Use this connection type Color Does connection have a return value?
Cause one data value to change another property-to-property Dark blue No
Change a data value whenever an event occurs event-to-method Dark green Yes
Call a public behavior whenever an event occurs event-to-method Dark green Yes
Call a behavior whenever an event occurs event-to-code Dark green Yes
Supply a value to a parameter parameter-from-property, parameter-from-code, or parameter-from-method Violet No

The Source and Target of a Connection

A connection is directional; it has a source and a target. The direction in which you draw the connection determines the source and target. The bean on which the connection begins is the source; the bean on which it ends is the target.

Often, it does not matter which bean you choose as the source or target, but there are connections where direction is important.

The target of a connection can have a return value. If it does, you can treat the return value as a feature of the connection and use it as the source of another connection. This return value appears in the connection menu for the connection as normalResult.

Property-to-Property Connections

A property-to-property connection links two property values together. This causes the value of one property to change when the value of the other changes, except as noted in the table below. A connection of this type appears as a bidirectional dark blue line Property-to-Property Connection with dots at either end. The solid dot indicates the target, and the hollow dot indicates the source.

When your bean is constructed at run time, the target property is set to the value of the source property. These connections never take parameters.

For indexed properties,VisualAge generates two get/set method pairs--one for the array and one for accessing elements within the array. When you connect indexed properties, VisualAge uses the accessors for the entire array. If you want to access an individual element, make a method connection to the specific accessor.

To achieve the behavior that you anticipate, you must know something about the properties you are connecting. The following table shows the results of connecting properties of different types.

Table 2. Behavioral Considerations for Connections

TARGET HAS...
SOURCE HAS... Set method and Event Event only Set method only
Set method and Event Source and target values are fully synchronized. This connection is not valid. The source initializes the target. The target updates whenever the source's value changes.
Event only The source initializes the target. The target updates whenever the source's value changes. This connection is not valid. The source initializes the target. The target updates whenever the source's value changes.
Set method only The source initializes the target only. The source updates whenever the target's value changes. This connection is not valid. The source initializes the target. No further updates occur.

A bound property is a property whose value changes as the result of an event. For example, when a deposit or withdrawal event occurs from a bank account, the balance property is said to be bound to the event.

Properties in a property-to-property connection do not synchronize if:

Because most of the properties in this version of AWT are not bound, the source initializes the target when constructed and performs no further updates. If you want the property values to synchronize when an event occurs, you must associate an event with the property. You can do this by opening the property sheet for that connection and selecting an event from the source or target event fields. For example, the text property in AWT components is unbound. You can force this property to fire by selecting the textChanged event from the event field.

Event-to-Property Connections

An event-to-property connection updates the target property whenever the source event occurs. An event-to-property connection appears as a unidirectional dark green arrow Event-to-Property Connection Line with the arrowhead pointing to the target.

The property must have a public set method known to VisualAge; otherwise, you cannot make the connection. If you open properties on a connection of this type, the target of the connection appears as a method with the same name as that of the target property.

Event-to-Method Connections

An event-to-method connection calls the specified method of the target object whenever the source event occurs. An event-to-method connection appears as a unidirectional dark green arrow Event-to-Method Connection Line with the arrowhead pointing to the target.

Often much of an application's behavior can be specified visually by causing a method of one bean to be invoked whenever an event is signalled by another bean. For example, you might invoke the dispose method on a Frame bean when the actionPerformed event is signalled by a button (this happens when the user clicks the button).

A connection with a dashed line requires parameters. You can provide parameters through a parameter connection, by passing event data (an option in the connection window), or through a return value. For more information, see the Task information on connections.

To access behavior that is not part of the bean interface, use code connections.

Code Connections

A code connection calls code of the composite bean whenever the source event occurs. This type of connection appears as a unidirectional dark green arrow Connection Line with the arrowhead pointing to a moveable text box on the free-formsurface.

If you want processing to occur when a bean in your composition signals an event, but no available bean has a public method to accomplish that process, you can write and connect to a custom private method of the class you are editing. These methods are called code to distinguish them from the public methods for the composite class that you create and publish as bean methods. Technically, your code does not need to be private, and it is not different from other Java methods.
Note:You might notice that in VisualAge Java, the word method is used in two subtly different ways. In the Java language, method refers to a callable function of any class. In JavaBeans, method refers to a subset of the Java class methods that are exported as bean features. The set of JavaBeans method features is often the same as the set of Java public methods. However, the bean provider may further restrict the set of Java methods that show up as JavaBeans features.

You can use a code connection for the bean you are developing to connect to:

You cannot, however, connect to private or protected methods of embedded beans.

You might want to create a code connection to:

Parameter Connections

In most cases, when a connection needs a parameter, the connection line appears dashed. Connection Needing a Parameter A parameter connection supplies an input value to the target of aconnection by passing either the value from a property or the returnvalue from a method. In a parameter-from-method connection, the connection appears as a unidirectional violet arrow Parameter Connection Line with the arrowhead pointing from the parameter of the original connectionto the method providing the value. In a parameter-from-property connection, the connection appears as a bidirectional violet line with dots at either end. The solid dot indicates the target, and the hollow dot indicates the source.

The original connection is always the source of a parameter connection; the source feature is the parameter itself. If you select the parameter as the target, VisualAge reverses the direction of the parameter connection automatically.

If the target of the original connection takes parameters and the same event provides parameters by default, the connection line might appear solid. This is true even if the target takes one input parameter and you have not otherwise provided one. VisualAge can use any of the following means to supply parameters with values:


Related concepts
Generated Feature Code

Related procedures
Connecting Beans
Changing the Source and Target of Connections
Supplying a Parameter Value Using a Constant

Related references
Beans for Visual Composition
Property-to-Property Connection Window
Event-to-Method Connection Window
Event-to-Code Connection Window
Constant Parameter Value Properties Window
Parameter-from-Code Connection Window