📄 selectablereadinglist.java
字号:
Channel selChan = mv.masterWFViewModel.get().getChannel();
int newIndex = visibleList.getIndexOf(selChan);
// if no match in list this keeps the "pointer" at the same position in the list when
// an item is deleted
if (newIndex > -1) {
index = newIndex;
} else {
index = oldIndex;
}
// just redo the list if ANYTHING changed in the readingList
setReadingList(readingList); // redo the whole thing
if (hasFocus()) {
// if you deleted the last thing in the list move up one
int maxIndex = jlist.getModel().getSize()-1;
if (index > maxIndex) index = maxIndex;
System.out.println ("JasiReadingListListener.stateChanged hasFocus() idx = "+index);
// NOTE: this fires an SelectionListenerEvent
jlist.setSelectedIndex(index);
}
// System.out.println ("JasiReadingListListener: "+index +"\n"+evt.toString());
}
*/
} // end of JasiReadingListListener
////////////////////////////////////////////////////////////////////////////////////
class SelectionListener implements ListSelectionListener {
/* The real work is done as a Runnable to guarantee that, even if called from another
thread, the selection action happens in the
Event-Dispatch thread, and does not cause thread dead-locks. */
Runnable runnable;
Channel chan;
double centerTime;
WFViewList wfvList;
// /////////////////////////////////////////////////////////////////////////////////
public SelectionListener() {
super();
// insure this happens in event-dispatch thread because it
// fires events that do graphics updates
runnable = new Runnable() {
public void run() {
WFView wfv = wfvList.get(chan);
if (wfv != null) {
// select this WFView
mv.masterWFViewModel.set(wfv);
mv.masterWFWindowModel.setFullAmp(); // set amp scale to full scale
mv.masterWFWindowModel.setCenterTime(centerTime);
}
}
};
}
/** React to a JList selection. */
public void valueChanged( ListSelectionEvent evt) {
// System.out.println("SelectionListener: "+ evt.toString());
if (evt.getValueIsAdjusting()) return; // don't react until mouseReleased
JList list = (JList) evt.getSource();
JasiReading jreading = (JasiReading) list.getSelectedValue();
if ((jreading != null)) {
chan = jreading.getChannelObj();
centerTime = jreading.getDateTime().getEpochSeconds();
wfvList = mv.wfvList;
// insure this happens in event-dispatch thread because it
// fires events that do graphics updates
// if (list.hasFocus())
SwingUtilities.invokeLater(runnable);
}
}
} // end of SelectionListener
////////////////////////////////////////////////////////////////////////////////////
/** React to change in selected WFView from outside. Highlight the reading if
* there is one. */
/*
class WFViewModelChangeListener implements ChangeListener {
public void valueChanged( ListSelectionEvent evt) {
}
}
*/
/** Make a renderer to make "bad" amp red. */
class SelectableListCellRenderer extends JLabel implements ListCellRenderer {
private Border lineBorder = BorderFactory.createLineBorder(Color.blue, 1);
private Border emptyBorder = BorderFactory.createEmptyBorder(1,1,1,1);
double redThreshold = 0.5;
double yellowThreshold = 0.25;
Color goodColor = Color.black;
Color warnColor = ColorList.burntOrange; // standard orange is too light
Color badColor = Color.red;
Color notUsedColor = Color.blue;
/** Set the values of the warning levels. */
public void setThresholds(double yellowValue, double redValue) {
redThreshold = redValue;
yellowThreshold = yellowValue;
}
/** Set the colors of the different warning levels. */
public void setColors (Color good, Color warn, Color bad, Color notUsed) {
goodColor = good;
warnColor = warn;
badColor = bad;
notUsedColor = notUsed;
}
/** Render the component */
public Component getListCellRendererComponent
(JList list, Object obj, int index, boolean isSelected, boolean hasFocus) {
if (!(obj instanceof JasiReading)) {
setText("No Data...");
return this;
}
JasiReading jreading = (JasiReading) obj;
setText(jreading.toNeatString());
setFont(list.getFont());
// Every JasiReading can return a "warning level" from 0.0 - 1.0
// indicating its "goodness"
if (!jreading.wasUsed()) {
setForeground(notUsedColor);
} else if (jreading.getWarningLevel() > redThreshold) {
setForeground(badColor);
} else if (jreading.getWarningLevel() > yellowThreshold) {
setForeground(warnColor);
} else {
setForeground(goodColor);
}
// highlight selected row
// setBackground DOES NOT WORK!
if (isSelected) {
// setBackground (list.getSelectionBackground());
setBackground (selectedBackgroundColor);
// setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
// setForeground(isSelected ? Color.white : Color.black);
// if (hasFocus) {
setBorder(lineBorder);
} else {
setBorder(emptyBorder);
// } else {
// setBackground (list.getBackground());
}
return this;
}
}
/** Create the popup menu that is activated by a right mouse click */
public void makePopup (Point point) {
PopupListener popupListener = new PopupListener();
JMenuItem mi;
JMenu submenu;
JPopupMenu popup = new JPopupMenu();
mi = popup.add(new JMenuItem("Delete"));
mi.addActionListener(popupListener);
mi = popup.add(new JMenuItem("Strip more distance"));
mi.addActionListener(popupListener);
// mi = popup.add(new JMenuItem("Zero-weight"));
// mi.addActionListener(popupListener);
if (recalcListener != null) {
popup.addSeparator();
mi = popup.add(new JMenuItem("RECALC"));
mi.addActionListener(popupListener);
}
popup.addSeparator();
mi = popup.add(new JMenuItem("Close Popup"));
mi.addActionListener(popupListener);
popup.show (this, point.x, point.y);
}
// Inner class to handle popup menu events
public class PopupListener implements ActionListener {
public void actionPerformed (ActionEvent evt) {
JComponent src = (JComponent) evt.getSource(); //the popup menu
String action = evt.getActionCommand();
int index = jlist.getSelectedIndex();
if (index > -1) {
if (action.equals("Delete")) {
// delete via the list to kick any listeners, including US!
// readingList.delete(jlist.getSelectedValue());
deleteCurrentReading();
// } else if (action == "Zero-weight") {
} else if (action.equals("RECALC")) {
recalcListener.actionPerformed(new ActionEvent(this, 0, "Recalc"));
} else if (action.equals("Strip more distant")) {
JasiReading jreading = getSelectedReading();
if (jreading == null) return;
double cutoff = jreading.getDistance();
if (type == Phases) {
mv.stripPhasesByDistance(cutoff, mv.getSelectedSolution());
} else if (type == Amps) {
mv.stripAmpsByDistance(cutoff, mv.getSelectedSolution());
} else if (type == Codas) {
mv.stripCodasByDistance(cutoff, mv.getSelectedSolution());
}
} else if (action == "Close Popup") {
// noop
}
}
}
}
// //////////////////////////////////////////////////////////////////////////////
public static void main(String args[]){
JFrame frame = new JFrame("Main");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
int evid;
if (args.length <= 0) {
System.out.println ("Usage: java this-thing [evid])");
evid = 9635181;
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();
}
BenchMark bm = new BenchMark();
System.out.println ("Making connection...");
DataSource init = new TestDataSource(); // make connection
init.setWriteBackEnabled(true);
/*
System.out.println ("Reading master channel list...");
MasterChannelList.set(ChannelList.readCurrentList());
*/
System.out.println ("Getting data for evid = "+evid);
MasterView mv = new MasterView();
//org.trinet.jiggle.MasterView mv = new org.trinet.jiggle.MasterView();
//mv.setWaveFormLoadMode(mv.LoadNone);
mv.setWaveFormLoadMode(mv.Cache);
mv.setCacheSize(50, 50);
mv.setLoadChannelData(true);
mv.setAlignmentMode(MasterView.AlignOnTime);
mv.defineByDataSource(evid);
Solution sol = mv.solList.getSelected();
mv.distanceSort(sol);
System.out.println ("Number of phases = "+sol.getPhaseList().size());
bm.print("BenchMark: event parameters loaded ");
bm.reset();
final WFScroller wfScroller = new WFScroller(mv, true) ; // make scroller
//final WFScroller wfScroller = new WFScroller(mv, false) ; // make scroller
mv.masterWFViewModel.selectFirst(mv.wfvList);
// make an empth Zoomable panel
ZoomPanel zpanel = new ZoomPanel(mv);
wfScroller.setMinimumSize(new Dimension(300, 100) );
// make a split pane with the zpanel and wfScroller
JSplitPane split =
new JSplitPane(JSplitPane.VERTICAL_SPLIT,
false, // don't repaint until resizing is done
zpanel, // top component
wfScroller); // bottom component
//frame.getContentPane().add(list);
SelectableReadingList plist = new SelectableReadingList(mv, sol, sol.phaseList);
SelectableReadingList alist = new SelectableReadingList(mv, sol, sol.ampList);
SelectableReadingList clist = new SelectableReadingList(mv, sol, sol.codaList);
JTabbedPane tabPane = new JTabbedPane();
tabPane.addTab("Phases", plist);
tabPane.addTab("Amplitudes", alist);
tabPane.addTab("Codas", clist);
// frame.getContentPane().add(wfScroller, BorderLayout.CENTER);
frame.getContentPane().add(split, BorderLayout.CENTER);
frame.getContentPane().add(tabPane, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -