Search in sources :

Example 1 with Factoid

use of retrospector.model.Factoid in project Retrospector by NonlinearFruit.

the class StatsTabController method updateOverall.

private void updateOverall() {
    // Constants
    int last__days = DataManager.getPastDays();
    // Graph Title
    chartReviewsPerDay.setTitle("Past " + last__days + " Days");
    // Data Mining - Vars
    Map<String, Integer> categories = new HashMap<>();
    Map<LocalDate, Map<String, Integer>> last30Days = new HashMap<>();
    InfoBlipAccumulator info = new InfoBlipAccumulator();
    // Data Mining - Calcs
    for (Media m : allMedia) {
        boolean used = false;
        for (Review r : m.getReviews()) {
            if (strooleans.stream().anyMatch(x -> x.getString().equalsIgnoreCase(r.getUser()) && x.isBoolean())) {
                if (ChronoUnit.DAYS.between(r.getDate(), LocalDate.now()) <= last__days) {
                    Map<String, Integer> cat2Num = last30Days.getOrDefault(r.getDate(), new HashMap<>());
                    Integer num = cat2Num.getOrDefault(m.getCategory(), 0);
                    cat2Num.put(m.getCategory(), num + 1);
                    last30Days.put(r.getDate(), cat2Num);
                }
                info.accumulate(r);
                used = true;
            }
        }
        if (used) {
            categories.put(m.getCategory(), categories.getOrDefault(m.getCategory(), 0) + 1);
            info.accumulate(m);
            for (Factoid f : m.getFactoids()) {
                info.accumulate(f);
            }
        //                media++;
        }
    }
    if (overallContainer.getChildren().size() > 3)
        overallContainer.getChildren().remove(2);
    overallContainer.getChildren().add(2, info.getInfo());
    // Chart # Media / Category
    chartMediaPerCategory.setData(FXCollections.observableArrayList(Arrays.asList(DataManager.getCategories()).stream().map(c -> {
        int count = categories.getOrDefault(c, 0);
        PieChart.Data data = new PieChart.Data(c + " - " + count, count);
        return data;
    }).collect(Collectors.toList())));
    for (PieChart.Data data : chartMediaPerCategory.getData()) {
        String category = data.getName().substring(0, data.getName().indexOf(" - "));
        int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
        data.getNode().setStyle("-fx-pie-color: " + colors[(i > 0 ? i : 0) % colors.length] + ";");
    }
    for (Node node : chartMediaPerCategory.lookupAll("Label.chart-legend-item")) {
        Shape symbol = new Circle(5);
        Label label = (Label) node;
        String category = label.getText().substring(0, label.getText().indexOf(" - "));
        int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
        symbol.setStyle("-fx-fill: " + colors[(i > 0 ? i : 0) % colors.length]);
        label.setGraphic(symbol);
    }
    // Chart # Reviews / Day
    ObservableList<XYChart.Series<String, Number>> list = FXCollections.observableArrayList();
    LocalDate now = LocalDate.now();
    for (String category : DataManager.getCategories()) {
        XYChart.Series data = new XYChart.Series();
        data.setName(category);
        for (int i = last__days; i > -1; i--) {
            LocalDate target = now.minusDays(i);
            int count = last30Days.getOrDefault(target, new HashMap<>()).getOrDefault(category, 0);
            String key = target.getDayOfMonth() + "";
            data.getData().add(new XYChart.Data(key, count));
        }
        list.add(data);
    }
    chartReviewsPerDay.setData(list);
    for (Node node : chartReviewsPerDay.lookupAll("Label.chart-legend-item")) {
        Shape symbol = new Rectangle(7, 7);
        Label label = (Label) node;
        String category = label.getText();
        int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
        symbol.setStyle("-fx-fill: " + colors[(i > 0 ? i : 0) % colors.length]);
        label.setGraphic(symbol);
    }
    for (XYChart.Series<String, Number> serie : chartReviewsPerDay.getData()) {
        String category = serie.getName();
        int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
        for (XYChart.Data<String, Number> data : serie.getData()) {
            data.getNode().setStyle("-fx-background-color: " + colors[(i > 0 ? i : 0) % colors.length] + ";");
        }
    }
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Factoid(retrospector.model.Factoid) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Media(retrospector.model.Media) HashSet(java.util.HashSet) LineChart(javafx.scene.chart.LineChart) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) Circle(javafx.scene.shape.Circle) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) Review(retrospector.model.Review) Node(javafx.scene.Node) Set(java.util.Set) Rectangle(javafx.scene.shape.Rectangle) CategoryAxis(javafx.scene.chart.CategoryAxis) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) TAB(retrospector.fxml.CoreController.TAB) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) PieChart(javafx.scene.chart.PieChart) Stroolean(retrospector.util.Stroolean) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) LocalDate(java.time.LocalDate) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) DataManager(retrospector.model.DataManager) Shape(javafx.scene.shape.Shape) Shape(javafx.scene.shape.Shape) HashMap(java.util.HashMap) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) Review(retrospector.model.Review) LocalDate(java.time.LocalDate) PieChart(javafx.scene.chart.PieChart) Factoid(retrospector.model.Factoid) Circle(javafx.scene.shape.Circle) Media(retrospector.model.Media) XYChart(javafx.scene.chart.XYChart) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Factoid

use of retrospector.model.Factoid in project Retrospector by NonlinearFruit.

the class StatsTabController method updateCategory.

private void updateCategory() {
    // Category Chooser
    String category = categorySelector.getValue();
    // Colors
    int index = Arrays.asList(DataManager.getCategories()).indexOf(category);
    if (category.equals(universalCategory))
        index = colors.length - 1;
    chartReviewsPerYear.setStyle("CHART_COLOR_1: " + colors[(index > 0 ? index : 0) % colors.length] + ";");
    chartReviewsPerRating.setStyle("CHART_COLOR_1: " + colors[(index > 0 ? index : 0) % colors.length] + ";");
    // Data Mining - Vars
    Map<String, Integer> reviewMap = new HashMap<>();
    int[] reviewsPerRating = new int[DataManager.getMaxRating() + 1];
    InfoBlipAccumulator info = new InfoBlipAccumulator();
    // Data Mining - Calcs
    for (Media m : allMedia) {
        if (category.equals(m.getCategory()) || category.equals(universalCategory)) {
            boolean used = false;
            for (Review r : m.getReviews()) {
                if (strooleans.stream().anyMatch(x -> x.getString().equalsIgnoreCase(r.getUser()) && x.isBoolean())) {
                    reviewsPerRating[r.getRating().intValue()] += 1;
                    String key = r.getDate().getMonthValue() + "-" + r.getDate().getYear();
                    reviewMap.put(key, reviewMap.getOrDefault(key, 0) + 1);
                    info.accumulate(r);
                    used = true;
                }
            }
            if (used) {
                info.accumulate(m);
                for (Factoid f : m.getFactoids()) {
                    info.accumulate(f);
                }
            }
        }
    }
    if (categoryContainer.getChildren().size() > 3)
        categoryContainer.getChildren().remove(2);
    categoryContainer.getChildren().add(2, info.getInfo());
    // Chart - # Reviewed / Year
    chartReviewsPerYear.setLegendVisible(false);
    chartReviewsPerYear.getData().clear();
    XYChart.Series data = new XYChart.Series();
    int year = info.getEarliest().getYear();
    int month = info.getEarliest().getMonthValue();
    for (int i = 0; i <= ChronoUnit.MONTHS.between(info.getEarliest(), LocalDate.now()) + 1; i++) {
        String key = month + "-" + year;
        data.getData().add(new XYChart.Data(key, reviewMap.getOrDefault(key, 0)));
        ++month;
        if (month > 12) {
            month = 1;
            ++year;
        }
        if (year >= LocalDate.now().getYear() && month > LocalDate.now().getMonthValue())
            break;
    }
    if (data.getData().size() < 1)
        data.getData().add(new XYChart.Data<>("", 0));
    chartReviewsPerYear.getData().addAll(data);
    // Chart - # Reviews / Rating
    data = new XYChart.Series();
    for (int i = 1; i < reviewsPerRating.length; i++) {
        data.getData().add(new XYChart.Data(i + "", reviewsPerRating[i]));
    }
    if (data.getData().size() < 1)
        data.getData().add(new XYChart.Data<>("", 0));
    chartReviewsPerRating.getData().clear();
    chartReviewsPerRating.getData().add(data);
}
Also used : HashMap(java.util.HashMap) Media(retrospector.model.Media) Review(retrospector.model.Review) XYChart(javafx.scene.chart.XYChart) Factoid(retrospector.model.Factoid)

Example 3 with Factoid

use of retrospector.model.Factoid in project Retrospector by NonlinearFruit.

the class StatsTabController method updateFactoid.

private void updateFactoid() {
    // Selector Values
    String factoidType = factoidSelector.getValue();
    String category = categorySelector.getValue();
    // Colors
    int index = Arrays.asList(DataManager.getFactiodTypes()).indexOf(factoidType);
    chartAverageFactRating.setStyle("CHART_COLOR_1: " + colors[(index >= 0 ? colors.length - index : 0) % colors.length] + ";");
    chartNumOfFacts.setStyle("CHART_COLOR_1: " + colors[(index >= 0 ? colors.length - index : 0) % colors.length] + ";");
    // Data Mining - Vars
    final Integer threshold = 5;
    final Integer maxLabelLen = 13;
    Map<String, Integer> ratingFactsMap = new HashMap<>();
    Map<String, Integer> countReviewFactsMap = new HashMap<>();
    Map<String, Integer> numberFactsMap = new HashMap<>();
    InfoBlipAccumulator info = new InfoBlipAccumulator();
    // Data Mining - Calcs
    for (Media m : allMedia) {
        List<Factoid> factoids = new ArrayList<>(m.getFactoids());
        factoids.add(new Factoid("Title", m.getTitle()));
        factoids.add(new Factoid("Creator", m.getCreator()));
        factoids.add(new Factoid("Season", m.getSeasonId()));
        factoids.add(new Factoid("Episode", m.getEpisodeId()));
        factoids.add(new Factoid("Category", m.getCategory()));
        if (category.equals(m.getCategory()) || category.equals(universalCategory)) {
            boolean user = false;
            boolean fact = false;
            for (Review r : m.getReviews()) if (strooleans.stream().anyMatch(x -> x.getString().equalsIgnoreCase(r.getUser()) && x.isBoolean()))
                user = true;
            for (Factoid factiod : factoids) if (factiod.getTitle().equals(factoidType))
                fact = true;
            if (user && fact) {
                Set<String> contentTypes = new HashSet<>();
                info.accumulate(m);
                SimpleIntegerProperty rating = new SimpleIntegerProperty(0);
                SimpleIntegerProperty count = new SimpleIntegerProperty(0);
                for (Review r : m.getReviews()) if (strooleans.stream().anyMatch(x -> x.getString().equalsIgnoreCase(r.getUser()) && x.isBoolean())) {
                    rating.set(rating.get() + r.getRating().intValueExact());
                    count.set(count.get() + 1);
                    info.accumulate(r);
                }
                for (Factoid factoid : factoids) if (factoid.getTitle().equals(factoidType)) {
                    String f = factoid.getContent();
                    if (f.length() > maxLabelLen)
                        f = f.substring(0, maxLabelLen);
                    contentTypes.add(f);
                    numberFactsMap.put(f, numberFactsMap.getOrDefault(f, 0) + 1);
                    info.accumulate(factoid);
                }
                contentTypes.stream().forEach(content -> {
                    ratingFactsMap.put(content, ratingFactsMap.getOrDefault(content, 0) + rating.get());
                    countReviewFactsMap.put(content, countReviewFactsMap.getOrDefault(content, 0) + count.get());
                });
            }
        }
    }
    if (mediaContainer.getChildren().size() > 3)
        mediaContainer.getChildren().remove(2);
    mediaContainer.getChildren().add(2, info.getInfo());
    // Chart - # of Facts
    chartNumOfFacts.getData().clear();
    XYChart.Series<String, Number> dataNum = new XYChart.Series<>();
    dataNum.setName(factoidType);
    numberFactsMap.keySet().stream().sorted(new NaturalOrderComparator()).forEachOrdered(factoid -> {
        if (numberFactsMap.get(factoid) > 1)
            dataNum.getData().add(new XYChart.Data<>(factoid, numberFactsMap.get(factoid)));
    });
    if (dataNum.getData().size() < 1)
        dataNum.getData().add(new XYChart.Data<>("", 0));
    chartNumOfFacts.getData().add(dataNum);
    // Chart - Average Fact Rating
    chartAverageFactRating.getData().clear();
    XYChart.Series<String, Number> dataAve = new XYChart.Series<>();
    dataAve.setName(factoidType);
    ratingFactsMap.keySet().stream().sorted(new NaturalOrderComparator()).forEachOrdered(factoid -> {
        if (countReviewFactsMap.get(factoid) >= threshold)
            dataAve.getData().add(new XYChart.Data<>(factoid, ratingFactsMap.get(factoid) * 1.0 / countReviewFactsMap.get(factoid)));
    });
    if (dataAve.getData().size() < 1)
        dataAve.getData().add(new XYChart.Data<>("", 0));
    chartAverageFactRating.getData().add(dataAve);
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Factoid(retrospector.model.Factoid) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Media(retrospector.model.Media) HashSet(java.util.HashSet) LineChart(javafx.scene.chart.LineChart) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) Circle(javafx.scene.shape.Circle) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) Review(retrospector.model.Review) Node(javafx.scene.Node) Set(java.util.Set) Rectangle(javafx.scene.shape.Rectangle) CategoryAxis(javafx.scene.chart.CategoryAxis) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) TAB(retrospector.fxml.CoreController.TAB) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) PieChart(javafx.scene.chart.PieChart) Stroolean(retrospector.util.Stroolean) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) LocalDate(java.time.LocalDate) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) DataManager(retrospector.model.DataManager) Shape(javafx.scene.shape.Shape) HashMap(java.util.HashMap) Media(retrospector.model.Media) ArrayList(java.util.ArrayList) Review(retrospector.model.Review) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) XYChart(javafx.scene.chart.XYChart) Factoid(retrospector.model.Factoid) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) HashSet(java.util.HashSet)

Example 4 with Factoid

use of retrospector.model.Factoid in project Retrospector by NonlinearFruit.

the class MediaTabController method getFactoid.

private Factoid getFactoid() {
    if (currentFactoid.get() == null) {
        currentFactoid.set(new Factoid());
        currentFactoid.get().setMediaId(getMedia().getId());
    }
    currentFactoid.get().setTitle(mediaTitleFactoid.getValue());
    currentFactoid.get().setContent(mediaContentFactoid.getText());
    return currentFactoid.get();
}
Also used : Factoid(retrospector.model.Factoid)

Example 5 with Factoid

use of retrospector.model.Factoid in project Retrospector by NonlinearFruit.

the class MediaTabController method initMediaTab.

private void initMediaTab() {
    // Rating Stuff
    mediaStars.setPartialRating(true);
    mediaStars.setDisable(true);
    mediaStars.setMax(DataManager.getMaxRating() / 2);
    mediaStars.setRating(DataManager.getDefaultRating() / 2);
    mediaRating.setText(CoreController.ratingFormat.format(DataManager.getDefaultRating()));
    mediaMaxRating.setText(CoreController.ratingFormat.format(DataManager.getMaxRating()));
    mediaCategory.setItems(FXCollections.observableArrayList(DataManager.getCategories()));
    mediaCategory.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
    });
    // Media Stuff
    mediaTitle.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaCreator.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaSeason.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaEpisode.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaDescription.textProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaCategory.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> mediaSave.setDisable(false));
    mediaType.setItems(FXCollections.observableArrayList(Media.Type.values()));
    mediaType.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
        switch(neo) {
            case SERIES:
                mediaSeasonBox.setVisible(true);
                mediaEpisodeBox.setVisible(true);
                mediaEpisodeBox.toFront();
                break;
            case MINISERIES:
                mediaSeasonBox.setVisible(false);
                mediaEpisodeBox.setVisible(true);
                mediaSeasonBox.toFront();
                break;
            case SINGLE:
            default:
                mediaSeasonBox.setVisible(false);
                mediaEpisodeBox.setVisible(false);
        }
    });
    // Buttons
    mediaSave.setOnAction(e -> {
        Media m = new Media();
        m.clone(getMedia());
        System.out.println("Media ID: " + m.getId());
        m.setTitle(mediaTitle.getText());
        m.setCreator(mediaCreator.getText());
        m.setSeasonId(mediaSeason.getText());
        m.setEpisodeId(mediaEpisode.getText());
        m.setCategory(mediaCategory.getValue());
        m.setType(mediaType.getValue());
        m.setDescription(mediaDescription.getText());
        DataManager.updateDB(m);
        setMedia(m);
        mediaSave.setDisable(true);
    });
    mediaDelete.setOnAction(e -> {
        if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
            DataManager.deleteDB(getMedia());
            setTab(TAB.SEARCH);
        }
    });
    mediaCancel.setOnAction(e -> {
        setTab(TAB.SEARCH);
    });
    mediaNewMedia.setOnAction(e -> {
        Media media = new Media();
        media.setId(DataManager.createDB(media));
        if (media.getId() < 2)
            System.err.println("Media got a <2 id (mediaNewMedia#setOnAction");
        setMedia(media);
        updateMediaTab();
        mediaTitle.requestFocus();
    });
    mediaAddSeason.setOnAction(e -> {
        Media media = new Media(getMedia().getTitle(), getMedia().getCreator(), getMedia().getCategory(), getMedia().getType());
        media.setDescription(getMedia().getDescription());
        int id = DataManager.createDB(media);
        for (Factoid factoid : getMedia().getFactoids()) {
            Factoid fact = new Factoid(factoid.getTitle(), factoid.getContent());
            fact.setMediaId(id);
            DataManager.createDB(fact);
        }
        setMedia(DataManager.getMedia(id));
        if (getMedia().getId() == -1)
            System.err.println("Media got a -1 id (mediaAddSeason#setOnAction");
        updateMediaTab();
        mediaSeason.requestFocus();
    });
    mediaAddEpisode.setOnAction(e -> {
        Media media = new Media(getMedia().getTitle(), getMedia().getCreator(), getMedia().getCategory(), getMedia().getType());
        media.setDescription(getMedia().getDescription());
        media.setSeasonId(getMedia().getSeasonId());
        int id = DataManager.createDB(media);
        for (Factoid factoid : getMedia().getFactoids()) {
            Factoid fact = new Factoid(factoid.getTitle(), factoid.getContent());
            fact.setMediaId(id);
            DataManager.createDB(fact);
        }
        setMedia(DataManager.getMedia(id));
        if (getMedia().getId() == -1)
            System.err.println("Media got a -1 id (mediaAddEpisode#setOnAction");
        updateMediaTab();
        mediaEpisode.requestFocus();
    });
    nextBtn.setOnAction(e -> {
        nextPreviousFunct.accept(1);
        update();
    });
    prevBtn.setOnAction(e -> {
        nextPreviousFunct.accept(-1);
        update();
    });
    // Factoid Stuff
    mediaTitleFactoid.setItems(FXCollections.observableArrayList(DataManager.getFactiodTypes()));
    mediaTitleFactoid.setDisable(true);
    mediaContentFactoid.setDisable(true);
    mediaSaveFactoid.setDisable(true);
    mediaEditFactoid.setDisable(true);
    mediaDeleteFactoid.setDisable(true);
    currentFactoid = new SimpleObjectProperty<>();
    currentFactoid.addListener((observe, old, neo) -> {
        boolean tf = false;
        if (neo == null)
            tf = true;
        mediaTitleFactoid.setDisable(tf);
        mediaContentFactoid.setDisable(tf);
        mediaSaveFactoid.setDisable(tf);
        mediaEditFactoid.setDisable(tf);
        mediaDeleteFactoid.setDisable(tf);
    });
    mediaFactoidTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
        boolean tf = false;
        if (neo == null)
            tf = true;
        mediaEditFactoid.setDisable(tf);
        mediaDeleteFactoid.setDisable(tf);
    });
    mediaFactoidTable.setRowFactory(tv -> {
        TableRow<Factoid> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                setFactoid(row.getItem());
            }
        });
        return row;
    });
    mediaTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
    mediaContentColumn.setCellValueFactory(new PropertyValueFactory<>("Content"));
    mediaNewFactoid.setOnAction(e -> {
        Factoid factoid = new Factoid();
        factoid.setMediaId(getMedia().getId());
        factoid.setId(DataManager.createDB(factoid));
        mediaFactoidTable.getItems().add(factoid);
        setFactoid(factoid);
    });
    mediaEditFactoid.setOnAction(e -> {
        setFactoid(mediaFactoidTable.getSelectionModel().getSelectedItem());
    });
    mediaDeleteFactoid.setOnAction(e -> {
        if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
            DataManager.deleteDB(mediaFactoidTable.getSelectionModel().getSelectedItem());
            updateMediaTab();
        }
    });
    mediaSaveFactoid.setOnAction(e -> {
        Factoid factoid = getFactoid();
        if (factoid.getId() > 0)
            DataManager.updateDB(factoid);
        else
            DataManager.createDB(factoid);
        updateMediaTab();
    });
    // Review Stuff
    mediaReviewTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
        setReview(neo);
    });
    mediaReviewTable.setRowFactory(tv -> {
        TableRow<Review> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                setTab(TAB.REVIEW);
            }
        });
        return row;
    });
    mediaRatingColumn.setCellValueFactory(new PropertyValueFactory<>("Rating"));
    mediaUserColumn.setCellValueFactory(new PropertyValueFactory<>("User"));
    mediaDateColumn.setCellValueFactory(new PropertyValueFactory<>("Date"));
    mediaNewReview.setOnAction(e -> {
        Review review = new Review();
        review.setMediaId(getMedia().getId());
        review.setId(DataManager.createDB(review));
        setReview(review);
        setTab(TAB.REVIEW);
    });
    mediaEditReview.setOnAction(e -> {
        setTab(TAB.REVIEW);
    });
    mediaDeleteReview.setOnAction(e -> {
        if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
            DataManager.deleteDB(getReview());
            updateMediaTab();
        }
    });
}
Also used : TableRow(javafx.scene.control.TableRow) Media(retrospector.model.Media) Alert(javafx.scene.control.Alert) Review(retrospector.model.Review) Factoid(retrospector.model.Factoid)

Aggregations

Factoid (retrospector.model.Factoid)7 ArrayList (java.util.ArrayList)4 Media (retrospector.model.Media)4 Review (retrospector.model.Review)4 URL (java.net.URL)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ResourceBundle (java.util.ResourceBundle)3 ObjectProperty (javafx.beans.property.ObjectProperty)3 ObservableList (javafx.collections.ObservableList)3 FXML (javafx.fxml.FXML)3 Initializable (javafx.fxml.Initializable)3 XYChart (javafx.scene.chart.XYChart)3 Text (javafx.scene.text.Text)3 TAB (retrospector.fxml.CoreController.TAB)3 DataManager (retrospector.model.DataManager)3 LocalDate (java.time.LocalDate)2 ChronoUnit (java.time.temporal.ChronoUnit)2 HashSet (java.util.HashSet)2