Archived
0

show distance in Ls if less 0.01

This commit is contained in:
iMoHax
2014-11-27 13:14:33 +03:00
parent eb713c340f
commit 86c4abaa96
7 changed files with 49 additions and 10 deletions

View File

@@ -2,10 +2,7 @@ package ru.trader.model;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ru.trader.core.OFFER_TYPE; import ru.trader.core.*;
import ru.trader.core.Offer;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.core.Vendor;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -106,7 +103,10 @@ public class StationModel {
} }
public double getDistance(StationModel other){ 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 @Override

View File

@@ -9,6 +9,7 @@ import org.controlsfx.glyphfont.Glyph;
import ru.trader.core.Order; import ru.trader.core.Order;
import ru.trader.graph.PathRoute; import ru.trader.graph.PathRoute;
import ru.trader.model.PathRouteModel; import ru.trader.model.PathRouteModel;
import ru.trader.view.support.cells.DistanceCell;
public class RouteNode { public class RouteNode {
private final static String CSS_PATH = "path"; private final static String CSS_PATH = "path";
@@ -52,7 +53,7 @@ public class RouteNode {
node.getChildren().addAll(v, icons); 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); t.getStyleClass().add(CSS_TRACK_TEXT);

View File

@@ -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<T> implements Callback<TableColumn<T, Double>, TableCell<T, Double>> {
public DistanceCell() {
}
@Override
public TableCell<T, Double> call(TableColumn<T, Double> param) {
param.setComparator(new NaNComparator<>());
return new TableCell<T, Double>(){
@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);
}
}

View File

@@ -9,6 +9,7 @@
<?import ru.trader.view.support.cells.OfferCellValueImpl?> <?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import ru.trader.view.support.cells.OfferTableCell?> <?import ru.trader.view.support.cells.OfferTableCell?>
<?import ru.trader.view.support.cells.DistanceCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.OrdersController" styleClass="dialog" fx:controller="ru.trader.controllers.OrdersController" styleClass="dialog"
prefWidth="1010"> prefWidth="1010">
@@ -58,7 +59,7 @@
<cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn fx:id="curDistance" minWidth="80.0" text="%market.order.distance"> <TableColumn fx:id="curDistance" minWidth="80.0" text="%market.order.distance">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory> <cellFactory><DistanceCell/></cellFactory>
</TableColumn> </TableColumn>
<TableColumn fx:id="curProfit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING"> <TableColumn fx:id="curProfit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING">
<cellFactory><DoubleCell/></cellFactory> <cellFactory><DoubleCell/></cellFactory>

View File

@@ -10,6 +10,7 @@
<?import ru.trader.view.support.cells.OfferCellValueImpl?> <?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import ru.trader.view.support.cells.OfferTableCell?> <?import ru.trader.view.support.cells.OfferTableCell?>
<?import ru.trader.view.support.cells.PathRouteCell?> <?import ru.trader.view.support.cells.PathRouteCell?>
<?import ru.trader.view.support.cells.DistanceCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.PathsController" styleClass="dialog" fx:controller="ru.trader.controllers.PathsController" styleClass="dialog"
prefWidth="1050"> prefWidth="1050">
@@ -28,7 +29,7 @@
<cellValueFactory><PropertyValueFactory property="lands"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="lands"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn minWidth="80.0" text="%market.order.distance"> <TableColumn minWidth="80.0" text="%market.order.distance">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory> <cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn minWidth="70.0" text="%market.order.profit"> <TableColumn minWidth="70.0" text="%market.order.profit">

View File

@@ -9,6 +9,7 @@
<?import ru.trader.view.support.cells.OfferCellValueImpl?> <?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import ru.trader.view.support.cells.DistanceCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.RouterController"> fx:controller="ru.trader.controllers.RouterController">
<fx:define><Insets fx:id="fields_group_margin" left="2" right="10"/></fx:define> <fx:define><Insets fx:id="fields_group_margin" left="2" right="10"/></fx:define>
@@ -99,7 +100,7 @@
<cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory> <cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn minWidth="80.0" text="%market.order.distance"> <TableColumn minWidth="80.0" text="%market.order.distance">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory> <cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn minWidth="80.0" text="%market.order.profit"> <TableColumn minWidth="80.0" text="%market.order.profit">

View File

@@ -9,6 +9,7 @@
<?import ru.trader.view.support.cells.OfferCellValueImpl?> <?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import ru.trader.view.support.cells.OfferTableCell?> <?import ru.trader.view.support.cells.OfferTableCell?>
<?import ru.trader.view.support.cells.DistanceCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.TopOrdersController" styleClass="dialog" fx:controller="ru.trader.controllers.TopOrdersController" styleClass="dialog"
prefWidth="725"> prefWidth="725">
@@ -27,7 +28,7 @@
<cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory> <cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn minWidth="80.0" text="%market.order.distance"> <TableColumn minWidth="80.0" text="%market.order.distance">
<cellFactory><DoubleCell format="\%.2f LY"/></cellFactory> <cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn fx:id="profit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING"> <TableColumn fx:id="profit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING">