class Cav_Energy_Out_Graph_Panel(JPanel):
	def __init__(self,scl_long_tuneup_controller):
		self.scl_long_tuneup_controller = scl_long_tuneup_controller
		self.setLayout(GridLayout(1,1))
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		self.setBorder(etched_border)
		self.gp_energy_plot = FunctionGraphsJPanel()
		self.gp_energy_plot.setLegendButtonVisible(true)
		self.gp_energy_plot.setChooseModeButtonVisible(true)
		self.gp_energy_plot.setName("Output Energy vs. Cavity Phase: ")
		self.gp_energy_plot.setAxisNames("Cav Phase, [deg]","Ekin Out, [MeV]")	
		self.gp_energy_plot.setBorder(etched_border)
		self.add(self.gp_energy_plot)
		
	def removeAllGraphData(self):
		self.gp_energy_plot.removeAllGraphData()
			
	def updateGraphData(self):
		self.gp_energy_plot.removeAllGraphData()
		scl_long_tuneup_phase_analysis_controller = self.scl_long_tuneup_controller.scl_long_tuneup_phase_analysis_controller
		cavs_table = scl_long_tuneup_phase_analysis_controller.cavs_table
		cav_selected_inds = cavs_table.getSelectedRows()
		if(len(cav_selected_inds) == 0 or cav_selected_inds[0] < 0):
			return
		for ind in cav_selected_inds:
			cav_wrapper = self.scl_long_tuneup_controller.cav_wrappers[ind]
			if(cav_wrapper == null or not cav_wrapper.isGood): 
				continue
			self.gp_energy_plot.addGraphData(cav_wrapper.eKinOutPlot)
			self.gp_energy_plot.addGraphData(cav_wrapper.eKinOutPlotTh)
class BPM_PhaseDiff_Graph_Panel(JPanel):
	def __init__(self,scl_long_tuneup_controller):
		self.scl_long_tuneup_controller = scl_long_tuneup_controller
		self.setLayout(GridLayout(1,1))
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		self.setBorder(etched_border)
		self.gp_bpm_phaseDiff = FunctionGraphsJPanel()
		self.gp_bpm_phaseDiff.setLegendButtonVisible(true)
		self.gp_bpm_phaseDiff.setChooseModeButtonVisible(true)
		self.gp_bpm_phaseDiff.setName("BPMs Phase Difference: ")
		self.gp_bpm_phaseDiff.setAxisNames("Cav Phase, [deg]","BPMs Phase Diff., [deg]")	
		self.gp_bpm_phaseDiff.setBorder(etched_border)
		self.add(self.gp_bpm_phaseDiff)
		
	def removeAllGraphData(self):
		self.gp_bpm_phaseDiff.removeAllGraphData()
			
	def updateGraphData(self):
		self.gp_bpm_phaseDiff.removeAllGraphData()
		scl_long_tuneup_phase_scan_controller = self.scl_long_tuneup_controller.scl_long_tuneup_phase_scan_controller
		cavs_table = scl_long_tuneup_phase_scan_controller.cavs_table
		cav_selected_inds = cavs_table.getSelectedRows()
		if(len(cav_selected_inds) == 0 or cav_selected_inds[0] < 0):
			return
		for ind in cav_selected_inds:
			cav_wrapper = self.scl_long_tuneup_controller.cav0_wrapper
			if(ind != 0):
				cav_wrapper = self.scl_long_tuneup_controller.cav_wrappers[ind-1]
			if(cav_wrapper == null or not cav_wrapper.isGood): 
				continue
			self.gp_bpm_phaseDiff.addGraphData(cav_wrapper.phaseDiffPlot)
			self.gp_bpm_phaseDiff.addGraphData(cav_wrapper.phaseDiffPlotTh)
class Acceptance_Graphs_Panel_Holder():
	def __init__(self,dtl_acceptance_scans_controller):
		self.dtl_acceptance_scans_controller = dtl_acceptance_scans_controller
		self.main_loop_controller = self.dtl_acceptance_scans_controller.main_loop_controller
		#----------------------------------------
		etched_border = BorderFactory.createEtchedBorder()
		self.gp_acc_scan = FunctionGraphsJPanel()
		self.gp_scan_width = FunctionGraphsJPanel()
		#------------------------------------------
		self.gp_acc_scan.setLegendButtonVisible(true)
		self.gp_scan_width.setLegendButtonVisible(true)
		#------------------------------------------	
		self.gp_acc_scan.setChooseModeButtonVisible(true)
		self.gp_scan_width.setChooseModeButtonVisible(true)
		#------------------------------------------
		self.gp_acc_scan.setName("Acceptance Scan: FC vs. RF Phase")
		self.gp_scan_width.setName("Acc. Width vs. RF Ampl")
		self.gp_acc_scan.setAxisNames("Cav Phase, [deg]","FC Q, [a.u.]")
		self.gp_scan_width.setAxisNames("RF Amplitude, [a.u]","Acceptance Width, [deg]")
		self.gp_acc_scan.setBorder(etched_border)
		self.gp_scan_width.setBorder(etched_border)
		#---------------------------------------------
		self.graphs_panel = JTabbedPane()
		self.graphs_panel.add("Acceptance Scan Data",self.gp_acc_scan)
		self.graphs_panel.add("Acc. Width",self.gp_scan_width)
		
	def getGraphsPanel(self):
		return self.graphs_panel
		
	def refreshGraphs(self):
		self.gp_acc_scan.refreshGraphJPanel()
		self.gp_scan_width.refreshGraphJPanel()
Exemple #4
0
class OneGraphPanel:
    def __init__(self, title):
        self.gpF = FunctionGraphsJPanel()
        self.gpF.setLegendButtonVisible(true)
        self.gpF.setChooseModeButtonVisible(true)
        self.gpF.setName(title)
        self.gpF.setAxisNames("time, [sec]", "Value, [arb. units]")
        etched_border = BorderFactory.createEtchedBorder()
        self.gpF.setBorder(etched_border)
        self.gd_arr = []
        self.color_arr = [
            Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, Color.MAGENTA
        ]

    def clean(self):
        self.gpF.removeAllGraphData()
        self.gd_arr = []

    def addGraph(self, pv_name, time_arr, val_arr):
        ind = len(self.gd_arr) % len(self.color_arr)
        gd = BasicGraphData()
        gd.setGraphProperty("Legend", pv_name)
        gd.addPoint(time_arr, val_arr)
        gd.setGraphColor(self.color_arr[ind])
        self.gpF.addGraphData(gd)
        self.gd_arr.append(gd)
class Table_and_Plots_Panel(JPanel):
	def __init__(self,scl_long_tuneup_controller):
		self.scl_long_tuneup_controller = scl_long_tuneup_controller
		self.setLayout(BorderLayout())
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		titled_border = BorderFactory.createTitledBorder(etched_border,"BPM Table and Plots")
		self.setBorder(titled_border)	
		#----------------------------------------
		self.bpm_table = JTable(Energy_Meter_BPMs_Table_Model(self.scl_long_tuneup_controller))
		self.bpm_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
		self.bpm_table.setFillsViewportHeight(true)
		self.bpm_table.setPreferredScrollableViewportSize(Dimension(400,300))	
		scrl_panel = JScrollPane(self.bpm_table)
		scrl_panel.setBorder(etched_border)
		bpm_table_panel = JPanel(BorderLayout())
		bpm_table_panel.add(scrl_panel,BorderLayout.WEST)
		#-----------------------------------------
		self.gp_bpm_phase_err = FunctionGraphsJPanel()
		self.gp_bpm_phase_err.setLegendButtonVisible(true)
		self.gp_bpm_phase_err.setChooseModeButtonVisible(true)	
		self.gp_bpm_phase_err.setName("BPM Phase Errors")
		self.gp_bpm_phase_err.setAxisNames("position, [m]","BPM Phase Error, [deg]")	
		self.gp_bpm_phase_err.setBorder(etched_border)
		bpm_graph_panel = JPanel(BorderLayout())
		bpm_graph_panel.add(self.gp_bpm_phase_err)
		#------graph data 
		self.bpm_phase_err_gd = BasicGraphData()
		self.bpm_phase_err_gd.setGraphPointSize(8)
		self.bpm_phase_err_gd.setDrawLinesOn(false)
		self.bpm_phase_err_gd.setGraphColor(Color.BLUE)	
		self.gp_bpm_phase_err.addGraphData(self.bpm_phase_err_gd)
		#-----------------------------------------
		self.add(bpm_table_panel,BorderLayout.WEST)	
		self.add(bpm_graph_panel,BorderLayout.CENTER)	
class BPMs_Amp_Phase_Graphs_Panel(JPanel):
	def __init__(self,scl_long_tuneup_controller):
		self.scl_long_tuneup_controller = scl_long_tuneup_controller
		self.setLayout(GridLayout(2,1))
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		self.setBorder(etched_border)
		self.gp_bpm_phases = FunctionGraphsJPanel()
		self.gp_bpm_amps = FunctionGraphsJPanel()
		self.gp_bpm_phases.setLegendButtonVisible(true)
		self.gp_bpm_phases.setChooseModeButtonVisible(true)	
		self.gp_bpm_amps.setLegendButtonVisible(true)
		self.gp_bpm_amps.setChooseModeButtonVisible(true)
		self.gp_bpm_phases.setName("BPM Phases")
		self.gp_bpm_phases.setAxisNames("Cav Phase, [deg]","BPM Phase, [deg]")	
		self.gp_bpm_amps.setName("BPM Amplitude")
		self.gp_bpm_amps.setAxisNames("Cav Phase, [deg]","Amplitude, a.u.")	
		self.gp_bpm_phases.setBorder(etched_border)
		self.gp_bpm_amps.setBorder(etched_border)
		self.add(self.gp_bpm_phases)
		self.add(self.gp_bpm_amps)	
		
	def removeAllGraphData(self):
		self.gp_bpm_phases.removeAllGraphData()
		self.gp_bpm_amps.removeAllGraphData()		
		
	def updateGraphData(self):
		self.gp_bpm_phases.removeAllGraphData()
		self.gp_bpm_amps.removeAllGraphData()
		scl_long_tuneup_phase_scan_controller = self.scl_long_tuneup_controller.scl_long_tuneup_phase_scan_controller
		bpms_table = scl_long_tuneup_phase_scan_controller.bpms_table
		bpms_table_model = scl_long_tuneup_phase_scan_controller.bpms_table_model
		bpm_wrappers = bpms_table_model.bpm_wrappers
		bpm_selected_inds = bpms_table.getSelectedRows()
		if(len(bpm_selected_inds) == 0 or bpm_selected_inds[0] < 0):
			return
		cav_wrapper = bpms_table_model.cav_wrapper
		if(cav_wrapper == null or not cav_wrapper.isGood): return
		for ind in bpm_selected_inds:
			bpm_wrapper = bpm_wrappers[ind]
			(graphDataAmp,graphDataPhase) = cav_wrapper.getAmpPhaseGraphs(bpm_wrapper)
			if(graphDataAmp != null):
				self.gp_bpm_amps.addGraphData(graphDataAmp)
			if(graphDataPhase != null):
				self.gp_bpm_phases.addGraphData(graphDataPhase)
Exemple #7
0
class Bad_BPMs_Amp_Phase_Graphs_Panel(JPanel):
    def __init__(self, scl_scan_data_cleanup_controller):
        self.scl_scan_data_cleanup_controller = scl_scan_data_cleanup_controller
        self.setLayout(GridLayout(2, 1))
        #----etched border
        etched_border = BorderFactory.createEtchedBorder()
        self.setBorder(etched_border)
        self.gp_bpm_phases = FunctionGraphsJPanel()
        self.gp_bpm_amps = FunctionGraphsJPanel()
        self.gp_bpm_phases.setLegendButtonVisible(true)
        self.gp_bpm_phases.setChooseModeButtonVisible(true)
        self.gp_bpm_amps.setLegendButtonVisible(true)
        self.gp_bpm_amps.setChooseModeButtonVisible(true)
        self.gp_bpm_phases.setName("BPM Phases")
        self.gp_bpm_phases.setAxisNames("Cav Phase, [deg]", "BPM Phase, [deg]")
        self.gp_bpm_amps.setName("BPM Amplitude")
        self.gp_bpm_amps.setAxisNames("Cav Phase, [deg]", "Amplitude, a.u.")
        self.gp_bpm_phases.setBorder(etched_border)
        self.gp_bpm_amps.setBorder(etched_border)
        self.add(self.gp_bpm_phases)
        self.add(self.gp_bpm_amps)

    def removeAllGraphData(self):
        self.gp_bpm_phases.removeAllGraphData()
        self.gp_bpm_amps.removeAllGraphData()

    def updateGraphData(self):
        self.gp_bpm_phases.removeAllGraphData()
        self.gp_bpm_amps.removeAllGraphData()
        bpms_table = self.scl_scan_data_cleanup_controller.bpms_table
        cavs_table = self.scl_scan_data_cleanup_controller.cavs_table
        bpm_wrappers = self.scl_scan_data_cleanup_controller.bpms_arr
        cav_wrappers = self.scl_scan_data_cleanup_controller.cavs_with_bad_data_arr
        bpm_selected_ind = bpms_table.getSelectedRow()
        cav_selected_ind = cavs_table.getSelectedRow()
        if (bpm_selected_ind >= 0 and cav_selected_ind >= 0):
            bpm_wrapper = bpm_wrappers[bpm_selected_ind]
            cav_wrapper = cav_wrappers[cav_selected_ind]
            (graphDataAmp,
             graphDataPhase) = cav_wrapper.getAmpPhaseGraphs(bpm_wrapper)
            if (graphDataAmp != null):
                self.gp_bpm_amps.addGraphData(graphDataAmp)
            if (graphDataPhase != null):
                self.gp_bpm_phases.addGraphData(graphDataPhase)
class OneGraphPanel:
	def __init__(self, title):
		self.gpF = FunctionGraphsJPanel()
		self.gpF.setLegendButtonVisible(true)
		self.gpF.setChooseModeButtonVisible(true)			
		self.gpF.setName(title)
		self.gpF.setAxisNames("time, [sec]","Value, [arb. units]")	
		etched_border = BorderFactory.createEtchedBorder()
		self.gpF.setBorder(etched_border)
		self.gd_arr = []
		self.color_arr = [Color.BLUE,Color.BLACK,Color.RED,Color.GREEN,Color.MAGENTA]
	
	def clean(self):
		self.gpF.removeAllGraphData()
		self.gd_arr = []
	
	def addGraph(self,pv_name,time_arr,val_arr):
		ind = len(self.gd_arr)%len(self.color_arr)
		gd = BasicGraphData()
		gd.setGraphProperty("Legend",pv_name)
		gd.addPoint(time_arr,val_arr)
		gd.setGraphColor(self.color_arr[ind])
		self.gpF.addGraphData(gd)
		self.gd_arr.append(gd)
