// @topic T11707 Swing demo A10 -- GUI window with radio buttons, menus, and dialogs
// @brief class DialogViewOptions extends JDialog implements ActionListener, PanelWithTabs
/**
 * @author ik
 */

package pckg;

import javax.swing.*;
import java.beans.*; //property change stuff
import java.awt.*;
import java.awt.event.*;

/**
* The custom dialog box
*/
class DialogViewOptions
    extends JDialog
    implements ActionListener
{
    FrameRadioButtons mFrameRadioButtons;
    JFrame mFrame;
    PanelWithTabs tabbedPanel;
    boolean mResult = false;

    /** Creates custom dialog. */
    //DEBUG//public DialogViewOptions(FrameRadioButtons aFrame)
    public DialogViewOptions(JFrame aFrame, FrameRadioButtons aFrameRadioButtons)
    {
        super(aFrame, true);
        mFrame = aFrame;
        mFrameRadioButtons = aFrameRadioButtons;

        //Create and set up the content pane.
        tabbedPanel = new PanelWithTabs(aFrame, this);
        tabbedPanel.setOpaque(true); //content panes must be opaque

        // Set the content pane, which has all GUI components of our dialog
        aFrame.setContentPane(tabbedPanel);

        aFrame.setTitle("Dialog View Options Title");

        //Handle window closing correctly.
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    }//constructor DialogViewOptions

    /** This method handles events for dialog UI components. */
    public void actionPerformed(ActionEvent event)
    {
        Object obj = event.getSource();
        if (obj == tabbedPanel.mButOK)
        {
            // OK
            mResult = true;
            mFrameRadioButtons.setBottomLabelText("[OK] " + getText());
        }
        else if (obj == tabbedPanel.mButCancel)
        {
            // Cancel
            mResult = false;
            mFrameRadioButtons.setBottomLabelText("[Cancel]");
        }
        mFrame.setVisible(false); // either button hides the dialog
    }// method actionPerformed

    /** Gets the text displayed by the text field. */
    public String getText()
    {
        return tabbedPanel.getText();
    }

    /** Sets the text of the text field. */
    public void setText(String aText)
    {
        tabbedPanel.setText(aText);
    }//void setText

    /** Gets the result. */
    public boolean getResult()
    {
        return mResult;
    }
}//class DialogViewOptions