You can think of a style object as a freestanding collection of properties. The term style is borrowed from the word processing world where the editing of a style sheet is independent of the documents to which you apply it. The same is true for using and applying style objects in this library.
As an example, consider that your boss tells you that the new corporate color is red and you need to change the color of elements of your HTML pages. You can, of course, set properties directly on elements if you like, which is the traditional model of GUI framework programming:
// old way of doing things...
DhText t1 = new DhText();
DhText t2 = new DhText();
t1.setColor( DhColors.RED );
t1.setFont( "arial", 10 );
t2.setColor( Color.RED );
t2.setFont( "arial", 10 );
You might be drawn toward using derivation to save yourself some time. For example, you might consider improving this with some code like the following:
// old way of doing things a little better...
public class MyText extends DhText
{
public MyText()
{
setColor( Color.RED );
setFont( "arial", 10 );
}
This works fine until you decide you also want those settings for buttons, labels, tabs, documents, panels, and so on. And youÆll find yourself with even more work when you want to apply these to another part of your program or to another program.
The answer to this problem is a style object. While using this library, you can at any point instantiate a style object and set its properties:
// STEP 1: Create style objects.
DhStyle myStyle = new DhStyle();
// STEP 2: Set properties on style objects
myStyle.setColor( Color.RED );
myStyle.setFont( "arial", 10 );
Then, at any other time in the code, you can apply that style to any number of elements:
DhText t1 = new DhText();
DhText t2 = new DhText();
// STEP 3: Apply styles using the setStyle method.
t1.setStyle( myStyle );
t2.setStyle( myStyle );
When it's time to keep up with the dynamic nature of high-level policy setting at your corporation, the following line will set all instances of all elements with myStyle set on them to change color:
myStyle.setColor( Color.BLUE );
Here is the really powerful part: all this is available during runtime. Every time you make a change to the style object, the DHTML runtime will dynamically reach back and update all elements to which that style object is applied.
For more information, see: