⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activewfpanel.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package org.trinet.jiggle;

// WFPanel.java

import java.applet.*;
import java.text.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import org.trinet.jasi.*;
import org.trinet.jasi.coda.*;

/** This class it the graphical representation of one waveform. It is different
 from a WFPanel in that it responds to mouse events and notifies the
 MasterWFVModel.  It is both a 'controller' and a 'view' in the MasterWFVModel
 MVC set.     <p>

 It also listens for change events from the phase and amplitude lists and will
 update in response.


Explanation of view areas used here.

Each "box" defines a 2-D area in time-amp space. Time is in seconds and amp is
in counts. These boxes are used to define and map time-amp areas into graphical
areas defined by 2-D boxes defined in terms of pixels in Height and Width.

We use 3 WFSelectionBox'es:
	1) dataBox - defines the extent of the waveform data in time and amp.
	   If there is no waveform this is null as tested by 'dataBox.isNull()'
	2) panelBox - defines the time-amp bounds of this WFPanel. Normally it is
	   the same as the dataBox for a zoomPanel. For a WFPanel in a
	   GroupPanel the panelBox time bounds will usually be equal to the
	   exteme bounds of the ViewList. This insures all data is visable and
	   time aligned. For dataless WFPanels the amp dimension is problematic
	   and is arbitrarily set to +100/-100 counts.
	3) MasterWFViewBox - defines the bounds of the view. For example, in a
	   zoomedpanel the viewbox represents the JViewport and the WFPanel expands
	   to accomodate the scaling of the viewBox to the JViewport. This is
	   only used by ActiveWFPanels.

<tt>
     panelBox
    +===================================================================+
    |	+-----------------------------------------------+		|
    |	| MasterWFViewBox       +-----------------+	|		|
    |	|	           	|dataBox          |	|		|
    |	|	            	|                 |	|		|
    |	|	                +-----------------+ 	|		|
    |	+-----------------------------------------------+		|
    +===================================================================+


                    +----------------------+
     panelBox       | MasterWFViewBox      |
    +===============+======================+============================+
    |	            |                 	   |                            |
    |	            |           +----------+------+	 		|
    |		    |      	|dataBox   |      |	 		|
    |  	            |      	|          |      |	 		|
    |   	    |           +----------+------+ 	 		|
    |	            +----------------------+	                        |
    +===================================================================+
</tt>
*/

public class ActiveWFPanel extends WFPanel {

/** Bounds of the actual data in the WFView */
    WFSelectionBox dragBox = new WFSelectionBox();

    // The following mouse variables are here rather than in the mouse classes
    // because we need them in both MouseAdapter and MouseMotionAdapter
    /** Mouse drag status.*/
    boolean amDragging = false;
    /** Mouse drag start/stop coordinates*/
    int x1, x2, y1, y2;
    static final int sloppyDragX = 3; // drag must be more than this many pixels
    static final int sloppyDragY = 3; // drag must be more than this many pixels

    /** Used for dynamic cursor location views (MVC) */
    CursorLocModel cursorLocModel;

// listen for changes to selected channel or time/amp window
      WFWindowListener wfwindowListener = new WFWindowListener();

      JasiReadingChangeListener readingChangeListener = new JasiReadingChangeListener();
/**
 * Constructors
 */
    public ActiveWFPanel () {

     super();

	addMouseListener ( new MsHandler() );		// mouse button handler
	addMouseMotionListener ( new MsMoveHandler() );	// mouse motion handler

    }

    public ActiveWFPanel (WFView wfview)  {

        this ();

        setWFView(wfview);

    }

    /** Overrides WFPanel.setWFView(WFView wfv) so that ActiveWFPanels will
     * register with the MasterView's ActivePhaseList & masterWFVModel models.
     * This can only be done once the WFView is set because the WFView has the
     * reference to the MasterView.phaseList. */

    public void setWFView(WFView wfview) {

    // if this is REPLACING a previous WFView we must clean up and remove the old
    // listeners, etc.

       if (wfview == wfv)  return;   // noop
//       removeReadingListeners();
       removeListeners();

	  super.setWFView(wfview);        // this also sets the MasterView

//       addReadingListeners();
       addListeners();

    }
    protected void  addListeners () {
	     addReadingListeners();
    }
    protected void  removeListeners () {
	     removeReadingListeners();
    }
/** Change this panel's selection state. The WFViewChangeListener and the
* WFWindowChangeListener are only registered for SELECTED WFPanels, otherwise
* every change of window must be processed by ALL WFPanels (> 1200). */
         public void setSelected (boolean tf) {

           if (tf == amSelected) return;   // no change, don't re-add listeners

           if (amSelected) {   // currently selected must be unselected now
              removeWFViewListeners();
              //setBackgroundColor(unselectedColor);
              amSelected = false;
	      repaint();
           } else {

              addWFViewListeners();
              //setBackgroundColor(selectedColor);
              amSelected = true;
           }
//           repaint();
    }

    /** Add listeners to the default MasterView's WFView and WFWindow models  */
    protected void addWFViewListeners() {
       addWFViewListeners (mv);
    }

