1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.displayers.info;
24
25 import java.awt.BorderLayout;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Iterator;
29 import java.util.Map;
30
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTable;
34
35 import com.cosylab.gui.components.introspection.PropertiesTableModel;
36
37 import de.desy.acop.displayers.tools.AcopInfoDialog;
38
39
40
41
42
43
44
45
46
47
48 public class CharacteristicsPanel extends JPanel {
49
50 private static final long serialVersionUID = 5967883467749353832L;
51 private Map<String, Object> characteristics;
52 private JTable table;
53 private PropertiesTableModel model;
54 private JScrollPane tableScroll;
55
56
57
58
59
60 public CharacteristicsPanel() {
61 super();
62 initialize();
63 }
64
65 private void initialize() {
66 this.setLayout(new BorderLayout());
67 model = new PropertiesTableModel() {
68 private static final long serialVersionUID = -8633216620068900661L;
69
70
71
72
73
74 @Override
75 public synchronized Object getValueAt(int rowIndex, int columnIndex) {
76 Object obj = super.getValueAt(rowIndex, columnIndex);
77 if (obj instanceof Object[]) {
78 return Arrays.toString((Object[])obj);
79 }
80 return obj;
81 }
82
83
84
85
86
87 @Override
88 public String getColumnName(int columnIndex)
89 {
90 String name = super.getColumnName(columnIndex);
91
92 if (name.equals("property")) {
93 return "Characteristic";
94 } else if (name.equals("value")) {
95 return "Value";
96 } else {
97 return name;
98 }
99 }
100 };
101 model.setEditable(false);
102 table = new JTable();
103 table.setModel(model);
104 table.setEnabled(false);
105 tableScroll = new JScrollPane(table);
106 this.add(tableScroll, BorderLayout.CENTER);
107 }
108
109
110
111
112
113
114 public void setCharacteristics(Map<String, Object> ch) {
115 this.characteristics = ch;
116 if (characteristics == null) {
117 model.setPropertyNames(new String[]{});
118 model.setPropertyTypes(new Class[]{});
119 model.setPropertyValues(new Object[]{});
120 } else {
121 Iterator<String> it = characteristics.keySet().iterator();
122 String key;
123 Object object;
124 ArrayList<String> names = new ArrayList<String>();
125 ArrayList<Class<?>> types = new ArrayList<Class<?>>();
126 ArrayList<Object> values = new ArrayList<Object>();
127 while (it.hasNext()) {
128 key = it.next();
129 object = characteristics.get(key);
130 if (object == null) continue;
131 names.add(key);
132 types.add(object.getClass());
133 values.add(object);
134 }
135 int size = names.size();
136 model.setPropertyNames(names.toArray(new String[size]));
137 model.setPropertyTypes(types.toArray(new Class[size]));
138 model.setPropertyValues(values.toArray(new Object[size]));
139 }
140 model.fireTableDataChanged();
141 }
142 }