📄 zoompanel.java
字号:
package org.trinet.jiggle;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.text.*;
import javax.swing.border.*;
import javax.swing.event.*;
import org.trinet.util.*;
import org.trinet.jasi.Waveform;
/**
* This is a panel that supports zooming and scrolling interface functions. The
* waveform is displayed in a ZoomableWFPanel in a BombSightViewport in a
* JScrollPane. There is also a button panel with scaling buttons and a label
* panel with channel and status info. This component does not support phase
* picking. The PickingPanel class extends this class for that purpose. <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>
/*
The ZoomPanel contains several other nested graphical components:
ZoomPanel
labelBox (JPanel)
scrollZoom (JScrollPane)
vport (BombSightViewport)
wfp (ZoomableWFPanel)
buttonPanel (JPanel)
*/
public class ZoomPanel extends JPanel {
JLabel staLabel;
public int width;
public int height;
public int UsableHeight;
public int UsableWidth;
public int BorderLeft;
public int BorderRight;
public int BorderTop;
public int BorderBottom;
Color WFColor = Color.blue;
Color TextColor = Color.black;
Color BackgroundColor = Color.white;
Color BombSightColor = Color.gray;
/** The ZoomableWFPanel that shows through the viewport. */
public ZoomableWFPanel zwfp;
TimeColumnHeader timeColumnHeader;
/** The master view of what's in the GUI */
public MasterView mv;
/** This extends JViewport and overrides its paint method to draw a
bombsight for picking. */
BombSightViewport vport = new BombSightViewport(BombSightColor) ;
JScrollPane scrollZoom;
/** Model of MVC for cursorLocLabel */
CursorLocModel cursorLocModel = new CursorLocModel();
CursorLocPanel cursorPanel = new CursorLocPanel(cursorLocModel);
/** Lable for channel and status info */
JPanel labelBox = new JPanel(); //top panel with sta label and cursor info
// event handling stuff
private Object objSelected; // the menu, list or button item selected
private String EventName; // String label of the event (e.g. "Exit")
private String ItemName;
/** If true, allow ZoomPanel scroll bars to scroll the window */
protected boolean scrollable = true;
protected boolean filterEnabled = false;
/** Format for distance in channel label: "####0.0"*/
DecimalFormat df = new DecimalFormat("####0.0");
DecimalFormat di = new DecimalFormat("#######0");
DecimalFormat dsci = new DecimalFormat("0.##E0");
/** Handles async. loading of waveforms */
ActiveWFLoadListener activeWFLoadListener = new ActiveWFLoadListener();
/** Debug verbosity flag */
// boolean debug = true;
boolean debug = false;
ImageIcon filterIcon = null;
ImageIcon unfilterIcon = null;
JToggleButton filterButton;
//-----------------------------------------------------------------
public ZoomPanel () { //constructor
}
/*
* Create a ZoomPanel based on information in this MasterView. This is only
* needed to support the red up/down buttons. They need the WFViewList in
* the master view to know the previous/next WFView. */
public ZoomPanel (MasterView masterView) { //constructor
mv = masterView;
buildPanel();
}
/** Builds the whole panel. */
protected void buildPanel() {
// listener updates the channel label when the selected WFView changes.
//NOTE: must be added BEFORE makeScrollZoom() makes the ZoomableWFPanel
// so it will be called AFTER ZoomableWFPanel reacts to WFViewModel changes
// (listeners are called in the opposite order they are added)
mv.masterWFViewModel.addChangeListener(new WFViewListener());
// icons
try {
filterIcon =
new ImageIcon(IconImage.getImage("filter16.gif"));
unfilterIcon =
new ImageIcon(IconImage.getImage("unfilter16.gif"));
} catch (Exception ex) {
System.out.println ("ZoomPanel could not find icon image files.");
}
setOpaque(true);
setLayout( new BorderLayout() );
// create the "North" main label
labelBox = makeInfoBar();
add("North", labelBox); // add it to the ZoomPanel
add("Center", makeScrollZoom());
// <> create the button panel
add("South", makeButtonPanel()); // add it to the ZoomPanel
// arrows to move to next/previous time-series
//add("West", makeArrowPanel());
add("East", makeArrowPanel());
//addKeyboardActions ();
// this.addKeyListener(new KeyHandler());
} // end of builder
public boolean isFocusTraversable() { return true;}
/** Arrow keys were not used because they are used to shift focus between components.
* (And because I couldn't get them to work.) */
/* public void addKeyboardActions () {
// final int RIGHTKEY = KeyEvent.VK_RIGHT;
// final int LEFTKEY = KeyEvent.VK_LEFT;
// final int RIGHTKEY = KeyEvent.VK_KP_RIGHT;
// final int LEFTKEY = KeyEvent.VK_KP_LEFT;
final int RIGHTKEY = KeyEvent.VK_PERIOD;
final int LEFTKEY = KeyEvent.VK_COMMA;
// < KEY
this.registerKeyboardAction(
new ActionListener (){
public void actionPerformed (ActionEvent e) {
JScrollBar bar = scrollZoom.getHorizontalScrollBar();
int inc = zwfp.getScrollableUnitIncrement(vport.getViewRect(),
bar.getOrientation(), SwingConstants.LEFT);
int val = Math.max(bar.getMinimum(), bar.getValue() - inc);
bar.setValue(val);
}
},
KeyStroke.getKeyStroke(LEFTKEY, 0, false),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
// shift-<
this.registerKeyboardAction(
new ActionListener (){
public void actionPerformed (ActionEvent e) {
JScrollBar bar = scrollZoom.getHorizontalScrollBar();
int inc = zwfp.getScrollableBlockIncrement(vport.getViewRect(),
bar.getOrientation(), SwingConstants.LEFT);
int val = Math.max(bar.getMinimum(), bar.getValue() - inc);
bar.setValue(val);
}
},
KeyStroke.getKeyStroke(LEFTKEY, InputEvent.SHIFT_MASK, false),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
// > KEY
// left arrow
this.registerKeyboardAction(
new ActionListener (){
public void actionPerformed (ActionEvent e) {
JScrollBar bar = scrollZoom.getHorizontalScrollBar();
int inc = zwfp.getScrollableUnitIncrement(vport.getViewRect(),
bar.getOrientation(), SwingConstants.RIGHT);
int val = Math.min(bar.getMaximum(), bar.getValue() + inc);
bar.setValue(val);
}
},
KeyStroke.getKeyStroke(RIGHTKEY, 0, false),
JComponent.WHEN_IN_FOCUSED_WINDOW);
// shift->
this.registerKeyboardAction(
new ActionListener (){
public void actionPerformed (ActionEvent e) {
JScrollBar bar = scrollZoom.getHorizontalScrollBar();
int inc = zwfp.getScrollableBlockIncrement(vport.getViewRect(),
bar.getOrientation(), SwingConstants.RIGHT);
int val = Math.min(bar.getMaximum(), bar.getValue() + inc);
bar.setValue(val);
}
},
KeyStroke.getKeyStroke(RIGHTKEY, InputEvent.SHIFT_MASK, false),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
*/
/** Construct the JScrollPane and the underlying ZoomableWFPanel that will
show through the viewport. */
// This is split into two steps to allow customizing by extending classes
protected JScrollPane makeScrollZoom () {
zwfp = new ZoomableWFPanel (makeScrollZoom1(), mv);
return setupZoomableWFPanel();
}
/**
* First part of making the JScrollPane.
*/
protected JScrollPane makeScrollZoom1 () {
// <> create the ScrollPane
scrollZoom = new JScrollPane(
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
// Replace the default viewport of the scrollPane with ours
scrollZoom.setViewport(vport);
// deprecated in v1.3
//vport.setBackingStoreEnabled(true); // speeds scrolling
// put filter button in lower right corner of the scroll panel
filterButton = new JToggleButton(filterIcon);
filterButton.setPressedIcon(unfilterIcon);
filterButton.setToolTipText("Toggle filter on/off");
filterButton.addActionListener(new FilterButtonHandler());
filterButton.setEnabled(getFilterEnabled());
scrollZoom.add(filterButton, ScrollPaneConstants.LOWER_RIGHT_CORNER);
return scrollZoom;
}
// Set characteristics of the ZoomableWFPanel
// THIS MUST BE DONE AFTER THE 'ScrollZoom.setViewport(vport)' ABOVE
////zwfp = new ZoomableWFPanel (scrollZoom, mv);
protected JScrollPane setupZoomableWFPanel() {
zwfp.setCursorLocModel(cursorLocModel);
// set the default filter
zwfp.setFilter(new GeneralButterworthFilter(GeneralButterworthFilter.HIGHPASS, true));
zwfp.setJScrollPane(scrollZoom);
// set scrolling time scale in column header
timeColumnHeader = new TimeColumnHeader(zwfp) ;
scrollZoom.setColumnHeaderView(timeColumnHeader);
// ** Had turned this off because of recursion problem with scroller
if (scrollable) { // control some of the scroll pane's behavior
// set scrolling increments
JScrollBar vBar = scrollZoom.getVerticalScrollBar();
JScrollBar hBar = scrollZoom.getHorizontalScrollBar();
// Add adjustment listener to both
// if (true) {
vBar.addAdjustmentListener(new VerticalScrollListener());
hBar.addAdjustmentListener(new HorizontalScrollListener());
/* } else {
ScrollListener scrollListener = new ScrollListener();
vBar.addAdjustmentListener(scrollListener);
hBar.addAdjustmentListener(scrollListener);
}
*/
}
return scrollZoom;
}
/**
* Make the panel with the up/down buttons for selecting next/prevous
* WFPanel.
*/
protected Box makeArrowPanel () {
JButton btn;
Box box = Box.createVerticalBox();
box.add(Box.createGlue());
Image image = IconImage.getImage("RedUp3.gif");
// arrow
if (image == null) { // handle situation when .gif file can't be found
btn = new JButton("^");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.TOP) );
btn.setToolTipText("Select top waveform");
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(btn);
box.add(Box.createVerticalStrut(5));
// arrow
image = IconImage.getImage("RedUp2.gif");
if (image == null) {
btn = new JButton("^");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.PAGEUP) );
btn.setToolTipText("Jump up a page");
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(btn);
box.add(Box.createVerticalStrut(5));
// arrow
image = IconImage.getImage("RedUp.gif");
if (image == null) {
btn = new JButton("^");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.UP) );
btn.setToolTipText("Select previous waveform");
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(btn);
box.add(Box.createVerticalStrut(5));
// arrow
image = IconImage.getImage("RedDown.gif");
if (image == null) {
btn = new JButton("v");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.DOWN) );
btn.setToolTipText("Select next waveform");
box.add(btn);
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(Box.createVerticalStrut(5));
// arrow
image = IconImage.getImage("RedDown2.gif");
if (image == null) {
btn = new JButton("v");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.PAGEDOWN) );
btn.setToolTipText("Jump down a page");
box.add(btn);
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(Box.createVerticalStrut(5));
// arrow
image = IconImage.getImage("RedDown3.gif");
if (image == null) {
btn = new JButton("v");
} else {
btn = new JButton(new ImageIcon(image));
}
btn.addActionListener (new ButtonHandler(ButtonHandler.BOTTOM) );
btn.setToolTipText("Select bottom waveform");
box.add(btn);
btn.setMargin(new Insets(0, 0, 0, 0));
box.add(Box.createGlue());
return box;
}
/**
* Define motion buttons. Can't do in ButtonHandler because you only do
* statics in top level classes.
*/
interface MotionButtons {
static final int TOP = 0;
static final int UP = 1;
static final int PAGEUP = 2;
static final int CENTER = 3;
static final int PAGEDOWN = 4;
static final int DOWN = 5;
static final int BOTTOM = 6;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -