note
	description: "[
			Used to hold a CHART_VIEW in the VITP game program.
			]"
	author: "Jimmy J. Johnson"

class
	CHART_TOOL

inherit

	VITP_TOOL
		redefine
			create_interface_objects,
			initialize,
--			add_actions,
			set_target,
			draw
		end

create
	default_create,
	make

feature {NONE} -- Initialization

	create_interface_objects
			-- Create objects to be used by `Current' in `initialize'
			-- Implemented by descendants to create attached objects
			-- in order to adhere to void-safety due to the implementation bridge pattern.
		do
			Precursor {VITP_TOOL}
			create japanese_oa_chart_view.make (vitp)
			create allied_oa_chart_view.make (vitp)
			create allied_starting_forces_view.make (vitp)
		end

	initialize
			-- Build the interface for this window
		do
			Precursor {VITP_TOOL}
			disable_history
			split_manager.extend (japanese_oa_chart_view)
			split_manager.extend (allied_starting_forces_view)
			split_manager.set_vertical
			split_manager.extend (allied_oa_chart_view)
		end

--	add_actions
--			-- Add actions to views
--		do
--			Precursor
----			japanese_oa_chart_view.pointer_button_press_actions.extend (agent on_pressed (japanese_oa_chart_view, ?,?,?,?,?,?,?,?))
----			allied_oa_chart_view.pointer_button_press_actions.extend (agent on_pressed (allied_oa_chart_view, ?,?,?,?,?,?,?,?))
----			allied_starting_forces_view.pointer_button_press_actions.extend (agent on_pressed (allied_starting_forces_view, ?,?,?,?,?,?,?,?))

--			allied_starting_forces_view.pointer_enter_actions.extend (agent on_enter)
--			allied_starting_forces_view.pointer_button_release_actions.extend (agent on_pressed (allied_starting_forces_view, ?,?,?,?,?,?,?,?))
--		end

feature {NONE} -- Agent actions

	on_enter
			-- Test actions
		do
			io.put_string (generating_type.name + ".on_enter:  %N")
		end

	on_pressed (a_view: ORDER_OF_APPEARANCE_VIEW;
						ax, ay, button: INTEGER;
						ax_tilt, ay_tilt, a_pressure: DOUBLE;
						a_screen_x, a_screen_y: INTEGER)
			-- I was going to use this feature for setting the `focused_view'
			-- when the user clicks within one of the views, but it never gets
			-- called (so I commented out `add_actions').  I bet the event
			-- loop never checks for `pointer_press_actions'. ???
		do
			io.put_string (generating_type.name + ".on_pressed:  " + a_view.generating_type.name + "%N")
			focused_view_imp := a_view
		end

feature -- Access

--	target: VITP_GAME

	japanese_oa_chart_view: JAPANESE_ORDER_OF_APPEARANCE_CHART_VIEW
			-- The view representing the Japanese order of appearance

	allied_oa_chart_view: ALLIED_ORDER_OF_APPEARANCE_CHART_VIEW
			-- The view representing the Allied ordr of appearance

	allied_starting_forces_view: ALLIED_STARTING_FORCES_VIEW
			-- The view reprsenting the Allied, turn 1, starting forces chart

	focused_view: VITP_CELL_VIEW
			-- The view that currently has the focus
		do
			if attached focused_view_imp as v and then v.is_displayed then
				Result := v
			else
				if japanese_oa_chart_view.is_displayed then
					Result := japanese_oa_chart_view
				elseif allied_oa_chart_view.is_displayed then
					Result := allied_oa_chart_view
				elseif allied_starting_forces_view.is_displayed then
					Result := allied_starting_forces_view
				else
						-- Unlikely, but all view are hidden, so default
					Result := japanese_oa_chart_view
				end
			end
		end

feature -- Element change

	set_target (a_game: like vitp)
			-- Change the value of `target' and add it to the `target_set' (the set
			-- of objects contained in this view.  The old target is removed from
			-- the set.
		do
			Precursor {VITP_TOOL} (a_game)
			japanese_oa_chart_view.set_target (a_game)
			allied_oa_chart_view.set_target (a_game)
			allied_starting_forces_view.set_target (a_game)
		end

	set_focused_view (a_view: ORDER_OF_APPEARANCE_VIEW)
			-- Set `focused_view' to `a_view'.
			-- Called by {ORDER_OF_APPEARANCE_VIEW} when `a_view' was clicked
		require
			valid_view: a_view = japanese_oa_chart_view or
						 a_view = allied_oa_chart_view or
						 a_view = allied_starting_forces_view
		do
			focused_view_imp := a_view
		end

feature -- Basic operations

	draw
			-- Redraw the tool and the contained view
		do
			Precursor {VITP_TOOL}
			japanese_oa_chart_view.draw
			allied_oa_chart_view.draw
		end

feature {NONE} -- Implementation

	focused_view_imp: detachable like focused_view
			-- Implementaion of `focused_view'
end
