void  
GLFitDirector::HandleHelpMenu
	(
	const JIndex index
	)
{
	if (index == kAboutCmd)
		{
		GLGetApplication()->DisplayAbout();
		}
	else if (index == kTOCCmd)
		{
		(JXGetHelpManager())->ShowSection(kGLTOCHelpName);
		}
	else if (index == kThisWindowCmd)
		{
		(JXGetHelpManager())->ShowSection(kGLFitHelpName);
		}
	else if (index == kChangesCmd)
		{
		(JXGetHelpManager())->ShowSection(kGLChangeLogName);
		}
	else if (index == kCreditsCmd)
		{
		(JXGetHelpManager())->ShowSection(kGLCreditsName);
		}
}
void
GXDataDocument::HandleFileMenu
	(
	const JIndex index
	)
{
	if (index == kNewCmd)
		{
		(GLGetApplication())->NewFile();
		}
	else if (index == kOpenCmd)
		{
		JString filename;
		if (JGetChooseSaveFile()->ChooseFile("Select Data File", "", &filename))
			{
			(GLGetApplication())->OpenFile(filename);
			}
		}
	else if (index == kSaveCmd)
		{
		SaveInCurrentFile();
		}
	else if (index == kSaveAsCmd)
		{
		SaveInNewFile();
		}
	else if (index == kPageSetupCmd)
		{
		itsPrinter->BeginUserPageSetup();
		}
	else if (index == kPrintCmd && itsTable->EndEditing())
		{
		itsPrinter->BeginUserPrintSetup();
		}
	else if (index == kCloseCmd)
		{
		Close();
		}

	else if (index == kQuitCmd)
		{
		(GLGetApplication())->Quit();
		}
}
void
GXDataDocument::LoadImportFile()
{
	JIndex filterIndex = itsFileImportDialog->GetFilterIndex();
	if (filterIndex <= kInternalModuleCount)
		{
		LoadInternalFile(filterIndex);
		}
	else
		{
		JString filter;
		if (!((GLGetApplication())->GetImportModulePath(filterIndex - kInternalModuleCount, &filter)))
			{
			return;
			}

		const JCharacter* argv[] = { filter, itsCurrentFileName, NULL };

		int inFD;
		pid_t pid;
		JError err = JExecute(argv, sizeof(argv), &pid,
							  kJIgnoreConnection, NULL,
							  kJCreatePipe, &inFD,
							  kJIgnoreConnection, NULL);

		if (!err.OK())
			{
			JGetUserNotification()->ReportError("Error executing filter.");
			return;
			}

		std::ifstream ip;
		JString tempName;
		if (JConvertToStream(inFD, &ip, &tempName))
			{
			int type;
			ip >> type;

			if (type == kGloveDataError)
				{
				JGetUserNotification()->ReportError("This file is not readable by this filter.");
				return;
				}

			itsData->ShouldBroadcast(kJFalse);
			itsListenToData = kJFalse;

			JLatentPG pg(10);
			pg.VariableLengthProcessBeginning("Loading file...", kJTrue, kJFalse);
			JBoolean keepGoing = kJTrue;

			if (type == kGloveMatrixDataFormat)
				{
				JSize colCount;
				ip >> colCount;

				for (JIndex i = 1; i <= colCount; i++)
					{
					itsData->AppendCol();
					}

				while (keepGoing)
					{
					for (JIndex i = 1; i <= colCount && keepGoing; i++)
						{
						JFloat value;
						ip >> value;
						if (ip.fail() || (ip.eof() && i < colCount))
							{
							keepGoing = kJFalse;
							break;
							}
						itsData->AppendElement(i, value);
						keepGoing = pg.IncrementProgress();
						}
					}
				}

			else if (type == kGloveRaggedDataFormat)
void
PlotDir::Receive
	(
	JBroadcaster* sender,
	const JBroadcaster::Message& message
	)
{
	if (sender == itsPlot && message.Is(J2DPlotWidget::kTitleChanged))
		{
		JString title = itsFileName + ":  " + itsPlot->GetTitle();
		GetWindow()->SetTitle(title);
		JString sessiontitle = "Glove session  -  " + title;
		(itsSessionDir->GetWindow())->SetTitle(sessiontitle);
		}

	else if (sender == itsPlot && message.Is(J2DPlotWidget::kPlotChanged))
		{
		itsSupervisor->DataModified();
		}

	else if (sender == itsSessionDir && message.Is(GloveHistoryDir::kSessionChanged))
		{
		itsSupervisor->DataModified();
		}

	else if (sender == itsPlot && message.Is(J2DPlotWidget::kIsEmpty))
		{
		if (!itsPlotIsClosing)
			{
			GLClosePlotDirTask* task = jnew GLClosePlotDirTask(this);
			assert(task != NULL);
			task->Go();
			}
		}

	else if (sender == itsPlot && message.Is(J2DPlotWidget::kCurveAdded))
		{
		HandleCurveAdded();
		}

	else if (sender == itsPlot && message.Is(J2DPlotWidget::kCurveRemoved))
		{
		const J2DPlotWidget::CurveRemoved* info =
			dynamic_cast<const J2DPlotWidget::CurveRemoved*>(&message);
		assert( info != NULL );
		HandleCurveRemoved(info->GetIndex());
		}

	else if (sender == itsPlotMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		HandlePlotMenu(selection->GetIndex());
		}
	else if (sender == itsAnalysisMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		HandleAnalysisMenu(selection->GetIndex());
		}
	else if (sender == itsHelpMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		HandleHelpMenu(selection->GetIndex());
		}

	else if (sender == itsFits &&
		( 	message.Is(JOrderedSetT::kElementsInserted) ||
			message.Is(JOrderedSetT::kElementsRemoved)))
		{
		UpdateFitParmsMenu();
		}

	else if (sender == itsDiffDirs &&
		( 	message.Is(JOrderedSetT::kElementsInserted) ||
			message.Is(JOrderedSetT::kElementsRemoved)))
		{
		UpdateDiffMenu();
		}


	else if (sender == itsFitParmsMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		itsFitParmsDir->Activate();
		itsFitParmsDir->ShowFit(selection->GetIndex());
		}

	else if (sender == itsDiffMenu && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		PlotDir* dir = itsDiffDirs->NthElement(selection->GetIndex());
		dir->Activate();
//		(itsDiffDirs->NthElement(selection->GetIndex()))->Activate();
		}


	else if (sender == itsFunctionDialog && message.Is(JXDialogDirector::kDeactivated))
		{
		const JXDialogDirector::Deactivated* info =
			dynamic_cast<const JXDialogDirector::Deactivated*>(&message);
		assert( info != NULL );
		if (info->Successful())
			{
			JString fnStr = itsFunctionDialog->GetFunctionString();
			JFunction* f;
			if (JParseFunction(fnStr, itsVarList, &f))
				{
				PlotFunction(f);
				}
			}
		itsFunctionDialog = NULL;
		}

	else if (sender == itsFitModuleDialog && message.Is(JXDialogDirector::kDeactivated))
		{
		const JXDialogDirector::Deactivated* info =
			dynamic_cast<const JXDialogDirector::Deactivated*>(&message);
		assert( info != NULL );
		if (info->Successful())
			{
			JIndex index = itsFitModuleDialog->GetFilterIndex();
			JPlotDataBase* data = &(itsPlot->GetCurve(itsCurveForFit));
			FitModule* fm;
			JString modName;
			(GLGetApplication())->GetFitModulePath(index, &modName);
			JBoolean success = FitModule::Create(&fm, this, data, modName);
			if (!success)
				{
				JGetUserNotification()->ReportError("Unknown module error.");
				}
			}
		itsFitModuleDialog = NULL;
		}

	else if (sender == itsPrinter &&
			 message.Is(JPrinter::kPageSetupFinished))
		{
		const JPrinter::PageSetupFinished* info =
			dynamic_cast<const JPrinter::PageSetupFinished*>(&message);
		assert(info != NULL);
		if (info->Changed())
			{
			itsSupervisor->DataModified();
			// for WYSISYG: adjust display to match new paper size
			}
		}

	else if (sender == itsPrinter &&
			 message.Is(JPrinter::kPrintSetupFinished))
		{
		const JPrinter::PrintSetupFinished* info =
			dynamic_cast<const JPrinter::PrintSetupFinished*>(&message);
		assert(info != NULL);
		if (info->Successful())
			{
			itsPlot->Print(*itsPrinter);
			if (itsIsPrintAll)
				{
				itsFitParmsDir->SendAllToSession();
				itsSessionDir->Print();
				}
			}
		}
	else
		{
		JXWindowDirector::Receive(sender, message);
		}
}