use of retrospector.util.NaturalOrderComparator in project Retrospector by NonlinearFruit.
the class SearchTabController method initSearchTab.
private void initSearchTab() {
searchEditMedia.setDisable(true);
searchDeleteMedia.setDisable(true);
// Table Double Click
searchTable.setRowFactory(tv -> {
TableRow<Media> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
setMedia(row.getItem());
setTab(TAB.MEDIA);
}
});
return row;
});
// Table data setup
searchTableData = DataManager.getMedia();
FilteredList<Media> mediaFiltered = new FilteredList(searchTableData, x -> true);
SortedList<Media> mediaSortable = new SortedList<>(mediaFiltered);
searchTable.setItems(mediaSortable);
mediaSortable.comparatorProperty().bind(searchTable.comparatorProperty());
// Link to data properties
searchTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
searchCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
searchSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
searchEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
searchCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
// Values for special columns
searchNumberColumn.setSortable(false);
searchNumberColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + searchTable.getItems().indexOf(p.getValue())));
searchReviewsColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, Integer>, ObservableValue<Integer>>() {
@Override
public ObservableValue<Integer> call(TableColumn.CellDataFeatures<Media, Integer> p) {
return new ReadOnlyObjectWrapper(p.getValue().getReviews().size());
}
});
searchMeanRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getAverageRating());
}
});
searchCurrentRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getCurrentRating());
}
});
// Comparators for string columns
searchTitleColumn.setComparator(new NaturalOrderComparator());
searchCreatorColumn.setComparator(new NaturalOrderComparator());
searchSeasonColumn.setComparator(new NaturalOrderComparator());
searchEpisodeColumn.setComparator(new NaturalOrderComparator());
searchCategoryColumn.setComparator(new NaturalOrderComparator());
searchTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
setMedia(neo);
});
searchBox.textProperty().addListener((observa, old, neo) -> {
String query = neo;
if (query == null || query.equals(""))
mediaFiltered.setPredicate(x -> true);
else {
String[] queries = query.split(":");
mediaFiltered.setPredicate(x -> QueryProcessor.isMatchForMedia(query, x));
}
updateStats();
});
// Buttons
searchNewMedia.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchQuickEntry.setOnAction(e -> {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("QuickEntry.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
QuickEntryController qec = fxmlLoader.getController();
qec.setup(currentTab);
Stage stage = new Stage();
stage.setTitle("Quick Entry");
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception ex) {
}
});
searchStandardEntry.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchBackup.setOnAction(e -> DataManager.makeBackup());
searchCheatsheet.setOnAction(e -> {
new Cheatsheet().start(new Stage());
});
searchEditMedia.setOnAction(e -> {
setTab(TAB.MEDIA);
});
searchDeleteMedia.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());
updateSearchTab();
}
});
// Init stuff
updateStats();
}
use of retrospector.util.NaturalOrderComparator in project Retrospector by NonlinearFruit.
the class MediaSectionController method initialize.
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
chartRatingOverTime.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data(0, 0))));
checkTitle.setSelected(true);
checkCreator.setSelected(true);
checkSeason.setSelected(true);
checkEpisode.setSelected(true);
checkCategory.setSelected(true);
checkTitle.selectedProperty().addListener((observe, old, neo) -> updateMedia());
checkCreator.selectedProperty().addListener((observe, old, neo) -> updateMedia());
checkSeason.selectedProperty().addListener((observe, old, neo) -> updateMedia());
checkEpisode.selectedProperty().addListener((observe, old, neo) -> updateMedia());
checkCategory.selectedProperty().addListener((observe, old, neo) -> updateMedia());
mediaTableFilter = new FilteredList(allMedia);
SortedList<Media> mediaSortable = new SortedList<>(mediaTableFilter);
mediaTable.setItems(mediaSortable);
mediaSortable.comparatorProperty().bind(mediaTable.comparatorProperty());
mediaColumnRowNumber.setSortable(false);
mediaColumnRowNumber.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + mediaTable.getItems().indexOf(p.getValue())));
mediaColumnTitle.setComparator(new NaturalOrderComparator());
mediaColumnCreator.setComparator(new NaturalOrderComparator());
mediaColumnSeason.setComparator(new NaturalOrderComparator());
mediaColumnEpisode.setComparator(new NaturalOrderComparator());
mediaColumnCategory.setComparator(new NaturalOrderComparator());
mediaColumnTitle.setCellValueFactory(new PropertyValueFactory<>("Title"));
mediaColumnCreator.setCellValueFactory(new PropertyValueFactory<>("Creator"));
mediaColumnSeason.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
mediaColumnEpisode.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
mediaColumnCategory.setCellValueFactory(new PropertyValueFactory<>("Category"));
chartRotY.setLabel("Reviews");
chartRotY.setAutoRanging(false);
chartRotY.setLowerBound(0);
chartRotY.setUpperBound(10);
chartRotY.setTickUnit(2);
chartRotY.setMinorTickCount(2);
chartRotX.setLabel("Time");
chartRotX.setAutoRanging(false);
chartRotX.setTickUnit(1);
chartRotX.setMinorTickCount(4);
chartRotX.setTickLabelFormatter(new StringConverter<Number>() {
@Override
public String toString(Number number) {
double x = number.doubleValue();
double decimal = x % 1;
double year = x - decimal;
double days = decimal * 365.25;
if (days > 365 || days < 1) {
return ((int) year) + "";
}
LocalDate date = LocalDate.ofYearDay((int) year, (int) days);
return date.format(DateTimeFormatter.ofPattern("MMM uuuu"));
}
@Override
public Number fromString(String string) {
//To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
use of retrospector.util.NaturalOrderComparator 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);
}
use of retrospector.util.NaturalOrderComparator 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());
}
Aggregations