User Tools

Site Tools


zalozeni:grafika:experimenttabs:tabulka

Tabulka s namerenymi daty

Pro tuto tabulku neni v jadre nic pripravneo. Je treba ji vytvorit od samotneho zacatku. Nejprve je treba definovat samotny controlelr + view. U nej staci definovat metody clear(), repaint(dataService) a addData(dataRow). Za povsimnuti stoji, ze si controller drzi jednak tabulku (tableView) a jednak jeji jednotlive sloupce (dataTime, dataVal1, dataVal2).

Pri inicializaci controlleru je treba kazdemu sloupci priradit prislusnou CallValueFactory, coz se deje v metode initialize(). Pro mapovani dat mezi DokuwikiDataRow a tableView slouzi nova trida DokuwikiDataTableRow, ktera je prilozena. Je treba si povsimnout, ze vsechny gettery byly upraveny tak, aby misto SimpleStringProperty vraceli String.

public class DokuwikiDataPaneController implements Initializable {
 
	@FXML
	private AnchorPane anchorPane;
 
	@FXML
	private TableView<DokuwikiDataTableRow> tableView;
	@FXML
	private TableColumn<DokuwikiDataTableRow, Long> dataTime;
	@FXML
	private TableColumn<DokuwikiDataTableRow, String> dataVal1;
	@FXML
	private TableColumn<DokuwikiDataTableRow, String> dataVal2;
 
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		dataTime.setCellValueFactory(new PropertyValueFactory<DokuwikiDataTableRow, Long>("time"));
		dataVal1.setCellValueFactory(new PropertyValueFactory<DokuwikiDataTableRow, String>("val1"));
		dataVal2.setCellValueFactory(new PropertyValueFactory<DokuwikiDataTableRow, String>("val2"));
	}
 
	public void clear()	 {
		tableView.getItems().clear();
	}
 
	public void repaint(DokuwikiDataService dataService) {
		clear();
		ObservableList<DokuwikiDataTableRow> data = FXCollections.observableArrayList();
		List<DokuwikiDataRow> dataRows = dataService.getDataRows();
		for (DokuwikiDataRow dr : dataRows) {
			data.add(new DokuwikiDataTableRow(dr));
		}
		tableView.setItems(data);
	}
 
	public void addData(DokuwikiDataRow dr) {
		tableView.getItems().add(new DokuwikiDataTableRow(dr));
 
		int row = tableView.getItems().size() - 1;
		tableView.getSelectionModel().select(row);
		tableView.getFocusModel().focus(row);
		tableView.scrollTo(row);
	}
 
}
public class DokuwikiDataTableRow {
 
	private SimpleStringProperty time;
	private SimpleStringProperty val1;
	private SimpleStringProperty val2;
 
	public DokuwikiDataTableRow(DokuwikiDataRow dr) {
		this.time = new SimpleStringProperty(dr.getTimeString());
		this.val1 = new SimpleStringProperty(dr.getValue1String());
		this.val2 = new SimpleStringProperty(dr.getValue2String());
	}
 
	public String getTime() {
		return time.get();
	}
 
	public void setTime(SimpleStringProperty time) {
		this.time = time;
	}
 
	public String getVal1() {
		return val1.get();
	}
 
	public void setVal1(SimpleStringProperty val1) {
		this.val1 = val1;
	}
 
	public String getVal2() {
		return val2.get();
	}
 
	public void setVal2(SimpleStringProperty val2) {
		this.val2 = val2;
	}	
 
}
zalozeni/grafika/experimenttabs/tabulka.txt · Last modified: 2016/07/25 13:48 by jlochman