void
GLFitDirector::BuildWindow()
{
	JCoordinate w = 600;
	JCoordinate h = 420;
	JXWindow* window = new JXWindow(this, w,h, "Fit");
    assert( window != NULL );
	window->SetCloseAction(JXWindow::kDeactivateDirector);
    
	JXMenuBar* menuBar =
		new JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 
			0,0, w,kJXDefaultMenuBarHeight);
	assert( menuBar != NULL );

	itsToolBar =
		new JXToolBar(GetPrefsMgr(), kFitToolBarID,
			menuBar, w, h,
			window, JXWidget::kHElastic, JXWidget::kVElastic, 
			0,kJXDefaultMenuBarHeight, w,h - kJXDefaultMenuBarHeight);
	assert( itsToolBar != NULL );

	JSize newHeight = itsToolBar->GetWidgetEnclosure()->GetBoundsHeight();

	const JCoordinate kPartitionHandleWidth	= 5;
	const JCoordinate kFitListWidth			= 155;

	JArray<JCoordinate> widths(2);
	widths.AppendElement(kFitListWidth);
	widths.AppendElement(w - kFitListWidth - kPartitionHandleWidth);

	JIndex elasticIndex = 2;

	JArray<JCoordinate> minWidths(2);
	minWidths.AppendElement(100);
	minWidths.AppendElement(300);

	itsMainPartition =
		new JXHorizPartition(widths, elasticIndex, minWidths,
							 itsToolBar->GetWidgetEnclosure(), 
							 JXWidget::kHElastic,JXWidget::kVElastic,
							 0, 0, w, newHeight);
	assert( itsMainPartition != NULL );

	// This is the first column the contains the curve and fit lists.
	
	JXContainer* container = itsMainPartition->GetCompartment(1);

	const JCoordinate kCurveListHeight	= 100;
	const JCoordinate kColHeaderHeight	= 20;
	const JCoordinate kExprHeight		= 50;
	const JCoordinate kFitListHeight	= newHeight - kCurveListHeight - 2 * kPartitionHandleWidth - kExprHeight;
	
	JArray<JCoordinate> heights(3);
	heights.AppendElement(kCurveListHeight);
	heights.AppendElement(kFitListHeight);
	heights.AppendElement(kExprHeight);

	elasticIndex = 2;

	JArray<JCoordinate> minHeights(3);
	minHeights.AppendElement(50);	
	minHeights.AppendElement(100);
	minHeights.AppendElement(40);

	itsListPartition =
		new JXVertPartition(heights, elasticIndex, minHeights, container,
			JXWidget::kHElastic, JXWidget::kVElastic, 0, 0, kFitListWidth, newHeight);
    assert( itsListPartition != NULL );

	container = itsListPartition->GetCompartment(1);
	
	JXScrollbarSet* scrollbarSet =
		new JXScrollbarSet(container, 
						   JXWidget::kHElastic,JXWidget::kVElastic,
						   0, kColHeaderHeight,
						   kFitListWidth, kCurveListHeight - kColHeaderHeight);
	assert( scrollbarSet != NULL );

	// This will be the curve list

	itsCurveList	= 
		new GLCurveNameList(itsDir, itsPlot, 
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0,  kFitListWidth, kCurveListHeight - kColHeaderHeight);
	assert(itsCurveList != NULL);
	ListenTo(itsCurveList);

	JXColHeaderWidget* header =
		new JXColHeaderWidget(itsCurveList, scrollbarSet,
			container,
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0, 0,  
			kFitListWidth, 
			kColHeaderHeight);
	assert(header != NULL);

	header->SetColTitle(1, "Curves");
	
	container = itsListPartition->GetCompartment(2);
	
	scrollbarSet =
		new JXScrollbarSet(container, 
						   JXWidget::kHElastic,JXWidget::kVElastic,
						   0, kColHeaderHeight,
						   kFitListWidth, 
						   kFitListHeight - kColHeaderHeight);
	assert( scrollbarSet != NULL );

	// This will be the fit list
	
	itsFitList	= 
		new GLFitDescriptionList(scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0,  
			kFitListWidth, 
			kFitListHeight - kColHeaderHeight);
	assert(itsFitList != NULL);
	ListenTo(itsFitList);

	header =
		new JXColHeaderWidget(itsFitList, scrollbarSet,
			container,
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0, 0,  
			kFitListWidth, 
			kColHeaderHeight);
	assert(header != NULL);

	header->SetColTitle(1, "Fits");

	// this is the expression widget that displays the current JFunction

	container = itsListPartition->GetCompartment(3);
	
	scrollbarSet =
		new JXScrollbarSet(container, 
						   JXWidget::kHElastic,JXWidget::kVElastic,
						   0, 0,
						   kFitListWidth, 
						   kExprHeight);
	assert( scrollbarSet != NULL );

	itsExprVarList	= new GVarList();
	assert(itsExprVarList != NULL);

	itsExprWidget	= 
		new JXExprWidget(itsExprVarList,
			scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0, 
			kFitListWidth, 
			kExprHeight);
	assert(itsExprWidget != NULL);
	itsExprWidget->Hide();

	// This is the second column that will contain the parameter table
	// and the plots

	container = itsMainPartition->GetCompartment(2);

	const JCoordinate kParmsTableHeight		= 50;
	const JCoordinate kChiSqHeight			= 20;
	const JCoordinate kTotalParmsHeight		= kParmsTableHeight + kColHeaderHeight + kChiSqHeight;
	const JCoordinate kFirstPlotHeight		= 120;
	const JCoordinate kMinPlotHeight		= 100;

	heights.RemoveAll();
	heights.AppendElement(kTotalParmsHeight);
	heights.AppendElement(kFirstPlotHeight);
	heights.AppendElement(newHeight - kFirstPlotHeight - kTotalParmsHeight - 2 * kPartitionHandleWidth);

	elasticIndex = 2;

	minHeights.RemoveAll();
	minHeights.AppendElement(kTotalParmsHeight - 20);
	minHeights.AppendElement(kMinPlotHeight);
	minHeights.AppendElement(kMinPlotHeight);
	
	itsPlotPartition =
		new JXVertPartition(heights, elasticIndex, minHeights, container,
			JXWidget::kHElastic, JXWidget::kVElastic, 
			0, 0, w - kFitListWidth - kPartitionHandleWidth, newHeight);
    assert( itsPlotPartition != NULL );

	container = itsPlotPartition->GetCompartment(1);
	
	scrollbarSet =
		new JXScrollbarSet(container, 
						   JXWidget::kHElastic,JXWidget::kVElastic,
						   0, kColHeaderHeight,
						   w - kFitListWidth - kPartitionHandleWidth, 
						   kParmsTableHeight);
	assert( scrollbarSet != NULL );

	// this will be the parameter table
	itsParameterTable =
		new GLFitParameterTable(scrollbarSet, scrollbarSet->GetScrollEnclosure(),
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0,  
			w - kFitListWidth - kPartitionHandleWidth, 
			kParmsTableHeight);
	assert(itsParameterTable != NULL);
	ListenTo(itsParameterTable);

	itsParameterColHeader = 
		new GLParmColHeaderWidget(itsParameterTable, scrollbarSet,
			container,
			JXWidget::kHElastic, JXWidget::kFixedTop,
			0, 0,  
			w - kFitListWidth - kPartitionHandleWidth, 
			kColHeaderHeight);
	assert(itsParameterColHeader != NULL);

	itsParameterTable->SetColHeaderWidget(itsParameterColHeader);
	    
	itsFitMenu = menuBar->AppendTextMenu(kFitMenuTitleStr);
	itsFitMenu->SetMenuItems(kFitMenuStr);
	itsFitMenu->SetUpdateAction(JXMenu::kDisableAll);
	ListenTo(itsFitMenu);

	const JCoordinate kChiSqLabelWidth	= 170;

	GLChiSqLabel* label = 
		new GLChiSqLabel(container, 
			JXWidget::kFixedLeft, JXWidget::kFixedBottom,
			0, kParmsTableHeight + kColHeaderHeight,
			kChiSqLabelWidth, kChiSqHeight);
	assert(label != NULL);

	JXDownRect* downRect =
		new JXDownRect(container,
			JXWidget::kHElastic, JXWidget::kFixedBottom,
			kChiSqLabelWidth, kParmsTableHeight + kColHeaderHeight,
			w - kFitListWidth - kPartitionHandleWidth, kChiSqHeight);
	assert(downRect != NULL);

	itsChiSq =
		new JXStaticText("", container,
			JXWidget::kHElastic, JXWidget::kFixedBottom,
			kChiSqLabelWidth + kJXDefaultBorderWidth, 
			kParmsTableHeight + kColHeaderHeight + kJXDefaultBorderWidth,
			w - kFitListWidth - kPartitionHandleWidth - 2 * kJXDefaultBorderWidth, 
			kChiSqHeight - 2 * kJXDefaultBorderWidth);
	assert(itsChiSq != NULL);
	itsChiSq->SetBackColor(GetColormap()->GetWhiteColor());

	// now add the 2 plots

	container = itsPlotPartition->GetCompartment(2);

	itsFitPlot	= 
		new JX2DPlotWidget(menuBar, container,
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0, 
			w - kFitListWidth - kPartitionHandleWidth,
			container->GetApertureHeight());
	assert(itsFitPlot != NULL);
	itsFitPlot->SetTitle(kFitPlotTitle);
	itsFitPlot->SetXLabel(itsPlot->GetXLabel());
	itsFitPlot->SetYLabel(itsPlot->GetYLabel());

	container = itsPlotPartition->GetCompartment(3);

	itsDiffPlot	= 
		new JX2DPlotWidget(itsFitPlot, container,
			JXWidget::kHElastic, JXWidget::kVElastic,
			0, 0, 
			w - kFitListWidth - kPartitionHandleWidth,
			newHeight - kFirstPlotHeight - kTotalParmsHeight - 2 * kPartitionHandleWidth);
	assert(itsDiffPlot != NULL);
	itsDiffPlot->SetTitle(kDiffPlotTitle);
	itsDiffPlot->SetXLabel(itsPlot->GetXLabel());
	itsDiffPlot->SetYLabel(itsPlot->GetYLabel());
	itsDiffPlot->ShowFrame(kJFalse);

	itsPrefsMenu = menuBar->AppendTextMenu(kPrefsMenuTitleStr);
	itsPrefsMenu->SetMenuItems(kPrefsMenuStr);
	itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsPrefsMenu);

	itsHelpMenu = menuBar->AppendTextMenu(kHelpMenuTitleStr);
	itsHelpMenu->SetMenuItems(kHelpMenuStr);
	itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsHelpMenu);

	itsHelpMenu->SetItemImage(kTOCCmd, jx_help_toc);
	itsHelpMenu->SetItemImage(kThisWindowCmd, JXPM(jx_help_specific));

	itsCurveList->SetCurrentCurveIndex(1);

	GetPrefsMgr()->ReadFitDirectorSetup(this);
}
void
SCFeedbackDirector::BuildWindow
(
    SCCircuitDocument* doc
)
{
    const SCCircuit* circuit = doc->GetCircuit();

    JArray<JCoordinate> heights(4);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);
    heights.AppendElement(kInitExprHeight);

    JArray<JCoordinate> minHeights(4);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);
    minHeights.AppendElement(kMinExprHeight);

// begin JXLayout

    JXWindow* window = new JXWindow(this, 360,520, "");
    assert( window != NULL );

    itsMainPartition =
        new JXVertPartition(heights, 0, minHeights, window,
                            JXWidget::kHElastic, JXWidget::kVElastic, 0,110, 365,415);
    assert( itsMainPartition != NULL );

    itsInputSource =
        new SCComponentMenu(circuit, SCACSourceFilter, "Input source:", window,
                            JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,20, 150,30);
    assert( itsInputSource != NULL );

    itsDepSource =
        new SCComponentMenu(circuit, SCDepSourceFilter, "Dependent source:", window,
                            JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,60, 150,30);
    assert( itsDepSource != NULL );

    itsEvalButton =
        new JXTextButton(JGetString("itsEvalButton::SCFeedbackDirector::JXLayout"), window,
                         JXWidget::kFixedRight, JXWidget::kFixedTop, 230,20, 80,20);
    assert( itsEvalButton != NULL );

    JXStaticText* layoutMessage =
        new JXStaticText(JGetString("layoutMessage::SCFeedbackDirector::JXLayout"), window,
                         JXWidget::kFixedRight, JXWidget::kFixedTop, 240,50, 110,60);
    assert( layoutMessage != NULL );

// end JXLayout

    const JCoordinate kMinWindowWidth = window->GetBoundsWidth();

    window->SetTitle("Feedback Theorem");
    window->SetMinSize(kMinWindowWidth, window->GetBoundsHeight());

    layoutMessage->SetText(
        "Output fn\nH0  |  Hinf\n T   |  Tn\nScratch area");

    itsInputSource->SetToPopupChoice(kJTrue);
    itsDepSource->SetToPopupChoice(kJTrue);

    ListenTo(itsEvalButton);

    // create sub-partitions

    const JCoordinate w =
        (itsMainPartition->GetBoundsWidth() - JPartition::kDragRegionSize)/2;
    JArray<JCoordinate> widths(2);
    widths.AppendElement(w);
    widths.AppendElement(w);

    const JCoordinate wMin = (kMinWindowWidth - JPartition::kDragRegionSize)/2;
    JArray<JCoordinate> minWidths(2);
    minWidths.AppendElement(wMin);
    minWidths.AppendElement(wMin);

    JXContainer* encl = itsMainPartition->GetCompartment(2);
    itsHPartition =
        new JXHorizPartition(widths, 0, minWidths, encl,
                             JXWidget::kHElastic, JXWidget::kVElastic,
                             0,0, encl->GetBoundsWidth(), encl->GetBoundsHeight());
    assert( itsHPartition != NULL );

    encl = itsMainPartition->GetCompartment(3);
    itsTPartition =
        new JXHorizPartition(widths, 0, minWidths, encl,
                             JXWidget::kHElastic, JXWidget::kVElastic,
                             0,0, encl->GetBoundsWidth(), encl->GetBoundsHeight());
    assert( itsTPartition != NULL );

    // create expressions

    SCExprEditorSet* exprSet =
        new SCExprEditorSet(doc, &itsOutputFn,
                            itsMainPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsH0,
                            itsHPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsHinf,
                            itsHPartition->GetCompartment(2),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsT,
                            itsTPartition->GetCompartment(1),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsTn,
                            itsTPartition->GetCompartment(2),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    exprSet =
        new SCExprEditorSet(doc, itsOutputFn, &itsScratchFn,
                            itsMainPartition->GetCompartment(4),
                            JXWidget::kHElastic, JXWidget::kVElastic,
                            0,0, 100,100);
    assert( exprSet != NULL );
    exprSet->FitToEnclosure();

    // add our menu items

    JXTextMenu* menu = itsOutputFn->GetExtraMenu();

    menu->AppendItem(kBuildH0FormItemStr);
    itsBuildH0Index = menu->GetItemCount();

    menu->AppendItem(kBuildHinfFormItemStr);
    itsBuildHinfIndex = menu->GetItemCount();

    menu->ShowSeparatorAfter(itsBuildH0Index-1);
    ListenTo(menu);
}