Skip to content

Commit

Permalink
Filter painting, filter tab (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvk committed Jan 15, 2021
1 parent 6a77111 commit 10cf00c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class MapViewModel implements ViewModel {

private final ObjectProperty<Object> selectionShape = new SimpleObjectProperty<>();
private final Preferences preferences;
private final FilterRepository filterRepository;

private ObservableList<PainterExecutor<?>> painterExecutors;

Expand All @@ -83,6 +84,7 @@ public MapViewModel(
final InternationalDateLineRepository internationalDateLineRepository,
final UpperInformationRegionRepository upperInformationRegionRepository,
final Preferences preferences,
final FilterRepository filterRepository,
@Named("world") final List<Polygon> world,
@Named("lakes") final List<Polygon> lakes
) {
Expand All @@ -93,6 +95,7 @@ public MapViewModel(
this.upperInformationRegionRepository = upperInformationRegionRepository;

this.preferences = preferences;
this.filterRepository = filterRepository;

this.scrollSpeed.bind(preferences.doubleProperty("general.scroll_speed"));

Expand Down Expand Up @@ -225,6 +228,7 @@ private ObservableList<PainterExecutor<?>> executors(final UpperInformationRegio
PainterExecutor.ofCollection("Active Firs", new ActiveFirbPainter(mapVariables), this::flightInformationRegionBoundaries, this::isNotSelected),
PainterExecutor.ofItem("Connections", new DepartureArrivalPathPainter(mapVariables), this.selectedItemProperty()::get),
PainterExecutor.ofCollection("Pilots", new PilotPainter(mapVariables), this::pilots, this::isNotSelected),
PainterExecutor.ofCollection("Filters", new FilterPainter(mapVariables, filterRepository.list()), this::pilots, this::isNotSelected),
PainterExecutor.ofCollection("Airports", new AirportPainter(mapVariables), this::airports, this::isNotSelected),
PainterExecutor.ofCollection("Search Items", new SelectedPainter(mapVariables, Color.DEEPSKYBLUE, true), statusScope::getSearchedData, this::isNotSelected),
PainterExecutor.ofItem("Selected Item", new SelectedPainter(mapVariables), selectedItem::get),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.marvk.fs.vatsim.map.view.painter;

import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.canvas.GraphicsContext;
import net.marvk.fs.vatsim.map.data.Filter;
import net.marvk.fs.vatsim.map.data.Pilot;
import net.marvk.fs.vatsim.map.view.map.MapVariables;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class FilterPainter extends CompositeMapPainter<Pilot> {

private final List<FilteredPilotPainter> filterPainters;
private MapVariables mapVariables;

public FilterPainter(final MapVariables mapVariables, final ObservableList<Filter> filters) {
this.mapVariables = mapVariables;
filterPainters = filters
.stream()
.map(FilteredPilotPainter::new)
.collect(Collectors.toCollection(ArrayList::new));

filters.addListener((ListChangeListener<Filter>) c -> {
while (c.next()) {
filterPainters.removeIf(e -> c.getRemoved().contains(e.filter));
c.getAddedSubList().forEach(e -> filterPainters.add(new FilteredPilotPainter(e)));
}
});
}

@Override
protected Collection<? extends Painter<?>> painters() {
return filterPainters;
}

@Override
protected Collection<? extends Painter<?>> getPainters() {
return filterPainters;
}

@Override
public void paint(final GraphicsContext context, final Pilot pilot) {
for (final FilteredPilotPainter painter : filterPainters) {
painter.paint(context, pilot);
}
}

private class FilteredPilotPainter extends MapPainter<Pilot> {
private final PilotPainter painter;
private final Filter filter;

public FilteredPilotPainter(final Filter filter) {
super(FilterPainter.this.mapVariables);

this.painter = new PilotPainter(mapVariables, filter.getTextColor(), filter.getBackgroundColor());
this.filter = filter;
}

@Override
public void paint(final GraphicsContext c, final Pilot pilot) {
if (filter.test(pilot)) {
painter.paint(c, pilot);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public class PilotPainter extends MapPainter<Pilot> {
@Parameter(value = "Head/Tail length scaled with speed")
private boolean headTailScaledWithSpeed = true;

public PilotPainter(final MapVariables mapVariables, final Color labelColor, final Color backgroundColor) {
super(mapVariables);
this.labelColor = labelColor;
this.backgroundColor = backgroundColor;
this.paintBackground = true;
}

public PilotPainter(final MapVariables mapVariables, final Color labelColor, final boolean paintBackground) {
super(mapVariables);
this.labelColor = labelColor;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/marvk/fs/vatsim/map/view/tabs/TabsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.marvk.fs.vatsim.map.view.datatable.flightinformationregionboundariestable.FlightInformationRegionBoundariesTableView;
import net.marvk.fs.vatsim.map.view.datatable.pilotstable.PilotsTableView;
import net.marvk.fs.vatsim.map.view.datatable.upperinformationregionstable.UpperInformationRegionsTableView;
import net.marvk.fs.vatsim.map.view.filter.filteroutline.FilterOutlineView;
import net.marvk.fs.vatsim.map.view.map.MapView;
import net.marvk.fs.vatsim.map.view.search.SearchView;

Expand Down Expand Up @@ -59,6 +60,7 @@ public void initialize() {
tabPane.getTabs().add(createJavaViewTab("Airports", AirportsTableView.class));
tabPane.getTabs().add(createJavaViewTab("FIRs", FlightInformationRegionBoundariesTableView.class));
tabPane.getTabs().add(createJavaViewTab("UIRs", UpperInformationRegionsTableView.class));
tabPane.getTabs().add(createFxmlViewTab("Filters", FilterOutlineView.class));

searchController.resultsVisibleProperty().bind(Bindings.createBooleanBinding(
() -> tabPane.getSelectionModel().getSelectedIndex() == 0,
Expand Down

0 comments on commit 10cf00c

Please sign in to comment.