- add edce settings
- add edce activate button
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package ru.trader;
|
package ru.trader;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -37,7 +40,8 @@ public class EDCE {
|
|||||||
private final StationUpdater updater;
|
private final StationUpdater updater;
|
||||||
private final EDSession session;
|
private final EDSession session;
|
||||||
private int errors;
|
private int errors;
|
||||||
private long interval;
|
private final Settings.EDCESettings settings;
|
||||||
|
private final BooleanProperty active;
|
||||||
private boolean forceUpdate;
|
private boolean forceUpdate;
|
||||||
|
|
||||||
public EDCE(ProfileModel profile, MarketModel world) throws IOException, ClassNotFoundException {
|
public EDCE(ProfileModel profile, MarketModel world) throws IOException, ClassNotFoundException {
|
||||||
@@ -45,7 +49,17 @@ public class EDCE {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
this.session = new EDSession();
|
this.session = new EDSession();
|
||||||
this.updater = new StationUpdater(world);
|
this.updater = new StationUpdater(world);
|
||||||
interval = 20;
|
this.settings = Main.SETTINGS.getEdce();
|
||||||
|
active = new SimpleBooleanProperty(settings.isActive());
|
||||||
|
settings.activeProperty().addListener((ov, o, n) -> {
|
||||||
|
if (n) run();
|
||||||
|
else stop();
|
||||||
|
});
|
||||||
|
if (active.get()) run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyBooleanProperty activeProperty() {
|
||||||
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForceUpdate(boolean forceUpdate) {
|
public void setForceUpdate(boolean forceUpdate) {
|
||||||
@@ -201,11 +215,13 @@ public class EDCE {
|
|||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
if (executor == null) executor = Executors.newSingleThreadScheduledExecutor();
|
if (executor == null) executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
LOG.info("Start EDCE checker each {} sec", interval);
|
LOG.info("Start EDCE checker each {} sec", settings.getInterval());
|
||||||
checker = executor.scheduleAtFixedRate(new EDCEChecker(), 1, interval, TimeUnit.SECONDS);
|
active.set(true);
|
||||||
|
checker = executor.scheduleAtFixedRate(new EDCEChecker(), 1, settings.getInterval(), TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
public void stop(){
|
public void stop(){
|
||||||
LOG.info("Stop EDCE checker");
|
LOG.info("Stop EDCE checker");
|
||||||
|
active.set(false);
|
||||||
if (checker != null){
|
if (checker != null){
|
||||||
checker.cancel(false);
|
checker.cancel(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.trader;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.controllers.MainController;
|
import ru.trader.controllers.MainController;
|
||||||
|
import ru.trader.controllers.Screeners;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -10,7 +11,9 @@ public class ServicesManager {
|
|||||||
private final static Logger LOG = LoggerFactory.getLogger(ServicesManager.class);
|
private final static Logger LOG = LoggerFactory.getLogger(ServicesManager.class);
|
||||||
private static EDCE edce;
|
private static EDCE edce;
|
||||||
|
|
||||||
|
public static EDCE getEdce() {
|
||||||
|
return edce;
|
||||||
|
}
|
||||||
|
|
||||||
public static void runAll(){
|
public static void runAll(){
|
||||||
runEDCE();
|
runEDCE();
|
||||||
@@ -25,7 +28,7 @@ public class ServicesManager {
|
|||||||
private static void runEDCE() {
|
private static void runEDCE() {
|
||||||
try {
|
try {
|
||||||
edce = new EDCE(MainController.getProfile(), MainController.getWorld());
|
edce = new EDCE(MainController.getProfile(), MainController.getWorld());
|
||||||
edce.run();
|
Screeners.getMainController().initEDCE();
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
LOG.warn("Error on init EDCE", e);
|
LOG.warn("Error on init EDCE", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package ru.trader;
|
package ru.trader;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.core.*;
|
import ru.trader.core.Market;
|
||||||
|
import ru.trader.core.MarketFilter;
|
||||||
|
import ru.trader.core.Profile;
|
||||||
|
import ru.trader.core.Ship;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -14,16 +18,19 @@ public class Settings {
|
|||||||
private final Properties values = new Properties();
|
private final Properties values = new Properties();
|
||||||
private final File file;
|
private final File file;
|
||||||
private Profile profile;
|
private Profile profile;
|
||||||
|
private final EDCESettings edce;
|
||||||
|
|
||||||
|
|
||||||
public Settings() {
|
public Settings() {
|
||||||
this.file = null;
|
this.file = null;
|
||||||
profile = new Profile(new Ship());
|
profile = new Profile(new Ship());
|
||||||
|
edce = new EDCESettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Settings(File file) {
|
public Settings(File file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
profile = new Profile(new Ship());
|
profile = new Profile(new Ship());
|
||||||
|
edce = new EDCESettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(Market market) {
|
public void load(Market market) {
|
||||||
@@ -35,11 +42,13 @@ public class Settings {
|
|||||||
LOG.error("Error on load settings", e);
|
LOG.error("Error on load settings", e);
|
||||||
}
|
}
|
||||||
profile = Profile.readFrom(values, market);
|
profile = Profile.readFrom(values, market);
|
||||||
|
edce.readFrom(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(){
|
public void save(){
|
||||||
try (OutputStream os = new FileOutputStream(file)) {
|
try (OutputStream os = new FileOutputStream(file)) {
|
||||||
profile.writeTo(values);
|
profile.writeTo(values);
|
||||||
|
edce.writeTo(values);
|
||||||
values.store(os, "settings");
|
values.store(os, "settings");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Error on load settings", e);
|
LOG.error("Error on load settings", e);
|
||||||
@@ -138,4 +147,70 @@ public class Settings {
|
|||||||
public Profile getProfile() {
|
public Profile getProfile() {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EDCESettings getEdce(){
|
||||||
|
return edce;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class EDCESettings {
|
||||||
|
private final BooleanProperty active;
|
||||||
|
private final StringProperty email;
|
||||||
|
private final IntegerProperty interval;
|
||||||
|
|
||||||
|
public EDCESettings() {
|
||||||
|
interval = new SimpleIntegerProperty();
|
||||||
|
email = new SimpleStringProperty();
|
||||||
|
active = new SimpleBooleanProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanProperty activeProperty() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active.set(active);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty emailProperty() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email.set(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInterval() {
|
||||||
|
return interval.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerProperty intervalProperty() {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInterval(int interval) {
|
||||||
|
this.interval.set(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFrom(Properties values){
|
||||||
|
setActive(!"0".equals(values.getProperty("edce.active", "0")));
|
||||||
|
setEmail(values.getProperty("edce.mail", "example@mail.com"));
|
||||||
|
setInterval(Integer.valueOf(values.getProperty("edce.interval", "20")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(Properties values){
|
||||||
|
values.setProperty("edce.active", isActive() ? "1":"0");
|
||||||
|
values.setProperty("edce.mail", getEmail());
|
||||||
|
values.setProperty("edce.interval", String.valueOf(getInterval()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javafx.scene.control.*;
|
|||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.trader.Main;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -35,6 +36,7 @@ public class LoginController {
|
|||||||
loginButton.setDisable(true);
|
loginButton.setDisable(true);
|
||||||
email.textProperty().addListener((observable, oldValue, newValue) -> {
|
email.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
loginButton.setDisable(newValue.trim().isEmpty());
|
loginButton.setDisable(newValue.trim().isEmpty());
|
||||||
|
Main.SETTINGS.getEdce().setEmail(newValue);
|
||||||
});
|
});
|
||||||
dialog.setResultConverter(dialogButton -> {
|
dialog.setResultConverter(dialogButton -> {
|
||||||
if (dialogButton == loginButtonType) {
|
if (dialogButton == loginButtonType) {
|
||||||
|
|||||||
@@ -112,6 +112,10 @@ public class MainController {
|
|||||||
routerController.init();
|
routerController.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initEDCE(){
|
||||||
|
profController.initEDCEBtn();
|
||||||
|
}
|
||||||
|
|
||||||
public void save(ActionEvent actionEvent) {
|
public void save(ActionEvent actionEvent) {
|
||||||
try {
|
try {
|
||||||
World.save();
|
World.save();
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
import ru.trader.Main;
|
||||||
|
import ru.trader.ServicesManager;
|
||||||
import ru.trader.core.Engine;
|
import ru.trader.core.Engine;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.view.support.NumberField;
|
import ru.trader.view.support.NumberField;
|
||||||
@@ -48,6 +50,8 @@ public class ProfileController {
|
|||||||
private Button btnAddSystem;
|
private Button btnAddSystem;
|
||||||
@FXML
|
@FXML
|
||||||
private Button btnAddStation;
|
private Button btnAddStation;
|
||||||
|
@FXML
|
||||||
|
private ToggleButton btnEDCE;
|
||||||
|
|
||||||
private AutoCompletion<SystemModel> system;
|
private AutoCompletion<SystemModel> system;
|
||||||
private ProfileModel profile;
|
private ProfileModel profile;
|
||||||
@@ -62,7 +66,10 @@ public class ProfileController {
|
|||||||
station.setItems(n.getStationNamesList());
|
station.setItems(n.getStationNamesList());
|
||||||
station.getSelectionModel().selectFirst();
|
station.getSelectionModel().selectFirst();
|
||||||
});
|
});
|
||||||
consumeChanges(() -> {profile.setSystem(n); profile.setStation(ModelFabric.NONE_STATION);});
|
consumeChanges(() -> {
|
||||||
|
profile.setSystem(n);
|
||||||
|
profile.setStation(ModelFabric.NONE_STATION);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
engine.setItems(FXCollections.observableList(Engine.getEngines()));
|
engine.setItems(FXCollections.observableList(Engine.getEngines()));
|
||||||
engine.setConverter(new EngineStringConverter());
|
engine.setConverter(new EngineStringConverter());
|
||||||
@@ -130,6 +137,29 @@ public class ProfileController {
|
|||||||
engine.valueProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipEngine(n)));
|
engine.valueProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipEngine(n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initEDCEBtn(){
|
||||||
|
btnEDCE.selectedProperty().bindBidirectional(Main.SETTINGS.getEdce().activeProperty());
|
||||||
|
setEDCEBtnStyles(btnEDCE.isSelected());
|
||||||
|
ServicesManager.getEdce().activeProperty().addListener((ov, o, n) -> {
|
||||||
|
setEDCEBtnStyles(n);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEDCEBtnStyles(boolean active){
|
||||||
|
final String CSS_OK_CLASS = "service-ok";
|
||||||
|
final String CSS_WARNING_CLASS = "service-warning";
|
||||||
|
if (active) {
|
||||||
|
btnEDCE.getStyleClass().remove(CSS_WARNING_CLASS);
|
||||||
|
btnEDCE.getStyleClass().add(CSS_OK_CLASS);
|
||||||
|
} else {
|
||||||
|
btnEDCE.getStyleClass().remove(CSS_OK_CLASS);
|
||||||
|
if (btnEDCE.isSelected()) {
|
||||||
|
btnEDCE.getStyleClass().add(CSS_WARNING_CLASS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setProfile(ProfileModel profile){
|
public void setProfile(ProfileModel profile){
|
||||||
if (this.profile != null){
|
if (this.profile != null){
|
||||||
unbind();
|
unbind();
|
||||||
|
|||||||
@@ -187,6 +187,8 @@ public class Screeners {
|
|||||||
return mainScreen;
|
return mainScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MainController getMainController(){return mainController;}
|
||||||
|
|
||||||
public static void changeItemDesc(ItemModel item){
|
public static void changeItemDesc(ItemModel item){
|
||||||
itemDescController.setItemDesc(item);
|
itemDescController.setItemDesc(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
<?import ru.trader.view.support.cells.OfferListCell?>
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import ru.trader.view.support.NumberField?>
|
|
||||||
<?import org.controlsfx.glyphfont.Glyph?>
|
<?import org.controlsfx.glyphfont.Glyph?>
|
||||||
|
<?import ru.trader.view.support.NumberField?>
|
||||||
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="ru.trader.controllers.ProfileController"
|
fx:controller="ru.trader.controllers.ProfileController"
|
||||||
spacing="4" >
|
spacing="4" >
|
||||||
@@ -44,4 +42,5 @@
|
|||||||
<ToggleButton minWidth="30" onAction="#toggleHelper">
|
<ToggleButton minWidth="30" onAction="#toggleHelper">
|
||||||
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
|
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
|
<ToggleButton fx:id="btnEDCE" text="EDCE"/>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user