package com.ht.ui.taginfo;

import java.text.DecimalFormat;
import java.util.Map;
import java.util.Map.Entry;

import com.ht.tags.model.index.IndexTreeNode;

import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

class BuildingInfoPanel extends VBox {

	private GridPane gridPane;

	public BuildingInfoPanel() {
		super(2);
		Label title1 = new Label("建筑信息");
		title1.getStyleClass().add("info-pane-header");
		
		gridPane = new GridPane();
		gridPane.setHgap(6);
		gridPane.setVgap(10);
		VBox.setMargin(gridPane, new Insets(0, 0, 10, 10));
		
		Region spacer = new Region();
		spacer.setMinHeight(20);

		getChildren().addAll(title1, gridPane, spacer);
	}
	
	void setInfoMap(IndexTreeNode node, Map<String, String> map) {
		gridPane.getChildren().clear();
		
		DecimalFormat df = new DecimalFormat("0.00");
		
		Label label = new Label("建筑名称");
		GridPane.setConstraints(label, 0, 0);
		GridPane.setHalignment(label, HPos.RIGHT);
		gridPane.getChildren().add(label);

		TextField value = new TextField(node.getName());
		value.setPrefWidth(node.getName().length() * 16);
		value.setMinWidth(60);
		GridPane.setConstraints(value, 1, 0);
		GridPane.setHalignment(value, HPos.LEFT);
		gridPane.getChildren().add(value);

		label = new Label("总建筑面积");
		GridPane.setConstraints(label, 2, 0);
		GridPane.setHalignment(label, HPos.RIGHT);
		gridPane.getChildren().add(label);

		String area = node.getArea() == null ? "" : df.format(node.getArea());
		value = new TextField(area);
		value.setPrefWidth(area.length() * 16);
		value.setMinWidth(60);
		GridPane.setConstraints(value, 3, 0);
		GridPane.setHalignment(value, HPos.LEFT);
		gridPane.getChildren().add(value);

		label = new Label("总空调面积");
		GridPane.setConstraints(label, 0, 1);
		GridPane.setHalignment(label, HPos.RIGHT);
		gridPane.getChildren().add(label);

		String air = node.getAirConditionArea() == null ? "" : df.format(node.getAirConditionArea());
		value = new TextField(air);
		value.setPrefWidth(air.length() * 16);
		value.setMinWidth(60);
		GridPane.setConstraints(value, 1, 1);
		GridPane.setHalignment(value, HPos.LEFT);
		gridPane.getChildren().add(value);

		label = new Label("总采暖面积");
		GridPane.setConstraints(label, 2, 1);
		GridPane.setHalignment(label, HPos.RIGHT);
		gridPane.getChildren().add(label);

		String heating = node.getHeatingArea() == null ? "" : df.format(node.getHeatingArea());
		value = new TextField(heating);
		value.setPrefWidth(heating.length() * 16);
		value.setMinWidth(60);
		GridPane.setConstraints(value, 3, 1);
		GridPane.setHalignment(value, HPos.LEFT);
		gridPane.getChildren().add(value);
			
		int i = 0;
		for (Entry<String, String> entry : map.entrySet()) {
			label = new Label(entry.getKey());
			GridPane.setConstraints(label, 0 + (i % 2) * 2, i / 2 + 2);
			GridPane.setHalignment(label, HPos.RIGHT);
			gridPane.getChildren().add(label);

			value = new TextField(entry.getValue());
			value.setPrefWidth(entry.getValue().length() * 16);
			value.setMinWidth(60);
			GridPane.setConstraints(value, 1 + (i % 2) * 2, i / 2 + 2);
			GridPane.setHalignment(value, HPos.LEFT);
			GridPane.setHgrow(value, Priority.NEVER);
			gridPane.getChildren().add(value);
			
			i++;
		}
	}

	
}
