Archived
0

- add edce settings

- add edce activate button
This commit is contained in:
Mo
2015-10-21 20:02:57 +03:00
parent 7a5a6d4a1c
commit 6e66aefa93
8 changed files with 150 additions and 19 deletions

View File

@@ -1,6 +1,9 @@
package ru.trader;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +40,8 @@ public class EDCE {
private final StationUpdater updater;
private final EDSession session;
private int errors;
private long interval;
private final Settings.EDCESettings settings;
private final BooleanProperty active;
private boolean forceUpdate;
public EDCE(ProfileModel profile, MarketModel world) throws IOException, ClassNotFoundException {
@@ -45,7 +49,17 @@ public class EDCE {
this.world = world;
this.session = new EDSession();
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) {
@@ -201,11 +215,13 @@ public class EDCE {
public void run(){
if (executor == null) executor = Executors.newSingleThreadScheduledExecutor();
LOG.info("Start EDCE checker each {} sec", interval);
checker = executor.scheduleAtFixedRate(new EDCEChecker(), 1, interval, TimeUnit.SECONDS);
LOG.info("Start EDCE checker each {} sec", settings.getInterval());
active.set(true);
checker = executor.scheduleAtFixedRate(new EDCEChecker(), 1, settings.getInterval(), TimeUnit.SECONDS);
}
public void stop(){
LOG.info("Stop EDCE checker");
active.set(false);
if (checker != null){
checker.cancel(false);
}

View File

@@ -3,6 +3,7 @@ package ru.trader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.controllers.MainController;
import ru.trader.controllers.Screeners;
import java.io.IOException;
@@ -10,7 +11,9 @@ public class ServicesManager {
private final static Logger LOG = LoggerFactory.getLogger(ServicesManager.class);
private static EDCE edce;
public static EDCE getEdce() {
return edce;
}
public static void runAll(){
runEDCE();
@@ -25,7 +28,7 @@ public class ServicesManager {
private static void runEDCE() {
try {
edce = new EDCE(MainController.getProfile(), MainController.getWorld());
edce.run();
Screeners.getMainController().initEDCE();
} catch (IOException | ClassNotFoundException e) {
LOG.warn("Error on init EDCE", e);
}

View File

@@ -1,8 +1,12 @@
package ru.trader;
import javafx.beans.property.*;
import org.slf4j.Logger;
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.util.Locale;
@@ -14,16 +18,19 @@ public class Settings {
private final Properties values = new Properties();
private final File file;
private Profile profile;
private final EDCESettings edce;
public Settings() {
this.file = null;
profile = new Profile(new Ship());
edce = new EDCESettings();
}
public Settings(File file) {
this.file = file;
profile = new Profile(new Ship());
edce = new EDCESettings();
}
public void load(Market market) {
@@ -35,12 +42,14 @@ public class Settings {
LOG.error("Error on load settings", e);
}
profile = Profile.readFrom(values, market);
edce.readFrom(values);
}
public void save(){
try (OutputStream os = new FileOutputStream(file)) {
profile.writeTo(values);
values.store(os,"settings");
edce.writeTo(values);
values.store(os, "settings");
} catch (IOException e) {
LOG.error("Error on load settings", e);
}
@@ -84,7 +93,7 @@ public class Settings {
}
public long getEMDNAutoUpdate(){
return Long.valueOf(values.getProperty("emdn.auto","0"));
return Long.valueOf(values.getProperty("emdn.auto", "0"));
}
public void setBalance(double balance){
@@ -138,4 +147,70 @@ public class Settings {
public Profile getProfile() {
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()));
}
}
}

View File

@@ -8,6 +8,7 @@ import javafx.scene.control.*;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.Main;
import ru.trader.view.support.Localization;
import java.util.Optional;
@@ -35,6 +36,7 @@ public class LoginController {
loginButton.setDisable(true);
email.textProperty().addListener((observable, oldValue, newValue) -> {
loginButton.setDisable(newValue.trim().isEmpty());
Main.SETTINGS.getEdce().setEmail(newValue);
});
dialog.setResultConverter(dialogButton -> {
if (dialogButton == loginButtonType) {

View File

@@ -112,6 +112,10 @@ public class MainController {
routerController.init();
}
public void initEDCE(){
profController.initEDCEBtn();
}
public void save(ActionEvent actionEvent) {
try {
World.save();

View File

@@ -8,6 +8,8 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.Pane;
import javafx.util.StringConverter;
import ru.trader.Main;
import ru.trader.ServicesManager;
import ru.trader.core.Engine;
import ru.trader.model.*;
import ru.trader.view.support.NumberField;
@@ -48,6 +50,8 @@ public class ProfileController {
private Button btnAddSystem;
@FXML
private Button btnAddStation;
@FXML
private ToggleButton btnEDCE;
private AutoCompletion<SystemModel> system;
private ProfileModel profile;
@@ -57,12 +61,15 @@ public class ProfileController {
private void initialize() {
init();
profile = MainController.getProfile();
system.valueProperty().addListener((ov, o , n) -> {
system.valueProperty().addListener((ov, o, n) -> {
doAndConsumeChanges(() -> {
station.setItems(n.getStationNamesList());
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.setConverter(new EngineStringConverter());
@@ -130,6 +137,29 @@ public class ProfileController {
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){
if (this.profile != null){
unbind();

View File

@@ -63,7 +63,7 @@ public class Screeners {
return mainScreen;
}
private static void addStylesheet(Parent screen){
private static void addStylesheet(Parent screen) {
screen.getStylesheets().addAll(mainScreen.getStylesheets());
}
@@ -187,6 +187,8 @@ public class Screeners {
return mainScreen;
}
public static MainController getMainController(){return mainController;}
public static void changeItemDesc(ItemModel item){
itemDescController.setItemDesc(item);
}

View File

@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import ru.trader.view.support.cells.OfferListCell?>
<?import javafx.geometry.Insets?>
<?import ru.trader.view.support.NumberField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?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"
fx:controller="ru.trader.controllers.ProfileController"
spacing="4" >
@@ -44,4 +42,5 @@
<ToggleButton minWidth="30" onAction="#toggleHelper">
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
</ToggleButton>
<ToggleButton fx:id="btnEDCE" text="EDCE"/>
</HBox>