001    /*
002    @license.text@
003     */
004    package biz.hammurapi.swing;
005    
006    import java.util.List;
007    
008    import javax.swing.table.DefaultTableModel;
009    import javax.swing.table.TableModel;
010    import javax.swing.tree.TreeNode;
011    
012    /**
013     * @author Pavel Vlasov
014     * @revision $Revision: 1.1 $
015     */
016    public class PrimitivesVisualizer {
017            
018            private static class PrimitiveVisualizable extends LazyTreeNodeTableVisualizable {
019                    Object o;
020                    
021                    public PrimitiveVisualizable(TreeNode parent, String name, Object o) {
022                            super(parent, name+" ["+o.getClass().getName()+"] "+o, EMPTY_LIST);
023                            this.o = o;
024                    }
025    
026                    public TableModel toTable() {
027                            DefaultTableModel tm=new DefaultTableModel(1,2);
028                            tm.setColumnIdentifiers(new String[] {"Type", "Value"});
029                            tm.setValueAt(o.getClass().getName(), 0, 0);
030                            tm.setValueAt(o, 0, 1);
031                            
032                            return tm;
033                    }
034    
035                    protected List loadChildren() {
036                            return EMPTY_LIST;
037                    }
038                    
039            }       
040            
041            public Visualizable convert(final String o) {
042                    return new Visualizable() {
043    
044                            public TreeNode toTreeNode(TreeNode parent, String title) {
045                                    return new PrimitiveVisualizable(parent, title, o);
046                            }
047                            
048                    };
049            }
050    
051            public Visualizable convert(final Number o) {
052                    return new Visualizable() {
053    
054                            public TreeNode toTreeNode(TreeNode parent, String title) {
055                                    return new PrimitiveVisualizable(parent, title, o);
056                            }
057                            
058                    };
059            }
060    
061            public Visualizable convert(final Boolean o) {
062                    return new Visualizable() {
063    
064                            public TreeNode toTreeNode(TreeNode parent, String title) {
065                                    return new PrimitiveVisualizable(parent, title, o);
066                            }
067                            
068                    };
069            }
070    
071            public Visualizable convert(final Character o) {
072                    return new Visualizable() {
073    
074                            public TreeNode toTreeNode(TreeNode parent, String title) {
075                                    return new PrimitiveVisualizable(parent, title, o);
076                            }
077                            
078                    };
079            }
080    }