Archived
0

add multiple select checked systems

This commit is contained in:
Mo
2016-12-09 20:52:52 +03:00
parent ee83ebf73a
commit 8cd40a233d
2 changed files with 33 additions and 14 deletions

View File

@@ -9,7 +9,6 @@ import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.*; import javafx.scene.input.*;
import javafx.util.converter.NumberStringConverter;
import org.controlsfx.control.CheckComboBox; import org.controlsfx.control.CheckComboBox;
import org.controlsfx.control.MasterDetailPane; import org.controlsfx.control.MasterDetailPane;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -89,6 +88,8 @@ public class PowerPlayController {
init(); init();
profile = MainController.getProfile(); profile = MainController.getProfile();
historySystems.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
cbCurrentPower.setConverter(new PowerStringConverter()); cbCurrentPower.setConverter(new PowerStringConverter());
cbCurrentPower.setItems(FXCollections.observableArrayList(POWER.values())); cbCurrentPower.setItems(FXCollections.observableArrayList(POWER.values()));
cbPower.setConverter(new PowerStringConverter()); cbPower.setConverter(new PowerStringConverter());
@@ -180,18 +181,17 @@ public class PowerPlayController {
} }
}); });
tblDetail.setOnDragDetected(new StarSystemDragDetect(tblDetail)); tblDetail.setOnDragDetected(new StarSystemDragDetect(tblDetail));
NumberStringConverter converter = new NumberStringConverter("#,##0.##");
result.addListener((InvalidationListener) i -> { result.addListener((InvalidationListener) i -> {
resultCCSumm.setText(getCCSummText(result, getCheckedSystem())); resultCCSumm.setText(getCCSummText(result, getSelectedSystems()));
} }
); );
detail.addListener((InvalidationListener) i -> { detail.addListener((InvalidationListener) i -> {
detailCCSumm.setText(getCCSummText(detail, detailSystem)); detailCCSumm.setText(getCCSummText(detail, detailSystem != null ? Collections.singleton(detailSystem) : null));
} }
); );
} }
private String getCCSummText(Collection<ResultEntry> collection, Place starSystem){ private String getCCSummText(Collection<ResultEntry> collection, Collection<Place> starSystems){
String ccFormat = Localization.getString("powerplay.label.summcc"); String ccFormat = Localization.getString("powerplay.label.summcc");
String pwCCFormat = Localization.getString("powerplay.label.cc"); String pwCCFormat = Localization.getString("powerplay.label.cc");
PowerStringConverter converter = new PowerStringConverter(); PowerStringConverter converter = new PowerStringConverter();
@@ -229,8 +229,10 @@ public class PowerPlayController {
} }
} }
double upkeep = 0; double upkeep = 0;
if (hq != null && starSystem != null){ if (hq != null && starSystems != null){
upkeep = starSystem.computeUpkeep(hq); for (Place starSystem : starSystems) {
upkeep += starSystem.computeUpkeep(hq);
}
} }
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@@ -259,6 +261,17 @@ public class PowerPlayController {
return ModelFabric.get(checkedSystem.getValue()); return ModelFabric.get(checkedSystem.getValue());
} }
private Collection<Place> getSelectedSystems() {
Collection<Place> 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(){ private void getIntersects(){
Place starSystem = getCheckedSystem(); Place starSystem = getCheckedSystem();
Collection<Place> controlls = getControlSystems(); Collection<Place> controlls = getControlSystems();
@@ -271,9 +284,11 @@ public class PowerPlayController {
private void getControlling(){ private void getControlling(){
final Place starSystem = getCheckedSystem(); final Place starSystem = getCheckedSystem();
final Collection<Place> selectedSystems = getSelectedSystems();
result.clear(); result.clear();
if (starSystem != null){ if (starSystem != null || !selectedSystems.isEmpty()){
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem); Collection<PowerPlayAnalyzator.IntersectData> controllings =
selectedSystems.isEmpty() ? analyzator.getControlling(starSystem) : analyzator.getControlling(selectedSystems);
controllings.add(new PowerPlayAnalyzator.IntersectData(starSystem)); controllings.add(new PowerPlayAnalyzator.IntersectData(starSystem));
result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem))); result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem)));
} }

View File

@@ -31,8 +31,12 @@ public class PowerPlayAnalyzator {
} }
public Collection<IntersectData> getControlling(Place starSystem){ public Collection<IntersectData> getControlling(Place starSystem){
return getControlling(Collections.singleton(starSystem));
}
public Collection<IntersectData> getControlling(Collection<Place> starSystems){
Stream<Place> candidates = market.get().stream().filter(Place::isPopulated); Stream<Place> 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<IntersectData> getIntersects(Collection<Place> starSystems){ public Collection<IntersectData> getIntersects(Collection<Place> starSystems){
@@ -63,12 +67,12 @@ public class PowerPlayAnalyzator {
return getNearExpansions(market.get(), starSystems, Market.CONTROLLING_RADIUS * 2); return getNearExpansions(market.get(), starSystems, Market.CONTROLLING_RADIUS * 2);
} }
public static Collection<IntersectData> getControlling(Place starSystem, Collection<Place> starSystems, double radius){ public static Collection<IntersectData> getControlling(Collection<Place> checkedSystems, Collection<Place> starSystems, double radius){
return getControlling(starSystem, starSystems.stream(), radius).collect(Collectors.toList()); return getControlling(checkedSystems, starSystems.stream(), radius).collect(Collectors.toList());
} }
public static Stream<IntersectData> getControlling(Place starSystem, Stream<Place> starSystems, double radius){ public static Stream<IntersectData> getControlling(Collection<Place> checkedSystems, Stream<Place> starSystems, double radius){
IntersectsMapper controllingMapper = new IntersectsMapper(Collections.singleton(starSystem), radius, true, true); IntersectsMapper controllingMapper = new IntersectsMapper(checkedSystems, radius, true, true);
return starSystems return starSystems
.map(controllingMapper) .map(controllingMapper)
.filter(IntersectData::isIntersect); .filter(IntersectData::isIntersect);