@Override public void start(Stage primaryStage) throws Exception { /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem saveMenuItem = new MenuItem("Save", imageFile("images/save.png")); fileMenu.getItems().add(saveMenuItem); MenuItem saveAsMenuItem = new MenuItem("Save As...", imageFile("images/save_as.png")); fileMenu.getItems().add(saveAsMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); primaryStage.setTitle("Lab08"); // grid contains all of the textfeilds, labels , buttons, ect.. GridPane grid = new GridPane(); // the tableview puts all of our data into a exel like format TableView<StudentRecord> table = new TableView<>(); table.setItems(DataSource.getAllMarks()); table.setEditable(true); TableColumn<StudentRecord, String> IDColumn = null; IDColumn = new TableColumn<>("SID"); IDColumn.setMinWidth(100); // the thing in quotes is what it will search for in the StudentRecords.java (MAKE SURE THERE IS // A GET FUNCTION FOR THAT VARIBALE) IDColumn.setCellValueFactory(new PropertyValueFactory<>("ID")); TableColumn<StudentRecord, Double> AssignmentColumn = null; AssignmentColumn = new TableColumn<>("Assignment"); AssignmentColumn.setMinWidth(100); AssignmentColumn.setCellValueFactory(new PropertyValueFactory<>("Assign")); TableColumn<StudentRecord, Float> MidtermColumn = null; MidtermColumn = new TableColumn<>("Midterm"); MidtermColumn.setMinWidth(100); MidtermColumn.setCellValueFactory(new PropertyValueFactory<>("Midterm")); TableColumn<StudentRecord, Float> FinalColumn = null; FinalColumn = new TableColumn<>("Final Exam"); FinalColumn.setMinWidth(100); FinalColumn.setCellValueFactory(new PropertyValueFactory<>("Final")); TableColumn<StudentRecord, String> GradeColumn = null; GradeColumn = new TableColumn<>("Letter Grade"); GradeColumn.setMinWidth(100); GradeColumn.setCellValueFactory(new PropertyValueFactory<>("Grade")); table.getColumns().add(IDColumn); table.getColumns().add(AssignmentColumn); table.getColumns().add(MidtermColumn); table.getColumns().add(FinalColumn); table.getColumns().add(GradeColumn); Label IDLabel = new Label("SID:"); grid.add(IDLabel, 0, 0); TextField IDField = new TextField(); IDField.setPromptText("SID"); grid.add(IDField, 1, 0); Label AssignLabel = new Label("Assignments:"); grid.add(AssignLabel, 2, 0); TextField AssignField = new TextField(); AssignField.setPromptText("Assignment"); grid.add(AssignField, 3, 0); Label MidLabel = new Label("Midterm:"); grid.add(MidLabel, 0, 1); TextField midField = new TextField(); midField.setPromptText("Midterm"); grid.add(midField, 1, 1); Label FinalLabel = new Label("Final:"); grid.add(FinalLabel, 2, 1); TextField FinalField = new TextField(); FinalField.setPromptText("Final"); grid.add(FinalField, 3, 1); Button AddButton = new Button("Add"); AddButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { char Grade; String SID = IDField.getText(); Float Assignment = Float.parseFloat(AssignField.getText()); Float Midterm = Float.parseFloat(midField.getText()); Float Final = Float.parseFloat(FinalField.getText()); table.getItems().add(new StudentRecord(SID, Assignment, Midterm, Final)); IDField.setText(""); AssignField.setText(""); midField.setText(""); FinalField.setText(""); } }); grid.add(AddButton, 0, 2); layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(grid); Scene scene = new Scene(layout); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(10); grid.setHgap(10); primaryStage.setScene(scene); primaryStage.show(); }
/** Done by Marco */ public void searchForPubs() { pubLayout.getChildren().remove(noPub); int y = 1; int x = 1; searchName = searchNameInput.getText(); searchStreet = searchStreetInput.getText(); /** End of marco's work */ /** Done by Ahmad */ if (!searchAgeInput.getText().equals("")) { searchAge = Integer.valueOf(searchAgeInput.getText()); } else searchAge = 100; pubs.getChildren().clear(); /* Random pub search */ randomPub = new Button("- Random Pub -"); randomPub.setId("randomPub-button"); randomPub.setMinWidth(230); randomPub.setMinHeight(100); Random random = new Random(); randomPub.setOnAction( (event) -> { idOfButton(random.nextInt(PubDataAccessor.pubs.size())); primaryStage.setScene(pubPage); setPubScene(); }); randomPub.setAlignment(Pos.CENTER); pubs.getChildren().add(randomPub); GridPane.setRowIndex(randomPub, 1); GridPane.setColumnIndex(randomPub, 0); /** End of Ahmad's Work */ /** Done by Shafiq & Antonino & Marco */ for (Pub pub : PubDataAccessor.pubs) { if (searchEvent && pub.eventName.isEmpty()) { continue; } if (area_checker != 2 && pub.location_id != area) { continue; } if (pub.name != null && (pub.name.toLowerCase().contains(searchName.toLowerCase())) && pub.street != null && (pub.street.toLowerCase().contains(searchStreet.toLowerCase())) && pub.age <= searchAge && pub.nrStars >= numberOfStars && pub.hasStudentDiscount >= discount && pub.hasFee <= fee) { /** End of Shafiq & Antonini & Marco's Work */ /** Done by Marco */ pubButton = new Button("- " + pub.name + " -"); pubButton.setId("pub-button"); pubButton.setMinWidth(230); pubButton.setMinHeight(100); pubButton.setOnAction( (event) -> { idOfButton(pub.id); primaryStage.setScene(pubPage); setPubScene(); }); pubButton.setStyle("-fx-background-image: url(" + "\"" + pub.picture + "\"" + "); "); pubButton.setAlignment(Pos.CENTER); pubs.getChildren().add(pubButton); GridPane.setRowIndex(pubButton, y); GridPane.setColumnIndex(pubButton, x); x++; } } if (pubs.getChildren().size() == 0) { pubLayout.getChildren().add(noPub); noPub.setId("nopubs_message"); } /* new elements */ pubs.setHgap(30); /** End of Marco's work */ }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Demo"); /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Save", imageFile("images/save.png"))); fileMenu.getItems().add(new MenuItem("Save As...", imageFile("images/save_as.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); /* create the table (for the center of the user interface) */ table = new TableView<>(); table.setItems(DataSource.getAllStudents()); table.setEditable(true); /* create the table's columns */ TableColumn<Student, Integer> sidColumn = null; sidColumn = new TableColumn<>("SID"); sidColumn.setMinWidth(100); sidColumn.setCellValueFactory(new PropertyValueFactory<>("sid")); TableColumn<Student, String> firstNameColumn = null; firstNameColumn = new TableColumn<>("First Name"); firstNameColumn.setMinWidth(200); firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName")); firstNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); firstNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setFirstName(event.getNewValue()); }); TableColumn<Student, String> lastNameColumn = null; lastNameColumn = new TableColumn<>("Last Name"); lastNameColumn.setMinWidth(200); lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName")); lastNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); lastNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setLastName(event.getNewValue()); }); TableColumn<Student, Double> gpaColumn = null; gpaColumn = new TableColumn<>("GPA"); gpaColumn.setMinWidth(100); gpaColumn.setCellValueFactory(new PropertyValueFactory<>("gpa")); table.getColumns().add(sidColumn); table.getColumns().add(lastNameColumn); table.getColumns().add(firstNameColumn); table.getColumns().add(gpaColumn); /* create an edit form (for the bottom of the user interface) */ GridPane editArea = new GridPane(); editArea.setPadding(new Insets(10, 10, 10, 10)); editArea.setVgap(10); editArea.setHgap(10); Label sidLabel = new Label("SID:"); editArea.add(sidLabel, 0, 0); TextField sidField = new TextField(); sidField.setPromptText("SID"); editArea.add(sidField, 1, 0); Label fnameLabel = new Label("First name:"); editArea.add(fnameLabel, 0, 1); TextField fnameField = new TextField(); fnameField.setPromptText("First Name"); editArea.add(fnameField, 1, 1); Label lnameLabel = new Label("Last name:"); editArea.add(lnameLabel, 0, 2); TextField lnameField = new TextField(); lnameField.setPromptText("Last Name"); editArea.add(lnameField, 1, 2); Label gpaLabel = new Label("GPA:"); editArea.add(gpaLabel, 0, 3); TextField gpaField = new TextField(); gpaField.setPromptText("GPA"); editArea.add(gpaField, 1, 3); Button addButton = new Button("Add"); addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { int sid = Integer.parseInt(sidField.getText()); String firstName = fnameField.getText(); String lastName = lnameField.getText(); double gpa = Double.parseDouble(gpaField.getText()); table.getItems().add(new Student(sid, firstName, lastName, gpa)); sidField.setText(""); fnameField.setText(""); lnameField.setText(""); gpaField.setText(""); } }); editArea.add(addButton, 1, 4); /* arrange all components in the main user interface */ layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(editArea); Scene scene = new Scene(layout, 600, 600); primaryStage.setScene(scene); primaryStage.show(); }
/* ADMIN SCENE */ public void start(Stage primaryStage) throws Exception { /** Done by Marco */ primaryStage.setTitle("PubFinder"); primaryStage.setResizable(false); PubDataAccessor.PubDataAccessor(); /*Welcome scene*/ WelcomeScene.welcomeScene(); welcomeScene = WelcomeScene.welcomeScene; /*Welcome scene*/ /** End of Marcos Work */ /** Done by Shafiq and Anotnino */ /* Admin add scene*/ AdminAddScene.adminAddscene(); adminAddScene = AdminAddScene.adminAddScene; /* Admin add scene*/ /*Admin login scene*/ AdminLoginScene.adminloginscene(); adminLoginScene = AdminLoginScene.adminLoginScene; /*Admin login scene*/ /*Admin choice scene*/ AdminChoiceScene.adminchoicescene(); adminChoiceScene = AdminChoiceScene.adminChoiceScene; /*Admin choice scene*/ /* Admin Edit Scene*/ adminEditScene = AdminEditScene.editScene; /* Admin Edit Scene*/ /** End of Shafiq and Anotonino's Work */ /*Pub button scene*/ pubLayout = new StackPane(); /** Done by Ahmad */ searchNameInput = new TextField(); searchNameInput.setId("search-field"); searchNameInput.setPromptText("NAME"); /** End of Ahmad's Work */ searchStreetInput = new TextField(); searchStreetInput.setId("search-field"); searchStreetInput.setPromptText("STREET"); searchAgeInput = new TextField(); searchAgeInput.setId("search-field"); searchAgeInput.setPromptText("AGE"); /** Done by Aseel */ CheckBox searchStudentDiscount = new CheckBox("DISCOUNTS"); CheckBox searchBySpecialEvents = new CheckBox("EVENTS"); CheckBox searchWithoutFees = new CheckBox("NO FEES"); searchStudentDiscount.setId("check-search"); searchBySpecialEvents.setId("check-search"); searchWithoutFees.setId("check-search"); ComboBox searchByRating = new ComboBox( FXCollections.observableArrayList( "\uF005", "\uF005\uF005", "\uF005\uF005\uF005", "\uF005\uF005\uF005\uF005", "\uF005\uF005\uF005\uF005\uF005")); searchByRating.setTooltip(new Tooltip("RATING")); searchByRating.setPromptText("RATING"); searchByRating.setId("combo-search"); ComboBox searchByArea = new ComboBox( FXCollections.observableArrayList( "All", "Avenyn", "Linné", "Haga", "Järntorget", "Magasinsgatan", "Vasastaden", "Gamlestaden", "Heden", "Masthugget", "Stigberget", "Other")); searchByArea.setTooltip(new Tooltip("AREA")); searchByArea.setPromptText("AREA"); searchByArea.setId("combo-search"); /** End of Aseel's Work */ /** Done by Marco */ pubLayout.setId("pubs"); search = new Button("SEARCH"); search.setId("button-search"); GridPane inputGrid = new GridPane(); inputGrid.setMaxHeight(100); inputGrid.setHgap(10); inputGrid.setVgap(10); inputGrid.setId("searchGrid"); StackPane.setAlignment(inputGrid, Pos.TOP_LEFT); StackPane.setAlignment(search, Pos.TOP_RIGHT); /** End of Marco's Work */ search.setOnAction(e -> searchForPubs()); /** Done by Ahmad */ searchNameInput.setOnKeyReleased( event1 -> { if (event1.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Ahmad's Work */ /** Done by Marco */ searchStreetInput.setOnKeyReleased( event2 -> { if (event2.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Marco's Work */ /** Done by Ahmad */ searchAgeInput.setOnKeyReleased( event3 -> { if (event3.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Ahmad's Work */ /** Done by Shafiq & Anotnino */ searchStudentDiscount.setOnAction( event4 -> { if (searchStudentDiscount.isSelected()) { discount = 1; } if (!searchStudentDiscount.isSelected()) { discount = 0; } }); searchWithoutFees.setOnAction( event5 -> { if (searchWithoutFees.isSelected()) { fee = 0; } if (!searchWithoutFees.isSelected()) { fee = 1; } }); searchBySpecialEvents.setOnAction( event6 -> { if (searchBySpecialEvents.isSelected()) { searchEvent = true; } if (!searchBySpecialEvents.isSelected()) { searchEvent = false; } }); searchByRating.setOnAction( event7 -> { if (searchByRating.getSelectionModel().isSelected(0)) { numberOfStars = 1; } else if (searchByRating.getSelectionModel().isSelected(1)) { numberOfStars = 2; } else if (searchByRating.getSelectionModel().isSelected(2)) { numberOfStars = 3; } else if (searchByRating.getSelectionModel().isSelected(3)) { numberOfStars = 4; } else if (searchByRating.getSelectionModel().isSelected(4)) { numberOfStars = 5; } }); /** End of Shafiq and Anotino's Work */ /** Done by Aseel and Antonino */ searchByArea.setOnAction( event8 -> { if (searchByArea.getSelectionModel().isSelected(0)) { area_checker = 2; } if (searchByArea.getSelectionModel().isSelected(1)) { area = 0; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(2)) { area = 2; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(3)) { area = 3; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(4)) { area = 4; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(5)) { area = 5; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(6)) { area = 6; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(7)) { area = 7; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(8)) { area = 8; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(9)) { area = 9; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(10)) { area = 10; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(11)) { area = 11; area_checker = 1; } }); /** End of Aeel and Antonino's Work */ /** Done by marco */ ScrollPane pubScroll = new ScrollPane(); pubScroll.setId("scroll"); pubScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); pubScroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubs = new GridPane(); pubScroll.setContent(pubs); pubs.setId("pub-grid"); pubs.setAlignment(Pos.CENTER); pubLayout.getChildren().add(pubScroll); inputGrid.add(searchNameInput, 1, 1); inputGrid.add(searchStreetInput, 2, 1); inputGrid.add(searchAgeInput, 3, 1); inputGrid.add(searchByRating, 4, 1); inputGrid.add(searchByArea, 5, 1); inputGrid.add(searchStudentDiscount, 6, 1); inputGrid.add(searchBySpecialEvents, 7, 1); inputGrid.add(searchWithoutFees, 8, 1); pubLayout.getChildren().add(inputGrid); pubLayout.getChildren().add(search); noPub = new Label("No pubs found"); searchForPubs(); pubScene = new Scene(pubLayout, 1000, 600); pubScene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); /*Pub button scene*/ /*Pub scene*/ ScrollPane pubPageLayout = new ScrollPane(); pubPageLayout.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubPageLayout.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubPageLayout.setFitToWidth(true); pubPageLayout.setContent(xPane); xPane.setId("pubScene"); pubPageLayout.setId("gej"); star.setId("starButton"); eventLabel.setId("eventLabel"); /*Items*/ xPane.add(back, 1, 1); back.setId("button-logout"); back.setOnAction( (event) -> { primaryStage.setScene(pubScene); xPane .getChildren() .removeAll(description, rating, overlay, pubName, map, star, rates, events); descriptionGrid .getChildren() .removeAll(age, open, address, type, discountForStudents, entranceFees); events.getChildren().removeAll(eventDescriptionGrid); eventDescriptionGrid.getChildren().removeAll(eventLabel, eventPane); eventPane.getChildren().removeAll(eventGrid); eventGrid.getChildren().removeAll(eventName, eventDescription); star.setText("0 \uF08A"); star.setStyle( "#starButton{-fx-text-fill: #fff;} #starButton:hover{-fx-text-fill: #fff;}"); }); /** End of Marco's work */ /** Done by Shafiq & Antonino */ star.setOnAction( event -> { int rate = PubDataAccessor.checkRate(this.id); int rateUpdate = rate + 1; /** End of Shafiq & Antonino's Work */ /** Done by marco */ star.setText((rateUpdate) + " \uF004"); PubDataAccessor.updateRate(this.id); star.setStyle("-fx-text-fill: #731a2b;"); }); overlay.setHeight(header.getFitHeight()); overlay.setWidth(header.getFitWidth() + 24); overlay.setX(0); overlay.setY(0); overlay.fillProperty().set(javafx.scene.paint.Color.rgb(115, 26, 43, 0.3)); pubPage = new Scene(pubPageLayout, 1000, 600); pubPage.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); /*Pub scene*/ primaryStage.setScene(welcomeScene); primaryStage.show(); Main.primaryStage = primaryStage; /** End of Marcos work */ }