1
2
3
4
5
6
7
8
9 package org.astrogrid.ui.votable;
10
11 import java.awt.BorderLayout;
12 import javax.swing.JPanel;
13 import javax.swing.JScrollPane;
14 import javax.swing.JTable;
15 import javax.swing.table.DefaultTableModel;
16
17 /***
18 * A panel for displaying a votable
19 *
20 * @version %I%
21 * @author M Hill
22 */
23
24 public class JVot extends JTable
25 {
26 private VOTableUtil.Votable votModel = null;
27
28 public JVot()
29 {
30 }
31
32 public void setVotModel(VOTableUtil.Votable givenVot)
33 {
34 votModel = givenVot;
35
36 DefaultTableModel model = (DefaultTableModel) getModel();
37 VOTableUtil.Table table = votModel.getResourceAt(0).getTableAt(0);
38 for(int i=0; i<table.getFieldCount(); i++)
39 {
40 VOTableUtil.Field field = (VOTableUtil.Field)table.getFieldAt(i);
41
42 String ucd = "";
43 if (field.getUcd() != null)
44 {
45 ucd = " ["+field.getUcd()+"]";
46 }
47
48 model.addColumn(field.getName()+ucd);
49 }
50
51 VOTableUtil.Tabledata data = table.getData().getTabledata();
52
53 for (int r=0; r<data.getTrCount(); r++)
54 {
55 VOTableUtil.Tr tr = data.getTrAt(r);
56 model.addRow( (Object[]) null);
57
58 for (int c=0; c<tr.getTdCount(); c++)
59 {
60 VOTableUtil.Td td = tr.getTdAt(c);
61
62 model.setValueAt(td.getPCDATA(), r, c);
63 }
64 }
65 }
66
67
68 public VOTableUtil.Votable getVotModel()
69 {
70 return votModel;
71 }
72
73 /***
74 * Factory method that sets up this instance within a scrollable panel
75 * with column headings
76 */
77 public JPanel newVotScrollPanel()
78 {
79 JPanel votPanel = new JPanel(new BorderLayout());
80 votPanel.add(getTableHeader(), BorderLayout.NORTH);
81 JScrollPane scroller = new JScrollPane(this);
82
83 votPanel.add(scroller, java.awt.BorderLayout.CENTER);
84 return votPanel;
85 }
86
87
88
89
90
91 /***
92 * See JVotBox for a useful test harness
93 *
94 public static void main(String [] args)
95 /**/
96
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119