Archived
0

implement saving vendor filters, modify filter screen

This commit is contained in:
iMoHax
2016-03-16 16:56:49 +03:00
parent 10bdb62164
commit 63299d825c
10 changed files with 523 additions and 59 deletions

View File

@@ -7,6 +7,8 @@ import ru.trader.core.Market;
import ru.trader.core.MarketFilter;
import ru.trader.core.Profile;
import ru.trader.core.Ship;
import ru.trader.store.json.FiltersStore;
import ru.trader.store.json.JsonStore;
import javax.swing.*;
import java.io.*;
@@ -21,6 +23,8 @@ public class Settings {
private Profile profile;
private final EDCESettings edce;
private final HelperSettings helper;
private final JsonStore jsonStore;
private MarketFilter filter;
public Settings() {
@@ -28,6 +32,7 @@ public class Settings {
profile = new Profile(new Ship());
edce = new EDCESettings();
helper = new HelperSettings();
jsonStore = new JsonStore();
}
public Settings(File file) {
@@ -35,16 +40,19 @@ public class Settings {
profile = new Profile(new Ship());
edce = new EDCESettings();
helper = new HelperSettings();
jsonStore = new JsonStore();
}
public void load(Market market) {
try (InputStream is = new FileInputStream(file)) {
values.load(is);
filter = jsonStore.getFilter(market);
} catch (FileNotFoundException e) {
LOG.warn("File {} not found", file);
} catch (IOException e) {
LOG.error("Error on load settings", e);
}
if (filter == null) filter = new MarketFilter();
profile = Profile.readFrom(values, market);
edce.readFrom(values);
helper.readFrom(values);
@@ -56,8 +64,9 @@ public class Settings {
edce.writeTo(values);
helper.writeTo(values);
values.store(os, "settings");
jsonStore.saveFilter(filter);
} catch (IOException e) {
LOG.error("Error on load settings", e);
LOG.error("Error on save settings", e);
}
}
@@ -143,11 +152,11 @@ public class Settings {
}
public MarketFilter getFilter(Market market){
return MarketFilter.buildFilter(values, market);
return filter;
}
public void setFilter(MarketFilter filter){
filter.writeTo(values);
this.filter = filter;
}
public Profile getProfile() {

View File

@@ -5,18 +5,16 @@ import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.util.Pair;
import org.controlsfx.control.CheckComboBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.MarketFilter;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.core.VendorFilter;
import ru.trader.core.*;
import ru.trader.model.MarketModel;
import ru.trader.model.ModelFabric;
import ru.trader.model.StationModel;
import ru.trader.model.SystemModel;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.Localization;
import ru.trader.view.support.NumberField;
import ru.trader.view.support.*;
import ru.trader.view.support.autocomplete.AutoCompletion;
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
import ru.trader.view.support.autocomplete.SystemsProvider;
@@ -41,23 +39,14 @@ public class FilterController {
@FXML
private ComboBox<String> station;
@FXML
private CheckBox cbMarket;
private CheckComboBox<STATION_TYPE> stationTypes;
@FXML
private CheckBox cbBlackMarket;
private CheckComboBox<SERVICE_TYPE> services;
@FXML
private CheckBox cbRefuel;
private CheckComboBox<FACTION> factions;
@FXML
private CheckBox cbRepair;
@FXML
private CheckBox cbMunition;
@FXML
private CheckBox cbOutfit;
@FXML
private CheckBox cbShipyard;
@FXML
private CheckBox cbMediumLandpad;
@FXML
private CheckBox cbLargeLandpad;
private CheckComboBox<GOVERNMENT> governments;
@FXML
private ListView<StationModel> excludes;
@FXML
@@ -76,6 +65,14 @@ public class FilterController {
@FXML
private void initialize(){
init();
stationTypes.setConverter(new StationTypeStringConverter());
stationTypes.getItems().setAll(STATION_TYPE.values());
services.setConverter(new ServiceTypeStringConverter());
services.getItems().setAll(SERVICE_TYPE.values());
factions.setConverter(new FactionStringConverter());
factions.getItems().setAll(FACTION.values());
governments.setConverter(new GovernmentStringConverter());
governments.getItems().setAll(GOVERNMENT.values());
excludes.setCellFactory(new CustomListCell<>(StationModel::getFullName));
system.valueProperty().addListener((ov, o, n) -> {
station.setItems(n.getStationNamesList());
@@ -134,15 +131,22 @@ public class FilterController {
center.setValue(market.getModeler().get(filter.getCenter()));
radius.setValue(filter.getRadius());
distance.setValue(filter.getDistance());
cbMarket.setSelected(filter.has(SERVICE_TYPE.MARKET));
cbBlackMarket.setSelected(filter.has(SERVICE_TYPE.BLACK_MARKET));
cbRefuel.setSelected(filter.has(SERVICE_TYPE.REFUEL));
cbMunition.setSelected(filter.has(SERVICE_TYPE.MUNITION));
cbRepair.setSelected(filter.has(SERVICE_TYPE.REPAIR));
cbOutfit.setSelected(filter.has(SERVICE_TYPE.OUTFIT));
cbShipyard.setSelected(filter.has(SERVICE_TYPE.SHIPYARD));
cbMediumLandpad.setSelected(filter.has(SERVICE_TYPE.MEDIUM_LANDPAD));
cbLargeLandpad.setSelected(filter.has(SERVICE_TYPE.LARGE_LANDPAD));
stationTypes.getCheckModel().clearChecks();
for (STATION_TYPE stationType : filter.getTypes()) {
stationTypes.getCheckModel().check(stationType);
}
services.getCheckModel().clearChecks();
for (SERVICE_TYPE service : filter.getServices()) {
services.getCheckModel().check(service);
}
factions.getCheckModel().clearChecks();
for (FACTION faction : filter.getFactions()) {
factions.getCheckModel().check(faction);
}
governments.getCheckModel().clearChecks();
for (GOVERNMENT government : filter.getGovernments()) {
governments.getCheckModel().check(government);
}
excludes.setItems(BindingsHelper.observableList(filter.getExcludes(), market.getModeler()::get));
vFilters.getItems().clear();
for (Map.Entry<String, VendorFilter> entry : filter.getVendorFilters().entrySet()) {
@@ -165,15 +169,14 @@ public class FilterController {
filter.setCenter(ModelFabric.isFake(s) ? null : ModelFabric.get(s));
filter.setRadius(radius.getValue().doubleValue());
filter.setDistance(distance.getValue().doubleValue());
if (cbMarket.isSelected()) filter.add(SERVICE_TYPE.MARKET); else filter.remove(SERVICE_TYPE.MARKET);
if (cbBlackMarket.isSelected()) filter.add(SERVICE_TYPE.BLACK_MARKET); else filter.remove(SERVICE_TYPE.BLACK_MARKET);
if (cbRefuel.isSelected()) filter.add(SERVICE_TYPE.REFUEL); else filter.remove(SERVICE_TYPE.REFUEL);
if (cbMunition.isSelected()) filter.add(SERVICE_TYPE.MUNITION); else filter.remove(SERVICE_TYPE.MUNITION);
if (cbRepair.isSelected()) filter.add(SERVICE_TYPE.REPAIR); else filter.remove(SERVICE_TYPE.REPAIR);
if (cbOutfit.isSelected()) filter.add(SERVICE_TYPE.OUTFIT); else filter.remove(SERVICE_TYPE.OUTFIT);
if (cbShipyard.isSelected()) filter.add(SERVICE_TYPE.SHIPYARD); else filter.remove(SERVICE_TYPE.SHIPYARD);
if (cbMediumLandpad.isSelected()) filter.add(SERVICE_TYPE.MEDIUM_LANDPAD); else filter.remove(SERVICE_TYPE.MEDIUM_LANDPAD);
if (cbLargeLandpad.isSelected()) filter.add(SERVICE_TYPE.LARGE_LANDPAD); else filter.remove(SERVICE_TYPE.LARGE_LANDPAD);
filter.clearTypes();
stationTypes.getCheckModel().getCheckedItems().forEach(filter::add);
filter.clearServices();
services.getCheckModel().getCheckedItems().forEach(filter::add);
filter.clearFactions();
factions.getCheckModel().getCheckedItems().forEach(filter::add);
filter.clearGovernments();
governments.getCheckModel().getCheckedItems().forEach(filter::add);
filter.clearExcludes();
excludes.getItems().forEach(st -> filter.addExclude(ModelFabric.get(st)));
filter.clearVendorFilters();

View File

@@ -11,6 +11,7 @@ market.station.name=Station
market.allegiance=Allegiance
market.government=Government
market.economic=Economy
market.station.services=Services
market.station.type=Station type
# Offer

View File

@@ -11,6 +11,7 @@ market.station.name=\u0421\u0442\u0430\u043D\u0446\u0438\u044F
market.allegiance=\u041F\u0440\u0438\u043D\u0430\u0434\u043B\u0435\u0436\u043D\u043E\u0441\u0442\u044C
market.government=\u0424\u043E\u0440\u043C\u0430 \u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u044F
market.economic=\u042D\u043A\u043E\u043D\u043E\u043C\u0438\u043A\u0430
market.station.services=\u0421\u0435\u0440\u0432\u0438\u0441\u044B
market.station.type=\u0422\u0438\u043F \u0441\u0442\u0430\u043D\u0446\u0438\u0438
# Offer

View File

@@ -2,6 +2,7 @@
<?import javafx.scene.layout.*?>
<?import org.controlsfx.glyphfont.*?>
<?import ru.trader.view.support.NumberField?>
<?import org.controlsfx.control.CheckComboBox?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.trader.controllers.FilterController"
styleClass="dialog" vgap="4" hgap="8">
<columnConstraints>
@@ -15,20 +16,28 @@
<NumberField fx:id="radius" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="%filter.distance" GridPane.rowIndex="3" />
<NumberField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="%filter.services" GridPane.rowIndex="4" />
<TilePane hgap="5" vgap="5" tileAlignment="BASELINE_LEFT" prefColumns="2" GridPane.columnIndex="1" GridPane.rowIndex="4" >
<CheckBox fx:id="cbMarket" text="%services.MARKET"/>
<CheckBox fx:id="cbBlackMarket" text="%services.BLACK_MARKET"/>
<CheckBox fx:id="cbRefuel" text="%services.REFUEL"/>
<CheckBox fx:id="cbRepair" text="%services.REPAIR"/>
<CheckBox fx:id="cbMunition" text="%services.MUNITION"/>
<CheckBox fx:id="cbOutfit" text="%services.OUTFIT"/>
<CheckBox fx:id="cbShipyard" text="%services.SHIPYARD"/>
<CheckBox fx:id="cbMediumLandpad" text="%services.MEDIUM_LANDPAD"/>
<CheckBox fx:id="cbLargeLandpad" text="%services.LARGE_LANDPAD"/>
</TilePane>
<Label text="%filter.excludes" GridPane.rowIndex="5" />
<VBox GridPane.rowIndex="6" spacing="4">
<HBox GridPane.rowIndex="4" GridPane.columnSpan="2" spacing="10" alignment="CENTER">
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.station.type"/>
<CheckComboBox fx:id="stationTypes" maxWidth="200" />
</VBox>
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.station.services"/>
<CheckComboBox fx:id="services" maxWidth="200" />
</VBox>
</HBox>
<HBox GridPane.rowIndex="5" GridPane.columnSpan="2" spacing="10" alignment="CENTER">
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.allegiance"/>
<CheckComboBox fx:id="factions" maxWidth="200" />
</VBox>
<VBox prefWidth="200" alignment="CENTER">
<Label text="%market.government"/>
<CheckComboBox fx:id="governments" maxWidth="200" />
</VBox>
</HBox>
<Label text="%filter.excludes" GridPane.rowIndex="6" />
<VBox GridPane.rowIndex="7" spacing="4">
<TextField fx:id="systemText" minWidth="180"/>
<ComboBox fx:id="station" minWidth="180"/>
<HBox spacing="2" alignment="BASELINE_RIGHT">
@@ -37,10 +46,10 @@
<Button prefWidth="30" onAction="#clean"><graphic><Glyph text="FontAwesome|TRASH_ALT"/></graphic></Button>
</HBox>
</VBox>
<ListView fx:id="excludes" GridPane.rowIndex="6" GridPane.columnIndex="1" maxHeight="120"/>
<ListView fx:id="excludes" GridPane.rowIndex="7" GridPane.columnIndex="1" maxHeight="120"/>
<Label text="Фильтры на товары:" GridPane.rowIndex="7" />
<VBox GridPane.rowIndex="8" spacing="4">
<Label text="Фильтры на товары:" GridPane.rowIndex="8" />
<VBox GridPane.rowIndex="9" spacing="4">
<TextField fx:id="vFilterSystemText" minWidth="180"/>
<ComboBox fx:id="vFilterStation" minWidth="180"/>
<HBox spacing="2" alignment="BASELINE_RIGHT">
@@ -50,8 +59,8 @@
<Button prefWidth="30" onAction="#cleanVendorFilters"><graphic><Glyph text="FontAwesome|TRASH_ALT"/></graphic></Button>
</HBox>
<Button prefWidth="180" text="Глобальный фильтр" onAction="#editDefaultVendorFilter"/>
</VBox>
<ListView fx:id="vFilters" GridPane.rowIndex="8" GridPane.columnIndex="1" maxHeight="120"/>
</VBox>
<ListView fx:id="vFilters" GridPane.rowIndex="9" GridPane.columnIndex="1" maxHeight="120"/>
</GridPane>