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

📄 activewfpanel.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 /**
 * Paint a highlighted box. It will always be at least 1 pixel in each dimension
 * so it will be visible.
 */
     public void paintHighlight(Graphics g,
				WFSelectionBox sb,
				Color color)
   {
	int xx1, xx2, yy1, yy2;

	  xx1 = pixelOfTime(sb.timeSpan.getStart());
	  xx2 = pixelOfTime(sb.timeSpan.getEnd());

       // make sure its always at least 1 pixel wide
       if (xx1 == x2) xx2 += 1;

	  yy1 = pixelOfAmp (sb.maxAmp);
	  yy2 = pixelOfAmp (sb.minAmp);

        // make sure its always at least 1 pixel high
       if (yy1 == yy2) yy2 += 1;

	g.setColor(color);
	g.fillRect(xx1, yy1, xx2 - xx1, yy2 - yy1);

    }
/** Return true if the mouse cursor was dragged. This enforces the "sloppy" constraints
 *  that don't consider it a real drag unless it moves some number of pixels.
 *  This prevents sloppy clicks from appearing to the user as if clicks
 *  "aren't working." */
    boolean wasDragged() {
      return (Math.abs(x1-x2) > sloppyDragX);
    }
//    boolean badDragged() {
////      return Math.abs(x1-x2) <= sloppyDragX || Math.abs(y1-y2) <= sloppyDragY;
//      return Math.abs(x1-x2) <= sloppyDragX;
//    }
// -------------------------------------------------------------------
/**
 *  Mouse interaction:
 *	1) Single Click Left button:
 *	    Select new trace and put in zoomed panel centered on the
 *	    time clicked, use existing timeSpan for the view, autoscale
 *	    the amp axis.
 *	2) Double Click Left button:
 *	    Select new trace and put in zoomed panel, reset timeSpan to
 *	    include whole seismogram in the view, autoscale the amp axis.
 *	3) Right Button Click:
 *	    Popup the popup
 *      4) Right Button Drag:
 *          Select a time window, set amp to full scale.
 *	5) Middle Button Drag:
 *	    Select new trace and put in zoomed panel, select timeSpan AND
 *	    Amp span using the highlighted dragged time.
 *	    Treat these the same because some computers only have
 *	    two buttons.
 */

 /* This is NOT called after a mouse drag! */

//  boolean wasDragged = false;
  Point startPoint = new Point();      // scoped here to be seen by both mouse listeners
  boolean mouseDown = false;
  boolean dragAmp = false;

  class MsHandler extends MouseAdapter
  {
/* Mysteriously, when I started using the Observable interface with WFPanel
 * none of the WFPanel was in scope for the MsHandler. It had been before.
 * This weirdness forced me to use 'e.source' before all the variables and
 * methods that are used here. (Aug. 17, 1998)
 */
     ActiveWFPanel wfp;   // source of the mouse action
     int mods;	     // mouse modifiers (which button was pushed)
     WFSelectionBox oldBox;

// button pressed and released without moving. The mouse-click event is
// processed AFTER the mouse-released event.
	public void mouseClicked (MouseEvent e) {

	    wfp = (ActiveWFPanel) e.getSource();

	    if (wfp == null) return;

         // modifiers tell us which button is pressed
	    mods = e.getModifiers();

	 // ignore rightclick, it was handled in mousePressed()
         if (e.isPopupTrigger() ||
	     (mods & MouseEvent.BUTTON2_MASK) != 0 ||
             (mods & MouseEvent.BUTTON3_MASK) != 0)  return;

// <> One click
   // Move select Box so its centered on clicktime. Never change the size of
   // the selected time but change the size of the amp to show whole amp.
   // (don't change its dimensions unless a new WFView is selected
	  if (e.getClickCount() == 1) {

	      double clickTime = wfp.getSampletimeNearX(e.getPoint().x);

	      if (UnpickMode.isTrue()) {
		  // Delete it in Solution's list so listeners know
		  if (wfp.mv != null) {
		     Solution sol = wfp.mv.getSelectedSolution();
		     sol.deletePhase(wfv.phaseList.getNearestPhase(clickTime, sol));
                  }
	      } else {
		 processSelection (clickTime);
	      }
	  } else {
	 // double (or more) click, create selectedBox showing whole trace
          if (wfp.mv != null) {
	      wfp.mv.masterWFViewModel.set(wfp.wfv);
              wfp.mv.masterWFWindowModel.setFullView(wfp.getWf());
          }
	}

	wfp.dragBox.setNull();  // erase drag box

      }

protected void processSelection (double clickTime) {
      // this may also be done in a WFViewList object that contains us
      // but calling it twice does no harm
      setSelected(true);    // select self (if not already)

      // notify other components
      if (wfp.mv != null) {

    // WFView change
      if (wfp.mv.masterWFViewModel.set(wfp.wfv)) {   // if it was a change...

	// Window size...
	oldBox = wfp.mv.masterWFWindowModel.getSelectionBox(wfp.getWf()); // get old, may be null

	if (oldBox.isNull()) {          // null if first time selected
	  wfp.mv.masterWFWindowModel.setFullView(wfp.getWf());
	  wfp.mv.masterWFWindowModel.setCenterTime(clickTime);
	} else {
	  // scale amp to this WFView
	  wfp.mv.masterWFWindowModel.setFullAmp(wfp.getWf());
	  wfp.mv.masterWFWindowModel.setCenterTime(clickTime);
	}

      } else {      // selected WFView didn't change, just move window
	wfp.mv.masterWFWindowModel.setCenterTime(clickTime);  // wfp the same
      }

  }
}

/**
 * Event handler is called when ANY mouse button is pressed. :. must check which.
 * This selects the WFView and begins a drag box. This defines the starting corner
 * of the drag box, the position at mouseReleased will define the opposing corner.
 */
	public void mousePressed (MouseEvent e) {

	    wfp = (ActiveWFPanel) e.getSource();

	    // IMPORTANT: getting focus enables default keyboard control
	    wfp.requestFocus();  // request focus when clicked for keyboard interation, etc.

	    if (wfp == null) return;

	    wfp.mouseDown = true;
	    wfp.x1 = wfp.x2 = wfp.y1 = wfp.y2 = 0;
	    //wasDragged = false;

         // want to preserve ampSpan of zoomed panel
	    wfp.dragBox.set(wfp.getVisibleBox());

    // set starting point of the selection area for either button
	    wfp.startPoint = e.getPoint();
	    mods = e.getModifiers();

         if (e.isPopupTrigger() || (mods & MouseEvent.BUTTON3_MASK) != 0) {

		makePopup(e.getPoint());
		wfp.mouseDown = false;

         } else if ( (mods & MouseEvent.BUTTON2_MASK) != 0 ||
//		 (mods & MouseEvent.BUTTON3_MASK) != 0 ||
		 ( (mods & MouseEvent.BUTTON1_MASK) != 0 &&
		   (mods & MouseEvent.SHIFT_MASK) != 0 ) )
	  {
	      wfp.dragAmp = true;
	  } else if ((mods & MouseEvent.BUTTON1_MASK) != 0) {	// must be button#1, change time only
	      wfp.dragAmp = false;
	  }

	}

/**
 * Handle end of dragging to set the selection Box that was
 * set in the mouseDragged() method to the selected box.
 * Method is called whether or not mouse was dragged. :. is called on a click
 * or double click but those are ignored because action is only taken here
 * if wasDragged = true.
 */
	public void mouseReleased (MouseEvent e){

	    mouseDown = false;

	    wfp = (ActiveWFPanel) e.getSource();
    // If no dragging happened, let mouseClicked() handle things.
	    if (!wasDragged()) {
	        int test = e.getClickCount();
		mouseClicked(e);
	    } else if (wasDragged()) {
		wfp.setSelected(true);
		      wfp.amDragging = false;
		if (wfp.mv != null) {
		  wfp.mv.masterWFViewModel.set(wfp.wfv);
		  wfp.mv.masterWFWindowModel.set(wfp.getWf(), wfp.dragBox);
              }
	    }

	}    // end of mouseReleased

        /** When the cursor exits the panel set the CursorLocModel to the centered position.*/
//        public void mouseExited(MouseEvent e)  {
//	    wfp = (ActiveWFPanel) e.getSource();
//            if (wfp != null && wfp.cursorLocModel != null) {
//              Need center point of scroll view in pixels!
//              wfp.cursorLocModel.set(wfp, wfp.getCenterPoint());
//            }
//        }
    } // end of MsHandler class

//---------------------------------------------------------------------
/**
 * Allow dynamic painting of the selected area.
 */

  class MsMoveHandler extends MouseMotionAdapter {

    ActiveWFPanel wfp;	    // source of the mouse action
//    int mods;	    // mouse modifiers (which button was pushed)

    public void mouseDragged (MouseEvent e) {

	wfp = (ActiveWFPanel) e.getSource();

	if (wfp == null) return;

	if (wfp.mouseDown)	    // active dragging
	{
//	  wasDragged = true;

	  Point cursorLoc = e.getPoint();

// handle case when cursor moves to left of original point (backward selection)
	  if (cursorLoc.x < wfp.startPoint.x)   // to the left, negative
	  {
	      wfp.x1 = cursorLoc.x;
              wfp.x2 = wfp.startPoint.x;

	  }
	  else	    // to the right, positive
	  {
	      wfp.x1 = wfp.startPoint.x;
              wfp.x2 = cursorLoc.x;
	  }

	  if (cursorLoc.y < wfp.startPoint.y)   // above, negative
	  {
	      wfp.y1 = cursorLoc.y;
              wfp.y2 = wfp.startPoint.y;

	  }
	  else	    // below, positive
	  {
	      wfp.y1 = wfp.startPoint.y;
              wfp.y2 = cursorLoc.y;
	  }

// clip selection box to dimensions of the panel. In the future will want to
// allow autoscrolling if you go outside the viewport.
	  wfp.x1 = Math.max(wfp.x1, 0);
	  wfp.x2 = Math.min(wfp.x2, getSize().width);
	  wfp.y1 = Math.max(wfp.y1, 0);
	  wfp.y2 = Math.min(wfp.y2, getSize().height);

       // Protect users from fumble-fingered clicks that are really a drag
       // or vertical drags with zero width.
       if (Math.abs(x1-x2) > wfp.sloppyDragX) {

         // set time span for either button
	    wfp.dragBox.setTimeSpan (wfp.dtOfPixel(wfp.x1), wfp.dtOfPixel(wfp.x2));

         // set Amp part of box only for middle or right button
	    if (wfp.dragAmp) {
	      wfp.y1 = Math.max(wfp.y1, 0);
	      wfp.y2 = Math.min(wfp.y2, getSize().height);
	      wfp.dragBox.setAmpSpan ((int) wfp.ampOfPixel(wfp.y1),
	                              (int) wfp.ampOfPixel(wfp.y2));
	    }

// display dragged rectangle, don't use selectionModel here because we
// don't want the expense of the zoomed view getting repainted as we
// drag. It's also rather annoying.
// Completion of the drag will be processed by mouseReleased()
           // wasDragged = true;
	    wfp.amDragging = true;
	    wfp.repaint();

       }

      }
    }

  /**
   * Update cursor location model dynamically as mouse cursor moves about
   */
    public void mouseMoved (MouseEvent e)
    {
	ActiveWFPanel wfp = (ActiveWFPanel) e.getSource();
	if (wfp.cursorLocModel != null) {
	    wfp.cursorLocModel.set(wfp, e.getPoint());
	}
    }

  }

} // end of MultiWFPanel class

⌨️ 快捷键说明

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