Skip to content
Snippets Groups Projects
Commit bed82295 authored by Mads Lundegaard's avatar Mads Lundegaard Committed by Eirik Steira
Browse files

View albums

parent 66294f69
No related branches found
No related tags found
1 merge request!165Weekly merge to Master
package NTNU.IDATT1002.controllers;
import NTNU.IDATT1002.App;
import NTNU.IDATT1002.models.Album;
import NTNU.IDATT1002.models.Image;
import NTNU.IDATT1002.service.AlbumService;
import NTNU.IDATT1002.service.ImageService;
import com.lynden.gmapsfx.GoogleMapView;
import com.lynden.gmapsfx.MapComponentInitializedListener;
import com.lynden.gmapsfx.javascript.object.GoogleMap;
import java.util.Optional;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
......@@ -48,6 +51,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
private GoogleMap map;
private ImageService imageService;
private AlbumService albumService;
private ExecutorService executorService = Executors.newCachedThreadPool();
private static Logger logger = LoggerFactory.getLogger(Map.class);
......@@ -55,6 +59,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
public Map() {
EntityManager entityManager = App.ex.getEntityManager();
imageService = new ImageService(entityManager);
albumService = new AlbumService(entityManager);
}
/**
......@@ -72,16 +77,31 @@ public class Map implements Initializable, MapComponentInitializedListener {
/**
* Fetch all images in a background task and create and display the map on success.
* Check is there is a current album in dataexchange first and uses images from album to display on map.
* If none is found it proceeds to get all images available and display on map
*/
@Override
public void mapInitialized() {
executorService.submit(fetchImages);
List<Image> albumImages = new ArrayList<>();
Long currentAlbumId;
fetchImages.setOnSucceeded(workerStateEvent -> {
List<Image> images = fetchImages.getValue();
ImageMapFactory.createMap(mapView, images);
});
if(App.ex.getChosenAlbumId() == null) {
executorService.submit(fetchImages);
fetchImages.setOnSucceeded(workerStateEvent -> {
List<Image> allImages = fetchImages.getValue();
ImageMapFactory.createMap(mapView, allImages);
});
}
else {
currentAlbumId = App.ex.getChosenAlbumId();
Optional<Album> optionalAlbum = albumService.getAlbumById(currentAlbumId);
if (optionalAlbum.isPresent()) {
Album album = optionalAlbum.get();
albumImages = album.getImages();
}
ImageMapFactory.createMap(mapView, albumImages);
}
}
/**
......@@ -105,6 +125,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
* @throws IOException
*/
public void switchToMain(MouseEvent mouseEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("main");
}
......@@ -118,6 +139,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
if (!tbar_search.getText().isEmpty()){
App.ex.setSearchField(tbar_search.getText());
}
App.ex.setChosenAlbumId(null);
App.setRoot("search");
}
......@@ -127,6 +149,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
* @throws IOException
*/
public void switchToExplore(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("explore");
}
......@@ -136,6 +159,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
* @throws IOException
*/
public void switchToAlbums(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("explore_albums");
}
......@@ -146,6 +170,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
* @throws IOException
*/
public void switchToMap(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("map");
}
......@@ -156,6 +181,7 @@ public class Map implements Initializable, MapComponentInitializedListener {
* @throws IOException this page does not exist
*/
public void switchToUpload(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("upload");
}
......
......@@ -5,6 +5,7 @@ import NTNU.IDATT1002.models.Album;
import NTNU.IDATT1002.models.Tag;
import NTNU.IDATT1002.service.AlbumDocument;
import NTNU.IDATT1002.service.AlbumService;
import NTNU.IDATT1002.service.TagService;
import NTNU.IDATT1002.utils.ImageUtil;
import java.io.File;
import java.io.IOException;
......@@ -63,6 +64,7 @@ public class ViewAlbum implements Initializable {
@FXML
public VBox albumTextContainer;
public HBox albumImages;
public Button viewOnMapBtn;
private AlbumService albumService;
private Album currentAlbum;
......@@ -87,8 +89,8 @@ public class ViewAlbum implements Initializable {
NTNU.IDATT1002.models.Image titleImage = album.getImages().get(0);
Image image = ImageUtil.convertToFXImage(titleImage);
mainPicture.setImage(image);
pictureTitleField.setText("LEGG TIL BILDETITTEL HER");
pictureTagsField.setText("#LEGG #TIL #TAGS #HER");
pictureTitleField.setText(album.getTitle());
pictureTagsField.setText(TagService.getTagsAsString(album.getTags()));
insertAlbumTextToContainer(album);
for (NTNU.IDATT1002.models.Image i: album.getImages()) {
ImageView iV = new ImageView();
......@@ -226,6 +228,7 @@ public class ViewAlbum implements Initializable {
* @throws IOException
*/
public void switchToMain(MouseEvent mouseEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("main");
}
......@@ -239,6 +242,7 @@ public class ViewAlbum implements Initializable {
if (!tbar_search.getText().isEmpty()){
App.ex.setSearchField(tbar_search.getText());
}
App.ex.setChosenAlbumId(null);
App.setRoot("search");
}
......@@ -248,6 +252,7 @@ public class ViewAlbum implements Initializable {
* @throws IOException
*/
public void switchToExplore(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("explore");
}
......@@ -257,6 +262,7 @@ public class ViewAlbum implements Initializable {
* @throws IOException
*/
public void switchToAlbums(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("explore_albums");
}
......@@ -266,6 +272,7 @@ public class ViewAlbum implements Initializable {
* @throws IOException
*/
public void switchToMap(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("map");
}
......@@ -275,6 +282,7 @@ public class ViewAlbum implements Initializable {
* @throws IOException this page does not exist
*/
public void switchToUpload(ActionEvent actionEvent) throws IOException {
App.ex.setChosenAlbumId(null);
App.setRoot("upload");
}
......@@ -346,4 +354,8 @@ public class ViewAlbum implements Initializable {
HostServices hostServices = App.ex.getHostServices();
hostServices.showDocument(file.getAbsolutePath());
}
public void viewOnMap(ActionEvent actionEvent) throws IOException {
App.setRoot("map");
}
}
......@@ -100,11 +100,20 @@
</font>
</Text>
<Pane fx:id="metadataPane" prefHeight="304.0" prefWidth="700.0" style="-fx-background-color: #ffffff;" />
<Button fx:id="createAlbumPdf" mnemonicParsing="false" onAction="#createPdf" text="CREATE ALBUM PDF">
<font>
<Font size="18.0" />
</font>
</Button>
<HBox prefHeight="39.0" prefWidth="700.0" spacing="20.0">
<children>
<Button fx:id="createAlbumPdf" mnemonicParsing="false" onAction="#createPdf" text="CREATE ALBUM PDF">
<font>
<Font size="18.0" />
</font>
</Button>
<Button fx:id="viewOnMapBtn" mnemonicParsing="false" onAction="#viewOnMap" text="VIEW ON MAP">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment