diff --git a/client/src/main/java/ru/trader/model/StationModel.java b/client/src/main/java/ru/trader/model/StationModel.java index 8ab4281..731e6e7 100644 --- a/client/src/main/java/ru/trader/model/StationModel.java +++ b/client/src/main/java/ru/trader/model/StationModel.java @@ -2,10 +2,7 @@ package ru.trader.model; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ru.trader.core.OFFER_TYPE; -import ru.trader.core.Offer; -import ru.trader.core.SERVICE_TYPE; -import ru.trader.core.Vendor; +import ru.trader.core.*; import java.util.*; import java.util.stream.Collectors; @@ -106,7 +103,10 @@ public class StationModel { } public double getDistance(StationModel other){ - return station.getPlace().getDistance(other.station.getPlace()); + Place place = station.getPlace(); + Place otherPlace = other.station.getPlace(); + if (!place.equals(otherPlace)) return station.getPlace().getDistance(other.station.getPlace()); + return (station.getDistance() + other.station.getDistance() + Math.abs(station.getDistance() - other.station.getDistance())) * 0.00000003169 / 2; } @Override diff --git a/client/src/main/java/ru/trader/view/support/RouteNode.java b/client/src/main/java/ru/trader/view/support/RouteNode.java index b2845f2..e4b9634 100644 --- a/client/src/main/java/ru/trader/view/support/RouteNode.java +++ b/client/src/main/java/ru/trader/view/support/RouteNode.java @@ -9,6 +9,7 @@ import org.controlsfx.glyphfont.Glyph; import ru.trader.core.Order; import ru.trader.graph.PathRoute; import ru.trader.model.PathRouteModel; +import ru.trader.view.support.cells.DistanceCell; public class RouteNode { private final static String CSS_PATH = "path"; @@ -52,7 +53,7 @@ public class RouteNode { node.getChildren().addAll(v, icons); - Text t = new Text(String.format("(%.2f LY)", p.getDistance())); + Text t = new Text(DistanceCell.distanceToString(p.getDistance())); t.getStyleClass().add(CSS_TRACK_TEXT); diff --git a/client/src/main/java/ru/trader/view/support/cells/DistanceCell.java b/client/src/main/java/ru/trader/view/support/cells/DistanceCell.java new file mode 100644 index 0000000..2420ba7 --- /dev/null +++ b/client/src/main/java/ru/trader/view/support/cells/DistanceCell.java @@ -0,0 +1,34 @@ +package ru.trader.view.support.cells; + +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.util.Callback; +import ru.trader.view.support.NaNComparator; + +public class DistanceCell implements Callback, TableCell> { + public DistanceCell() { + } + + @Override + public TableCell call(TableColumn param) { + param.setComparator(new NaNComparator<>()); + return new TableCell(){ + @Override + protected void updateItem(Double item, boolean empty) { + super.updateItem(item, empty); + if (empty) { + setText(null); + setGraphic(null); + } else { + setText(distanceToString(item)); + setGraphic(null); + } + } + }; + } + + public static String distanceToString(double distance){ + if (distance < 0.01) return String.format("%.0f Ls", distance / 0.00000003169); + return String.format("%.2f LY", distance); + } +} diff --git a/client/src/main/resources/view/orders.fxml b/client/src/main/resources/view/orders.fxml index 579c33d..78e4962 100644 --- a/client/src/main/resources/view/orders.fxml +++ b/client/src/main/resources/view/orders.fxml @@ -9,6 +9,7 @@ + @@ -58,7 +59,7 @@ - + diff --git a/client/src/main/resources/view/paths.fxml b/client/src/main/resources/view/paths.fxml index 958808a..f6ec245 100644 --- a/client/src/main/resources/view/paths.fxml +++ b/client/src/main/resources/view/paths.fxml @@ -10,6 +10,7 @@ + @@ -28,7 +29,7 @@ - + diff --git a/client/src/main/resources/view/router.fxml b/client/src/main/resources/view/router.fxml index 0dba8d4..9fd157d 100644 --- a/client/src/main/resources/view/router.fxml +++ b/client/src/main/resources/view/router.fxml @@ -9,6 +9,7 @@ + @@ -99,7 +100,7 @@ - + diff --git a/client/src/main/resources/view/topOrders.fxml b/client/src/main/resources/view/topOrders.fxml index fa32782..3b0e95f 100644 --- a/client/src/main/resources/view/topOrders.fxml +++ b/client/src/main/resources/view/topOrders.fxml @@ -9,6 +9,7 @@ + @@ -27,7 +28,7 @@ - +