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
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
super.stop();
|
super.stop();
|
||||||
|
KeyBinding.unbind();
|
||||||
|
ServicesManager.stopAll();
|
||||||
|
SETTINGS.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -77,10 +80,11 @@ public class Main extends Application {
|
|||||||
if (World.getMarket().isChange()) {
|
if (World.getMarket().isChange()) {
|
||||||
Action res = Screeners.showConfirm(Localization.getString("dialog.confirm.save"));
|
Action res = Screeners.showConfirm(Localization.getString("dialog.confirm.save"));
|
||||||
if (res == Dialog.ACTION_YES) World.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();
|
Screeners.closeAll();
|
||||||
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
|
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
|
||||||
LOG.error("Error on save world", 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.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import ru.trader.KeyBinding;
|
||||||
import ru.trader.model.OrderModel;
|
import ru.trader.model.OrderModel;
|
||||||
import ru.trader.model.RouteEntryModel;
|
import ru.trader.model.RouteEntryModel;
|
||||||
import ru.trader.model.RouteModel;
|
import ru.trader.model.RouteModel;
|
||||||
import ru.trader.view.support.ViewUtils;
|
import ru.trader.view.support.ViewUtils;
|
||||||
import ru.trader.view.support.cells.OrderListCell;
|
import ru.trader.view.support.cells.OrderListCell;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
|
||||||
public class HelperController {
|
public class HelperController {
|
||||||
|
|
||||||
@@ -30,7 +37,7 @@ public class HelperController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ListView<OrderModel> sellOrders;
|
private ListView<OrderModel> sellOrders;
|
||||||
|
|
||||||
|
private Stage stage;
|
||||||
private RouteModel route;
|
private RouteModel route;
|
||||||
private final BooleanProperty docked;
|
private final BooleanProperty docked;
|
||||||
private final IntegerProperty currentEntry;
|
private final IntegerProperty currentEntry;
|
||||||
@@ -45,11 +52,25 @@ public class HelperController {
|
|||||||
currentEntry.addListener(routeEntryListener);
|
currentEntry.addListener(routeEntryListener);
|
||||||
buyOrders.setCellFactory(new OrderListCell(false));
|
buyOrders.setCellFactory(new OrderListCell(false));
|
||||||
sellOrders.setCellFactory(new OrderListCell(true));
|
sellOrders.setCellFactory(new OrderListCell(true));
|
||||||
|
bindKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoute(RouteModel route) {
|
public void show(Parent content, RouteModel route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
currentEntry.setValue(0);
|
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){
|
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 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() {
|
public static void closeAll() {
|
||||||
itemDescController.close();
|
itemDescController.close();
|
||||||
|
helperController.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<OrderModel> showOrders(ObservableList<OrderModel> orders) {
|
public static Optional<OrderModel> showOrders(ObservableList<OrderModel> orders) {
|
||||||
@@ -247,14 +248,7 @@ public class Screeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showHelper(RouteModel route){
|
public static void showHelper(RouteModel route){
|
||||||
helperController.setRoute(route);
|
helperController.show(helperScreen, route);
|
||||||
if (helperScreen.getScene() == null){
|
|
||||||
Stage stage = new Stage();
|
|
||||||
stage.setScene(new Scene(helperScreen));
|
|
||||||
stage.show();
|
|
||||||
} else {
|
|
||||||
((Stage)helperScreen.getScene().getWindow()).show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reinitAll() {
|
public static void reinitAll() {
|
||||||
|
|||||||
5
pom.xml
5
pom.xml
@@ -95,6 +95,11 @@
|
|||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tulskiy</groupId>
|
||||||
|
<artifactId>jkeymaster</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,10 @@
|
|||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tulskiy</groupId>
|
||||||
|
<artifactId>jkeymaster</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user