
package org.openspml.browser;

import java.util.ArrayList;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import javax.swing.*;
import javax.swing.event.*;

/**
 * A panel combining a request id text box with an async mode checkbox.
 * Needed by most request submission panels.
 */
public class RequestIdPanel extends JPanel implements ActionListener {

    JTextField _id;
    LabeledCheckbox _async;
    ActionListener _listener;

    public RequestIdPanel() {

	setLayout(new LinearLayout(0));
	
        _id = new JTextField(25);
        _id.addActionListener(this);
        add(_id);

        _async = new LabeledCheckbox("Asynchronous");
        _async.addActionListener(this);
        add(_async);
    }

    public void addActionListener(ActionListener l) {
	_listener = l;
    }

    public void actionPerformed(ActionEvent e) {
        // mutate it into an event on ourslves
        // actually it doesn't really matter at the moment,
        // any event will cause the parent panels to regen the XML
        if (_listener != null) {
            e = new ActionEvent(this, 0, null);
            _listener.actionPerformed(e);
        }
    }

    public String getRequestId() {
        return SwingUtil.getText(_id);
    }

    public boolean isAsync() {
	return _async.isSelected();
    }

}
