View Javadoc

1   
2   package edu.sc.seis.TauP;
3   
4   import javax.swing.table.AbstractTableModel;
5   
6   /*
7     The TauP Toolkit: Flexible Seismic Travel-Time and Raypath Utilities.
8     Copyright (C) 1998-2000 University of South Carolina
9   
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License
12    as published by the Free Software Foundation; either version 2
13    of the License, or (at your option) any later version.
14  
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19  
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  
24    The current version can be found at 
25    <A HREF="www.seis.sc.edu">http://www.seis.sc.edu</A>
26  
27    Bug reports and comments should be directed to 
28    H. Philip Crotwell, crotwell@seis.sc.edu or
29    Tom Owens, owens@seis.sc.edu
30  
31  */
32  
33  /***
34   * PierceTableModel
35   *
36   *
37   * Created: Thu May  6 14:42:17 1999
38   *
39   * @author Philip Crotwell
40   * @version 1.1.3 Wed Jul 18 15:00:35 GMT 2001
41  
42  
43  
44   */
45  
46  public class PierceTableModel extends AbstractTableModel {
47  
48      public PierceTableModel() {
49  
50      }
51  
52      public int getRowCount() {
53  	if (arrivals.length != 0) {
54  	    return arrivals[selectedIndex].getNumPiercePoints();
55  	} else {
56  	    return 0;
57  	}
58      }
59  
60      public int getColumnCount() {
61  	return 2;
62      }
63  
64      public Object getValueAt(int row, int col) {
65  	switch (col) {
66  	case 0:
67  	    double dist = (180.0/Math.PI*
68                             arrivals[selectedIndex].getPiercePoint(row).dist);
69  	    if (arrivals[selectedIndex].getDistDeg() % 360 > 180 &&
70  		dist != 0.0) {
71  		dist *= -1.0;
72  	    }
73  	    return float8_2.form(dist);
74  	case 1:
75              return float8_2.form(arrivals[selectedIndex].getPiercePoint(row).depth);
76  	default:
77              return "";
78  	}
79      }
80  
81      public String getColumnName(int col) {
82  	switch (col) {
83  	case 0:
84              return "Dist";
85  	case 1:
86              return "Depth";
87  	default:
88              return "";
89  	}
90      }
91  
92      public void setArrivals(Arrival[] arrivals) {
93  	this.arrivals = arrivals;
94  	setSelectedIndex(0);
95  	
96  	fireTableDataChanged();
97      }
98  
99      public void setSelectedIndex(int index) {
100 	this.selectedIndex = index;
101 	fireTableDataChanged();
102     }
103 
104     private int selectedIndex = 0;
105     private Arrival[] arrivals = new Arrival[0];
106 
107     private static Format float8_2 = new Format("%8.2f");
108 
109 } // PierceTableModel