add global key binding
This commit is contained in:
21
client/src/main/java/ru/trader/KeyBinding.java
Normal file
21
client/src/main/java/ru/trader/KeyBinding.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package ru.trader;
|
||||
|
||||
import com.tulskiy.keymaster.common.HotKeyListener;
|
||||
import com.tulskiy.keymaster.common.Provider;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class KeyBinding {
|
||||
private final static Provider provider = Provider.getCurrentProvider(false);
|
||||
|
||||
public static void bind(KeyStroke keys, HotKeyListener listener){
|
||||
provider.register(keys, listener);
|
||||
}
|
||||
|
||||
public static void unbind(){
|
||||
provider.reset();
|
||||
provider.stop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -45,6 +45,9 @@ public class Main extends Application {
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
super.stop();
|
||||
KeyBinding.unbind();
|
||||
ServicesManager.stopAll();
|
||||
SETTINGS.save();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -77,10 +80,11 @@ public class Main extends Application {
|
||||
if (World.getMarket().isChange()) {
|
||||
Action res = Screeners.showConfirm(Localization.getString("dialog.confirm.save"));
|
||||
if (res == Dialog.ACTION_YES) World.save();
|
||||
else if (res == Dialog.ACTION_CANCEL) we.consume();
|
||||
else if (res == Dialog.ACTION_CANCEL) {
|
||||
we.consume();
|
||||
return;
|
||||
}
|
||||
}
|
||||
ServicesManager.stopAll();
|
||||
SETTINGS.save();
|
||||
Screeners.closeAll();
|
||||
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
|
||||
LOG.error("Error on save world", e);
|
||||
|
||||
@@ -6,14 +6,21 @@ import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.stage.Stage;
|
||||
import ru.trader.KeyBinding;
|
||||
import ru.trader.model.OrderModel;
|
||||
import ru.trader.model.RouteEntryModel;
|
||||
import ru.trader.model.RouteModel;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
import ru.trader.view.support.cells.OrderListCell;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
public class HelperController {
|
||||
|
||||
@@ -30,7 +37,7 @@ public class HelperController {
|
||||
@FXML
|
||||
private ListView<OrderModel> sellOrders;
|
||||
|
||||
|
||||
private Stage stage;
|
||||
private RouteModel route;
|
||||
private final BooleanProperty docked;
|
||||
private final IntegerProperty currentEntry;
|
||||
@@ -45,11 +52,25 @@ public class HelperController {
|
||||
currentEntry.addListener(routeEntryListener);
|
||||
buyOrders.setCellFactory(new OrderListCell(false));
|
||||
sellOrders.setCellFactory(new OrderListCell(true));
|
||||
bindKeys();
|
||||
}
|
||||
|
||||
public void setRoute(RouteModel route) {
|
||||
public void show(Parent content, RouteModel route) {
|
||||
this.route = route;
|
||||
currentEntry.setValue(0);
|
||||
if (stage == null){
|
||||
stage = new Stage();
|
||||
stage.setScene(new Scene(content));
|
||||
stage.show();
|
||||
} else {
|
||||
stage.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void close(){
|
||||
if (stage != null){
|
||||
stage.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void setRouteEntry(int index){
|
||||
@@ -84,4 +105,9 @@ public class HelperController {
|
||||
}
|
||||
|
||||
private final ChangeListener<Number> routeEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
||||
|
||||
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_NUMPAD6, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::next));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ public class Screeners {
|
||||
|
||||
public static void closeAll() {
|
||||
itemDescController.close();
|
||||
helperController.close();
|
||||
}
|
||||
|
||||
public static Optional<OrderModel> showOrders(ObservableList<OrderModel> orders) {
|
||||
@@ -247,14 +248,7 @@ public class Screeners {
|
||||
}
|
||||
|
||||
public static void showHelper(RouteModel route){
|
||||
helperController.setRoute(route);
|
||||
if (helperScreen.getScene() == null){
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(helperScreen));
|
||||
stage.show();
|
||||
} else {
|
||||
((Stage)helperScreen.getScene().getWindow()).show();
|
||||
}
|
||||
helperController.show(helperScreen, route);
|
||||
}
|
||||
|
||||
public static void reinitAll() {
|
||||
|
||||
Reference in New Issue
Block a user