01: package org.uispec4j;
02:
03: import javax.swing.*;
04: import java.awt.*;
05:
06: /**
07: * Default implementation for the TreeCellValueConverter interface.
08: * This converter returns the text displayed by JLabel components only - it will throw an
09: * exception if another renderer component is not used.
10: */
11: public class DefaultTreeCellValueConverter implements
12: TreeCellValueConverter {
13: public String getValue(Component renderedComponent,
14: Object modelObject) {
15: return getLabel(renderedComponent).getText();
16: }
17:
18: public boolean isBold(Component renderedComponent,
19: Object modelObject) {
20: Font font = getLabel(renderedComponent).getFont();
21: return (font == null) ? false : font.isBold();
22: }
23:
24: public Color getForeground(Component renderedComponent,
25: Object modelObject) {
26: return getLabel(renderedComponent).getForeground();
27: }
28:
29: protected JLabel getLabel(Component renderedComponent) {
30: if (!JLabel.class.isInstance(renderedComponent)) {
31: throw new RuntimeException(
32: "Unexpected renderer for jTree: only JLabel is supported");
33: }
34: return (JLabel) renderedComponent;
35: }
36: }
|