Archived
0

show time and distance in helper

This commit is contained in:
Mo
2015-10-24 16:15:42 +03:00
parent 74962519cc
commit 97ec8ce1cf
8 changed files with 75 additions and 24 deletions

View File

@@ -45,6 +45,10 @@ public class HelperController {
@FXML
private Label time;
@FXML
private Label distance;
@FXML
private Label stationDistance;
@FXML
private Label refuel;
@FXML
private ListView<OrderModel> buyOrders;
@@ -197,9 +201,18 @@ public class HelperController {
station.setText(entry.getStation().getName());
system.setText(entry.getStation().getSystem().getName());
if (index > 0){
time.setText(ViewUtils.timeToString(route.get(index-1).getTime()));
RouteEntryModel prev = route.get(index - 1);
time.setText(ViewUtils.timeToString(prev.getTime()));
distance.setText(ViewUtils.distanceToString(prev.getStation().getSystem().getDistance(entry.getStation().getSystem())));
if (entry.isTransit()) {
stationDistance.setText("");
} else {
stationDistance.setText(ViewUtils.stationDistanceToString(entry.getStation().getDistance()));
}
} else {
time.setText(ViewUtils.timeToString(0));
time.setText("");
distance.setText("");
stationDistance.setText("");
}
refuel.setText(String.valueOf(entry.getRefill()));
buyOrders.setItems(entry.orders());
@@ -213,6 +226,8 @@ public class HelperController {
station.setText("");
system.setText("No route");
time.setText("");
distance.setText("");
stationDistance.setText("");
refuel.setText("");
buyOrders.setItems(FXCollections.emptyObservableList());
sellOrders.setItems(FXCollections.emptyObservableList());
@@ -253,7 +268,7 @@ public class HelperController {
}
private void bindKeys(){
KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK), k -> ViewUtils.doFX(this::complete));
KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), k -> ViewUtils.doFX(this::complete));
}
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));

View File

@@ -72,7 +72,7 @@ public class RouteModel {
}
public int getJumps() {
return entries.size();
return entries.size()-1;
}
public int getRefuels() {

View File

@@ -10,7 +10,6 @@ import ru.trader.analysis.Route;
import ru.trader.analysis.RouteEntry;
import ru.trader.core.Vendor;
import ru.trader.model.RouteModel;
import ru.trader.view.support.cells.DistanceCell;
public class RouteNode {
private final static String CSS_PATH = "path";
@@ -39,7 +38,7 @@ public class RouteNode {
VBox.setVgrow(track, Priority.ALWAYS);
track.getStyleClass().add(CSS_TRACK);
Text t = new Text(DistanceCell.distanceToString(entry.getVendor().getDistance(prev)));
Text t = new Text(ViewUtils.distanceToString(entry.getVendor().getDistance(prev)));
t.getStyleClass().add(CSS_TRACK_TEXT);
track.getChildren().addAll(t, Glyph.create("FontAwesome|LONG_ARROW_RIGHT"));

View File

@@ -45,4 +45,13 @@ public class ViewUtils {
public static String timeToString(long time){
return String.format("%d:%02d:%02d", time/3600, (time%3600)/60, (time%60));
}
public static String distanceToString(double distance){
if (distance < 0.01) return String.format("%.0f Ls", distance / 0.00000003169);
return String.format("%.2f LY", distance);
}
public static String stationDistanceToString(double distance){
return String.format("%.2f Ls", distance);
}
}

View File

@@ -4,6 +4,7 @@ import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
import ru.trader.view.support.NaNComparator;
import ru.trader.view.support.ViewUtils;
public class DistanceCell<T> implements Callback<TableColumn<T, Double>, TableCell<T, Double>> {
public DistanceCell() {
@@ -20,15 +21,11 @@ public class DistanceCell<T> implements Callback<TableColumn<T, Double>, TableCe
setText(null);
setGraphic(null);
} else {
setText(distanceToString(item));
setText(ViewUtils.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

@@ -0,0 +1,26 @@
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.ViewUtils;
public class TimeCell<T> implements Callback<TableColumn<T, Long>, TableCell<T, Long>> {
@Override
public TableCell<T, Long> call(TableColumn<T, Long> param) {
return new TableCell<T, Long>(){
@Override
protected void updateItem(Long item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setText(ViewUtils.timeToString(item));
setGraphic(null);
}
}
};
}
}

View File

@@ -6,18 +6,22 @@
<?import org.controlsfx.glyphfont.Glyph?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.HelperController"
spacing="4" minWidth="200" fx:id="helper">
spacing="4" minWidth="220" maxWidth="220" fx:id="helper">
<HBox>
<VBox>
<VBox HBox.hgrow="ALWAYS">
<HBox>
<Button onAction="#copy" minWidth="30">
<graphic><Glyph text="FontAwesome|COPY" /></graphic>
</Button>
<Label fx:id="system" text="Breksta" prefWidth="130" maxWidth="130" styleClass="text-big" />
<Label fx:id="time" text="0:44:15" styleClass="text-small"/>
<Label fx:id="system" text="Breksta" styleClass="text-big" />
</HBox>
<Label fx:id="station" text="Pieres Market" styleClass="text-medium" />
</VBox>
<VBox minWidth="60" alignment="TOP_RIGHT">
<Label fx:id="time" text="00:44:15" styleClass="text-small"/>
<Label fx:id="distance" text="10 LY" styleClass="text-small"/>
<Label fx:id="stationDistance" text="123456 ls" styleClass="text-small"/>
</VBox>
</HBox>
<HBox fx:id="refuelGroup"><Label text="Заправить:" /><Label fx:id="refuel" /></HBox>
<HBox>

View File

@@ -1,16 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import ru.trader.view.support.cells.DoubleCell?>
<?import ru.trader.view.support.cells.OfferCellValueImpl?>
<?import ru.trader.view.support.cells.OfferTableCell?>
<?import ru.trader.view.support.cells.PathRouteCell?>
<?import javafx.scene.layout.HBox?>
<?import ru.trader.view.support.cells.DistanceCell?>
<?import ru.trader.view.support.cells.DoubleCell?>
<?import ru.trader.view.support.cells.PathRouteCell?>
<?import ru.trader.view.support.cells.TimeCell?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.PathsController" styleClass="dialog"
prefWidth="1050">
@@ -35,7 +32,11 @@
<TableColumn minWidth="70.0" text="%market.order.profit">
<cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
</TableColumn>
<TableColumn fx:id="profitByTime" minWidth="70.0" text="%market.offer.avg" sortType="DESCENDING">
<TableColumn minWidth="70.0" text="%market.route.time" sortType="DESCENDING">
<cellFactory><TimeCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="time"/></cellValueFactory>
</TableColumn>
<TableColumn fx:id="profitByTime" minWidth="70.0" text="%market.route.profitByTime" sortType="DESCENDING">
<cellFactory><DoubleCell format="\%.0f"/></cellFactory>
<cellValueFactory><PropertyValueFactory property="profitByTime"/></cellValueFactory>
</TableColumn>