Loading palettes

A palette is a JAR file. The content of the palette is described in an XML file, palette.xml , which defines the hierarchy of symbols and categories. The JAR file also contains subdirectories which store:
  • Images used by the palette symbols
  • The CSS file describing the symbols
  • Additional resources
The following figure shows the structure of a palette JAR file.
Diagram
showing a Microsoft Explorer view of the contents of a palette JAR
file. The left pane shows a tree view, with the com directory at the
top, followed successively by the ilog, views, palettes, and svgprogressbar
nodes. The latter directory is highlighted, and its images and symbols
subdirectories are visible in the tree view and in the right pane
that also contains a listing of the palette.xml and the palette.properties
files.
The palette structure
There are two main scenarios when loading a palette:
  • Scenario 1: The application uses a fixed set of symbols from a palette. In this case, the easiest way is to put the palette on the class path. No palette manager is needed. This also works for (unsigned) applets.
  • Scenario 2: The application uses a variable set of palettes. The application allows you to dynamically load palettes from the user file system at any time. In this case, a palette manager is needed, since only a palette manager can load palettes that are not on the class path. Symbol applications developed as applets must be signed for them to be able to load palettes from the user machine.
To load a palette in Scenario 1:
  1. Make sure the palette.jar file is in the class path.
  2. Create a palette:
    new IlvPalette();
    
  3. Load the palette data from the .jar file.
    You need to know the path to the palette description. For example, the description of the palette lib/palettes/jviews-palette-shared-symbols-8.10.jar is in ilog/views/palettes/shared/palette.xml . You see the path when you look at the palette in the Symbol Editor.
    palette.load(getClass().getResource(pathToPaletteXML));
    
    Now you have an IlvPalette object filled with the palette data.
  4. Retrieve a symbol from the palette by specifying its category and name path.
    IlvPaletteSymbol psymbol = palette.getSymbol("Symbols.Controls.Dial");
    
To load a palette in Scenario 2:
  1. The palette.jar must be somewhere on the file system. It does not have to be on the class path. The file system must be accessible, that is, if the application is an applet, it must be signed to access the user’s file system.
  2. Load the palette through the palette manager:
    IlvPalette[] palettes = myIlvPaletteManager.load(new URL("file://c:/
    myPalette.jar"));
    
    Since the .jar file can contain multiple palettes, an array of palettes is returned. These palettes are also added to the palette manager.
  3. Retrieve a symbol from the palette by specifying its category and name path, like in scenario 1.
    For example, if the palettes array contains only one palette:
    IlvPaletteSymbol psymbol = palettes[0].getSymbol("Symbols.Controls.Dial");