Interaction between style components and style sheet
As described previously , several components are involved in paragraph and named styles manipulation:
Components reflecting named styles have to be updated accordingly when
Listeners to watch for changes
Instead of implementing hard wired relations between objects to handle style related events, application SimplyHTML implements listeners with these objects.
StyleSelector
Class StyleSelector implements the ChangeListener interface to handle ChangeEvents. The StyleSelector object in the tool bar is registered as a ChangeListener with the style sheet of any document with method registerDocument of class FrmMain. With that the StyleSelector object is notified whenever a style sheet changes. When a document is closed, class StyleSelector is removed as a ChangeListener in method unregisterDocument of class FrmMain.
In method createToolBar of class FrmMain class StyleSelector is registered with FrmMain's JTabbedPane as ChangeListener too. Whenever another document is activated in the JTabbedPane, the StyleSelector object in the tool bar is notified.
ParaStyleDialog
Class ParaStyleDialog is also implementing the ChangeListener interface. It registers itself as a ChangeListener with the style sheet of the currently active document. Whenever class ParaStyleDialog is used in MODE_NAMED_STYLE and a style is saved to the style sheet, the respective change event triggers an update of class ParaStyleDialog's list of named styles.
Class ParaStyleDialog overrides method dispose to remove itself from the list of ChangeListeners of the underlying style sheet.