Exemple #9
0
class Graphs_Panel(JPanel):
	def __init__(self,transverse_twiss_analysis_Controller):
		self.transverse_twiss_analysis_Controller = transverse_twiss_analysis_Controller
		self.setLayout(GridLayout(3,1))
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		self.setBorder(etched_border)
		self.gpanel_hor = FunctionGraphsJPanel()
		self.gpanel_ver = FunctionGraphsJPanel()
		self.gpanel_lon = FunctionGraphsJPanel()		
		self.gpanel_hor.setLegendButtonVisible(true)
		self.gpanel_ver.setLegendButtonVisible(true)
		self.gpanel_lon.setLegendButtonVisible(true)
		self.gpanel_hor.setName("Horizontal Size")
		self.gpanel_hor.setAxisNames("pos, [m]","Size, [mm]")	
		self.gpanel_ver.setName("Vertical Size")
		self.gpanel_ver.setAxisNames("pos, [m]","Size, [mm]")	
		self.gpanel_lon.setName("Longitudinal Size, RF Freq. = 402.5 MHz")
		self.gpanel_lon.setAxisNames("pos, [m]","Size, [deg]")	
		self.gpanel_hor.setBorder(etched_border)
		self.gpanel_ver.setBorder(etched_border)
		self.gpanel_lon.setBorder(etched_border)
		self.add(self.gpanel_hor)
		self.add(self.gpanel_ver)	
		self.add(self.gpanel_lon)
		
	def removeAllGraphData(self):
		self.gpanel_hor.removeAllGraphData()
		self.gpanel_ver.removeAllGraphData()
		self.gpanel_lon.removeAllGraphData()		
		
	def updateGraphData(self):
		self.gpanel_hor.removeAllGraphData()
		self.gpanel_ver.removeAllGraphData()
		self.gpanel_lon.removeAllGraphData()
		accStatesKeeper = self.transverse_twiss_analysis_Controller.accStatesKeeper
		accStatesKeeper.updateGraphData()
		accState = null
		for accState0 in accStatesKeeper.getAccStatesArr():
			if(accState0.isSelected()):
				accState = accState0
				break
		if(accState == null): return
		accState.updateGraphData()
		self.gpanel_hor.addGraphData(accState.gd_exp_hor)
		self.gpanel_hor.addGraphData(accState.gd_model_hor)
		self.gpanel_ver.addGraphData(accState.gd_exp_ver)
		self.gpanel_ver.addGraphData(accState.gd_model_ver)
		self.gpanel_lon.addGraphData(accState.gd_model_lon)
		#---set up vertical lines
		self.gpanel_hor.removeHorizontalValues()
		self.gpanel_ver.removeHorizontalValues()
		self.gpanel_lon.removeHorizontalValues()
		self.gpanel_hor.removeVerticalValues()
		self.gpanel_ver.removeVerticalValues()
		self.gpanel_lon.removeVerticalValues()
		accSeq = self.transverse_twiss_analysis_Controller.linac_wizard_document.accSeq
		quads = accSeq.getAllNodesWithQualifier((AndTypeQualifier().and((OrTypeQualifier()).or(Quadrupole.s_strType))).andStatus(true))
		cavs = accSeq.getAllNodesWithQualifier((AndTypeQualifier().and((OrTypeQualifier()).or(RfCavity.s_strType))).andStatus(true))
		for quad in quads:
			pos = accSeq.getPosition(quad)
			self.gpanel_hor.addVerticalLine(pos,Color.BLACK)
			self.gpanel_ver.addVerticalLine(pos,Color.BLACK)
			self.gpanel_lon.addVerticalLine(pos,Color.BLACK)															 
		for cav in cavs:	
			pos = accSeq.getPosition(cav)	
			self.gpanel_hor.addVerticalLine(pos,Color.RED)
			self.gpanel_ver.addVerticalLine(pos,Color.RED)
			self.gpanel_lon.addVerticalLine(pos,Color.RED)
Exemple #10
0
class WS_Data_Analysis_Controller:
	""" 
	This controller manages the WS data analysis. 
	Its panel is in the WS_LW_Acquisition_Controller panel. 
	"""
	def __init__(self,ws_lw_acquisition_controller):
		self.ws_lw_acquisition_controller = ws_lw_acquisition_controller
		self.local_gauss_fitter = Local_Gauss_Fitter()
		self.main_panel = JPanel(BorderLayout())
		self.ws_records_table_model = WS_Records_Table_Model()
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		#---make the WS_Records_JTable + Graph Panel
		self.records_table = JTable(self.ws_records_table_model)
		self.records_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
		self.records_table.setFillsViewportHeight(true)
		#----set up records_table columns width
		columnModel = self.records_table.getColumnModel()
		columnModel.getColumn(0).setPreferredWidth(30)
		columnModel.getColumn(1).setPreferredWidth(160)
		columnModel.getColumn(2).setPreferredWidth(40)
		columnModel.getColumn(3).setPreferredWidth(40)
		columnModel.getColumn(4).setPreferredWidth(80)
		columnModel.getColumn(5).setPreferredWidth(70)
		columnModel.getColumn(6).setPreferredWidth(70)
		#---------------------------------------------------
		records_panel = JPanel(BorderLayout())
		records_panel.add(JScrollPane(self.records_table), BorderLayout.CENTER)
		knobs_gauss_panel = JPanel(BorderLayout())
		records_panel.add(knobs_gauss_panel, BorderLayout.SOUTH)
		records_panel.setBorder(etched_border)
		#---records knobs ---------------------------------------------
		records_knobs_panel = JPanel(FlowLayout(FlowLayout.CENTER,5,5))
		guess_and_fit_button = JButton("Guess and Fit")
		analysis_all_button = JButton("G&F All")		
		fit_button = JButton("Fit")
		fit_all_button = JButton("Fit All")
		send_to_twiss_button = JButton("Send to Twiss Analysis")
		records_knobs_panel.add(guess_and_fit_button)
		records_knobs_panel.add(analysis_all_button)		
		records_knobs_panel.add(fit_button)
		records_knobs_panel.add(fit_all_button)
		records_knobs_panel.add(send_to_twiss_button)
		guess_and_fit_button.addActionListener(Guess_And_Fit_Listener(self.ws_lw_acquisition_controller))
		fit_button.addActionListener(Fit_Listener(self.ws_lw_acquisition_controller))
		fit_all_button.addActionListener(Fit_All_Listener(self.ws_lw_acquisition_controller))
		analysis_all_button.addActionListener(Guess_And_Fit_All_Listener(self.ws_lw_acquisition_controller))
		send_to_twiss_button.addActionListener(SendToAnalysis_Listener(self.ws_lw_acquisition_controller))
		self.gauss_fit_param_panel = GaussFitDataPanel()
		knobs_gauss_panel.add(records_knobs_panel, BorderLayout.NORTH)
		knobs_gauss_panel.add(self.gauss_fit_param_panel, BorderLayout.SOUTH)
		#---------------------------------------------------------
		self.record_analysis_panel = JPanel(BorderLayout())
		border = BorderFactory.createTitledBorder(etched_border,"WS/LW Wave Form Analysis")
		self.record_analysis_panel.setBorder(border)
		self.record_analysis_panel.add(records_panel, BorderLayout.WEST)
		self.gpanel_WF = FunctionGraphsJPanel()
		self.gpanel_WF.setLegendButtonVisible(true)
		self.gpanel_WF.setChooseModeButtonVisible(true)			
		self.gpanel_WF.setName("Profile")
		self.gpanel_WF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_WF.setBorder(etched_border)
		self.gpanel_WF.addVerticalLine(-1.0e+30,Color.red)
		self.gpanel_WF.addVerticalLine(+1.0e+30,Color.red)
		self.gpanel_WF.setVerLinesButtonVisible(true)
		self.gpanel_WF.addDraggedVerLinesListener(Position_Limits_Listener(self.ws_lw_acquisition_controller))
		write_waveforms_to_ascii_button = JButton("Write Waveforms to ASCII File")
		write_waveforms_to_ascii_button.addActionListener(Write_Waveforms_to_ASCII_Listener(self.ws_lw_acquisition_controller))
		below_graph_panel = JPanel(FlowLayout(FlowLayout.LEFT,5,5))
		below_graph_panel.add(write_waveforms_to_ascii_button)
		graph_panel_left = JPanel(BorderLayout())
		graph_panel_left.add(self.gpanel_WF, BorderLayout.CENTER)	
		graph_panel_left.add(below_graph_panel, BorderLayout.SOUTH)
		self.record_analysis_panel.add(graph_panel_left, BorderLayout.CENTER)		
		self.main_panel.add(self.record_analysis_panel, BorderLayout.CENTER)
		#---set up Listeners 
		self.records_table.getSelectionModel().addListSelectionListener(WS_Record_Table_Selection_Listener(self.ws_lw_acquisition_controller))

	def setDataToGraphPanel(self,ws_record):
		self.gpanel_WF.removeAllGraphData()
		self.gpanel_WF.addGraphData(ws_record.gd_wf)
		self.gpanel_WF.addGraphData(ws_record.gd_fit_wf)
Exemple #11
0
class WS_LW_Acquisition_Controller:
	def __init__(self,linac_wizard_document):
		#--- linac_wizard_document the parent document for all controllers
		self.linac_wizard_document = linac_wizard_document		
		self.main_panel = JPanel(GridLayout(2,1))
		self.quadFieldDict = {}
		self.cavAmpPhaseDict = {}
		self.quads = []
		self.cavs = []
		self.ws_table_model = WS_Table_Model()
		#----make LW or WS nodes
		self.ws_nodes = []
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		#---make the WS_JTable + H&V Graphs Panels
		self.ws_table = JTable(self.ws_table_model)
		self.ws_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
		self.ws_table.setFillsViewportHeight(true)	
		ws_panel = JPanel(BorderLayout())
		ws_panel.add(JScrollPane(self.ws_table), BorderLayout.CENTER)
		ws_knobs_panel = JPanel(FlowLayout(FlowLayout.CENTER,5,5))
		ws_panel.add(ws_knobs_panel, BorderLayout.SOUTH)
		ws_panel.setBorder(etched_border)
		#---ws knobs ---------------------------------------------
		get_ws_data_button = JButton("Get WS/LW Data")
		switch_hv_button = JButton(" Switch H/V  ")	
		add_data_to_pool_button = JButton("  Add Data to Pool  ")
		ws_knobs_panel.add(get_ws_data_button)
		ws_knobs_panel.add(switch_hv_button)
		ws_knobs_panel.add(add_data_to_pool_button)
		get_ws_data_button.addActionListener(WS_GET_Data_Listener(self))
		switch_hv_button.addActionListener(Switch_HV_Listener(self))
		add_data_to_pool_button.addActionListener(WS_Data_to_Pool_Listener(self))
		#---------------------------------------------------------
		ws_and_graphs_panel = JPanel(BorderLayout())
		border = BorderFactory.createTitledBorder(etched_border,"WS/LW Raw Data Acquisition")
		ws_and_graphs_panel.setBorder(border)
		ws_and_graphs_panel.add(ws_panel, BorderLayout.WEST)
		graphs_panel = JPanel(GridLayout(1,2))
		self.gpanel_horWF = FunctionGraphsJPanel()
		self.gpanel_verWF = FunctionGraphsJPanel()
		self.gpanel_horWF.setLegendButtonVisible(true)
		self.gpanel_horWF.setChooseModeButtonVisible(true)			
		self.gpanel_verWF.setLegendButtonVisible(true)
		self.gpanel_verWF.setChooseModeButtonVisible(true)			
		self.gpanel_horWF.setName("Horizontal Profiles")
		self.gpanel_horWF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_verWF.setName("Vertical Profiles")
		self.gpanel_verWF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_horWF.setBorder(etched_border)
		self.gpanel_verWF.setBorder(etched_border)
		graphs_panel.add(self.gpanel_horWF)
		graphs_panel.add(self.gpanel_verWF)
		ws_and_graphs_panel.add(graphs_panel, BorderLayout.CENTER)
		self.setDataToGraphPanels(-1)
		#------analysis sub-panel
		self.ws_data_analysis_controller = WS_Data_Analysis_Controller(self)
		#---put everything into the main_panel
		self.main_panel.add(ws_and_graphs_panel)
		self.main_panel.add(self.ws_data_analysis_controller.main_panel)
		#---set up Listeners 
		self.ws_table.getSelectionModel().addListSelectionListener(WS_Table_Selection_Listener(self))	
		
	def setAccSeq(self,accSeq):
		self.ws_table_model.ws_table_element_arr = []
		self.ws_nodes = []
		if(accSeq == null): 
			self.ws_table_model.fireTableDataChanged()
			return
		nodes = accSeq.filterNodesByStatus(accSeq.getAllNodesOfType(ProfileMonitor.s_strType),true)
		for node in nodes:
			self.ws_nodes.append(node)
		nodes = accSeq.filterNodesByStatus(accSeq.getAllNodesOfType(Marker.s_strType),true)
		for node in nodes:
			if(node.getId().find("LW") >= 0 and node.getId().find("SCL") >= 0):
				self.ws_nodes.append(node)
		for node in self.ws_nodes:
			self.ws_table_model.addWS_TableElement(WS_Table_Element(node))	
		self.makePVforWS()
		#ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		#for ws_table_element in ws_table_elements_arr:	
		#	ws_table_element.readPVData()
		#----update data and graphs
		self.ws_table_model.fireTableDataChanged()
		self.setDataToGraphPanels(-1)
		#------------set up the quad and cavities dictionaries
		self.quadFieldDict = {}
		self.quads = accSeq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(Quadrupole.s_strType)))
		for quad in self.quads:
			self.quadFieldDict[quad] = quad.getDfltField()
			"""
			if(quad.isPermanent()):
				self.quadFieldDict[quad] = quad.getDfltField()
			else:
				self.quadFieldDict[quad] = quad.getFieldReadback()
			"""
		self.cavAmpPhaseDict = {}
		rf_gaps = accSeq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(RfGap.s_strType)))	
		self.cavs = []
		for rf_gap in rf_gaps:
			cav = rf_gap.getParent()
			if(cav not in self.cavs):
				self.cavs.append(cav)
				amp = cav.getDfltCavAmp()
				phase = cav.getDfltCavPhase()
				self.cavAmpPhaseDict[cav] = [amp,phase]
			
	def cleanOldWSdata(self):
		#----clean all data for analysis -- may be we want to keep them?
		ws_data_analysis_controller = self.ws_data_analysis_controller
		ws_data_analysis_controller.ws_records_table_model.ws_rec_table_element_arr = []
		ws_data_analysis_controller.ws_records_table_model.fireTableDataChanged()
		tr_twiss_analysis_controller = self.linac_wizard_document.tr_twiss_analysis_controller
		accStatesKeeper = tr_twiss_analysis_controller.accStatesKeeper
		accStatesKeeper.clean()
		tr_twiss_analysis_controller.dict_panel.dict_table.getModel().fireTableDataChanged()

	def getFreshCopyQuadCavDict(self):
		""" Returns a copy of the fresh  dictionaries [quadFieldDict,cavAmpPhaseDict] """
		quadFieldDict = {}
		for quad in self.quads:
			if(quad.isPermanent()):
				self.quadFieldDict[quad] = quad.getDfltField()
			else:
				self.quadFieldDict[quad] = quad.getFieldReadback()
			quadFieldDict[quad] = self.quadFieldDict[quad]
			#print "debug quad=",quad.getId()," G=",self.quadFieldDict[quad]
		cavAmpPhaseDict = {}
		for cav in self.cavs:
			amp = cav.getDfltCavAmp()
			phase = cav.getDfltCavPhase()
			self.cavAmpPhaseDict[cav] = [amp,phase]
			cavAmpPhaseDict[cav] = [amp,phase]
		return [quadFieldDict,cavAmpPhaseDict]

	def getMainPanel(self):
		return self.main_panel
		
	def setDataToGraphPanels(self,index):
		self.gpanel_horWF.removeAllGraphData()
		self.gpanel_verWF.removeAllGraphData()
		ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		if(index < 0 or index >= len(ws_table_elements_arr)): return
		ws_table_element = ws_table_elements_arr[index]
		hor_record = ws_table_element.getRecords(WS_DIRECTION_HOR)
		ver_record = ws_table_element.getRecords(WS_DIRECTION_VER)			
		self.gpanel_horWF.addGraphData(hor_record.gd_wf)
		self.gpanel_verWF.addGraphData(ver_record.gd_wf)
				
	def makePVforWS(self):
		ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		for ws_table_element in ws_table_elements_arr:
			ws_node = ws_table_element.ws
			if(ws_node.getId().find("WS") >= 0):
				pv_pos_wf_name = ws_node.getId()+":Hor_prof_pos"
				pv_wf_name     = ws_node.getId()+":Hor_prof_sig"
				sigma_name     = ws_node.getId()+":Hor_Sigma_gs"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_HOR)
				pv_pos_wf_name = ws_node.getId()+":Ver_prof_pos"
				pv_wf_name     = ws_node.getId()+":Ver_prof_sig"
				sigma_name     = ws_node.getId()+":Ver_Sigma_gs"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_VER)
			else:
				name = ws_node.getId().replace(":LW",":LW_")+":LASER_WIRE_axis"
				pv_pos_wf_name = name+"01_ScanPosArray"
				pv_wf_name     = name+"01_Peak_Profile_WFM"
				sigma_name     = name+"01_Peak_Info_Sigma"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_HOR)
				pv_pos_wf_name = name+"02_ScanPosArray"
				pv_wf_name     = name+"02_Peak_Profile_WFM"
				sigma_name     = name+"02_Peak_Info_Sigma"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_VER)
