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.Collection;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class PowerPlayController { public class PowerPlayController {
@@ -32,6 +33,8 @@ public class PowerPlayController {
private TextField controlSystemText; private TextField controlSystemText;
private AutoCompletion<SystemModel> controlSystem; private AutoCompletion<SystemModel> controlSystem;
@FXML @FXML
private ComboBox<POWER> cbCurrentPower;
@FXML
private ComboBox<POWER> cbPower; private ComboBox<POWER> cbPower;
@FXML @FXML
private CheckComboBox<POWER_STATE> cbStates; private CheckComboBox<POWER_STATE> cbStates;
@@ -47,6 +50,8 @@ public class PowerPlayController {
@FXML @FXML
private RadioButton rbControlling; private RadioButton rbControlling;
@FXML @FXML
private ListView<SystemModel> historySystems;
@FXML
private ListView<SystemModel> controlSystems; private ListView<SystemModel> controlSystems;
@FXML @FXML
private MasterDetailPane resultPane; private MasterDetailPane resultPane;
@@ -57,6 +62,7 @@ public class PowerPlayController {
private MarketModel world; private MarketModel world;
private ProfileModel profile; private ProfileModel profile;
private Optional<SystemModel> hqSystem;
private PowerPlayAnalyzator analyzator; private PowerPlayAnalyzator analyzator;
private final List<ResultEntry> result = FXCollections.observableArrayList(); private final List<ResultEntry> result = FXCollections.observableArrayList();
private final List<ResultEntry> detail = FXCollections.observableArrayList(); private final List<ResultEntry> detail = FXCollections.observableArrayList();
@@ -67,6 +73,8 @@ public class PowerPlayController {
init(); init();
profile = MainController.getProfile(); profile = MainController.getProfile();
cbCurrentPower.setConverter(new PowerStringConverter());
cbCurrentPower.setItems(FXCollections.observableArrayList(POWER.values()));
cbPower.setConverter(new PowerStringConverter()); cbPower.setConverter(new PowerStringConverter());
cbPower.setItems(FXCollections.observableArrayList(POWER.values())); cbPower.setItems(FXCollections.observableArrayList(POWER.values()));
cbStates.setConverter(new PowerStateStringConverter()); cbStates.setConverter(new PowerStateStringConverter());
@@ -81,8 +89,17 @@ public class PowerPlayController {
} }
void init(){ void init(){
//TODO: add to screens reinit
world = MainController.getWorld(); world = MainController.getWorld();
analyzator = world.getPowerPlayAnalyzer(); 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(); SystemsProvider provider = world.getSystemsProvider();
if (checkedSystem == null){ 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(){ 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 -> { tblResults.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ESCAPE){ if (e.getCode() == KeyCode.ESCAPE) {
if (!tblResults.getSelectionModel().isEmpty()) { if (!tblResults.getSelectionModel().isEmpty()) {
tblResults.getSelectionModel().clearSelection(); tblResults.getSelectionModel().clearSelection();
} }
} }
}); });
tblResults.getSelectionModel().selectedItemProperty().addListener((ov, o, n) -> { tblResults.getSelectionModel().selectedItemProperty().addListener((ov, o, n) -> {
if (n != null){ if (n != null) {
fillDetail(n.starSystem); fillDetail(n.starSystem);
resultPane.setShowDetailNode(true); resultPane.setShowDetailNode(true);
} else { } else {
@@ -122,7 +156,7 @@ public class PowerPlayController {
detail.clear(); detail.clear();
if (starSystem != null){ if (starSystem != null){
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem); 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 @FXML
private void search(){ private void search(){
addHistorySystem();
if (controlSystems.getItems().isEmpty()){ if (controlSystems.getItems().isEmpty()){
addControlSystem(); addControlSystem();
} }
@@ -231,18 +266,47 @@ public class PowerPlayController {
} }
@FXML @FXML
private void copyToClipboard(){ private void addHistorySystem() {
ResultEntry entry = tblResults.getSelectionModel().getSelectedItem(); addHistorySystem(checkedSystem.getValue());
if (entry != null){ }
Main.copyToClipboard(entry.starSystem.getName());
private void addHistorySystem(SystemModel starSystem){
if (!ModelFabric.isFake(starSystem)){
if (!historySystems.getItems().contains(starSystem)) {
historySystems.getItems().add(starSystem);
}
} }
} }
@FXML @FXML
private void copyDetailToClipboard(){ 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(); ResultEntry entry = tblDetail.getSelectionModel().getSelectedItem();
if (entry != null){ starSystem = entry != null ? entry.starSystem : null;
Main.copyToClipboard(entry.starSystem.getName()); }
if (starSystem != null){
Main.copyToClipboard(starSystem.getName());
} }
} }
@@ -250,6 +314,7 @@ public class PowerPlayController {
private final SystemModel starSystem; private final SystemModel starSystem;
private final StationModel nearStation; private final StationModel nearStation;
private final ReadOnlyDoubleProperty distance; private final ReadOnlyDoubleProperty distance;
private final ReadOnlyDoubleProperty distanceHQ;
private final ReadOnlyStringProperty maxSizePad; private final ReadOnlyStringProperty maxSizePad;
private final ReadOnlyIntegerProperty intersectCount; private final ReadOnlyIntegerProperty intersectCount;
private final ReadOnlyStringProperty controlling; private final ReadOnlyStringProperty controlling;
@@ -265,6 +330,8 @@ public class PowerPlayController {
nearStation = starSystem.getNear(); nearStation = starSystem.getNear();
controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems())); controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN); 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) { private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
@@ -306,6 +373,10 @@ public class PowerPlayController {
return distance; return distance;
} }
public ReadOnlyDoubleProperty distanceHQProperty() {
return distanceHQ;
}
public ReadOnlyStringProperty maxSizePadProperty() { public ReadOnlyStringProperty maxSizePadProperty() {
return maxSizePad; return maxSizePad;
} }

View File

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