Archived
0

change combobox to autocomplete textfield

This commit is contained in:
iMoHax
2015-10-01 16:08:16 +03:00
parent 6ffe545f3b
commit ac08034a64
4 changed files with 55 additions and 31 deletions

View File

@@ -6,16 +6,15 @@ import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.*;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableView;
import ru.trader.Main; import ru.trader.Main;
import ru.trader.analysis.CrawlerSpecificator; import ru.trader.analysis.CrawlerSpecificator;
import ru.trader.model.*; import ru.trader.model.*;
import ru.trader.model.support.ChangeMarketListener; import ru.trader.model.support.ChangeMarketListener;
import ru.trader.view.support.NumberField; import ru.trader.view.support.NumberField;
import ru.trader.view.support.RouteNode; import ru.trader.view.support.RouteNode;
import ru.trader.view.support.autocomplete.AutoCompletion;
import ru.trader.view.support.autocomplete.SystemsProvider;
import java.util.Optional; import java.util.Optional;
@@ -46,13 +45,15 @@ public class RouterController {
private Button removeBtn; private Button removeBtn;
@FXML @FXML
private ComboBox<SystemModel> source; private TextField sourceText;
private AutoCompletion<SystemModel> source;
@FXML @FXML
private ComboBox<StationModel> sStation; private ComboBox<StationModel> sStation;
@FXML @FXML
private ComboBox<SystemModel> target; private TextField targetText;
private AutoCompletion<SystemModel> target;
@FXML @FXML
private ComboBox<StationModel> tStation; private ComboBox<StationModel> tStation;
@@ -80,14 +81,14 @@ public class RouterController {
cargo.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setCargo(n.intValue())); cargo.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setCargo(n.intValue()));
tank.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setTank(n.doubleValue())); tank.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setTank(n.doubleValue()));
jumps.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setJumps(n.intValue())); jumps.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setJumps(n.intValue()));
source.valueProperty().addListener((ov, o, n) -> { source.completionProperty().addListener((ov, o, n) -> {
if (n != null) { if (n != null) {
sStation.setItems(n.getStationsList()); sStation.setItems(n.getStationsList());
} else { } else {
sStation.setItems(FXCollections.emptyObservableList()); sStation.setItems(FXCollections.emptyObservableList());
} }
}); });
target.valueProperty().addListener((ov, o, n) -> { target.completionProperty().addListener((ov, o, n) -> {
if (n != null) { if (n != null) {
tStation.setItems(n.getStationsList()); tStation.setItems(n.getStationsList());
} else { } else {
@@ -108,9 +109,9 @@ public class RouterController {
jumps.setValue(Main.SETTINGS.getJumps()); jumps.setValue(Main.SETTINGS.getJumps());
addBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> { addBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> {
StationModel st = tStation.getValue(); SystemModel system = target.getCompletion();
return st == null || st == ModelFabric.NONE_STATION; return ModelFabric.isFake(system);
}, tStation.valueProperty())); }, target.completionProperty()));
editBtn.disableProperty().bind(tblOrders.getSelectionModel().selectedIndexProperty().isEqualTo(-1)); editBtn.disableProperty().bind(tblOrders.getSelectionModel().selectedIndexProperty().isEqualTo(-1));
removeBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> { removeBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> {
@@ -135,10 +136,12 @@ public class RouterController {
void init(){ void init(){
market = MainController.getMarket(); market = MainController.getMarket();
market.getNotificator().add(new RouterChangeListener()); market.getNotificator().add(new RouterChangeListener());
source.setItems(market.systemsProperty()); SystemsProvider provider = new SystemsProvider(market);
source.getSelectionModel().selectFirst(); if (source != null) source.dispose();
target.setItems(market.systemsListProperty()); source = new AutoCompletion<>(sourceText, provider, ModelFabric.NONE_SYSTEM, provider.getConverter());
target.getSelectionModel().selectFirst(); if (target != null) target.dispose();
provider = new SystemsProvider(market);
target = new AutoCompletion<>(targetText, provider, ModelFabric.NONE_SYSTEM, provider.getConverter());
orders.clear(); orders.clear();
totalBalance.setValue(balance.getValue()); totalBalance.setValue(balance.getValue());
totalProfit.setValue(0); totalProfit.setValue(0);
@@ -162,14 +165,15 @@ public class RouterController {
target.setValue(ModelFabric.NONE_SYSTEM); target.setValue(ModelFabric.NONE_SYSTEM);
if (orders.isEmpty()) { if (orders.isEmpty()) {
balance.setDisable(false); balance.setDisable(false);
source.setDisable(false);
} }
} }
public void addStationToRoute(){ public void addStationToRoute(){
SystemModel s = source.getCompletion();
SystemModel t = target.getCompletion();
StationModel sS = sStation.getValue(); StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue(); StationModel tS = tStation.getValue();
RouteModel r = market.getPath(sS, tS); RouteModel r = market.getPath(s, sS, t, tS);
if (r == null) return; if (r == null) return;
if (route != null){ if (route != null){
route.add(r); route.add(r);
@@ -177,7 +181,7 @@ public class RouterController {
route = r; route = r;
} }
refreshPath(); refreshPath();
source.setValue(tS.getSystem()); source.setValue(target.getCompletion());
sStation.setValue(tS); sStation.setValue(tS);
} }
@@ -252,8 +256,8 @@ public class RouterController {
} }
public void showOrders(){ public void showOrders(){
SystemModel s = source.getValue(); SystemModel s = source.getCompletion();
SystemModel t = target.getValue(); SystemModel t = target.getCompletion();
StationModel sS = sStation.getValue(); StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue(); StationModel tS = tStation.getValue();
market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> { market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> {
@@ -266,8 +270,8 @@ public class RouterController {
} }
public void showRoutes(){ public void showRoutes(){
SystemModel s = source.getValue(); SystemModel s = source.getCompletion();
SystemModel t = target.getValue(); SystemModel t = target.getCompletion();
StationModel sS = sStation.getValue(); StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue(); StationModel tS = tStation.getValue();
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), new CrawlerSpecificator(), routes -> { market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), new CrawlerSpecificator(), routes -> {
@@ -275,7 +279,6 @@ public class RouterController {
if (path.isPresent()){ if (path.isPresent()){
orders.addAll(path.get().getOrders()); orders.addAll(path.get().getOrders());
addRouteToPath(path.get()); addRouteToPath(path.get());
MainController.getProfile().setRoute(path.get());
Screeners.showHelper(); Screeners.showHelper();
} }
}); });
@@ -310,6 +313,7 @@ public class RouterController {
} }
private void refreshPath(){ private void refreshPath(){
MainController.getProfile().setRoute(route);
if (route != null) if (route != null)
path.setContent(new RouteNode(route).getNode()); path.setContent(new RouteNode(route).getNode());
else else
@@ -320,20 +324,20 @@ public class RouterController {
@Override @Override
public void add(StationModel station) { public void add(StationModel station) {
if (station.getSystem().equals(source.getValue())){ if (station.getSystem().equals(source.getCompletion())){
sStation.getItems().add(station); sStation.getItems().add(station);
} }
if (station.getSystem().equals(target.getValue())){ if (station.getSystem().equals(target.getCompletion())){
tStation.getItems().add(station); tStation.getItems().add(station);
} }
} }
@Override @Override
public void remove(StationModel station) { public void remove(StationModel station) {
if (station.getSystem().equals(source.getValue())){ if (station.getSystem().equals(source.getCompletion())){
sStation.getItems().remove(station); sStation.getItems().remove(station);
} }
if (station.getSystem().equals(target.getValue())){ if (station.getSystem().equals(target.getCompletion())){
tStation.getItems().remove(station); tStation.getItems().remove(station);
} }
} }

View File

@@ -244,11 +244,23 @@ public class MarketModel {
return analyzer.getPath(order.getOrder()); return analyzer.getPath(order.getOrder());
} }
public RouteModel getPath(StationModel from, StationModel to) { private RouteModel getPath(Vendor from, Vendor to) {
Route p = analyzer.getPath(from.getStation(), to.getStation()); Route p = analyzer.getPath(from, to);
return modeler.get(p); return modeler.get(p);
} }
public RouteModel getPath(StationModel from, StationModel to) {
return getPath(from.getStation(), to.getStation());
}
public RouteModel getPath(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo){
if (ModelFabric.isFake(stationFrom)){
return getPath(from.getSystem().asTransit(), ModelFabric.isFake(stationTo) ? to.getSystem().asTransit() : stationTo.getStation());
} else {
return getPath(stationFrom.getStation(), ModelFabric.isFake(stationTo) ? to.getSystem().asTransit() : stationTo.getStation());
}
}
public RouteModel getPath(OrderModel order) { public RouteModel getPath(OrderModel order) {
Route p = analyzer.getPath(order.getOrder()); Route p = analyzer.getPath(order.getOrder());
return modeler.get(p); return modeler.get(p);

View File

@@ -121,6 +121,14 @@ public class ModelFabric {
public static StationModel NONE_STATION = new FAKE_STATION_MODEL(); public static StationModel NONE_STATION = new FAKE_STATION_MODEL();
public static ItemModel NONE_ITEM = new FAKE_ITEM_MODEL(); public static ItemModel NONE_ITEM = new FAKE_ITEM_MODEL();
public static boolean isFake(StationModel station) {
return station == null || station instanceof FAKE_STATION_MODEL;
}
public static boolean isFake(SystemModel system) {
return system == null || system instanceof FAKE_SYSTEM_MODEL;
}
private static class FAKE_SYSTEM_MODEL extends SystemModel { private static class FAKE_SYSTEM_MODEL extends SystemModel {
FAKE_SYSTEM_MODEL() { FAKE_SYSTEM_MODEL() {
super(); super();

View File

@@ -39,10 +39,10 @@
<ColumnConstraints minWidth="170" maxWidth="170"/> <ColumnConstraints minWidth="170" maxWidth="170"/>
</columnConstraints> </columnConstraints>
<Label text="%router.pane.route.from" /> <Label text="%router.pane.route.from" />
<ComboBox fx:id="source" prefWidth="170" GridPane.columnIndex="1" /> <TextField fx:id="sourceText" prefWidth="170" GridPane.columnIndex="1" />
<ComboBox fx:id="sStation" prefWidth="170" GridPane.rowIndex="1" GridPane.columnIndex="1" /> <ComboBox fx:id="sStation" prefWidth="170" GridPane.rowIndex="1" GridPane.columnIndex="1" />
<Label text="%router.pane.route.to" GridPane.rowIndex="2"/> <Label text="%router.pane.route.to" GridPane.rowIndex="2"/>
<ComboBox fx:id="target" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="2"/> <TextField fx:id="targetText" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<ComboBox fx:id="tStation" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="3"/> <ComboBox fx:id="tStation" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="%router.pane.route.jumps" GridPane.rowIndex="4" /> <Label text="%router.pane.route.jumps" GridPane.rowIndex="4" />
<NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="4" /> <NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="4" />