Skip to content
Snippets Groups Projects
Commit 4f111ca8 authored by George Adrian Stoica's avatar George Adrian Stoica
Browse files

changed the cell UI to be generated with code and dropped the fxml

parent b168dca5
Branches
Tags
1 merge request!6Issue 11 allow user to enter and update metadata about the latlong points
...@@ -90,6 +90,11 @@ public class FxApp extends Application { ...@@ -90,6 +90,11 @@ public class FxApp extends Application {
+ " tortor maximus tristique. Vestibulum at mauris massa. Nulla laoreet, velit eu lobortis efficitur, " + " tortor maximus tristique. Vestibulum at mauris massa. Nulla laoreet, velit eu lobortis efficitur, "
+ "tortor sem molestie massa, at pellentesque tortor elit a nibh. In vel orci vitae magna rhoncus pulvinar " + "tortor sem molestie massa, at pellentesque tortor elit a nibh. In vel orci vitae magna rhoncus pulvinar "
+ "sit amet id erat."); + "sit amet id erat.");
latLongWithMetaData.getMetaData().addTags("tag 1","tag 2","a much longer tag 3");
latLongWithMetaData.getMetaData().setProperty("custom property 1", "this is the value for custom property 1");
latLongWithMetaData.getMetaData().setIntegerProperty("custom property 2 (int)", 13);
latLongWithMetaData.getMetaData().setDoubleProperty("custom property 3 (double)", 35.13);
latLongWithMetaData.getMetaData().setBooleanProperty("custom property 4 (boolean)", false);
latLongs.addLatLong(latLongWithMetaData); latLongs.addLatLong(latLongWithMetaData);
return latLongs; return latLongs;
} }
......
...@@ -21,7 +21,7 @@ public class LatLongCell extends ListCell<LatLong> { ...@@ -21,7 +21,7 @@ public class LatLongCell extends ListCell<LatLong> {
} else { } else {
LatLongCellController latLongCellController = new LatLongCellController(); LatLongCellController latLongCellController = new LatLongCellController();
latLongCellController.setLatLong(location); latLongCellController.setLatLong(location);
setGraphic(latLongCellController.getCellView()); setGraphic(latLongCellController.getCellView(this.isSelected()));
setPrefHeight(Region.USE_COMPUTED_SIZE); setPrefHeight(Region.USE_COMPUTED_SIZE);
//setPrefHeight(50.0); //setPrefHeight(50.0);
......
package simpleex.ui; package simpleex.ui;
import java.io.IOException;
import javafx.fxml.FXML; import java.util.Iterator;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import simpleex.core.LatLong; import simpleex.core.LatLong;
import simpleex.core.MetaData; import simpleex.core.MetaData;
/**
* The controller for the renderer in the ListView cells
* containing the locations
* @author Adrian Stoica
*
*/
public class LatLongCellController { public class LatLongCellController {
@FXML /**
* The main container of the cell UI
*/
private Region root;
/**
* the horizontal box containing the coordinates
* and the add/edit button
*/
private HBox hBox;
/**
* The button that will allow opening the editor
* for the selected item
*/
private Button editMetadataButton;
/**
* container for the additional metadata
*/
private VBox vBox; private VBox vBox;
@FXML /**
* the label for the name property
*/
private Label nameLabel; private Label nameLabel;
@FXML /**
* the label for the coordinates
*/
private Label coordinatesLabel; private Label coordinatesLabel;
@FXML /**
* the label for the description
*/
private Label descriptionLabel; private Label descriptionLabel;
/**
* the current LatLong object that needs to be displayed
*/
private LatLong latLong; private LatLong latLong;
/**
* create a new controller for managing a LatLong list cell
*/
public LatLongCellController() { public LatLongCellController() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("LatLongCell.fxml")); super();
fxmlLoader.setController(this);
try {
vBox = fxmlLoader.load();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
/**
* set the location object
* @param latLong the reference to the object to be displayed
*/
public void setLatLong(LatLong latLong) { public void setLatLong(LatLong latLong) {
this.latLong = latLong; this.latLong = latLong;
if(latLong != null) { }
coordinatesLabel.setText(latLong.toString());
/**
* prepare the cell UI
* @param selected flag indicating that the item is selected
*/
protected void prepareView(boolean selected) {
this.hBox = new HBox();
this.coordinatesLabel = new Label(this.latLong.toString());
coordinatesLabel.setPrefWidth(200.0);
this.hBox.getChildren().add(coordinatesLabel);
if(selected) {
this.editMetadataButton = new Button("...");
this.hBox.getChildren().add(editMetadataButton);
}
if(this.latLong.hasMetaData()) { if(this.latLong.hasMetaData()) {
this.vBox = new VBox();
MetaData metaData = this.latLong.getMetaData(); MetaData metaData = this.latLong.getMetaData();
if(metaData.hasProperty(MetaData.NAME_PROPERTY)) { if(metaData.hasProperty(MetaData.NAME_PROPERTY)) {
nameLabel = new Label();
nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY)); nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY));
vBox.getChildren().add(nameLabel);
} }
else { vBox.getChildren().add(this.hBox);
nameLabel.setMaxHeight(0.0);
}
if(metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) { if(metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) {
descriptionLabel = new Label();
descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY)); descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY));
descriptionLabel.setWrapText(true); descriptionLabel.setWrapText(true);
descriptionLabel.setMaxHeight(50.0); descriptionLabel.setMaxHeight(50.0);
descriptionLabel.setManaged(true); descriptionLabel.setManaged(true);
descriptionLabel.setMaxWidth(200.0); descriptionLabel.setMaxWidth(200.0);
} vBox.getChildren().add(descriptionLabel);
else {
descriptionLabel.setMaxHeight(0.0);
} }
vBox.autosize(); final Iterator<String> tags = metaData.tags();
} else { if (tags.hasNext()) {
nameLabel.setVisible(false); HBox tagsBox = new HBox();
descriptionLabel.setVisible(false); tagsBox.setSpacing(5.0);
//nameLabel.setMaxHeight(0.0); while (tags.hasNext()) {
//descriptionLabel.setMaxHeight(0.0); Label tagLabel = new Label(tags.next());
vBox.setPrefHeight(30.0); tagLabel.setStyle("-fx-background-color: #43464b; \r\n" +
" -fx-text-fill: white;\r\n" +
" -fx-border-radius: 3 3 3 3; \r\n" +
" -fx-background-radius: 3 3 3 03; ");
tagLabel.setPadding(new Insets(0.0,3.0,0.0,3.0));
tagsBox.getChildren().add(tagLabel);
} }
vBox.getChildren().add(tagsBox);
}
this.root = this.vBox;
} else {
this.root = this.hBox;
} }
} }
public Region getCellView() { /**
return this.vBox; * get the UI for the cell based on selection and
* the available info in the latLong object
* @param selected flag indicating that the item is selected
* @return the root container for the cell UI
*/
public Region getCellView(boolean selected) {
prepareView(selected);
return this.root;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment