Archived
0

save helper window position

This commit is contained in:
Mo
2015-10-22 17:49:35 +03:00
parent a9005c6539
commit 5b1fc17951
9 changed files with 119 additions and 12 deletions

View File

@@ -49,7 +49,7 @@ 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);
this.settings = Main.SETTINGS.getEdce(); this.settings = Main.SETTINGS.edce();
active = new SimpleBooleanProperty(settings.isActive()); active = new SimpleBooleanProperty(settings.isActive());
settings.activeProperty().addListener((ov, o, n) -> { settings.activeProperty().addListener((ov, o, n) -> {
if (n) run(); if (n) run();

View File

@@ -40,6 +40,9 @@ public class Main extends Application {
loadMainScene(); loadMainScene();
loadResources(); loadResources();
primaryStage.show(); primaryStage.show();
if (Main.SETTINGS.helper().isVisible()){
Screeners.showHelper();
}
ServicesManager.runAll(); ServicesManager.runAll();
} }
@@ -67,10 +70,14 @@ public class Main extends Application {
public static void changeLocale(Locale locale) throws IOException { public static void changeLocale(Locale locale) throws IOException {
Localization.setLocale(locale); Localization.setLocale(locale);
primaryStage.hide(); primaryStage.hide();
Screeners.closeAll();
MainController.getWorld().refresh(); MainController.getWorld().refresh();
loadMainScene(); loadMainScene();
loadResources(); loadResources();
primaryStage.show(); primaryStage.show();
if (Main.SETTINGS.helper().isVisible()){
Screeners.showHelper();
}
} }
private static void loadMainScene() throws IOException { private static void loadMainScene() throws IOException {

View File

@@ -19,18 +19,21 @@ public class Settings {
private final File file; private final File file;
private Profile profile; private Profile profile;
private final EDCESettings edce; private final EDCESettings edce;
private final HelperSettings helper;
public Settings() { public Settings() {
this.file = null; this.file = null;
profile = new Profile(new Ship()); profile = new Profile(new Ship());
edce = new EDCESettings(); edce = new EDCESettings();
helper = new HelperSettings();
} }
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(); edce = new EDCESettings();
helper = new HelperSettings();
} }
public void load(Market market) { public void load(Market market) {
@@ -43,12 +46,14 @@ public class Settings {
} }
profile = Profile.readFrom(values, market); profile = Profile.readFrom(values, market);
edce.readFrom(values); edce.readFrom(values);
helper.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); edce.writeTo(values);
helper.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);
@@ -148,10 +153,14 @@ public class Settings {
return profile; return profile;
} }
public EDCESettings getEdce(){ public EDCESettings edce(){
return edce; return edce;
} }
public HelperSettings helper(){
return helper;
}
public final class EDCESettings { public final class EDCESettings {
private final BooleanProperty active; private final BooleanProperty active;
private final StringProperty email; private final StringProperty email;
@@ -213,4 +222,65 @@ public class Settings {
} }
public final class HelperSettings {
private final IntegerProperty x;
private final IntegerProperty y;
private final BooleanProperty visible;
public HelperSettings() {
x = new SimpleIntegerProperty();
y = new SimpleIntegerProperty();
visible = new SimpleBooleanProperty();
}
public int getX() {
return x.get();
}
public IntegerProperty xProperty() {
return x;
}
public void setX(int x) {
this.x.set(x);
}
public int getY() {
return y.get();
}
public IntegerProperty yProperty() {
return y;
}
public void setY(int y) {
this.y.set(y);
}
public boolean isVisible() {
return visible.get();
}
public BooleanProperty visibleProperty() {
return visible;
}
public void setVisible(boolean visible) {
this.visible.set(visible);
}
public void readFrom(Properties values){
setVisible(!"0".equals(values.getProperty("helper.visible", "0")));
setX(Integer.valueOf(values.getProperty("helper.x", "100")));
setY(Integer.valueOf(values.getProperty("helper.y", "100")));
}
public void writeTo(Properties values){
values.setProperty("helper.visible", isVisible() ? "1":"0");
values.setProperty("helper.x", String.valueOf(getX()));
values.setProperty("helper.y", String.valueOf(getY()));
}
}
} }

View File

@@ -66,9 +66,6 @@ public class HelperController {
@FXML @FXML
private void initialize(){ private void initialize(){
ProfileModel profile = MainController.getProfile();
profile.routeProperty().addListener(routeListener);
profile.dockedProperty().addListener(dockedListener);
buyOrders.setCellFactory(new OrderListCell(false)); buyOrders.setCellFactory(new OrderListCell(false));
sellOrders.setCellFactory(new OrderListCell(true)); sellOrders.setCellFactory(new OrderListCell(true));
sellOffers.setCellFactory(new OfferListCell(true)); sellOffers.setCellFactory(new OfferListCell(true));
@@ -83,7 +80,6 @@ public class HelperController {
infoGroup.managedProperty().bind(infoGroup.visibleProperty()); infoGroup.managedProperty().bind(infoGroup.visibleProperty());
hideInfo(); hideInfo();
hideStationInfo(); hideStationInfo();
bindKeys();
} }
private void resize(){ private void resize(){
@@ -138,11 +134,18 @@ public class HelperController {
scene.setFill(Color.TRANSPARENT); scene.setFill(Color.TRANSPARENT);
stage.setAlwaysOnTop(true); stage.setAlwaysOnTop(true);
addDragListeners(content); addDragListeners(content);
stage.setX(Main.SETTINGS.helper().getX());
stage.setY(Main.SETTINGS.helper().getY());
bind();
Main.SETTINGS.helper().setVisible(true);
stage.show(); stage.show();
setRoute(MainController.getProfile().getRoute());
} else { } else {
if (toggle && stage.isShowing()){ if (toggle && stage.isShowing()){
Main.SETTINGS.helper().setVisible(false);
stage.hide(); stage.hide();
} else { } else {
Main.SETTINGS.helper().setVisible(true);
stage.show(); stage.show();
} }
} }
@@ -151,9 +154,28 @@ public class HelperController {
public void close(){ public void close(){
if (stage != null){ if (stage != null){
stage.close(); stage.close();
unbind();
stage = null;
} }
} }
private void bind(){
ProfileModel profile = MainController.getProfile();
profile.routeProperty().addListener(routeListener);
profile.dockedProperty().addListener(dockedListener);
Main.SETTINGS.helper().xProperty().bind(stage.xProperty());
Main.SETTINGS.helper().yProperty().bind(stage.yProperty());
bindKeys();
}
private void unbind(){
ProfileModel profile = MainController.getProfile();
profile.routeProperty().removeListener(routeListener);
profile.dockedProperty().removeListener(dockedListener);
Main.SETTINGS.helper().xProperty().unbind();
Main.SETTINGS.helper().yProperty().unbind();
}
private void setRoute(RouteModel route){ private void setRoute(RouteModel route){
if (this.route != null){ if (this.route != null){
this.route.currentEntryProperty().removeListener(currentEntryListener); this.route.currentEntryProperty().removeListener(currentEntryListener);
@@ -246,8 +268,7 @@ public class HelperController {
} }
private void bindKeys(){ private void bindKeys(){
KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD4, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::previous)); KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK), k -> ViewUtils.doFX(this::complete));
KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::next));
} }
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue())); private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));

View File

@@ -36,7 +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); Main.SETTINGS.edce().setEmail(newValue);
}); });
dialog.setResultConverter(dialogButton -> { dialog.setResultConverter(dialogButton -> {
if (dialogButton == loginButtonType) { if (dialogButton == loginButtonType) {

View File

@@ -110,6 +110,7 @@ public class MainController {
itemsController.init(); itemsController.init();
offersController.init(); offersController.init();
routerController.init(); routerController.init();
//TODO: add init all controllers
} }
public void initEDCE(){ public void initEDCE(){

View File

@@ -51,6 +51,8 @@ public class ProfileController {
@FXML @FXML
private Button btnAddStation; private Button btnAddStation;
@FXML @FXML
private ToggleButton btnHelper;
@FXML
private ToggleButton btnEDCE; private ToggleButton btnEDCE;
private AutoCompletion<SystemModel> system; private AutoCompletion<SystemModel> system;
@@ -81,6 +83,8 @@ public class ProfileController {
if (ModelFabric.isFake(profile.getStation())) Screeners.showAddStation(profile.getSystem()); if (ModelFabric.isFake(profile.getStation())) Screeners.showAddStation(profile.getSystem());
else Screeners.showEditStation(profile.getStation()); else Screeners.showEditStation(profile.getStation());
}); });
btnHelper.setOnAction(e -> toggleHelper());
btnHelper.setSelected(Main.SETTINGS.helper().isVisible());
shipInfo.setVisible(false); shipInfo.setVisible(false);
initListeners(); initListeners();
} }
@@ -138,7 +142,7 @@ public class ProfileController {
} }
public void initEDCEBtn(){ public void initEDCEBtn(){
btnEDCE.selectedProperty().bindBidirectional(Main.SETTINGS.getEdce().activeProperty()); btnEDCE.selectedProperty().bindBidirectional(Main.SETTINGS.edce().activeProperty());
setEDCEBtnStyles(btnEDCE.isSelected()); setEDCEBtnStyles(btnEDCE.isSelected());
ServicesManager.getEdce().activeProperty().addListener((ov, o, n) -> { ServicesManager.getEdce().activeProperty().addListener((ov, o, n) -> {
setEDCEBtnStyles(n); setEDCEBtnStyles(n);

View File

@@ -238,7 +238,7 @@ public class Screeners {
return showTextDialog(Localization.getString("verify.title"), return showTextDialog(Localization.getString("verify.title"),
Localization.getString("verify.header"), Localization.getString("verify.header"),
Localization.getString("verify.content") Localization.getString("verify.content")
); );
} }
public static Optional<String> showTextDialog(String title, String header, String content){ public static Optional<String> showTextDialog(String title, String header, String content){
@@ -249,6 +249,10 @@ public class Screeners {
return dialog.showAndWait(); return dialog.showAndWait();
} }
public static void showHelper(){
helperController.show(helperScreen, false);
}
public static void toggleHelper(){ public static void toggleHelper(){
helperController.show(helperScreen, true); helperController.show(helperScreen, true);
} }

View File

@@ -39,7 +39,7 @@
<ToggleButton minWidth="30" onAction="#toggleShipInfo"> <ToggleButton minWidth="30" onAction="#toggleShipInfo">
<graphic><Glyph text="FontAwesome|SPACE_SHUTTLE"/></graphic> <graphic><Glyph text="FontAwesome|SPACE_SHUTTLE"/></graphic>
</ToggleButton> </ToggleButton>
<ToggleButton minWidth="30" onAction="#toggleHelper"> <ToggleButton fx:id="btnHelper" minWidth="30">
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic> <graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
</ToggleButton> </ToggleButton>
<ToggleButton fx:id="btnEDCE" text="EDCE"/> <ToggleButton fx:id="btnEDCE" text="EDCE"/>