Tutorial: Learning to Create Java Custom Toolkit Support > Learning to Support a Complex Control > Implementing Support for the AllLights Control > Implementing Support for Recording

Implementing Support for Recording

Because you planned to support recording on the AllLights control, you suppressed low-level recording on this object, and registered to listen for mouse events on this control.

The only mouse event that you want to trigger recording on the AllLights control is a mouse click. Therefore, in this section, you implement only the mouseClicked (MouseEvent arg0) event handler method and leave the other mouse event handler methods empty.

Implement the mouseClicked method as follows and save the AllLightsCS.java file:

public void mouseClicked(MouseEvent arg0) {
    AllLights lights = (AllLights) arg0.getSource();
    int x = arg0.getX();
    int y = arg0.getY();
        if (!isInRecord())
        /* If click is within the Restart button borders*/
        if ((x > 210) && (x < 270) && (y > 165) && (y < 185)) {
            MicAPI.logLine(DEBUG_ALLLIGHTSCS, "Record Restart operation");    
            MicAPI.record(lights, "Restart");
        /* If click is within the borders of the grid, record ClickLights*/
        if ((x >= 0) && (x < 200) && (y >= 0) && (y < 200)) {
            MicAPI.logLine(DEBUG_ALLLIGHTSCS, "Record ClickLight operation");
            MicAPI.record(lights, "ClickLight", new String[] {String.valueOf(y/40), String.valueOf(x/40)});
    } catch (Throwable th) { MicAPI.logStackTrace(th);}

Note: When the wizard created the AllLightsCS.java file, it automatically added the import com.mercury.ftjadin.custom.MicAPI, required to support this code.

In this event handler method, you call MicAPI.record in different ways. To record the Restart operation you provide only the object and the operation name. To record the ClickLight operation you provide additional arguments as well, specifying the coordinates of the clicked light.

The isInRecord method is called avoid carrying out any unnecessary operations if UFT is not currently recording.

The MicAPI.logLine method prints the message to the log file only when the DEBUG_ALLLIGHTSCS flag is on. For more information, see Logging and Debugging the Custom Support Class.

The try ... catch block prevents unnecessary activity if this code is reached when the Java application is running while UFT is idle. The MicAPI.logStackTrace method prints a stack trace to the same log file as other Java Add-in Extensibility log messages, enabling you to determine when this mouseClicked method was called inadvertently.