001: package salomeTMF_plug.abbotScriptRunner;
002:
003: import java.awt.BorderLayout;
004: import java.awt.FlowLayout;
005: import java.awt.Frame;
006: import java.awt.GridLayout;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.awt.event.ItemEvent;
010: import java.awt.event.ItemListener;
011: import java.awt.event.WindowAdapter;
012: import java.awt.event.WindowEvent;
013:
014: import javax.swing.JButton;
015: import javax.swing.JCheckBox;
016: import javax.swing.JDialog;
017: import javax.swing.JOptionPane;
018: import javax.swing.JPanel;
019:
020: public class SetUpDialog extends JDialog implements ItemListener,
021: ActionListener {
022: private String btnOk = "OK";
023: private String btnCancel = "Cancel";
024: private JOptionPane optionPane;
025:
026: JCheckBox pSlowPlaybacCheckbox;
027: JCheckBox pStopOnFailureCheckbox;
028: JCheckBox pStopOnErrorCheckbox;
029: JCheckBox pForkedCheckbox;
030:
031: boolean isSlowPlayback;
032: boolean isStopOnFailure;
033: boolean isStopOnError;
034: boolean isForked;
035:
036: JPanel contentPan;
037: JPanel buttonPan;
038: JPanel checkPan;
039:
040: String result;
041:
042: JButton okButton;
043: JButton cancelButton;
044:
045: SetUpDialog(Frame pFrame, boolean _isSlowPlayback,
046: boolean _isStopOnFailure, boolean _isStopOnError,
047: boolean _isForked) {
048: super (pFrame, "Setup Aboot Script Runner");
049: setModal(true);
050: setResizable(false);
051:
052: okButton = new JButton(btnOk);
053: cancelButton = new JButton(btnCancel);
054: okButton.addActionListener(this );
055: cancelButton.addActionListener(this );
056:
057: buttonPan = new JPanel(new FlowLayout());
058: buttonPan.add(okButton);
059: buttonPan.add(cancelButton);
060:
061: this .isSlowPlayback = _isSlowPlayback;
062: this .isStopOnFailure = _isStopOnFailure;
063: this .isStopOnError = _isStopOnError;
064: this .isForked = _isForked;
065:
066: pSlowPlaybacCheckbox = new JCheckBox("Slow Playback",
067: isSlowPlayback);
068: pStopOnFailureCheckbox = new JCheckBox("Stop on faillure",
069: isStopOnFailure);
070: pStopOnErrorCheckbox = new JCheckBox("Stop on error",
071: isStopOnError);
072: pForkedCheckbox = new JCheckBox("Fork new JVM", isForked);
073:
074: pSlowPlaybacCheckbox.addItemListener(this );
075: pStopOnFailureCheckbox.addItemListener(this );
076: pStopOnErrorCheckbox.addItemListener(this );
077: pForkedCheckbox.addItemListener(this );
078:
079: checkPan = new JPanel(new GridLayout(0, 1));
080: checkPan.add(pStopOnFailureCheckbox);
081: checkPan.add(pStopOnErrorCheckbox);
082: checkPan.add(pSlowPlaybacCheckbox);
083: checkPan.add(pForkedCheckbox);
084:
085: // Handle window closing correctly.
086: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
087: addWindowListener(new WindowAdapter() {
088: public void windowClosing(WindowEvent we) {
089: result = null;
090: clearAndHide();
091: }
092: });
093:
094: contentPan = new JPanel(new BorderLayout());
095: contentPan.add(checkPan, BorderLayout.CENTER);
096: contentPan.add(buttonPan, BorderLayout.SOUTH);
097:
098: setContentPane(contentPan);
099: //optionPane.addPropertyChangeListener(this);
100: //this.setLocation(300,200);
101: this .setLocationRelativeTo(this .getParent());
102: pack();
103:
104: }
105:
106: public void itemStateChanged(ItemEvent e) {
107: boolean value = true;
108: Object source = e.getItemSelectable();
109: if (e.getStateChange() == ItemEvent.DESELECTED) {
110: value = false;
111: }
112: if (source == pSlowPlaybacCheckbox) {
113: isSlowPlayback = value;
114: } else if (source == pStopOnFailureCheckbox) {
115: isStopOnFailure = value;
116: } else if (source == pStopOnErrorCheckbox) {
117: isStopOnError = value;
118: } else if (source == pForkedCheckbox) {
119: isForked = value;
120: }
121: }
122:
123: public void actionPerformed(ActionEvent e) {
124: if (e.getSource().equals(okButton)) {
125: makeResult();
126: clearAndHide();
127: } else if (e.getSource().equals(cancelButton)) {
128: result = null;
129: clearAndHide();
130: }
131:
132: }
133:
134: void makeResult() {
135: result = abbotScriptPlugin.EXIT_ON_FAILLURE + "="
136: + isStopOnError + "," + abbotScriptPlugin.EXIT_ON_ERROR
137: + "=" + isStopOnError + ","
138: + abbotScriptPlugin.SLOW_PLAYBACK + "="
139: + isSlowPlayback + "," + abbotScriptPlugin.FORKED + "="
140: + isForked;
141: }
142:
143: /** This method clears the dialog and hides it. */
144: public void clearAndHide() {
145: //textField.setText(null);
146: setVisible(false);
147: }
148:
149: public String getValue() {
150: return result;
151: }
152: }
|