📄 wfpanel.java
字号:
PickFlag pf;
// Note that PickFlag.draw(g) will not draw 'deleted' phases
for (int i = 0; i < ph.length; i++) {
if (! ph[i].isDeleted()) {
pf = new PickFlag (this, ph[i]);
pf.setShowDescription(showPhaseDescriptions);
pf.draw(g);
}
}
}
/** Turns on or off the display of phase descriptions in the "flag" part
* of the pick flags. */
public void showPhaseDescriptions (boolean tf) {
showPhaseDescriptions = tf;
}
/**
* Plot the amplitudes on the Waveform
*/
public void paintAmpFlags (Graphics g)
{
if ( wfv == null ) return; // bail if no WFView (no data loaded)
// get the phase list
Amplitude amp[] = (Amplitude[]) wfv.ampList.getArray();
AmpFlag flag;
// Note that AmpFlag.draw(g) will not draw 'deleted' phases
for (int i = 0; i < amp.length; i++) {
if (! amp[i].isDeleted()) {
flag = new AmpFlag (this, amp[i]);
flag.draw(g);
}
}
}
/**
* Plot the codas on the waveform
*/
public void paintCodaFlags (Graphics g) {
if ( wfv == null ) return; // bail if no WFView (no data loaded)
// get the phase list
Coda coda[] = (Coda[]) wfv.codaList.getArray();
CodaFlag flag;
// Note that AmpFlag.draw(g) will not draw 'deleted' phases
for (int i = 0; i < coda.length; i++) {
if (! coda[i].isDeleted()
&& !(coda[i].getWindowTimeAmpPairs().size() == 0)) // DK 082802 added for codadurs without AvAmpWindows
{
flag = new CodaFlag (this, coda[i]);
flag.draw(g);
}
}
}
/**
* Paint a graphical marker to show where P & S phases are expected to lie.
* Its just a colored rectangle.
*/
public void paintPhaseCues(Graphics g) {
if ( wfv == null ) return; // bail if no WFView (no data loaded)
Solution sol = wfv.mv.getSelectedSolution();
if (sol == null || sol.datetime.isNull()) return; // no location
// note solution must be the first arg.
double ptime = wfv.tt.getTTp( sol.getLatLonZ(), wfv.getChannelObj().latlonz);
double stime = ptime * wfv.tt.getPSRatio();
// change from traveltime to absolute epoch time
ptime += sol.datetime.doubleValue();
stime += sol.datetime.doubleValue();
cue.set(this, ptime);
cue.draw(g);
cue.set(this, stime);
cue.draw(g);
}
/**
* Plot the phases on the waveform
*/
//TODO: could set an optional mode that would show deleted phases
/*
public void paintPickFlags (Graphics g)
{
if (pickFlagList == null) return;
// get array of PickFlags
PickFlag pf[] = new PickFlag[pickFlagList.size()];
pickFlagList.toArray(pf);
for (int i = 0; i < pf.length; i++) {
pf[i].draw(g);
}
}
*/
/**
* Paint the time scale. Also paints at bounding box.
*
*/
public void paintScale (Graphics g)
{
Color scaleColor = ScaleColor;
// Hardwired test to indicating bad time with red time ticks
if (wfv.getWaveform() != null &&
wfv.getWaveform().getTimeQuality().doubleValue() < mv.getClockQualityThreshold()) {
// System.out.println(wfv.getWaveform().toString() +" "+
// wfv.getWaveform().getTimeQuality().doubleValue());
scaleColor = Color.red;
}
if (getShowTimeScale()) {
g.setColor (scaleColor);
// paint the bounding box
g.drawRect (0, 0, getSize().width, getSize().height);
// g.drawLine (0, 0, getSize().width, 0); //top horizontal line
// g.drawLine (0, getSize().height-1,
// getSize().width, getSize().height-1); //bottom horizontal line
int smallTick = getSize().height / 30;
int tick;
double startTime = panelBox.getStartTime();
double frac = startTime - (double) ((long) startTime);
double startSec = startTime - frac;
double sec;
for (int tsec=1; tsec < panelBox.getTimeSize(); tsec++)
{
sec = startSec + (double)tsec;
tick = smallTick;
if (sec% 5 == 0) tick = smallTick * 2; // 5 sec
if (sec%10 == 0) tick = smallTick * 3; // 10 sec
if (sec%60 == 0) tick = smallTick * 4; // 60 sec
int x = pixelOfTime(sec);
g.drawLine (x, 0, x, tick);
if (showTimeLabel) {
if (sec%60 == 0) {
String label = EpochTime.epochToString (sec, "HH:mm");
g.drawString(label, x+2, 12);
}
}
}
}
if (getShowAmpScale()) {
// not implemented
}
} // end of paintScale()
/**
* Return a rectangle in pixels for the given WFSelectionBox.
* This is a method of WFPanel because it needs the WFPanel
* scaling information.
*/
public Rectangle rectOfBox(WFSelectionBox box)
{
return new Rectangle (
pixelOfTime(box.getStartTime()), // x
pixelOfAmp (box.maxAmp), // y
(int) (box.getTimeSize() * pixelsPerSecond), // width
(int) (box.getAmpSize() * pixelsPerCount) ); // height
}
/**
* Return a rectangle in pixels for the given WFSelectionBox.
* This is a method of WFPanel because it needs the WFPanel
* scaling information.
*/
public WFSelectionBox boxOfRect(Rectangle rec)
{
TimeSpan ts = new TimeSpan(dtOfPixel(rec.x),
dtOfPixel(rec.x + rec.width));
return new WFSelectionBox (ts,
(int) ampOfPixel(rec.y),
(int) ampOfPixel(rec.y + rec.height));
}
/**
* Return dt Time of this x position in the panel
*/
double dtOfPixel (Point pt)
{
return dtOfPixel(pt.x) ;
}
double dtOfPixel (int x)
{
return (panelBox.getStartTime() + ((double)x / pixelsPerSecond) ) ;
}
/**
* Calculate the pixel on the WFPanel that corrisponds to this time.
*/
int pixelOfTime (double dt)
{
// round() finds closest pixel, returns long so cast to int
return (int) Math.round( (dt - panelBox.getStartTime()) * pixelsPerSecond);
}
/**
* Return the amplitude of y position
*/
double ampOfPixel (Point pt)
{
return ampOfPixel (pt.y);
}
/**
* Return the amplitude of y position
*/
double ampOfPixel (int y)
{
return ((double) -( (y / pixelsPerCount) - transY)) ;
}
/**
* Return the amplitude of y position
*/
int pixelOfAmp (double amp)
{
return (int) Math.rint( (transY - amp) * pixelsPerCount) ;
}
/** Return a WFSelectionBox representing the part of this WFPanel that is
* visible. Simply returns the panelBox. */
public WFSelectionBox getVisibleBox() {
return panelBox;
}
/** Return the point in (x,y) pixels of the center point of this panel. */
// public Point getCenterPoint () {
// // need center of scroll window!
// return new Point (getWidth()/2, getHeight()/2);
// }
/** **************************************************************************************
* Scrollable interface methods
* These methods determine the behavior of this component if it is placed in a JScrollPane.
* @See: Scrollable
*/
boolean trackViewportX = false;
boolean trackViewportY = false;
public Dimension getPreferredScrollableViewportSize()
{
return getPreferredSize();
}
public boolean getScrollableTracksViewportWidth()
{
return trackViewportX;
}
public boolean getScrollableTracksViewportHeight()
{
return trackViewportY;
}
public void setScrollableTracksViewportWidth(boolean tf)
{
trackViewportX = tf;;
}
public void setScrollableTracksViewportHeight(boolean tf)
{
trackViewportY = tf;
}
/**
* Determines scrolling increment when "track" is clicked. (Coarse scrolling)
* Default is 1/10 of the WFPanel dimension. Override this method to change this
* behavior.
*/
public int getScrollableBlockIncrement (Rectangle visRec, int orient, int dir)
{
if (orient == SwingConstants.VERTICAL)
{
return getSize().height/10; // jump 1/10 the height
} else {
return getSize().width/10; // jump 1/10 the width
}
}
/**
* Determines scrolling increment when arrow widgit is clicked. (Fine scrolling)
* Default is 1 pixel. Override this method to change this behavior.
*/
//TODO: because of rounding, repeated scroll jumps cause cumulative error in whole.
// :. should calc. jump amt. to be explicit to next sample.
public int getScrollableUnitIncrement (Rectangle visRec, int orient, int dir)
{
if (orient == SwingConstants.VERTICAL)
{
return 5; // jump 1/10 the height
} else {
return Math.max(1, getWidth() / 100);
}
}
/*
* End of Scrollable interface methods
************************************************************************************** */
// //////////////////////////////////////////////////////
/*
* This needs more work. The width does not adjust to the text within the panel.
*/
class WFRowHeader extends JPanel
{
// ColumnLayout layout = new ColumnLayout();
// Use of a BoxLayout here does not work! Can't control the size of the panel
// with setPreferredSize() it sizes the box using the contents.
//BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
WFPanel wfp;
int fontSize = 2;
int widest = 50;
JLabel htmlLabel = new JLabel();
// constructor
public WFRowHeader(WFPanel wfpanel) {
wfp = wfpanel;
setDefaultText() ;
add(htmlLabel, JLabel.CENTER);
setBorder(BorderFactory.createLineBorder(Color.black, 1));
setMinimumSize(new Dimension(1,1)); // doesnt work
}
/** Set the text in tool tip and Panel row label */
void setDefaultText() {
if (wfp == null || wfp.wfv == null || wfp.wfv.chan == null) {
setToolTipText("");
htmlLabel.setText("");
} else {
String strtt = wfp.wfv.chan.getNet() +" "+ wfp.wfv.chan.getSta() +
" "+ wfp.wfv.chan.getSeedchan() +
" dist= "+df1.format(wfp.wfv.getDistance());
if (wfp.getWf() != null) {
strtt +=
" amp min/max= "+wfp.getWf().getMinAmp()+"/"+wfp.getWf().getMaxAmp() +
" "+wfp.getWf().getAmpUnits()+
" bias= "+wfp.getWf().getBias();
}
setToolTipText(strtt);
// labels can interpret HTML (Java v1.3 and higher)
String str = "<html>"+
"<b>"+
wfp.wfv.chan.getNet()+"<p>"+
wfp.wfv.chan.getSta() + "<p>"+
wfp.wfv.chan.getSeedchan() +"<p>"+
"</b>"+
"</html>";
htmlLabel.setText(str);
}
// setAlignmentX(JComponent.LEFT_ALIGNMENT);
// setAlignmentY(JComponent.CENTER_ALIGNMENT);
// htmlLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
// htmlLabel.setAlignmentY(JComponent.CENTER_ALIGNMENT);
}
/*
void setText() {
setToolTipText(
wfp.wfv.chan.getNet() +" "+ wfp.wfv.chan.getSta() +
" "+ wfp.wfv.chan.getSeedchan() +
" dist= "+wfp.wfv.getDistance() +
" amp min/max= "+wfp.getWf().getMinAmp()+"/"+wfp.getWf().getMaxAmp() +
+ " "+wfp.getWf().getAmpUnits()+
+" bias= "+wfp.getWf().getBias());
label[0].setText( wfp.wfv.chan.getNet()+" "+ wfp.wfv.chan.getSta());
// trying to keep track of widest label, doesn't work worth a shit.
widest = Math.max(widest, (int)label[0].getPreferredSize().getWidth());
label[1].setText( wfp.wfv.chan.getSeedchan() );
label[2].setText( ""+wfp.wfv.getDistance());
label[3].setText( wfp.getWf().getMinAmp()+"-"+wfp.getWf().getMaxAmp() );
}
*/
/** Reports the preferred size of this component as equal to the height of
* the WFPanel it represents. This keeps the row header aligned with the
* WFPanels in the WFGroupPanel. */
public Dimension getPreferredSize () {
return new Dimension (40, wfp.getHeight());
}
/** WFRowHeader adjusts its font size a bit when resized. */
public void paintComponent (Graphics g) {
setSize(getPreferredSize());
// make sure the rowheader text is up to date, something may have changed
setDefaultText();
// scale font size to size of viewport (within max/min of 8/14)
/* int newFontSize = Math.max(8, getPreferredSize().height/15);
newFontSize = Math.min(newFontSize, 14);
if (newFontSize != fontSize) {
fontSize = newFontSize;
Font font = new Font("Serif", Font.PLAIN, fontSize);
// Font font = new Font("Lucida Sans", Font.PLAIN, fontSize);
for (int i = 0; i<this.getComponentCount(); i++) {
this.getComponent(i).setFont(font);
}
}
*/
super.paintComponent(g);
}
} // end of class WFRowHeader
} // end of WFPanel class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -