diff --git a/app-core/pom.xml b/app-core/pom.xml
index 7ec54ce4..d1cafeae 100644
--- a/app-core/pom.xml
+++ b/app-core/pom.xml
@@ -19,6 +19,11 @@
app-shared
1.0.0.5
+
+ com.1stleg
+ jnativehook
+ 2.0.2
+
lc.kra.system
system-hook
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 95a42dde..6389f0d2 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));
+ keyMap.put(HotKeyType.TRADE_PLAYER.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_2,'2',true,false,false));
+ keyMap.put(HotKeyType.KICK_PLAYER.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_3,'3',true,false,false));
+ keyMap.put(HotKeyType.STILL_INTERESTING.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_4,'4',true,false,false));
+ keyMap.put(HotKeyType.CLOSE_NOTIFICATION.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_5,'5',true,false,false));
+ keyMap.put(HotKeyType.EXPAND_ALL.name(),new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'1',false,false,true));
+ keyMap.put("button_1",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'1',false,true,false));
+ keyMap.put("button_2",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'2',false,true,false));
+ keyMap.put("button_3",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'3',false,true,false));
+ keyMap.put("button_4",new HotKeyDescriptor("",GlobalKeyEvent.VK_1,'4',false,true,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 477dadb0..69d6dd8c 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,11 +10,10 @@
@AllArgsConstructor
@NoArgsConstructor
public class HotKeyDescriptor implements Serializable{
- private String title = "";
+ private String title = "...";
private int virtualKeyCode;
private char keyChar;
private boolean menuPressed;
private boolean shiftPressed;
private boolean controlPressed;
- private boolean extendedKey;
}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java
index ee0274f7..42104258 100644
--- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java
+++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java
@@ -9,7 +9,7 @@
@EqualsAndHashCode(callSuper = true)
@Data
public class AdrCaptureDescriptor extends AdrColoredComponentDescriptor implements Serializable {
- private int fps = 1;
+ private int fps = 5;
private Dimension captureSize = new Dimension(64,64);
private Point captureLocation;
}
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 98e7f827..f13fb8d1 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
@@ -16,7 +16,6 @@ private HotKeyDescriptor convert(GlobalKeyEvent event) {
descriptor.setKeyChar(event.getKeyChar());
descriptor.setVirtualKeyCode(event.getVirtualKeyCode());
descriptor.setControlPressed(event.isControlPressed());
- descriptor.setExtendedKey(event.isExtendedKey());
descriptor.setMenuPressed(event.isMenuPressed());
descriptor.setShiftPressed(event.isShiftPressed());
return descriptor;
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 2f48f2dd..28d384d6 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
@@ -1,49 +1,37 @@
package com.mercury.platform.shared.hotkey;
+import org.jnativehook.GlobalScreen;
+import org.jnativehook.NativeHookException;
-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;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class HotKeysInterceptor {
public HotKeysInterceptor() {
- GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(false);
- keyboardHook.addKeyListener(new HotKeyAdapter());
+ Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
+ logger.setLevel(Level.OFF);
- GlobalMouseHook mouseHook = new GlobalMouseHook(false);
- mouseHook.addMouseListener(new GlobalMouseAdapter() {
- @Override
- 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;
- }
- });
+ logger.setUseParentHandlers(false);
+ try {
+ GlobalScreen.registerNativeHook();
+ } catch (NativeHookException e) {
+ e.printStackTrace();
+ }
+ GlobalScreen.addNativeKeyListener(new MercuryNativeKeyListener());
+ GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener());
}
public static void main(String[] args) {
- new HotKeysInterceptor();
+// new HotKeysInterceptor();
+ Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
+ logger.setLevel(Level.OFF);
+
+ logger.setUseParentHandlers(false);
+ try {
+ GlobalScreen.registerNativeHook();
+ } catch (NativeHookException e) {
+ e.printStackTrace();
+ }
+ GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener());
}
}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java
new file mode 100644
index 00000000..51090bcc
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java
@@ -0,0 +1,74 @@
+package com.mercury.platform.shared.hotkey;
+
+
+import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor;
+import com.mercury.platform.shared.store.MercuryStoreCore;
+import org.jnativehook.keyboard.NativeKeyEvent;
+import org.jnativehook.keyboard.NativeKeyListener;
+
+public class MercuryNativeKeyListener implements NativeKeyListener{
+ private boolean menuPressed;
+ private boolean shiftPressed;
+ private boolean ctrlpressed;
+ @Override
+ public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {
+ switch (nativeKeyEvent.getKeyCode()){
+ case 42 : {
+ this.shiftPressed = true;
+ break;
+ }
+ case 29: {
+ this.ctrlpressed = true;
+ break;
+ }
+ case 56: {
+ this.menuPressed = true;
+ break;
+ }
+ default:{
+ HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor();
+ hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode()));
+ hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode());
+ hotKeyDescriptor.setControlPressed(this.ctrlpressed);
+ hotKeyDescriptor.setShiftPressed(this.shiftPressed);
+ hotKeyDescriptor.setMenuPressed(this.menuPressed);
+
+ hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor));
+ MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor);
+ }
+ }
+ }
+
+ @Override
+ public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {
+ switch (nativeKeyEvent.getKeyCode()){
+ case 42 : {
+ this.shiftPressed = false;
+ break;
+ }
+ case 29: {
+ this.ctrlpressed = false;
+ break;
+ }
+ case 56: {
+ this.menuPressed = false;
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {
+
+ }
+ private String getButtonText(HotKeyDescriptor descriptor){
+ String text = descriptor.getTitle();
+ if(descriptor.isShiftPressed())
+ text = "Shift + " + text;
+ if(descriptor.isMenuPressed())
+ text = "Alt + " + text;
+ if(descriptor.isControlPressed())
+ text = "Ctrl + " + text;
+ return text;
+ }
+}
diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java
new file mode 100644
index 00000000..d80943e3
--- /dev/null
+++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java
@@ -0,0 +1,53 @@
+package com.mercury.platform.shared.hotkey;
+
+import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor;
+import com.mercury.platform.shared.store.MercuryStoreCore;
+import org.jnativehook.mouse.NativeMouseEvent;
+import org.jnativehook.mouse.NativeMouseListener;
+
+public class MercuryNativeMouseListener implements NativeMouseListener {
+ @Override
+ public void nativeMouseClicked(NativeMouseEvent nativeMouseEvent) {
+ }
+
+ @Override
+ public void nativeMousePressed(NativeMouseEvent nativeMouseEvent) {
+ HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor();
+ hotKeyDescriptor.setVirtualKeyCode(nativeMouseEvent.getButton() + 10000);
+ hotKeyDescriptor.setTitle(this.getModifiersText(nativeMouseEvent.getButton()));
+ MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor);
+ }
+
+ @Override
+ public void nativeMouseReleased(NativeMouseEvent nativeMouseEvent) {
+ }
+
+ private String getModifiersText(int code) {
+ switch (code) {
+ case 1: {
+ return "Mouse left";
+ }
+ case 2: {
+ return "Mouse right";
+ }
+ case 3: {
+ return "Mouse middle";
+ }
+ case 4: {
+ return "Button 4";
+ }
+ case 5: {
+ return "Button 5";
+ }
+ case 6: {
+ return "Button 6";
+ }
+ case 7: {
+ return "Button 7";
+ }
+ default: {
+ return "Undefined";
+ }
+ }
+ }
+}
diff --git a/app-core/src/test/java/com/mercury/platform/shared/MainTestKeyHook.java b/app-core/src/test/java/com/mercury/platform/shared/MainTestKeyHook.java
new file mode 100644
index 00000000..7a921ab7
--- /dev/null
+++ b/app-core/src/test/java/com/mercury/platform/shared/MainTestKeyHook.java
@@ -0,0 +1,38 @@
+package com.mercury.platform.shared;
+
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.User32;
+import com.sun.jna.platform.win32.WinDef.HINSTANCE;
+import com.sun.jna.platform.win32.WinDef.LPARAM;
+import com.sun.jna.platform.win32.WinDef.LRESULT;
+import com.sun.jna.platform.win32.WinDef.WPARAM;
+import com.sun.jna.platform.win32.WinUser.HOOKPROC;
+
+public class MainTestKeyHook {
+
+
+ public static void main(String[] args) throws Exception {
+ HOOKPROC hookProc = new HOOKPROC_bg();
+ HINSTANCE hInst = Kernel32.INSTANCE.GetModuleHandle(null);
+
+ User32.HHOOK hHook = User32.INSTANCE.SetWindowsHookEx(User32.WH_KEYBOARD_LL, hookProc, hInst, 0);
+ if (hHook == null)
+ return;
+ User32.MSG msg = new User32.MSG();
+ System.err.println("Please press any key ....");
+ while (true) {
+ User32.INSTANCE.GetMessage(msg, null, 0, 0);
+ }
+ }
+}
+
+class HOOKPROC_bg implements HOOKPROC {
+
+ public HOOKPROC_bg() {
+ }
+
+ public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) {
+ System.err.println("callback bbbnhkilhjkibh nCode: " + nCode);
+ return new LRESULT(0);
+ }
+}
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 da94e2f6..76f4d383 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
@@ -170,7 +170,7 @@ public JPanel getCaptureLocationPanel(AdrCaptureDescriptor descriptor){
}
public JButton getHotKeyButton(AdrDurationComponentDescriptor descriptor) {
- JButton button = this.componentsFactory.getBorderedButton(this.getButtonText(descriptor.getHotKeyDescriptor()));
+ JButton button = this.componentsFactory.getBorderedButton(descriptor.getHotKeyDescriptor().getTitle());
button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 18f));
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
@@ -192,7 +192,7 @@ public void mousePressed(MouseEvent e) {
} else {
descriptor.setHotKeyDescriptor(hotKey);
}
- button.setText(getButtonText(descriptor.getHotKeyDescriptor()));
+ button.setText(hotKey.getTitle());
allowed = false;
MercuryStoreUI.adrReloadSubject.onNext(descriptor);
button.addMouseListener(mouseAdapter);
@@ -881,22 +881,6 @@ private JColorChooser getColorChooser(){
}
return colorChooser;
}
- private String getButtonText(HotKeyDescriptor descriptor){
- if(!descriptor.getTitle().equals("")){
- return descriptor.getTitle();
- }
- if(descriptor.getKeyChar() == '\u0000') {
- return "...";
- }
- String text = String.valueOf(descriptor.getKeyChar());
- if(descriptor.isShiftPressed())
- text = "Shift + " + text;
- if(descriptor.isMenuPressed())
- text = "Alt + " + text;
- if(descriptor.isControlPressed())
- text = "Ctrl + " + text;
- return text;
- }
private class ColorChooserMouseListener extends MouseAdapter {
private JPanel panel;
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java
new file mode 100644
index 00000000..845a610b
--- /dev/null
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java
@@ -0,0 +1,7 @@
+package com.mercury.platform.ui.components.panel.message;
+
+/**
+ * Created by Константин on 10.08.2017.
+ */
+public class HistoryMessagePanel {
+}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java
new file mode 100644
index 00000000..bc018b19
--- /dev/null
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java
@@ -0,0 +1,571 @@
+package com.mercury.platform.ui.components.panel.message;
+
+import com.mercury.platform.shared.AsSubscriber;
+import com.mercury.platform.shared.config.Configuration;
+import com.mercury.platform.shared.config.configration.KeyValueConfigurationService;
+import com.mercury.platform.shared.config.configration.PlainConfigurationService;
+import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor;
+import com.mercury.platform.shared.config.descriptor.HotKeyType;
+import com.mercury.platform.shared.config.descriptor.NotificationDescriptor;
+import com.mercury.platform.shared.entity.message.CurrencyMessage;
+import com.mercury.platform.shared.entity.message.ItemMessage;
+import com.mercury.platform.shared.entity.message.Message;
+import com.mercury.platform.shared.config.descriptor.ResponseButtonDescriptor;
+import com.mercury.platform.shared.store.MercuryStoreCore;
+import com.mercury.platform.ui.components.ComponentsFactory;
+import com.mercury.platform.ui.components.fields.font.FontStyle;
+import com.mercury.platform.ui.components.fields.font.TextAlignment;
+import com.mercury.platform.ui.components.panel.misc.HasUI;
+import com.mercury.platform.ui.frame.movable.container.MessageFrame;
+import com.mercury.platform.ui.misc.AppThemeColor;
+import com.mercury.platform.ui.misc.HasHotkey;
+import com.mercury.platform.ui.misc.MercuryStoreUI;
+import com.mercury.platform.ui.misc.TooltipConstants;
+import lombok.Getter;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import javax.swing.*;
+import javax.swing.Timer;
+import javax.swing.border.Border;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.text.DecimalFormat;
+import java.util.*;
+import java.util.List;
+
+
+public class InMessagePanel extends JPanel implements AsSubscriber, HasUI,HasHotkey{
+ private static final Logger logger = LogManager.getLogger(InMessagePanel.class.getSimpleName());
+
+ private ComponentsFactory componentsFactory;
+ private PlainConfigurationService notificationService;
+ private MessagePanelController controller;
+ private MessagePanelStyle style;
+
+ private String whisper;
+ private JLabel whisperLabel;
+ private JButton tradeButton;
+ private JButton expandButton;
+
+ @Getter
+ private Message message;
+
+ private Timer timeAgo;
+ private String cachedTime = "0m";
+ private JLabel timeLabel;
+ private Color cachedWhisperColor = AppThemeColor.TEXT_NICKNAME;
+ private JPanel whisperPanel;
+ private JPanel messagePanel;
+ private JPanel customButtonsPanel;
+
+ private boolean expanded = false;
+
+ private InMessagePanel(Message message, MessagePanelStyle style) {
+ super(new BorderLayout());
+ this.message = message;
+ this.style = style;
+ this.whisper = message.getWhisperNickname();
+ this.notificationService = Configuration.get().notificationConfiguration();
+ if(!style.equals(MessagePanelStyle.HISTORY)) {
+ this.initHotKeyListeners();
+ }
+ }
+ public InMessagePanel(Message message, MessagePanelStyle style, MessagePanelController controller, ComponentsFactory componentsFactory){
+ this(message,style);
+ this.componentsFactory = componentsFactory;
+ this.controller = controller;
+ createUI();
+ }
+
+ @Override
+ public void createUI() {
+ this.setBackground(AppThemeColor.FRAME);
+ this.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,1),
+ BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)));
+ init();
+ subscribe();
+ setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ }
+ private void init(){
+ this.removeAll();
+ this.whisperPanel = getWhisperPanel();
+ this.messagePanel = getFormattedMessagePanel();
+ this.customButtonsPanel = getButtonsPanel();
+ whisperPanel.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createMatteBorder(1, 0, 1, 0, AppThemeColor.MSG_HEADER_BORDER),
+ BorderFactory.createEmptyBorder(-6, 0, -6, 0)));
+ if(style.equals(MessagePanelStyle.IN_DOWNWARDS) ||
+ style.equals(MessagePanelStyle.HISTORY) || style.equals(MessagePanelStyle.RELOADED)) {
+ this.add(whisperPanel,BorderLayout.PAGE_START);
+ this.add(messagePanel,BorderLayout.CENTER);
+ this.add(customButtonsPanel,BorderLayout.PAGE_END);
+ }else {
+ this.add(customButtonsPanel,BorderLayout.PAGE_START);
+ this.add(messagePanel,BorderLayout.CENTER);
+ this.add(whisperPanel,BorderLayout.PAGE_END);
+ }
+ switch (style){
+ case IN_DOWNWARDS:{
+ messagePanel.setVisible(expanded);
+ customButtonsPanel.setVisible(expanded);
+ break;
+ }
+ case IN_UPWARDS:{
+ messagePanel.setVisible(expanded);
+ customButtonsPanel.setVisible(expanded);
+ break;
+ }
+ case HISTORY:{
+ messagePanel.setVisible(true);
+ customButtonsPanel.setVisible(false);
+ break;
+ }
+ case RELOADED:{
+ messagePanel.setVisible(true);
+ customButtonsPanel.setVisible(true);
+ }
+ }
+ this.repaint();
+ }
+
+ private JPanel getFormattedMessagePanel(){
+ JPanel labelsPanel = new JPanel();
+ labelsPanel.setLayout(new BoxLayout(labelsPanel,BoxLayout.Y_AXIS));
+ labelsPanel.setBackground(AppThemeColor.TRANSPARENT);
+
+ JPanel tradePanel = new JPanel(new BorderLayout());
+ tradePanel.setBackground(AppThemeColor.TRANSPARENT);
+ tradePanel.setBorder(BorderFactory.createEmptyBorder(-11,2,-11,0));
+ if(message instanceof ItemMessage) {
+ JButton itemButton = componentsFactory.getButton(
+ FontStyle.BOLD,
+ AppThemeColor.BUTTON,
+ BorderFactory.createEmptyBorder(0,4,0,2),
+ ((ItemMessage) message).getItemName(), 17f);
+
+ itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT);
+ itemButton.setBackground(AppThemeColor.TRANSPARENT);
+ itemButton.setHorizontalAlignment(SwingConstants.LEFT);
+ itemButton.setContentAreaFilled(false);
+ itemButton.setRolloverEnabled(false);
+ itemButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ controller.showITH();
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ itemButton.setBorder(new CompoundBorder(
+ BorderFactory.createMatteBorder(0,1,0,1,AppThemeColor.BORDER),
+ BorderFactory.createEmptyBorder(0,3,0,1)));
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ itemButton.setBorder(BorderFactory.createEmptyBorder(0,4,0,2));
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+ });
+ tradePanel.add(itemButton,BorderLayout.CENTER);
+ }else if(message instanceof CurrencyMessage){
+ JPanel fromPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ fromPanel.setBackground(AppThemeColor.TRANSPARENT);
+ CurrencyMessage message = (CurrencyMessage) this.message;
+
+ String curCount = message.getCurrForSaleCount() % 1 == 0 ?
+ String.valueOf(message.getCurrForSaleCount().intValue()) :
+ String.valueOf(message.getCurrForSaleCount());
+ JPanel curCountPanel = getCurrencyPanel(curCount);
+ JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrForSaleTitle() + ".png", 26);
+ JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ curPanel.setBackground(AppThemeColor.TRANSPARENT);
+ curPanel.add(curCountPanel);
+ curPanel.add(currencyLabel);
+ curPanel.add(getCurrencyRatePanel());
+ fromPanel.add(curPanel);
+ tradePanel.add(fromPanel,BorderLayout.CENTER);
+ }
+
+ JPanel forPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+ forPanel.setBackground(AppThemeColor.TRANSPARENT);
+
+ JLabel separator = componentsFactory.getTextLabel(
+ FontStyle.BOLD,
+ AppThemeColor.TEXT_MESSAGE,
+ TextAlignment.CENTER,
+ 18f,
+ "=>");
+ separator.setHorizontalAlignment(SwingConstants.CENTER);
+ String curCount = " ";
+ if(message.getCurCount() > 0) {
+ curCount = message.getCurCount() % 1 == 0 ?
+ String.valueOf(message.getCurCount().intValue()) :
+ String.valueOf(message.getCurCount());
+ }
+ String currency = message.getCurrency();
+ if(!Objects.equals(curCount, "") && currency != null) {
+ JPanel curCountPanel = getCurrencyPanel(curCount);
+ JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + currency + ".png", 26);
+ JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ curPanel.setBackground(AppThemeColor.TRANSPARENT);
+ curPanel.add(separator);
+ curPanel.add(curCountPanel);
+ curPanel.add(currencyLabel);
+ forPanel.add(curPanel);
+ }
+ tradePanel.add(forPanel,BorderLayout.LINE_END);
+ labelsPanel.add(tradePanel);
+ String offer = message.getOffer();
+ if(offer != null && offer.trim().length() > 0) {
+ JLabel offerLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 17f, offer);
+ offerLabel.setAlignmentY(Component.TOP_ALIGNMENT);
+ labelsPanel.add(offerLabel);
+ }
+ return labelsPanel;
+ }
+ private JPanel getCurrencyPanel(String curCount){
+ JPanel curCountPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ curCountPanel.setBackground(AppThemeColor.TRANSPARENT);
+
+ JLabel priceLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER,17f,null, curCount);
+ curCountPanel.add(priceLabel);
+ curCountPanel.setPreferredSize(new Dimension((int)(componentsFactory.getScale() * 40),curCountPanel.getPreferredSize().height));
+ return curCountPanel;
+ }
+ private JPanel getCurrencyRatePanel(){
+ CurrencyMessage message = (CurrencyMessage) this.message;
+ Double currForSaleCount = message.getCurrForSaleCount();
+ Double curCount = message.getCurCount();
+ double rate = curCount / currForSaleCount;
+ DecimalFormat decimalFormat = new DecimalFormat("#.####");
+ JPanel ratePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT));
+ ratePanel.add(componentsFactory.
+ getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,"("));
+ JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrency() + ".png", 26);
+ currencyLabel.setBorder(null);
+ ratePanel.add(currencyLabel);
+ ratePanel.add(componentsFactory.
+ getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,decimalFormat.format(rate)));
+ ratePanel.add(componentsFactory.
+ getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,")"));
+ ratePanel.setBorder(BorderFactory.createEmptyBorder(-5,0,-5,0));
+ return ratePanel;
+ }
+ private JPanel getWhisperPanel(){
+ JPanel topPanel = new JPanel(new BorderLayout());
+ topPanel.setBackground(AppThemeColor.MSG_HEADER);
+
+ whisperLabel = componentsFactory.getTextLabel(FontStyle.BOLD,cachedWhisperColor, TextAlignment.LEFTOP,15f,getNicknameLabel());
+ Border border = whisperLabel.getBorder();
+ whisperLabel.setBorder(new CompoundBorder(border,new EmptyBorder(0,0,0,5)));
+ whisperLabel.setVerticalAlignment(SwingConstants.CENTER);
+
+ JPanel nickNamePanel = componentsFactory.getTransparentPanel(new BorderLayout());
+ if(style.equals(MessagePanelStyle.HISTORY)){
+ nickNamePanel.add(whisperLabel,BorderLayout.CENTER);
+ }else {
+ JPanel buttonWrapper = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER));
+ buttonWrapper.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
+ buttonWrapper.add(getExpandButton());
+ if(!style.equals(MessagePanelStyle.RELOADED)) {
+ nickNamePanel.add(buttonWrapper, BorderLayout.LINE_START);
+ }
+ nickNamePanel.add(whisperLabel,BorderLayout.CENTER);
+ }
+ topPanel.add(nickNamePanel,BorderLayout.CENTER);
+
+ JPanel interactionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ interactionPanel.setBorder(BorderFactory.createEmptyBorder(1,0,1,0));
+ interactionPanel.setBackground(AppThemeColor.TRANSPARENT);
+ interactionPanel.add(getTimePanel());
+ if(!style.equals(MessagePanelStyle.HISTORY)) {
+ JButton inviteButton = componentsFactory.getIconButton("app/invite.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.INVITE);
+ inviteButton.addActionListener(e -> controller.performInvite());
+ JButton kickButton = componentsFactory.getIconButton("app/kick.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.KICK);
+ kickButton.addActionListener(e -> {
+ controller.performKick();
+ if(this.notificationService.get().isDismissAfterKick() && !style.equals(MessagePanelStyle.RELOADED)){
+ controller.performHide();
+ }
+ });
+ tradeButton = componentsFactory.getIconButton("app/trade.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE);
+ tradeButton.addActionListener(e -> controller.performOfferTrade());
+ interactionPanel.add(inviteButton);
+ interactionPanel.add(kickButton);
+ interactionPanel.add(tradeButton);
+ interactionPanel.add(getStillInterestedButton());
+ }else {
+ JButton reloadButton = componentsFactory.getIconButton("app/reload-history.png", 14, AppThemeColor.MSG_HEADER, "Restore");
+ reloadButton.addActionListener(e -> controller.reloadMessage(this));
+ interactionPanel.add(reloadButton);
+ }
+ JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT);
+ openChatButton.setToolTipText("Open chat");
+ openChatButton.addActionListener(e -> controller.performOpenChat());
+
+ interactionPanel.add(openChatButton);
+ JButton hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL);
+ hideButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ if(SwingUtilities.isLeftMouseButton(e)) {
+ controller.performHide();
+ }
+ }
+ });
+ if(!style.equals(MessagePanelStyle.HISTORY) && !style.equals(MessagePanelStyle.RELOADED)) {
+ interactionPanel.add(hideButton);
+ }
+
+ topPanel.add(interactionPanel,BorderLayout.LINE_END);
+ return topPanel;
+ }
+ private String getNicknameLabel(){
+ String whisperNickname = message.getWhisperNickname();
+ String result = whisperNickname + ":";
+ if(this.notificationService.get().isShowLeague()) {
+ if (message.getLeague() != null) {
+ String league = message.getLeague().trim();
+ if (league.length() == 0) {
+ return result;
+ }
+ if (league.contains("Hardcore")) {
+ if (league.equals("Hardcore")) {
+ result = "HC " + result;
+ } else {
+ result = String.valueOf(league.split(" ")[1].charAt(0)) + "HC " + result;
+ }
+ } else if (league.contains("Standard")) {
+ result = "Standard " + result;
+ } else {
+ result = String.valueOf(league.charAt(0)) + "SC " + result;
+ }
+ }
+ }
+ return result;
+ }
+ private JPanel getTimePanel(){
+ JPanel panel = new JPanel();
+ panel.setBackground(AppThemeColor.TRANSPARENT);
+ timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 14, cachedTime);
+ if(timeAgo == null) {
+ timeAgo = new Timer(60000, new ActionListener() {
+ private int minute = 0;
+ private int hours = 0;
+ private int day = 0;
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String labelText = "";
+ minute++;
+ if (minute > 60) {
+ hours++;
+ minute = 0;
+ if (hours > 24) {
+ day++;
+ hours = 0;
+ }
+ }
+ if (hours == 0 && day == 0) {
+ labelText = minute + "m";
+ } else if (hours > 0) {
+ labelText = hours + "h " + minute + "m";
+ } else if (day > 0) {
+ labelText = day + "d " + hours + "h " + minute + "m";
+ }
+ timeLabel.setText(labelText);
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+ });
+ timeAgo.start();
+ }
+ panel.add(timeLabel);
+ return panel;
+ }
+ public void disableTime(){
+ if(timeAgo != null) {
+ timeAgo.stop();
+ timeLabel.setText("");
+ }
+ }
+ private JButton getExpandButton(){
+ String iconPath = "app/default-mp.png";
+ if(expanded){
+ if(style.equals(MessagePanelStyle.IN_DOWNWARDS)){
+ iconPath = "app/expand-mp.png";
+ }else {
+ iconPath = "app/collapse-mp.png";
+ }
+ }
+ expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,"");
+ expandButton.setBorder(BorderFactory.createEmptyBorder(4,4,4,0));
+ expandButton.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ if(SwingUtilities.isLeftMouseButton(e)) {
+ if (!messagePanel.isVisible()) {
+ expand();
+ } else {
+ collapse();
+ }
+ }
+ }
+ });
+ return expandButton;
+ }
+ public void expand(){
+ expanded = true;
+ if(style.equals(MessagePanelStyle.IN_DOWNWARDS)) {
+ expandButton.setIcon(componentsFactory.getIcon("app/expand-mp.png", 18f));
+ messagePanel.setVisible(true);
+ customButtonsPanel.setVisible(true);
+ }else {
+ expandButton.setIcon(componentsFactory.getIcon("app/collapse-mp.png", 18f));
+ messagePanel.setVisible(true);
+ customButtonsPanel.setVisible(true);
+ }
+ setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ MercuryStoreUI.expandMessageSubject.onNext(true);
+ MercuryStoreUI.packSubject.onNext(MessageFrame.class);
+ }
+ public void collapse(){
+ expanded = false;
+ if(style.equals(MessagePanelStyle.IN_DOWNWARDS)) {
+ expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18));
+ messagePanel.setVisible(false);
+ customButtonsPanel.setVisible(false);
+ }else {
+ expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18));
+ messagePanel.setVisible(false);
+ customButtonsPanel.setVisible(false);
+ }
+ setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ MercuryStoreUI.collapseMessageSubject.onNext(true);
+ MercuryStoreUI.packSubject.onNext(MessageFrame.class);
+ }
+
+ public boolean isExpanded() {
+ return expanded;
+ }
+
+ public void setStyle(MessagePanelStyle style) {
+ this.style = style;
+ this.cachedTime = timeLabel.getText();
+ init();
+ setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
+ }
+
+ public MessagePanelStyle getStyle() {
+ return style;
+ }
+ private JPanel getButtonsPanel(){
+ JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ panel.setBackground(AppThemeColor.TRANSPARENT);
+ initResponseButtons(panel);
+ return panel;
+ }
+ @Override
+ public void subscribe() {
+ MercuryStoreCore.playerJoinSubject.subscribe(nickname -> {
+ if(nickname.equals(whisper)){
+ whisperLabel.setForeground(AppThemeColor.TEXT_SUCCESS);
+ cachedWhisperColor = AppThemeColor.TEXT_SUCCESS;
+ if(!style.equals(MessagePanelStyle.HISTORY)) {
+ tradeButton.setEnabled(true);
+ }
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+ });
+ MercuryStoreCore.playerLeftSubject.subscribe(nickname -> {
+ if (nickname.equals(whisper)) {
+ whisperLabel.setForeground(AppThemeColor.TEXT_DISABLE);
+ cachedWhisperColor = AppThemeColor.TEXT_DISABLE;
+ if (!style.equals(MessagePanelStyle.HISTORY)) {
+ tradeButton.setEnabled(false);
+ }
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ }
+ });
+ MercuryStoreCore.buttonsChangedSubject.subscribe(state -> {
+ this.customButtonsPanel.removeAll();
+ initResponseButtons(customButtonsPanel);
+ MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
+ });
+ }
+ private void initResponseButtons(JPanel panel){
+ List buttonsConfig = this.notificationService.get().getButtons();
+ Collections.sort(buttonsConfig);
+ buttonsConfig.forEach((buttonConfig)->{
+ JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(),15f);
+ button.addActionListener(e -> {
+ controller.performResponse(buttonConfig.getResponseText());
+ if(buttonConfig.isClose() && !style.equals(MessagePanelStyle.RELOADED)){
+ controller.performHide();
+ }
+ });
+ panel.add(button);
+ });
+ }
+ private JButton getStillInterestedButton(){
+ JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.STILL_INTERESTED);
+
+ String curCount = message.getCurCount() % 1 == 0 ?
+ String.valueOf(message.getCurCount().intValue()) :
+ String.valueOf(message.getCurCount());
+ String responseText = "Hi, are you still interested in ";
+ if(message instanceof ItemMessage){
+ ItemMessage message = (ItemMessage) this.message;
+ if(message.getCurrency().equals("???")){
+ responseText += message.getItemName() + "?";
+ }else {
+ responseText += message.getItemName() +
+ " for " + curCount + " " + message.getCurrency() + "?";
+ }
+ }else {
+ CurrencyMessage message = (CurrencyMessage) this.message;
+ String curForSaleCount = message.getCurCount() % 1 == 0 ?
+ String.valueOf(message.getCurrForSaleCount().intValue()) :
+ String.valueOf(message.getCurrForSaleCount());
+ responseText += curForSaleCount + " " + message.getCurrForSaleTitle() + " for " +
+ curCount + " " + message.getCurrency() + "?";
+ }
+ String finalResponseText = responseText; // hate java
+ stillIntButton.addActionListener(
+ (action)->controller.performResponse(finalResponseText)
+ );
+ return stillIntButton;
+ }
+
+ public void setComponentsFactory(ComponentsFactory componentsFactory) {
+ this.componentsFactory = componentsFactory;
+ }
+
+ @Override
+ public void initHotKeyListeners() {
+ KeyValueConfigurationService config = Configuration.get().hotKeysConfiguration();
+ MercuryStoreCore.hotKeySubject.subscribe(descriptor -> {
+ HotKeyDescriptor hotKeyDescriptor = config.get(HotKeyType.CLOSE_NOTIFICATION.name());
+ if(descriptor.equals(hotKeyDescriptor)) {
+ this.controller.performHide();
+ }
+ });
+ }
+}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java
index 03c17cd6..b44f42bd 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java
@@ -1,571 +1,16 @@
package com.mercury.platform.ui.components.panel.message;
+
import com.mercury.platform.shared.AsSubscriber;
-import com.mercury.platform.shared.config.Configuration;
-import com.mercury.platform.shared.config.configration.KeyValueConfigurationService;
import com.mercury.platform.shared.config.configration.PlainConfigurationService;
-import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor;
-import com.mercury.platform.shared.config.descriptor.HotKeyType;
import com.mercury.platform.shared.config.descriptor.NotificationDescriptor;
-import com.mercury.platform.shared.entity.message.CurrencyMessage;
-import com.mercury.platform.shared.entity.message.ItemMessage;
-import com.mercury.platform.shared.entity.message.Message;
-import com.mercury.platform.shared.config.descriptor.ResponseButtonDescriptor;
-import com.mercury.platform.shared.store.MercuryStoreCore;
import com.mercury.platform.ui.components.ComponentsFactory;
-import com.mercury.platform.ui.components.fields.font.FontStyle;
-import com.mercury.platform.ui.components.fields.font.TextAlignment;
import com.mercury.platform.ui.components.panel.misc.HasUI;
-import com.mercury.platform.ui.frame.movable.container.MessageFrame;
-import com.mercury.platform.ui.misc.AppThemeColor;
import com.mercury.platform.ui.misc.HasHotkey;
-import com.mercury.platform.ui.misc.MercuryStoreUI;
-import com.mercury.platform.ui.misc.TooltipConstants;
-import lombok.Getter;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import javax.swing.*;
-import javax.swing.Timer;
-import javax.swing.border.Border;
-import javax.swing.border.CompoundBorder;
-import javax.swing.border.EmptyBorder;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.text.DecimalFormat;
-import java.util.*;
-import java.util.List;
-
-
-public class MessagePanel extends JPanel implements AsSubscriber, HasUI,HasHotkey{
- private static final Logger logger = LogManager.getLogger(MessagePanel.class.getSimpleName());
-
- private ComponentsFactory componentsFactory;
- private PlainConfigurationService notificationService;
- private MessagePanelController controller;
- private MessagePanelStyle style;
-
- private String whisper;
- private JLabel whisperLabel;
- private JButton tradeButton;
- private JButton expandButton;
-
- @Getter
- private Message message;
-
- private Timer timeAgo;
- private String cachedTime = "0m";
- private JLabel timeLabel;
- private Color cachedWhisperColor = AppThemeColor.TEXT_NICKNAME;
- private JPanel whisperPanel;
- private JPanel messagePanel;
- private JPanel customButtonsPanel;
-
- private boolean expanded = false;
-
- private MessagePanel(Message message, MessagePanelStyle style) {
- super(new BorderLayout());
- this.message = message;
- this.style = style;
- this.whisper = message.getWhisperNickname();
- this.notificationService = Configuration.get().notificationConfiguration();
- if(!style.equals(MessagePanelStyle.HISTORY)) {
- this.initHotKeyListeners();
- }
- }
- public MessagePanel(Message message, MessagePanelStyle style, MessagePanelController controller, ComponentsFactory componentsFactory){
- this(message,style);
- this.componentsFactory = componentsFactory;
- this.controller = controller;
- createUI();
- }
-
- @Override
- public void createUI() {
- this.setBackground(AppThemeColor.FRAME);
- this.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,1),
- BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)));
- init();
- subscribe();
- setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- }
- private void init(){
- this.removeAll();
- this.whisperPanel = getWhisperPanel();
- this.messagePanel = getFormattedMessagePanel();
- this.customButtonsPanel = getButtonsPanel();
- whisperPanel.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createMatteBorder(1, 0, 1, 0, AppThemeColor.MSG_HEADER_BORDER),
- BorderFactory.createEmptyBorder(-6, 0, -6, 0)));
- if(style.equals(MessagePanelStyle.DOWNWARDS_SMALL) ||
- style.equals(MessagePanelStyle.HISTORY) || style.equals(MessagePanelStyle.SP_MODE)) {
- this.add(whisperPanel,BorderLayout.PAGE_START);
- this.add(messagePanel,BorderLayout.CENTER);
- this.add(customButtonsPanel,BorderLayout.PAGE_END);
- }else {
- this.add(customButtonsPanel,BorderLayout.PAGE_START);
- this.add(messagePanel,BorderLayout.CENTER);
- this.add(whisperPanel,BorderLayout.PAGE_END);
- }
- switch (style){
- case DOWNWARDS_SMALL:{
- messagePanel.setVisible(expanded);
- customButtonsPanel.setVisible(expanded);
- break;
- }
- case UPWARDS_SMALL:{
- messagePanel.setVisible(expanded);
- customButtonsPanel.setVisible(expanded);
- break;
- }
- case HISTORY:{
- messagePanel.setVisible(true);
- customButtonsPanel.setVisible(false);
- break;
- }
- case SP_MODE:{
- messagePanel.setVisible(true);
- customButtonsPanel.setVisible(true);
- }
- }
- this.repaint();
- }
-
- private JPanel getFormattedMessagePanel(){
- JPanel labelsPanel = new JPanel();
- labelsPanel.setLayout(new BoxLayout(labelsPanel,BoxLayout.Y_AXIS));
- labelsPanel.setBackground(AppThemeColor.TRANSPARENT);
-
- JPanel tradePanel = new JPanel(new BorderLayout());
- tradePanel.setBackground(AppThemeColor.TRANSPARENT);
- tradePanel.setBorder(BorderFactory.createEmptyBorder(-11,2,-11,0));
- if(message instanceof ItemMessage) {
- JButton itemButton = componentsFactory.getButton(
- FontStyle.BOLD,
- AppThemeColor.BUTTON,
- BorderFactory.createEmptyBorder(0,4,0,2),
- ((ItemMessage) message).getItemName(), 17f);
-
- itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT);
- itemButton.setBackground(AppThemeColor.TRANSPARENT);
- itemButton.setHorizontalAlignment(SwingConstants.LEFT);
- itemButton.setContentAreaFilled(false);
- itemButton.setRolloverEnabled(false);
- itemButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- controller.showITH();
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- itemButton.setBorder(new CompoundBorder(
- BorderFactory.createMatteBorder(0,1,0,1,AppThemeColor.BORDER),
- BorderFactory.createEmptyBorder(0,3,0,1)));
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- itemButton.setBorder(BorderFactory.createEmptyBorder(0,4,0,2));
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
- });
- tradePanel.add(itemButton,BorderLayout.CENTER);
- }else if(message instanceof CurrencyMessage){
- JPanel fromPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- fromPanel.setBackground(AppThemeColor.TRANSPARENT);
- CurrencyMessage message = (CurrencyMessage) this.message;
-
- String curCount = message.getCurrForSaleCount() % 1 == 0 ?
- String.valueOf(message.getCurrForSaleCount().intValue()) :
- String.valueOf(message.getCurrForSaleCount());
- JPanel curCountPanel = getCurrencyPanel(curCount);
- JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrForSaleTitle() + ".png", 26);
- JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- curPanel.setBackground(AppThemeColor.TRANSPARENT);
- curPanel.add(curCountPanel);
- curPanel.add(currencyLabel);
- curPanel.add(getCurrencyRatePanel());
- fromPanel.add(curPanel);
- tradePanel.add(fromPanel,BorderLayout.CENTER);
- }
-
- JPanel forPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- forPanel.setBackground(AppThemeColor.TRANSPARENT);
-
- JLabel separator = componentsFactory.getTextLabel(
- FontStyle.BOLD,
- AppThemeColor.TEXT_MESSAGE,
- TextAlignment.CENTER,
- 18f,
- "=>");
- separator.setHorizontalAlignment(SwingConstants.CENTER);
- String curCount = " ";
- if(message.getCurCount() > 0) {
- curCount = message.getCurCount() % 1 == 0 ?
- String.valueOf(message.getCurCount().intValue()) :
- String.valueOf(message.getCurCount());
- }
- String currency = message.getCurrency();
- if(!Objects.equals(curCount, "") && currency != null) {
- JPanel curCountPanel = getCurrencyPanel(curCount);
- JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + currency + ".png", 26);
- JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- curPanel.setBackground(AppThemeColor.TRANSPARENT);
- curPanel.add(separator);
- curPanel.add(curCountPanel);
- curPanel.add(currencyLabel);
- forPanel.add(curPanel);
- }
- tradePanel.add(forPanel,BorderLayout.LINE_END);
- labelsPanel.add(tradePanel);
- String offer = message.getOffer();
- if(offer != null && offer.trim().length() > 0) {
- JLabel offerLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 17f, offer);
- offerLabel.setAlignmentY(Component.TOP_ALIGNMENT);
- labelsPanel.add(offerLabel);
- }
- return labelsPanel;
- }
- private JPanel getCurrencyPanel(String curCount){
- JPanel curCountPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- curCountPanel.setBackground(AppThemeColor.TRANSPARENT);
-
- JLabel priceLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER,17f,null, curCount);
- curCountPanel.add(priceLabel);
- curCountPanel.setPreferredSize(new Dimension((int)(componentsFactory.getScale() * 40),curCountPanel.getPreferredSize().height));
- return curCountPanel;
- }
- private JPanel getCurrencyRatePanel(){
- CurrencyMessage message = (CurrencyMessage) this.message;
- Double currForSaleCount = message.getCurrForSaleCount();
- Double curCount = message.getCurCount();
- double rate = curCount / currForSaleCount;
- DecimalFormat decimalFormat = new DecimalFormat("#.####");
- JPanel ratePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT));
- ratePanel.add(componentsFactory.
- getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,"("));
- JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrency() + ".png", 26);
- currencyLabel.setBorder(null);
- ratePanel.add(currencyLabel);
- ratePanel.add(componentsFactory.
- getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,decimalFormat.format(rate)));
- ratePanel.add(componentsFactory.
- getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,")"));
- ratePanel.setBorder(BorderFactory.createEmptyBorder(-5,0,-5,0));
- return ratePanel;
- }
- private JPanel getWhisperPanel(){
- JPanel topPanel = new JPanel(new BorderLayout());
- topPanel.setBackground(AppThemeColor.MSG_HEADER);
-
- whisperLabel = componentsFactory.getTextLabel(FontStyle.BOLD,cachedWhisperColor, TextAlignment.LEFTOP,15f,getNicknameLabel());
- Border border = whisperLabel.getBorder();
- whisperLabel.setBorder(new CompoundBorder(border,new EmptyBorder(0,0,0,5)));
- whisperLabel.setVerticalAlignment(SwingConstants.CENTER);
-
- JPanel nickNamePanel = componentsFactory.getTransparentPanel(new BorderLayout());
- if(style.equals(MessagePanelStyle.HISTORY)){
- nickNamePanel.add(whisperLabel,BorderLayout.CENTER);
- }else {
- JPanel buttonWrapper = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER));
- buttonWrapper.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
- buttonWrapper.add(getExpandButton());
- if(!style.equals(MessagePanelStyle.SP_MODE)) {
- nickNamePanel.add(buttonWrapper, BorderLayout.LINE_START);
- }
- nickNamePanel.add(whisperLabel,BorderLayout.CENTER);
- }
- topPanel.add(nickNamePanel,BorderLayout.CENTER);
-
- JPanel interactionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- interactionPanel.setBorder(BorderFactory.createEmptyBorder(1,0,1,0));
- interactionPanel.setBackground(AppThemeColor.TRANSPARENT);
- interactionPanel.add(getTimePanel());
- if(!style.equals(MessagePanelStyle.HISTORY)) {
- JButton inviteButton = componentsFactory.getIconButton("app/invite.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.INVITE);
- inviteButton.addActionListener(e -> controller.performInvite());
- JButton kickButton = componentsFactory.getIconButton("app/kick.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.KICK);
- kickButton.addActionListener(e -> {
- controller.performKick();
- if(this.notificationService.get().isDismissAfterKick() && !style.equals(MessagePanelStyle.SP_MODE)){
- controller.performHide();
- }
- });
- tradeButton = componentsFactory.getIconButton("app/trade.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE);
- tradeButton.addActionListener(e -> controller.performOfferTrade());
- interactionPanel.add(inviteButton);
- interactionPanel.add(kickButton);
- interactionPanel.add(tradeButton);
- interactionPanel.add(getStillInterestedButton());
- }else {
- JButton reloadButton = componentsFactory.getIconButton("app/reload-history.png", 14, AppThemeColor.MSG_HEADER, "Restore");
- reloadButton.addActionListener(e -> controller.reloadMessage(this));
- interactionPanel.add(reloadButton);
- }
- JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT);
- openChatButton.setToolTipText("Open chat");
- openChatButton.addActionListener(e -> controller.performOpenChat());
-
- interactionPanel.add(openChatButton);
- JButton hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL);
- hideButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- if(SwingUtilities.isLeftMouseButton(e)) {
- controller.performHide();
- }
- }
- });
- if(!style.equals(MessagePanelStyle.HISTORY) && !style.equals(MessagePanelStyle.SP_MODE)) {
- interactionPanel.add(hideButton);
- }
-
- topPanel.add(interactionPanel,BorderLayout.LINE_END);
- return topPanel;
- }
- private String getNicknameLabel(){
- String whisperNickname = message.getWhisperNickname();
- String result = whisperNickname + ":";
- if(this.notificationService.get().isShowLeague()) {
- if (message.getLeague() != null) {
- String league = message.getLeague().trim();
- if (league.length() == 0) {
- return result;
- }
- if (league.contains("Hardcore")) {
- if (league.equals("Hardcore")) {
- result = "HC " + result;
- } else {
- result = String.valueOf(league.split(" ")[1].charAt(0)) + "HC " + result;
- }
- } else if (league.contains("Standard")) {
- result = "Standard " + result;
- } else {
- result = String.valueOf(league.charAt(0)) + "SC " + result;
- }
- }
- }
- return result;
- }
- private JPanel getTimePanel(){
- JPanel panel = new JPanel();
- panel.setBackground(AppThemeColor.TRANSPARENT);
- timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 14, cachedTime);
- if(timeAgo == null) {
- timeAgo = new Timer(60000, new ActionListener() {
- private int minute = 0;
- private int hours = 0;
- private int day = 0;
-
- @Override
- public void actionPerformed(ActionEvent e) {
- String labelText = "";
- minute++;
- if (minute > 60) {
- hours++;
- minute = 0;
- if (hours > 24) {
- day++;
- hours = 0;
- }
- }
- if (hours == 0 && day == 0) {
- labelText = minute + "m";
- } else if (hours > 0) {
- labelText = hours + "h " + minute + "m";
- } else if (day > 0) {
- labelText = day + "d " + hours + "h " + minute + "m";
- }
- timeLabel.setText(labelText);
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
- });
- timeAgo.start();
- }
- panel.add(timeLabel);
- return panel;
- }
- public void disableTime(){
- if(timeAgo != null) {
- timeAgo.stop();
- timeLabel.setText("");
- }
- }
- private JButton getExpandButton(){
- String iconPath = "app/default-mp.png";
- if(expanded){
- if(style.equals(MessagePanelStyle.DOWNWARDS_SMALL)){
- iconPath = "app/expand-mp.png";
- }else {
- iconPath = "app/collapse-mp.png";
- }
- }
- expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,"");
- expandButton.setBorder(BorderFactory.createEmptyBorder(4,4,4,0));
- expandButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- if(SwingUtilities.isLeftMouseButton(e)) {
- if (!messagePanel.isVisible()) {
- expand();
- } else {
- collapse();
- }
- }
- }
- });
- return expandButton;
- }
- public void expand(){
- expanded = true;
- if(style.equals(MessagePanelStyle.DOWNWARDS_SMALL)) {
- expandButton.setIcon(componentsFactory.getIcon("app/expand-mp.png", 18f));
- messagePanel.setVisible(true);
- customButtonsPanel.setVisible(true);
- }else {
- expandButton.setIcon(componentsFactory.getIcon("app/collapse-mp.png", 18f));
- messagePanel.setVisible(true);
- customButtonsPanel.setVisible(true);
- }
- setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- MercuryStoreUI.expandMessageSubject.onNext(true);
- MercuryStoreUI.packSubject.onNext(MessageFrame.class);
- }
- public void collapse(){
- expanded = false;
- if(style.equals(MessagePanelStyle.DOWNWARDS_SMALL)) {
- expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18));
- messagePanel.setVisible(false);
- customButtonsPanel.setVisible(false);
- }else {
- expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18));
- messagePanel.setVisible(false);
- customButtonsPanel.setVisible(false);
- }
- setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- MercuryStoreUI.collapseMessageSubject.onNext(true);
- MercuryStoreUI.packSubject.onNext(MessageFrame.class);
- }
-
- public boolean isExpanded() {
- return expanded;
- }
-
- public void setStyle(MessagePanelStyle style) {
- this.style = style;
- this.cachedTime = timeLabel.getText();
- init();
- setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height));
- }
-
- public MessagePanelStyle getStyle() {
- return style;
- }
- private JPanel getButtonsPanel(){
- JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- panel.setBackground(AppThemeColor.TRANSPARENT);
- initResponseButtons(panel);
- return panel;
- }
- @Override
- public void subscribe() {
- MercuryStoreCore.playerJoinSubject.subscribe(nickname -> {
- if(nickname.equals(whisper)){
- whisperLabel.setForeground(AppThemeColor.TEXT_SUCCESS);
- cachedWhisperColor = AppThemeColor.TEXT_SUCCESS;
- if(!style.equals(MessagePanelStyle.HISTORY)) {
- tradeButton.setEnabled(true);
- }
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
- });
- MercuryStoreCore.playerLeftSubject.subscribe(nickname -> {
- if (nickname.equals(whisper)) {
- whisperLabel.setForeground(AppThemeColor.TEXT_DISABLE);
- cachedWhisperColor = AppThemeColor.TEXT_DISABLE;
- if (!style.equals(MessagePanelStyle.HISTORY)) {
- tradeButton.setEnabled(false);
- }
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- }
- });
- MercuryStoreCore.buttonsChangedSubject.subscribe(state -> {
- this.customButtonsPanel.removeAll();
- initResponseButtons(customButtonsPanel);
- MercuryStoreUI.repaintSubject.onNext(MessageFrame.class);
- });
- }
- private void initResponseButtons(JPanel panel){
- List buttonsConfig = this.notificationService.get().getButtons();
- Collections.sort(buttonsConfig);
- buttonsConfig.forEach((buttonConfig)->{
- JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(),15f);
- button.addActionListener(e -> {
- controller.performResponse(buttonConfig.getResponseText());
- if(buttonConfig.isClose() && !style.equals(MessagePanelStyle.SP_MODE)){
- controller.performHide();
- }
- });
- panel.add(button);
- });
- }
- private JButton getStillInterestedButton(){
- JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.STILL_INTERESTED);
-
- String curCount = message.getCurCount() % 1 == 0 ?
- String.valueOf(message.getCurCount().intValue()) :
- String.valueOf(message.getCurCount());
- String responseText = "Hi, are you still interested in ";
- if(message instanceof ItemMessage){
- ItemMessage message = (ItemMessage) this.message;
- if(message.getCurrency().equals("???")){
- responseText += message.getItemName() + "?";
- }else {
- responseText += message.getItemName() +
- " for " + curCount + " " + message.getCurrency() + "?";
- }
- }else {
- CurrencyMessage message = (CurrencyMessage) this.message;
- String curForSaleCount = message.getCurCount() % 1 == 0 ?
- String.valueOf(message.getCurrForSaleCount().intValue()) :
- String.valueOf(message.getCurrForSaleCount());
- responseText += curForSaleCount + " " + message.getCurrForSaleTitle() + " for " +
- curCount + " " + message.getCurrency() + "?";
- }
- String finalResponseText = responseText; // hate java
- stillIntButton.addActionListener(
- (action)->controller.performResponse(finalResponseText)
- );
- return stillIntButton;
- }
-
- public void setComponentsFactory(ComponentsFactory componentsFactory) {
- this.componentsFactory = componentsFactory;
- }
- @Override
- public void initHotKeyListeners() {
- KeyValueConfigurationService config = Configuration.get().hotKeysConfiguration();
- MercuryStoreCore.hotKeySubject.subscribe(descriptor -> {
- HotKeyDescriptor hotKeyDescriptor = config.get(HotKeyType.CLOSE_NOTIFICATION.name());
- if(descriptor.equals(hotKeyDescriptor)) {
- this.controller.performHide();
- }
- });
- }
+public abstract class MessagePanel extends JPanel implements AsSubscriber, HasUI {
+ protected ComponentsFactory componentsFactory;
+ protected PlainConfigurationService notificationService;
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java
index 0225fa0b..da5a667f 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java
@@ -2,5 +2,5 @@
public class MessagePanelBuilder {
-
+ private MessagePanelStyle style;
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java
index c0135d80..5fd05539 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java
@@ -14,5 +14,5 @@ public interface MessagePanelController {
* Show Item Stash Highlights
*/
void showITH();
- void reloadMessage(@NonNull MessagePanel panel);
+ void reloadMessage(@NonNull InMessagePanel panel);
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java
new file mode 100644
index 00000000..36c0bb5b
--- /dev/null
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java
@@ -0,0 +1,5 @@
+package com.mercury.platform.ui.components.panel.message;
+
+
+public class MessagePanelFactory {
+}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java
new file mode 100644
index 00000000..ed7d2e26
--- /dev/null
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java
@@ -0,0 +1,7 @@
+package com.mercury.platform.ui.components.panel.message;
+
+
+public interface MessagePanelProvider {
+ boolean isSuitable(MessagePanelStyle style);
+
+}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java
index 6c65d4c1..0c549a83 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java
@@ -1,8 +1,5 @@
package com.mercury.platform.ui.components.panel.message;
-/**
- * Created by Константин on 24.12.2016.
- */
public enum MessagePanelStyle {
- DOWNWARDS_SMALL, UPWARDS_SMALL,HISTORY, SP_MODE
+ OUT_MESSAGE, IN_DOWNWARDS, IN_UPWARDS,HISTORY, RELOADED
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/NotificationMessageController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/NotificationMessageController.java
index ce122b04..12fc186c 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/NotificationMessageController.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/NotificationMessageController.java
@@ -3,7 +3,6 @@
import com.mercury.platform.shared.entity.message.ItemMessage;
import com.mercury.platform.shared.entity.message.Message;
import com.mercury.platform.shared.store.MercuryStoreCore;
-import com.mercury.platform.ui.frame.movable.container.MessageFrame;
import com.mercury.platform.ui.misc.MercuryStoreUI;
import lombok.NonNull;
import org.apache.logging.log4j.LogManager;
@@ -64,7 +63,7 @@ public void showITH() {
}
@Override
- public void reloadMessage(MessagePanel panel) {
+ public void reloadMessage(InMessagePanel panel) {
MercuryStoreUI.reloadMessageSubject.onNext(panel);
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java
new file mode 100644
index 00000000..e617bd57
--- /dev/null
+++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java
@@ -0,0 +1,7 @@
+package com.mercury.platform.ui.components.panel.message;
+
+/**
+ * Created by Константин on 10.08.2017.
+ */
+public class OutMessagePanel {
+}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java
index c63716a6..19a5fc36 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java
@@ -12,7 +12,7 @@
import com.mercury.platform.ui.components.ComponentsFactory;
import com.mercury.platform.ui.components.fields.font.FontStyle;
import com.mercury.platform.ui.components.fields.font.TextAlignment;
-import com.mercury.platform.ui.components.panel.message.MessagePanel;
+import com.mercury.platform.ui.components.panel.message.InMessagePanel;
import com.mercury.platform.ui.components.panel.message.MessagePanelController;
import com.mercury.platform.ui.components.panel.message.NotificationMessageController;
import com.mercury.platform.ui.components.panel.message.MessagePanelStyle;
@@ -34,7 +34,7 @@
import java.util.stream.Collectors;
public class MessageFrame extends AbstractMovableComponentFrame implements MessagesContainer {
- private List currentMessages = new ArrayList<>();
+ private List currentMessages = new ArrayList<>();
private PlainConfigurationService notificationConfig;
private boolean wasVisible;
private FlowDirections flowDirections;
@@ -112,7 +112,7 @@ public void subscribe() {
}
});
MercuryStoreCore.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> {
- List collect = this.currentMessages.stream()
+ List collect = this.currentMessages.stream()
.filter(panel -> panel.getMessage().equals(message))
.collect(Collectors.toList());
if(collect.size() == 0) {
@@ -120,17 +120,17 @@ public void subscribe() {
}
}));
MercuryStoreUI.closeMessage.subscribe(message -> {
- MessagePanel messagePanel = this.currentMessages.stream()
+ InMessagePanel inMessagePanel = this.currentMessages.stream()
.filter(panel -> panel.getMessage().equals(message))
.collect(Collectors.toList()).get(0);
- if(messagePanel.isExpanded()){
+ if(inMessagePanel.isExpanded()){
this.currentUnfoldCount--;
if(this.currentUnfoldCount < 0){
this.currentUnfoldCount = 0;
}
}
- this.remove(messagePanel);
- this.currentMessages.remove(messagePanel);
+ this.remove(inMessagePanel);
+ this.currentMessages.remove(inMessagePanel);
if (this.currentMessages.size() == 0) {
this.setVisible(false);
@@ -150,8 +150,8 @@ public void subscribe() {
private void addMessage(Message message){
MessagePanelStyle style = flowDirections.equals(FlowDirections.DOWNWARDS)?
- MessagePanelStyle.DOWNWARDS_SMALL: MessagePanelStyle.UPWARDS_SMALL;
- MessagePanel messagePanel = new MessagePanel(
+ MessagePanelStyle.IN_DOWNWARDS : MessagePanelStyle.IN_UPWARDS;
+ InMessagePanel inMessagePanel = new InMessagePanel(
message,
style,
new NotificationMessageController(message),
@@ -162,18 +162,18 @@ private void addMessage(Message message){
this.prevState = FrameVisibleState.SHOW;
}
if (flowDirections.equals(FlowDirections.UPWARDS)) {
- this.mainContainer.add(messagePanel, 1);
+ this.mainContainer.add(inMessagePanel, 1);
} else {
- this.mainContainer.add(messagePanel);
+ this.mainContainer.add(inMessagePanel);
}
- this.currentMessages.add(messagePanel);
+ this.currentMessages.add(inMessagePanel);
this.pack();
if (this.currentUnfoldCount < this.unfoldCount) {
- messagePanel.expand();
+ inMessagePanel.expand();
}
if(this.currentMessages.size() > this.limitMsgCount){
if(!expanded) {
- messagePanel.setVisible(false);
+ inMessagePanel.setVisible(false);
}
if(ProdStarter.APP_STATUS == FrameVisibleState.SHOW) {
this.setUpExpandButton();
@@ -320,7 +320,7 @@ private void onLimitCountChange(){
private void onExpandedCountChange(){
this.currentUnfoldCount = 0;
- this.currentMessages.forEach(MessagePanel::collapse);
+ this.currentMessages.forEach(InMessagePanel::collapse);
this.currentUnfoldCount = 0;
this.currentMessages.stream().limit(this.unfoldCount).forEach(panel -> {
panel.expand();
@@ -410,7 +410,7 @@ private void changeDirectionTo(FlowDirections direction){
this.mainContainer.remove(this.buffer);
Component[] components = this.mainContainer.getComponents();
for (Component component : components) {
- ((MessagePanel) component).setStyle(MessagePanelStyle.DOWNWARDS_SMALL);
+ ((InMessagePanel) component).setStyle(MessagePanelStyle.IN_DOWNWARDS);
this.mainContainer.remove(component);
this.mainContainer.add(component, 0);
}
@@ -420,7 +420,7 @@ private void changeDirectionTo(FlowDirections direction){
this.mainContainer.add(buffer,0);
Component[] components = this.mainContainer.getComponents();
for (int i = 1; i < components.length; i++) {
- ((MessagePanel) components[i]).setStyle(MessagePanelStyle.UPWARDS_SMALL);
+ ((InMessagePanel) components[i]).setStyle(MessagePanelStyle.IN_UPWARDS);
this.mainContainer.remove(components[i]);
this.mainContainer.add(components[i], 1);
}
@@ -535,11 +535,11 @@ public void performHide() {}
@Override
public void showITH() {}
@Override
- public void reloadMessage(MessagePanel panel1) {}
+ public void reloadMessage(InMessagePanel panel1) {}
};
- MessagePanel messagePanel = new MessagePanel(message, MessagePanelStyle.DOWNWARDS_SMALL, stubController, factory);
- messagePanel.expand();
- panel.add(messagePanel);
+ InMessagePanel inMessagePanel = new InMessagePanel(message, MessagePanelStyle.IN_DOWNWARDS, stubController, factory);
+ inMessagePanel.expand();
+ panel.add(inMessagePanel);
return panel;
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java
index 48af7ff7..f5b2be32 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java
@@ -1,7 +1,7 @@
package com.mercury.platform.ui.frame.titled.container;
-import com.mercury.platform.ui.components.panel.message.MessagePanel;
+import com.mercury.platform.ui.components.panel.message.InMessagePanel;
public interface HistoryContainer {
- void onReloadMessage(MessagePanel messagePanel);
+ void onReloadMessage(InMessagePanel inMessagePanel);
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryFrame.java
index 4dabe623..b495a9be 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryFrame.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryFrame.java
@@ -6,7 +6,7 @@
import com.mercury.platform.shared.entity.message.Message;
import com.mercury.platform.shared.store.MercuryStoreCore;
import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI;
-import com.mercury.platform.ui.components.panel.message.MessagePanel;
+import com.mercury.platform.ui.components.panel.message.InMessagePanel;
import com.mercury.platform.ui.components.panel.VerticalScrollContainer;
import com.mercury.platform.ui.components.panel.message.NotificationMessageController;
import com.mercury.platform.ui.components.panel.message.MessagePanelStyle;
@@ -64,13 +64,13 @@ public void mouseWheelMoved(MouseWheelEvent e) {
MessageParser parser = new MessageParser();
Message parsedMessage = parser.parse(message);
if(parsedMessage != null) {
- MessagePanel messagePanel = new MessagePanel(
+ InMessagePanel inMessagePanel = new InMessagePanel(
parsedMessage,
MessagePanelStyle.HISTORY,
new NotificationMessageController(parsedMessage),
this.componentsFactory);
- messagePanel.disableTime();
- mainContainer.add(messagePanel);
+ inMessagePanel.disableTime();
+ mainContainer.add(inMessagePanel);
}
}
this.miscPanel.add(getClearButton(),0);
@@ -83,13 +83,13 @@ public void mouseWheelMoved(MouseWheelEvent e) {
MessageParser parser = new MessageParser();
Message parsedMessage = parser.parse(message);
if(parsedMessage != null) {
- MessagePanel messagePanel = new MessagePanel(
+ InMessagePanel inMessagePanel = new InMessagePanel(
parsedMessage,
MessagePanelStyle.HISTORY,
new NotificationMessageController(parsedMessage),
this.componentsFactory);
- messagePanel.disableTime();
- this.mainContainer.add(messagePanel, 0);
+ inMessagePanel.disableTime();
+ this.mainContainer.add(inMessagePanel, 0);
}
vBar.setValue(vBar.getValue() + 100);
}
@@ -124,12 +124,12 @@ protected String getFrameTitle() {
public void subscribe() {
MercuryStoreCore.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> {
HistoryManager.INSTANCE.add(message);
- MessagePanel messagePanel = new MessagePanel(
+ InMessagePanel inMessagePanel = new InMessagePanel(
message,
MessagePanelStyle.HISTORY,
new NotificationMessageController(message),
this.componentsFactory);
- this.mainContainer.add(messagePanel);
+ this.mainContainer.add(inMessagePanel);
this.trimContainer();
this.pack();
}));
@@ -145,9 +145,9 @@ private void trimContainer(){
}
@Override
- public void onReloadMessage(MessagePanel messagePanel) {
- messagePanel.setStyle(MessagePanelStyle.SP_MODE);
- messagePanel.setPreferredSize(new Dimension(this.getWidth()-10,messagePanel.getPreferredSize().height));
+ public void onReloadMessage(InMessagePanel inMessagePanel) {
+ inMessagePanel.setStyle(MessagePanelStyle.RELOADED);
+ inMessagePanel.setPreferredSize(new Dimension(this.getWidth()-10, inMessagePanel.getPreferredSize().height));
this.pack();
this.repaint();
}
diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java
index 67bf946d..a13c88b9 100644
--- a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java
+++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java
@@ -9,7 +9,7 @@
import com.mercury.platform.ui.adr.routing.AdrPageDefinition;
import com.mercury.platform.ui.components.panel.grid.ItemInfoPanel;
import com.mercury.platform.ui.components.panel.grid.TabInfoPanel;
-import com.mercury.platform.ui.components.panel.message.MessagePanel;
+import com.mercury.platform.ui.components.panel.message.InMessagePanel;
import com.mercury.platform.ui.dialog.DialogCallback;
import rx.subjects.PublishSubject;
@@ -22,7 +22,7 @@ public class MercuryStoreUI {
public static final PublishSubject dismissTabInfoPanelSubject = PublishSubject.create();
public static final PublishSubject expandMessageSubject = PublishSubject.create();
public static final PublishSubject itemCellStateSubject = PublishSubject.create();
- public static final PublishSubject reloadMessageSubject = PublishSubject.create();
+ public static final PublishSubject reloadMessageSubject = PublishSubject.create();
//Scale
public static final PublishSubject