Archived
0

add support position of station

This commit is contained in:
iMoHax
2014-08-06 16:10:33 +04:00
parent 9c5bbdc0c2
commit fe9abae295
18 changed files with 193 additions and 19 deletions

View File

@@ -50,6 +50,9 @@ public class OrdersController {
@FXML
private TableColumn<OfferModel, Double> curProfit;
@FXML
private TableColumn<OfferModel, Double> curDistance;
private OrderModel order;
@FXML
@@ -60,7 +63,11 @@ public class OrdersController {
tblBuyers.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> setBuyer(n));
curProfit.setCellValueFactory(param -> {
OfferModel offer = param.getValue();
return order !=null ? order.getProfit(offer) : new SimpleDoubleProperty(Double.NaN).asObject();
return order !=null ? order.getProfit(offer) : new SimpleDoubleProperty(Double.NaN).asObject();
});
curDistance.setCellValueFactory(param -> {
OfferModel offer = param.getValue();
return new SimpleDoubleProperty(order !=null ? order.getVendor().getDistance(offer.getVendor()) :Double.NaN).asObject();
});
}

View File

@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
import ru.trader.core.OFFER_TYPE;
import ru.trader.model.*;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.NumberField;
import ru.trader.view.support.PriceStringConverter;
import ru.trader.view.support.ViewUtils;
import ru.trader.view.support.cells.TextFieldCell;
@@ -54,6 +55,14 @@ public class VendorEditorController {
@FXML
private TableColumn<FakeOffer, Double> sell;
@FXML
private NumberField x;
@FXML
private NumberField y;
@FXML
private NumberField z;
@FXML
private void initialize() {
items.getSelectionModel().setCellSelectionEnabled(true);
@@ -78,6 +87,9 @@ public class VendorEditorController {
private void fill(){
name.setText(vendor.getName());
x.setValue(vendor.getX());
y.setValue(vendor.getY());
z.setValue(vendor.getZ());
vendor.getSells().forEach(this::fillOffer);
vendor.getBuys().forEach(this::fillOffer);
}
@@ -151,11 +163,13 @@ public class VendorEditorController {
if (vendor == null) {
market.setAlert(false);
vendor = market.newVendor(name.getText());
vendor.setPosition(x.getValue().doubleValue(), y.getValue().doubleValue(), z.getValue().doubleValue());
items.getItems().forEach((o) -> commit(market, vendor, o));
market.setAlert(true);
market.add(vendor);
} else {
vendor.setName(name.getText());
vendor.setPosition(x.getValue().doubleValue(), y.getValue().doubleValue(), z.getValue().doubleValue());
items.getItems().forEach((o) -> commit(market, vendor, o));
}
}

View File

@@ -67,6 +67,15 @@ public class MarketModel {
return listener;
}
void updatePosition(VendorModel model, double x, double y, double z) {
Vendor vendor = model.getVendor();
double oldX = vendor.getX();
double oldY = vendor.getY();
double oldZ = vendor.getZ();
market.updatePosition(vendor, x, y, z);
if (alert) listener.forEach((c) -> c.positionChange(model, oldX, oldY, oldZ, x, y, z));
}
void updateName(ItemModel model, String value) {
Item item = model.getItem();
String old = item.getName();

View File

@@ -14,6 +14,7 @@ public class OrderModel {
private final ObjectProperty<OfferModel> buyer = new SimpleObjectProperty<>();
private long max;
private DoubleProperty profit;
private DoubleProperty distance;
private DoubleProperty bestProfit;
public OrderModel(OfferDescModel offer) {
@@ -87,12 +88,13 @@ public class OrderModel {
return profitProperty().get();
}
public ObjectProperty<OfferModel> buyerProperty() {
public ReadOnlyObjectProperty<OfferModel> buyerProperty() {
return buyer;
}
public void setBuyer(OfferModel buyer) {
this.buyer.set(buyer);
if (distance!=null) distance.set(getVendor().getDistance(buyer.getVendor()));
}
public OfferModel getBuyer() {
@@ -115,4 +117,13 @@ public class OrderModel {
return offer.getBuyer();
}
public ReadOnlyDoubleProperty distanceProperty() {
if (distance == null){
OfferModel buyOffer = getBuyer();
distance = new SimpleDoubleProperty(buyOffer!=null ? getVendor().getDistance(buyOffer.getVendor()) : Double.NaN);
}
return distance;
}
}

View File

@@ -36,6 +36,40 @@ public class VendorModel {
return name;
}
public void setPosition(double x, double y, double z){
if (x == vendor.getX() && y == vendor.getY() && z == vendor.getZ()) return;
LOG.info("Change position of vendor {} to ({};{};{})", vendor, x, y, z);
market.updatePosition(this, x, y, z);
}
public double getX(){
return vendor.getX();
}
public double getY(){
return vendor.getY();
}
public double getZ(){
return vendor.getZ();
}
public ReadOnlyDoubleProperty xProperty(){
return new SimpleDoubleProperty(vendor.getX());
}
public ReadOnlyDoubleProperty yProperty(){
return new SimpleDoubleProperty(vendor.getY());
}
public ReadOnlyDoubleProperty zProperty(){
return new SimpleDoubleProperty(vendor.getZ());
}
public double getDistance(VendorModel other){
return vendor.getDistance(other.vendor);
}
public List<OfferModel> getSells() {
return vendor.getAllSellOffers().stream().map(market::asModel).collect(Collectors.toList());
}

View File

@@ -31,4 +31,7 @@ public class ChangeMarketListener {
public void remove(OfferModel offer) {
}
public void positionChange(VendorModel vendor, double oldX, double oldY, double oldZ, double x, double y, double z) {
}
}

View File

@@ -12,7 +12,7 @@ public class NumberField extends TextField {
private final static NumberStringConverter converter = new NumberStringConverter("#0.#");
private final Tooltip tooltip = new Tooltip();
private final ObjectProperty<Number> number = new SimpleObjectProperty<>(0);
private final ObjectProperty<Number> number = new SimpleObjectProperty<Number>(0);
private final BooleanProperty wrong = new SimpleBooleanProperty(false);
public ObjectProperty<Number> numberProperty() {

View File

@@ -1,11 +1,21 @@
package ru.trader.view.support.cells;
import javafx.beans.NamedArg;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import ru.trader.view.support.NaNComparator;
public class DoubleCell<T> implements Callback<TableColumn<T, Double>, TableCell<T, Double>> {
private String format = "%.0f";
public DoubleCell() {
}
public DoubleCell(@NamedArg("format")String format) {
this.format = format;
}
@Override
public TableCell<T, Double> call(TableColumn<T, Double> param) {
param.setComparator(new NaNComparator<>());
@@ -17,7 +27,7 @@ public class DoubleCell<T> implements Callback<TableColumn<T, Double>, TableCell
setText(null);
setGraphic(null);
} else {
setText(String.format("%.0f", item));
setText(String.format(format, item));
setGraphic(null);
}
}

View File

@@ -11,7 +11,7 @@
<?import ru.trader.view.support.cells.OfferTableCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.OrdersController" styleClass="dialog"
prefWidth="850">
prefWidth="1010">
<TableView fx:id="tblOrders" editable="true">
<columns>
<TableColumn minWidth="160.0" text="Товар">
@@ -24,7 +24,7 @@
<TableColumn fx:id="count" minWidth="60.0" text="Кол-во">
<cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120.0" text="Покупатель">
<TableColumn minWidth="160.0" text="Покупатель">
<cellValueFactory><OfferCellValueImpl property="buyer"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="Прибыль">
@@ -51,15 +51,17 @@
<fx:reference source="bestProfit"/>
</sortOrder>
</TableView>
<TableView fx:id="tblBuyers" minWidth="215">
<TableView fx:id="tblBuyers" minWidth="335">
<columns>
<TableColumn minWidth="120.0" text="Покупатель">
<TableColumn minWidth="160.0" text="Покупатель">
<cellFactory><OfferTableCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
</TableColumn>
<TableColumn fx:id="curDistance" minWidth="80.0" text="Дистанция">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory>
</TableColumn>
<TableColumn fx:id="curProfit" minWidth="80.0" text="Прибыль" sortType="DESCENDING">
<cellFactory><DoubleCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
</TableColumn>
</columns>
<columnResizePolicy>

View File

@@ -56,10 +56,10 @@
</VBox>
<TableView fx:id="tblOrders" HBox.hgrow="ALWAYS">
<columns>
<TableColumn minWidth="230.0" text="Продавец">
<TableColumn minWidth="200.0" text="Продавец">
<cellValueFactory><PropertyValueFactory property="vendor"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="230.0" text="Товар">
<TableColumn minWidth="180.0" text="Товар">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="Цена">
@@ -72,6 +72,10 @@
<TableColumn minWidth="120.0" text="Покупатель">
<cellValueFactory><OfferCellValueImpl property="buyer"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="Дистанция">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="Прибыль">
<cellFactory><DoubleCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>

View File

@@ -11,21 +11,25 @@
<?import ru.trader.view.support.cells.OfferTableCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.TopOrdersController" styleClass="dialog"
prefWidth="555">
prefWidth="715">
<TableView fx:id="tblOrders" editable="true">
<columns>
<TableColumn minWidth="160.0" text="Товар">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120.0" text="Продавец">
<TableColumn minWidth="160.0" text="Продавец">
<cellValueFactory><OfferCellValueImpl property="offer"/></cellValueFactory>
</TableColumn>
<TableColumn fx:id="count" minWidth="60.0" text="Кол-во">
<cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120.0" text="Покупатель">
<TableColumn minWidth="160.0" text="Покупатель">
<cellValueFactory><OfferCellValueImpl property="buyer"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="Дистанция">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn>
<TableColumn fx:id="profit" minWidth="80.0" text="Прибыль" sortType="DESCENDING">
<cellFactory><DoubleCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>

View File

@@ -7,16 +7,27 @@
<?import org.controlsfx.glyphfont.Glyph?>
<?import ru.trader.view.support.NumberField?>
<?import javafx.geometry.Insets?>
<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"
fx:controller="ru.trader.controllers.VendorEditorController" styleClass="dialog"
vgap="10" hgap="4">
<TextField fx:id="name" alignment="CENTER" GridPane.columnSpan="2"/>
<VBox GridPane.rowIndex="1" alignment="CENTER" spacing="10">
<fx:define><Insets fx:id="hbox_margin" left="10" /></fx:define>
<TextField fx:id="name" GridPane.columnSpan="2" alignment="CENTER" />
<HBox GridPane.rowIndex="1" GridPane.columnIndex="1" spacing="4" alignment="BASELINE_CENTER">
<Label text="x:" HBox.margin="$hbox_margin" />
<NumberField fx:id="x" prefWidth="60" />
<Label text="y:" HBox.margin="$hbox_margin" />
<NumberField fx:id="y" prefWidth="60" />
<Label text="z:" HBox.margin="$hbox_margin" />
<NumberField fx:id="z" prefWidth="60" />
</HBox>
<VBox GridPane.rowIndex="2" alignment="CENTER" spacing="10">
<Button prefWidth="30" onAction="#up"><graphic><Glyph text="FontAwesome|ARROW_UP"/></graphic></Button>
<Button prefWidth="30" onAction="#down"><graphic><Glyph text="FontAwesome|ARROW_DOWN"/></graphic></Button>
<Button prefWidth="30" onAction="#add"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
</VBox>
<TableView fx:id="items" minWidth="375.0" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="1">
<TableView fx:id="items" prefWidth="375.0" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
<columns>
<TableColumn minWidth="200.0" text="Товар" editable="false">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>