Commit 4f111ca8 authored by George Adrian Stoica's avatar George Adrian Stoica

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

parent b168dca5
package simpleex.ui; package simpleex.ui;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.HttpServer;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import simpleex.core.LatLong; import simpleex.core.LatLong;
import simpleex.core.LatLongs; import simpleex.core.LatLongs;
import simpleex.core.MetaData; import simpleex.core.MetaData;
import simpleex.restapi.LatLongsService; import simpleex.restapi.LatLongsService;
import simpleex.restserver.LatLongGrizzlyApp; import simpleex.restserver.LatLongGrizzlyApp;
public class FxApp extends Application { public class FxApp extends Application {
private HttpServer restServer = null; private HttpServer restServer = null;
@Override @Override
public void start(final Stage stage) throws Exception { public void start(final Stage stage) throws Exception {
URI baseUri = null; URI baseUri = null;
final List<String> args = getParameters().getRaw(); final List<String> args = getParameters().getRaw();
if (args.size() >= 1) { if (args.size() >= 1) {
final List<String> serverArgs = new ArrayList<String>(); final List<String> serverArgs = new ArrayList<String>();
baseUri = URI.create(args.get(0)); baseUri = URI.create(args.get(0));
serverArgs.add(baseUri.toString()); serverArgs.add(baseUri.toString());
if (args.size() >= 2) { if (args.size() >= 2) {
// json of initial data // json of initial data
serverArgs.add(args.get(1)); serverArgs.add(args.get(1));
} }
restServer = LatLongGrizzlyApp.startServer(serverArgs.toArray(new String[serverArgs.size()]), 5); restServer = LatLongGrizzlyApp.startServer(serverArgs.toArray(new String[serverArgs.size()]), 5);
} }
final String fxml = (baseUri != null ? "FxAppUsingRest.fxml" : "FxApp.fxml"); final String fxml = (baseUri != null ? "FxAppUsingRest.fxml" : "FxApp.fxml");
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxml)); final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxml));
final Parent root = fxmlLoader.load(); final Parent root = fxmlLoader.load();
if (baseUri == null) { if (baseUri == null) {
// set initial data manually // set initial data manually
final FxAppController controller = fxmlLoader.getController(); final FxAppController controller = fxmlLoader.getController();
//controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0)); //controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0));
controller.setLatLongs(getInitialData()); controller.setLatLongs(getInitialData());
} else { } else {
final FxAppUsingRestController controller = fxmlLoader.getController(); final FxAppUsingRestController controller = fxmlLoader.getController();
controller.setDataAccess(new RestLatLongsDataAccess(baseUri + LatLongsService.LAT_LONG_SERVICE_PATH, controller.getObjectMapper())); controller.setDataAccess(new RestLatLongsDataAccess(baseUri + LatLongsService.LAT_LONG_SERVICE_PATH, controller.getObjectMapper()));
} }
final Scene scene = new Scene(root); final Scene scene = new Scene(root);
stage.setScene(scene); stage.setScene(scene);
stage.show(); stage.show();
} }
@Override @Override
public void stop() throws Exception { public void stop() throws Exception {
if (restServer != null) { if (restServer != null) {
restServer.shutdown(); restServer.shutdown();
} }
super.stop(); super.stop();
} }
/** /**
* Launches the app. * Launches the app.
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
// only needed on ios // only needed on ios
System.setProperty("os.target", "ios"); System.setProperty("os.target", "ios");
System.setProperty("os.name", "iOS"); System.setProperty("os.name", "iOS");
System.setProperty("glass.platform", "ios"); System.setProperty("glass.platform", "ios");
System.setProperty("targetos.name", "iOS"); System.setProperty("targetos.name", "iOS");
launch(args); launch(args);
} }
/** /**
* Method to prepare the initial entries in the loaction list * Method to prepare the initial entries in the loaction list
* @return LatLongs instance with several items * @return LatLongs instance with several items
*/ */
private LatLongs getInitialData() { private LatLongs getInitialData() {
LatLongs latLongs = new LatLongs(); LatLongs latLongs = new LatLongs();
latLongs.addLatLong(new LatLong(63.1, 11.2)); latLongs.addLatLong(new LatLong(63.1, 11.2));
latLongs.addLatLong(new LatLong(63.2, 11.0)); latLongs.addLatLong(new LatLong(63.2, 11.0));
LatLong latLongWithMetaData = new LatLong(63.5, 11.5); LatLong latLongWithMetaData = new LatLong(63.5, 11.5);
latLongWithMetaData.getMetaData().setProperty(MetaData.NAME_PROPERTY, "Awsome place"); latLongWithMetaData.getMetaData().setProperty(MetaData.NAME_PROPERTY, "Awsome place");
latLongWithMetaData.getMetaData().setProperty(MetaData.DESCRIPTION_PROPERTY, "Lorem ipsum dolor sit amet," latLongWithMetaData.getMetaData().setProperty(MetaData.DESCRIPTION_PROPERTY, "Lorem ipsum dolor sit amet,"
+ " consectetur adipiscing elit. Nulla placerat urna non aliquet imperdiet. Nullam tincidunt felis " + " consectetur adipiscing elit. Nulla placerat urna non aliquet imperdiet. Nullam tincidunt felis "
+ "vel sem blandit viverra. Etiam non volutpat erat. In hac habitasse platea dictumst. In lacus quam, " + "vel sem blandit viverra. Etiam non volutpat erat. In hac habitasse platea dictumst. In lacus quam, "
+ "rutrum vel malesuada non, molestie eu velit. Donec ut vulputate tortor, id convallis enim. Mauris " + "rutrum vel malesuada non, molestie eu velit. Donec ut vulputate tortor, id convallis enim. Mauris "
+ "et ipsum volutpat, dictum risus sed, aliquet sapien. Nam congue fermentum porta. Nullam non " + "et ipsum volutpat, dictum risus sed, aliquet sapien. Nam congue fermentum porta. Nullam non "
+ "odio consequat, laoreet est eget, egestas dui. Aliquam suscipit elit non nisi sagittis, nec " + "odio consequat, laoreet est eget, egestas dui. Aliquam suscipit elit non nisi sagittis, nec "
+ "ultrices leo condimentum. Maecenas vel ligula nec mi feugiat volutpat. Aenean semper nisi sed" + "ultrices leo condimentum. Maecenas vel ligula nec mi feugiat volutpat. Aenean semper nisi sed"
+ " 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.");
latLongs.addLatLong(latLongWithMetaData); latLongWithMetaData.getMetaData().addTags("tag 1","tag 2","a much longer tag 3");
return latLongs; 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);
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());
if (this.latLong.hasMetaData()) { /**
MetaData metaData = this.latLong.getMetaData(); * prepare the cell UI
if(metaData.hasProperty(MetaData.NAME_PROPERTY)) { * @param selected flag indicating that the item is selected
nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY)); */
} protected void prepareView(boolean selected) {
else { this.hBox = new HBox();
nameLabel.setMaxHeight(0.0); this.coordinatesLabel = new Label(this.latLong.toString());
} coordinatesLabel.setPrefWidth(200.0);
this.hBox.getChildren().add(coordinatesLabel);
if(metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) { if(selected) {
descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY)); this.editMetadataButton = new Button("...");
descriptionLabel.setWrapText(true); this.hBox.getChildren().add(editMetadataButton);
descriptionLabel.setMaxHeight(50.0); }
descriptionLabel.setManaged(true);
descriptionLabel.setMaxWidth(200.0); if(this.latLong.hasMetaData()) {
} this.vBox = new VBox();
else { MetaData metaData = this.latLong.getMetaData();
descriptionLabel.setMaxHeight(0.0); if(metaData.hasProperty(MetaData.NAME_PROPERTY)) {
} nameLabel = new Label();
nameLabel.setText(metaData.getProperty(MetaData.NAME_PROPERTY));
vBox.autosize(); vBox.getChildren().add(nameLabel);
} else { }
nameLabel.setVisible(false); vBox.getChildren().add(this.hBox);
descriptionLabel.setVisible(false); if(metaData.hasProperty(MetaData.DESCRIPTION_PROPERTY)) {
//nameLabel.setMaxHeight(0.0); descriptionLabel = new Label();
//descriptionLabel.setMaxHeight(0.0); descriptionLabel.setText(metaData.getProperty(MetaData.DESCRIPTION_PROPERTY));
vBox.setPrefHeight(30.0); descriptionLabel.setWrapText(true);
descriptionLabel.setMaxHeight(50.0);
descriptionLabel.setManaged(true);
descriptionLabel.setMaxWidth(200.0);
vBox.getChildren().add(descriptionLabel);
} }
final Iterator<String> tags = metaData.tags();
if (tags.hasNext()) {
HBox tagsBox = new HBox();
tagsBox.setSpacing(5.0);
while (tags.hasNext()) {
Label tagLabel = new Label(tags.next());
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;
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment