Archived
0

add history list to PP controller, enable Ctrl+C for copy star system name

This commit is contained in:
Mo
2016-11-08 13:01:51 +03:00
parent 4b01ac9bc1
commit 22c5992691
2 changed files with 132 additions and 29 deletions

View File

@@ -21,6 +21,7 @@ import ru.trader.view.support.autocomplete.SystemsProvider;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class PowerPlayController {
@@ -32,6 +33,8 @@ public class PowerPlayController {
private TextField controlSystemText;
private AutoCompletion<SystemModel> controlSystem;
@FXML
private ComboBox<POWER> cbCurrentPower;
@FXML
private ComboBox<POWER> cbPower;
@FXML
private CheckComboBox<POWER_STATE> cbStates;
@@ -47,6 +50,8 @@ public class PowerPlayController {
@FXML
private RadioButton rbControlling;
@FXML
private ListView<SystemModel> historySystems;
@FXML
private ListView<SystemModel> controlSystems;
@FXML
private MasterDetailPane resultPane;
@@ -57,6 +62,7 @@ public class PowerPlayController {
private MarketModel world;
private ProfileModel profile;
private Optional<SystemModel> hqSystem;
private PowerPlayAnalyzator analyzator;
private final List<ResultEntry> result = FXCollections.observableArrayList();
private final List<ResultEntry> detail = FXCollections.observableArrayList();
@@ -67,6 +73,8 @@ public class PowerPlayController {
init();
profile = MainController.getProfile();
cbCurrentPower.setConverter(new PowerStringConverter());
cbCurrentPower.setItems(FXCollections.observableArrayList(POWER.values()));
cbPower.setConverter(new PowerStringConverter());
cbPower.setItems(FXCollections.observableArrayList(POWER.values()));
cbStates.setConverter(new PowerStateStringConverter());
@@ -81,8 +89,17 @@ public class PowerPlayController {
}
void init(){
//TODO: add to screens reinit
world = MainController.getWorld();
analyzator = world.getPowerPlayAnalyzer();
if (cbCurrentPower.getValue() != POWER.NONE && cbCurrentPower.getValue() != null){
hqSystem = getHeadquarter(cbCurrentPower.getValue());
} else {
hqSystem = Optional.empty();
}
historySystems.getItems().clear();
controlSystems.getItems().clear();
SystemsProvider provider = world.getSystemsProvider();
if (checkedSystem == null){
@@ -99,16 +116,33 @@ public class PowerPlayController {
}
}
private Optional<SystemModel> getHeadquarter(POWER power) {
StarSystemFilter filter = new StarSystemFilter(true);
filter.add(power);
filter.add(POWER_STATE.HEADQUARTERS);
return world.getSystems(filter).stream().findFirst();
}
private void initListeners(){
cbCurrentPower.valueProperty().addListener((ov, o, n) -> {
hqSystem = getHeadquarter(n);
});
historySystems.getSelectionModel().selectedItemProperty().addListener((ov, o, n) -> {
if (n != null){
checkedSystem.setValue(n);
}
});
tblResults.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ESCAPE){
if (e.getCode() == KeyCode.ESCAPE) {
if (!tblResults.getSelectionModel().isEmpty()) {
tblResults.getSelectionModel().clearSelection();
}
}
});
tblResults.getSelectionModel().selectedItemProperty().addListener((ov, o, n) -> {
if (n != null){
if (n != null) {
fillDetail(n.starSystem);
resultPane.setShowDetailNode(true);
} else {
@@ -122,7 +156,7 @@ public class PowerPlayController {
detail.clear();
if (starSystem != null){
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem);
detail.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem)));
detail.addAll(BindingsHelper.observableList(controllings, d -> new ResultEntry(d, starSystem)));
}
}
@@ -182,6 +216,7 @@ public class PowerPlayController {
@FXML
private void search(){
addHistorySystem();
if (controlSystems.getItems().isEmpty()){
addControlSystem();
}
@@ -231,18 +266,47 @@ public class PowerPlayController {
}
@FXML
private void copyToClipboard(){
ResultEntry entry = tblResults.getSelectionModel().getSelectedItem();
if (entry != null){
Main.copyToClipboard(entry.starSystem.getName());
private void addHistorySystem() {
addHistorySystem(checkedSystem.getValue());
}
private void addHistorySystem(SystemModel starSystem){
if (!ModelFabric.isFake(starSystem)){
if (!historySystems.getItems().contains(starSystem)) {
historySystems.getItems().add(starSystem);
}
}
}
@FXML
private void copyDetailToClipboard(){
ResultEntry entry = tblDetail.getSelectionModel().getSelectedItem();
if (entry != null){
Main.copyToClipboard(entry.starSystem.getName());
private void removeHistorySystem(){
int index = historySystems.getSelectionModel().getSelectedIndex();
if (index >= 0){
historySystems.getItems().remove(index);
}
}
@FXML
private void clearHistorySystems(){
controlSystems.getItems().clear();
}
@FXML
private void copySystemToClipboard(){
SystemModel starSystem = null;
if (historySystems.isFocused()) starSystem = historySystems.getSelectionModel().getSelectedItem();
if (controlSystems.isFocused()) starSystem = controlSystems.getSelectionModel().getSelectedItem();
if (tblResults.isFocused()){
ResultEntry entry = tblResults.getSelectionModel().getSelectedItem();
starSystem = entry != null ? entry.starSystem : null;
}
if (tblDetail.isFocused()){
ResultEntry entry = tblDetail.getSelectionModel().getSelectedItem();
starSystem = entry != null ? entry.starSystem : null;
}
if (starSystem != null){
Main.copyToClipboard(starSystem.getName());
}
}
@@ -250,6 +314,7 @@ public class PowerPlayController {
private final SystemModel starSystem;
private final StationModel nearStation;
private final ReadOnlyDoubleProperty distance;
private final ReadOnlyDoubleProperty distanceHQ;
private final ReadOnlyStringProperty maxSizePad;
private final ReadOnlyIntegerProperty intersectCount;
private final ReadOnlyStringProperty controlling;
@@ -265,6 +330,8 @@ public class PowerPlayController {
nearStation = starSystem.getNear();
controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
Place hq = ModelFabric.get(hqSystem.orElse(null));
distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN);
}
private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
@@ -306,6 +373,10 @@ public class PowerPlayController {
return distance;
}
public ReadOnlyDoubleProperty distanceHQProperty() {
return distanceHQ;
}
public ReadOnlyStringProperty maxSizePadProperty() {
return maxSizePad;
}

View File

@@ -19,8 +19,28 @@
<TextField fx:id="checkedSystemText" prefWidth="220"/>
<Button minWidth="30" onAction="#currentAsChecked"><graphic><Glyph text="FontAwesome|MAP_MARKER"/></graphic></Button>
</HBox>
<HBox spacing="4" alignment="CENTER" VBox.vgrow="ALWAYS" HBox.hgrow="ALWAYS">
<ListView fx:id="historySystems" HBox.hgrow="ALWAYS">
<contextMenu>
<ContextMenu>
<items>
<MenuItem text="%dialog.button.copy" accelerator="Shortcut+C" onAction="#copySystemToClipboard" />
</items>
</ContextMenu>
</contextMenu>
</ListView>
<VBox spacing="4">
<Button prefWidth="30" onAction="#addHistorySystem"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
<Button prefWidth="30" onAction="#removeHistorySystem"><graphic><Glyph text="FontAwesome|MINUS"/></graphic></Button>
<Button prefWidth="30" onAction="#clearHistorySystems"><graphic><Glyph text="FontAwesome|TRASH"/></graphic></Button>
</VBox>
</HBox>
</VBox>
<VBox minWidth="250" maxWidth="250" spacing="10" alignment="CENTER_LEFT">
<HBox spacing="4">
<Label text="Сила:" minWidth="86" maxWidth="86" />
<ComboBox fx:id="cbCurrentPower" minWidth="160"/>
</HBox>
<fx:define><ToggleGroup fx:id="analyzeType" /></fx:define>
<RadioButton fx:id="rbIntersect" text="Поиск пересечений" selected="true" toggleGroup="$analyzeType"/>
<RadioButton fx:id="rbNear" text="Поиск ближайших без пересечений" selected="false" toggleGroup="$analyzeType"/>
@@ -46,7 +66,15 @@
<CheckComboBox fx:id="cbStates" minWidth="160" />
</HBox>
<HBox spacing="4" alignment="CENTER" VBox.vgrow="ALWAYS" HBox.hgrow="ALWAYS">
<ListView fx:id="controlSystems" HBox.hgrow="ALWAYS"/>
<ListView fx:id="controlSystems" HBox.hgrow="ALWAYS">
<contextMenu>
<ContextMenu>
<items>
<MenuItem text="%dialog.button.copy" accelerator="Shortcut+C" onAction="#copySystemToClipboard" />
</items>
</ContextMenu>
</contextMenu>
</ListView>
<VBox spacing="4">
<Button prefWidth="30" onAction="#addControlSystem"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
<Button prefWidth="30" onAction="#removeControlSystem"><graphic><Glyph text="FontAwesome|MINUS"/></graphic></Button>
@@ -56,43 +84,47 @@
</VBox>
</HBox>
</TitledPane>
<MasterDetailPane fx:id="resultPane" detailSide="RIGHT" prefWidth="1190" dividerPosition="0.566" showDetailNode="false">
<MasterDetailPane fx:id="resultPane" detailSide="RIGHT" prefWidth="1190" dividerPosition="0.566" showDetailNode="false" VBox.vgrow="ALWAYS">
<masterNode>
<TitledPane text="Результаты анализа" collapsible="false">
<TableView fx:id="tblResults">
<columns>
<TableColumn minWidth="200" text="%market.system">
<TableColumn prefWidth="200" text="%market.system">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="180" text="Пересекается с">
<TableColumn prefWidth="180" text="Пересекается с">
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="90" text="Пересечений">
<TableColumn prefWidth="90" text="Пересечений">
<cellValueFactory><PropertyValueFactory property="intersectCount"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="100" text="%market.powerState">
<TableColumn prefWidth="100" text="%market.powerState">
<cellFactory><TextCell><converter><PowerStateStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="powerState"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="100" text="%market.power">
<TableColumn prefWidth="100" text="%market.power">
<cellFactory><TextCell><converter><PowerStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="power"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120" text="%market.government">
<TableColumn prefWidth="120" text="%market.government">
<cellFactory><TextCell><converter><GovernmentStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="government"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120" text="%market.allegiance">
<TableColumn prefWidth="120" text="%market.allegiance">
<cellFactory><TextCell><converter><FactionStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80" text="%market.order.distance">
<TableColumn prefWidth="80" text="%market.order.distance">
<cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="100" text="Тип площадки">
<TableColumn prefWidth="100" text="Тип площадки">
<cellValueFactory><PropertyValueFactory property="maxSizePad"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="80" text="Дистанция до HQ">
<cellFactory><DistanceCell /></cellFactory>
<cellValueFactory><PropertyValueFactory property="distanceHQ"/></cellValueFactory>
</TableColumn>
</columns>
<columnResizePolicy>
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
@@ -100,7 +132,7 @@
<contextMenu>
<ContextMenu>
<items>
<MenuItem text="%dialog.button.copy" onAction="#copyToClipboard" />
<MenuItem text="%dialog.button.copy" accelerator="Shortcut+C" onAction="#copySystemToClipboard" />
</items>
</ContextMenu>
</contextMenu>
@@ -111,22 +143,22 @@
<TitledPane text="Системы в радиусе 15 LY" collapsible="false">
<TableView fx:id="tblDetail">
<columns>
<TableColumn minWidth="100" text="%market.system">
<TableColumn prefWidth="100" text="%market.system">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="100" text="%market.powerState">
<TableColumn prefWidth="100" text="%market.powerState">
<cellFactory><TextCell><converter><PowerStateStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="powerState"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="100" text="%market.power">
<TableColumn prefWidth="100" text="%market.power">
<cellFactory><TextCell><converter><PowerStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="power"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120" text="%market.government">
<TableColumn prefWidth="120" text="%market.government">
<cellFactory><TextCell><converter><GovernmentStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="government"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="120" text="%market.allegiance">
<TableColumn prefWidth="120" text="%market.allegiance">
<cellFactory><TextCell><converter><FactionStringConverter /></converter></TextCell></cellFactory>
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
</TableColumn>
@@ -137,7 +169,7 @@
<contextMenu>
<ContextMenu>
<items>
<MenuItem text="%dialog.button.copy" onAction="#copyDetailToClipboard" />
<MenuItem text="%dialog.button.copy" accelerator="Shortcut+C" onAction="#copySystemToClipboard" />
</items>
</ContextMenu>
</contextMenu>