User Tools

Site Tools


zalozeni:grafika:genericcell

GenericCell

GenericCell je definovana v jadre a definuje tridu, ktera je pomoci tridy GenericCellUpdater extends ListCell<GenericCell> vykreslovana do ListView s jednotlivymi experimety. Pri jejim vytvareni je treba dodrzovat nektere direktivy

  1. @FXML protected AnchorPane anchorPane; definuje AnchorPane, ktera by mela zaobalovat celou GenericCell. GenericCell je vzde treba vytvorit vlozenou do AnchorPane, ktera MUSI MIT fx:id=“anchorPane”.
  2. anchorPane z predchoziho bodu musi mit nastavenou fixni height, tj. nastavit Pref height = xxx, Min height = USE_PREF_HEIGHT a Max height = USER_PREF_HEIGHT.
  3. view se nelinkuje s controllerem na urovni xml, tj. NEVYPLNUJE se fx:controller=“…”. Misto toho se overriduje contructor a vola se v nem metoda setFXMLFile(String m_FXMLFile).
  4. metoda fillGraphics() je volana pri vkladani grafiky do ListView. Je volana az po constructoru a mela by v sobe obsahovat defaultni plneni grafiky
  5. metoda setBackgroundColor() v zavislosti na ExperimentStatus nastavuje barevne pozadi GenerciCell
public abstract class GenericCell implements Initializable {
	private String m_FXMLFile;
	protected ExperimentInstance expInst;
 
	@FXML
	protected AnchorPane anchorPane;
 
	public void setBackgroundColor() {
		if (expInst == null) {
			setBackgroundColor(Color.rgb(60,60,60));
		} else {
			setBackgroundColor(ExperimentStatusHelper.toColor(expInst.getStatus()));
		}
	}
 
	public void setBackgroundColor(Color color) {
		if (anchorPane == null)
			return;
		int r = (int) (255 * color.getRed());
		int g = (int) (255 * color.getGreen());
		int b = (int) (255 * color.getBlue());
		anchorPane.setStyle("-fx-background-color: rgba(" + r + "," + g + "," + b + ",0.3);");
	}
 
	public GenericCell(ExperimentInstance expInst) {
		this.expInst = expInst;
	}
 
	public abstract void fillGraphics();
 
	public void loadGraphics() {
		FXMLLoader fxmlLoader = new FXMLLoader();
		fxmlLoader.setResources(I18n.getGraphicsBundle());
		fxmlLoader.setLocation(getClass().getResource(m_FXMLFile));
		fxmlLoader.setController(this);
		try {
			fxmlLoader.load();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	public void setFXMLFile(String m_FXMLFile) {
		this.m_FXMLFile = m_FXMLFile;
	}
 
	+ getters, setters, ...
}
zalozeni/grafika/genericcell.txt · Last modified: 2016/07/25 15:33 by jlochman