class WS_Data_Analysis_Controller:
	""" 
	This controller manages the WS data analysis. 
	Its panel is in the WS_LW_Acquisition_Controller panel. 
	"""
	def __init__(self,ws_lw_acquisition_controller):
		self.ws_lw_acquisition_controller = ws_lw_acquisition_controller
		self.local_gauss_fitter = Local_Gauss_Fitter()
		self.main_panel = JPanel(BorderLayout())
		self.ws_records_table_model = WS_Records_Table_Model()
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		#---make the WS_Records_JTable + Graph Panel
		self.records_table = JTable(self.ws_records_table_model)
		self.records_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
		self.records_table.setFillsViewportHeight(true)
		#----set up records_table columns width
		columnModel = self.records_table.getColumnModel()
		columnModel.getColumn(0).setPreferredWidth(30)
		columnModel.getColumn(1).setPreferredWidth(160)
		columnModel.getColumn(2).setPreferredWidth(40)
		columnModel.getColumn(3).setPreferredWidth(40)
		columnModel.getColumn(4).setPreferredWidth(80)
		columnModel.getColumn(5).setPreferredWidth(70)
		columnModel.getColumn(6).setPreferredWidth(70)
		#---------------------------------------------------
		records_panel = JPanel(BorderLayout())
		records_panel.add(JScrollPane(self.records_table), BorderLayout.CENTER)
		knobs_gauss_panel = JPanel(BorderLayout())
		records_panel.add(knobs_gauss_panel, BorderLayout.SOUTH)
		records_panel.setBorder(etched_border)
		#---records knobs ---------------------------------------------
		records_knobs_panel = JPanel(FlowLayout(FlowLayout.CENTER,5,5))
		guess_and_fit_button = JButton("Guess and Fit")
		analysis_all_button = JButton("G&F All")		
		fit_button = JButton("Fit")
		fit_all_button = JButton("Fit All")
		send_to_twiss_button = JButton("Send to Twiss Analysis")
		records_knobs_panel.add(guess_and_fit_button)
		records_knobs_panel.add(analysis_all_button)		
		records_knobs_panel.add(fit_button)
		records_knobs_panel.add(fit_all_button)
		records_knobs_panel.add(send_to_twiss_button)
		guess_and_fit_button.addActionListener(Guess_And_Fit_Listener(self.ws_lw_acquisition_controller))
		fit_button.addActionListener(Fit_Listener(self.ws_lw_acquisition_controller))
		fit_all_button.addActionListener(Fit_All_Listener(self.ws_lw_acquisition_controller))
		analysis_all_button.addActionListener(Guess_And_Fit_All_Listener(self.ws_lw_acquisition_controller))
		send_to_twiss_button.addActionListener(SendToAnalysis_Listener(self.ws_lw_acquisition_controller))
		self.gauss_fit_param_panel = GaussFitDataPanel()
		knobs_gauss_panel.add(records_knobs_panel, BorderLayout.NORTH)
		knobs_gauss_panel.add(self.gauss_fit_param_panel, BorderLayout.SOUTH)
		#---------------------------------------------------------
		self.record_analysis_panel = JPanel(BorderLayout())
		border = BorderFactory.createTitledBorder(etched_border,"WS/LW Wave Form Analysis")
		self.record_analysis_panel.setBorder(border)
		self.record_analysis_panel.add(records_panel, BorderLayout.WEST)
		self.gpanel_WF = FunctionGraphsJPanel()
		self.gpanel_WF.setLegendButtonVisible(true)
		self.gpanel_WF.setChooseModeButtonVisible(true)			
		self.gpanel_WF.setName("Profile")
		self.gpanel_WF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_WF.setBorder(etched_border)
		self.gpanel_WF.addVerticalLine(-1.0e+30,Color.red)
		self.gpanel_WF.addVerticalLine(+1.0e+30,Color.red)
		self.gpanel_WF.setVerLinesButtonVisible(true)
		self.gpanel_WF.addDraggedVerLinesListener(Position_Limits_Listener(self.ws_lw_acquisition_controller))
		self.record_analysis_panel.add(self.gpanel_WF, BorderLayout.CENTER)
		self.main_panel.add(self.record_analysis_panel, BorderLayout.CENTER)
		#---set up Listeners 
		self.records_table.getSelectionModel().addListSelectionListener(WS_Record_Table_Selection_Listener(self.ws_lw_acquisition_controller))

	def setDataToGraphPanel(self,ws_record):
		self.gpanel_WF.removeAllGraphData()
		self.gpanel_WF.addGraphData(ws_record.gd_wf)
		self.gpanel_WF.addGraphData(ws_record.gd_fit_wf)