    /** Add listeners to this MasterView's WFView and WFWindow models  */
    protected void addWFViewListeners (MasterView mv) {

       if (mv != null) {

//         if (mv.masterWFViewModel != null)
//             mv.masterWFViewModel.addChangeListener(wfviewListener);

         if (mv.masterWFWindowModel != null)
             mv.masterWFWindowModel.addChangeListener(wfwindowListener);
       }
    }

    /** Remove WF listeners  */
    protected void removeWFViewListeners() {
       if (mv != null) {

//         if (mv.masterWFViewModel != null)
//             mv.masterWFViewModel.removeChangeListener(wfviewListener);

         if (mv.masterWFWindowModel != null)
             mv.masterWFWindowModel.removeChangeListener(wfwindowListener);
       }
   }
    /** Remove listeners from the WFView's reading lists (phases, amps, etc.)
    * These update the panel if phase, amps etc. are changed.   */
    protected void removeReadingListeners() {

         if (wfv == null) return;

       // listener for phase list changes
         if (wfv.phaseList != null)
             wfv.phaseList.removeChangeListener(readingChangeListener);

       // listener for amp list changes
         if (wfv.ampList != null)
             wfv.ampList.removeChangeListener(readingChangeListener);

       // listener for amp list changes
         if (wfv.codaList != null)
             wfv.codaList.removeChangeListener(readingChangeListener);
    }

    /** Add listeners to the WFView's reading lists (phases, amps, etc.)
    * These update the panel if phase, amps etc. are changed. */
    protected void addReadingListeners () {

         if (wfv == null) return;

       // listener for phase list changes
         if (wfv.phaseList != null)
             wfv.phaseList.addChangeListener(readingChangeListener);

       // listener for amp list changes
         if (wfv.ampList != null)
             wfv.ampList.addChangeListener(readingChangeListener);

       // listener for amp list changes
         if (wfv.codaList != null)
             wfv.codaList.addChangeListener(readingChangeListener);
       }

/*
     if (mv != null) {
       Solution sol[] = mv.solList.getArray();
       for (int i = 0; i<sol.length; i++) {

       // listener for phase list changes
         if (sol[i].phaseList != null)
             sol[i].phaseList.addChangeListener(readingChangeListener);

       // listener for amp list changes
         if (sol[i].ampList != null)
             sol[i].ampList.addChangeListener(readingChangeListener);

       // listener for amp list changes
         if (sol[i].codaList != null)
             sol[i].codaList.addChangeListener(readingChangeListener);
       }
     }

    }
*/

    /** Set the CursorLocModel for dynamic display of cursor location */
    public void setCursorLocModel (CursorLocModel model) {
	cursorLocModel = model;
    }

    /** Create the popup menu that is activated by a right mouse click */
    public void makePopup (Point point) {

       PopupListener popupListener = new PopupListener(mv);
       JMenuItem mi;
       JMenu submenu;

       JPopupMenu popup = new JPopupMenu();

       if (wfv.hasPhases()) {
         mi = popup.add(new JMenuItem("Delete Pick"));
         mi.addActionListener(popupListener);
       }

       if (wfv.hasAmps()) {
         mi = popup.add(new JMenuItem("Delete Amp"));
         mi.addActionListener(popupListener);
       }

       if (wfv.hasCodas()) {
         mi = popup.add(new JMenuItem("Delete Coda"));
         mi.addActionListener(popupListener);
       }

       popup.addSeparator();

       mi = popup.add(new JMenuItem("Strip more distant picks"));
       mi.addActionListener(popupListener);

       mi = popup.add(new JMenuItem("Strip by residual"));
       mi.addActionListener(popupListener);

       mi = popup.add(new JMenuItem("Strip more distant amps"));
       mi.addActionListener(popupListener);

       mi = popup.add(new JMenuItem("Strip more distant codas"));
       mi.addActionListener(popupListener);

       popup.addSeparator();

       mi = popup.add(new JMenuItem("Show waveform info"));
       mi.addActionListener(popupListener);

       mi = popup.add(new JMenuItem("Close Popup"));
       mi.addActionListener(popupListener);

       /*
       submenu = new JMenu("Strip");
       mi = submenu.add(new JMenuItem("By residual"));
       mi.addActionListener(popupListener);
       mi = submenu.add(new JMenuItem("By distance"));
       popup.add(submenu);
       mi.addActionListener(popupListener);
       */
//       mi = submenu.add(new JMenuItem("Sub3"));
//       mi.addActionListener(popupListener);

       popup.show (this, point.x, point.y);

    }
// Inner class to handle popup menu events
    public class PopupListener implements ActionListener {

      MasterView mv;

      public PopupListener (MasterView mv) {
        super();
        this.mv = mv;
      }
      Solution sol;
      public void actionPerformed (ActionEvent evt) {

	     JComponent src = (JComponent) evt.getSource(); //the popup menu

          double clickTime = dtOfPixel(src.getX());

        String action = evt.getActionCommand();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -