Class ParaStyleDialog

Class ParaStyleDialog has two major functions:

- to manipulate any given paragraph style and
- to maintain all paragraph styles in a given style sheet.

The two tasks are available as two separate operation modes of the component, MODE_PARAGRAPH_STYLE and MODE_NAMED_STYLES.

In MODE_PARAGRAPH_STYLE class ParaStyleDialog is used to directly manipulate a given set of paragraph style attributes. In MODE_NAMED_STYLES, the dialog is used to manipulate styles in a style sheet which does not affect formats of the underlying document directly (only indirect through style sheet changes).

Setting the operation mode

The operation mode is derived from the constructor used to create a ParaStyleDialog. When constructed to operate with a certain Document, MODE_NAMED_STYLES is assumed and the Document's style sheet is taken to be operated upon.

If no Document is passed to the constructor of ParaStyleDialog, it is constructed in MODE_PARAGRAPH_STYLE, i.e. not using a style sheet.

Passing initial dialog settings

Class ParaStyleDialog implements interface AttributeComponent (introduced as FontComponent initially in stage 3) so that its contents can be set or read through a set of attributes in an AttributeSet object. When in MODE_PARAGRAPH_STYLE, initial dialog contents need to be set by a call to method setValue passing an AttributeSet object having all initial paragraph styles to be manipulated.

When in MODE_NAMED_STYLES , a list of existing named paragraph styles is read from the style sheet of the Document passed in the constructor. Whenever a style is picked from those, the dialog is set to show the attributes of this style.

Reading dialog settings

As an AttributeComponent class ParaStyleDialog returns its currents attribute settings in an AttributeSet object through method getValue. In MODE_PARAGRAPH_STYLE method getValue can be used to get the set of attrbutes to be applied.

In MODE_NAMED_STYLES class ParaStyleDialog is not meant to deliver a set of attribute settings, although method setValue certainly can be used too. Instead, the dialog only makes available all named paragraph styles found in a given style sheet.

All changes to a given set of paragraph attributes can be saved to that style sheet using class ParaStyleDialog. By changing attribute settings of an existing named paragraph style and storing them back to the style sheet, format of all paragraphs using respective named style is changed implicitly, immediately and automatically in the underlying document.

Thus no direct reading of attribute settings is necessary in MODE_NAMED_STYLES.

Style sheet manipulation

In MODE_NAMED_STYLES class ParaStyleDialog offers to

- save settings to an existing named style
- create a new named style and
- to remove an exsting named style from the style sheet

Saving attributes to an existing style and creation of a new style both is done using method addRule of class StyleSheet. This method expects a style to be passed in the form of a CSS declaration string,

e.g. p.myStyle { text-align:center; }.

To transform attribute settings from class ParaStyleDialog in to this format, method writeRule of class CSSWriter is used.To remove an existing style from the style sheet class ParaStyleDialog uses method removeStyle of class StyleSheet.

Class ParaStyleDialog adds methods necessary to interact with the user upon style changes accordingly, e.g. by asking whether or not to really delete a particular style or by checking whether or not a style shall be overwritten having the same name as a name entered by the user.

With stage 8 class Util has some new methods combining a generic JOptionPane with calls to SimplyHTML's class DynamicResource for support of messages in other languages. These methods are applied to other usages of JOptionPane in SimplyHTML as well.