class WS_LW_Acquisition_Controller:
	def __init__(self,linac_wizard_document):
		#--- linac_wizard_document the parent document for all controllers
		self.linac_wizard_document = linac_wizard_document		
		self.main_panel = JPanel(GridLayout(2,1))
		self.quadFieldDict = {}
		self.cavAmpPhaseDict = {}
		self.quads = []
		self.cavs = []
		self.ws_table_model = WS_Table_Model()
		#----make LW or WS nodes
		self.ws_nodes = []
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		#---make the WS_JTable + H&V Graphs Panels
		self.ws_table = JTable(self.ws_table_model)
		self.ws_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
		self.ws_table.setFillsViewportHeight(true)	
		ws_panel = JPanel(BorderLayout())
		ws_panel.add(JScrollPane(self.ws_table), BorderLayout.CENTER)
		ws_knobs_panel = JPanel(FlowLayout(FlowLayout.CENTER,5,5))
		ws_panel.add(ws_knobs_panel, BorderLayout.SOUTH)
		ws_panel.setBorder(etched_border)
		#---ws knobs ---------------------------------------------
		get_ws_data_button = JButton("Get WS/LW Data")
		switch_hv_button = JButton(" Switch H/V  ")	
		add_data_to_pool_button = JButton("  Add Data to Pool  ")
		ws_knobs_panel.add(get_ws_data_button)
		ws_knobs_panel.add(switch_hv_button)
		ws_knobs_panel.add(add_data_to_pool_button)
		get_ws_data_button.addActionListener(WS_GET_Data_Listener(self))
		switch_hv_button.addActionListener(Switch_HV_Listener(self))
		add_data_to_pool_button.addActionListener(WS_Data_to_Pool_Listener(self))
		#---------------------------------------------------------
		ws_and_graphs_panel = JPanel(BorderLayout())
		border = BorderFactory.createTitledBorder(etched_border,"WS/LW Raw Data Acquisition")
		ws_and_graphs_panel.setBorder(border)
		ws_and_graphs_panel.add(ws_panel, BorderLayout.WEST)
		graphs_panel = JPanel(GridLayout(1,2))
		self.gpanel_horWF = FunctionGraphsJPanel()
		self.gpanel_verWF = FunctionGraphsJPanel()
		self.gpanel_horWF.setLegendButtonVisible(true)
		self.gpanel_horWF.setChooseModeButtonVisible(true)			
		self.gpanel_verWF.setLegendButtonVisible(true)
		self.gpanel_verWF.setChooseModeButtonVisible(true)			
		self.gpanel_horWF.setName("Horizontal Profiles")
		self.gpanel_horWF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_verWF.setName("Vertical Profiles")
		self.gpanel_verWF.setAxisNames("pos, [mm]","Amp, [arb. units]")	
		self.gpanel_horWF.setBorder(etched_border)
		self.gpanel_verWF.setBorder(etched_border)
		graphs_panel.add(self.gpanel_horWF)
		graphs_panel.add(self.gpanel_verWF)
		ws_and_graphs_panel.add(graphs_panel, BorderLayout.CENTER)
		self.setDataToGraphPanels(-1)
		#------analysis sub-panel
		self.ws_data_analysis_controller = WS_Data_Analysis_Controller(self)
		#---put everything into the main_panel
		self.main_panel.add(ws_and_graphs_panel)
		self.main_panel.add(self.ws_data_analysis_controller.main_panel)
		#---set up Listeners 
		self.ws_table.getSelectionModel().addListSelectionListener(WS_Table_Selection_Listener(self))	
		
	def setAccSeq(self,accSeq):
		self.ws_table_model.ws_table_element_arr = []
		self.ws_nodes = []
		if(accSeq == null): 
			self.ws_table_model.fireTableDataChanged()
			return
		nodes = accSeq.filterNodesByStatus(accSeq.getAllNodesOfType(ProfileMonitor.s_strType),true)
		for node in nodes:
			self.ws_nodes.append(node)
		nodes = accSeq.filterNodesByStatus(accSeq.getAllNodesOfType(Marker.s_strType),true)
		for node in nodes:
			if(node.getId().find("LW") >= 0 and node.getId().find("SCL") >= 0):
				self.ws_nodes.append(node)
		for node in self.ws_nodes:
			self.ws_table_model.addWS_TableElement(WS_Table_Element(node))	
		self.makePVforWS()
		#ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		#for ws_table_element in ws_table_elements_arr:	
		#	ws_table_element.readPVData()
		#----update data and graphs
		self.ws_table_model.fireTableDataChanged()
		self.setDataToGraphPanels(-1)
		#------------set up the quad and cavities dictionaries
		self.quadFieldDict = {}
		self.quads = accSeq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(Quadrupole.s_strType)))
		for quad in self.quads:
			self.quadFieldDict[quad] = quad.getDfltField()
			"""
			if(quad.isPermanent()):
				self.quadFieldDict[quad] = quad.getDfltField()
			else:
				self.quadFieldDict[quad] = quad.getFieldReadback()
			"""
		self.cavAmpPhaseDict = {}
		rf_gaps = accSeq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(RfGap.s_strType)))	
		self.cavs = []
		for rf_gap in rf_gaps:
			cav = rf_gap.getParent()
			if(cav not in self.cavs):
				self.cavs.append(cav)
				amp = cav.getDfltCavAmp()
				phase = cav.getDfltCavPhase()
				self.cavAmpPhaseDict[cav] = [amp,phase]
			
	def cleanOldWSdata(self):
		#----clean all data for analysis -- may be we want to keep them?
		ws_data_analysis_controller = self.ws_data_analysis_controller
		ws_data_analysis_controller.ws_records_table_model.ws_rec_table_element_arr = []
		ws_data_analysis_controller.ws_records_table_model.fireTableDataChanged()
		tr_twiss_analysis_controller = self.linac_wizard_document.tr_twiss_analysis_controller
		accStatesKeeper = tr_twiss_analysis_controller.accStatesKeeper
		accStatesKeeper.clean()
		tr_twiss_analysis_controller.dict_panel.dict_table.getModel().fireTableDataChanged()

	def getFreshCopyQuadCavDict(self):
		""" Returns a copy of the fresh  dictionaries [quadFieldDict,cavAmpPhaseDict] """
		quadFieldDict = {}
		for quad in self.quads:
			if(quad.isPermanent()):
				self.quadFieldDict[quad] = quad.getDfltField()
			else:
				self.quadFieldDict[quad] = quad.getFieldReadback()
			quadFieldDict[quad] = self.quadFieldDict[quad]
			#print "debug quad=",quad.getId()," G=",self.quadFieldDict[quad]
		cavAmpPhaseDict = {}
		for cav in self.cavs:
			amp = cav.getDfltCavAmp()
			phase = cav.getDfltCavPhase()
			self.cavAmpPhaseDict[cav] = [amp,phase]
			cavAmpPhaseDict[cav] = [amp,phase]
		return [quadFieldDict,cavAmpPhaseDict]

	def getMainPanel(self):
		return self.main_panel
		
	def setDataToGraphPanels(self,index):
		self.gpanel_horWF.removeAllGraphData()
		self.gpanel_verWF.removeAllGraphData()
		ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		if(index < 0 or index >= len(ws_table_elements_arr)): return
		ws_table_element = ws_table_elements_arr[index]
		hor_record = ws_table_element.getRecords(WS_DIRECTION_HOR)
		ver_record = ws_table_element.getRecords(WS_DIRECTION_VER)			
		self.gpanel_horWF.addGraphData(hor_record.gd_wf)
		self.gpanel_verWF.addGraphData(ver_record.gd_wf)
				
	def makePVforWS(self):
		ws_table_elements_arr = self.ws_table_model.getWS_TableElements()
		for ws_table_element in ws_table_elements_arr:
			ws_node = ws_table_element.ws
			if(ws_node.getId().find("WS") >= 0):
				pv_pos_wf_name = ws_node.getId()+":Hor_prof_pos"
				pv_wf_name     = ws_node.getId()+":Hor_prof_sig"
				sigma_name     = ws_node.getId()+":Hor_Sigma_gs"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_HOR)
				pv_pos_wf_name = ws_node.getId()+":Ver_prof_pos"
				pv_wf_name     = ws_node.getId()+":Ver_prof_sig"
				sigma_name     = ws_node.getId()+":Ver_Sigma_gs"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_VER)
			else:
				name = ws_node.getId().replace(":LW",":LW_")+":LASER_WIRE_axis"
				pv_pos_wf_name = name+"01_ScanPosArray"
				pv_wf_name     = name+"01_Peak_Profile_WFM"
				sigma_name     = name+"01_Peak_Info_Sigma"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_HOR)
				pv_pos_wf_name = name+"02_ScanPosArray"
				pv_wf_name     = name+"02_Peak_Profile_WFM"
				sigma_name     = name+"02_Peak_Info_Sigma"
				ws_table_element.setPV_Names(pv_pos_wf_name,pv_wf_name,sigma_name,WS_DIRECTION_VER)
