add complete hotkey to settings
This commit is contained in:
@@ -4,17 +4,30 @@ import com.tulskiy.keymaster.common.HotKeyListener;
|
||||
import com.tulskiy.keymaster.common.Provider;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KeyBinding {
|
||||
private final static Provider provider = Provider.getCurrentProvider(false);
|
||||
private final static Map<KeyStroke, HotKeyListener> hotKeys = new HashMap<>(10, 0.9f);
|
||||
|
||||
public static void bind(KeyStroke keys, HotKeyListener listener){
|
||||
if (keys == null) return;
|
||||
provider.register(keys, listener);
|
||||
hotKeys.put(keys, listener);
|
||||
}
|
||||
|
||||
public static void unbind(KeyStroke hotKey){
|
||||
if (hotKey == null) return;
|
||||
provider.reset();
|
||||
hotKeys.remove(hotKey);
|
||||
hotKeys.forEach(provider::register);
|
||||
}
|
||||
|
||||
public static void unbind(){
|
||||
provider.reset();
|
||||
provider.stop();
|
||||
hotKeys.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import ru.trader.core.MarketFilter;
|
||||
import ru.trader.core.Profile;
|
||||
import ru.trader.core.Ship;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
@@ -227,11 +228,13 @@ public class Settings {
|
||||
private final IntegerProperty x;
|
||||
private final IntegerProperty y;
|
||||
private final BooleanProperty visible;
|
||||
private final ObjectProperty<KeyStroke> completeKey;
|
||||
|
||||
public HelperSettings() {
|
||||
x = new SimpleIntegerProperty();
|
||||
y = new SimpleIntegerProperty();
|
||||
visible = new SimpleBooleanProperty();
|
||||
completeKey = new SimpleObjectProperty<>();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
@@ -270,16 +273,30 @@ public class Settings {
|
||||
this.visible.set(visible);
|
||||
}
|
||||
|
||||
public KeyStroke getCompleteKey() {
|
||||
return completeKey.get();
|
||||
}
|
||||
|
||||
public ObjectProperty<KeyStroke> completeKeyProperty() {
|
||||
return completeKey;
|
||||
}
|
||||
|
||||
public void setCompleteKey(KeyStroke completeKey) {
|
||||
this.completeKey.set(completeKey);
|
||||
}
|
||||
|
||||
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")));
|
||||
setCompleteKey(KeyStroke.getKeyStroke(values.getProperty("helper.keys.complete", "pressed END")));
|
||||
}
|
||||
|
||||
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()));
|
||||
values.setProperty("helper.keys.complete", String.valueOf(getCompleteKey()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import ru.trader.view.support.cells.OrderListCell;
|
||||
import ru.trader.view.support.cells.StationListCell;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
public class HelperController {
|
||||
@@ -167,17 +166,20 @@ public class HelperController {
|
||||
ProfileModel profile = MainController.getProfile();
|
||||
profile.routeProperty().addListener(routeListener);
|
||||
profile.dockedProperty().addListener(dockedListener);
|
||||
Main.SETTINGS.helper().completeKeyProperty().addListener(completeKeyListener);
|
||||
Main.SETTINGS.helper().xProperty().bind(stage.xProperty());
|
||||
Main.SETTINGS.helper().yProperty().bind(stage.yProperty());
|
||||
bindKeys();
|
||||
bindKeys(Main.SETTINGS.helper().getCompleteKey());
|
||||
}
|
||||
|
||||
private void unbind(){
|
||||
ProfileModel profile = MainController.getProfile();
|
||||
profile.routeProperty().removeListener(routeListener);
|
||||
profile.dockedProperty().removeListener(dockedListener);
|
||||
Main.SETTINGS.helper().completeKeyProperty().removeListener(completeKeyListener);
|
||||
Main.SETTINGS.helper().xProperty().unbind();
|
||||
Main.SETTINGS.helper().yProperty().unbind();
|
||||
KeyBinding.unbind(Main.SETTINGS.helper().getCompleteKey());
|
||||
}
|
||||
|
||||
private void setRoute(RouteModel route){
|
||||
@@ -267,13 +269,21 @@ public class HelperController {
|
||||
Main.copyToClipboard(system.getText());
|
||||
}
|
||||
|
||||
private void bindKeys(){
|
||||
KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), k -> ViewUtils.doFX(this::complete));
|
||||
private void bindKeys(KeyStroke completeKey){
|
||||
KeyBinding.bind(completeKey, k -> ViewUtils.doFX(this::complete));
|
||||
}
|
||||
|
||||
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
||||
private final ChangeListener<Boolean> dockedListener = (ov, o, n) -> ViewUtils.doFX(() -> setDocked(n));
|
||||
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> ViewUtils.doFX(() -> setRoute(n));
|
||||
private final ChangeListener<KeyStroke> completeKeyListener = (ov, o, n) -> {
|
||||
if (o != null){
|
||||
KeyBinding.unbind(o);
|
||||
}
|
||||
if (n != null){
|
||||
bindKeys(n);
|
||||
}
|
||||
};
|
||||
|
||||
private void addDragListeners(final Node node){
|
||||
new DragListener(node);
|
||||
|
||||
@@ -4,13 +4,18 @@ import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.Main;
|
||||
import ru.trader.core.Profile;
|
||||
import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.NumberField;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
public class SettingsController {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(SettingsController.class);
|
||||
@@ -48,11 +53,31 @@ public class SettingsController {
|
||||
@FXML
|
||||
private NumberField edceInterval;
|
||||
|
||||
@FXML
|
||||
private TextField completeKeyText;
|
||||
private KeyStroke completeKey;
|
||||
|
||||
private Dialog<ButtonType> dlg;
|
||||
|
||||
@FXML
|
||||
private void initialize(){
|
||||
pathPriority.setItems(FXCollections.observableArrayList(Profile.PATH_PRIORITY.values()));
|
||||
completeKeyText.setOnKeyReleased(KeyEvent::consume);
|
||||
completeKeyText.setOnKeyTyped(KeyEvent::consume);
|
||||
completeKeyText.setOnKeyPressed(e -> {
|
||||
if (e.getCode().equals(KeyCode.ESCAPE)) {
|
||||
completeKey = null;
|
||||
completeKeyText.setText("");
|
||||
} else {
|
||||
int modifiers = 0;
|
||||
if (e.isAltDown()) modifiers |= InputEvent.ALT_DOWN_MASK;
|
||||
if (e.isShiftDown()) modifiers |= InputEvent.SHIFT_DOWN_MASK;
|
||||
if (e.isControlDown()) modifiers |= InputEvent.CTRL_DOWN_MASK;
|
||||
completeKey = KeyStroke.getKeyStroke(e.getCode().impl_getCode(), modifiers);
|
||||
completeKeyText.setText(ViewUtils.keyToString(completeKey));
|
||||
}
|
||||
e.consume();
|
||||
});
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -77,6 +102,8 @@ public class SettingsController {
|
||||
|
||||
edceActive.setSelected(Main.SETTINGS.edce().isActive());
|
||||
edceInterval.setValue(Main.SETTINGS.edce().getInterval());
|
||||
|
||||
completeKeyText.setText(ViewUtils.keyToString(Main.SETTINGS.helper().getCompleteKey()));
|
||||
}
|
||||
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
@@ -120,6 +147,8 @@ public class SettingsController {
|
||||
|
||||
Main.SETTINGS.edce().setActive(edceActive.isSelected());
|
||||
Main.SETTINGS.edce().setInterval(edceInterval.getValue().intValue());
|
||||
|
||||
Main.SETTINGS.helper().setCompleteKey(completeKey);
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content){
|
||||
|
||||
@@ -10,6 +10,10 @@ import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TablePosition;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class ViewUtils {
|
||||
|
||||
//Scroll to row if invisible
|
||||
@@ -69,4 +73,28 @@ public class ViewUtils {
|
||||
public static String stationDistanceToString(double distance){
|
||||
return String.format("%.2f Ls", distance);
|
||||
}
|
||||
|
||||
public static String keyToString(KeyStroke key){
|
||||
if (key == null) return "";
|
||||
if (key.getKeyCode() == KeyEvent.VK_SHIFT
|
||||
|| key.getKeyCode() == KeyEvent.VK_CONTROL
|
||||
|| key.getKeyCode() == KeyEvent.VK_ALT
|
||||
|| key.getKeyCode() == KeyEvent.VK_ALT_GRAPH){
|
||||
return KeyEvent.getKeyText(key.getKeyCode());
|
||||
}
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int modifiers = key.getModifiers();
|
||||
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0 ) {
|
||||
buf.append("SHIFT+");
|
||||
}
|
||||
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0 ) {
|
||||
buf.append("CTRL+");
|
||||
}
|
||||
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0 ) {
|
||||
buf.append("ALT+");
|
||||
}
|
||||
buf.append(KeyEvent.getKeyText(key.getKeyCode()));
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
<NumberField fx:id="takeoffTime" maxWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="12" />
|
||||
<Label text="Время перезарядки FSD:" GridPane.rowIndex="13" />
|
||||
<NumberField fx:id="rechargeTime" maxWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="13" />
|
||||
<Label text="Горячие клавиши" styleClass="settings-group" GridPane.halignment="CENTER" GridPane.columnSpan="2" GridPane.rowIndex="14"/>
|
||||
<Label text="Точка маршрута достигнута:" GridPane.rowIndex="15" />
|
||||
<TextField fx:id="completeKeyText" maxWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="15" />
|
||||
|
||||
</GridPane>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user