Search in sources :

Example 1 with Stroolean

use of retrospector.util.Stroolean in project Retrospector by NonlinearFruit.

the class ListsTabController method updateListTab.

private void updateListTab() {
    listTableData.clear();
    if (!listGroupCreator.isSelected())
        return;
    boolean creator = listGroupCreator.isSelected();
    boolean title = listGroupTitle.isSelected();
    boolean season = listGroupSeason.isSelected();
    boolean episode = listGroupEpisode.isSelected();
    Chartagories chartagory = episode ? Chartagories.CURRENT_MEDIA : season ? Chartagories.SEASON : title ? Chartagories.TITLE : Chartagories.CREATOR;
    Integer top = listTop10.isSelected() ? 10 : listTop25.isSelected() ? 25 : listTop50.isSelected() ? 50 : listTop100.isSelected() ? 100 : listTop500.isSelected() ? 500 : 1000;
    LocalDate start = listCustomDateRange.isSelected() ? listStartDate.getValue().minus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) - 1, 12, 31);
    start = listUseAllTime.isSelected() ? LocalDate.MIN : start;
    LocalDate end = listCustomDateRange.isSelected() ? listEndDate.getValue().plus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) + 1, 1, 1);
    end = listUseAllTime.isSelected() ? LocalDate.MAX : end;
    String user = listUser.getText();
    for (Media media : DataManager.getMedia()) {
        for (Stroolean stroolean : strooleans) {
            if (stroolean.isBoolean() && media.getCategory().equals(stroolean.getString())) {
                boolean homeless = true;
                for (Media data : listTableData) {
                    Media temp = new Media();
                    temp.clone(media);
                    temp.setCategory(data.getCategory());
                    temp.setType(data.getType());
                    if (UtilityCloset.isSameMedia(chartagory, data, temp)) {
                        homeless = false;
                        for (Review review : media.getReviews()) {
                            if (review.getDate().isBefore(end) && review.getDate().isAfter(start) && review.getUser().equals(user)) {
                                data.getReviews().add(review);
                            }
                        }
                        break;
                    }
                }
                if (homeless) {
                    Media m = new Media();
                    if (creator)
                        m.setCreator(media.getCreator());
                    if (title)
                        m.setTitle(media.getTitle());
                    if (season)
                        m.setSeasonId(media.getSeasonId());
                    if (episode)
                        m.setEpisodeId(media.getEpisodeId());
                    m.setCategory(media.getCategory());
                    for (Review review : media.getReviews()) {
                        if (review.getUser().equals(user)) {
                            if (review.getDate().isBefore(end) && review.getDate().isAfter(start)) {
                                m.getReviews().add(review);
                            }
                        }
                    }
                    listTableData.add(m);
                }
            }
        }
    }
    List rankedResults = listTableData.stream().sorted(new MediaComparator()).limit(top).collect(Collectors.toList());
    listTable.setItems(FXCollections.observableArrayList(rankedResults));
    listRankColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + rankedResults.indexOf(p.getValue())));
    listTable.refresh();
}
Also used : Stroolean(retrospector.util.Stroolean) MediaComparator(retrospector.util.MediaComparator) Media(retrospector.model.Media) List(java.util.List) ObservableList(javafx.collections.ObservableList) Review(retrospector.model.Review) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) LocalDate(java.time.LocalDate)

Example 2 with Stroolean

use of retrospector.util.Stroolean in project Retrospector by NonlinearFruit.

the class StatsTabController method initialize.

/**
     * Initializes the controller class.
     */
