public void setStyle(ButtonStyle style) { if (!(style instanceof ImageButtonStyle)) throw new IllegalArgumentException("style must be an ImageButtonStyle."); super.setStyle(style); this.style = (ImageButtonStyle) style; if (image != null) updateImage(); }
private void configureButtons() { // Restaurant button restaurantButton.setGraphic(restaurantIMV); restaurantButton.setStyle("-fx-background-color: transparent"); // reservations button reservationsButton.setGraphic(reservationsIMV); reservationsButton.setStyle("-fx-background-color: transparent"); // customers button customersButton.setGraphic(customersIMV); customersButton.setStyle("-fx-background-color: transparent"); // employees button employeesButton.setGraphic(employeesIMV); employeesButton.setStyle("-fx-background-color: transparent"); // rating button ratingButton.setGraphic(ratingIMV); ratingButton.setStyle("-fx-background-color: transparent"); // archive button archiveButton.setGraphic(archiveIMV); archiveButton.setStyle("-fx-background-color: transparent"); }
@SuppressWarnings("deprecation") private Form getRemoveForm(final String admin) { removeExperimentForm = new Form(); removeExperimentForm.setCaption("Remove Existing Experiment"); removeExperimentForm.setWidth("50%"); expList = eh.getExperiments(null); List<String> strExpList = new ArrayList<String>(); for (ExperimentBean exp : expList.values()) { if (user.getEmail().equalsIgnoreCase("*****@*****.**") || exp.getEmail().equalsIgnoreCase(user.getEmail())) { String str = exp.getExpId() + " " + exp.getName() + " ( " + exp.getUploadedByName() + " )"; strExpList.add(str); } } final Select selectExp = new Select("Experiment ID", strExpList); selectExp.setWidth("100%"); removeExperimentForm.addField(Integer.valueOf(1), selectExp); Button removeExpButton = new Button("Remove Experiment"); removeExpButton.setStyle(Reindeer.BUTTON_SMALL); removeExperimentForm.addField(Integer.valueOf(2), removeExpButton); removeExpButton.addListener( new ClickListener() { /** */ private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { String str = selectExp.getValue().toString(); String[] strArr = str.split("\t"); Integer expId = (Integer.valueOf(strArr[0])); if (expId != null) { boolean test = auth.removeExp(expId); if (test) { updateComponents(user); } else { getWindow().showNotification("Failed to Remove The Experiment! "); } } else { } } }); return removeExperimentForm; }
public void setStyle(ButtonStyle style) { if (!(style instanceof ImageTextButtonStyle)) throw new IllegalArgumentException("style must be a ImageTextButtonStyle."); super.setStyle(style); this.style = (ImageTextButtonStyle) style; if (image != null) updateImage(); if (label != null) { ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle) style; LabelStyle labelStyle = label.getStyle(); labelStyle.font = textButtonStyle.font; labelStyle.fontColor = textButtonStyle.fontColor; label.setStyle(labelStyle); } }
@FXML private void archiveButtonClicked(ActionEvent event) { configureButtons(); archiveButton.setGraphic(archiveSelectedIMV); // clear old content contentPane.getChildren().clear(); // ask for archive date titleLabel.setText("Archiving"); // create text and textfield VBox mainBox = new VBox(); mainBox.setSpacing(20); mainBox.setAlignment(Pos.CENTER); HBox box = new HBox(); contentPane.getChildren().add(mainBox); box.setSpacing(5); box.setAlignment(Pos.CENTER); Label dateLabel = new Label("Cut Off Date:"); dateLabel.setFont(new Font("System", 24)); TextField dateTF = new TextField(); dateTF.setPromptText("YYYY-MM-DD"); Label errorLabel = new Label(); errorLabel.setTextFill(Paint.valueOf("#f5515f")); errorLabel.setFont(new Font("System", 14)); Button confirmButton = new Button("Confirm"); confirmButton.setStyle( "-fx-background-color: #e63347;" + "-fx-background-radius: 7;" + "-fx-text-fill: white"); confirmButton.setPrefSize(130, 40); confirmButton.setOnAction( e -> { if (dateTF.getText() != null) { String cutoffDate = dateTF.getText().trim(); if (cutoffDate.length() > 10) { errorLabel.setText("Too long"); return; } else if (!isDate(cutoffDate)) { errorLabel.setText("Wrong date format"); return; } boolean success = operation.archive(cutoffDate); if (success) { // set up content contentPane.getChildren().clear(); TableView table = new TableView(); TableColumn fnCol = new TableColumn("First Name"); fnCol.setCellValueFactory(new PropertyValueFactory<>("firstName")); TableColumn lnCol = new TableColumn("Last Name"); lnCol.setCellValueFactory(new PropertyValueFactory<>("lastName")); TableColumn emailCol = new TableColumn("Email"); emailCol.setCellValueFactory(new PropertyValueFactory<>("email")); TableColumn lvCol = new TableColumn("Updated At"); lvCol.setCellValueFactory(new PropertyValueFactory<>("updatedAt")); TableColumn discountCol = new TableColumn("Discount"); discountCol.setCellValueFactory(new PropertyValueFactory<>("discount")); table.getColumns().addAll(fnCol, lnCol, emailCol, lvCol, discountCol); ObservableList<Customer> data = FXCollections.observableArrayList(operation.getArchivedCustomers()); table.setItems(data); contentPane.getChildren().add(table); titleLabel.setText("Archived Customers"); } else { titleLabel.setText("Can't archive"); return; } } else { errorLabel.setText("Please enter a date"); return; } }); box.getChildren().addAll(dateLabel, dateTF, errorLabel); mainBox.getChildren().addAll(box, confirmButton); }
@FXML private void ratingButtonClicked(ActionEvent event) throws SQLException { configureButtons(); ratingButton.setGraphic(ratingSelectedIMV); // clear old content contentPane.getChildren().clear(); // set up titleLabel.setText("Rating and Feedback"); // rating box HBox ratingBox = new HBox(); ratingBox.setAlignment(Pos.CENTER); ratingBox.setSpacing(20); ratingBox.setPadding(new Insets(10, 0, 10, 0)); // Rating label Label ratingTitle = new Label("Average Rating: "); ratingTitle.setFont(new Font("System", 24)); // 5 stars String yellowStarURL = "Graphics/StarYellow.png"; String blankStarURL = "Graphics/StarBlank.png"; ImageView starBlank1 = new ImageView(new Image(getClass().getResourceAsStream("Graphics/StarBlank.png"))); ImageView starBlank2 = new ImageView(new Image(getClass().getResourceAsStream("Graphics/StarBlank.png"))); ImageView starBlank3 = new ImageView(new Image(getClass().getResourceAsStream("Graphics/StarBlank.png"))); ImageView starBlank4 = new ImageView(new Image(getClass().getResourceAsStream("Graphics/StarBlank.png"))); ImageView starBlank5 = new ImageView(new Image(getClass().getResourceAsStream("Graphics/StarBlank.png"))); Button star1 = new Button(); star1.setGraphic(starBlank1); star1.setStyle("-fx-background-color: transparent"); Button star2 = new Button(); star2.setGraphic(starBlank2); star2.setStyle("-fx-background-color: transparent"); Button star3 = new Button(); star3.setGraphic(starBlank3); star3.setStyle("-fx-background-color: transparent"); Button star4 = new Button(); star4.setGraphic(starBlank4); star4.setStyle("-fx-background-color: transparent"); Button star5 = new Button(); star5.setGraphic(starBlank5); star5.setStyle("-fx-background-color: transparent"); // get average rating double avgRating = 0; try { avgRating = operation.getAverageRating(); } catch (SQLException e) { e.printStackTrace(); ratingTitle.setText("Error! Can't get average rating"); } Button[] buttonlist = new Button[5]; buttonlist[0] = star1; buttonlist[1] = star2; buttonlist[2] = star3; buttonlist[3] = star4; buttonlist[4] = star5; for (int i = 0; i < Math.floor(avgRating); i++) { ImageView image = new ImageView(new Image(getClass().getResourceAsStream(yellowStarURL))); buttonlist[i].setGraphic(image); } // feedback box VBox feedBackBox = new VBox(); feedBackBox.setAlignment(Pos.CENTER); feedBackBox.setSpacing(20); // Feedback title Label feedBackLabel = new Label("Feedback:"); feedBackLabel.setFont(new Font("System", 24)); // get feedback string String feedback = ""; ArrayList<Rating> list = operation.getRatingsAndFeedbacks(); for (Rating r : list) { feedback += r.getFeedback() + "\n\n"; } Text feedbackText = new Text(feedback); feedbackText.setFont(new Font("System", 14)); ScrollPane scrollPane = new ScrollPane(); scrollPane.setContent(feedbackText); // Add children nodes to appropriate boxes ratingBox.getChildren().addAll(ratingTitle, star1, star2, star3, star4, star5); feedBackBox.getChildren().addAll(feedBackLabel, scrollPane); // main box VBox mainBox = new VBox(); mainBox.setSpacing(40); mainBox.getChildren().addAll(ratingBox, feedBackBox); contentPane.getChildren().add(mainBox); }
/** * Draws the MapMaker screen and displays it to the user * * @param primaryStage the stage to show it in * @throws Exception */ public void drawScreen(Stage primaryStage) throws Exception { // Create the base BorderPane for the whole window BorderPane borderPane = new BorderPane(); borderPane.setStyle("-fx-background-color: papayawhip"); // Add some instructions to the user String text = "Instructions:\n" + "1. Click on the map component that you would like to place in the map\n" + "2. Click on the place in the map where you want to place the component\n" + "3. Repeat until you built the map you want!\n" + "4. Hit the 'Save' button when you are done"; Label instructions = new Label(text); instructions.setFont(Font.font("Arial", FontWeight.BOLD, 12)); instructions.setPadding(new Insets(5, 5, 5, 5)); borderPane.setTop(instructions); // Create the blank Map Pane mapPane = new Pane(); Map map = new Map(width, height); MapGridGUIDecorator mapGridGUIDecorator = new MapGridGUIDecorator(map.getGrid()); ResizeFactor rf = ResizeFactor.getSuggestedResizeFactor(width, height); mapGridGUIDecorator.setResizeFactor(rf); GridPane mapGridPane = mapGridGUIDecorator.drawComponents(); mapGridPane.setPadding(new Insets(0, 0, 5, 5)); mapPane.getChildren().add(mapGridPane); borderPane.setCenter(mapPane); MapMakerController.setCurrentFocused(ComponentType.NOTHING); VBox sideComponents = new VBox(); /* Add "Components" label */ Label componentsLabel = new Label("Components"); componentsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14)); componentsLabel.setPadding(new Insets(15, 5, 0, 20)); sideComponents.getChildren().add(componentsLabel); /* Add Intersection square image */ VBox intersectionPane = new VBox(); Label intersectionLabel = new Label("Intersection"); intersectionLabel.setPadding(new Insets(5, 5, 0, 30)); intersectionLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image intersectionImg = new Image("IntersectionX.png", 60, 60, true, false); intersectionImgView = new ImageView(intersectionImg); StackPane intersectionStackPane = new StackPane(intersectionImgView); intersectionStackPane.setPadding(new Insets(0, 10, 10, 10)); intersectionPane.getChildren().add(intersectionLabel); intersectionPane.getChildren().add(intersectionStackPane); sideComponents.getChildren().add(intersectionPane); /* Add RoadNS square image */ VBox roadNSPane = new VBox(); Label roadNSLabel = new Label("Road (North-South)"); roadNSLabel.setPadding(new Insets(5, 5, 0, 15)); roadNSLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image roadNSImg = new Image("RoadBackgroundNS.png", 60, 60, true, false); roadNSImgView = new ImageView(roadNSImg); StackPane roadNSStackPane = new StackPane(roadNSImgView); roadNSStackPane.setPadding(new Insets(0, 10, 10, 10)); roadNSPane.getChildren().add(roadNSLabel); roadNSPane.getChildren().add(roadNSStackPane); sideComponents.getChildren().add(roadNSPane); /* Add RoadEW square image */ VBox roadEWPane = new VBox(); Label roadEWLabel = new Label("Road (East-West)"); roadEWLabel.setPadding(new Insets(5, 5, 0, 15)); roadEWLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image roadEWImg = new Image("RoadBackgroundEW.png", 60, 60, true, false); roadEWImgView = new ImageView(roadEWImg); StackPane roadEWStackPane = new StackPane(roadEWImgView); roadEWStackPane.setPadding(new Insets(0, 10, 10, 10)); roadEWPane.getChildren().add(roadEWLabel); roadEWPane.getChildren().add(roadEWStackPane); sideComponents.getChildren().add(roadEWPane); /* Add Grass square image to empty out cells */ VBox grassPane = new VBox(); Label grassLabel = new Label("Grass (clear square)"); grassLabel.setPadding(new Insets(5, 5, 0, 15)); grassLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12)); Image grassImg = new Image("Grass.png", 60, 60, true, false); grassImgView = new ImageView(grassImg); StackPane grassStackPane = new StackPane(grassImgView); grassStackPane.setPadding(new Insets(0, 10, 10, 10)); grassPane.getChildren().add(grassLabel); grassPane.getChildren().add(grassStackPane); sideComponents.getChildren().add(grassPane); /* Add Save, Reset buttons */ VBox buttonsPane = new VBox(); buttonsPane.setPadding(new Insets(0, 0, 0, 10)); Label toolsLabel = new Label("Tools"); toolsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14)); toolsLabel.setPadding(new Insets(15, 5, 5, 35)); buttonsPane.getChildren().add(toolsLabel); Insets padding = new Insets(0, 0, 5, 0); Button saveButton = new Button("Save Map"); StackPane saveButtonPane = new StackPane(saveButton); saveButtonPane.setPadding(padding); saveButton.setStyle("-fx-base:Gold"); saveButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); buttonsPane.getChildren().add(saveButtonPane); Button resetButton = new Button("Reset Map"); resetButton.setStyle("-fx-base:Gold"); resetButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); StackPane resetButtonPane = new StackPane(resetButton); resetButtonPane.setPadding(padding); buttonsPane.getChildren().add(resetButtonPane); Button backButton = new Button("Go Back"); backButton.setStyle("-fx-base:Gold"); backButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13)); StackPane backButtonPane = new StackPane(backButton); backButtonPane.setPadding(padding); buttonsPane.getChildren().add(backButtonPane); sideComponents.getChildren().add(buttonsPane); Ticker.start(); /* Add click processing for Map grid squares */ for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Node current = getNodeFromIndex(i, j, mapGridPane); final int x = j; final int y = i; current.setOnMouseClicked( (MouseEvent click) -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.MAP_SQUARE); current.requestFocus(); }); current .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { ComponentType previous = MapMakerController.getPreviousFocused(); if (previous == ComponentType.INTERSECTION) { addIntersection( x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView); } else if (previous == ComponentType.ROADNS) { addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView); } else if (previous == ComponentType.ROADEW) { addRoadEW(x, y, map, mapGridGUIDecorator, mapGridPane, roadEWImgView); } else if (previous == ComponentType.GRASS) { addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView); } }); } } /* Add intersection icon click processing */ DropShadow ds = new DropShadow(15, Color.BLUE); intersectionImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.INTERSECTION); intersectionImgView.requestFocus(); }); intersectionImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) intersectionImgView.setEffect(ds); else intersectionImgView.setEffect(null); }); /* Add roadNS icon click processing */ roadNSImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.ROADNS); roadNSImgView.requestFocus(); }); roadNSImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) roadNSImgView.setEffect(ds); else roadNSImgView.setEffect(null); }); /* Add roadEW icon click processing */ roadEWImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.ROADEW); roadEWImgView.requestFocus(); }); roadEWImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) roadEWImgView.setEffect(ds); else roadEWImgView.setEffect(null); }); /* Add grass icon click processing */ grassImgView.setOnMouseClicked( click -> { MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused()); MapMakerController.setCurrentFocused(ComponentType.GRASS); grassImgView.requestFocus(); }); grassImgView .focusedProperty() .addListener( (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if (newValue) grassImgView.setEffect(ds); else grassImgView.setEffect(null); }); /* Add save button functionality */ saveButton.setOnMouseClicked( click -> { TextInputDialog nameDialog = new TextInputDialog(); nameDialog.setTitle("Save Map"); nameDialog.setHeaderText( "Please provide a name for your map (no spaces or special characters).\nSaved maps go into the /maps directory of your working directory."); nameDialog.setContentText("File name"); Button btOk = (Button) nameDialog.getDialogPane().lookupButton(ButtonType.OK); TextField textfield = nameDialog.getEditor(); Platform.runLater(() -> textfield.requestFocus()); btOk.setDisable(true); textfield .textProperty() .addListener( ((observable, oldValue, newValue) -> { btOk.setDisable(newValue.trim().isEmpty()); })); Optional<String> result = nameDialog.showAndWait(); result.ifPresent( name -> { name = name.concat(".map"); try { Map finalMap = buildAndSaveMap(map); finalMap.saveMap(name); goBack(primaryStage); } catch (Exception e) { e.printStackTrace(); } }); }); resetButton.setOnMouseClicked( click -> { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Component component = map.getAtLocation(new Coordinate(x, y)); if (component instanceof Road || component instanceof Intersection) { addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView); } } } }); backButton.setOnMouseClicked( click -> { try { goBack(primaryStage); } catch (Exception e) { e.printStackTrace(); } }); borderPane.setRight(sideComponents); Scene scene = new Scene(borderPane); primaryStage.setScene(scene); primaryStage.centerOnScreen(); primaryStage.setResizable(false); }