-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/net/marvk/fs/vatsim/map/view/painter/FilterPainter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters