View Javadoc

1   package edu.sc.seis.TauP;
2   
3   import javax.swing.DefaultListModel;
4   import javax.swing.JTable;
5   import javax.swing.event.ListSelectionEvent;
6   import javax.swing.event.ListSelectionListener;
7   
8   /*
9     The TauP Toolkit: Flexible Seismic Travel-Time and Raypath Utilities.
10    Copyright (C) 1998-2000 University of South Carolina
11  
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License
14    as published by the Free Software Foundation; either version 2
15    of the License, or (at your option) any later version.
16  
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21  
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  
26    The current version can be found at 
27    <A HREF="www.seis.sc.edu">http://www.seis.sc.edu</A>
28  
29    Bug reports and comments should be directed to 
30    H. Philip Crotwell, crotwell@seis.sc.edu or
31    Tom Owens, owens@seis.sc.edu
32  
33  */
34  
35  /***
36   *
37   * @author H. Philip Crotwell
38   * @version 1.1.3 Wed Jul 18 15:00:35 GMT 2001
39  
40  
41  
42   */
43  public class TauP extends javax.swing.JFrame {
44  
45      /*** Initializes the Form */
46      protected double distance = 0;
47  
48      protected javax.swing.JTable timeTable, pierceTable;
49  
50      protected ArrivalTableModel arrivalTM;
51      PierceTableModel pierceTableModel;
52      protected PathPlot pathPlotArea;
53  
54      public TauP() {
55          super("The TauP Toolkit");
56          initComponents ();
57          pack ();
58          try {
59              timeTool = new TauP_Time("iasp91");
60              timeTool.init();
61              pierceTool = new TauP_Pierce(timeTool.getTauModel());
62              pierceTool.init();
63              pathTool = new TauP_Path(timeTool.getTauModel());
64              pathTool.init();
65              phaseDialog = new PhaseDialog(this, false);
66              phaseDialog.setPhases(timeTool.getPhaseNames());
67  
68              pathPlotArea = new PathPlot();
69              pathPlotArea.setPreferredSize(new java.awt.Dimension(500, 300));
70              pathPlotArea.setMinimumSize(new java.awt.Dimension(500, 200));
71              pathPanel.add(pathPlotArea, java.awt.BorderLayout.CENTER);
72  
73          } catch (TauModelException e) {
74              System.out.println(e);
75          } catch (java.io.IOException e) {
76              System.out.println(e);
77          }
78  
79          arrivalTM = new ArrivalTableModel();
80          timeTable = new javax.swing.JTable(arrivalTM);
81  
82          javax.swing.JScrollPane timeTableScrollPane =
83              new javax.swing.JScrollPane (timeTable);
84          timeTableScrollPane.setPreferredSize(new java.awt.Dimension(500, 300));
85          timeTableScrollPane.setMinimumSize(new java.awt.Dimension(500, 200));
86  
87          timePanel.add (timeTableScrollPane, java.awt.BorderLayout.CENTER);
88  
89          modelComboBox.addItem("iasp91");
90          modelComboBox.addItem("prem");
91          modelComboBox.addItem("qdt");
92          setSize(new java.awt.Dimension(500, 300));
93  
94          pierceTableModel = new PierceTableModel();
95          pierceTable = new JTable(pierceTableModel);
96  
97          pierceArrivalList.addListSelectionListener
98              (new ListSelectionListener() {
99                      public void valueChanged(ListSelectionEvent e) {
100                         if ( ! e.getValueIsAdjusting()) {
101                             pierceListValueChanged(e);
102                         }
103                     }
104                 });
105         jScrollPane2.setViewportView(pierceTable);
106         pierceModel = new DefaultListModel();
107         pierceArrivalList.setModel(pierceModel);
108   
109         // path list
110         jList1.setModel(pierceModel);
111         jList1.setSelectionModel(pierceArrivalList.getSelectionModel());
112         validate();
113     }
114 
115     /*** This method is called from within the constructor to
116      * initialize the form.
117      * WARNING: Do NOT modify this code. The content of this method is
118      * always regenerated by the FormEditor.
119      */
120     private void initComponents () {//GEN-BEGIN:initComponents
121         // This code was developed using a non-commercially licensed version of NetBeans Developer 2.x.
122         // For details, see http://www.netbeans.com/non_commercial.html
123 
124         addWindowListener (new java.awt.event.WindowAdapter () {
125                 public void windowClosing (java.awt.event.WindowEvent evt) {
126                     exitForm (evt);
127                 }
128             }
129                            );
130         getContentPane ().setLayout (new java.awt.BorderLayout ());
131 
132         jTabbedPane1 = new javax.swing.JTabbedPane ();
133         jTabbedPane1.setMinimumSize (new java.awt.Dimension(200, 200));
134 
135         timePanel = new javax.swing.JPanel ();
136         timePanel.setToolTipText ("travel times");
137         timePanel.setName ("Time");
138         timePanel.setLayout (new java.awt.BorderLayout ());
139 
140         jTabbedPane1.addTab ("Time", null, timePanel, "travel times");
141 
142         piercePanel = new javax.swing.JPanel ();
143         piercePanel.setToolTipText ("pierce points");
144         piercePanel.setName ("Pierce");
145         piercePanel.setLayout (new java.awt.BorderLayout ());
146 
147         jScrollPane1 = new javax.swing.JScrollPane ();
148 
149         pierceArrivalList = new javax.swing.JList ();
150         pierceArrivalList.setPreferredSize (new java.awt.Dimension(60, 60));
151         pierceArrivalList.setSelectionMode (javax.swing.ListSelectionModel.SINGLE_SELECTION);
152         pierceArrivalList.setMinimumSize (new java.awt.Dimension(60, 60));
153         jScrollPane1.add (pierceArrivalList);
154 
155         jScrollPane1.setViewportView (pierceArrivalList);
156         piercePanel.add (jScrollPane1, "West");
157 
158         jScrollPane2 = new javax.swing.JScrollPane ();
159 
160         piercePanel.add (jScrollPane2, "Center");
161 
162         jTabbedPane1.addTab ("Pierce", piercePanel);
163 
164         pathPanel = new javax.swing.JPanel ();
165         pathPanel.setToolTipText ("path points");
166         pathPanel.setName ("Path Points");
167         pathPanel.setLayout (new java.awt.BorderLayout ());
168 
169         jScrollPane3 = new javax.swing.JScrollPane ();
170 
171         jList1 = new javax.swing.JList ();
172         jList1.setPreferredSize (new java.awt.Dimension(60, 60));
173         jList1.setMinimumSize (new java.awt.Dimension(60, 60));
174 
175         jScrollPane3.setViewportView (jList1);
176         pathPanel.add (jScrollPane3, "West");
177 
178         jTabbedPane1.addTab ("Path", pathPanel);
179 
180         getContentPane ().add (jTabbedPane1, "Center");
181 
182         jPanel1 = new javax.swing.JPanel ();
183         jPanel1.setLayout (new java.awt.GridBagLayout ());
184         java.awt.GridBagConstraints gridBagConstraints1;
185 
186         jLabel1 = new javax.swing.JLabel ();
187         jLabel1.setText ("Model");
188         jLabel1.setName ("modelLabel");
189         gridBagConstraints1 = new java.awt.GridBagConstraints ();
190         gridBagConstraints1.gridx = 0;
191         gridBagConstraints1.gridy = 0;
192         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         jPanel1.add (jLabel1, gridBagConstraints1);
194 
195         modelComboBox = new javax.swing.JComboBox ();
196         modelComboBox.setToolTipText ("choose a model");
197         modelComboBox.setActionCommand ("modelChanged");
198         modelComboBox.setName ("modelMenu");
199         modelComboBox.addActionListener (new java.awt.event.ActionListener () {
200                 public void actionPerformed (java.awt.event.ActionEvent evt) {
201                     chooseModelActionPerformed (evt);
202                 }
203             }
204                                          );
205         gridBagConstraints1 = new java.awt.GridBagConstraints ();
206         gridBagConstraints1.gridx = 1;
207         gridBagConstraints1.gridy = 0;
208         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
209         jPanel1.add (modelComboBox, gridBagConstraints1);
210 
211         jLabel2 = new javax.swing.JLabel ();
212         jLabel2.setText ("Distance (deg)");
213         gridBagConstraints1 = new java.awt.GridBagConstraints ();
214         gridBagConstraints1.gridx = 2;
215         gridBagConstraints1.gridy = 0;
216         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
217         gridBagConstraints1.insets = new java.awt.Insets (0, 10, 0, 0);
218         gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
219         jPanel1.add (jLabel2, gridBagConstraints1);
220 
221         distanceTextField = new javax.swing.JTextField ();
222         distanceTextField.setToolTipText ("distance in degrees");
223         distanceTextField.setPreferredSize (new java.awt.Dimension(100, 21));
224         distanceTextField.setMinimumSize (new java.awt.Dimension(100, 21));
225         distanceTextField.setText ("50.0");
226         distanceTextField.addActionListener (new java.awt.event.ActionListener () {
227                 public void actionPerformed (java.awt.event.ActionEvent evt) {
228                     distanceActionPerformed (evt);
229                 }
230             }
231                                              );
232         gridBagConstraints1 = new java.awt.GridBagConstraints ();
233         gridBagConstraints1.gridx = 3;
234         gridBagConstraints1.gridy = 0;
235         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
236         jPanel1.add (distanceTextField, gridBagConstraints1);
237 
238         jLabel3 = new javax.swing.JLabel ();
239         jLabel3.setText ("Depth");
240         jLabel3.setHorizontalAlignment (javax.swing.SwingConstants.RIGHT);
241         gridBagConstraints1 = new java.awt.GridBagConstraints ();
242         gridBagConstraints1.gridx = 2;
243         gridBagConstraints1.gridy = 1;
244         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
245         gridBagConstraints1.insets = new java.awt.Insets (0, 10, 0, 0);
246         gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
247         jPanel1.add (jLabel3, gridBagConstraints1);
248 
249         depthTextField = new javax.swing.JTextField ();
250         depthTextField.setToolTipText ("source depth in km");
251         depthTextField.setPreferredSize (new java.awt.Dimension(100, 21));
252         depthTextField.setMinimumSize (new java.awt.Dimension(100, 21));
253         depthTextField.setText ("0.0");
254         depthTextField.setName ("depthTextField");
255         depthTextField.addActionListener (new java.awt.event.ActionListener () {
256                 public void actionPerformed (java.awt.event.ActionEvent evt) {
257                     depthActionPerformed (evt);
258                 }
259             } );
260 
261         gridBagConstraints1 = new java.awt.GridBagConstraints ();
262         gridBagConstraints1.gridx = 3;
263         gridBagConstraints1.gridy = 1;
264         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         jPanel1.add (depthTextField, gridBagConstraints1);
266 
267         phaseChooserButton = new javax.swing.JButton ();
268         phaseChooserButton.setToolTipText ("show phase chooser");
269         phaseChooserButton.setText ("Phases");
270         phaseChooserButton.setActionCommand ("showPhases");
271         phaseChooserButton.setLabel ("Phases");
272         phaseChooserButton.setName ("phaseButton");
273         phaseChooserButton.addActionListener (new java.awt.event.ActionListener () {
274                 public void actionPerformed (java.awt.event.ActionEvent evt) {
275                     phaseChooserActionPerformed (evt);
276                 }
277             }
278                                               );
279         gridBagConstraints1 = new java.awt.GridBagConstraints ();
280         gridBagConstraints1.gridx = 1;
281         gridBagConstraints1.gridy = 1;
282         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
283         jPanel1.add (phaseChooserButton, gridBagConstraints1);
284 
285         calculateButton = new javax.swing.JButton ();
286         calculateButton.setToolTipText ("calculate times");
287         calculateButton.setText ("Calculate");
288         calculateButton.addActionListener (new java.awt.event.ActionListener () {
289                 public void actionPerformed (java.awt.event.ActionEvent evt) {
290                     calculateActionPerformed (evt);
291                 }
292             }
293                                            );
294         gridBagConstraints1 = new java.awt.GridBagConstraints ();
295         gridBagConstraints1.gridx = 4;
296         gridBagConstraints1.gridy = 0;
297         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
298         gridBagConstraints1.insets = new java.awt.Insets (0, 20, 0, 0);
299         jPanel1.add (calculateButton, gridBagConstraints1);
300 
301         jButton1 = new javax.swing.JButton ();
302         jButton1.setText ("Quit");
303         jButton1.setActionCommand ("quit");
304         jButton1.setLabel ("Quit");
305         jButton1.addActionListener (new java.awt.event.ActionListener () {
306                 public void actionPerformed (java.awt.event.ActionEvent evt) {
307                     quitActionPerformed (evt);
308                 }
309             }
310                                     );
311         gridBagConstraints1 = new java.awt.GridBagConstraints ();
312         gridBagConstraints1.gridx = 4;
313         gridBagConstraints1.gridy = 1;
314         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
315         gridBagConstraints1.insets = new java.awt.Insets (0, 20, 0, 0);
316         jPanel1.add (jButton1, gridBagConstraints1);
317 
318         getContentPane ().add (jPanel1, "South");
319 
320 
321     }//GEN-END:initComponents
322 
323 
324     protected boolean quitExits = false;
325     
326     /***
327        * Get the value of quitExits.
328        * @return Value of quitExits.
329        */
330     public boolean getQuitExits() {return quitExits;}
331 
332     /***
333        * Set the value of quitExits.
334        * @param v  Value to assign to quitExits.
335        */
336     public void setQuitExits(boolean  v) {this.quitExits = v;}
337     
338 
339     private void phaseChooserActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_phaseChooserActionPerformed
340         // Add your handling code here:
341         phaseDialog.setVisible(true);
342     }//GEN-LAST:event_phaseChooserActionPerformed
343 
344     private void quitActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitActionPerformed
345         // Add your handling code here:
346         if (getQuitExits()) {       
347             System.exit(0);
348         } else {
349             dispose();
350         }
351     }//GEN-LAST:event_quitActionPerformed
352 
353     private void calculateActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateActionPerformed
354         // Add your handling code here:
355         try {
356             timeTool.setSourceDepth(Double.valueOf(depthTextField.getText()).doubleValue());
357 
358             timeTool.clearPhaseNames();
359             timeTool.setPhaseNames(phaseDialog.getPhases());
360             setDistance(Double.valueOf(distanceTextField.getText()).doubleValue());
361             timeTool.calculate(distance);
362             
363             //            System.out.println("Done calculating time"+distance+" "+timeTool.getNumArrivals()
364             //                  +" "+timeTool.getPhaseNameString()+" "+timeTool.getTauModelName()
365             //                  );
366 
367             pierceTool.setSourceDepth(Double.valueOf(depthTextField.getText()).doubleValue());
368 
369             pierceTool.clearPhaseNames();
370             pierceTool.setPhaseNames(phaseDialog.getPhases());
371             pierceTool.calculate(distance);
372 
373             pathTool.setSourceDepth(Double.valueOf(depthTextField.getText()).doubleValue());
374             pathTool.clearPhaseNames();
375             pathTool.setPhaseNames(phaseDialog.getPhases());
376             pathTool.calculate(distance);
377 
378             showResults();
379         } catch (Exception e) {
380             System.out.println("exception in calculate "+e);
381             e.printStackTrace();
382         }
383     }//GEN-LAST:event_calculateActionPerformed
384 
385     private void distanceActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distanceActionPerformed
386         // Add your handling code here:
387         setDistance(Double.valueOf(evt.getActionCommand()).doubleValue());
388         calculateActionPerformed(evt);
389     }//GEN-LAST:event_distanceActionPerformed
390 
391     private void depthActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distanceActionPerformed
392         // Add your handling code here:
393         setDepth(Double.valueOf(evt.getActionCommand()).doubleValue());
394         calculateActionPerformed(evt);
395     }//GEN-LAST:event_distanceActionPerformed
396 
397     private void chooseModelActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseModelActionPerformed
398         // Add your handling code here:
399         setModel((String)(modelComboBox.getSelectedItem()));
400     }//GEN-LAST:event_chooseModelActionPerformed
401 
402     private void pierceListValueChanged(ListSelectionEvent e) {
403         pierceTableModel.setSelectedIndex(pierceArrivalList.getSelectedIndex());
404         pathPlotArea.setSelectedIndex(pierceArrivalList.getSelectedIndex());
405     }
406 
407     /*** Exit the Application */
408     private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
409         if (getQuitExits()) {       
410             System.exit(0);
411         } else {
412             dispose();
413         }
414     }//GEN-LAST:event_exitForm
415 
416 
417     // Variables declaration - do not modify//GEN-BEGIN:variables
418     private javax.swing.JTabbedPane jTabbedPane1;
419     private javax.swing.JPanel jPanel1;
420     private javax.swing.JPanel timePanel;
421     private javax.swing.JPanel piercePanel;
422     private javax.swing.JPanel pathPanel;
423     private javax.swing.JScrollPane jScrollPane1;
424     private javax.swing.JScrollPane jScrollPane2;
425     private javax.swing.JList pierceArrivalList;
426     private javax.swing.JLabel jLabel1;
427     private javax.swing.JComboBox modelComboBox;
428     private javax.swing.JLabel jLabel2;
429     private javax.swing.JTextField distanceTextField;
430     private javax.swing.JLabel jLabel3;
431     private javax.swing.JTextField depthTextField;
432     private javax.swing.JButton phaseChooserButton;
433     private javax.swing.JButton calculateButton;
434     private javax.swing.JButton jButton1;
435     private javax.swing.JScrollPane jScrollPane3;
436     private javax.swing.JList jList1;
437     // End of variables declaration//GEN-END:variables
438 
439     private TauP_Time timeTool;
440     private TauP_Pierce pierceTool;
441     private TauP_Path pathTool;
442     private PhaseDialog phaseDialog;
443     private DefaultListModel pierceModel;
444 
445     protected void setModel(String modelName) {
446         try {
447             timeTool.loadTauModel(modelName);
448             pierceTool.setTauModel(timeTool.getTauModel());
449             pathTool.setTauModel(timeTool.getTauModel());
450         } catch (Exception e) {
451             System.out.println(e);
452         }
453     }
454 
455     protected void setDepth(double depth) {
456         timeTool.setSourceDepth(depth);
457     }
458 
459     protected void setDistance(double distance) {
460         this.distance = distance;
461     }
462 
463     protected void showResults() {
464         arrivalTM.setArrivals(timeTool.getArrivals());
465         pierceTableModel.setArrivals(pierceTool.getArrivals());
466         pierceModel.removeAllElements();
467         for (int i=0; i< pierceTool.getNumArrivals(); i++) {
468             pierceModel.addElement(pierceTool.getArrival(i).getName());
469         }
470         pierceArrivalList.setSelectedIndex(0);
471 
472         pathPlotArea.setTauModel(pathTool.getTauModel());
473         pathPlotArea.removeAllElements();
474         for (int i=0; i< pathTool.getNumArrivals(); i++) {
475             pathPlotArea.addElement(pathTool.getArrival(i));
476         }
477         pathPlotArea.repaint();
478     }
479 
480     public static void main(java.lang.String[] args) {
481         TauP t = new TauP();
482         t.setQuitExits(true);
483         t.show();
484     }
485 
486 }