MapVisualizer.java

biz/hammurapi/swing/MapVisualizer.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 089 Type is not documented 2 41:1
Java Inspector 089 Undocumented method 2 43:9
Java Inspector 089 Undocumented method 2 46:25
Java Inspector 089 Undocumented method 2 49:41
Java Inspector 089 Undocumented method 2 59:41
Java Inspector 089 Undocumented method 2 76:9
Java Inspector 089 Undocumented method 2 79:25
Java Inspector 089 Undocumented method 2 82:41
Java Inspector 089 Undocumented method 2 91:41
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 60:92
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 60:94
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 92:92
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 92:94
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 96:116
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 100:120
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 54:85
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 61:87
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 61:99
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 62:63
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 64:63
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 85:78
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 87:78
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 93:87
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 93:97
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 93:105
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 94:63
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 95:86
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 96:86
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 98:63
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 99:88
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 100:88

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.swing;
24
25import java.util.ArrayList;
26import java.util.Iterator;
27import java.util.List;
28import java.util.Map;
29
30import javax.swing.table.DefaultTableModel;
31import javax.swing.table.TableModel;
32import javax.swing.tree.TreeNode;
33
34import biz.hammurapi.convert.Converter;
35
36/**
37 * @author Pavel Vlasov
38 *
39 * @version $Revision: 1.1 $
40 */
41public class MapVisualizer {
42
43 public Visualizable convert(final Map map, final Converter master) {
44 return new Visualizable() {
45
46 public TreeNode toTreeNode(TreeNode parent, String title) {
47 return new LazyTreeNodeTableVisualizable(parent, title) {
48
49 protected List loadChildren() {
50 ArrayList ret = new ArrayList();
51 Iterator it = map.entrySet().iterator();
52 for (int i=0; it.hasNext(); ++i) {
53 Visualizable vs = (Visualizable) master.convert(it.next(), Visualizable.class, null);
54 ret.add(vs.toTreeNode(this, "entry "+i));
55 }
56 return ret;
57 }
58
59 public TableModel toTable() {
60 DefaultTableModel tm=new DefaultTableModel(2,2);
61 tm.setColumnIdentifiers(new String[] {"Property", "Value"});
62 tm.setValueAt("type", 0, 0);
63 tm.setValueAt(map.getClass().getName(), 0, 1);
64 tm.setValueAt("size", 1, 0);
65 tm.setValueAt(String.valueOf(map.size()), 1, 1);
66
67 return tm;
68 }
69
70 };
71 }
72
73 };
74 }
75
76 public Visualizable convert(final Map.Entry entry, final Converter master) {
77 return new Visualizable() {
78
79 public TreeNode toTreeNode(TreeNode parent, String title) {
80 return new LazyTreeNodeTableVisualizable(parent, title) {
81
82 protected List loadChildren() {
83 List ret = new ArrayList();
84 Visualizable kvs = (Visualizable) master.convert(entry.getKey(), Visualizable.class, null);
85 ret.add(kvs.toTreeNode(this, "key"));
86 Visualizable vvs = (Visualizable) master.convert(entry.getKey(), Visualizable.class, null);
87 ret.add(vvs.toTreeNode(this, "value"));
88 return ret;
89 }
90
91 public TableModel toTable() {
92 DefaultTableModel tm=new DefaultTableModel(2,3);
93 tm.setColumnIdentifiers(new String[] {"Member", "Type", "Value"});
94 tm.setValueAt("key", 0, 0);
95 tm.setValueAt(entry.getKey()==null ? "(null)" : entry.getKey().getClass().getName(), 0, 1);
96 tm.setValueAt(entry.getKey()==null ? "(null)" : entry.getKey(), 0, 2);
97
98 tm.setValueAt("value", 1, 0);
99 tm.setValueAt(entry.getValue()==null ? "(null)" : entry.getValue().getClass().getName(), 1, 1);
100 tm.setValueAt(entry.getValue()==null ? "(null)" : entry.getValue(), 1, 2);
101
102 return tm;
103 }
104
105
106 };
107 }
108 };
109 }
110}
111