modify helper window
This commit is contained in:
@@ -1,28 +1,42 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
import javafx.beans.property.BooleanProperty;
|
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.geometry.Bounds;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.ToggleButton;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.StageStyle;
|
||||||
import ru.trader.KeyBinding;
|
import ru.trader.KeyBinding;
|
||||||
import ru.trader.Main;
|
import ru.trader.Main;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.view.support.ViewUtils;
|
import ru.trader.view.support.ViewUtils;
|
||||||
import ru.trader.view.support.cells.OfferListCell;
|
import ru.trader.view.support.cells.OfferListCell;
|
||||||
import ru.trader.view.support.cells.OrderListCell;
|
import ru.trader.view.support.cells.OrderListCell;
|
||||||
|
import ru.trader.view.support.cells.StationListCell;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.KeyStroke;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
|
||||||
public class HelperController {
|
public class HelperController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Node refuelGroup;
|
||||||
|
@FXML
|
||||||
|
private Node ordersGroup;
|
||||||
|
@FXML
|
||||||
|
private Node missionsGroup;
|
||||||
|
@FXML
|
||||||
|
private Node infoGroup;
|
||||||
@FXML
|
@FXML
|
||||||
private Label station;
|
private Label station;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -41,29 +55,85 @@ public class HelperController {
|
|||||||
private ListView<StationModel> stations;
|
private ListView<StationModel> stations;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<OfferModel> sellOffers;
|
private ListView<OfferModel> sellOffers;
|
||||||
|
@FXML
|
||||||
|
private ToggleButton infoBtn;
|
||||||
|
|
||||||
|
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
private RouteModel route;
|
private RouteModel route;
|
||||||
private final BooleanProperty docked;
|
private RouteEntryModel entry;
|
||||||
|
|
||||||
public HelperController() {
|
|
||||||
docked = new SimpleBooleanProperty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize(){
|
private void initialize(){
|
||||||
MainController.getProfile().routeProperty().addListener(routeListener);
|
ProfileModel profile = MainController.getProfile();
|
||||||
|
profile.routeProperty().addListener(routeListener);
|
||||||
|
profile.dockedProperty().addListener(dockedListener);
|
||||||
buyOrders.setCellFactory(new OrderListCell(false));
|
buyOrders.setCellFactory(new OrderListCell(false));
|
||||||
sellOrders.setCellFactory(new OrderListCell(true));
|
sellOrders.setCellFactory(new OrderListCell(true));
|
||||||
sellOffers.setCellFactory(new OfferListCell(true));
|
sellOffers.setCellFactory(new OfferListCell(true));
|
||||||
|
stations.setCellFactory(new StationListCell());
|
||||||
|
infoBtn.selectedProperty().addListener((ov, o, n) -> {
|
||||||
|
if (n) showInfo();
|
||||||
|
else hideInfo();
|
||||||
|
});
|
||||||
|
refuelGroup.managedProperty().bind(refuelGroup.visibleProperty());
|
||||||
|
missionsGroup.managedProperty().bind(missionsGroup.visibleProperty());
|
||||||
|
ordersGroup.managedProperty().bind(ordersGroup.visibleProperty());
|
||||||
|
infoGroup.managedProperty().bind(infoGroup.visibleProperty());
|
||||||
|
hideInfo();
|
||||||
|
hideStationInfo();
|
||||||
bindKeys();
|
bindKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resize(){
|
||||||
|
if (stage == null) return;
|
||||||
|
Pane root = (Pane)stage.getScene().getRoot();
|
||||||
|
root.autosize();
|
||||||
|
Bounds bounds = root.getLayoutBounds();
|
||||||
|
stage.setWidth(bounds.getWidth());
|
||||||
|
stage.setHeight(bounds.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDocked(boolean docked){
|
||||||
|
if (docked && MainController.getProfile().getStation().equals(entry.getStation())){
|
||||||
|
showStationInfo();
|
||||||
|
} else {
|
||||||
|
hideStationInfo();
|
||||||
|
hideInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showStationInfo(){
|
||||||
|
refuelGroup.setVisible(entry.getRefill() > 0);
|
||||||
|
ordersGroup.setVisible(!buyOrders.getItems().isEmpty() || !sellOrders.getItems().isEmpty());
|
||||||
|
missionsGroup.setVisible(!missions.getItems().isEmpty());
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideStationInfo(){
|
||||||
|
refuelGroup.setVisible(false);
|
||||||
|
ordersGroup.setVisible(false);
|
||||||
|
missionsGroup.setVisible(false);
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showInfo(){
|
||||||
|
infoGroup.setVisible(true);
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideInfo(){
|
||||||
|
infoGroup.setVisible(false);
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
public void show(Parent content) {
|
public void show(Parent content) {
|
||||||
if (stage == null){
|
if (stage == null){
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
stage.setScene(new Scene(content));
|
stage.setScene(new Scene(content));
|
||||||
|
stage.initStyle(StageStyle.UNDECORATED);
|
||||||
stage.setAlwaysOnTop(true);
|
stage.setAlwaysOnTop(true);
|
||||||
|
addDragListeners(content);
|
||||||
stage.show();
|
stage.show();
|
||||||
} else {
|
} else {
|
||||||
stage.show();
|
stage.show();
|
||||||
@@ -83,10 +153,11 @@ public class HelperController {
|
|||||||
this.route = route;
|
this.route = route;
|
||||||
setRouteEntry(route.getCurrentEntry());
|
setRouteEntry(route.getCurrentEntry());
|
||||||
this.route.currentEntryProperty().addListener(currentEntryListener);
|
this.route.currentEntryProperty().addListener(currentEntryListener);
|
||||||
|
showStationInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRouteEntry(int index){
|
private void setRouteEntry(int index){
|
||||||
RouteEntryModel entry = route.get(index);
|
entry = route.get(index);
|
||||||
station.setText(entry.getStation().getName());
|
station.setText(entry.getStation().getName());
|
||||||
system.setText(entry.getStation().getSystem().getName());
|
system.setText(entry.getStation().getSystem().getName());
|
||||||
time.setText(ViewUtils.timeToString(entry.getTime()));
|
time.setText(ViewUtils.timeToString(entry.getTime()));
|
||||||
@@ -135,11 +206,33 @@ public class HelperController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
||||||
|
private final ChangeListener<Boolean> dockedListener = (ov, o, n) -> ViewUtils.doFX(() -> setDocked(n));
|
||||||
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> {
|
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> {
|
||||||
if (n != null){
|
if (n != null){
|
||||||
ViewUtils.doFX(() -> setRoute(n));
|
ViewUtils.doFX(() -> setRoute(n));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void addDragListeners(final Node node){
|
||||||
|
new DragListener(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DragListener {
|
||||||
|
private final EventHandler<MouseEvent> pressedListener;
|
||||||
|
private final EventHandler<MouseEvent> draggedListener;
|
||||||
|
double x, y;
|
||||||
|
|
||||||
|
private DragListener(Node node) {
|
||||||
|
pressedListener = (MouseEvent mouseEvent) -> {
|
||||||
|
x = mouseEvent.getSceneX();
|
||||||
|
y = mouseEvent.getSceneY();
|
||||||
|
};
|
||||||
|
draggedListener = (MouseEvent mouseEvent) -> {
|
||||||
|
node.getScene().getWindow().setX(mouseEvent.getScreenX()-x);
|
||||||
|
node.getScene().getWindow().setY(mouseEvent.getScreenY()-y);
|
||||||
|
};
|
||||||
|
node.setOnMousePressed(pressedListener);
|
||||||
|
node.setOnMouseDragged(draggedListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package ru.trader.model;
|
package ru.trader.model;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.StringBinding;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.core.*;
|
import ru.trader.core.*;
|
||||||
|
import ru.trader.model.support.ModelBindings;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -130,6 +133,10 @@ public class StationModel {
|
|||||||
return station.getDistance(other.station);
|
return station.getDistance(other.station);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringBinding asString(){
|
||||||
|
return Bindings.createStringBinding(() -> getSystem().getName()+": "+getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (LOG.isTraceEnabled()){
|
if (LOG.isTraceEnabled()){
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package ru.trader.view.support.cells;
|
||||||
|
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import ru.trader.model.StationModel;
|
||||||
|
|
||||||
|
public class StationListCell implements Callback<ListView<StationModel>, ListCell<StationModel>> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListCell<StationModel> call(ListView<StationModel> param){
|
||||||
|
return new ListCell<StationModel>(){
|
||||||
|
private StationModel s;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItem(StationModel station, boolean empty) {
|
||||||
|
super.updateItem(station, empty);
|
||||||
|
if (!empty){
|
||||||
|
if (s != station){
|
||||||
|
textProperty().unbind();
|
||||||
|
textProperty().bind(station.asString());
|
||||||
|
s = station;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textProperty().unbind();
|
||||||
|
s = null;
|
||||||
|
setText(null);
|
||||||
|
setGraphic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
<HBox><Label text="Система:" /><Label fx:id="system" /></HBox>
|
<HBox><Label text="Система:" /><Label fx:id="system" /></HBox>
|
||||||
<HBox><Label text="Станция:" /><Label fx:id="station" /></HBox>
|
<HBox><Label text="Станция:" /><Label fx:id="station" /></HBox>
|
||||||
<HBox><Label text="Время:" /><Label fx:id="time" /></HBox>
|
<HBox><Label text="Время:" /><Label fx:id="time" /></HBox>
|
||||||
<HBox><Label text="Заправить:" /><Label fx:id="refuel" /></HBox>
|
<HBox fx:id="refuelGroup"><Label text="Заправить:" /><Label fx:id="refuel" /></HBox>
|
||||||
<HBox maxHeight="100">
|
<HBox fx:id="ordersGroup" maxHeight="100">
|
||||||
<VBox>
|
<VBox>
|
||||||
<Label text="Продать:" />
|
<Label text="Продать:" />
|
||||||
<ListView fx:id="sellOrders"/>
|
<ListView fx:id="sellOrders"/>
|
||||||
@@ -24,11 +24,11 @@
|
|||||||
<ListView fx:id="buyOrders"/>
|
<ListView fx:id="buyOrders"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
</HBox>
|
</HBox>
|
||||||
<VBox maxHeight="100">
|
<VBox fx:id="missionsGroup" maxHeight="100">
|
||||||
<Label text="Сдать миссии:" />
|
<Label text="Сдать миссии:" />
|
||||||
<ListView fx:id="missions"/>
|
<ListView fx:id="missions"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
<HBox>
|
<HBox fx:id="infoGroup">
|
||||||
<VBox maxHeight="100">
|
<VBox maxHeight="100">
|
||||||
<Label text="Станции:" />
|
<Label text="Станции:" />
|
||||||
<ListView fx:id="stations"/>
|
<ListView fx:id="stations"/>
|
||||||
@@ -51,5 +51,8 @@
|
|||||||
<Button prefWidth="30" onAction="#copy">
|
<Button prefWidth="30" onAction="#copy">
|
||||||
<graphic><Glyph text="FontAwesome|COPY"/></graphic>
|
<graphic><Glyph text="FontAwesome|COPY"/></graphic>
|
||||||
</Button>
|
</Button>
|
||||||
|
<ToggleButton fx:id="infoBtn" prefWidth="30">
|
||||||
|
<graphic><Glyph text="FontAwesome|HELP"/></graphic>
|
||||||
|
</ToggleButton>
|
||||||
</HBox>
|
</HBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user