Skip to content
Snippets Groups Projects
Commit f4cfe0b0 authored by Eirik Steira's avatar Eirik Steira
Browse files

Merge branch 'feat/view-album-fields' into 'dev'

Feat/view album fields

See merge request !81
parents 12efc012 239dce78
No related branches found
No related tags found
2 merge requests!104Weekly merge to Master,!81Feat/view album fields
......@@ -21,7 +21,7 @@ public final class ApplicationState {
/**
* Anonymous user for developing purposes.
*/
private static User anonymousUser;
private static String anonymousUserUsername = "Anonymous";
private static UserRepository userRepository;
......@@ -47,7 +47,7 @@ public final class ApplicationState {
*/
public static User getCurrentUser() {
return userRepository.findById(currentUser.getUsername())
.orElseGet(() -> userRepository.findById(anonymousUser.getUsername())
.orElseGet(() -> userRepository.findById(anonymousUserUsername)
.orElseThrow(IllegalArgumentException::new));
}
}
......@@ -59,7 +59,7 @@ public class ExploreAlbums implements Initializable {
@FXML
private GridPane albums_grid_pane;
private Pane paneContainer;
private Pane album_pane_container;
private ImageAlbumService imageAlbumService;
......@@ -67,7 +67,6 @@ public class ExploreAlbums implements Initializable {
imageAlbumService = new ImageAlbumService();
}
/**
* Initialize page with all albums. Max 5 per page.
*
......@@ -81,13 +80,13 @@ public class ExploreAlbums implements Initializable {
int maxPerPage = Math.min(albums.size(), 5);
for(int i = 0; i<maxPerPage; i++) {
paneContainer = new Pane();
paneContainer.setPrefWidth(200);
paneContainer.setPrefHeight(100);
album_pane_container = new Pane();
album_pane_container.setPrefWidth(200);
album_pane_container.setPrefHeight(100);
addSingleAlbumContentToPane(albums.get(i), paneContainer);
addSingleAlbumContentToPane(albums.get(i), album_pane_container);
albums_grid_pane.add(paneContainer, 0, i);
albums_grid_pane.add(album_pane_container, 0, i);
}
}
......
......@@ -3,57 +3,274 @@ package NTNU.IDATT1002.controllers;
import NTNU.IDATT1002.App;
import NTNU.IDATT1002.models.ImageAlbum;
import NTNU.IDATT1002.service.ImageAlbumService;
import NTNU.IDATT1002.service.TagService;
import NTNU.IDATT1002.utils.PdfDocument;
import javafx.application.HostServices;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.StrokeType;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
/**
* Controls the buttons and changeable elements on view_album.fxml,
* a page where get a more detailed view of an album
* @version 1.0 22.03.2020
*/
public class ViewAlbum {
public class ViewAlbum implements Initializable {
public TextField tbar_search;
public ImageView tbar_logo;
public Button tbar_explore;
public Button tbar_map;
public Button tbar_upload;
public Button create_album_pdf;
public Pane metadata_pane;
public Text desc_textField;
public Text album_tagsField;
public Button tbar_searchBtn;
public Button tbar_albums;
public Text album_titleField;
public Button scroll_button_next;
public Button scroll_button_previous;
public Text album_authorField;
public Text album_tagsField;
public Text album_descField;
public Pane metadata_pane;
public Button create_album_pdf;
public ImageView main_picture;
public ImageView scroll_picture6;
public ImageView scroll_picture5;
public ImageView scroll_picture4;
public ImageView scroll_picture3;
public ImageView scroll_picture2;
public ImageView scroll_picture1;
public Button scroll_button_next;
public Button scroll_button_previous;
public Text picture_title_field;
public Text picture_tagsField;
public ImageView main_picture;
public Button tbar_searchBtn;
public Button tbar_albums;
private ImageAlbumService imageAlbumService;
@FXML
public GridPane album_fields_grid_pane;
private Pane album_field_container;
private static Logger logger = LoggerFactory.getLogger(ViewAlbum.class);
private ImageAlbumService imageAlbumService;
private Long currentAlbumId;
public ViewAlbum() {
this.imageAlbumService = new ImageAlbumService();
imageAlbumService = new ImageAlbumService();
currentAlbumId = App.ex.getChosenAlbumId();
}
/**
* Initialize view with real album data.
*
* @param url
* @param resourceBundle
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
album_field_container = new Pane();
album_field_container.setPrefHeight(1011.0);
album_field_container.setPrefWidth(975.0);
album_field_container.setStyle("-fx-background-color: #999999;");
Optional<ImageAlbum> foundImageAlbum = imageAlbumService.getImageAlbumById(currentAlbumId);
foundImageAlbum.ifPresent(imageAlbum -> addAlbumToPane(imageAlbum, album_field_container));
album_fields_grid_pane.add(album_field_container, 0, 0);
}
/**
* Add given album to given pane.
*
* @param imageAlbum the album to add
* @param pane the pane to add the album to
*/
private void addAlbumToPane(ImageAlbum imageAlbum, Pane pane) {
addAlbumFieldsToPane(imageAlbum, pane);
}
/**
* Add albums fields and labels to display an album by.
* This includes title, author, tags and description
*
* @param album the album to display
* @param pane the pane to add the album to
*/
private void addAlbumFieldsToPane(ImageAlbum album, Pane pane) {
insertAlbumTitleLabelToPane(pane);
insertAlbumTitleToPane(album, pane);
insertAlbumAuthorLabelToPane(pane);
insertAlbumAuthorToPane(album, pane);
insertAlbumTagsLabelToPane(pane);
insertAlbumTagsToPane(album, pane);
insertAlbumDescriptionLabelToPane(pane);
insertAlbumDescriptionToPane(album, pane);
}
/**
* Insert album title label to given pane.
*
* @param pane the pane to add the title to
*/
private void insertAlbumTitleLabelToPane(Pane pane) {
Text text = new Text();
text.setText("TITLE: ");
text.setFont(Font.font(36.0));
text.setLayoutX(76.0);
text.setLayoutY(170.0);
text.setStrokeType(StrokeType.OUTSIDE);
pane.getChildren().add(text);
}
/**
* Insert title of the given album to the given pane
*
* @param album the album which title to display
* @param pane the pane to add the title to
*/
private void insertAlbumTitleToPane(ImageAlbum album, Pane pane) {
album_titleField = new Text();
album_titleField.setId("album_titleField");
album_titleField.setText(album.getTitle());
album_titleField.setFont(Font.font(36.0));
album_titleField.setLayoutX(190.0);
album_titleField.setLayoutY(170.0);
album_titleField.setStrokeType(StrokeType.OUTSIDE);
album_titleField.setStrokeWidth(0.0);
pane.getChildren().add(album_titleField);
}
/**
* Insert author label of the given album to the given pane
*
* @param pane the pane to add the author label to
*/
private void insertAlbumAuthorLabelToPane(Pane pane) {
Text authorLabel = new Text();
authorLabel.setText("AUTHOR: ");
authorLabel.setFont(Font.font(24.0));
authorLabel.setLayoutX(76.0);
authorLabel.setLayoutY(206.0);
authorLabel.setStrokeType(StrokeType.OUTSIDE);
authorLabel.setStrokeWidth(0.0);
pane.getChildren().add(authorLabel);
}
/**
* Insert author of the given album to the given pane
*
* @param album the album which author to display
* @param pane the pane to add the author to
*/
private void insertAlbumAuthorToPane(ImageAlbum album, Pane pane) {
album_authorField = new Text();
album_authorField.setId("album_authorField");
album_authorField.setText(album.getUser().getUsername());
album_authorField.setFont(Font.font(24.0));
album_authorField.setLayoutX(200.0);
album_authorField.setLayoutY(206.0);
album_authorField.setStrokeType(StrokeType.OUTSIDE);
album_authorField.setStrokeWidth(0.0);
pane.getChildren().add(album_authorField);
}
/**
* Insert tags label of the given album to the given pane
*
* @param pane the pane to add the tags label to
*/
private void insertAlbumTagsLabelToPane(Pane pane) {
Text tagsLabel = new Text();
tagsLabel.setText("TAGS: ");
tagsLabel.setFont(Font.font(24.0));
tagsLabel.setLayoutX(76.0);
tagsLabel.setLayoutY(239.0);
tagsLabel.setStrokeType(StrokeType.OUTSIDE);
tagsLabel.setStrokeWidth(0.0);
pane.getChildren().add(tagsLabel);
}
/**
* Insert tags of the given album to the given pane
*
* @param album the album which tags to display
* @param pane the pane to add the tags to
*/
private void insertAlbumTagsToPane(ImageAlbum album, Pane pane) {
String tagsAsString = TagService.getTagsAsString(album.getTags());
album_tagsField = new Text();
album_tagsField.setText(tagsAsString);
album_tagsField.setFont(Font.font(24.0));
album_tagsField.setLayoutX(156.0);
album_tagsField.setLayoutY(239.0);
album_tagsField.setStrokeType(StrokeType.OUTSIDE);
album_tagsField.setStrokeWidth(0.0);
pane.getChildren().add(album_tagsField);
}
/**
* Insert description label of the given album to the given pane
*
* @param pane the pane to add the description label to
*/
private void insertAlbumDescriptionLabelToPane(Pane pane) {
Text descriptionLabel = new Text();
descriptionLabel.setText("DESCRIPTION: ");
descriptionLabel.setFont(Font.font(24.0));
descriptionLabel.setLayoutX(76.0);
descriptionLabel.setLayoutY(271.0);
descriptionLabel.setStrokeType(StrokeType.OUTSIDE);
descriptionLabel.setStrokeWidth(0.0);
descriptionLabel.setWrappingWidth(164.24609375);
pane.getChildren().add(descriptionLabel);
}
/**
* Insert description of the given album to the given pane
*
* @param album the album which description to display
* @param pane the pane to add the description to
*/
private void insertAlbumDescriptionToPane(ImageAlbum album, Pane pane) {
album_descField = new Text();
album_descField.setId("album_descField");
album_descField.setText(album.getDescription());
album_descField.setFont(Font.font(14.0));
album_descField.setLayoutX(76.0);
album_descField.setLayoutY(294.0);
album_descField.setStrokeType(StrokeType.OUTSIDE);
album_descField.setStrokeWidth(0.0);
album_descField.setWrappingWidth(822.0);
pane.getChildren().add(album_descField);
}
/**
......
......@@ -30,7 +30,7 @@ public class ViewPicture implements Initializable{
public ImageView picture;
public Text picture_tagsField;
public Text picture_title_field;
public Text desc_textField;
public Text picture_descField;
public Pane metadata_pane;
public Button tbar_searchBtn;
public Button tbar_albums;
......
......@@ -48,7 +48,7 @@ public class LoadDatabase {
new File("t14-test-images/1.jpg"),
tags).get();
imageAlbumService.createImageAlbum("First",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#winter"),
new Tag("#nature"),
......@@ -66,7 +66,7 @@ public class LoadDatabase {
new File("t14-test-images/7.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Seventh",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#winter"),
new Tag("#nature"),
......@@ -93,7 +93,7 @@ public class LoadDatabase {
new File("t14-test-images/2.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Second",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#mountains"),
new Tag("#water"),
......@@ -110,7 +110,7 @@ public class LoadDatabase {
new File("t14-test-images/10.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Tenth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#fjords"),
new Tag("#nature"),
......@@ -137,7 +137,7 @@ public class LoadDatabase {
new File("t14-test-images/3.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Third",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#mountains"),
new Tag("#water"),
......@@ -155,7 +155,7 @@ public class LoadDatabase {
new File("t14-test-images/9.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Ninth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#art"),
new Tag("#nature"),
......@@ -184,7 +184,7 @@ public class LoadDatabase {
tags).get();
imageAlbumService.createImageAlbum("Fourth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#mountains"),
new Tag("#grass"),
......@@ -202,7 +202,7 @@ public class LoadDatabase {
new File("t14-test-images/5.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Fifth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#mountains"),
new Tag("#water"),
......@@ -230,7 +230,7 @@ public class LoadDatabase {
new File("t14-test-images/6.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Sixth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#mountains"),
new Tag("#waterfall"),
......@@ -258,7 +258,7 @@ public class LoadDatabase {
new File("t14-test-images/8.jpg"),
tags).get();
imageAlbumService.createImageAlbum("Eighth",
"Lorem Ipsum",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",
user,
Arrays.asList(new Tag("#winter"),
new Tag("#nature"),
......
......@@ -15,7 +15,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static NTNU.IDATT1002.service.TagService.getTagsFromString;
/**
......@@ -106,20 +107,6 @@ public class ImageAlbumService {
return createImageAlbum(title, description, user, tags, new ArrayList<>());
}
/**
* Retrieves tags from text field and converts them to a list of tag objects.
*
* @return the list of tag objects
*/
private List<Tag> getTagsFromString(String tagsAsString) {
String[] tags = tagsAsString
.trim()
.split("[, ?.@]+");
return Stream.of(tags)
.map(Tag::new)
.collect(Collectors.toList());
}
/**
* Retrieves all image albums created by the given user by username.
......
package NTNU.IDATT1002.service;
import NTNU.IDATT1002.models.Tag;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Tag Service. Supports common domain specific operations such as converting a list of tags to a string
* and opposite.
*
* @author Eirik Steira
* @version 1.0 26.03.20
*/
public class TagService {
/**
* Retrieves tags from text field and converts them to a list of tag objects.
*
* @return the list of tag objects
*/
public static List<Tag> getTagsFromString(String tagsAsString) {
String[] tags = tagsAsString
.trim()
.split("[, ?.@]+");
return Stream.of(tags)
.map(Tag::new)
.collect(Collectors.toList());
}
/**
* Retrieves tags from list of tags and converts them to a concatenated string.
*
* @param tags the list of tags
* @return the tags as a string
*/
public static String getTagsAsString(List<Tag> tags) {
return tags.stream()
.map(Tag::getName)
.collect(Collectors.joining(", "));
}
}
......@@ -11,6 +11,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.layout.GridPane?>
<AnchorPane prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="NTNU.IDATT1002.controllers.ViewAlbum">
<children>
<VBox prefHeight="1080.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
......@@ -85,51 +86,32 @@
<Button fx:id="scroll_button_next" layoutX="835.0" layoutY="221.0" mnemonicParsing="false" onAction="#loadNextScrollbarView" text="Next" />
</children>
</Pane>
<Pane prefHeight="981.0" prefWidth="975.0" style="-fx-background-color: #999999;">
<children>
<Text layoutX="76.0" layoutY="170.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TITLE:">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Text>
<Text fx:id="album_titleField" layoutX="190.0" layoutY="170.0" strokeType="OUTSIDE" strokeWidth="0.0" text="title">
<font>
<Font size="36.0" />
</font>
</Text>
<Text layoutX="76.0" layoutY="206.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TAGS:">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Text fx:id="album_tagsField" layoutX="156.0" layoutY="206.0" strokeType="OUTSIDE" strokeWidth="0.0" text="#tags">
<font>
<Font size="24.0" />
</font>
</Text>
<Text layoutX="76.0" layoutY="239.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DESCRIPTION:" wrappingWidth="164.24609375">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Text fx:id="desc_textField" layoutX="76.0" layoutY="261.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." wrappingWidth="822.0">
<font>
<Font size="14.0" />
</font>
</Text>
<Text layoutX="76.0" layoutY="357.0" strokeType="OUTSIDE" strokeWidth="0.0" text="PICTURE METADATA:">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Pane fx:id="metadata_pane" layoutX="76.0" layoutY="371.0" prefHeight="391.0" prefWidth="822.0" style="-fx-background-color: #ffffff;" />
<Button fx:id="create_album_pdf" layoutX="394.0" layoutY="810.0" mnemonicParsing="false" onAction="#createPdf" text="CREATE ALBUM PDF">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</Pane>
<GridPane fx:id="album_fields">
<Pane>
<children>
<GridPane fx:id="album_fields_grid_pane">
<Text layoutX="76.0" layoutY="357.0" strokeType="OUTSIDE" strokeWidth="0.0" text="We're sorry, but we could not find the album you were looking for :(">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Text>
</GridPane>
<Text layoutX="76.0" layoutY="357.0" strokeType="OUTSIDE" strokeWidth="0.0" text="PICTURE METADATA:">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Pane fx:id="metadata_pane" layoutX="76.0" layoutY="371.0" prefHeight="391.0" prefWidth="822.0" style="-fx-background-color: #ffffff;" />
<Button fx:id="create_album_pdf" layoutX="394.0" layoutY="810.0" mnemonicParsing="false" onAction="#createPdf" text="CREATE ALBUM PDF">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</Pane>
</GridPane>
</children>
</HBox>
</children>
......
......@@ -56,7 +56,7 @@
<Font name="System Bold" size="24.0" />
</font>
</Text>
<Text fx:id="desc_textField" layoutX="36.0" layoutY="794.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." wrappingWidth="1008.0">
<Text fx:id="picture_descField" layoutX="36.0" layoutY="794.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." wrappingWidth="1008.0">
<font>
<Font size="14.0" />
</font>
......
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