/******************************************************************************
 JXPlotLabelDialog.cc

	BASE CLASS = JXDialogDirector

	Written by John Lindal.

 ******************************************************************************/

#include "JXPlotLabelDialog.h"

#include <JXFontNameMenu.h>
#include <JXFontSizeMenu.h>
#include <JXWindow.h>
#include <JXTextButton.h>
#include <JXInputField.h>
#include <JXStaticText.h>

#include <JString.h>

#include <jAssert.h>

/******************************************************************************
 Constructor

 ******************************************************************************/

JXPlotLabelDialog::JXPlotLabelDialog
	(
	JXWindowDirector* 	supervisor, 
	const JString& 		title,
	const JString& 		xLabel, 
	const JString& 		yLabel,
	const JString& 		font, 
	const JSize 		size,
	const J2DPlotWidget::LabelSelection selection
	)
	:
	JXDialogDirector(supervisor, kTrue),
	itsSelection(selection)
{
	BuildWindow();
	itsPlotTitle->SetText(title);
	itsXAxisLabel->SetText(xLabel);
	itsYAxisLabel->SetText(yLabel);

	itsFontMenu->SetFontName(font);
	itsSizeMenu->SetFontSize(size);
}

/******************************************************************************
 Destructor

 ******************************************************************************/

JXPlotLabelDialog::~JXPlotLabelDialog()
{
}

/******************************************************************************
 BuildWindow (private)

 ******************************************************************************/

void
JXPlotLabelDialog::BuildWindow()
{
// begin JXLayout

    JXWindow* window = new JXWindow(this, 540,140, "");
    assert( window != NULL );
    SetWindow(window);

    itsPlotTitle =
        new JXInputField(window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 130,10, 220,20);
    assert( itsPlotTitle != NULL );

    itsXAxisLabel =
        new JXInputField(window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 130,40, 220,20);
    assert( itsXAxisLabel != NULL );

    itsYAxisLabel =
        new JXInputField(window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 130,70, 220,20);
    assert( itsYAxisLabel != NULL );

    JXStaticText* obj1 =
        new JXStaticText("Plot Title:", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 10,13, 120,20);
    assert( obj1 != NULL );

    JXStaticText* obj2 =
        new JXStaticText("X Axis Label:", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 10,43, 120,20);
    assert( obj2 != NULL );

    JXStaticText* obj3 =
        new JXStaticText("Y Axis Label:", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 10,73, 120,20);
    assert( obj3 != NULL );

    JXTextButton* okButton =
        new JXTextButton("OK", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 320,110, 70,20);
    assert( okButton != NULL );
    okButton->SetShortcuts("^M");

    JXTextButton* cancelButton =
        new JXTextButton("Cancel", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 150,110, 70,20);
    assert( cancelButton != NULL );

    itsFontMenu =
        JXFontNameMenu::Create("Font", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 370,10, 150,30);
    assert( itsFontMenu != NULL );

    itsSizeMenu =
        JXFontSizeMenu::Create(itsFontMenu, "Size", window,
                    JXWidget::kHElastic, JXWidget::kVElastic, 370,50, 150,30);
    assert( itsSizeMenu != NULL );

// end JXLayout

	window->SetTitle("Edit Plot Labels");
	SetButtons(okButton, cancelButton);

	itsFontMenu->SetToPopupChoice();
	itsSizeMenu->SetToPopupChoice();
}

/******************************************************************************
 GetLabels 

 ******************************************************************************/

void
JXPlotLabelDialog::GetLabels
	(
	JString* title, 
	JString* xLabel, 
	JString* yLabel
	)
	const
{
	*title = itsPlotTitle->GetText();
	*xLabel = itsXAxisLabel->GetText();
	*yLabel = itsYAxisLabel->GetText();
}

/******************************************************************************
 GetFontName

 ******************************************************************************/

const JString&
JXPlotLabelDialog::GetFontName()
	const
{
	return itsFontMenu->GetFontName();
}

/******************************************************************************
 GetFontSize

 ******************************************************************************/

JSize
JXPlotLabelDialog::GetFontSize()
	const
{
	return itsSizeMenu->GetFontSize();
}

/******************************************************************************


 ******************************************************************************/

void
JXPlotLabelDialog::Activate()
{
	JXDialogDirector::Activate();
	if (itsSelection == J2DPlotWidget::kTitle)
		{
		itsPlotTitle->Focus();
		}
	else if (itsSelection == J2DPlotWidget::kXLabel)
		{
		itsXAxisLabel->Focus();
		}
	else if (itsSelection == J2DPlotWidget::kYLabel)
		{
		itsYAxisLabel->Focus();
		}
}
