From 9baa38c2b21ff3dba76b53b4281f958514972096 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Mon, 5 Dec 2016 16:46:34 +0300 Subject: [PATCH] add population to systems editor --- .../trader/controllers/SystemsEditorController.java | 13 +++++++++++++ .../src/main/java/ru/trader/model/ModelFabric.java | 10 ++++++++++ .../src/main/java/ru/trader/model/SystemModel.java | 11 +++++++++++ client/src/main/resources/view/db/systems.fxml | 3 +++ client/src/main/resources/view/sEditor.fxml | 3 +++ 5 files changed, 40 insertions(+) diff --git a/client/src/main/java/ru/trader/controllers/SystemsEditorController.java b/client/src/main/java/ru/trader/controllers/SystemsEditorController.java index 494c115..b157d88 100644 --- a/client/src/main/java/ru/trader/controllers/SystemsEditorController.java +++ b/client/src/main/java/ru/trader/controllers/SystemsEditorController.java @@ -8,6 +8,7 @@ import javafx.scene.control.*; import javafx.scene.control.cell.ComboBoxTableCell; import javafx.util.converter.DefaultStringConverter; import javafx.util.converter.DoubleStringConverter; +import javafx.util.converter.LongStringConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ru.trader.Main; @@ -43,6 +44,8 @@ public class SystemsEditorController { @FXML private TableColumn clnPowerState; @FXML + private TableColumn clnPopulation; + @FXML private TableColumn clnX; @FXML private TableColumn clnY; @@ -90,6 +93,7 @@ public class SystemsEditorController { clnGovernment.setCellFactory(ComboBoxTableCell.forTableColumn(new GovernmentStringConverter(), FXCollections.observableArrayList(GOVERNMENT.values()))); clnPower.setCellFactory(ComboBoxTableCell.forTableColumn(new PowerStringConverter(), FXCollections.observableArrayList(POWER.values()))); clnPowerState.setCellFactory(ComboBoxTableCell.forTableColumn(new PowerStateStringConverter(), FXCollections.observableArrayList(POWER_STATE.values()))); + clnPopulation.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter())); clnX.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter())); clnY.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter())); clnZ.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter())); @@ -284,6 +288,7 @@ public class SystemsEditorController { private final DoubleProperty x; private final DoubleProperty y; private final DoubleProperty z; + private final LongProperty population; private final ObjectProperty faction; private final ObjectProperty government; private final ObjectProperty power; @@ -303,6 +308,7 @@ public class SystemsEditorController { x = new SimpleDoubleProperty(Double.NaN); y = new SimpleDoubleProperty(Double.NaN); z = new SimpleDoubleProperty(Double.NaN); + population = new SimpleLongProperty(0); faction = new SimpleObjectProperty<>(FACTION.NONE); government = new SimpleObjectProperty<>(GOVERNMENT.NONE); power = new SimpleObjectProperty<>(POWER.NONE); @@ -315,6 +321,7 @@ public class SystemsEditorController { x = new SimpleDoubleProperty(system.getX()); y = new SimpleDoubleProperty(system.getY()); z = new SimpleDoubleProperty(system.getZ()); + population = new SimpleLongProperty(system.getPopulation()); faction = new SimpleObjectProperty<>(system.getFaction()); government = new SimpleObjectProperty<>(system.getGovernment()); power = new SimpleObjectProperty<>(system.getPower()); @@ -337,6 +344,10 @@ public class SystemsEditorController { return z; } + public LongProperty populationProperty() { + return population; + } + public DoubleProperty s1Property() { return s1; } @@ -386,12 +397,14 @@ public class SystemsEditorController { if (system != null){ system.setName(name.get()); system.setPosition(x.get(), y.get(), z.get()); + system.setPopulation(population.get()); system.setFaction(faction.get()); system.setGovernment(government.get()); system.setPower(power.get()); system.setPowerState(powerState.get()); } else { SystemModel system = market.add(name.get(), x.get(), y.get(), z.get()); + system.setPopulation(population.get()); system.setFaction(faction.get()); system.setGovernment(government.get()); system.setPower(power.get()); diff --git a/client/src/main/java/ru/trader/model/ModelFabric.java b/client/src/main/java/ru/trader/model/ModelFabric.java index 7871fbc..18175c8 100644 --- a/client/src/main/java/ru/trader/model/ModelFabric.java +++ b/client/src/main/java/ru/trader/model/ModelFabric.java @@ -220,6 +220,16 @@ public class ModelFabric { throw new UnsupportedOperationException("Is fake system, change unsupported"); } + @Override + public long getPopulation() { + return 0; + } + + @Override + public void setPopulation(long population) { + throw new UnsupportedOperationException("Is fake system, change unsupported"); + } + @Override public FACTION getFaction() { return FACTION.NONE; diff --git a/client/src/main/java/ru/trader/model/SystemModel.java b/client/src/main/java/ru/trader/model/SystemModel.java index 5c29b90..3f72095 100644 --- a/client/src/main/java/ru/trader/model/SystemModel.java +++ b/client/src/main/java/ru/trader/model/SystemModel.java @@ -113,6 +113,17 @@ public class SystemModel { system.setPosition(x, y, z); } + public long getPopulation(){ + return system.getPopulation(); + } + + public void setPopulation(long population){ + if (population == system.getPopulation()) return; + LOG.info("Change population of system {} to {}", this.system, population); + system.setPopulation(population); + } + + public double getDistance(SystemModel other){ return system.getDistance(ModelFabric.get(other)); } diff --git a/client/src/main/resources/view/db/systems.fxml b/client/src/main/resources/view/db/systems.fxml index 3c46e71..ce5e241 100644 --- a/client/src/main/resources/view/db/systems.fxml +++ b/client/src/main/resources/view/db/systems.fxml @@ -21,6 +21,9 @@ + + + diff --git a/client/src/main/resources/view/sEditor.fxml b/client/src/main/resources/view/sEditor.fxml index 032297d..7ffe795 100644 --- a/client/src/main/resources/view/sEditor.fxml +++ b/client/src/main/resources/view/sEditor.fxml @@ -76,6 +76,9 @@ + + +