Archived
0

add columns to powerplay screen

This commit is contained in:
Mo
2016-11-09 16:39:44 +03:00
parent f728fbd699
commit fd95692271
4 changed files with 120 additions and 15 deletions

View File

@@ -312,13 +312,15 @@ public class PowerPlayController {
public class ResultEntry {
private final SystemModel starSystem;
private final StationModel nearStation;
private final ReadOnlyStringProperty nearStations;
private final ReadOnlyDoubleProperty distance;
private final ReadOnlyDoubleProperty distanceHQ;
private final ReadOnlyStringProperty maxSizePad;
private final ReadOnlyIntegerProperty intersectCount;
private final ReadOnlyStringProperty intersecting;
private final ReadOnlyStringProperty controlling;
private final ReadOnlyLongProperty population;
private final ReadOnlyLongProperty upkeep;
private final ReadOnlyLongProperty income;
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
this(data, null);
@@ -326,14 +328,17 @@ public class PowerPlayController {
public ResultEntry(PowerPlayAnalyzator.IntersectData data, Place from) {
starSystem = world.getModeler().get(data.getStarSystem());
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
intersectCount = new SimpleIntegerProperty(data.getCount());
nearStation = starSystem.getNear();
nearStations = new SimpleStringProperty(getStationsString(starSystem.getNearByType()));
intersecting = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
controlling = new SimpleStringProperty(getControllingString(data.getStarSystem()));
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
Place hq = ModelFabric.get(hqSystem.orElse(null));
distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN);
population = new SimpleLongProperty(data.getStarSystem().getPopulation());
upkeep = new SimpleLongProperty(data.getStarSystem().getUpkeep());
income = new SimpleLongProperty(data.getStarSystem().getIncome());
}
private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
@@ -356,10 +361,29 @@ public class PowerPlayController {
return res.toString();
}
public ReadOnlyStringProperty stationProperty(){
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
private String getStationsString(Collection<StationModel> stations) {
StringBuilder res = new StringBuilder();
for (StationModel station : stations) {
if (res.length() != 0) res.append("\n");
if (station.getType() != null){
if (station.getType().isPlanetary()) {
res.append("LP");
} else
if (station.getType().hasLargeLandpad()){
res.append("L");
} else {
res.append("M");
}
} else {
res.append("?");
}
res.append(" - ").append(station.getName());
res.append(" (").append(ViewUtils.stationDistanceToString(station.getDistance())).append(")");
}
return res.toString();
}
public ReadOnlyStringProperty nameProperty(){
return starSystem.nameProperty();
}
@@ -388,10 +412,6 @@ public class PowerPlayController {
return distanceHQ;
}
public ReadOnlyStringProperty maxSizePadProperty() {
return maxSizePad;
}
public ReadOnlyIntegerProperty intersectCountProperty() {
return intersectCount;
}
@@ -403,5 +423,21 @@ public class PowerPlayController {
public ReadOnlyStringProperty intersectingProperty() {
return intersecting;
}
public ReadOnlyLongProperty populationProperty() {
return population;
}
public ReadOnlyLongProperty upkeepProperty() {
return upkeep;
}
public ReadOnlyLongProperty incomeProperty() {
return income;
}
public ReadOnlyStringProperty nearStationsProperty() {
return nearStations;
}
}
}

View File

@@ -1,12 +1,15 @@
package ru.trader.model;
import javafx.beans.property.*;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -187,6 +190,33 @@ public class SystemModel {
return asModel(near.orElse(null));
}
public Collection<StationModel> getNearByType(){
Collection<Vendor> stations = system.get().stream().sorted((v1, v2) -> Double.compare(v1.getDistance(), v2.getDistance())).collect(Collectors.toList());
Collection<StationModel> result = new ArrayList<>(4);
boolean findLarge = false, findMedium = false, findPlanetary = false;
for (Vendor station : stations) {
if (station.getType() != null){
if (station.getType().isPlanetary()){
if (!findPlanetary) {
result.add(asModel(station));
findPlanetary = true;
}
} else
if (station.getType().hasLargeLandpad()){
if (!findLarge) {
result.add(asModel(station));
findLarge = true;
}
} else
if (!findMedium){
result.add(asModel(station));
findMedium = true;
}
}
}
return result;
}
@Override
public String toString() {
if (LOG.isTraceEnabled()){

View File

@@ -0,0 +1,14 @@
package ru.trader.view.support;
import javafx.beans.NamedArg;
import javafx.util.converter.NumberStringConverter;
public class CustomNumberStringConverter extends NumberStringConverter {
public CustomNumberStringConverter(@NamedArg("pattern")String pattern) {
super(pattern);
}
}

View File

@@ -89,11 +89,11 @@
<TitledPane text="Результаты анализа" collapsible="false">
<TableView fx:id="tblResults">
<columns>
<TableColumn prefWidth="200" text="%market.system">
<TableColumn prefWidth="150" text="%market.system">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="180" text="Пересекается с">
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
<TableColumn prefWidth="150" text="Пересекается с">
<cellValueFactory><PropertyValueFactory property="intersecting"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="90" text="Пересечений">
<cellValueFactory><PropertyValueFactory property="intersectCount"/></cellValueFactory>
@@ -118,8 +118,20 @@
<cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Income">
<cellValueFactory><PropertyValueFactory property="income"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Upkeep">
<cellValueFactory><PropertyValueFactory property="upkeep"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Население">
<cellValueFactory><PropertyValueFactory property="population"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="100" text="Тип площадки">
<cellValueFactory><PropertyValueFactory property="maxSizePad"/></cellValueFactory>
<cellValueFactory><PropertyValueFactory property="nearStations"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="150" text="Контролируется">
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Дистанция до HQ">
<cellFactory><DistanceCell /></cellFactory>
@@ -162,6 +174,19 @@
<cellFactory><TextCell><converter><FactionStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Income">
<cellValueFactory><PropertyValueFactory property="income"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Upkeep">
<cellValueFactory><PropertyValueFactory property="upkeep"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Население">
<cellFactory><TextCell><converter><CustomNumberStringConverter pattern="#,##0.##" /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="population"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="150" text="Контролируется">
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
</TableColumn>
</columns>
<columnResizePolicy>
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>