📄 wfscroller.java
字号:
package org.trinet.jiggle;
import java.text.*;
import java.awt.*;
import java.util.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import org.trinet.jdbc.*;
import org.trinet.jasi.*;
import org.trinet.util.graphics.NumberChooser;
/**
* ScrollPane that contains the MultiWFPanels. Is a 'view' in the MVC group for
* selectionModel so that it can keep the selected WFPanel visible in the
* ViewPort. <p>
*
* If the view object has focus this component responds to the default keyboard actions
* for JScrollPane as defined in the Java Look and Feel:<p>
<tt>
JScrollPane (Java L&F) (Navigate refers to focus)
Navigate out forward | Tab
Navigate out backward | Shift+Tab
Move up/down | Up, Down
Move left/right | Left, Right
Move to start/end of data | Ctrl+Home, Ctrl+End
Block move up/down | PgUp, PgDn
Block move right | Ctrl+PgDn
Block move left | Ctrl+PgUp
</tt>
*/
/*
*** RUN-AWAY SCROLL BAR BEHAVIOR ****
If you press and hold the vertical scroll arrow the scroller runs-away. It
appears that holding the arrow causes many scroll events to be queued and the
scroller scrolls until they are all serviced. This seems to be a general bug in
the JScrollPane. It can happen wiht the JTable in the CatalogPanel also.
I don't know how to fix this weirdness. DDG 11/19/99 */
public class WFScroller extends JScrollPane {
MasterView mv; // the master view
/** The underlying panel that shows thru the viewport. */
public WFGroupPanel groupPanel;
/** How many panels are visible in the viewport */
static final int DEFAULT_PANEL_COUNT = 10;
int panelsInView = DEFAULT_PANEL_COUNT;
double secondsInViewport = 90.0;
boolean showFullTime = false; // flag for "show all"
boolean showRowHeader = false;
// listen for changes to selected channel or time/amp window
WFWindowListener wfwChangeListener = new WFWindowListener();
WFViewListener wfvChangeListener = new WFViewListener();
VerticalScrollListener vertScrollListener = new VerticalScrollListener();
/** Null constructor */
public WFScroller () {
}
/**
* Constructor with placeholder string. This is used to create a valid WFScroller
* when there is no data loaded yet.
*/
public WFScroller(String str) {
add(new JLabel(str));
}
/**
* Create a WFScroller containing a WFGroupPanel that has one passive
* WFPanel for each WFView in the MasterView. By default 10 WFPanels will be
* visible in the viewport. */
public WFScroller (MasterView mview) {
this(mview, DEFAULT_PANEL_COUNT, false);
}
/**
* Create a WFScroller containing a WFGroupPanel that has one WFPanel
* for each WFView in the MasterView. If the second argument is 'true'
* the WFPanels will be active and will respond to mouse events and
* notify the MasterWFVModel. By default 10 WFPanels will be visible in
* the viewport.
*/
public WFScroller (MasterView mview, boolean activePanels) {
this(mview, DEFAULT_PANEL_COUNT, activePanels);
}
/**
* Create a WFScroller containing a WFGroupPanel that has one WFPanel
* for each WFView in the MasterView. The second argument is the number of
* WFPanels visible in the scroller's viewport. If the third argument is 'true'
* the WFPanels will be active and will respond to mouse events and
* notify the MasterWFVModel.<p>
* Note that a fraction of a WFPanel may be visible at the bottom of the view.
* This is because the viewport size (in pixels) may not be perfectly
* divisible by the value of 'Jiggle.props.tracesPerPage' and the "remainder" is extra pixels
* that show at the bottom as the next panel.
*/
public WFScroller (MasterView mview, int panelsVisible, boolean activePanels) {
this.mv = mview;
addListeners();
// make a panel with all the WFPanels in it
// this is what will be scrolled and show thru the viewport
groupPanel = new WFGroupPanel(mv, activePanels);
// define the component being scrolled
this.setViewportView(groupPanel);
// speeds scrolling mucho
// deprecated in v1.3
//getViewport().setBackingStoreEnabled(true);
// scales the groupPanel to fit right number of WFPanels in the viewport
setPanelsInView(panelsVisible);
/* // Not a good idea because the lower-right corner DISAPPEARS when there is no
// horizontal scrollbar!
JToggleButton cornerButton = new JToggleButton();
// cornerButton.setPressedIcon(unfilterIcon);
cornerButton.setToolTipText("Toggle fixed/auto timescale");
cornerButton.addActionListener(new CornerButtonHandler());
add(cornerButton, ScrollPaneConstants.LOWER_RIGHT_CORNER);
*/
// show row header?
if (getShowRowHeader())
setRowHeaderView(getWFGroupPanel().getRowHeaderPanel());
}
/** Scales the groupPanel to fit right number of WFPanels in the viewport */
public void setPanelsInView (int panelsVisible) {
// sanity checks
// don't exceed max panels
if (panelsVisible > groupPanel.getPanelCount()) {
panelsVisible = groupPanel.getPanelCount();
}
if (panelsVisible < 1) return; // positive values only!
panelsInView = panelsVisible;
// tell the model so it can jump pages
mv.masterWFViewModel.setViewsPerPage(panelsInView);
int topIndex = getTopIndex();
// use viewport size to set dimensions of ONE wfpanel in the group panel
JViewport vp = getViewport();
int height = vp.getHeight() / panelsInView;
int width = vp.getWidth();
// this means: just repaint area newly scrolled into view
// should improve performance
// v1.3 only vp.setScrollMode(JViewport.BLIT_SCROLL_MODE);
// handle auto vs fixed time scale
if (getSecondsInViewport() > 0.0) {
width = (int)(((double)width / getSecondsInViewport())* mv.getViewSpan().getDuration());
}
// This will scale the whole WFGroupPanel
groupPanel.setSinglePanelSize(width, height);
// keep same top panel
setTopIndex(topIndex);
validate();
}
/** Add model listeners */
protected void addListeners() {
addListeners (mv);
}
/** Add model listeners to this MasterView's models. */
protected void addListeners (MasterView mview) {
// add this panel as an observer of the MVC model of the MasterView
// to which the WFView belongs
if (mview != null) {
// scroll listener to manage waveform cache
this.getVerticalScrollBar().addAdjustmentListener(vertScrollListener);
// listener for selected panel changes
if (mview.masterWFViewModel != null) {
wfvChangeListener = new WFViewListener();
mview.masterWFViewModel.addChangeListener(wfvChangeListener);
}
// listener for selected time window changes
if (mview.masterWFWindowModel != null) {
mview.masterWFWindowModel.addChangeListener(wfwChangeListener);
}
}
}
/** Remove model listeners to this MasterView's models. */
protected void removeListeners (MasterView mv) {
// add this panel as an observer of the MVC model of the MasterView
// to which the WFView belongs
if (mv != null) {
this.getVerticalScrollBar().removeAdjustmentListener(vertScrollListener);
// listener for selected panel changes
if (mv.masterWFViewModel != null) {
mv.masterWFViewModel.removeChangeListener(wfvChangeListener);
}
// listener for selected time window changes
if (mv.masterWFWindowModel != null) {
mv.masterWFWindowModel.removeChangeListener(wfwChangeListener);
}
}
}
/** Clean up this object before destruction. Removes listeners from other
* components, otherwise dangling references will not allow this object to
* be garbage collected. */
/*
public void destroy () {
removeListeners(mv);
}
*/
/** Return the value, in pixels, to be used as the vertical scrolling unit
increment. Jump one trace */
public int getUnitHeight() {
return groupPanel.singlePanelSize.height;
}
/** Return the value, in pixels, to be used as the vertical scrolling block
increment. Jump one screen minus one trace */
public int getBlockHeight() {
return getViewport().getHeight() - groupPanel.singlePanelSize.height;
}
public void setWFGroupPanel(WFGroupPanel panel) {
groupPanel = panel;
}
public WFGroupPanel getWFGroupPanel() {
return groupPanel;
}
/** Override paint() so that vertical scrollbar increments will be reset if the
panel is resized */
public void paintComponent (Graphics g) {
JScrollBar vbar = getVerticalScrollBar();
vbar.setUnitIncrement(getUnitHeight());
vbar.setBlockIncrement(getBlockHeight());
// adjust the waveform cache (if there is one)
// This stopped working in SDK1.3, so I added the VerticalScrollListener
// mv.wfvList.setCacheIndex(getTopIndex());
// resize wfpanels here
setPanelsInView(panelsInView);
// now do normal repaint
super.paintComponent(g);
}
/**
* Return the index of the wfPanel at the top of the viewport
*/
public int getTopIndex() {
if (getScrollPixelsPerPanel() <= 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -