1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
package ThePEG;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class RunSelector extends JDialog
implements MouseListener,
ActionListener {
Object selectedRun;
boolean done = false;
JList runList = new JList();
JButton cancelButton = new JButton("Cancel");
JButton okButton = new JButton("Select");
SetupThePEG thepeg;
public RunSelector(SetupThePEG thepeg) {
super(thepeg, "Choose a run", true);
this.thepeg = thepeg;
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
LinkedList ret = thepeg.exec("lsruns");
Vector runs = new Vector();
while ( ret.size() > 0 ) runs.add(thepeg.getRun((String)ret.removeFirst()));
runs.add("Create a new run");
runList.setListData(runs);
runList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
runList.addMouseListener(this);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JScrollPane(runList), BorderLayout.CENTER);
JPanel panel = new JPanel();
cancelButton.addActionListener(this);
okButton.addActionListener(this);
panel.add(cancelButton);
panel.add(okButton);
getContentPane().add(panel, BorderLayout.SOUTH);
setSize(300,300);
thepeg.setLocation(this);
setVisible(true);
}
public Object selected() {
if ( selectedRun == null || !done ) return null;
return selectedRun;
}
public void actionPerformed(ActionEvent e) {
if ( e.getSource() == cancelButton ) {
selectedRun = null;
dispose();
}
if ( e.getSource() == okButton ) {
if ( selectedRun != null ) {
done = true;
dispose();
} else if ( runList.getSelectedValue() != null ) {
selectedRun = runList.getSelectedValue();
done = true;
dispose();
}
}
}
public void mouseClicked(MouseEvent e) {
if ( e.getSource() == runList && e.getClickCount() >= 2 ) {
selectedRun = runList.getSelectedValue();
done = true;
dispose();
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void dispose() {
thepeg.removeLocation(this);
super.dispose();
}
public static void classcheck() {}
}
|