1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jhylafax;
21
22 import static net.sf.jhylafax.JHylaFAX.i18n;
23 import java.awt.Component;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JFrame;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTable;
29 import javax.swing.table.AbstractTableModel;
30 import javax.swing.table.DefaultTableCellRenderer;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.xnap.commons.gui.ColoredTable;
34 import org.xnap.commons.gui.DefaultDialog;
35 import org.xnap.commons.gui.table.TableLayout;
36 import org.xnap.commons.gui.table.TableSorter;
37
38 public class DetailsDialog extends DefaultDialog {
39
40 private final static Log logger = LogFactory.getLog(DetailsDialog.class);
41 private net.sf.jhylafax.DetailsDialog.KeyValueTableModel jobTableModel;
42 private ColoredTable jobTable;
43 private TableLayout jobTableLayout;
44 private List<Property> data;
45
46 public DetailsDialog(JFrame owner, List<Property> data) {
47 super(owner, BUTTON_CLOSE);
48
49 initialize();
50
51 setData(data);
52 revert();
53
54 updateLabels();
55 pack();
56 }
57
58 public void setData(List<Property> data) {
59 this.data = data;
60 }
61
62 public List<Property> getData() {
63 return data;
64 }
65
66 private void initialize() {
67 jobTableModel = new KeyValueTableModel();
68 TableSorter sorter = new TableSorter(jobTableModel);
69 jobTable = new ColoredTable(sorter);
70 jobTable.setShowVerticalLines(true);
71 jobTable.setShowHorizontalLines(false);
72 jobTable.setAutoCreateColumnsFromModel(true);
73 jobTable.setIntercellSpacing(new java.awt.Dimension(2, 1));
74 jobTable.setDefaultRenderer(Object.class, new ValueTableCellRenderer());
75 jobTableLayout = new TableLayout(jobTable);
76 jobTableLayout.setColumnProperties(0, "key", 200);
77 jobTableLayout.setColumnProperties(1, "value", 150);
78 jobTableLayout.setMaintainSortOrder(true);
79 jobTableLayout.sortByColumn(0, TableSorter.Order.ASCENDING, false);
80 setMainComponent(new JScrollPane(jobTable));
81 }
82
83 public void revert()
84 {
85 jobTableModel.setJob(data);
86 }
87
88 public void updateLabels() {
89 setTitle(i18n.tr("JHylaFAX Job Details"));
90
91 jobTableLayout.setColumnNames(new String[] {
92 i18n.tr("Property"),
93 i18n.tr("Value"),
94 });
95 }
96
97 private static class ValueTableCellRenderer extends DefaultTableCellRenderer {
98 @Override
99 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
100
101 return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
102 row, column);
103 }
104 }
105
106 public static class Property {
107 private String key;
108 private Object value;
109
110 public Property(String key, Object value) {
111 this.key = key;
112 this.value = value;
113 }
114
115 public String getKey() {
116 return key;
117 }
118
119 public void setKey(String key) {
120 this.key = key;
121 }
122
123 public Object getValue() {
124 return value;
125 }
126
127 public void setValue(Object value) {
128 this.value = value;
129 }
130
131
132 }
133
134 private static class KeyValueTableModel extends AbstractTableModel {
135
136 private List<Property> data = new ArrayList<Property>();
137
138 private static final Class[] columnClasses= {
139 String.class,
140 Object.class,
141 };
142
143 public KeyValueTableModel()
144 {
145 }
146
147 public void setJob(List<Property> data)
148 {
149 this.data = data;
150 fireTableDataChanged();
151 }
152
153 public Object getValueAt(int row, int column)
154 {
155 Property property = data.get(row);
156 switch (column) {
157 case 0:
158 return property.getKey();
159 case 1:
160 return property.getValue();
161 default:
162 return null;
163 }
164 }
165
166 public int getRowCount()
167 {
168 return data.size();
169 }
170
171 public int getColumnCount()
172 {
173 return columnClasses.length;
174 }
175
176 public Class<?> getColumnClass(int column) {
177 return columnClasses[column];
178 }
179
180 public Property getProperty(int row) {
181 return data.get(row);
182 }
183
184 }
185 }