View Javadoc

1   package edu.sc.seis.TauP;
2   
3   import java.awt.Color;
4   import java.awt.Graphics;
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   * PathPlot.java
35   *
36   *
37   * Created: Fri May  7 15:45:43 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 PathPlot extends ArrivalPlot {
47  
48      public PathPlot() {
49          super();
50          //  setDebugGraphicsOptions(DebugGraphics.LOG_OPTION);
51          setOpaque(true);
52          //  setBackground(java.awt.Color.white);
53      }
54  
55      public void paintBackground(Graphics g) {
56          int xOffset = getSize().width/2;
57          int yOffset = getSize().height/2;
58          int pixelRad = Math.min(xOffset,
59                                  yOffset);
60          double roe = 6371;
61          Color origColor = g.getColor();
62  
63          Color aColor, bColor, fillColor;
64          aColor = new Color(220, 220, 220);
65          bColor = Color.white;
66          fillColor = aColor;
67          boolean whichColor = true;
68  
69          int disconRad;
70          if (tMod != null) {
71              roe = tMod.getRadiusOfEarth();
72              disconRad =  pixelRad;
73              fillColor = whichColor ? aColor : bColor;
74              g.setColor(fillColor);
75              whichColor = ! whichColor;
76              g.fillOval(xOffset-disconRad, yOffset-disconRad,
77                         2*disconRad,
78                         2*disconRad);
79              for (int i=0;i<tMod.tauBranches[0].length-1;i++) {
80                  if (tMod.tauBranches[0][i].getBotDepth() !=
81                      tMod.tauBranches[1][i].getBotDepth()) {
82                      disconRad = (int)Math.round((tMod.getRadiusOfEarth()-
83                                                       tMod.tauBranches[0][i].getBotDepth()) /
84                                                      roe * pixelRad);
85                      fillColor = whichColor ? aColor : bColor;
86                      g.setColor(fillColor);
87                      whichColor = ! whichColor;
88                      g.fillOval(xOffset-disconRad, yOffset-disconRad,
89                                 2*disconRad,
90                                 2*disconRad);
91                  } else {
92                      disconRad = (int)Math.round((tMod.getRadiusOfEarth()-
93                                                       tMod.tauBranches[1][i].getBotDepth()) /
94                                                      roe * pixelRad);
95                      fillColor = whichColor ? aColor : bColor;
96                      g.setColor(fillColor);
97                      whichColor = ! whichColor;
98                      g.fillOval(xOffset-disconRad, yOffset-disconRad,
99                                 2*disconRad,
100                                2*disconRad);
101                 }
102             }
103         }
104 
105         g.setColor(origColor);
106     }
107 
108     public void paintArrivals(Graphics g) {
109         for (int i=0;i<arrivals.size(); i++) {
110             paintPaths(g, i);
111         }
112     }
113 
114     public void paintForeground(Graphics g) {
115         if (selectedIndex >= 0 && selectedIndex < arrivals.size()) {
116             Color orig = g.getColor();
117             g.setColor(Color.red);
118             paintPaths(g, selectedIndex);
119             g.setColor(orig);
120         }
121     }
122 
123     protected void paintPaths(Graphics g, int i) {
124         Arrival a;
125         int[] x, y;
126         int xOffset = getSize().width/2;
127         int yOffset = getSize().height/2;
128         int pixelRad = Math.min(xOffset,
129                                 yOffset);
130         double roe = 6371;
131 
132         a = (Arrival)arrivals.elementAt(i);
133         x = new int[a.getNumPathPoints()];
134         y = new int[a.getNumPathPoints()];
135 
136         if ((a.dist*180/Math.PI) % 360 > 180) {
137             // long way around
138             for (int j = 0; j < x.length; j++) {
139                 x[j] = xOffset +(int)Math.rint(Math.sin(-1*a.getPathPoint(j).dist)
140                                                    * ( roe-a.getPathPoint(j).depth) /
141                                                    roe * pixelRad);
142                 y[j] = yOffset -(int)Math.rint(Math.cos(-1*a.getPathPoint(j).dist)
143                                                    * ( roe-a.getPathPoint(j).depth) /
144                                                    roe * pixelRad);
145             }
146         } else {
147             for (int j = 0; j < x.length; j++) {
148                 x[j] = xOffset +(int)Math.rint(Math.sin(a.getPathPoint(j).dist)
149                                                    * ( roe-a.getPathPoint(j).depth) /
150                                                    roe * pixelRad);
151                 y[j] = yOffset -(int)Math.rint(Math.cos(a.getPathPoint(j).dist)
152                                                    * ( roe-a.getPathPoint(j).depth) /
153                                                    roe * pixelRad);
154             }
155         }
156 
157         g.drawPolyline(x, y, x.length);
158     }
159 
160 } // PathPlot