Using Icons

This is the second step in building the oneway advisor.  In step 1 the code for the main window was developed.  But the window didn’t contain any icons – that’s the goal of this step.

Referencing External Files

A framework needs to be established for referencing external files.  To achieve this open a new script window and write the following code:

The code creates a user-defined function called Get Icons Namespace.  As the name suggests the function “gets” a namespace.  That namespace is created on line 3 and returned in line 9.  A namespace is simply a container that is used to store variables.  Those variables are created on lines 6 to 8; they identify the files used to display the icons in the application. This script needs to be saved with the name Filepath Definitions.jsl.

Abstraction

Creating functions and namespaces just to reference a file path might seem somewhat long-winded and unnecessary.  But file names are one of the few elements of a script that have the potential to lock the code to our own particular computer configuration.

I want to be confident that if the script is run on another computer that it will still work.  I also want to be confident that if the script is packaged as an JMP Add-In then it will still work.  Or if it doesn’t work then I want just a single location where I can fix problems related to file locations.

Once the Filepath Definitions file is created this is the single place for me to look for filepath-related problems.  Outside of this file, I don’t need to worry, I can use abstract names such as nsICONS:PASS_ICON without worrying about the file-specific implementation.

Also, I can easily change an icon if I decide I don’t like it!

Placing Icons On A Button Box

Now back to the original script that was saved as step1.jsl.  The code needs to be revised to include references to the icons namespace:

Let’s take a look at what has changed.  The original code now appears on lines 10 to 32.  Note the change to the Button Boxes:

Button Box("",, <<Set Icon(nsICONS:READY_ICON) )

Now, instead of displaying an ‘X’ the button will display an icon:

step2-output

Including  JSL Scripts

In order to reference the icon namespace the script  “includes” the FIlepath Definitions file (line 4) and invokes the function Get Icons Namespace (line 7).

And Finally

Line 1 has been added to be consistent with  best practice according to JMP guidelines.

The revised code should be saved as step2.jsl.

Share the joy:
facebooktwittergoogle_pluslinkedinmailfacebooktwittergoogle_pluslinkedinmail

One thought on “Using Icons”

Leave a Reply