package imseProc.aqui.proc;

import imseProc.aqui.AquisitionHanger;
import imseProc.core.IMSEProc;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

public class ImageStepSyncController {
	
	private Group swtGroup;
	private Button calc;
	private Label text;
	
	private ImageStepSyncProc proc;
	
	public ImageStepSyncController(Composite parent, int style, AquisitionHanger aquiProc) {
		proc = new ImageStepSyncProc(aquiProc, this);
		
		swtGroup = new Group(parent, style);
		swtGroup.setText("Image/Step Counters");
		swtGroup.setLayout(new GridLayout(3, false));
				
		text = new Label(swtGroup, SWT.NONE);
		text.setText("No init");
		text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true, 3, 1));
		
		calc = new Button(swtGroup, SWT.PUSH);
		calc.setText("Process");
		calc.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { calcButtonEvent(event); }});
		calc.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 3, 1));
		
		swtGroup.pack();
	}
	
	public Composite getComposite(){ return swtGroup; }

	private void calcButtonEvent(Event event) {
		proc.calc();
	}
	
	public void update() {
		IMSEProc.ensureFinalSWTUpdate(swtGroup.getDisplay(), this, new Runnable() { @Override public void run() { doUpdate(); }});
	}
		
	private void doUpdate() {
		text.setText(proc.getStatus());
	}
}
