User Tools

Site Tools


zalozeni:grafika:measurementcontrollpanel

MeasurementControllPane

Tento pane se nachazi v prave horni casti a krome zobrazovani aktualniho stavu mereni by mel umoznovat uzivateli mereni ovladat (menit status mereni, ovladat pristroj). Je nezbytne, aby controller dedil od tridy ControllPaneController. Ukazka implementace tohoto controlleru nasleduje.

Veskere grafika je obsazena v anchorPane, ktera se pouziva pouze v metode clearGraphics() (naproste vycisteni grafiky, napr. pri smazani ExperimentInstance)

Grafika dale obsahule lblTemp, zobrazujici aktualni teplotu a lblStatus zobrazujici aktualni status experimentu. btn1 a btn2 slouzi k prepinani mezi jednotlivym ExperimentStatus aktualni ExperimentInstance. Tato tlacitka jsou predana tride DokuwikiStatusButtonHandler (jeji zdrojak je na konci).

Metoda repaint() je volana pri novem prekresleni celeho DokuwikiControllPaneController (takze by se v ni melo nastavit defaultni vykresleni).

Metoda newData() je obsolete. Misto ni se pouzva LogicModuleManager implementujici Oserver pattern. Ukazka registrace listeneru na dva eventy je v metode setExpInstance().

V teto casti grafiky jsem hojne vyuzival JavaFX gauge, jejichz implementace je na mavenu v balicku eu.hansolo.medusa

public class DokuwikiControllPaneController extends ControllPaneController {
 
	@FXML
	private AnchorPane anchorPane;
 
	@FXML
	private Label lblTemp;
	@FXML
	private Label lblStatus;
 
	@FXML
	private Button btn1;
	@FXML
	private Button btn2;
 
	private DokuwikiStatusButtonHandler statusBtnHandler;
 
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
	}
 
	@Override
	public void setExpInstance(ExperimentInstance expInstance) {
		super.setExpInstance(expInstance);
 
		repaint();
		statusBtnHandler = new DokuwikiStatusButtonHandler(btn1, btn2, expInstance);
		handleExperimentStatus(expInstance.getStatus());
 
		ServiceLocator.getInstance().getLogicModuleManager().registerListener(expInstance, new ExperimentLogicListener() {
 
			public void processEvent(LogicModuleEvent event) {
				if (event instanceof TempReadOutEvent) {
					TempReadOutEvent pevent = (TempReadOutEvent) event;
					lblTemp.setText(pevent.getTempString());
				} else if (event instanceof StatusChangeEvent) {
					StatusChangeEvent pevent = (StatusChangeEvent) event;
					handleExperimentStatus(pevent.getEndStatus());
				}
 
			}
		});
	}
 
	private void handleExperimentStatus(ExperimentStatus status) {
		statusBtnHandler.repaint(status);
		lblStatus.setText(ExperimentStatusHelper.toString(status));
		lblStatus.setTextFill(ExperimentStatusHelper.toColor(status));
	}
 
	@Override
	public void clearGraphics() {
		anchorPane.getChildren().clear();
	}
 
	@Override
	public void repaint() {
		lblTemp.setText("");
	}
 
	@Override
	public void newData(Object dataRow) {
		DokuwikiDataRow dr = (DokuwikiDataRow) dataRow;
		lblTemp.setText(dr.getValue1String());
	}
 
}
public class DokuwikiStatusButtonHandler {
 
	private Button btn1;
	private Button btn2;
	private ExperimentInstance expInst;
	private LogicModuleManager logicModuleManager;
 
	public DokuwikiStatusButtonHandler(Button btn1, Button btn2, ExperimentInstance expInst) {
		this.btn1 = btn1;
		this.btn2 = btn2;
		this.expInst = expInst;
		logicModuleManager = ServiceLocator.getInstance().getLogicModuleManager();
	}
 
	public void repaint(ExperimentStatus status) {
		switch (status) {
		case NEW: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("lockMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.lockInstance(expInst);
			});
 
			btn2.setVisible(false);
			break;
		}
		case NEW_LOCKED: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("startMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.runInstance(expInst);
			});
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("unlockMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.unLockInstance(expInst);
			});
 
			break;
		}
		case RUNNING: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("endMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.abortInstance(expInst);
			});
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("pauseMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.pauseInstance(expInst);
			});
 
			break;
		}
		case PAUSED: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("continueMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.unpauseInstance(expInst);
			});
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("scrapMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.suspendInstance(expInst);
			});
 
			break;
		}
		case SUSPENDED: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("restoreMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.resumeInstance(expInst);
			});
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("markAsSuccessfulMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.abortInstance(expInst);
			});
 
			break;
		}
		case ABORTED: {
			btn1.setVisible(false);
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("scrapMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.suspendInstance(expInst);
			});
 
			break;
		}
		case ENDED: {
			btn1.setVisible(false);
 
			btn2.setVisible(true);
			btn2.setText(I18n.getGraphicsBundle().getString("scrapMeasurement"));
			btn2.setOnAction((ActionEvent event) -> {
				logicModuleManager.suspendInstance(expInst);
			});
 
			break;
		}
		case CRASHED: {
			btn1.setVisible(true);
			btn1.setText(I18n.getGraphicsBundle().getString("resurectMeasurement"));
			btn1.setOnAction((ActionEvent event) -> {
				logicModuleManager.restoreInstance(expInst);
			});
 
			btn2.setVisible(false);
			break;
		}
		default: {
			break;
		}
		}
	}
}
zalozeni/grafika/measurementcontrollpanel.txt · Last modified: 2016/07/25 10:32 by jlochman