From 069d31b6d465e3ee251e62a0b1c5964c5b9b394e Mon Sep 17 00:00:00 2001 From: noraej <noraej@stud.ntnu.no> Date: Tue, 21 Apr 2020 23:22:31 +0200 Subject: [PATCH 1/3] lot of updates --- src/App/Components/ImageAnalyzer.java | 31 +-- src/App/Css/Css.java | 340 +++++++++++------------- src/App/Logger/MyLogger.java | 25 -- src/App/Main/Main.java | 12 +- src/App/Scenes/AlbumScene.java | 12 +- src/App/Scenes/ConfirmationBox.java | 5 +- src/App/Scenes/ForgotPasswordScene.java | 12 +- src/App/Scenes/Header.java | 2 +- src/App/Scenes/LogInScene.java | 17 +- src/App/Scenes/MainMenu.java | 6 +- src/App/Scenes/MakeAlbumScene.java | 10 +- src/App/Scenes/MapScene.java | 8 +- src/App/Scenes/PictureScene.java | 6 +- src/App/Scenes/ProfileScene.java | 10 +- src/App/Scenes/SignUpScene.java | 12 +- src/App/Scenes/StageInitializer.java | 3 - src/App/Scenes/UploadScene.java | 18 +- src/App/Scenes/ViewAlbumScene.java | 2 +- src/App/Scenes/ViewPictureBox.java | 11 +- src/App/properties/PropertyValues.java | 20 +- 20 files changed, 254 insertions(+), 308 deletions(-) delete mode 100644 src/App/Logger/MyLogger.java diff --git a/src/App/Components/ImageAnalyzer.java b/src/App/Components/ImageAnalyzer.java index e0b43c7..26032a3 100644 --- a/src/App/Components/ImageAnalyzer.java +++ b/src/App/Components/ImageAnalyzer.java @@ -13,7 +13,7 @@ import java.net.URLConnection; public class ImageAnalyzer { /** - * Used to analyze a image + * Used to analyze an image * * @param url Is the url to where the image is saved * @return A Picture object that contains all the image metadata of the image @@ -26,22 +26,19 @@ public class ImageAnalyzer { InputStream in = con.getInputStream(); javaxt.io.Image image = new javaxt.io.Image(in); java.util.HashMap<Integer, Object> exif = image.getExifTags(); - try { - double[] coord = image.getGPSCoordinate(); - Picture picture = new Picture(); - picture.setUrl(url); - picture.setDate((String) exif.get(0x0132)); - if (coord != null) { - picture.setLatitude(coord[0]); - picture.setLongitude(coord[1]); - } - picture.setHeight(image.getHeight()); - picture.setWidth(image.getWidth()); - picture.setFileSize(con.getContentLength()); - picture.setFileType(con.getContentType()); - return picture; - } catch (NullPointerException e) { - throw e; + + double[] coord = image.getGPSCoordinate(); + Picture picture = new Picture(); + picture.setUrl(url); + picture.setDate((String) exif.get(0x0132)); + if (coord != null) { + picture.setLatitude(coord[0]); + picture.setLongitude(coord[1]); } + picture.setHeight(image.getHeight()); + picture.setWidth(image.getWidth()); + picture.setFileSize(con.getContentLength()); + picture.setFileType(con.getContentType()); + return picture; } } \ No newline at end of file diff --git a/src/App/Css/Css.java b/src/App/Css/Css.java index 6a7d662..b5d1e72 100644 --- a/src/App/Css/Css.java +++ b/src/App/Css/Css.java @@ -15,31 +15,36 @@ import javafx.scene.text.TextAlignment; * The Css class sets the layout for buttons, textfields ect... */ public class Css { - + private static String style = "-fx-cursor: hand;" + + "-fx-border-style:solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px; " + + "-fx-border-color: #C686A5;" + + "-fx-background-color: #D5A6BD; " + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0"; + private static String hoverStyle = "-fx-cursor: hand;" + + "-fx-border-style: solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px;" + + "-fx-border-color: #C686A5;" + + "-fx-background-color: #C686A5;" + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0"; /** * Takes in an array of buttons and sets universal button. * * @param args array of buttons */ - public static void setUniversalButton(Button... args) { + public static void setUniversalButton(int fontSize, int width, int height, Button... args) { for (Button button : args) { - String style = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-width: 1px;-fx-border-radius: 10px; " + - "-fx-border-color: #C686A5;-fx-background-color: #D5A6BD; " + - "-fx-background-radius: 10px;-fx-background-insets: 0"; button.setStyle(style); - button.setFont(Font.font("Century Gothic", 20)); - button.setPrefHeight(30); - button.setPrefWidth(180); + button.setFont(Font.font("Century Gothic", fontSize)); + button.setPrefHeight(height); + button.setPrefWidth(width); button.setAlignment(Pos.CENTER); - button.setOnMouseEntered((e) -> { - button.setStyle("-fx-cursor: hand;-fx-border-style: solid inside;-fx-border-width: 1px;" + - "-fx-border-radius: 10px;-fx-border-color: #C686A5;-fx-background-color: #C686A5;" + - "-fx-background-radius: 10px;-fx-background-insets: 0"); - }); - button.setOnMouseExited((e) -> { - button.setStyle(style); - }); + button.setOnMouseEntered((e) -> button.setStyle(hoverStyle)); + button.setOnMouseExited((e) -> button.setStyle(style)); } } @@ -48,24 +53,18 @@ public class Css { * * @param args array of buttons */ - public static void setUniversalMenuButton(MenuButton... args) { - for (MenuButton button : args) { - String style = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-width: 1px;-fx-border-radius: 10px; " + - "-fx-border-color: #C686A5;-fx-background-color: #D5A6BD; " + - "-fx-background-radius: 10px;-fx-background-insets: 0"; - button.setStyle(style); - button.setFont(Font.font("Century Gothic", 20)); - button.setPrefHeight(30); - button.setPrefWidth(180); - button.setAlignment(Pos.CENTER); - button.setOnMouseEntered((e) -> { - button.setStyle("-fx-cursor: hand;-fx-border-style: solid inside;-fx-border-width: 1px;" + - "-fx-border-radius: 10px;-fx-border-color: #C686A5;-fx-background-color: #C686A5;" + - "-fx-background-radius: 10px;-fx-background-insets: 0"); + public static void setUniversalMenuButton(int fontSize, int width, int height, MenuButton... args) { + for (MenuButton menuButton : args) { + menuButton.setStyle(style); + menuButton.setFont(Font.font("Century Gothic", fontSize)); + menuButton.setPrefHeight(height); + menuButton.setPrefWidth(width); + menuButton.setAlignment(Pos.CENTER); + menuButton.setOnMouseEntered((e) -> { + menuButton.setStyle(hoverStyle); }); - button.setOnMouseExited((e) -> { - button.setStyle(style); + menuButton.setOnMouseExited((e) -> { + menuButton.setStyle(style); }); } } @@ -75,19 +74,24 @@ public class Css { * * @param args array of text fields */ - public static void setTextField(TextField... args) { - String textFieldStyle = "-fx-background-color: #F1F1F1;-fx-border-color: #656565;" + - "-fx-border-radius: 10px;-fx-background-radius: 10px"; + public static void setTextField(int fontSize, int width, int height, TextField... args) { + String textFieldStyle = "-fx-background-color: #F1F1F1;" + + "-fx-border-color: #656565;" + + "-fx-border-radius: 10px;" + + "-fx-background-radius: 10px"; for (TextField textField : args) { textField.setStyle(textFieldStyle); - textField.setPrefHeight(25); - textField.setPrefWidth(700); - textField.setFont(Font.font("Century Gothic", 20)); + textField.setPrefHeight(height); + textField.setPrefWidth(width); + textField.setFont(Font.font("Century Gothic", fontSize)); textField.setOnMouseEntered((e) -> { textField.setStyle("-fx-border-width: 1px;" + - "-fx-border-radius: 10px;-fx-border-color: #000000;-fx-background-color: #E6E6E6;" + - "-fx-background-radius: 10px;-fx-background-insets: 0"); + "-fx-border-radius: 10px;" + + "-fx-border-color: #000000;" + + "-fx-background-color: #E6E6E6;" + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0"); }); textField.setOnMouseExited((e) -> { @@ -139,10 +143,14 @@ public class Css { */ public static void setAlbumButton(Button... arg) { for (Button button : arg) { - String buttonStyle = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-width: 1px;-fx-border-radius: 10px; " + - "-fx-border-color: #DEBACB ;-fx-background-color: #EFDCE5; " + - "-fx-background-radius: 10px;-fx-background-insets: 0;" + + String buttonStyle = "-fx-cursor: hand;" + + "-fx-border-style:solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px; " + + "-fx-border-color: #DEBACB ;" + + "-fx-background-color: #EFDCE5; " + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0;" + "-fx-text-fill: black"; button.setStyle(buttonStyle); button.setFont(Font.font("Century Gothic", 20)); @@ -150,9 +158,14 @@ public class Css { button.setPrefWidth(200); button.setAlignment(Pos.CENTER); button.setOnMouseEntered((e) -> { - button.setStyle("-fx-cursor: hand;-fx-border-style: solid inside;-fx-border-width: 1px;" + - "-fx-border-radius: 10px;-fx-border-color: #793958;-fx-background-color: #EFDCE5;" + - "-fx-background-radius: 10px;-fx-background-insets: 0;" + + button.setStyle("-fx-cursor: hand;" + + "-fx-border-style: solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px;" + + "-fx-border-color: #793958;" + + "-fx-background-color: #EFDCE5;" + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0;" + "-fx-text-fill: black"); }); button.setOnMouseExited((e) -> { @@ -162,129 +175,113 @@ public class Css { } /** - * Takes in an array of labels, and sets the succsesslabel + * Takes in an array of labels and sets a label. * - * @param args array of labels + * @param args array of labels. */ - public static void setSuccessLabel(Label... args) { + public static void setLabel(int fontSize, String color, Label... args) { for (Label label : args) { - label.setStyle("-fx-text-fill: #D5A6BD"); - label.setFont(Font.font("Century Gothic", 20)); + label.setFont(Font.font("Century Gothic", fontSize)); + label.setStyle("-fx-text-fill:" + color); + label.setAlignment(Pos.CENTER); } } /** - * Takes in an array of labels and sets the error label. + * Sets info box. * - * @param args array of labels. + * @param args array of VBoxes */ - public static void setErrorLabel(Label... args) { - for (Label label : args) { - label.setStyle("-fx-text-fill: red"); - label.setFont(Font.font("Century Gothic", 20)); - + public static void setInfoBox(VBox... args) { + String style = "-fx-cursor: hand;" + + "-fx-border-style:solid inside;" + + "-fx-border-width: 2px;" + + "-fx-border-radius: 5px; " + + "-fx-border-color: #F4F4F4;" + + "-fx-background-color: #F4F4F4; " + + "-fx-background-radius: 5px;" + + "-fx-background-insets: 0;" + + "-fx-arc-height: 300"; + for (VBox vBox : args) { + vBox.setStyle(style); } } /** - * Takes in an array of labels and sets a label. + * Sets text style. * - * @param args array of labels. + * @param args array of Text */ - public static void setLabel(Label... args) { - for (Label label : args) { - label.setFont(Font.font("Century Gothic", 28)); - label.setStyle("-fx-text-fill: #656565"); - label.setAlignment(Pos.CENTER); + public static void setText(Text... args) { + for (Text text : args) { + text.setFont(Font.font("Century Gothic", 20)); } } - public static void setTitle(Label... args) { - for (Label label : args) { - label.setFont(Font.font("Century Gothic", 25)); - label.setStyle("-fx-text-fill: #656565"); - } - } - - public static void setTextLabel(Label... args) { - for (Label label : args) { - label.setFont(Font.font("Century Gothic", 20)); - label.setStyle("-fx-text-fill: black"); + /** + * Sets home button style. + * + * @param args list of buttons. + */ + public static void setHomeButton(Button... args) { + for (Button button : args) { + button.setStyle("-fx-background-color: none;"); + button.setOnMouseEntered((e) -> { + button.setStyle("-fx-background-color: #F2F2F2; -fx-cursor: hand"); + }); + button.setOnMouseExited((e) -> { + button.setStyle("-fx-background-color: none"); + }); } } - public static void setInfoBox(VBox infoBox) { - String style = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-width: 2px;-fx-border-radius: 5px; " + - "-fx-border-color: #F4F4F4;-fx-background-color: #F4F4F4; " + - "-fx-background-radius: 5px;-fx-background-insets: 0;-fx-arc-height: 300"; - infoBox.setStyle(style); - } - - public static void setPageTitle(Label pageTitle) { - pageTitle.setFont(Font.font("Century Gothic", 40)); - pageTitle.setStyle("-fx-text-fill: #B6638B"); - } - - public static void setText(Text text) { - text.setFont(Font.font("Century Gothic", 20)); - } - /** - * Sets home button. + * Sets menu button style. * - * @param button an button. + * @param args array of menu buttons */ - public static void setHomeButton(Button button) { - button.setStyle("-fx-background-color: none;"); - button.setOnMouseEntered((e) -> { - button.setStyle("-fx-background-color: #F2F2F2; -fx-cursor: hand"); - }); - button.setOnMouseExited((e) -> { - button.setStyle("-fx-background-color: none"); - }); + public static void setMenuButton(MenuButton... args) { + for (MenuButton menuButton : args) { + menuButton.setStyle("-fx-background-color: none;"); + menuButton.setOnMouseEntered((e) -> { + menuButton.setStyle("-fx-background-color: #F2F2F2; -fx-cursor: hand"); + }); + menuButton.setOnMouseExited((e) -> { + menuButton.setStyle("-fx-background-color: none"); + }); + } } /** - * Sets menu button. + * Sets confirmation button. * - * @param menuButton a MenuButton. + * @param args array of buttons */ - public static void setMenuButton(MenuButton menuButton) { - menuButton.setStyle("-fx-background-color: none;"); - menuButton.setOnMouseEntered((e) -> { - menuButton.setStyle("-fx-background-color: #F2F2F2; -fx-cursor: hand"); - }); - menuButton.setOnMouseExited((e) -> { - menuButton.setStyle("-fx-background-color: none"); - }); - } - - public static void setSmallTextfield(TextField textfield) { - setTextField(textfield); - textfield.setPrefWidth(200); - } - - public static void setSmallButton(Button button) { - setUniversalButton(button); - button.setPrefWidth(100); - } - public static void setConfirmationButton(Button... args) { for (Button button : args) { - String style = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-width: 1px;-fx-border-radius: 10px; " + - "-fx-border-color: #C686A5;-fx-background-color: #D5A6BD; " + - "-fx-background-radius: 10px;-fx-background-insets: 0"; + String style = "-fx-cursor: hand;" + + "-fx-border-style:solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px; " + + "-fx-border-color: #C686A5;" + + "-fx-background-color: #D5A6BD; " + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0"; button.setStyle(style); button.setFont(Font.font("Century Gothic", 15)); button.setPrefHeight(20); button.setPrefWidth(50); button.setAlignment(Pos.CENTER); button.setOnMouseEntered((e) -> { - button.setStyle("-fx-cursor: hand;-fx-border-style: solid inside;-fx-border-width: 1px;" + - "-fx-border-radius: 10px;-fx-border-color: #C686A5;-fx-background-color: #C686A5;" + - "-fx-background-radius: 10px;-fx-background-insets: 0"); + button.setStyle("" + + "-fx-cursor: hand;" + + "-fx-border-style: solid inside;" + + "-fx-border-width: 1px;" + + "-fx-border-radius: 10px;" + + "-fx-border-color: #C686A5;" + + "-fx-background-color: #C686A5;" + + "-fx-background-radius: 10px;" + + "-fx-background-insets: 0"); }); button.setOnMouseExited((e) -> { button.setStyle(style); @@ -292,66 +289,37 @@ public class Css { } } - public static void setConfirmationLabel(Label... args) { - for (Label label : args) { - label.setFont(Font.font("Century Gothic", 20)); - label.setStyle("-fx-text-fill: #656565"); - label.setTextAlignment(TextAlignment.CENTER); - label.setAlignment(Pos.CENTER); - } - } - - public static void setTransparentButton(Button button) { - String style = "-fx-cursor: hand;-fx-border-style:solid inside;" + - "-fx-border-color: transparent;-fx-background-color: transparent;" + - "-fx-text-fill: #793958"; - button.setStyle(style); - button.setFont(Font.font("Century Gothic", 15)); - button.setPrefHeight(50); - button.setPrefWidth(200); - button.setAlignment(Pos.CENTER); - button.setTextAlignment(TextAlignment.RIGHT); - button.setOnMouseEntered((e) -> { - button.setStyle("-fx-cursor: hand;-fx-border-style: solid inside;-fx-border-width: 1px;" + - "-fx-border-color: transparent;-fx-background-color: transparent;-fx-font-weight: bold;" + - "-fx-text-fill: #793958 "); - }); - button.setOnMouseExited((e) -> { - button.setStyle(style); - }); - } - - public static void setButton(int width, int height, int fontSize, Button... arg){ - for (Button button : arg) { - String buttonStyle = "" + + /** + * Sets transparent button. + * + * @param args array of buttons + */ + public static void setTransparentButton(Button... args) { + for (Button button : args) { + String style = "" + "-fx-cursor: hand;" + - "-fx-border-style: solid inside;" + - "-fx-border-width: 1px;" + - "-fx-border-radius: 10px;" + - "-fx-border-color: #C686A5;" + - "-fx-background-color: #D5A6BD;" + - "-fx-background-radius: 10px;" + - "-fx-background-insets: 0;" + - "-fx-text-fill: black"; - button.setStyle(buttonStyle); - button.setFont(Font.font("Century Gothic", fontSize)); - button.setPrefHeight(height); - button.setPrefWidth(width); + "-fx-border-style:solid inside;" + + "-fx-border-color: transparent;" + + "-fx-background-color: transparent;" + + "-fx-text-fill: #793958"; + button.setStyle(style); + button.setFont(Font.font("Century Gothic", 15)); + button.setPrefHeight(50); + button.setPrefWidth(200); button.setAlignment(Pos.CENTER); + button.setTextAlignment(TextAlignment.RIGHT); button.setOnMouseEntered((e) -> { button.setStyle("" + "-fx-cursor: hand;" + "-fx-border-style: solid inside;" + "-fx-border-width: 1px;" + - "-fx-border-radius: 10px;" + - "-fx-border-color: #C686A5;" + - "-fx-background-color: #C686A5;" + - "-fx-background-radius: 10px;" + - "-fx-background-insets: 0;" + - "-fx-text-fill: black"); + "-fx-border-color: transparent;" + + "-fx-background-color: transparent;" + + "-fx-font-weight: bold;" + + "-fx-text-fill: #793958 "); }); button.setOnMouseExited((e) -> { - button.setStyle(buttonStyle); + button.setStyle(style); }); } } diff --git a/src/App/Logger/MyLogger.java b/src/App/Logger/MyLogger.java deleted file mode 100644 index 6e90261..0000000 --- a/src/App/Logger/MyLogger.java +++ /dev/null @@ -1,25 +0,0 @@ -package Logger; - -import java.io.IOException; -import java.util.logging.*; - -public class MyLogger { - private final Logger logger = Logger.getLogger(MyLogger.class.getName()); - private Handler handler; - - public MyLogger() throws IOException { - handler = new FileHandler("log.txt", true); - handler.setFormatter(new SimpleFormatter()); - logger.addHandler(handler); - logger.setLevel(Level.ALL); - } - - public Logger getLogger() { - return logger; - } - - public void closeLogger() { - logger.removeHandler(handler); - handler.close(); - } -} diff --git a/src/App/Main/Main.java b/src/App/Main/Main.java index b2652be..8b63758 100644 --- a/src/App/Main/Main.java +++ b/src/App/Main/Main.java @@ -4,9 +4,6 @@ import Scenes.StageInitializer; import javafx.application.Application; import javafx.stage.Stage; -import javax.persistence.EntityManager; - -import static Database.Hibernate.getEm; /** * The class who ruins the applications @@ -15,15 +12,22 @@ public class Main extends Application { /** * The entry point of application. + * * @param args the input arguments */ public static void main(String[] args) { launch(args); } + /** + * start method. Overrides the start method from its super class + * Starts a stage from stage initializer + * + * @param stage the stage + * @throws Exception . + */ @Override public void start(Stage stage) throws Exception { - EntityManager em = getEm(); StageInitializer.initialize(stage); } } diff --git a/src/App/Scenes/AlbumScene.java b/src/App/Scenes/AlbumScene.java index c8df2a0..e6b921e 100644 --- a/src/App/Scenes/AlbumScene.java +++ b/src/App/Scenes/AlbumScene.java @@ -48,7 +48,7 @@ public class AlbumScene extends SceneBuilder { Label label = new Label(); label.setPrefWidth(200); backButton.setOnAction(e -> StageInitializer.setMainMenuScene()); - Css.setUniversalButton(backButton); + Css.setUniversalButton(20, 180, 30, backButton); GridPane gridPane = new GridPane(); gridPane.setPadding(new Insets(30, 30, 30, 0)); @@ -98,6 +98,12 @@ public class AlbumScene extends SceneBuilder { return albums; } + /** + * Method that views a message if there is no albums. + * + * @return VBox with message + */ + private VBox noAlbumsMessage() { VBox noAlbumsBox = new VBox(); if (albumList.size() == 0) { @@ -105,8 +111,8 @@ public class AlbumScene extends SceneBuilder { Button MakeAlbumButton = new Button("Make album"); noAlbumsBox.setPadding(new Insets(10, 10, 10, 0)); noAlbumsBox.setSpacing(10); - Css.setTextLabel(noAlbumsLabel); - Css.setButton(200, 30, 20, MakeAlbumButton); + Css.setLabel(20, "black", noAlbumsLabel); + Css.setUniversalButton(20, 200, 30, MakeAlbumButton); noAlbumsBox.getChildren().addAll(noAlbumsLabel, MakeAlbumButton); noAlbumsBox.setAlignment(Pos.CENTER); diff --git a/src/App/Scenes/ConfirmationBox.java b/src/App/Scenes/ConfirmationBox.java index 3af6d42..f1050e8 100644 --- a/src/App/Scenes/ConfirmationBox.java +++ b/src/App/Scenes/ConfirmationBox.java @@ -28,11 +28,12 @@ public class ConfirmationBox { /** * Display. Shows the display of the box. Uses title and message as parameters * and gives you the options to say yes or no. + * * @param title the title * @param message the message * @return the boolean */ - public static boolean display(String title, String message){ + public static boolean display(String title, String message) { Stage window = new Stage(); window.getIcons().add(new Image("file:src/App/Images/Logo3.png")); @@ -42,7 +43,7 @@ public class ConfirmationBox { window.setMinHeight(200); Label label = new Label(message); - Css.setConfirmationLabel(label); + Css.setLabel(20, "#656565", label); Button yesButton = new Button("Yes"); Button noButton = new Button("No"); diff --git a/src/App/Scenes/ForgotPasswordScene.java b/src/App/Scenes/ForgotPasswordScene.java index dcd1320..eb4da8d 100644 --- a/src/App/Scenes/ForgotPasswordScene.java +++ b/src/App/Scenes/ForgotPasswordScene.java @@ -2,7 +2,6 @@ package Scenes; import Css.Css; import Database.HibernateClasses.User; -import Logger.MyLogger; import UserSession.UserDAO; import javafx.geometry.Insets; import javafx.scene.control.Button; @@ -19,7 +18,7 @@ import static UserSession.UserSession.newUserSession; * Class LogInScene */ public class ForgotPasswordScene extends SceneBuilder { - private MyLogger logger = new MyLogger(); + private Label usernameLabel = new Label("Username: "); private TextField usernameField = new TextField(); private Button nextButton = new Button("Next"); @@ -68,9 +67,9 @@ public class ForgotPasswordScene extends SceneBuilder { }); - Css.setLabel(usernameLabel, questionLabel, feedbackLabel); - Css.setTextField(usernameField, answerField); - Css.setUniversalButton(loginButton, backButton, nextButton); + Css.setLabel(28,"#656565", usernameLabel, questionLabel, feedbackLabel); + Css.setTextField(20, 700, 25, usernameField, answerField); + Css.setUniversalButton(20, 180, 30, loginButton, backButton, nextButton); loginButton.setOnAction(event -> login(usernameField.getText(), answerField.getText())); @@ -95,14 +94,11 @@ public class ForgotPasswordScene extends SceneBuilder { try { if (userDAO.checkInfoHelp(username, answer)) { newUserSession(username); - logger.getLogger().log(Level.FINE, "Log in successful for user " + username); StageInitializer.setProfileScene(); } else { - logger.getLogger().log(Level.FINE, "Log in failed"); feedbackLabel.setText("Wrong username or answer"); } } catch (NullPointerException e) { - logger.getLogger().log(Level.FINE, "Log in failed"); feedbackLabel.setText("No answer registered"); } } diff --git a/src/App/Scenes/Header.java b/src/App/Scenes/Header.java index e2fd219..3218b82 100644 --- a/src/App/Scenes/Header.java +++ b/src/App/Scenes/Header.java @@ -119,7 +119,7 @@ public class Header { private void setVBox() { vBox.setSpacing(10.0D); vBox.setAlignment(Pos.CENTER); - Css.setPageTitle(pageTitle); + Css.setLabel(28, "#B6638B", pageTitle); vBox.getChildren().addAll(hBox, pageTitle); vBox.setMaxWidth(1000); vBox.setPrefHeight(100.0D); diff --git a/src/App/Scenes/LogInScene.java b/src/App/Scenes/LogInScene.java index 1b1a075..e109187 100644 --- a/src/App/Scenes/LogInScene.java +++ b/src/App/Scenes/LogInScene.java @@ -1,7 +1,6 @@ package Scenes; import Css.Css; -import Logger.MyLogger; import UserSession.UserDAO; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -18,8 +17,6 @@ import static UserSession.UserSession.newUserSession; * Class LogInScene */ public class LogInScene extends SceneBuilder { - private MyLogger logger = new MyLogger(); - private Label usernameLabel = new Label("Username: "); private TextField usernameField = new TextField(); @@ -61,12 +58,16 @@ public class LogInScene extends SceneBuilder { super.getGridPane().add(buttonBox, 0, 4); super.getGridPane().add(feedbackLabel, 0, 6); - Css.setLabel(usernameLabel, passwordLabel, feedbackLabel); - Css.setTextField(usernameField, passwordField); - Css.setUniversalButton(loginButton, signupButton, forgotButton); + Css.setLabel(28, "#656565", usernameLabel, passwordLabel, feedbackLabel); + Css.setTextField(20, 700, 25, usernameField, passwordField); + Css.setUniversalButton(20, 180, 30, loginButton, signupButton, forgotButton); Css.setTransparentButton(forgotButton); - loginButton.setOnAction(event -> login(usernameField.getText(), passwordField.getText())); + try{ + loginButton.setOnAction(event -> login(usernameField.getText(), passwordField.getText())); + } catch (Exception e){ + feedbackLabel.setText("Username or password missing"); + } loginButton.setDefaultButton(true); //Makes it possible to use enter to log in signupButton.setOnAction(event -> { try { @@ -94,10 +95,8 @@ public class LogInScene extends SceneBuilder { UserDAO userDAO = new UserDAO(); if (userDAO.checkInfo(username, password)) { newUserSession(username); - logger.getLogger().log(Level.FINE, "Log in successful for user " + username); StageInitializer.setMainMenuScene(); } else { - logger.getLogger().log(Level.FINE, "Log in failed"); feedbackLabel.setText("Wrong username or password"); } } diff --git a/src/App/Scenes/MainMenu.java b/src/App/Scenes/MainMenu.java index 186918b..ed626b3 100644 --- a/src/App/Scenes/MainMenu.java +++ b/src/App/Scenes/MainMenu.java @@ -60,7 +60,6 @@ public class MainMenu extends SceneBuilder { uploadPic.setPreserveRatio(true); //Preserving ratio uploadPic.setSmooth(true); //Higher quality filtering method uploadPic.setCache(true); //improve performance - Css.setLabel(upload); upload.setPadding(new Insets(40, 0, 0, 0)); uploadBox.getChildren().addAll(uploadPic, upload); uploadBox.setAlignment(Pos.CENTER); @@ -71,7 +70,6 @@ public class MainMenu extends SceneBuilder { picturesPic.setPreserveRatio(true); picturesPic.setSmooth(true); picturesPic.setCache(true); - Css.setLabel(pictures); pictures.setPadding(new Insets(40, 0, 0, 0)); pictureBox.setAlignment(Pos.CENTER); pictureBox.getChildren().addAll(picturesPic, pictures); @@ -82,7 +80,6 @@ public class MainMenu extends SceneBuilder { makeAlbumsPic.setPreserveRatio(true); makeAlbumsPic.setSmooth(true); makeAlbumsPic.setCache(true); - Css.setLabel(makeAlbum); makeAlbum.setPadding(new Insets(12, 0, 0, 0)); makeAlbum.setFont(Font.font("Century Gothic", 27)); makeAlbumBox.setAlignment(Pos.CENTER); @@ -94,7 +91,6 @@ public class MainMenu extends SceneBuilder { albumsPic.setPreserveRatio(true); albumsPic.setSmooth(true); albumsPic.setCache(true); - Css.setLabel(albums); albums.setPadding(new Insets(40, 0, 0, 0)); albumBox.setAlignment(Pos.CENTER); albumBox.getChildren().addAll(albumsPic, albums); @@ -105,13 +101,13 @@ public class MainMenu extends SceneBuilder { mapPic.setPreserveRatio(true); mapPic.setSmooth(true); mapPic.setCache(true); - Css.setLabel(map); map.setPadding(new Insets(40, 0, 0, 0)); mapBox.setAlignment(Pos.CENTER); mapBox.getChildren().addAll(mapPic, map); Button mapButton = new Button("", mapBox); Css.setMainMenuButtons(uploadButton, myPicturesButton, makeAlbumsButton, albumButton, mapButton); + Css.setLabel(28, "#656565", pictures, map, albums, makeAlbum, upload); //Setting all the buttons on actions uploadButton.setOnAction(e -> StageInitializer.setUploadScene()); diff --git a/src/App/Scenes/MakeAlbumScene.java b/src/App/Scenes/MakeAlbumScene.java index f9b5c59..ae36fc9 100644 --- a/src/App/Scenes/MakeAlbumScene.java +++ b/src/App/Scenes/MakeAlbumScene.java @@ -76,15 +76,15 @@ public class MakeAlbumScene extends SceneBuilder { choiceBox.getStylesheets().add("file:src/App/Css/ChoiceBox.css"); //choiceBox.setStyle("-fx-font: Century Gothic"); //choiceBox.getItems().addAll(getAvailableTags()); - Css.setUniversalButton(makeAlbumButton, backButton); - Css.setLabel(searchBoxLabel); + Css.setUniversalButton(20, 180, 30, makeAlbumButton, backButton); + Css.setLabel(28, "#656565", searchBoxLabel); makeAlbumButton.setOnAction(e -> { if (choiceBox.getValue() != t) { makeAlbum(choiceBox.getValue()); } else { feedbackLabel.setText("Select tag"); - Css.setErrorLabel(feedbackLabel); + Css.setLabel(20, "red", feedbackLabel); } }); backButton.setOnAction (e -> StageInitializer.setMainMenuScene ()); @@ -116,10 +116,10 @@ public class MakeAlbumScene extends SceneBuilder { } if (tags.size() > 0) { feedbackLabel.setText("Album " + name + " made"); - Css.setSuccessLabel(feedbackLabel); + Css.setLabel(20, "#656565",feedbackLabel); } else { feedbackLabel.setText("No tag found"); - Css.setErrorLabel(feedbackLabel); + Css.setLabel(20, "red",feedbackLabel); } em.getTransaction().commit(); diff --git a/src/App/Scenes/MapScene.java b/src/App/Scenes/MapScene.java index 4aa3941..1034140 100644 --- a/src/App/Scenes/MapScene.java +++ b/src/App/Scenes/MapScene.java @@ -58,7 +58,7 @@ public class MapScene extends SceneBuilder implements MapComponentInitializedLis super.getGridPane().add(backButton, 0, 1); super.getGridPane().setPadding(new Insets(30, 30, 30, 30)); - Css.setUniversalButton(backButton); + Css.setUniversalButton(20, 180, 30, backButton); backButton.setOnAction(event -> { StageInitializer.setMainMenuScene(); @@ -137,7 +137,7 @@ public class MapScene extends SceneBuilder implements MapComponentInitializedLis info = new Text("There are no pictures with location"); } Css.setInfoBox(pictureInfo); - Css.setTitle(title); + Css.setLabel(28, "#B6638B", title); Css.setText(info); pictureInfo.getChildren().addAll(title, info); return pictureInfo; @@ -166,9 +166,9 @@ public class MapScene extends SceneBuilder implements MapComponentInitializedLis } Css.setInfoBox(pictureInfo); - Css.setTitle(title); + Css.setLabel(28, "#B6638B", title); Css.setText(info); - Css.setUniversalButton(viewPictureButton); + Css.setUniversalButton(20, 180, 30, viewPictureButton); pictureInfo.getChildren().addAll(title, info, viewPictureButton); return pictureInfo; diff --git a/src/App/Scenes/PictureScene.java b/src/App/Scenes/PictureScene.java index 72a0faf..9905de2 100644 --- a/src/App/Scenes/PictureScene.java +++ b/src/App/Scenes/PictureScene.java @@ -53,7 +53,7 @@ public class PictureScene extends SceneBuilder { Button sortByTime = new Button("Sort by date"); MenuButton filterByTag = new MenuButton("Filter by tag"); Button removeFilter = new Button("Remove filter"); - Css.setUniversalButton(sortByTime, removeFilter, backButton); + Css.setUniversalButton(20, 180, 30, sortByTime, removeFilter, backButton); filterByTag.getStylesheets().add("file:src/App/Css/MenuButton.css"); buttonBox.getChildren().addAll(backButton, sortByTime, filterByTag, removeFilter); buttonBox.setAlignment(Pos.CENTER); @@ -191,8 +191,8 @@ public class PictureScene extends SceneBuilder { Button uploadButton = new Button("Upload pictures"); noPicturesBox.setPadding(new Insets(10, 10, 10, 10)); noPicturesBox.setSpacing(10); - Css.setTextLabel(noPicturesLabel); - Css.setButton(200, 50, 17, uploadButton); + Css.setLabel(20, "black", noPicturesLabel); + Css.setUniversalButton(17, 200, 50, uploadButton); noPicturesBox.getChildren().addAll(noPicturesLabel, uploadButton); noPicturesBox.setAlignment(Pos.CENTER); diff --git a/src/App/Scenes/ProfileScene.java b/src/App/Scenes/ProfileScene.java index f2a7b72..ec3a093 100644 --- a/src/App/Scenes/ProfileScene.java +++ b/src/App/Scenes/ProfileScene.java @@ -54,9 +54,9 @@ public class ProfileScene extends SceneBuilder { super.getGridPane().add(feedbackLabel, 0, 8); super.getGridPane().setAlignment(Pos.TOP_CENTER); - Css.setUniversalButton(passwordButton, backButton, deleteButton); - Css.setLabel(passwordTextLabel); - Css.setTextField(passwordField, repeatPasswordField); + Css.setUniversalButton(20, 180, 30, passwordButton, backButton, deleteButton); + Css.setLabel(28, "#656565", passwordTextLabel); + Css.setTextField(20, 200, 25, passwordField, repeatPasswordField); passwordButton.setOnAction(event -> changePassword()); @@ -79,11 +79,11 @@ public class ProfileScene extends SceneBuilder { String newPassword = passwordField.getText(); if (userDAO.checkPassword(newPassword, repeatPasswordField.getText())) { userDAO.changePassword(newPassword); - Css.setSuccessLabel(feedbackLabel); + Css.setLabel(15, "#B6638B", feedbackLabel); feedbackLabel.setText("Password changed"); } else { - Css.setErrorLabel(feedbackLabel); + Css.setLabel(16, "red", feedbackLabel); feedbackLabel.setText("Passwords dont match"); } passwordField.clear(); diff --git a/src/App/Scenes/SignUpScene.java b/src/App/Scenes/SignUpScene.java index a072acd..c9e9fca 100644 --- a/src/App/Scenes/SignUpScene.java +++ b/src/App/Scenes/SignUpScene.java @@ -1,11 +1,9 @@ package Scenes; import Css.Css; -import Logger.MyLogger; import UserSession.UserDAO; import javafx.geometry.Insets; import javafx.scene.control.*; -import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -18,7 +16,6 @@ import static UserSession.UserSession.newUserSession; * Class SignUpScene */ public class SignUpScene extends SceneBuilder{ - private MyLogger logger = new MyLogger(); private Label usernameLabel = new Label("Username* "); private TextField usernameField = new TextField(); @@ -68,9 +65,9 @@ public class SignUpScene extends SceneBuilder{ signUpBox.setSpacing(10); signUpBox.setPadding(new Insets(10, 10, 30, 10)); - Css.setLabel(usernameLabel, passwordLabel, forgotLabel, answereLabel, feedbackLabel); - Css.setTextField(usernameField, passwordField, repeatPasswordField, forgotQuestionField, forgotAnswerField); - Css.setUniversalButton(loginButton, signUpButton); + Css.setLabel(28, "#656565", usernameLabel, passwordLabel, forgotLabel, answereLabel, feedbackLabel); + Css.setTextField(20, 700, 25, usernameField, passwordField, repeatPasswordField, forgotQuestionField, forgotAnswerField); + Css.setUniversalButton(20, 180, 30, loginButton, signUpButton); loginButton.setOnAction(event -> { try { @@ -103,15 +100,12 @@ public class SignUpScene extends SceneBuilder{ if (userDAO.checkUsername(username) && userDAO.checkPassword(password, repeatpassword)) { userDAO.makeUser(username, password, forgotQuestion, forgotAnswer); newUserSession(username); - logger.getLogger().log(Level.FINE, "Sign up successful for user " + username); StageInitializer.setMainMenuScene(); } else if (!userDAO.checkUsername(username)) { - logger.getLogger().log(Level.FINE, "Sign up failed - Username already in use"); feedbackLabel.setText("Username already in use"); } else { - logger.getLogger().log(Level.FINE, "Sign up failed - Passwords don't match"); feedbackLabel.setText("Passwords don't match"); } } diff --git a/src/App/Scenes/StageInitializer.java b/src/App/Scenes/StageInitializer.java index 1c946ab..2be1980 100644 --- a/src/App/Scenes/StageInitializer.java +++ b/src/App/Scenes/StageInitializer.java @@ -1,7 +1,6 @@ package Scenes; import Database.Hibernate; -import Logger.MyLogger; import javafx.scene.image.Image; import javafx.stage.Stage; @@ -138,8 +137,6 @@ public class StageInitializer { static void closeProgram() throws IOException { boolean close = ConfirmationBox.display("Exit", "Are you sure you want to exit?"); if(close) { - MyLogger logger = new MyLogger(); - logger.closeLogger(); stage.close(); Hibernate.getEm().clear(); Hibernate.getEntityManagerFactory().close(); diff --git a/src/App/Scenes/UploadScene.java b/src/App/Scenes/UploadScene.java index d752de2..227d01f 100644 --- a/src/App/Scenes/UploadScene.java +++ b/src/App/Scenes/UploadScene.java @@ -68,13 +68,9 @@ public class UploadScene extends SceneBuilder { super.getGridPane().add(feedbackLabel, 0, 8); super.getGridPane().setAlignment(Pos.TOP_CENTER); - Css.setUniversalButton(browseButton); - Css.setUniversalButton(uploadButton); - Css.setLabel(urlTextLabel); - Css.setTextField(urlTextField); - Css.setLabel(tagTextLabel); - Css.setTextField(tagTextField); - Css.setUniversalButton(backButton); + Css.setUniversalButton(20, 180, 30, browseButton, uploadButton, backButton); + Css.setTextField(20, 700, 25, urlTextField, tagTextField); + Css.setLabel(28, "#656565", tagTextLabel, urlTextLabel); browseButton.setOnAction(event -> { try { @@ -108,22 +104,22 @@ public class UploadScene extends SceneBuilder { feedbackLabel.setVisible(true); if (urlTextField.getText().length() == 0) { feedbackLabel.setText("URL missing"); - Css.setErrorLabel(feedbackLabel); + Css.setLabel(15, "red", feedbackLabel); return false; } try { Image imageTest = new Image(urlTextField.getText()); if (imageTest.isError()) { - Css.setErrorLabel(feedbackLabel); + Css.setLabel(15, "red", feedbackLabel); feedbackLabel.setText("URL is invalid"); return false; } } catch (Exception ex) { - Css.setErrorLabel(feedbackLabel); + Css.setLabel(15, "red", feedbackLabel); feedbackLabel.setText("URL is invalid"); return false; } - Css.setSuccessLabel(feedbackLabel); + Css.setLabel(15, "#B6638B", feedbackLabel); feedbackLabel.setText("Image uploaded successfully"); return true; } diff --git a/src/App/Scenes/ViewAlbumScene.java b/src/App/Scenes/ViewAlbumScene.java index bcd8f31..bcb6767 100644 --- a/src/App/Scenes/ViewAlbumScene.java +++ b/src/App/Scenes/ViewAlbumScene.java @@ -101,7 +101,7 @@ public class ViewAlbumScene extends SceneBuilder { }); backButton.setOnAction(e -> StageInitializer.setAlbumScene()); deleteButton.setOnAction(e -> deleteButtonClicked(name)); - Css.setUniversalButton(makePDFButton, backButton, deleteButton); + Css.setUniversalButton(20, 180, 30, makePDFButton, backButton, deleteButton); HBox hBox = new HBox(); hBox.setAlignment(Pos.CENTER); diff --git a/src/App/Scenes/ViewPictureBox.java b/src/App/Scenes/ViewPictureBox.java index d1ef8b0..b269be2 100644 --- a/src/App/Scenes/ViewPictureBox.java +++ b/src/App/Scenes/ViewPictureBox.java @@ -50,14 +50,12 @@ class ViewPictureBox { Button closeButton = new Button("Close"); closeButton.setOnAction(e -> popUp.close()); - Css.setUniversalButton(closeButton); Button deleteButton = new Button("Delete picture"); deleteButton.setOnAction(e -> deleteButtonClicked(pictureId)); - Css.setUniversalButton(deleteButton); Label title = new Label("Info"); - Css.setTitle(title); + Css.setLabel(25, "#656565", title); ImageView picture = new ImageView(new Image(getPicture(pictureId).getUrl(), 300, 300, true, true, true)); Text info = new Text(); info.setText(getPicture(pictureId).toString()); @@ -85,9 +83,10 @@ class ViewPictureBox { Button addTagButton = new Button("Add"); buttonBox.getChildren().addAll(closeButton, newTagName, addTagButton, deleteButton); - Css.setSmallTextfield(newTagName); - Css.setSmallButton(addTagButton); - Css.setErrorLabel(feedBackLabel); + Css.setUniversalButton(20, 180, 30, closeButton, deleteButton); + Css.setTextField(20, 200, 25, newTagName); + Css.setUniversalButton(20, 100, 30, addTagButton); + Css.setLabel(15, "red", feedBackLabel); newTagName.setPromptText("Add tag"); addTagButton.setOnAction(e -> addTag()); VBox layout = new VBox(); diff --git a/src/App/properties/PropertyValues.java b/src/App/properties/PropertyValues.java index 16b2f39..6ab1565 100644 --- a/src/App/properties/PropertyValues.java +++ b/src/App/properties/PropertyValues.java @@ -5,13 +5,19 @@ import java.io.InputStream; import java.util.Properties; /** - * Class PropertyValues + * Class PropertyValues */ public class PropertyValues { private String propFileName = "pictureit.properties"; private Properties prop = new Properties(); + /** + * Method for getting username to database + * + * @return username + * @throws IOException + */ public String getDBusername() throws IOException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); prop.load(inputStream); @@ -19,6 +25,12 @@ public class PropertyValues { return prop.getProperty("username"); } + /** + * Method for getting password to database + * + * @return password + * @throws IOException + */ public String getDBpassword() throws IOException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); prop.load(inputStream); @@ -26,6 +38,12 @@ public class PropertyValues { return prop.getProperty("password"); } + /** + * Method for getting map key + * + * @return map kay + * @throws IOException + */ public String getMapKey() throws IOException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); prop.load(inputStream); -- GitLab From c7be9af8ba88362742ed62a3da56f05c0dd344ba Mon Sep 17 00:00:00 2001 From: noraej <noraej@stud.ntnu.no> Date: Tue, 21 Apr 2020 23:34:25 +0200 Subject: [PATCH 2/3] more fix --- src/App/Scenes/MakeAlbumScene.java | 2 +- src/App/Scenes/ProfileScene.java | 13 +++++------- src/App/Scenes/UploadScene.java | 8 +++---- src/App/Scenes/ViewPictureBox.java | 34 ++++++++++++++++-------------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/App/Scenes/MakeAlbumScene.java b/src/App/Scenes/MakeAlbumScene.java index ae36fc9..2dfd8b9 100644 --- a/src/App/Scenes/MakeAlbumScene.java +++ b/src/App/Scenes/MakeAlbumScene.java @@ -116,7 +116,7 @@ public class MakeAlbumScene extends SceneBuilder { } if (tags.size() > 0) { feedbackLabel.setText("Album " + name + " made"); - Css.setLabel(20, "#656565",feedbackLabel); + Css.setLabel(20, "#B6638B",feedbackLabel); } else { feedbackLabel.setText("No tag found"); Css.setLabel(20, "red",feedbackLabel); diff --git a/src/App/Scenes/ProfileScene.java b/src/App/Scenes/ProfileScene.java index 7e967f1..4ee2020 100644 --- a/src/App/Scenes/ProfileScene.java +++ b/src/App/Scenes/ProfileScene.java @@ -73,13 +73,10 @@ public class ProfileScene extends SceneBuilder { securityLabel, questionLabel, answerLabel, securityButton); gridPane.setAlignment(Pos.TOP_CENTER); - Css.setUniversalButton(passwordButton, securityButton, changeButton, backButton, deleteButton); - Css.setLabel(passwordTextLabel, questionLabel, answerLabel, forgotQuestionLabel, securityLabel); - Css.setTextField(passwordField, repeatPasswordField, forgotQuestionField, forgotAnswerField); - Css.setTextLabel(questionLabel, answerLabel); - Css.setUniversalButton(20, 180, 30, passwordButton, backButton, deleteButton); - Css.setLabel(28, "#656565", passwordTextLabel); - Css.setTextField(20, 200, 25, passwordField, repeatPasswordField); + Css.setUniversalButton(20, 180, 30, passwordButton, securityButton, changeButton, backButton, deleteButton); + Css.setLabel(28, "#656565", passwordTextLabel, questionLabel, answerLabel, forgotQuestionLabel, securityLabel); + Css.setTextField(20, 200, 25, passwordField, repeatPasswordField, forgotQuestionField, forgotAnswerField); + Css.setLabel(20, "black", questionLabel, answerLabel); passwordButton.setOnAction(event -> changePassword()); @@ -149,7 +146,7 @@ public class ProfileScene extends SceneBuilder { if (forgotQuestionField.getText() == null || forgotAnswerField.getText() == null || forgotQuestionField.getText().equals("") || forgotAnswerField.getText().equals("")) { feedbackLabel.setText("Fill in fields"); - Css.setErrorLabel(feedbackLabel); + Css.setLabel(20, "red", feedbackLabel); } else { user.setForgotQuestion(forgotQuestionField.getText()); diff --git a/src/App/Scenes/UploadScene.java b/src/App/Scenes/UploadScene.java index 227d01f..cefe596 100644 --- a/src/App/Scenes/UploadScene.java +++ b/src/App/Scenes/UploadScene.java @@ -104,22 +104,22 @@ public class UploadScene extends SceneBuilder { feedbackLabel.setVisible(true); if (urlTextField.getText().length() == 0) { feedbackLabel.setText("URL missing"); - Css.setLabel(15, "red", feedbackLabel); + Css.setLabel(20, "red", feedbackLabel); return false; } try { Image imageTest = new Image(urlTextField.getText()); if (imageTest.isError()) { - Css.setLabel(15, "red", feedbackLabel); + Css.setLabel(20, "red", feedbackLabel); feedbackLabel.setText("URL is invalid"); return false; } } catch (Exception ex) { - Css.setLabel(15, "red", feedbackLabel); + Css.setLabel(20, "red", feedbackLabel); feedbackLabel.setText("URL is invalid"); return false; } - Css.setLabel(15, "#B6638B", feedbackLabel); + Css.setLabel(20, "#B6638B", feedbackLabel); feedbackLabel.setText("Image uploaded successfully"); return true; } diff --git a/src/App/Scenes/ViewPictureBox.java b/src/App/Scenes/ViewPictureBox.java index b269be2..43bbd4a 100644 --- a/src/App/Scenes/ViewPictureBox.java +++ b/src/App/Scenes/ViewPictureBox.java @@ -244,24 +244,26 @@ class ViewPictureBox { */ private void addTag() { String newTag = newTagName.getText().trim(); - if (tagCheck(newTag)){ - feedBackLabel.setText("Tag already assigned"); - newTagName.clear(); - } else { - Tag tag = new Tag(); - EntityManager entityManager = getEm(); - entityManager.getTransaction().begin(); - tag.setTag(newTagName.getText().trim()); - tag.setPictureId(pictureId); - tag.setUsername(getInstance().getUserName()); - entityManager.persist(tag); - entityManager.getTransaction().commit(); + if (newTag.equals("")) { + newTagName.clear(); + } else if (tagCheck(newTag)) { + feedBackLabel.setText("Tag already assigned"); + newTagName.clear(); + } else { + Tag tag = new Tag(); + EntityManager entityManager = getEm(); + entityManager.getTransaction().begin(); + tag.setTag(newTagName.getText().trim()); + tag.setPictureId(pictureId); + tag.setUsername(getInstance().getUserName()); + entityManager.persist(tag); + entityManager.getTransaction().commit(); - UploadScene.updateAlbum(tag.getTag(), pictureId); - scrollPane.setContent(tagsBox()); - newTagName.clear(); - } + UploadScene.updateAlbum(tag.getTag(), pictureId); + scrollPane.setContent(tagsBox()); + newTagName.clear(); } + } private boolean tagCheck(String newTag) { boolean tagExists = false; -- GitLab From 74be37918a35ed28dcf9df073375212f2cc7a6fb Mon Sep 17 00:00:00 2001 From: noraej <noraej@stud.ntnu.no> Date: Tue, 21 Apr 2020 23:50:50 +0200 Subject: [PATCH 3/3] More fix --- src/App/Components/PDF.java | 10 ---------- src/App/Scenes/AlbumScene.java | 4 ++-- src/App/Scenes/ForgotPasswordScene.java | 2 +- src/App/Scenes/Header.java | 3 +-- src/App/Scenes/MakeAlbumScene.java | 7 +++---- src/App/Scenes/MapScene.java | 4 ++-- src/App/Scenes/PictureScene.java | 10 +++++----- src/App/Scenes/ProfileScene.java | 5 ++--- src/App/Scenes/UploadScene.java | 10 +++++----- src/App/Scenes/ViewAlbumScene.java | 3 +-- src/App/Scenes/ViewPictureBox.java | 4 ++-- 11 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/App/Components/PDF.java b/src/App/Components/PDF.java index 1c4d720..dd3ce63 100644 --- a/src/App/Components/PDF.java +++ b/src/App/Components/PDF.java @@ -22,16 +22,6 @@ import java.util.ArrayList; * Class PDF */ public class PDF { - private Document document; - - /** - * Constructor for PDF document - * - * @param document a document - */ - public PDF(Document document) { - this.document = document; - } /** * Creates a PDF document based on an album, and adds table with content diff --git a/src/App/Scenes/AlbumScene.java b/src/App/Scenes/AlbumScene.java index e6b921e..d73f3d2 100644 --- a/src/App/Scenes/AlbumScene.java +++ b/src/App/Scenes/AlbumScene.java @@ -14,7 +14,7 @@ import javax.persistence.Query; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; +import static UserSession.UserSession.getUserSession; /** * Class AlbumScene @@ -93,7 +93,7 @@ public class AlbumScene extends SceneBuilder { private static List<String> getAlbums() { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT DISTINCT name FROM albums a WHERE a.username = ?1") - .setParameter(1, getInstance().getUserName()); + .setParameter(1, getUserSession().getUserName()); List<String> albums = q.getResultList(); return albums; } diff --git a/src/App/Scenes/ForgotPasswordScene.java b/src/App/Scenes/ForgotPasswordScene.java index eb4da8d..b542990 100644 --- a/src/App/Scenes/ForgotPasswordScene.java +++ b/src/App/Scenes/ForgotPasswordScene.java @@ -111,7 +111,7 @@ public class ForgotPasswordScene extends SceneBuilder { */ private String getQuestion(String username) { UserDAO userDAO = new UserDAO(); - User user = userDAO.getUserbyUsername(username); + User user = userDAO.getUserByUsername(username); return user.getForgotQuestion(); } } diff --git a/src/App/Scenes/Header.java b/src/App/Scenes/Header.java index 3218b82..ffe82e0 100644 --- a/src/App/Scenes/Header.java +++ b/src/App/Scenes/Header.java @@ -12,7 +12,6 @@ import javafx.scene.text.Font; import java.io.IOException; -import static UserSession.UserSession.getInstance; import static UserSession.UserSession.getUserSession; /** @@ -150,7 +149,7 @@ public class Header { openView.setCache(true); menuButton.setGraphic(openView); - MenuItem m1 = new MenuItem("@" + getInstance().getUserName()); + MenuItem m1 = new MenuItem("@" + getUserSession().getUserName()); SeparatorMenuItem separatorMenuItem1 = new SeparatorMenuItem(); MenuItem m2 = new MenuItem("Home"); MenuItem m3 = new MenuItem("Upload"); diff --git a/src/App/Scenes/MakeAlbumScene.java b/src/App/Scenes/MakeAlbumScene.java index 2dfd8b9..bc9cb2b 100644 --- a/src/App/Scenes/MakeAlbumScene.java +++ b/src/App/Scenes/MakeAlbumScene.java @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; import static UserSession.UserSession.getUserSession; /** @@ -111,7 +110,7 @@ public class MakeAlbumScene extends SceneBuilder { Album album = new Album(); album.setName(name); album.setPictureId(t.getPictureId()); - album.setUsername(getInstance().getUserName()); + album.setUsername(getUserSession().getUserName()); em.persist(album); } if (tags.size() > 0) { @@ -171,7 +170,7 @@ public class MakeAlbumScene extends SceneBuilder { private static List<Album> getAlbums() { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT * FROM albums a WHERE a.username = ?1", Album.class) - .setParameter(1, getInstance().getUserName()); + .setParameter(1, getUserSession().getUserName()); List<Album> albums = q.getResultList(); return albums; } @@ -183,7 +182,7 @@ public class MakeAlbumScene extends SceneBuilder { private static List<Tag> getTags(){ EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT distinct * FROM tags t WHERE t.username = ?1", Tag.class) - .setParameter(1, getInstance().getUserName()); + .setParameter(1, getUserSession().getUserName()); List <Tag> tagList = q.getResultList(); return tagList; } diff --git a/src/App/Scenes/MapScene.java b/src/App/Scenes/MapScene.java index 1034140..cf5484c 100644 --- a/src/App/Scenes/MapScene.java +++ b/src/App/Scenes/MapScene.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; +import static UserSession.UserSession.getUserSession; /** * Class MapScene @@ -184,7 +184,7 @@ public class MapScene extends SceneBuilder implements MapComponentInitializedLis EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT * FROM pictures p WHERE p.username = ?1 " + "AND p.latitude != ?2 AND p.longitude != ?3", Picture.class) - .setParameter(1, getInstance().getUserName()) + .setParameter(1, getUserSession().getUserName()) .setParameter(2, 0) .setParameter(3, 0); List<Picture> pictures = q.getResultList(); diff --git a/src/App/Scenes/PictureScene.java b/src/App/Scenes/PictureScene.java index 9905de2..cf63275 100644 --- a/src/App/Scenes/PictureScene.java +++ b/src/App/Scenes/PictureScene.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; +import static UserSession.UserSession.getUserSession; /** * Class PictureScene @@ -126,7 +126,7 @@ public class PictureScene extends SceneBuilder { private static List<String> getTags() { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT DISTINCT tag FROM tags t WHERE t.username = ?1") - .setParameter(1, getInstance().getUserName()); //does not fetch the same tag twice + .setParameter(1, getUserSession().getUserName()); //does not fetch the same tag twice return q.getResultList(); } @@ -140,7 +140,7 @@ public class PictureScene extends SceneBuilder { private static List<Picture> getPictures() { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT * FROM pictures p WHERE p.username = ?1", Picture.class) - .setParameter(1, getInstance().getUserName()); + .setParameter(1, getUserSession().getUserName()); List<Picture> pictures = q.getResultList(); return pictures; } @@ -155,7 +155,7 @@ public class PictureScene extends SceneBuilder { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT * FROM tags t WHERE t.username = ?1 AND tag = ?2", Tag.class) - .setParameter(1, getInstance().getUserName()) + .setParameter(1, getUserSession().getUserName()) .setParameter(2, tag); List<Tag> tags = q.getResultList(); @@ -180,7 +180,7 @@ public class PictureScene extends SceneBuilder { EntityManager em = getEm(); Query q = em.createNativeQuery("SELECT * FROM pictures p WHERE p.username = ?1 ORDER BY date DESC", Picture.class) - .setParameter(1, getInstance().getUserName()); + .setParameter(1, getUserSession().getUserName()); return q.getResultList(); } diff --git a/src/App/Scenes/ProfileScene.java b/src/App/Scenes/ProfileScene.java index 4ee2020..501b18a 100644 --- a/src/App/Scenes/ProfileScene.java +++ b/src/App/Scenes/ProfileScene.java @@ -10,7 +10,6 @@ import javafx.scene.layout.GridPane; import java.io.IOException; -import static UserSession.UserSession.getInstance; import static UserSession.UserSession.getUserSession; @@ -54,7 +53,7 @@ public class ProfileScene extends SceneBuilder { @Override public void setLayout() { super.setLayout(); - super.setPageTitle("@" + getInstance().getUserName()); + super.setPageTitle("@" + getUserSession().getUserName()); passwordField.setPromptText("New password"); repeatPasswordField.setPromptText("Repeat password"); forgotQuestionField.setPromptText("Question"); @@ -142,7 +141,7 @@ public class ProfileScene extends SceneBuilder { } private void changeQuestion() { - User user = userDAO.getUserbyUsername(getUserSession().getUserName()); + User user = userDAO.getUserByUsername(getUserSession().getUserName()); if (forgotQuestionField.getText() == null || forgotAnswerField.getText() == null || forgotQuestionField.getText().equals("") || forgotAnswerField.getText().equals("")) { feedbackLabel.setText("Fill in fields"); diff --git a/src/App/Scenes/UploadScene.java b/src/App/Scenes/UploadScene.java index cefe596..09be811 100644 --- a/src/App/Scenes/UploadScene.java +++ b/src/App/Scenes/UploadScene.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; +import static UserSession.UserSession.getUserSession; /** @@ -147,7 +147,7 @@ public class UploadScene extends SceneBuilder { EntityManager em = getEm(); em.getTransaction().begin(); Picture picture = ImageAnalyzer.analyze(urlIn()); - picture.setUsername(getInstance().getUserName()); + picture.setUsername(getUserSession().getUserName()); em.persist(picture); em.getTransaction().commit(); if (picture.getId() > 0) { @@ -177,7 +177,7 @@ public class UploadScene extends SceneBuilder { Tag tag = new Tag(); tag.setTag(tagName.trim()); tag.setPictureId(pictureID); - tag.setUsername(getInstance().getUserName()); + tag.setUsername(getUserSession().getUserName()); entityManager.persist(tag); entityManager.getTransaction().commit(); @@ -209,7 +209,7 @@ public class UploadScene extends SceneBuilder { public static void updateAlbum(String tag, Long pictureID) { EntityManager entityManager = getEm(); Query q = entityManager.createNativeQuery("SELECT * FROM albums a WHERE a.username = ?1 AND a.name = ?2", Album.class) - .setParameter(1, getInstance().getUserName()) + .setParameter(1, getUserSession().getUserName()) .setParameter(2, tag); List<Album> albums = q.getResultList(); if (albums.size() > 0) { @@ -217,7 +217,7 @@ public class UploadScene extends SceneBuilder { Album album = new Album(); album.setName(tag); album.setPictureId(pictureID); - album.setUsername(getInstance().getUserName()); + album.setUsername(getUserSession().getUserName()); entityManager.persist(album); entityManager.getTransaction().commit(); } diff --git a/src/App/Scenes/ViewAlbumScene.java b/src/App/Scenes/ViewAlbumScene.java index bcb6767..af15671 100644 --- a/src/App/Scenes/ViewAlbumScene.java +++ b/src/App/Scenes/ViewAlbumScene.java @@ -34,7 +34,6 @@ public class ViewAlbumScene extends SceneBuilder { private Button backButton = new Button("Back"); private Button deleteButton = new Button("Delete"); private ArrayList<Long> pictureIds; - private Document document; /** * Constructor: Uses the variables of its super class @@ -92,7 +91,7 @@ public class ViewAlbumScene extends SceneBuilder { makePDFButton.setOnAction(event -> { try { - PDF pdfen = new PDF(document); + PDF pdfen = new PDF(); pdfen.createPDF(pictures, name); } catch (IOException | DocumentException e) { diff --git a/src/App/Scenes/ViewPictureBox.java b/src/App/Scenes/ViewPictureBox.java index 43bbd4a..ea0c44d 100644 --- a/src/App/Scenes/ViewPictureBox.java +++ b/src/App/Scenes/ViewPictureBox.java @@ -25,7 +25,7 @@ import javax.persistence.Query; import java.util.List; import static Database.Hibernate.getEm; -import static UserSession.UserSession.getInstance; +import static UserSession.UserSession.getUserSession; /** * Class ViewPictureBox @@ -255,7 +255,7 @@ class ViewPictureBox { entityManager.getTransaction().begin(); tag.setTag(newTagName.getText().trim()); tag.setPictureId(pictureId); - tag.setUsername(getInstance().getUserName()); + tag.setUsername(getUserSession().getUserName()); entityManager.persist(tag); entityManager.getTransaction().commit(); -- GitLab