Archived
0

add station select on route select

This commit is contained in:
iMoHax
2014-11-29 14:14:24 +03:00
parent 86053d7b0c
commit 57ecdcb47b
7 changed files with 300 additions and 66 deletions

View File

@@ -5,7 +5,6 @@ import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
@@ -13,11 +12,9 @@ import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableView;
import ru.trader.Main;
import ru.trader.model.*;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.NumberField;
import ru.trader.view.support.RouteNode;
import java.util.List;
public class RouterController {
@@ -44,9 +41,16 @@ public class RouterController {
@FXML
private ComboBox<SystemModel> source;
@FXML
private ComboBox<StationModel> sStation;
@FXML
private ComboBox<SystemModel> target;
@FXML
private ComboBox<StationModel> tStation;
@FXML
private TableView<OrderModel> tblOrders;
@@ -83,6 +87,25 @@ public class RouterController {
market.getAnalyzer().setJumps(n.intValue());
Main.SETTINGS.setJumps(n.intValue());
});
source.valueProperty().addListener((ov, o, n) -> {
if (n != ModelFabric.NONE_SYSTEM){
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
stations.addAll(n.getStations());
sStation.setItems(stations);
} else {
sStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
}
});
target.valueProperty().addListener((ov, o, n) -> {
if (n != ModelFabric.NONE_SYSTEM){
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
stations.addAll(n.getStations());
tStation.setItems(stations);
} else {
tStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
}
});
balance.setOnAction((v)->cargo.requestFocus());
cargo.setOnAction((v) -> tank.requestFocus());
@@ -132,14 +155,16 @@ public class RouterController {
private void onAdd(OrderModel order){
totalProfit.add(order.getProfit());
totalBalance.add(order.getProfit());
source.getSelectionModel().select(order.getBuyOffer().getSystem());
source.setValue(order.getBuyer().getSystem());
sStation.setValue(order.getBuyer());
balance.setDisable(true);
}
private void onRemove(OrderModel order) {
totalProfit.sub(order.getProfit());
totalBalance.sub(order.getProfit());
source.getSelectionModel().select(order.getStation().getSystem());
source.setValue(order.getSystem());
sStation.setValue(order.getStation());
if (orders.isEmpty()) {
balance.setDisable(false);
source.setDisable(false);
@@ -189,30 +214,24 @@ public class RouterController {
}
public void showOrders(){
//TODO: fix set balanace
SystemModel s = source.getSelectionModel().getSelectedItem();
SystemModel t = target.getSelectionModel().getSelectedItem();
OrderModel order;
if (t == ModelFabric.NONE_SYSTEM){
order = Screeners.showOrders(market.getOrders(s, totalBalance.getValue().doubleValue()));
} else {
order = Screeners.showOrders(market.getOrders(s, t, totalBalance.getValue().doubleValue()));
}
SystemModel s = source.getValue();
SystemModel t = target.getValue();
StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue();
OrderModel order = Screeners.showOrders(market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue()));
if (order!=null){
//TODO: fix set balanace
orders.add(order);
addOrderToPath(order);
}
}
public void showRoutes(){
SystemModel s = source.getSelectionModel().getSelectedItem();
SystemModel t = target.getSelectionModel().getSelectedItem();
PathRouteModel path;
if (t == ModelFabric.NONE_SYSTEM){
path = Screeners.showRouters(market.getRoutes(s, totalBalance.getValue().doubleValue()));
} else {
path = Screeners.showRouters(market.getRoutes(s, t, totalBalance.getValue().doubleValue()));
}
SystemModel s = source.getValue();
SystemModel t = target.getValue();
StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue();
PathRouteModel path = Screeners.showRouters(market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue()));
if (path!=null){
orders.addAll(path.getOrders());
addRouteToPath(path);

View File

@@ -12,6 +12,8 @@ import ru.trader.graph.PathRoute;
import ru.trader.model.support.BindingsHelper;
import ru.trader.model.support.Notificator;
import java.util.Collection;
public class MarketModel {
private final static Logger LOG = LoggerFactory.getLogger(MarketModel.class);
@@ -74,15 +76,41 @@ public class MarketModel {
}
public ObservableList<OrderModel> getOrders(SystemModel from, double balance) {
return BindingsHelper.observableList(analyzer.getOrders(from.getSystem(), balance), modeler::get);
return getOrders(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance);
}
public ObservableList<OrderModel> getOrders(SystemModel from, SystemModel to, double balance) {
return BindingsHelper.observableList(analyzer.getOrders(from.getSystem(), to.getSystem(), balance), modeler::get);
return getOrders(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance);
}
public ObservableList<OrderModel> getOrders(StationModel from, StationModel to, double balance) {
return BindingsHelper.observableList(analyzer.getOrders(from.getStation(), to.getStation(), balance), modeler::get);
return getOrders(from.getSystem(), from, to.getSystem(), to, balance);
}
public ObservableList<OrderModel> getOrders(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance) {
Collection<Order> orders;
if (stationFrom != null && stationFrom != ModelFabric.NONE_STATION){
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
orders = analyzer.getOrders(stationFrom.getStation(), stationTo.getStation(), balance);
} else {
if (to != null && to != ModelFabric.NONE_SYSTEM){
orders = analyzer.getOrders(stationFrom.getStation(), to.getSystem(), balance);
} else {
orders = analyzer.getOrders(stationFrom.getStation(), balance);
}
}
} else {
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
orders = analyzer.getOrders(from.getSystem(), stationTo.getStation(), balance);
} else {
if (to != null && to != ModelFabric.NONE_SYSTEM){
orders = analyzer.getOrders(from.getSystem(), to.getSystem(), balance);
} else {
orders = analyzer.getOrders(from.getSystem(), balance);
}
}
}
return BindingsHelper.observableList(orders, modeler::get);
}
public ObservableList<OrderModel> getTop(double balance){
@@ -90,13 +118,41 @@ public class MarketModel {
}
public ObservableList<PathRouteModel> getRoutes(SystemModel from, double balance){
return BindingsHelper.observableList(analyzer.getPaths(from.getSystem(), balance), modeler::get);
return getRoutes(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance);
}
public ObservableList<PathRouteModel> getRoutes(SystemModel from, SystemModel to, double balance){
return BindingsHelper.observableList(analyzer.getPaths(from.getSystem(), to.getSystem(), balance), modeler::get);
return getRoutes(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance);
}
public ObservableList<PathRouteModel> getRoutes(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance) {
Collection<PathRoute> routes;
if (stationFrom != null && stationFrom != ModelFabric.NONE_STATION){
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
routes = analyzer.getPaths(stationFrom.getStation(), stationTo.getStation(), balance);
} else {
if (to != null && to != ModelFabric.NONE_SYSTEM){
routes = analyzer.getPaths(stationFrom.getStation(), to.getSystem(), balance);
} else {
routes = analyzer.getPaths(stationFrom.getStation(), balance);
}
}
} else {
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
routes = analyzer.getPaths(from.getSystem(), stationTo.getStation(), balance);
} else {
if (to != null && to != ModelFabric.NONE_SYSTEM){
routes = analyzer.getPaths(from.getSystem(), to.getSystem(), balance);
} else {
routes = analyzer.getPaths(from.getSystem(), balance);
}
}
}
return BindingsHelper.observableList(routes, modeler::get);
}
public ObservableList<PathRouteModel> getTopRoutes(double balance){
return BindingsHelper.observableList(analyzer.getTopPaths(balance), modeler::get);
}

View File

@@ -5,6 +5,7 @@ import ru.trader.core.*;
import ru.trader.graph.PathRoute;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -102,6 +103,7 @@ public class ModelFabric {
}
public static SystemModel NONE_SYSTEM = new FAKE_SYSTEM_MODEL();
public static StationModel NONE_STATION = new FAKE_STATION_MODEL();
private static class FAKE_SYSTEM_MODEL extends SystemModel {
FAKE_SYSTEM_MODEL() {
@@ -174,4 +176,100 @@ public class ModelFabric {
}
}
private static class FAKE_STATION_MODEL extends StationModel {
FAKE_STATION_MODEL() {
super();
}
@Override
Vendor getStation() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public String getName() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public void setName(String value) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public double getDistance() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public void setDistance(double value) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public boolean hasService(SERVICE_TYPE service) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public Collection<SERVICE_TYPE> getServices() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public void addService(SERVICE_TYPE service) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public void removeService(SERVICE_TYPE service) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public SystemModel getSystem() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public List<OfferModel> getSells() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public List<OfferModel> getBuys() {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public OfferModel add(OFFER_TYPE type, ItemModel item, double price, long count) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public void remove(OfferModel offer) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public boolean hasSell(ItemModel item) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public boolean hasBuy(ItemModel item) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public double getDistance(StationModel other) {
throw new UnsupportedOperationException("Is fake system, unsupported");
}
@Override
public String toString() {
return "";
}
}
}

View File

@@ -20,6 +20,11 @@ public class StationModel {
return market.getModeler().get(offer, item);
}
StationModel() {
this.station = null;
this.market = null;
}
StationModel(Vendor station, MarketModel market) {
this.station = station;
this.market = market;

View File

@@ -22,7 +22,7 @@
<ColumnConstraints fillWidth="true"/>
</columnConstraints>
<TitledPane GridPane.rowSpan="3" text="%market.systems" minWidth="250" prefHeight="530" collapsible="false">
<TitledPane GridPane.rowSpan="3" text="%market.systems" minWidth="250" prefHeight="570" collapsible="false">
<ListView fx:id="systems">
<contextMenu>
<ContextMenu>

View File

@@ -40,13 +40,15 @@
</columnConstraints>
<Label text="%router.pane.route.from" />
<ComboBox fx:id="source" prefWidth="160" GridPane.columnIndex="1" />
<Label text="%router.pane.route.to" GridPane.rowIndex="1"/>
<ComboBox fx:id="target" prefWidth="160" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label text="%router.pane.route.jumps" GridPane.rowIndex="2" />
<NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<ComboBox fx:id="sStation" prefWidth="160" GridPane.rowIndex="1" GridPane.columnIndex="1" />
<Label text="%router.pane.route.to" GridPane.rowIndex="2"/>
<ComboBox fx:id="target" prefWidth="160" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<ComboBox fx:id="tStation" prefWidth="160" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="%router.pane.route.jumps" GridPane.rowIndex="4" />
<NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Separator GridPane.columnSpan="2" GridPane.rowIndex="3" GridPane.margin="$separator_margin"/>
<VBox GridPane.columnSpan="2" GridPane.rowIndex="4" spacing="5">
<Separator GridPane.columnSpan="2" GridPane.rowIndex="5" GridPane.margin="$separator_margin"/>
<VBox GridPane.columnSpan="2" GridPane.rowIndex="6" spacing="5">
<HBox alignment="CENTER" spacing="5">
<Button fx:id="editBtn" text="%dialog.button.edit" onAction="#editOrders"/>
<Button fx:id="removeBtn" text="%dialog.button.remove" onAction="#removeSelected"/>