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

📄 zoompanel.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**
     * Handle next/prevous buttons actions. This allows control of the selected WFView.
     */
    class ButtonHandler implements ActionListener, MotionButtons {


	int action;		// defines what action this listener should take.

	/**
	 * Create the button listener and define what action this listener should take
	 * based on the value of 'type'. Thus, on class can service all actions.
	 */
	public ButtonHandler (int type) {

	    action = type;

	}

	public void actionPerformed (ActionEvent evt) {

	    Object source = evt.getSource();

	    switch (action) {

	    case TOP:
  		mv.masterWFViewModel.selectFirst(mv.wfvList);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    case PAGEUP:
  		mv.masterWFViewModel.pageUp(mv.wfvList, false);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    case UP:
		mv.masterWFViewModel.selectPrevious(mv.wfvList);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    case CENTER:
		break;

	    case DOWN:
		mv.masterWFViewModel.selectNext(mv.wfvList);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    case PAGEDOWN:
  		mv.masterWFViewModel.pageDown(mv.wfvList, false);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    case BOTTOM:
   		mv.masterWFViewModel.selectLast(mv.wfvList);
          mv.masterWFWindowModel.setFullAmp(zwfp.getWf());
		break;

	    }

	}

    }
    /**
     * Build the "north" bar of the panel display.
     */
    protected JPanel makeInfoBar() {

	JPanel jp = new JPanel();

	GridBagLayout layout = new GridBagLayout();
	jp.setLayout(layout);
	GridBagConstraints GB  = new GridBagConstraints();
	// define a generic layout object that we'll reuse for diff. comps^M
	GB.weighty = 100;
	GB.fill    = GridBagConstraints.BOTH;
	GB.anchor  = GridBagConstraints.NORTHWEST;
	GB.gridx   = GridBagConstraints.RELATIVE;
	GB.gridy   = 0;

	// The staLabel has file scope because it is changed by another method
	staLabel = new JLabel("Station Info here...");
	staLabel.setBackground(Color.black);
	staLabel.setForeground(Color.blue);

	//
	GB.weightx = 60;		// 60% of bar
	layout.setConstraints(staLabel, GB);
	jp.add (staLabel);

	// cursor position labels
	GB.weightx = 40;			// 40% of bar
	layout.setConstraints(labelBox, GB);
	jp.add(cursorPanel);

	return jp;
}

//-----------------------------------------------------------------
// Make the button panel
    protected JPanel makeButtonPanel () {

	JPanel bp = new JPanel();
	// JToolBar bp = new JToolBar();


// parameters describing the Button panel's grid layout
     final int GridRows = 1;  // either rows or columns
	final int GridCols = 0;  // should be = 0
     final int Vgap = 10;
	final int Hgap = 10;

    // define the grid layout object
	GridLayout LayOut = new GridLayout(GridRows, GridCols, Vgap, Hgap);

	bp.setLayout(LayOut);

// 1st row
	//    addButton(bp, new JButton("Next"), "Jump to next waveform");
	//    addButton(bp, new JButton("Previous"), "Jump to Previous waveform");
      addButton(bp, new JButton("<-->"), "Expand time scale x2");
      addButton(bp, new JButton("-><-"), "Compress time scale x2");
      addButton(bp, new JButton("Full View"), "Return to full seismogram view");

// 2nd row
      addButton(bp, new JButton("v^"), "Expand amplitude scale x2");
      addButton(bp, new JButton("X"), "Compress amplitude scale x2");

// <> create a zoom viewport scale combobox. Values are seconds for width of viewport.

      bp.add(new JLabel("Sec/view->"));
      bp.add(new ZoomScaleComboBox(mv));

      return bp;
    }

/*-----------------------------------------------------------------
 *  method to streamline adding of buttons
 */
     void addButton (Container cont, JButton btn)
    {
      btn.addActionListener (new ActionHandler() );
      cont.add(btn);
    }
/*-----------------------------------------------------------------
 *  method to stream line adding of buttons, with tooltips
 */
     JButton addButton (Container cont, JButton btn, String tip) {
      btn.addActionListener (new ActionHandler() );
      btn.setToolTipText(tip);

      cont.add(btn);

      return btn;
    }

    /** Set Filtering enabled. Enables button in lower-right corner of the
    * scroller that toggles waveform filtering on/off. By default a Butterworth
    * highpass filter is used. A different filter can be set by calling
    * zwfp.setFilter(FilterIF). */
    public void setFilterEnabled (boolean tf) {

       filterEnabled = tf;
       if (filterButton != null) filterButton.setEnabled(filterEnabled);
    }

    /** Returns true if the filter button is enabled. */
    public boolean getFilterEnabled () {
       return filterEnabled;
    }

/** Handle filter button actions. */
class FilterButtonHandler implements ActionListener {

	public void actionPerformed (ActionEvent evt) {

         // toggle state
         zwfp.setShowAlternateWf(!zwfp.getShowAlternateWf());

         zwfp.repaint();
         repaint();

         makeChannelLabel();

     }

}

/**
 * Make the Label describing the channel.
 */
  void makeChannelLabel () {

      String header = "";

       if (zwfp == null || zwfp.wfv == null) {
         header = "No View Data.";
       } else {

         header = zwfp.wfv.getChannelObj().toDelimitedString(' ');

         if (zwfp.wfv.hasTimeSeries()) {
           Waveform wfx = zwfp.getWf();  // get selected waveform

           DecimalFormat fmt = di;
           if (Math.abs(wfx.getMaxAmp()) < 1.0) fmt = dsci;  // Sci. Notatation for small numbers

           header +=
               " bias=" + fmt.format((int) wfx.getBias()) +
               " max= " + fmt.format(wfx.getMaxAmp()) +
               " min= " + fmt.format(wfx.getMinAmp()) +
               " dist= "+ df.format(zwfp.wfv.getDistance());
         } else {
           header += " No time series.";
         }
       }

       staLabel.setText(header);   //should repaint automatically

    }

////
    /** INNER CLASS: Change events are expected from Waveform objects when the
     *  timeseries is loaded. */
    class ActiveWFLoadListener implements ChangeListener {

	public void stateChanged (ChangeEvent changeEvent) {

         setWFView(mv.masterWFViewModel.get());
	    //makeChannelLabel();

	}
    }
////

    /** Return the ZoomableWFPanel */
    public ZoomableWFPanel getActiveWFPanel() {
	return  zwfp;
    }

    /** */
    void setWFView (WFView wfv) {

         makeChannelLabel();

         // set the cursor location panel's amp style
         if (wfv == null) return;

         Waveform wf = zwfp.getWf();

         if (wf != null) {
            synchronized (wf) {
	         cursorPanel.setAmpFormat(wf.getAmpUnits(), wf.getMaxAmp());

	         if (!wf.hasTimeSeries())  {
                // remove old one then add again, else might register multi. times
                wf.removeChangeListener(activeWFLoadListener);
                wf.addChangeListener (activeWFLoadListener);
              }
            }
         }

    }

/** INNER CLASS: Handle changes to the selected WFView. */
      class WFViewListener implements ChangeListener {

         public void stateChanged (ChangeEvent changeEvent) {

	    WFView wfv =  mv.masterWFViewModel.get();
	    setWFView (wfv);

	    }
      }  // end of WFViewListener

/** INNER CLASS: Handle changes to the selected time/amp window. */
      class WFWindowListener implements ChangeListener {
     	public void stateChanged (ChangeEvent changeEvent) {
	    // noop
          }
      }

