From 8cd40a233dd49b585febaa614dfa7f48672f31ee Mon Sep 17 00:00:00 2001 From: Mo Date: Fri, 9 Dec 2016 20:52:52 +0300 Subject: [PATCH] add multiple select checked systems --- .../controllers/PowerPlayController.java | 33 ++++++++++++++----- .../trader/analysis/PowerPlayAnalyzator.java | 14 +++++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/PowerPlayController.java b/client/src/main/java/ru/trader/controllers/PowerPlayController.java index 4e1da9a..96e1624 100644 --- a/client/src/main/java/ru/trader/controllers/PowerPlayController.java +++ b/client/src/main/java/ru/trader/controllers/PowerPlayController.java @@ -9,7 +9,6 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.input.*; -import javafx.util.converter.NumberStringConverter; import org.controlsfx.control.CheckComboBox; import org.controlsfx.control.MasterDetailPane; import org.slf4j.Logger; @@ -89,6 +88,8 @@ public class PowerPlayController { init(); profile = MainController.getProfile(); + historySystems.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + cbCurrentPower.setConverter(new PowerStringConverter()); cbCurrentPower.setItems(FXCollections.observableArrayList(POWER.values())); cbPower.setConverter(new PowerStringConverter()); @@ -180,18 +181,17 @@ public class PowerPlayController { } }); tblDetail.setOnDragDetected(new StarSystemDragDetect(tblDetail)); - NumberStringConverter converter = new NumberStringConverter("#,##0.##"); result.addListener((InvalidationListener) i -> { - resultCCSumm.setText(getCCSummText(result, getCheckedSystem())); + resultCCSumm.setText(getCCSummText(result, getSelectedSystems())); } ); detail.addListener((InvalidationListener) i -> { - detailCCSumm.setText(getCCSummText(detail, detailSystem)); + detailCCSumm.setText(getCCSummText(detail, detailSystem != null ? Collections.singleton(detailSystem) : null)); } ); } - private String getCCSummText(Collection collection, Place starSystem){ + private String getCCSummText(Collection collection, Collection starSystems){ String ccFormat = Localization.getString("powerplay.label.summcc"); String pwCCFormat = Localization.getString("powerplay.label.cc"); PowerStringConverter converter = new PowerStringConverter(); @@ -229,8 +229,10 @@ public class PowerPlayController { } } double upkeep = 0; - if (hq != null && starSystem != null){ - upkeep = starSystem.computeUpkeep(hq); + if (hq != null && starSystems != null){ + for (Place starSystem : starSystems) { + upkeep += starSystem.computeUpkeep(hq); + } } StringBuilder builder = new StringBuilder(); @@ -259,6 +261,17 @@ public class PowerPlayController { return ModelFabric.get(checkedSystem.getValue()); } + private Collection getSelectedSystems() { + Collection places = historySystems.getSelectionModel().getSelectedItems().stream().map(ModelFabric::get).collect(Collectors.toSet()); + if (places.isEmpty()){ + Place starSystem = getCheckedSystem(); + if (starSystem != null){ + return Collections.singleton(starSystem); + } + } + return places; + } + private void getIntersects(){ Place starSystem = getCheckedSystem(); Collection controlls = getControlSystems(); @@ -271,9 +284,11 @@ public class PowerPlayController { private void getControlling(){ final Place starSystem = getCheckedSystem(); + final Collection selectedSystems = getSelectedSystems(); result.clear(); - if (starSystem != null){ - Collection controllings = analyzator.getControlling(starSystem); + if (starSystem != null || !selectedSystems.isEmpty()){ + Collection controllings = + selectedSystems.isEmpty() ? analyzator.getControlling(starSystem) : analyzator.getControlling(selectedSystems); controllings.add(new PowerPlayAnalyzator.IntersectData(starSystem)); result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem))); } diff --git a/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java b/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java index b152b45..0e64f8e 100644 --- a/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java +++ b/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java @@ -31,8 +31,12 @@ public class PowerPlayAnalyzator { } public Collection getControlling(Place starSystem){ + return getControlling(Collections.singleton(starSystem)); + } + + public Collection getControlling(Collection starSystems){ Stream candidates = market.get().stream().filter(Place::isPopulated); - return getControlling(starSystem, candidates, Market.CONTROLLING_RADIUS).collect(Collectors.toList()); + return getControlling(starSystems, candidates, Market.CONTROLLING_RADIUS).collect(Collectors.toList()); } public Collection getIntersects(Collection starSystems){ @@ -63,12 +67,12 @@ public class PowerPlayAnalyzator { return getNearExpansions(market.get(), starSystems, Market.CONTROLLING_RADIUS * 2); } - public static Collection getControlling(Place starSystem, Collection starSystems, double radius){ - return getControlling(starSystem, starSystems.stream(), radius).collect(Collectors.toList()); + public static Collection getControlling(Collection checkedSystems, Collection starSystems, double radius){ + return getControlling(checkedSystems, starSystems.stream(), radius).collect(Collectors.toList()); } - public static Stream getControlling(Place starSystem, Stream starSystems, double radius){ - IntersectsMapper controllingMapper = new IntersectsMapper(Collections.singleton(starSystem), radius, true, true); + public static Stream getControlling(Collection checkedSystems, Stream starSystems, double radius){ + IntersectsMapper controllingMapper = new IntersectsMapper(checkedSystems, radius, true, true); return starSystems .map(controllingMapper) .filter(IntersectData::isIntersect);