diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java new file mode 100644 index 0000000000000000000000000000000000000000..6ee07ef42c9f6c9f939075204f4265fcaf188367 --- /dev/null +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java @@ -0,0 +1,30 @@ +package simpleex.ui; + +import javafx.scene.control.ListCell; +import javafx.scene.layout.Region; +import simpleex.core.LatLong; + +/** + * + * @author Adrian Stoica + * + */ +public class LatLongCell extends ListCell<LatLong> { + + @Override + public void updateItem(LatLong location, boolean empty) { + super.updateItem(location, empty); + if(empty || location == null) { + setText(null); + setGraphic(null); + setPrefHeight(25.0); + } else { + LatLongCellController latLongCellController = new LatLongCellController(); + latLongCellController.setLatLong(location); + setGraphic(latLongCellController.getCellView()); + setPrefHeight(Region.USE_COMPUTED_SIZE); + //setPrefHeight(50.0); + + } + } +} diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java new file mode 100644 index 0000000000000000000000000000000000000000..03a0fa5eab937bc22811b0e1d95a1e1215c0093c --- /dev/null +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java @@ -0,0 +1,74 @@ +package simpleex.ui; + +import java.io.IOException; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; +import simpleex.core.LatLong; +import simpleex.core.MetaData; + +public class LatLongCellController { + + @FXML + private VBox vBox; + + @FXML + private Label nameLabel; + + @FXML + private Label coordinatesLabel; + + @FXML + private Label descriptionLabel; + + private LatLong latLong; + + public LatLongCellController() { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("LatLongCell.fxml")); + fxmlLoader.setController(this); + try { + vBox = fxmlLoader.load(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void setLatLong(LatLong latLong) { + this.latLong = latLong; + if(latLong != null) { + coordinatesLabel.setText(latLong.toString()); + if (this.latLong.hasMetaData()) { + MetaData metaData = this.latLong.getMetaData(); + if(metaData.hasProperty(MetaData.NAME_PROPERTY)) { + nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY)); + } + else { + nameLabel.setMaxHeight(0.0); + } + + if(metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) { + descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY)); + descriptionLabel.setWrapText(true); + descriptionLabel.setMaxHeight(50.0); + descriptionLabel.setManaged(true); + descriptionLabel.setMaxWidth(200.0); + } + else { + descriptionLabel.setMaxHeight(0.0); + } + + vBox.autosize(); + } else { + vBox.setPrefHeight(30.0); + } + + } + } + + public Region getCellView() { + return this.vBox; + } +} diff --git a/simpleexample2/fxui/src/main/resources/simpleex/ui/LatLongCell.fxml b/simpleexample2/fxui/src/main/resources/simpleex/ui/LatLongCell.fxml new file mode 100644 index 0000000000000000000000000000000000000000..bd907476ea425f40a80efbab8c092970c443aa0c --- /dev/null +++ b/simpleexample2/fxui/src/main/resources/simpleex/ui/LatLongCell.fxml @@ -0,0 +1,12 @@ +<?import simpleex.core.LatLong?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> + +<VBox xmlns:fx="http://javafx.com/fxml" fx:id="vBox" fillWidth="true"> + <children> + <Label fx:id="nameLabel" /> + <Label fx:id="coordinatesLabel" /> + <Label fx:id="descriptionLabel" /> + </children> +</VBox> \ No newline at end of file