class Orbit_Diff_Graphs_Panel(JPanel):
	def __init__(self,mebt_main_orbit_diff_cntrl):
		self.mebt_main_orbit_diff_cntrl = mebt_main_orbit_diff_cntrl
		self.setLayout(BorderLayout())
		tabbedPane = JTabbedPane()
		#----etched border
		etched_border = BorderFactory.createEtchedBorder()
		#---- plots for Hor-Ver and Longitudinal
		self.hor_plot = FunctionGraphsJPanel()
		self.hor_plot.setLegendButtonVisible(true)
		self.hor_plot.setChooseModeButtonVisible(true)
		self.hor_plot.setName("Horizontal Plane (Vert.Lns.: Black:quads Blue:DC Red:Cavs)")
		self.hor_plot.setAxisNames("Position, m","X[mm]")	
		self.hor_plot.setBorder(etched_border)		
		self.ver_plot = FunctionGraphsJPanel()
		self.ver_plot.setLegendButtonVisible(true)
		self.ver_plot.setChooseModeButtonVisible(true)
		self.ver_plot.setName("Vertical Plane (Vert.Lns.: Black:quads Blue:DC Red:Cavs)")
		self.ver_plot.setAxisNames("Position, m","Y[mm]")	
		self.ver_plot.setBorder(etched_border)		
		#------------------------------------------------
		self.hor_diff_plot = FunctionGraphsJPanel()
		self.hor_diff_plot.setLegendButtonVisible(true)
		self.hor_diff_plot.setChooseModeButtonVisible(true)
		self.hor_diff_plot.setName("Horizontal Plane (Vert.Lns.: Black:quads Blue:DC Red:Cavs)")
		self.hor_diff_plot.setAxisNames("Position, m","Diff X[mm]")	
		self.hor_diff_plot.setBorder(etched_border)		
		self.ver_diff_plot = FunctionGraphsJPanel()
		self.ver_diff_plot.setLegendButtonVisible(true)
		self.ver_diff_plot.setChooseModeButtonVisible(true)
		self.ver_diff_plot.setName("Vertical Plane (Vert.Lns.: Black:quads Blue:DC Red:Cavs)")
		self.ver_diff_plot.setAxisNames("Position, m","Diff Y[mm]")	
		self.ver_diff_plot.setBorder(etched_border)	
		#--------------------------------------------------------------------
		quad_wrappers = self.mebt_main_orbit_diff_cntrl.quad_wrappers
		dc_wrappers = self.mebt_main_orbit_diff_cntrl.dc_wrappers
		mebt_cav_wrappers = self.mebt_main_orbit_diff_cntrl.mebt_cav_wrappers
		for wrapper in quad_wrappers:
			self.hor_plot.addVerticalLine(wrapper.pos,Color.BLACK)
			self.ver_plot.addVerticalLine(wrapper.pos,Color.BLACK)
			self.hor_diff_plot.addVerticalLine(wrapper.pos,Color.BLACK)
			self.ver_diff_plot.addVerticalLine(wrapper.pos,Color.BLACK)
		for wrapper in dc_wrappers:
			self.hor_plot.addVerticalLine(wrapper.pos,Color.BLUE)
			self.ver_plot.addVerticalLine(wrapper.pos,Color.BLUE)
			self.hor_diff_plot.addVerticalLine(wrapper.pos,Color.BLUE)
			self.ver_diff_plot.addVerticalLine(wrapper.pos,Color.BLUE)
		for wrapper in mebt_cav_wrappers:
			self.hor_plot.addVerticalLine(wrapper.pos,Color.RED)
			self.ver_plot.addVerticalLine(wrapper.pos,Color.RED)
			self.hor_diff_plot.addVerticalLine(wrapper.pos,Color.RED)
			self.ver_diff_plot.addVerticalLine(wrapper.pos,Color.RED)
		#---------------------------------------------------------------------
		#--------------------------------------------------
		#---- panels
		graph_diff_panel = JPanel(GridLayout(2,1))
		graph_diff_panel.add(self.hor_diff_plot)
		graph_diff_panel.add(self.ver_diff_plot)
		#----------------------------------
		graph_panel = JPanel(GridLayout(2,1))
		graph_panel.add(self.hor_plot)
		graph_panel.add(self.ver_plot)
		#----------------------------------
		tabbedPane.add("Orbit Difference",graph_diff_panel)
		tabbedPane.add("Orbit",graph_panel)
		#-------------------------------------
		self.x_model_gd = BasicGraphData()
		self.x_model_gd.setLineThick(3)
		self.x_model_gd.setGraphPointSize(7)
		self.x_model_gd.setGraphColor(Color.BLUE)
		self.x_model_gd.setGraphProperty(GRAPH_LEGEND_KEY,"X Model [mm]")
		self.x_model_gd.setDrawLinesOn(true)
		self.x_model_gd.setDrawPointsOn(false)
		#-------------------------------------
		self.y_model_gd = BasicGraphData()
		self.y_model_gd.setLineThick(3)
		self.y_model_gd.setGraphPointSize(7)
		self.y_model_gd.setGraphColor(Color.RED)
		self.y_model_gd.setGraphProperty(GRAPH_LEGEND_KEY,"Y Model [mm]")
		self.y_model_gd.setDrawLinesOn(true)
		self.y_model_gd.setDrawPointsOn(false)
		#-------------------------------------
		self.x_model_diff_gd = BasicGraphData()
		self.x_model_diff_gd.setLineThick(3)
		self.x_model_diff_gd.setGraphPointSize(7)
		self.x_model_diff_gd.setGraphColor(Color.BLUE)
		self.x_model_diff_gd.setGraphProperty(GRAPH_LEGEND_KEY,"X Diff Model [mm]")
		self.x_model_diff_gd.setDrawLinesOn(true)
		self.x_model_diff_gd.setDrawPointsOn(false)
		#-------------------------------------
		self.y_model_diff_gd = BasicGraphData()
		self.y_model_diff_gd.setLineThick(3)
		self.y_model_diff_gd.setGraphPointSize(7)
		self.y_model_diff_gd.setGraphColor(Color.RED)
		self.y_model_diff_gd.setGraphProperty(GRAPH_LEGEND_KEY,"Y Diff Model [mm]")
		self.y_model_diff_gd.setDrawLinesOn(true)
		self.y_model_diff_gd.setDrawPointsOn(false)
		#-------------------------------------
		#-------------------------------------
		self.x_bpm_gd = BasicGraphData()
		self.x_bpm_gd.setLineThick(3)
		self.x_bpm_gd.setGraphPointSize(7)
		self.x_bpm_gd.setGraphColor(Color.BLUE)
		self.x_bpm_gd.setGraphProperty(GRAPH_LEGEND_KEY,"X BPM [mm]")
		self.x_bpm_gd.setDrawLinesOn(false)
		self.x_bpm_gd.setDrawPointsOn(true)
		#-------------------------------------
		self.y_bpm_gd = BasicGraphData()
		self.y_bpm_gd.setLineThick(3)
		self.y_bpm_gd.setGraphPointSize(7)
		self.y_bpm_gd.setGraphColor(Color.RED)
		self.y_bpm_gd.setGraphProperty(GRAPH_LEGEND_KEY,"Y BPM [mm]")
		self.y_bpm_gd.setDrawLinesOn(false)
		self.y_bpm_gd.setDrawPointsOn(true)
		#-------------------------------------
		self.x_bpm_diff_gd = BasicGraphData()
		self.x_bpm_diff_gd.setLineThick(3)
		self.x_bpm_diff_gd.setGraphPointSize(7)
		self.x_bpm_diff_gd.setGraphColor(Color.BLUE)
		self.x_bpm_diff_gd.setGraphProperty(GRAPH_LEGEND_KEY,"X Diff BPM [mm]")
		self.x_bpm_diff_gd.setDrawLinesOn(false)
		self.x_bpm_diff_gd.setDrawPointsOn(true)
		#-------------------------------------
		self.y_bpm_diff_gd = BasicGraphData()
		self.y_bpm_diff_gd.setLineThick(3)
		self.y_bpm_diff_gd.setGraphPointSize(7)
		self.y_bpm_diff_gd.setGraphColor(Color.RED)
		self.y_bpm_diff_gd.setGraphProperty(GRAPH_LEGEND_KEY,"Y Diff BPM [mm]")
		self.y_bpm_diff_gd.setDrawLinesOn(false)
		self.y_bpm_diff_gd.setDrawPointsOn(true)
		#-------------------------------------		
		self.index0_button = JRadioButton("Orbit #0")
		self.index1_button = JRadioButton("Orbit #1")
		self.button_group = ButtonGroup()
		self.button_group.add(self.index0_button)
		self.button_group.add(self.index1_button)
		self.index0_button.setSelected(true)
		replot_button = JButton("Replot Graphs")
		replot_button.addActionListener(Replot_Button_Listener(self.mebt_main_orbit_diff_cntrl))
		button_panel = JPanel(FlowLayout(FlowLayout.LEFT,3,3))
		button_panel.add(self.index0_button)
		button_panel.add(self.index1_button)
		button_panel.add(replot_button)
		#-----------------------------------------------
		self.add(tabbedPane,BorderLayout.CENTER)
		self.add(button_panel,BorderLayout.SOUTH)
				
	def removeAllGraphData(self):
		self.hor_plot.removeAllGraphData()
		self.ver_plot.removeAllGraphData()
		self.hor_diff_plot.removeAllGraphData()
		self.ver_diff_plot.removeAllGraphData()
		#--------------------------------------
		self.x_model_gd.removeAllPoints()
		self.y_model_gd.removeAllPoints()
		self.x_model_diff_gd.removeAllPoints()
		self.y_model_diff_gd.removeAllPoints()
		#--------------------------------------
		self.x_bpm_gd.removeAllPoints()
		self.y_bpm_gd.removeAllPoints()
		self.x_bpm_diff_gd.removeAllPoints()
		self.y_bpm_diff_gd.removeAllPoints()
								
	def updateGraphData(self):
		self.removeAllGraphData()
		orb_index = 0
		if(self.index1_button.isSelected()):
			orb_index = 1
		#print "debug orb_index=",orb_index
		#==== update graph data from calculator and measurer
		orbit_measurer = self.mebt_main_orbit_diff_cntrl.orbit_measurer
		mebt_orbit_holder_0 = orbit_measurer.mebt_orbit_holder_0
		mebt_orbit_holder_1 = orbit_measurer.mebt_orbit_holder_1
		bpm_orbit_holder_0 = orbit_measurer.bpm_orbit_holder_0
		bpm_orbit_holder_1 = orbit_measurer.bpm_orbit_holder_1
		bpm_wrappers = self.mebt_main_orbit_diff_cntrl.bpm_wrappers
		max_pos = 0.
		for bpm_wrapper in bpm_wrappers:
			if(bpm_wrapper.use):
				if(max_pos < bpm_wrapper.pos):
					max_pos = bpm_wrapper.pos
		#----------------------------------------
		pos_step = 0.1
		pos_old = -1.
		traj0 = mebt_orbit_holder_0.getTrajectory()
		traj1 = mebt_orbit_holder_1.getTrajectory()
		for ind in range(traj0.numStates()):
			state0 = traj0.stateWithIndex(ind)
			pos = state0.getPosition()
			state1 = traj1.stateNearestPosition(pos)
			if(pos > (pos_old + pos_step) and pos_old < max_pos):
				x0 = state0.getPhaseCoordinates().getx()*1000.
				y0 = state0.getPhaseCoordinates().gety()*1000.
				x1 = state1.getPhaseCoordinates().getx()*1000.
				y1 = state1.getPhaseCoordinates().gety()*1000.
				pos_old = pos
				if(orb_index == 0):
					self.x_model_gd.addPoint(pos,x0)
					self.y_model_gd.addPoint(pos,y0)
				else:
					self.x_model_gd.addPoint(pos,x1)
					self.y_model_gd.addPoint(pos,y1)					
				self.x_model_diff_gd.addPoint(pos,x1-x0)
				self.y_model_diff_gd.addPoint(pos,y1-y0)
		#----------------------------------------------
		#bpm_orbit_holder_0.calcStatistics()
		#bpm_orbit_holder_1.calcStatistics()
		for bpm_wrapper in bpm_wrappers:
			if(bpm_wrapper.use):		
				(x0,x0_err,y0,y0_err) = bpm_orbit_holder_0.getXY_and_Err(bpm_wrapper)
				(x1,x1_err,y1,y1_err) = bpm_orbit_holder_1.getXY_and_Err(bpm_wrapper)
				if(orb_index == 0):
					self.x_bpm_gd.addPoint(bpm_wrapper.pos,x0,x0_err)
					self.y_bpm_gd.addPoint(bpm_wrapper.pos,y0,y0_err)
				else:
					self.x_bpm_gd.addPoint(bpm_wrapper.pos,x1,x1_err)
					self.y_bpm_gd.addPoint(bpm_wrapper.pos,y1,y1_err)					
				self.x_bpm_diff_gd.addPoint(bpm_wrapper.pos,x1-x0,math.sqrt(x0_err**2+x1_err**2))
				self.y_bpm_diff_gd.addPoint(bpm_wrapper.pos,y1-y0,math.sqrt(y0_err**2+y1_err**2))
		#-------------------------------------
		self.hor_plot.addGraphData(self.x_model_gd)
		self.hor_plot.addGraphData(self.x_bpm_gd)
		self.ver_plot.addGraphData(self.y_model_gd)
		self.ver_plot.addGraphData(self.y_bpm_gd)
		#-------------------------------------
		self.hor_diff_plot.addGraphData(self.x_model_diff_gd)
		self.hor_diff_plot.addGraphData(self.x_bpm_diff_gd)
		self.ver_diff_plot.addGraphData(self.y_model_diff_gd)
		self.ver_diff_plot.addGraphData(self.y_bpm_diff_gd)