/*********************************************************************************
 J2DPlotWidget.h

	Interface for the J2DPlotWidget class.

	Copyright @ 1997 by Glenn W. Bach. All rights reserved.

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

#ifndef _H_J2DPlotWidget
#define _H_J2DPlotWidget

#include <JBroadcaster.h>
#include <jColor.h>
#include <JRect.h>
#include <JPtrArray.h>
#include <JFontStyle.h>
#include <JString.h>
#include <JCurveInfo.h>

class JPainter;
class JPagePrinter;
class JPlotDataBase;

class J2DPlotWidget : virtual public JBroadcaster
{
public:

	enum
	{
		kMin = 0,
		kMax,
		kInc,
		kStart
	};

	enum
	{
		kXMajor = 0,
		kXMinor,
		kYMajor,
		kYMinor
	};

	enum LabelSelection
	{
		kNoLabel = 1,
		kTitle,
		kYLabel,
		kXLabel
	};

	enum CursorIndex
	{
		kNoCursor = 0,
		kX1,
		kX2,
		kY1,
		kY2
	};

	enum MouseCursor
	{
		kDblClickChangeCursor,		// arrow
		kDragXCursor,				// drag horiz
		kDragYCursor,				// drag vert
		kZoomCursor					// crosshair
	};

public:

	J2DPlotWidget(JColorIndex black, JColorIndex white,
					JColorIndex gray, JColorIndex selection);

	virtual ~J2DPlotWidget();

	void	Print(JPagePrinter& p);

	void	PWReadSetup(istream& input);
	void	PWWriteSetup(ostream& output) const;

	void	PWReadCurveSetup(istream& input);
	void	PWWriteCurveSetup(ostream& output) const;

	JBoolean		WillAutoRefresh() const;
	void			ShouldAutoRefresh(const JBoolean refresh);

	void 			SetLabels(const JCharacter* title, const JCharacter* xLabel, const JCharacter* yLabel);
	const JString&	GetXLabel() const;
	void 			SetXLabel(const JCharacter* xLabel);
	const JString&	GetYLabel() const;
	void 			SetYLabel(const JCharacter* yLabel);
	const JString&	GetTitle() const;
	void 			SetTitle(const JCharacter* xLabel);


	const JString& 	GetFontName() const;
	void 			SetFontName(const JCharacter* name);

	JSize 			GetFontSize() const;
	void 			SetFontSize(const JSize size);

	JBoolean 		LegendIsVisible() const;
	void 			ShowLegend(const JBoolean show);
	JBoolean 		FrameIsVisible() const;
	void 			ShowFrame(const JBoolean show);
	JBoolean 		GridIsVisible() const;
	void 			ShowGrid(const JBoolean show);


	JBoolean 		CurveIsVisible(const JIndex curveIndex) const;
	void 			ShowCurve(const JIndex curveIndex, const JBoolean show);
	JBoolean 		LinesAreVisible(const JIndex curveIndex) const;
	void 			ShowLines(const JIndex curveIndex, const JBoolean show);
	JBoolean 		SymbolIsVisible(const JIndex curveIndex) const;
	void 			ShowSymbol(const JIndex curveIndex, const JBoolean show);
	JBoolean 		CurveIsProtected(const JIndex curveIndex) const;
	void 			ProtectCurve(const JIndex curveIndex, const JBoolean protect);


	JSize 			GetCurveCount() const;

	void 			SetCurveName(const JIndex index, const JCharacter* xLabel);
	const JString& 	GetCurveName(const JIndex index) const;

	void 			AddColor(const JColorIndex color);
	JColorIndex 	GetCurveColor(const JIndex index) const;
	JSymbolType 	GetSymbolType(const JIndex index) const;

	JPlotDataBase&			GetCurve(const JIndex index);
	const JPlotDataBase&	GetCurve(const JIndex index) const;
	void 					GetCurveNames(JPtrArray<JString>* names);

	JIndex 			AddCurve(JPlotDataBase* data, const JBoolean ownsData,
							const JCharacter* name,
							const JBoolean line = kFalse, const JBoolean symbol = kTrue,
							const JBoolean point = kFalse);
	JIndex 			AddCurve(JArray<JFloat>& x, JArray<JFloat>& y,
							const JBoolean listen, const JCharacter* name,
							const JBoolean line = kFalse, const JBoolean symbol = kTrue,
							const JBoolean point = kFalse);
	void 			RemoveCurve(const JIndex index);

	void 			ResetScaling();

	JBoolean 		IsZoomed() const;
	void 			Zoom(const JRect rect, const JBoolean clean);

	void 			GetXScaling(JFloat* min, JFloat* max, JFloat* inc);
	void 			SetXScaling(const JFloat min, const JFloat max, const JFloat inc);
	void 			GetYScaling(JFloat* min, JFloat* max, JFloat* inc);
	void 			SetYScaling(const JFloat min, const JFloat max, const JFloat inc);



	JBoolean 		XAxisIsLinear() const;
	void 			SetXAxisLinear(const JBoolean linear);
	JBoolean 		YAxisIsLinear() const;
	void 			SetYAxisLinear(const JBoolean linear);

	JBoolean 		XErrorsAreVisible(const JIndex index);
	void 			ShowXErrors(const JBoolean show, const JIndex index);
	JBoolean 		YErrorsAreVisible(const JIndex index);
	void 			ShowYErrors(const JBoolean show, const JIndex index);


	JBoolean 		ArrayIsInCurve(JArray<JFloat>* testArray);
	void 			RemoveCurvesContainingArray(JArray<JFloat>* testArray);

	JSize 			GetSmoothSteps() const;
	void			SetSmoothDivisor(const JSize divisor);
	void			GetDefaultXRange(JFloat* min, JFloat* max) const;
	void			SetDefaultXRange(const JFloat min, const JFloat max);
	void			GetDefaultYRange(JFloat* min, JFloat* max) const;
	void			SetDefaultYRange(const JFloat min, const JFloat max);

	JBoolean		GetRange(JFloat* xmin, JFloat* xmax, JFloat* ymin, JFloat* ymax);
	void			SetRange();
	void			SetRange(const JFloat xmin, const JFloat xmax,
							 const JFloat ymin, const JFloat ymax);
	void			ClearRange();
	JBoolean 		IsUsingRange() const;

	JBoolean		GetCurveIndex(JPlotDataBase* data, JIndex* index);

	// Cursors

	JSize			GetXMarkCount() const;
	JSize			GetYMarkCount() const;
	JFloat			GetXMarkValue(const JIndex index) const;
	JFloat			GetYMarkValue(const JIndex index) const;
	void			MarkCurrentCursor();
	void			RemoveAllMarks();
	void			RemoveXMark(const JIndex index);
	void			RemoveYMark(const JIndex index);

	JBoolean		CursorIsSelected();
	JBoolean		XCursorVisible();
	void			ToggleXCursor();
	JBoolean		YCursorVisible();
	void			ToggleYCursor();
	JBoolean		DualCursorsVisible();
	void			ToggleDualCursors();

	JBoolean		GetXCursorVal1(JFloat* value);
	JBoolean		GetXCursorVal2(JFloat* value);
	JBoolean		GetYCursorVal1(JFloat* value);
	JBoolean		GetYCursorVal2(JFloat* value);

protected:

	virtual void 	PWDraw(JPainter& p, const JRect& rect);
	void		 	PWHandleMouseDown(const JPoint& pt, const JSize clickCount);
	void 			PWHandleMouseDrag(const JPoint& pt);
	void 			PWHandleMouseUp(const JPoint& pt, const JBoolean cleanZoom);
	MouseCursor		GetMouseCursor(const JPoint& pt) const;

	// for cursors
	void	PWHandleKeyPress(const int key, const JBoolean reverse,
							 const JBoolean interval, const JBoolean skip);

	virtual JPainter*	PWCreateDragInsidePainter() = 0;
	virtual JPainter*	PWGetDragPainter() 			= 0;
	virtual void		PWDeleteDragPainter() 		= 0;

	void 			PWBoundsChanged();
	void 			PWRefresh();
	virtual void 	PWRefreshRect(const JRect& rect) = 0;
	virtual void 	PWRedraw() 						= 0;
	virtual void 	PWRedrawRect(const JRect& rect) = 0;
	virtual void 	PWForceRefresh() 				= 0;
	virtual void	PWRefreshUpdate()				= 0;

	JSize 			PWGetWidth() const;
	JSize 			PWGetHeight() const;
	virtual JSize 	PWGetGUIWidth() const			= 0;
	virtual JSize 	PWGetGUIHeight() const			= 0;
	virtual void	PWDisplayCursor(const MouseCursor cursor) = 0;

	virtual void 	ProtectionChanged() 			= 0;

	virtual void	ChangeCurveOptions(const JIndex index) 			= 0;
	virtual void 	ChangeLabels(const LabelSelection selection)	= 0;
	virtual void	ChangeScale(const JBoolean xAxis) 				= 0;

	virtual JBoolean	PrintMarks(JPagePrinter& p, const JBoolean putOnSamePage,
									const JRect& partialPageRect) = 0;

	virtual void	Receive(JBroadcaster* sender, const Message& message);
	void			GetFrameGeometry(JCoordinate* xmin, JCoordinate* xmax,
									 JCoordinate* ymin, JCoordinate* ymax);

	JFloat			GetRealX(const JCoordinate frameX);
	JFloat			GetRealY(const JCoordinate frameY);
	void			GetRealPoint(const JPoint framePoint, JFloat* x, JFloat* y);

	JBoolean		GetFrameX(const JFloat x, JCoordinate* frameX);
	JBoolean		GetFrameY(const JFloat y, JCoordinate* frameY);
	JBoolean		GetFramePoint(const JFloat x, const JFloat y, JPoint* framePoint);

	const JArray<JCurveInfo>&	GetCurveInfoArray();
	void						SetCurveInfoArray(const JArray<JCurveInfo>& infoArray);

private:

	JString			itsTitle;
	JString			itsXLabel;
	JString			itsYLabel;

	JBoolean		itsShowLegend;
	JBoolean		itsShowGrid;
	JBoolean		itsShowFrame;

	JBoolean		itsGeometryNeedsAdjustment;
	JBoolean		itsAutomaticRefresh;

	JArray<JCurveInfo>* 		itsCurvesInfo;
	JArray<JColorIndex>*		itsColors;
	JArray<JSize>* 				itsColorUsage;

	JPtrArray<JPlotDataBase>*	itsCurves;

	JFloat			itsCurrentXScale[4];
	JFloat			itsCurrentYScale[4];
	JFloat			itsDefXScale[3];
	JFloat			itsDefYScale[3];

	JSize			itsSymbolUsage [ kSymbolCount ];

	JString 		itsFontName;
	JSize			itsFontSize;

	JSize			itsLegendWidth;
	JSize			itsMaxCurveNameWidth;

	JCoordinate		itsXAxisStart;
	JCoordinate		itsXAxisEnd;
	JCoordinate		itsYAxisStart;
	JCoordinate		itsYAxisEnd;

	JFloat			itsXTrans;
	JFloat			itsYTrans;

	JSize			itsCurrentXDecimalPoints;
	JSize			itsCurrentYDecimalPoints;
	JCoordinate		itsCurrentXExp;
	JCoordinate		itsCurrentYExp;
	JBoolean		itsForceXExp;
	JBoolean		itsForceYExp;

	JBoolean		itsXAxisIsLinear;
	JBoolean		itsYAxisIsLinear;
	JBoolean		itsIsZoomed;
	JBoolean		itsUseRealXStart;
	JBoolean		itsUseRealYStart;

	JBoolean		itsShowXMinorTics;
	JBoolean		itsShowYMinorTics;

	const JColorIndex 	itsBlackColor;
	const JColorIndex 	itsWhiteColor;
	const JColorIndex 	itsGrayColor;
	const JColorIndex 	itsSelectionColor;

	JSize 			itsSmoothSteps;
	JSize 			itsSmoothDivisor;
	JFloat 			itsDefaultXMax;
	JFloat 			itsDefaultXMin;
	JFloat 			itsDefaultYMax;
	JFloat 			itsDefaultYMin;

	JFloat 			itsRangeXMax;
	JFloat 			itsRangeXMin;
	JFloat 			itsRangeYMax;
	JFloat 			itsRangeYMin;
	JBoolean 		itsUsingRange;

	JPoint			itsStartPt;
	JPoint			itsPrevPt;

	JSize			itsCurrentStringHeight;
	JSize			itsMaxXLabelWidth;
	JRect			itsLegendRect;
	JRect			itsTitleRect;
	JRect			itsXLabelRect;
	JRect			itsYLabelRect;
	JRect			itsXAxisRect;
	JRect			itsYAxisRect;

	// Printing

	JBoolean		itsIsPrintingFlag;
	JCoordinate		itsPrintWidth;
	JCoordinate		itsPrintHeight;

	// Cursors

	JBoolean		itsXCursorVisible;
	JBoolean		itsYCursorVisible;
	JBoolean		itsDualCursors;
	JCoordinate		itsXCursorPos1;
	JCoordinate		itsXCursorPos2;
	JCoordinate		itsYCursorPos1;
	JCoordinate		itsYCursorPos2;
	JArray<JFloat>*	itsXMarks;
	JArray<JFloat>*	itsYMarks;
	JBoolean		itsIsCursorDragging;
	JFloat			itsXCursorVal1;
	JFloat			itsXCursorVal2;
	JFloat			itsYCursorVal1;
	JFloat			itsYCursorVal2;
	CursorIndex		itsSelectedCursor;
	JBoolean		itsIsInited;
	JBoolean		itsChangingScale;
	JSize			itsCurrentCursorLabelHeight;

private:

	void 			AdjustGeometry(JPainter& p);
	void 			AdjustScaling();
	void 			AdjustScaling(	const JBoolean isX, const JBoolean linear,
									const JFloat max, const JFloat min,
									JFloat scale[], JFloat defScale[]);

	void 			DrawAxes(JPainter& p);

	void 			DrawTicks(JPainter& p);
	void 			DrawXLogMinorTicks(JPainter& p, JCoordinate yTick, JSize tickCount, JCoordinate yLabel);
	void 			DrawYLogMinorTicks(JPainter& p, JCoordinate xTick, JSize tickCount, JCoordinate xLabel, JBoolean xLabelEndKnown);
	void 			DrawXTicks(JPainter& p, JCoordinate yTick, JCoordinate yLabel, JSize tickCount);
	void			DrawXTick(JPainter& p, JFloat value, JCoordinate yVal,
							  JCoordinate tickLength,
							  JCoordinate yLabel,
							  JBoolean drawStr,
							  JBoolean lightGrid);
	void 			DrawYTicks(JPainter& p, JCoordinate xTick, JCoordinate xLabel, JBoolean xLabelEndKnown, JSize tickCount);
	void			DrawYTick(JPainter& p, JFloat value, JCoordinate xVal,
							  JCoordinate tickLength,
							  JCoordinate xLabel,
							  JCoordinate xLabelEndKnown,
							  JBoolean drawStr,
							  JBoolean lightGrid);
	void			GetLogTicks(JFloat min, JFloat max, JFloat inc,
								JArray<JFloat>* major,
								JArray<JFloat>* minor);

	void 			DrawLabels(JPainter& p);
	void 			DrawCurves(JPainter& p);
	void 			DrawPoints(JPainter& p);
	void 			DrawErrors(JPainter& p);
	void 			DrawVectors(JPainter& p);
	void 			DrawLegend(JPainter& p);

	void 			DrawSymbol(JPainter& p, const JPoint point, const JSymbolType type);

	void			GetLogAxisString(JFloat value, JString* str);

	void			SetClipping(JPainter& p) const;

	JSymbolType		GetFirstAvailableSymbol();
	JIndex			GetFirstAvailableColor();

	void 			GetRanges(JFloat *maxX, JFloat *minX, JFloat *maxY, JFloat *minY);
	void			AdjustExtremes(	const JBoolean first,
									JFloat* max, const JFloat testMax,
									JFloat* min, const JFloat testMin);

	JSize 			GetDecPlaces(const JFloat value);
	void 			SetPlotDecPlaces();

	JBoolean 		GetMinimumPositiveValue(const JBoolean isX, JFloat *min);

	JFloat 			GetLogIncrement(JFloat max, JFloat min);
	void 			FindLogRange(JFloat max, JFloat min, JFloat *inc, JFloat *start, JFloat *end);

	void 			TruncateCurveName(JPainter& p, const JIndex index);
	void 			UpdatePlot(const JBoolean geometry = kFalse,
								const JBoolean scaling = kFalse);

	void 			SetCurrentExp();
	JBoolean 		GetExp(const JFloat value, JCoordinate *exp);


	// Cursors

	void			AdjustCursors();
	void			UpdateCursorInternals();
	void			DrawCursors(JPainter& p);
	void			DrawCursorLabels(JPainter& p);
	void			DrawMarks(JPainter& p);
	JSize			GetCursorLabelHeight(JPainter& p);
	CursorIndex		GetCursorIndex(const JPoint& pt) const;
	JBoolean		MoveCursor(const JCoordinate min, const JCoordinate max,
								const JCoordinate delta, JCoordinate* cursorPos) const;

public:

	static const JCharacter* kTitleChanged;
	static const JCharacter* kScaleChanged;
	static const JCharacter* kGeometryChanged;
	static const JCharacter* kPlotChanged;
	static const JCharacter* kIsEmpty;
	static const JCharacter* kCurveAdded;
	static const JCharacter* kCurveRemoved;

	// Cursors
	static const JCharacter* kCursorsChanged;
	static const JCharacter* kCursorMarked;
	static const JCharacter* kMarkRemoved;

	class TitleChanged : public JBroadcaster::Message
	{
	public:

		TitleChanged()
			:
			JBroadcaster::Message(kTitleChanged)
			{ };
	};

	class ScaleChanged : public JBroadcaster::Message
	{
	public:

		ScaleChanged()
			:
			JBroadcaster::Message(kScaleChanged)
			{ };
	};

	class GeometryChanged : public JBroadcaster::Message
	{
	public:

		GeometryChanged()
			:
			JBroadcaster::Message(kGeometryChanged)
			{ };
	};

	class PlotChanged : public JBroadcaster::Message
	{
	public:

		PlotChanged()
			:
			JBroadcaster::Message(kPlotChanged)
			{ };
	};


	class IsEmpty : public JBroadcaster::Message
	{
	public:

		IsEmpty()
			:
			JBroadcaster::Message(kIsEmpty)
			{ };
	};

	class CurveAdded : public JBroadcaster::Message
	{
	public:

		CurveAdded(const JIndex index)
			:
			JBroadcaster::Message(kCurveAdded),
			itsIndex(index)
			{ };

		JIndex
		GetIndex() const
		{
			return itsIndex;
		};

	private:

		JIndex itsIndex;

	};

	class CurveRemoved : public JBroadcaster::Message
	{
	public:

		CurveRemoved(const JIndex index)
			:
			JBroadcaster::Message(kCurveRemoved),
			itsIndex(index)
			{ };

		JIndex
		GetIndex() const
		{
			return itsIndex;
		};

	private:

		JIndex itsIndex;

	};

	class CursorsChanged : public JBroadcaster::Message
	{
	public:

		CursorsChanged
			(
			const JBoolean showX,
			const JBoolean showY,
			const JBoolean dual,
			const JFloat x1,
			const JFloat x2,
			const JFloat y1,
			const JFloat y2
			)
			:
			JBroadcaster::Message(kCursorsChanged),
			itsShowX(showX),
			itsShowY(showY),
			itsDual(dual),
			itsX1(x1),
			itsX2(x2),
			itsY1(y1),
			itsY2(y2)
			{ };

			JBoolean
			ShowX() const
			{
			return itsShowX;
			};

			JBoolean
			ShowY() const
			{
			return itsShowY;
			};

			JBoolean
			Dual() const
			{
			return itsDual;
			};

			JFloat
			GetX1() const
			{
			return itsX1;
			};

			JFloat
			GetX2() const
			{
			return itsX2;
			};

			JFloat
			GetY1() const
			{
			return itsY1;
			};

			JFloat
			GetY2() const
			{
			return itsY2;
			};

		private:

			JBoolean	itsShowX;
			JBoolean	itsShowY;
			JBoolean	itsDual;
			JFloat		itsX1;
			JFloat		itsX2;
			JFloat		itsY1;
			JFloat		itsY2;
	};

	class CursorMarked : public JBroadcaster::Message
	{
	public:

		CursorMarked(const JBoolean isXCursor, const JFloat value)
			:
			JBroadcaster::Message(kCursorMarked),
			itsIsXCursor(isXCursor),
			itsValue(value)
			{ };

		JBoolean
		IsXCursor() const
		{
			return itsIsXCursor;
		};

		JFloat
		GetValue() const
		{
			return itsValue;
		};

	private:

		JBoolean 	itsIsXCursor;
		JFloat		itsValue;
	};

	class MarkRemoved : public JBroadcaster::Message
	{
	public:

		MarkRemoved(const JBoolean isXCursor, const JIndex index)
			:
			JBroadcaster::Message(kMarkRemoved),
			itsIsXCursor(isXCursor),
			itsIndex(index)
			{ };

		JBoolean
		IsXCursor() const
		{
			return itsIsXCursor;
		};

		JIndex
		GetIndex() const
		{
			return itsIndex;
		};

	private:

		JBoolean 	itsIsXCursor;
		JIndex 		itsIndex;

	};

};

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

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

inline const JString&
J2DPlotWidget::GetFontName()
	const
{
	return itsFontName;
}

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

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

inline JSize
J2DPlotWidget::GetFontSize()
	const
{
	return itsFontSize;
}

/******************************************************************************
 GetTitle

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

inline const JString&
J2DPlotWidget::GetTitle()
	const
{
	return itsTitle;
}

/******************************************************************************
 GetXLabel

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

inline const JString&
J2DPlotWidget::GetXLabel()
	const
{
	return itsXLabel;
}

/******************************************************************************
 GetTitle

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

inline const JString&
J2DPlotWidget::GetYLabel()
	const
{
	return itsYLabel;
}

/******************************************************************************
 XAxisIsLinear

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

inline JBoolean
J2DPlotWidget::XAxisIsLinear()
	const
{
	return itsXAxisIsLinear;
}

/******************************************************************************
 YAxisIsLinear

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

inline JBoolean
J2DPlotWidget::YAxisIsLinear()
	const
{
	return itsYAxisIsLinear;
}

/******************************************************************************
 IsZoomed

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

inline JBoolean
J2DPlotWidget::IsZoomed()
	const
{
	return itsIsZoomed;
}

/*******************************************************************************
 LegendIsVisible

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

inline JBoolean
J2DPlotWidget::LegendIsVisible()
	const
{
	return itsShowLegend;
}

/*******************************************************************************
 FrameIsVisible

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

inline JBoolean
J2DPlotWidget::FrameIsVisible()
	const
{
	return itsShowFrame;
}

/*******************************************************************************
 GridIsVisible

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

inline JBoolean
J2DPlotWidget::GridIsVisible()
	const
{
	return itsShowGrid;
}

/*******************************************************************************
 AddColor

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

inline void
J2DPlotWidget::AddColor
	(
	const JColorIndex color
	)
{
	itsColors->AppendElement(color);
	itsColorUsage->AppendElement(0);
}

/*******************************************************************************
 PWRefresh

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

inline void
J2DPlotWidget::PWRefresh()
{
	if (itsAutomaticRefresh)
		{
		PWForceRefresh();
		}
}

/*******************************************************************************
 AutoRefresh

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

inline JBoolean
J2DPlotWidget::WillAutoRefresh()
	const
{
	return itsAutomaticRefresh;
}

inline void
J2DPlotWidget::ShouldAutoRefresh
	(
	const JBoolean refresh
	)
{
	itsAutomaticRefresh = refresh;
	if (refresh)
		{
		PWRefresh();
		}
}

/******************************************************************************
 GetSmoothSteps

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

inline JSize
J2DPlotWidget::GetSmoothSteps()
	const
{
	return itsSmoothSteps;
}

/*******************************************************************************
 SetSmoothDivisor

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

inline void
J2DPlotWidget::SetSmoothDivisor
	(
	const JSize divisor
	)
{
	itsSmoothDivisor = (divisor < 1) ? 1 : divisor;
}

/******************************************************************************
 GetDefaultXRange

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

inline void
J2DPlotWidget::GetDefaultXRange
	(
	JFloat* min,
	JFloat* max
	)
	const
{
	*max = itsDefaultXMax;
	*min = itsDefaultXMin;
}

/*******************************************************************************
 SetDefaultXRange

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

inline void
J2DPlotWidget::SetDefaultXRange
	(
	const JFloat min,
	const JFloat max
	)
{
	itsDefaultXMin = min;
	itsDefaultXMax = max;
}

/******************************************************************************
 GetDefaultYRange

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

inline void
J2DPlotWidget::GetDefaultYRange
	(
	JFloat* min,
	JFloat* max
	)
	const
{
	*max = itsDefaultYMax;
	*min = itsDefaultYMin;
}

/*******************************************************************************
 SetDefaultYRange

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

inline void
J2DPlotWidget::SetDefaultYRange
	(
	const JFloat min,
	const JFloat max
	)
{
	itsDefaultYMin = min;
	itsDefaultYMax = max;
}

/******************************************************************************
 IsUsingRange (public)

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

inline JBoolean
J2DPlotWidget::IsUsingRange()
	const
{
	return itsUsingRange;
}

/******************************************************************************
 GetFrameGeometry (public)

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

inline void
J2DPlotWidget::GetFrameGeometry
	(
	JCoordinate* xmin,
	JCoordinate* xmax,
	JCoordinate* ymin,
	JCoordinate* ymax
	)
{
	*xmin = itsXAxisStart;
	*xmax = itsXAxisEnd;
	*ymin = itsYAxisStart;
	*ymax = itsYAxisEnd;
}

/*******************************************************************************
 GetFramePoint (public)

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

inline JBoolean
J2DPlotWidget::GetFramePoint
	(
	const JFloat	x,
	const JFloat	y,
	JPoint*			framePoint
	)
{
	return JI2B(GetFrameX(x, &(framePoint->x)) && GetFrameY(y, &(framePoint->y)));
}

/*******************************************************************************
 GetCurveIndex (public)

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

inline JBoolean
J2DPlotWidget::GetCurveIndex
	(
	JPlotDataBase*	data,
	JIndex*			index
	)
{
	return itsCurves->Find(data, index);
}

/******************************************************************************
 CursorIsSelected (public)

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

inline JBoolean
J2DPlotWidget::CursorIsSelected()
{
	return JConvertToBoolean(itsSelectedCursor != kNoCursor);
}

/******************************************************************************
 XCursorVisible (public)

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

inline JBoolean
J2DPlotWidget::XCursorVisible()
{
	return itsXCursorVisible;
}

/******************************************************************************
 YCursorVisible (public)

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

inline JBoolean
J2DPlotWidget::YCursorVisible()
{
	return itsYCursorVisible;
}

/******************************************************************************
 GetXCursorVal1 (public)

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

inline JBoolean
J2DPlotWidget::GetXCursorVal1
	(
	JFloat* value
	)
{
	if (itsXCursorVisible)
		{
		*value = itsXCursorVal1;
		return kTrue;
		}
	return kFalse;
}

/******************************************************************************
 GetXCursorVal2 (public)

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

inline JBoolean
J2DPlotWidget::GetXCursorVal2
	(
	JFloat* value
	)
{
	if (itsXCursorVisible && itsDualCursors)
		{
		*value = itsXCursorVal2;
		return kTrue;
		}
	return kFalse;
}

/******************************************************************************
 GetYCursorVal1 (public)

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

inline JBoolean
J2DPlotWidget::GetYCursorVal1
	(
	JFloat* value
	)
{
	if (itsYCursorVisible)
		{
		*value = itsYCursorVal1;
		return kTrue;
		}
	return kFalse;
}

/******************************************************************************
 GetYCursorVal1 (public)

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

inline JBoolean
J2DPlotWidget::GetYCursorVal2
	(
	JFloat* value
	)
{
	if (itsYCursorVisible && itsDualCursors)
		{
		*value = itsYCursorVal2;
		return kTrue;
		}
	return kFalse;
}

/******************************************************************************
 GetCurveInfoArray (protected)

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

inline const JArray<JCurveInfo>&
J2DPlotWidget::GetCurveInfoArray()
{
	return *itsCurvesInfo;
}

#endif
