diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java index 9daec36f..95a42dde 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java @@ -20,16 +20,16 @@ public HotKeysConfigurationService(ProfileDescriptor selectedProfile) { @Override public Map getDefault() { Map keyMap = new HashMap<>(); - keyMap.put(HotKeyType.INVITE_PLAYER.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_1,'1',true,false,false,false)); - keyMap.put(HotKeyType.TRADE_PLAYER.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_2,'2',true,false,false,false)); - keyMap.put(HotKeyType.KICK_PLAYER.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_3,'3',true,false,false,false)); - keyMap.put(HotKeyType.STILL_INTERESTING.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_4,'4',true,false,false,false)); - keyMap.put(HotKeyType.CLOSE_NOTIFICATION.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_5,'5',true,false,false,false)); - keyMap.put(HotKeyType.EXPAND_ALL.name(),new HotKeyDescriptor(GlobalKeyEvent.VK_1,'1',false,false,true,false)); - keyMap.put("button_1",new HotKeyDescriptor(GlobalKeyEvent.VK_1,'1',false,true,false,false)); - keyMap.put("button_2",new HotKeyDescriptor(GlobalKeyEvent.VK_1,'2',false,true,false,false)); - keyMap.put("button_3",new HotKeyDescriptor(GlobalKeyEvent.VK_1,'3',false,true,false,false)); - keyMap.put("button_4",new HotKeyDescriptor(GlobalKeyEvent.VK_1,'4',false,true,false,false)); + keyMap.put(HotKeyType.INVITE_PLAYER.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'1',true,false,false,false)); + keyMap.put(HotKeyType.TRADE_PLAYER.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_2,'2',true,false,false,false)); + keyMap.put(HotKeyType.KICK_PLAYER.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_3,'3',true,false,false,false)); + keyMap.put(HotKeyType.STILL_INTERESTING.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_4,'4',true,false,false,false)); + keyMap.put(HotKeyType.CLOSE_NOTIFICATION.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_5,'5',true,false,false,false)); + keyMap.put(HotKeyType.EXPAND_ALL.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'1',false,false,true,false)); + keyMap.put("button_1",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'1',false,true,false,false)); + keyMap.put("button_2",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'2',false,true,false,false)); + keyMap.put("button_3",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'3',false,true,false,false)); + keyMap.put("button_4",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'4',false,true,false,false)); return keyMap; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java index 303ca052..477dadb0 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java @@ -10,6 +10,7 @@ @AllArgsConstructor @NoArgsConstructor public class HotKeyDescriptor implements Serializable{ + private String title = ""; private int virtualKeyCode; private char keyChar; private boolean menuPressed; diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeyAdapter.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeyAdapter.java index 4db9a435..98e7f827 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeyAdapter.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeyAdapter.java @@ -1,24 +1,14 @@ package com.mercury.platform.shared.hotkey; import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; import lc.kra.system.keyboard.event.GlobalKeyAdapter; import lc.kra.system.keyboard.event.GlobalKeyEvent; public class HotKeyAdapter extends GlobalKeyAdapter { - private HotKeyDescriptor currentKey; - public void keyTyped(HotKeyDescriptor descriptor) { - } - @Override public void keyPressed(GlobalKeyEvent event) { - this.currentKey = this.convert(event); - } - - @Override - public void keyReleased(GlobalKeyEvent event) { - if(this.currentKey != null && this.currentKey.equals(this.convert(event))) { - this.keyTyped(this.currentKey); - } + MercuryStoreCore.hotKeySubject.onNext(this.convert(event)); } private HotKeyDescriptor convert(GlobalKeyEvent event) { diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java index 02060705..2f48f2dd 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java @@ -4,15 +4,46 @@ import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import lc.kra.system.keyboard.GlobalKeyboardHook; +import lc.kra.system.mouse.GlobalMouseHook; +import lc.kra.system.mouse.event.GlobalMouseAdapter; +import lc.kra.system.mouse.event.GlobalMouseEvent; public class HotKeysInterceptor { public HotKeysInterceptor() { GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(false); - keyboardHook.addKeyListener(new HotKeyAdapter() { + keyboardHook.addKeyListener(new HotKeyAdapter()); + + GlobalMouseHook mouseHook = new GlobalMouseHook(false); + mouseHook.addMouseListener(new GlobalMouseAdapter() { @Override - public void keyTyped(HotKeyDescriptor descriptor) { - MercuryStoreCore.hotKeySubject.onNext(descriptor); + public void mousePressed(GlobalMouseEvent globalMouseEvent) { + MercuryStoreCore.hotKeySubject.onNext(this.convert(globalMouseEvent)); + } + private HotKeyDescriptor convert(GlobalMouseEvent event) { + HotKeyDescriptor descriptor = new HotKeyDescriptor(); + switch (event.getButton()){ + case 1: { + descriptor.setVirtualKeyCode(1000); + descriptor.setTitle("Mouse left"); + break; + } + case 2: { + descriptor.setVirtualKeyCode(1002); + descriptor.setTitle("Mouse right"); + break; + } + case 16: { + descriptor.setVirtualKeyCode(1016); + descriptor.setTitle("Mouse middle"); + break; + } + } + return descriptor; } }); } + + public static void main(String[] args) { + new HotKeysInterceptor(); + } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java index 616d3331..17c8ed43 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java @@ -121,32 +121,38 @@ public JPanel getLocationPanel(AdrComponentDescriptor descriptor, boolean fromGr return root; } - public JButton getHotKeyButton(AdrComponentDescriptor descriptor){ + public JButton getHotKeyButton(AdrComponentDescriptor descriptor) { JButton button = this.componentsFactory.getBorderedButton(this.getButtonText(descriptor.getHotKeyDescriptor())); - button.setFont(this.componentsFactory.getFont(FontStyle.BOLD,18f)); - button.addMouseListener(new MouseAdapter() { + button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 18f)); + MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - button.setBackground(AppThemeColor.SLIDE_BG); - button.setText("Press any key"); - allowed = true; + if(SwingUtilities.isLeftMouseButton(e)) { + button.setBackground(AppThemeColor.SLIDE_BG); + button.setText("Press any key"); + allowed = true; + } } - }); + }; + button.addMouseListener(mouseAdapter); MercuryStoreCore.hotKeySubject.subscribe(hotKey -> { - if(allowed) { + if (allowed) { + button.removeMouseListener(mouseAdapter); button.setBackground(AppThemeColor.BUTTON); - if(hotKey.getVirtualKeyCode() == 27){ + if (hotKey.getVirtualKeyCode() == 27) { descriptor.setHotKeyDescriptor(new HotKeyDescriptor()); - }else { + } else { descriptor.setHotKeyDescriptor(hotKey); } - button.setText(getButtonText( descriptor.getHotKeyDescriptor())); + button.setText(getButtonText(descriptor.getHotKeyDescriptor())); allowed = false; MercuryStoreUI.adrReloadSubject.onNext(descriptor); + button.addMouseListener(mouseAdapter); } }); return button; } + public JPanel getHotKeyPanel(AdrComponentDescriptor descriptor){ JButton hotKeyButton = this.getHotKeyButton(descriptor); JPanel hotKeyPanel = this.componentsFactory.getJPanel(new BorderLayout()); @@ -820,6 +826,9 @@ private JColorChooser getColorChooser(){ return colorChooser; } private String getButtonText(HotKeyDescriptor descriptor){ + if(!descriptor.getTitle().equals("")){ + return descriptor.getTitle(); + } if(descriptor.getKeyChar() == '\u0000') { return "..."; } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/ItemsGridFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/ItemsGridFrame.java index 3bf6adb8..21ea9698 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/ItemsGridFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/ItemsGridFrame.java @@ -125,7 +125,7 @@ protected JPanel getPanelForPINSettings() { }); tabType.setPreferredSize(new Dimension((int)(componentsFactory.getScale() * 70),tabType.getHeight())); - labelPanel.add(tabType,BorderLayout.LINE_START); + labelPanel.add(this.componentsFactory.wrapToSlide(tabType,AppThemeColor.FRAME),BorderLayout.LINE_START); Color titleColor = this.applicationConfig.get().isItemsGridEnable()?AppThemeColor.TEXT_NICKNAME:AppThemeColor.TEXT_DISABLE; JLabel titleLabel = componentsFactory.getTextLabel(FontStyle.BOLD, titleColor, TextAlignment.LEFTOP, 20f, "Align this grid(approximately)"); labelPanel.add(titleLabel,BorderLayout.CENTER);