00001 package GuiComponents.SctApi;
00002
00003 import java.awt.BorderLayout;
00004
00005 import java.awt.Window;
00006 import java.awt.event.ActionEvent;
00007 import java.awt.event.ActionListener;
00008 import java.awt.event.WindowAdapter;
00009 import java.awt.event.WindowEvent;
00010
00011 import javax.swing.JButton;
00012 import javax.swing.JFrame;
00013 import javax.swing.JList;
00014 import javax.swing.JPanel;
00015 import javax.swing.JScrollPane;
00016
00017 public class ScanList extends JPanel {
00018 JList theList;
00019 Sct_SctApi.SctApiIPC api;
00020 Sct_SctApi.Scan[] scans;
00021
00022 public ScanList(Sct_SctApi.SctApiIPC a, Sct_SctApi.Scan[] s) {
00023 api = a; scans = s;
00024
00025 buildGui();
00026 }
00027
00028 void buildGui() {
00029 setLayout(new BorderLayout());
00030
00031 System.out.println("Found " + scans.length + " scans");
00032
00033 Object [] myScans = new Object[scans.length];
00034
00035 for(int si=0; si < scans.length; si++) {
00036 Sct_SctApi.Scan thisScan = scans[si];
00037
00038 if(thisScan != null) {
00039 System.out.println(thisScan.print());
00040
00041 myScans[si] = "" + si;
00042 }
00043 }
00044
00045 theList = new JList(myScans);
00046 add(new JScrollPane(theList));
00047
00048 JPanel buttonPanel = new JPanel();
00049
00050 JButton openButton = new JButton("Open scan");
00051
00052 openButton.addActionListener(new ActionListener() {
00053 public void actionPerformed(ActionEvent e) {
00054 int index = theList.getSelectedIndex();
00055
00056 if(index < 0) return;
00057
00058 JFrame frame = new JFrame("Scan View");
00059 frame.getContentPane().add(new ScanView(api, scans[index]));
00060
00061 frame.addWindowListener(new WindowAdapter() {
00062 public void windowClosing(WindowEvent e) {
00063 e.getWindow().dispose();
00064 }
00065 });
00066 frame.pack();
00067 frame.setVisible(true);
00068
00069 ((Window)getTopLevelAncestor()).dispose();
00070 }
00071 });
00072
00073 buttonPanel.add(openButton);
00074
00075 JButton newScan = new JButton("New scan");
00076 newScan.addActionListener(new ActionListener() {
00077 public void actionPerformed(ActionEvent e) {
00078 Sct_SctApi.Scan scan = api.createScan();
00079
00080 scan.configure((short)1, 0.0, 100.0, 10.0);
00081
00082 scan.setNTrigs(1000);
00083
00084 scan.getTrigger1().singleL1A();
00085
00086 JFrame frame = new JFrame("Scan View");
00087 frame.getContentPane().add(new ScanView(api, scan));
00088
00089 frame.pack();
00090 frame.setVisible(true);
00091 ((Window)getTopLevelAncestor()).dispose();
00092 }
00093 });
00094 buttonPanel.add(newScan);
00095
00096 add(buttonPanel, BorderLayout.SOUTH);
00097 }
00098 }