Chapter 3 The Application Description Language

3.27 Assets

Assets allow the customization of AM2 applications on several levels. They also help to separate the implementation of an interface and its look and feel.

You can initialize any variable in an ADL program using assets, thereby allowing these items to be customized on a per platform, per installation, per user, and per application basis. Note that different platforms may support different degrees of customization. For example, Macintosh and Windows 3.1 systems do not have separate user accounts.

Suppose an author builds an application containing a button that causes the application to exit. In the U.S., you might use the label "Quit." However, in Norway you would probably use the label "Avslutt." You can create the two labels using assets without making modifications to the actual program code.

AM2 assets correspond roughly to X Window System resources, Microsoft Windows 3.1 and Windows NT .INI files, and Macintosh preferences. However, AM2 uses its own asset mechanism rather than the native one for each platform in order to provide a portable, common interface. An ADL programmer or an application editor need only create one asset file, for use with the ADL code on all platforms.

3.27.1 Asset File Structure

Asset files are ADL code files containing application data initializationsthat the user can customize. There are three types of asset blocks: class, member and global. Class and member asset blocks are associated with an identifier and can contain statements, class asset blocks, or member asset blocks. When an asset block is applied to an object, any nested asset blocks are then applied when creating members of that object. Also, any statements it contains are evaluated in the context of the object being created, after evaluation of the izor block and before sending the Init message.

Class Asset Blocks

The assets in class asset blocks apply to all objects of the named class except those that are created dynamically (see Section 3.17, "Dynamic Objects and Storage Management" page 36). They typically appear at the top level, i.e., not embedded in any other asset block. Top-level class asset blocks do not, however, affect , dynamically created objects (see "Global Asset blocks" on page 54).
Asset Block Examples
// class asset block:

// all buttons under here will be red

class assets XFbutton

{

background = 'red;

}

// member asset block:

// the member "theExitButton" of this class will be labelled "Quit"

member assets theExitButton

{

label = 'Quit;

}

// global asset block:

// all objects of class ExitButton in the application (including

// dynamically created objects) will be labelled "Avslutt"

global assets

{

class assets ExitButton

{

label = 'Avslutt;

}

}

Member Asset Blocks

The assets in a member asset block apply to the member with the same name in the class associated with the most closely enclosing class or member asset block.

Global Asset blocks

Global asset blocks are evaluated immediately after being parsed, before the application has been completely defined or instantiated. This is intended to be used to set paths for the library mechanism. Any statements are evaluated in the scope of the wrapped asset manager class.

Global asset blocks can contain class asset blocks but not member asset blocks or other global asset blocks. Such class asset blocks are then associated with both the heap and the application class, and are applied to all objects, including dynamically created objects.

Assets and the Library Mechanism

Libraries are an abstraction that allow collections of files, both for code and for data, to be grouped without worrying about portable pathnames. Library mappings, that is associations between library and directory names, can be made in platform, installation, and user dependant asset files. Files in these libraries can then be accessed via the statement "file"@"libraryname" both in uses statements and elsewhere in ADL code, such as in media element constructors. The AppLib library automatically maps to the directory containing the original ADL file given on the command line. The wrapped asset manager handles library mappings. To set a library path, use the 'SetLibrary method, and to retrieve a mapping use the 'GetLibrary method. Note that the path returned by 'GetLibrary always ends in a directory separator that so you can concatenate it directly to a file or subdirectory name. For example, lines 3-5 of
Library Mechanism Examples
global assets

{

{ 'SetLibrary,

'MyCode,

( {'GetLibrary, 'AppLib} => self ) + "code" } => self;

}

uses "mybutton.adl"@"MyCode";

MMimage {'MEimage, {'MAfile, "bird.gif"@"AppLib"}} => mBird;
Figure 3.51 retrieve the path for the AppLib library, append the name of the code subdirectory, and then set the library named MyCode to this new path. The uses statement on line 7 then includes mybutton.adl from that library. So if the ADL program being run were /mit/ceci/user/demo/buttons.adl, it would be including /mit/ceci/user/demo/code/mybutton.adl. Similarly, the second example constructs an MMimage named mBird using the file bird.gif from the same directory as the main ADL program.

3.27.2 Assets and Precedence

You can determine precedence in the asset mechanism using these simple rules to determine which assets will be applied to an object. Assets that have higher precedence are evaluated later, causing their values to override any assigned earlier.

The order of initialization is crucial in understanding the effect of asset specifications (see Section 3.25, "Object Initialization" page 49). For instance, in the example involving exitButton described above, if the exitButton constructor sets attribute label to "Exit", but the user's asset file sets all XFbutton labels to "XFbutton", an exitButton will have label "Exit". Why? Because the derived constructor is executed after the assets for the base class are consulted.

3.27.3 Example of Using Assets

hello.adl Using Assets
uses "hello.am";

class exitButton : XFbutton

{

upon Construct

{

Pressed = {'Exit, theApp};

}

};

class Greetings : XFtop

{

exitButton hello;

} myGreetings;

Figure 3.52 and Figure 3.53
hello.am
class assets Greetings

{

member assets hello

{

label = "Hello, world!";

height = 40;

width = 200;

}

height = 40;

width = 200;

}

class assets exitButton

{

label = 'Exit; // This gets overriden by the member assets above!

}

present hello.adl, rewritten to use assets. Notice that it is broken up into separate asset and code files. As a convention, the asset file has a .am extension. In this example the asset file is explicitly included via a uses statement, but the asset specifications could just as well have been placed in the platform specific asset files. On UNIX, for instance, the assets in the file .am2rc in the user's home directory are read in during application startup.

3.27.1 - Asset File Structure
3.27.2 - Assets and Precedence
3.27.3 - Example of Using Assets

AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker