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

📄 wfscroller.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          return 0;
  } else {
    return (int) Math.ceil((double)getVerticalScrollBar().getValue() / (double)getScrollPixelsPerPanel());
        }
    }

    /**
     * Set the top visible WFPanel to this index value of the WFGroupPanel. The move is
     * done via the scrollbar so that the scroll bar stays in synch.
     */
    public void setTopIndex (int index) {

  int pixValue = index * getScrollPixelsPerPanel();

  getVerticalScrollBar().setValue(pixValue);
    }

    /**
     * Set the center visible WFPanel to this index value of the
     * WFGroupPanel. The move is done via the scrollbar so that the scroll bar
     * stays in synch.  */
    public void setCenterIndex (int index) {

  int idx = index - (panelsInView/2);
  if (idx < 0) idx = 0;
  setTopIndex(idx);
    }


    /** Return how many scroll bar pixels represent on WFPanel in the viewport */
    int getScrollPixelsPerPanel() {
  JScrollBar vbar = getVerticalScrollBar();
  return (int) ( (double)vbar.getMaximum() /
           (double)groupPanel.getComponentCount());
    }

/**
 * Make this WFPanel visible in the viewPort. If it's already visible do nothing.
 */
 public void makePanelVisible(WFPanel wfp) {

     if (wfp == null) return;
     if (panelIsVisible(wfp)) return;		// only move is necessary

     Dimension size = wfp.getSize();
     wfp.scrollRectToVisible(new Rectangle(0,0, size.width, size.height));
 }

 /** Set the width of the viewport in seconds. If 'secs' <= 0.0 then the width
  *  is set to the legth of the data. Note that if the value set here is greater
  *  than the duration of the data in the view getSecondsInViewport() will return
  *  the data duration rather than this value. This prevents a "short" view with
  *  gray space at the end. */
 public void setSecondsInViewport(double secs) {
   if (secs <= 0.0) {
     setShowFullTime(true);
   } else {
     setShowFullTime(false);
     secondsInViewport = secs;
   }
 }
/** Return the width of the Viewport in seconds. This value is set with
setSecondsInViewport(). If the value passed to setSecondsInViewport() is <= 0
this method returns the width of the MasterView's viewspan.
The returned value will never be greater than the duration of the data even if
setSecondsInViewport() is used to set it to a larger value. */
 public double getSecondsInViewport() {
    if (getShowFullTime()) return mv.getViewSpan().getDuration();

    return Math.min(secondsInViewport, mv.getViewSpan().getDuration());
 }
 /** Set true to show the fill time series in the window. */
 public void setShowFullTime(boolean tf) {
     showFullTime = tf;
 }
 /** Returns true if flag is set to show the fill time series in the window. */
 public boolean getShowFullTime() {
     return showFullTime;
 }
 /** Set true to show the WFPanel row headers in the scroller. */
 public void setShowRowHeader(boolean tf) {

     if (getShowRowHeader() == tf) return;    // no change

     showRowHeader = tf;
     if (getShowRowHeader()) {
      setRowHeaderView(getWFGroupPanel().getRowHeaderPanel());
     } else {
      setRowHeaderView(null);
     }
 }
 /** Returns true if flag is set to show the WFPanel row headers in the scroller. */
 public boolean getShowRowHeader() {
     return showRowHeader;
 }
 /**
 * Center this WFPanel in the viewPort. Sets as the selected view.
 */

 public void centerViewportOnPanel(WFPanel wfp) {

     // set selected
 // causes infinite loop!    mv.masterWFViewModel.set(wfp.wfv);

     Point viewXY = getViewport().getViewPosition();	// get ViewPort origin
     // only change Y for now
     Point newPoint = new Point(viewXY.x, wfp.getY());

     getViewport().setViewPosition (newPoint);

     validate();	// insure complete repaint, it may have done its 'update' before we did
 }

 /**
 * Center this Channel's WFPanel in the viewPort.
 */

 public void centerViewportOnPanel(Channel chan) {

     WFView wfview = mv.wfvList.get(chan);

     if (wfview == null) return;

     WFPanel wfp = groupPanel.wfpList.get(wfview);

     if (wfp == null) return;

     centerViewportOnPanel(wfp);

 }

 /** Return true if the given WFPanel is visible in the viewport */
     public boolean panelIsVisible(WFPanel wfp) {

       Rectangle viewRect = getViewport().getViewRect();		// whats showing?

       if ( viewRect.contains( wfp.getLocation() ) &&			// top corner
         viewRect.contains (wfp.getX(), wfp.getY()+ wfp.getHeight())	// bottom corner
    ) return true;

       return false;

     }

/** INNER CLASS: Handle changes to the selected WFView. */
      class WFViewListener implements ChangeListener {
      public void stateChanged (ChangeEvent changeEvent) {

            WFView newWFV = ((SelectedWFViewModel) changeEvent.getSource()).get();

            if (groupPanel != null &&  groupPanel.wfpList != null) {
              makePanelVisible(groupPanel.wfpList.get(newWFV));
           }

          }
      }  // end of WFViewListener

/** INNER CLASS: Handle changes to the selected time/amp window. */
      private class WFWindowListener implements ChangeListener {
      public void stateChanged (ChangeEvent changeEvent) {
              // NOOP yet, keep time window in view
          }
      }  // end of WFWindowListener

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

     double viewSpan = secondsInViewport;

  public void actionPerformed (ActionEvent evt) {

         // toggle state
         setShowFullTime(!getShowFullTime());
         repaint();

         AbstractButton but = (AbstractButton) evt.getSource();
         if (getShowFullTime()) {
//             but.setBackground(Color.red);
           but.setText("X");
         } else {
//             but.setBackground(Color.gray);
           but.setText("O");
         }
     }
}
*/
/// --------------------------------------------------------------------------
/**
 * Main for testing
 */

    public static void main (String args[])  {

  int evid;

  if (args.length <= 0)	// no args
  {
    System.out.println ("Usage: java WFScroller [evid])");

    evid = 9655069;
    System.out.println ("Using evid "+ evid+" as a test...");

  } else {

    Integer val = Integer.valueOf(args[0]);	    // convert arg String to 'double'
    evid = (int) val.intValue();
  }

// make a frame
        JFrame frame = new JFrame("Main");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });

        System.out.println ("Making connection...");
  DataSource init = new TestDataSource();  // make connection

  // NOTE: this demonstrates making a static Channel list.
        System.out.println ("Reading in station list...");
  //	Channel.setList (Channel.getAllList());

        System.out.println ("Making MasterView for evid = "+evid);

  MasterView mv = new MasterView();
  mv.setWaveFormLoadMode(MasterView.Cache);
        mv.setAlignmentMode(MasterView.AlignOnTime);
  mv.defineByDataSource(evid);

  final WFScroller wfs = new WFScroller(mv) ;	    // make scroller

        NumberChooser numberChooser =
      new NumberChooser(5, 30, 5, wfs.panelsInView);

  Container contentPane = frame.getContentPane();

        contentPane.add(numberChooser, BorderLayout.NORTH);

        numberChooser.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
             {
              NumberChooser nc = (NumberChooser) e.getSource();
              int val = (int) nc.getSelectedValue();
              System.out.println (" set panels in view = " + val);
        wfs.setPanelsInView(val);
             }
         });

  frame.getContentPane().add( wfs );	    // add scroller to frame
  contentPane.add(wfs, BorderLayout.CENTER);

        frame.pack();
        frame.setVisible(true);

  frame.setSize(800, 800);	// must be done AFTER setVisible

    }
/**
 * Keep the waveform cache centered on the area in view. This was done via the
 * repaint() method until v1.3 when it stopped working! Seems someone optimized
 * the code to reduce repaints.
 * Note: Adjustment events are triggered by BOTH mouse down and mouse up.
 * So use isAdjusting()to reduce hyperactivity.
 * They are also fired by a frame resize but the 'value' is 0.
 */
 private class VerticalScrollListener implements AdjustmentListener {

 /** Keep WFViewList.cacheMgr, if there is one, in synch with the scroller. */
       public void adjustmentValueChanged (AdjustmentEvent e) {
          if ( ((JScrollBar)e.getSource()).getValueIsAdjusting() == false) {
       if (mv.wfvList.cacheMgr != null)
                       mv.wfvList.cacheMgr.setIndex(getTopIndex());
          }
       }
  }

} // end of class

⌨️ 快捷键说明

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