View Javadoc

1   /*
2    * $Id: JVot.java,v 1.2 2004/12/07 01:33:05 jdt Exp $
3    * Copyright 2003 AstroGrid. All rights reserved.
4    *
5    * This software is published under the terms of the AstroGrid Software License,
6    * a copy of which has been included with this distribution in the LICENSE.txt file.
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        // scroller.setHorizontalScrollBarPolicy(scroller.HORIZONTAL_SCROLLBAR_NEVER);
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  $Log: JVot.java,v $
100 Revision 1.2  2004/12/07 01:33:05  jdt
101 Merge from PAL_Itn07
102 
103 Revision 1.1.116.1  2004/11/30 01:16:54  mch
104 switched to commons logging
105 
106 Revision 1.1  2004/04/15 16:34:53  mch
107 Tidied up, introduced stuff from datacenter ui
108 
109 Revision 1.1  2004/03/03 17:40:58  mch
110 Moved ui package
111 
112 Revision 1.1  2004/02/17 16:04:06  mch
113 New Desktop GUI
114 
115 Revision 1.1  2004/02/15 23:25:30  mch
116 Datacenter and MySpace desktop client GUIs
117 
118  */
119