/**
 * Adjustment events are triggered by BOTH mouse down and mouse up.
 * They are also fired by a frame resize but the 'value' is 0.
 * The object here is to keep the masterWFViewWindowModel in synch with
 * the viewport area.
 */
 class VerticalScrollListener implements AdjustmentListener {

       WFSelectionBox viewBox = new WFSelectionBox();   //viewport box
       Rectangle vrect;
       int oldValue = 0;
       int newValue = 0;

       public void adjustmentValueChanged (AdjustmentEvent e) {

	   if (zwfp.wfv == null) return;	// empty panel

	   newValue = e.getValue();	// the "change" value (= pixels scrolled)
	   if (newValue == 0) return;	// ignore resize events

        // the following prevents recursive thrash
        // rounding error in conversion from amp to pixels can cause a difference
        // of one pixel in the value even if there was no change
        if (Math.abs(newValue - oldValue) <= 1) return;   // ignore redundant events
//        if (newValue == oldValue) return;   // ignore redundant events

        oldValue = newValue;

	   // get current JViewport rectangle
        // NOTE: the viewport has already been adjusted by the underlying component!
        // So just synch masterWFWindowModel with current viewport.
	   vrect = vport.getViewRect();

        double centerAmp = zwfp.ampOfPixel(vrect.y + (vrect.height/2));
//        double centerAmp = zwfp.ampOfPixel(vrect.height/2);
// THIS FIRES WFV EVENT!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
        mv.masterWFWindowModel.setCenterAmp(zwfp.getWf(), (int) Math.round(centerAmp) );
        //mv.masterWFWindowModel.setCenterAmp( (int) centerAmp);

       }

 }  // end of VerticalScrollListener

/*
 class ScrollListener implements AdjustmentListener {

       WFSelectionBox vpBox = new WFSelectionBox();   //viewport box

       public void adjustmentValueChanged (AdjustmentEvent e) {

              vpBox = zwfp.getVisibleBox();

              mv.masterWFWindowModel.set(vpBox);
       }
 }
*/
/**
 * Adjustment events are triggered by BOTH mouse down and mouse up.
 * They are also fired by a frame resize but the 'value' is 0.
 */
 class HorizontalScrollListener implements AdjustmentListener {

       WFSelectionBox viewBox = new WFSelectionBox();   //viewport box
       Rectangle vrect;
       int oldValue = 0;
       int newValue = 0;

       public void adjustmentValueChanged (AdjustmentEvent e) {

	   if (zwfp.wfv == null) return;	// empty panel

	   int newValue = e.getValue();	// the "change" value (= pixels scrolled)
	   if (newValue == 0) return;	// ignore resize events

        // the following prevents recursive thrash
        if (newValue == oldValue) return;

        oldValue = newValue;

	   // get current JViewport rectangle
	   vrect = vport.getViewRect();

        double centerTime = zwfp.dtOfPixel(vrect.x + (vrect.width/2));

        mv.masterWFWindowModel.setCenterTime(centerTime);
       }

 }  // end of HorizontalScrollListener

//-----------------------------------------------------------------
// Event handling
//-----------------------------------------------------------------

// Handle button and menu events
class ActionHandler implements ActionListener {
	private int EventNo;	// a unique # for each item (not used)

	ActionHandler (int number)	//constructor
	{
	  EventNo = number;
	}

	ActionHandler ()			// alternate constructor
	{
	  EventNo = 0;
	}
//------------------------------------------------------------------
    // actual event handling happens here (we're using the Java 1.1 model)
	public void actionPerformed (ActionEvent evt) {
        // save and make public the string of the menu item selected
          objSelected = evt;
	  EventName =  evt.getActionCommand();

// *** if button push
	if (EventName == "<-->")
	{
	    zwfp.setScale(2.0, 1.0);
	}
	if (EventName == "-><-")
	{
	    zwfp.setScale(0.5, 1.0);
	}

	if (EventName == "v^")
	{
	    zwfp.setScale(1.0, 2.0);
	}
	if (EventName == "X")
	{
	    zwfp.setScale(1.0, 0.5);
	}
	if (EventName == "Full View")
	{
	    // notify selection model that the panelbox changed
	    mv.masterWFWindowModel.set(zwfp.getWf(), zwfp.dataBox);
	}

// repaint the panel to update labels, etc. Otherwise, you get PARTIAL repaint
// when you zoom.

//	System.out.println ("repaint from ZoomPanel.actionPerformed...");

// DK/JRR 032603 bug - remove repaint --       repaint();

	}	    // end of actionPerformed

    }	// end of ActionHandler class

} // end of ZoomPanel class


⌨️ 快捷键说明

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