/**
* Formats the label according to the field's formatting specifications.
*/
public void format() {
JTextPane textPane = (JTextPane)getComponent();
Format format = field.getFormat();
Style style = StyleContext.getDefaultStyleContext()
.getStyle(StyleContext.DEFAULT_STYLE);
// Save selection and select all text
int selStart = textPane.getSelectionStart();
int selEnd = textPane.getSelectionEnd();
textPane.selectAll();
StyleConstants.setBold(style, format.isBold());
StyleConstants.setItalic(style, format.isItalic());
StyleConstants.setUnderline(style, format.isUnderline());
StyleConstants.setFontSize(style, (int)format.getSize());
StyleConstants.setFontFamily(style, format.getFontFamilyName());
// Color is based on visibility flag of field
StyleConstants.setForeground(style, getColor(format));
// Align
switch (format.getAlign()) {
case Format.ALIGN_CENTER:
StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
break;
case Format.ALIGN_RIGHT:
StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT);
break;
default:
StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
break;
}
textPane.setParagraphAttributes(style, true);
// Restore selection
textPane.setCaretPosition(selStart);
textPane.moveCaretPosition(selEnd);
makeBorders();
}