import javafx.scene.control.Label; //导入方法依赖的package包/类
private void initializePropertyTag() {
final TagPresentation propertyTag = controller.propertyTag;
final Line propertyTagLine = controller.propertyTagLine;
propertyTag.setComponent(controller.getComponent());
propertyTag.setLocationAware(controller.getNail());
// Bind the line to the tag
BindingHelper.bind(propertyTagLine, propertyTag);
// Bind the color of the tag to the color of the component
propertyTag.bindToColor(controller.getComponent().colorProperty(), controller.getComponent().colorIntensityProperty());
// Updates visibility and placeholder of the tag depending on the type of nail
final Consumer updatePropertyType = (propertyType) -> {
// If it is not a property nail hide the tag otherwise show it and write proper placeholder
if(propertyType.equals(Edge.PropertyType.NONE)) {
propertyTag.setVisible(false);
} else {
// Show the property tag since the nail is a property nail
propertyTag.setVisible(true);
// Set and bind the location of the property tag
if((controller.getNail().getPropertyX() != 0) && (controller.getNail().getPropertyY() != 0)) {
propertyTag.setTranslateX(controller.getNail().getPropertyX());
propertyTag.setTranslateY(controller.getNail().getPropertyY());
}
controller.getNail().propertyXProperty().bind(propertyTag.translateXProperty());
controller.getNail().propertyYProperty().bind(propertyTag.translateYProperty());
Label propertyLabel = controller.propertyLabel;
if(propertyType.equals(Edge.PropertyType.SELECTION)) {
propertyTag.setPlaceholder("Select");
propertyLabel.setText(":");
propertyLabel.setTranslateX(-3);
propertyLabel.setTranslateY(-8);
propertyTag.setAndBindString(controller.getEdge().selectProperty());
} else if(propertyType.equals(Edge.PropertyType.GUARD)) {
propertyTag.setPlaceholder("Guard");
propertyLabel.setText("
propertyLabel.setTranslateX(-3);
propertyLabel.setTranslateY(-7);
propertyTag.setAndBindString(controller.getEdge().guardProperty());
} else if(propertyType.equals(Edge.PropertyType.SYNCHRONIZATION)) {
propertyTag.setPlaceholder("Sync");
propertyLabel.setText("!?");
propertyLabel.setTranslateX(-6);
propertyLabel.setTranslateY(-7);
propertyTag.setAndBindString(controller.getEdge().syncProperty());
} else if(propertyType.equals(Edge.PropertyType.UPDATE)) {
propertyTag.setPlaceholder("Update");
propertyLabel.setText("=");
propertyLabel.setTranslateX(-3);
propertyLabel.setTranslateY(-7);
propertyTag.setAndBindString(controller.getEdge().updateProperty());
}
propertyTag.requestTextFieldFocus();
propertyTag.requestTextFieldFocus(); // Requesting it twice is needed for some reason
}
};
// Whenever the property type updates update the tag
controller.getNail().propertyTypeProperty().addListener((obs, oldPropertyType, newPropertyType) -> {
updatePropertyType.accept(newPropertyType);
});
// Update the tag initially
updatePropertyType.accept(controller.getNail().getPropertyType());
}