Archived
0

implement illegal commodity visualisation

This commit is contained in:
iMoHax
2016-03-14 14:15:35 +03:00
parent 2eef6db53b
commit 01fc65ec94
14 changed files with 270 additions and 9 deletions

View File

@@ -20,9 +20,7 @@ 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.*;
import ru.trader.view.support.cells.OrderListCell;
import ru.trader.view.support.cells.StationListCell;
import javax.swing.*; import javax.swing.*;
@@ -70,8 +68,8 @@ public class HelperController {
@FXML @FXML
private void initialize(){ private void initialize(){
buyOrders.setCellFactory(new OrderListCell(false)); buyOrders.setCellFactory(new OrderListCell(false));
sellOrders.setCellFactory(new OrderListCell(true)); sellOrders.setCellFactory(new OrderDecoratedListCell(true));
sellOffers.setCellFactory(new OfferListCell(true)); sellOffers.setCellFactory(new OfferDecoratedListCell(true));
stations.setCellFactory(new StationListCell()); stations.setCellFactory(new StationListCell());
infoBtn.selectedProperty().addListener((ov, o, n) -> { infoBtn.selectedProperty().addListener((ov, o, n) -> {
if (n) showInfo(); if (n) showInfo();

View File

@@ -17,6 +17,7 @@ import ru.trader.view.support.ViewUtils;
import ru.trader.view.support.autocomplete.AutoCompletion; import ru.trader.view.support.autocomplete.AutoCompletion;
import ru.trader.view.support.autocomplete.CachedSuggestionProvider; import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
import ru.trader.view.support.autocomplete.SystemsProvider; import ru.trader.view.support.autocomplete.SystemsProvider;
import ru.trader.view.support.cells.OrderDecoratedListCell;
import ru.trader.view.support.cells.OrderListCell; import ru.trader.view.support.cells.OrderListCell;
import java.util.ArrayList; import java.util.ArrayList;
@@ -70,7 +71,7 @@ public class RouteTrackController {
private void initialize(){ private void initialize(){
addMissionsList.setItems(missionsController.getMissions()); addMissionsList.setItems(missionsController.getMissions());
buyOrders.setCellFactory(new OrderListCell(false)); buyOrders.setCellFactory(new OrderListCell(false));
sellOrders.setCellFactory(new OrderListCell(true)); sellOrders.setCellFactory(new OrderDecoratedListCell(true));
editGroup.setVisible(false); editGroup.setVisible(false);
init(); init();
newEntrySystem.valueProperty().addListener((ov, o , n) -> { newEntrySystem.valueProperty().addListener((ov, o , n) -> {

View File

@@ -51,6 +51,10 @@ public class OfferModel {
return item; return item;
} }
public boolean isIllegal() {
return offer.isIllegal();
}
public OFFER_TYPE getType(){ public OFFER_TYPE getType(){
return offer.getType(); return offer.getType();
} }

View File

@@ -65,6 +65,11 @@ public class OrderModel {
this.count.set(count); this.count.set(count);
} }
public boolean isIllegal(){
OfferModel offer = getBuyOffer();
return offer != null && offer.isIllegal();
}
public LongProperty countProperty() { public LongProperty countProperty() {
return count; return count;
} }

View File

@@ -15,6 +15,7 @@ import java.awt.event.InputEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class ViewUtils { public class ViewUtils {
public final static String ILLEGAL_ITEM_STYLE = "illegal_item";
//Scroll to row if invisible //Scroll to row if invisible
public static void show(TableView tableView, int index){ public static void show(TableView tableView, int index){

View File

@@ -0,0 +1,45 @@
package ru.trader.view.support.cells;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
public abstract class DecoratedCellFactory<S, T> implements Callback<TableColumn<S,T>, TableCell<S,T>> {
private final Callback<TableColumn<S,T>, TableCell<S,T>> decorated;
public DecoratedCellFactory() {
//noinspection unchecked
this((Callback) TableColumn.DEFAULT_CELL_FACTORY);
}
public DecoratedCellFactory(Callback<TableColumn<S, T>, TableCell<S, T>> decorated) {
this.decorated = decorated;
}
abstract void doStyle(TableCell<S, T> cell, S entry, T item);
@Override
public final TableCell<S, T> call(TableColumn<S, T> param) {
TableCell<S,T> cell = decorated.call(param);
cell.itemProperty().addListener(new ItemChangeListener(cell));
return cell;
}
private class ItemChangeListener implements ChangeListener<T> {
private final TableCell<S, T> cell;
private ItemChangeListener(TableCell<S, T> cell) {
this.cell = cell;
}
@Override
public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue) {
@SuppressWarnings("unchecked")
S entry = (S) cell.getTableRow().getItem();
doStyle(cell, entry, newValue);
}
}
}

View File

@@ -0,0 +1,64 @@
package ru.trader.view.support.cells;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
public abstract class DecoratedListCellFactory<T> implements Callback<ListView<T>, ListCell<T>> {
private final Callback<ListView<T>, ListCell<T>> decorated;
private final static Callback<ListView<?>, ListCell<?>> DEFAULT_CELL_FACTORY = cell -> new ListCell<Object>() {
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else if (item instanceof Node) {
setText(null);
Node currentNode = getGraphic();
Node newNode = (Node) item;
if (currentNode == null || ! currentNode.equals(newNode)) {
setGraphic(newNode);
}
} else {
setText(item == null ? "null" : item.toString());
setGraphic(null);
}
}
};
public DecoratedListCellFactory() {
//noinspection unchecked
this((Callback) DEFAULT_CELL_FACTORY);
}
public DecoratedListCellFactory(Callback<ListView<T>, ListCell<T>> decorated) {
this.decorated = decorated;
}
abstract void doStyle(ListCell<T> cell, T item);
@Override
public final ListCell<T> call(ListView<T> param) {
ListCell<T> cell = decorated.call(param);
cell.itemProperty().addListener(new ItemChangeListener(cell));
return cell;
}
private class ItemChangeListener implements ChangeListener<T> {
private final ListCell<T> cell;
private ItemChangeListener(ListCell<T> cell) {
this.cell = cell;
}
@Override
public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue) {
doStyle(cell, newValue);
}
}
}

View File

@@ -0,0 +1,44 @@
package ru.trader.view.support.cells;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.util.Callback;
public abstract class DecoratedRowFactory<S> implements Callback<TableView<S>, TableRow<S>> {
private final Callback<TableView<S>, TableRow<S>> decorated;
private final static Callback<TableView<?>, TableRow<?>> DEFAULT_ROW_FACTORY = row -> new TableRow<>();
public DecoratedRowFactory() {
//noinspection unchecked
this((Callback) DEFAULT_ROW_FACTORY);
}
public DecoratedRowFactory(Callback<TableView<S>, TableRow<S>> decorated) {
this.decorated = decorated;
}
abstract void doStyle(TableRow<S> row, S entry);
@Override
public final TableRow<S> call(TableView<S> param) {
TableRow<S> row = decorated.call(param);
row.itemProperty().addListener(new ItemChangeListener(row));
return row;
}
private class ItemChangeListener implements ChangeListener<S> {
private final TableRow<S> row;
private ItemChangeListener(TableRow<S> row) {
this.row = row;
}
@Override
public void changed(ObservableValue<? extends S> observable, S oldValue, S newValue) {
doStyle(row, newValue);
}
}
}

View File

@@ -0,0 +1,32 @@
package ru.trader.view.support.cells;
import javafx.collections.ObservableList;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
import ru.trader.model.OfferModel;
import ru.trader.model.OrderModel;
import ru.trader.view.support.ViewUtils;
public class OfferDecoratedListCell extends DecoratedListCellFactory<OfferModel> {
public OfferDecoratedListCell() {
this(new OfferListCell());
}
public OfferDecoratedListCell(boolean asItem) {
this(new OfferListCell(asItem));
}
public OfferDecoratedListCell(Callback<ListView<OfferModel>, ListCell<OfferModel>> decorated) {
super(decorated);
}
@Override
void doStyle(ListCell<OfferModel> cell, OfferModel item) {
ObservableList<String> styles = cell.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (item != null && item.isIllegal()){
styles.add(ViewUtils.ILLEGAL_ITEM_STYLE);
}
}
}

View File

@@ -0,0 +1,26 @@
package ru.trader.view.support.cells;
import javafx.collections.ObservableList;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.util.Callback;
import ru.trader.model.OfferModel;
import ru.trader.view.support.ViewUtils;
public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
public OfferDecoratedRow() {
}
public OfferDecoratedRow(Callback<TableView<OfferModel>, TableRow<OfferModel>> decorated) {
super(decorated);
}
@Override
void doStyle(TableRow<OfferModel> row, OfferModel entry) {
ObservableList<String> styles = row.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (entry != null && entry.isIllegal()){
styles.add(ViewUtils.ILLEGAL_ITEM_STYLE);
}
}
}

View File

@@ -0,0 +1,27 @@
package ru.trader.view.support.cells;
import javafx.collections.ObservableList;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
import ru.trader.model.OrderModel;
import ru.trader.view.support.ViewUtils;
public class OrderDecoratedListCell extends DecoratedListCellFactory<OrderModel> {
public OrderDecoratedListCell(boolean isBuy) {
this(new OrderListCell(isBuy));
}
public OrderDecoratedListCell(Callback<ListView<OrderModel>, ListCell<OrderModel>> decorated) {
super(decorated);
}
@Override
void doStyle(ListCell<OrderModel> cell, OrderModel item) {
ObservableList<String> styles = cell.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (item != null && item.isIllegal()){
styles.add(ViewUtils.ILLEGAL_ITEM_STYLE);
}
}
}

View File

@@ -3,8 +3,8 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import ru.trader.view.support.cells.OfferListCell?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import ru.trader.view.support.cells.OfferDecoratedListCell?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" <VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.ItemDescController" fx:controller="ru.trader.controllers.ItemDescController"
spacing="4" > spacing="4" >
@@ -12,10 +12,10 @@
<Label text="%itemDesc.sellers" VBox.margin="$vbox_margin"/> <Label text="%itemDesc.sellers" VBox.margin="$vbox_margin"/>
<ListView fx:id="seller" maxHeight="200.0"> <ListView fx:id="seller" maxHeight="200.0">
<cellFactory><OfferListCell/></cellFactory> <cellFactory><OfferDecoratedListCell/></cellFactory>
</ListView> </ListView>
<Label text="%itemDesc.buyers" VBox.margin="$vbox_margin"/> <Label text="%itemDesc.buyers" VBox.margin="$vbox_margin"/>
<ListView fx:id="buyer" maxHeight="200.0"> <ListView fx:id="buyer" maxHeight="200.0">
<cellFactory><OfferListCell/></cellFactory> <cellFactory><OfferDecoratedListCell/></cellFactory>
</ListView> </ListView>
</VBox> </VBox>

View File

@@ -67,6 +67,7 @@
<panes> <panes>
<TitledPane fx:id="paneSells" animated="false" text="%offers.pane.sell"> <TitledPane fx:id="paneSells" animated="false" text="%offers.pane.sell">
<TableView fx:id="tblSell" editable="true"> <TableView fx:id="tblSell" editable="true">
<rowFactory><OfferDecoratedRow /></rowFactory>
<columns> <columns>
<TableColumn minWidth="230.0" text="%market.item.name"> <TableColumn minWidth="230.0" text="%market.item.name">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
@@ -115,6 +116,7 @@
</TitledPane> </TitledPane>
<TitledPane animated="false" text="%offers.pane.buy"> <TitledPane animated="false" text="%offers.pane.buy">
<TableView fx:id="tblBuy" editable="true"> <TableView fx:id="tblBuy" editable="true">
<rowFactory><OfferDecoratedRow /></rowFactory>
<columns> <columns>
<TableColumn minWidth="230.0" text="%market.item.name"> <TableColumn minWidth="230.0" text="%market.item.name">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory> <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>

View File

@@ -1,3 +1,11 @@
.illegal_item {
-fx-base: red;
}
.illegal_item .bad .diff {
-fx-fill: white;
}
.good .diff { .good .diff {
-fx-fill: green; -fx-fill: green;
-fx-font-weight: bold; -fx-font-weight: bold;
@@ -204,6 +212,10 @@ HBox.fields-group hbox-margin{
-fx-faint-focus-color: #bb6b0022; -fx-faint-focus-color: #bb6b0022;
} }
#helper .illegal_item {
-fx-base: darkred;
}
.text-small, .text-medium, .text-big { .text-small, .text-medium, .text-big {
-fx-font-weight: bold; -fx-font-weight: bold;
} }