@Override
public void initialize(URL url, ResourceBundle rb) {
    //        Collections.rotate(Arrays.asList(colors), -5);
    // Bug Work Around
    chartReviewsPerYear.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data("", 0))));
    chartReviewsPerDay.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data("", 0))));
    chartReviewsPerRating.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data("", 0))));
    chartAverageFactRating.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data("", 0))));
    chartNumOfFacts.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data("", 0))));
    // Overall
    for (String user : DataManager.getUsers()) {
        Stroolean c = new Stroolean(user, true);
        c.booleanProperty().addListener((observe, old, neo) -> update());
        strooleans.add(c);
        overallUserList.getItems().add(c);
    }
    overallUserList.setCellFactory(CheckBoxListCell.forListView(Stroolean::booleanProperty));
    overallUserList.setOnMouseClicked(e -> {
        if (e.getClickCount() == 2) {
            Stroolean me = overallUserList.getSelectionModel().getSelectedItem();
            for (Stroolean stroolean : strooleans) {
                stroolean.setBoolean(false);
            }
            me.setBoolean(true);
        }
    });
    chartMediaPerCategory.setLegendVisible(true);
    chartRpdX.setLabel("Day");
    chartRpdY.setLabel("Reviews");
    // Category
    ObservableList<String> categories = FXCollections.observableArrayList(DataManager.getCategories());
    categories.add(0, universalCategory);
    categorySelector.setItems(categories);
    categorySelector.setValue(DataManager.getCategories()[0]);
    categorySelector.valueProperty().addListener((observe, old, neo) -> updateCategory());
    chartReviewsPerRating.setLegendVisible(false);
    chartRprX.setLabel("Rating");
    chartRprY.setLabel("Reviews");
    chartRpyX.setLabel("Month");
    chartRpyY.setLabel("Reviews");
    // Factoid
    factoidSelector.setItems(FXCollections.observableArrayList(DataManager.getFactiodTypes()));
    factoidSelector.setValue(DataManager.getFactiodTypes()[0]);
    factoidSelector.valueProperty().addListener((observe, old, neo) -> updateFactoid());
    categorySelector.valueProperty().addListener((observe, old, neo) -> updateFactoid());
    chartNumOfFacts.setLegendVisible(false);
    chartAverageFactRating.setLegendVisible(false);
}
Also used : Stroolean(retrospector.util.Stroolean) XYChart(javafx.scene.chart.XYChart)

Example 3 with Stroolean

use of retrospector.util.Stroolean in project Retrospector by NonlinearFruit.

the class ListsTabController method initListTab.

private void initListTab() {
    // Include
    for (String category : DataManager.getCategories()) {
        Stroolean c = new Stroolean(category);
        c.booleanProperty().addListener((observe, old, neo) -> updateListTab());
        strooleans.add(c);
        listIncludeList.getItems().add(c);
    }
    listIncludeList.setCellFactory(CheckBoxListCell.forListView(Stroolean::booleanProperty));
    listIncludeList.setOnMouseClicked(e -> {
        if (e.getClickCount() == 2) {
            Stroolean me = listIncludeList.getSelectionModel().getSelectedItem();
            for (Stroolean stroolean : strooleans) {
                stroolean.setBoolean(false);
            }
            me.setBoolean(true);
        }
    });
    // Group By
    listGroupCreator.setSelected(true);
    listGroupCreator.selectedProperty().addListener((observe, old, neo) -> {
        if (neo) {
        // Nothing to select, top of the food chain
        } else {
            listGroupTitle.setSelected(false);
            listGroupSeason.setSelected(false);
            listGroupEpisode.setSelected(false);
        }
        updateListTab();
    });
    listGroupTitle.selectedProperty().addListener((observe, old, neo) -> {
        if (neo) {
            listGroupCreator.setSelected(true);
        } else {
            listGroupSeason.setSelected(false);
            listGroupEpisode.setSelected(false);
        }
        updateListTab();
    });
    listGroupSeason.selectedProperty().addListener((observe, old, neo) -> {
        if (neo) {
            listGroupCreator.setSelected(true);
            listGroupTitle.setSelected(true);
        } else {
            listGroupEpisode.setSelected(false);
        }
        updateListTab();
    });
    listGroupEpisode.selectedProperty().addListener((observe, old, neo) -> {
        if (neo) {
            listGroupCreator.setSelected(true);
            listGroupTitle.setSelected(true);
            listGroupSeason.setSelected(true);
        } else {
        // Nothing to deselect, bottom of the food chain
        }
        updateListTab();
    });
    // Top 10/0/0
    listTop10.setSelected(true);
    listTop10.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop25.setSelected(false);
            listTop50.setSelected(false);
            listTop100.setSelected(false);
            listTop500.setSelected(false);
            listTop1000.setSelected(false);
        }
    });
    listTop25.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop10.setSelected(false);
            listTop50.setSelected(false);
            listTop100.setSelected(false);
            listTop500.setSelected(false);
            listTop1000.setSelected(false);
        }
    });
    listTop50.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop10.setSelected(false);
            listTop25.setSelected(false);
            listTop100.setSelected(false);
            listTop500.setSelected(false);
            listTop1000.setSelected(false);
        }
    });
    listTop100.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop10.setSelected(false);
            listTop25.setSelected(false);
            listTop50.setSelected(false);
            listTop500.setSelected(false);
            listTop1000.setSelected(false);
        }
    });
    listTop500.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop10.setSelected(false);
            listTop25.setSelected(false);
            listTop50.setSelected(false);
            listTop100.setSelected(false);
            listTop1000.setSelected(false);
        }
    });
    listTop1000.selectedProperty().addListener((observe, old, neo) -> {
        updateListTab();
        if (neo) {
            listTop10.setSelected(false);
            listTop25.setSelected(false);
            listTop50.setSelected(false);
            listTop100.setSelected(false);
            listTop500.setSelected(false);
        }
    });
    // Dates
    listYear.setText(String.valueOf(LocalDate.now().getYear()));
    listYear.setOnAction(e -> updateListTab());
    listStartDate.setValue(LocalDate.now().withMonth(1).withDayOfMonth(1));
    listStartDate.valueProperty().addListener((observe, old, neo) -> updateListTab());
    listEndDate.setValue(LocalDate.now().withMonth(12).withDayOfMonth(31));
    listEndDate.valueProperty().addListener((observe, old, neo) -> updateListTab());
    listUseAllTime.selectedProperty().addListener((observe, old, neo) -> updateListTab());
    listUseYear.selectedProperty().addListener((observe, old, neo) -> updateListTab());
    listCustomDateRange.selectedProperty().addListener((observe, old, neo) -> updateListTab());
    //  - Enable/Disble
    dateToggleGroup.getToggles().addAll(listUseYear, listUseAllTime, listCustomDateRange);
    dateToggleGroup.selectToggle(listUseAllTime);
    listYear.disableProperty().bind(Bindings.not(listUseYear.selectedProperty()));
    listStartDate.disableProperty().bind(Bindings.not(listCustomDateRange.selectedProperty()));
    listEndDate.disableProperty().bind(Bindings.not(listCustomDateRange.selectedProperty()));
    // User
    listUser.setText(DataManager.getDefaultUser());
    listUser.setOnAction(e -> updateListTab());
    // Table
    listTable.setItems(listTableData);
    // Link to Properties
    listTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
    listCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
    listSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
    listEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
    listCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
    // Special Table Cells
    listReviewsColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(p.getValue().getReviews().size()));
    listRatingColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(p.getValue().getAverageRating()));
    // Comparors for string columns
    listTitleColumn.setComparator(new NaturalOrderComparator());
    listCreatorColumn.setComparator(new NaturalOrderComparator());
    listSeasonColumn.setComparator(new NaturalOrderComparator());
    listEpisodeColumn.setComparator(new NaturalOrderComparator());
    listCategoryColumn.setComparator(new NaturalOrderComparator());
}
Also used : Stroolean(retrospector.util.Stroolean) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) NaturalOrderComparator(retrospector.util.NaturalOrderComparator)

Aggregations

Stroolean (retrospector.util.Stroolean)3 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)2 LocalDate (java.time.LocalDate)1 List (java.util.List)1 ObservableList (javafx.collections.ObservableList)1 XYChart (javafx.scene.chart.XYChart)1 Media (retrospector.model.Media)1 Review (retrospector.model.Review)1 MediaComparator (retrospector.util.MediaComparator)1 NaturalOrderComparator (retrospector.util.NaturalOrderComparator)1