diff --git a/app-core/pom.xml b/app-core/pom.xml index e6f06c66..9906e445 100644 --- a/app-core/pom.xml +++ b/app-core/pom.xml @@ -39,6 +39,14 @@ commons-io commons-io + + io.reactivex + rxjava + + + com.google.code.gson + gson + junit junit diff --git a/app-core/src/main/java/com/mercury/platform/core/AppStarter.java b/app-core/src/main/java/com/mercury/platform/core/AppStarter.java index 00e4d658..f9cb631b 100644 --- a/app-core/src/main/java/com/mercury/platform/core/AppStarter.java +++ b/app-core/src/main/java/com/mercury/platform/core/AppStarter.java @@ -4,13 +4,18 @@ import com.mercury.platform.core.update.UpdateClientStarter; import com.mercury.platform.core.utils.error.ErrorHandler; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.HistoryManager; import com.mercury.platform.shared.UpdateManager; +import com.mercury.platform.shared.config.BaseConfigManager; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.MercuryDataSource; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; +import com.mercury.platform.shared.store.MercuryStore; import com.sun.jna.Native; import com.sun.jna.PointerType; +import com.sun.jna.platform.win32.WinDef; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,18 +24,20 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; -/** - * Created by Константин on 31.12.2016. - */ public class AppStarter { private static final Logger logger = LogManager.getLogger(AppStarter.class.getSimpleName()); - public static FrameStates APP_STATUS = FrameStates.HIDE; + public static FrameVisibleState APP_STATUS = FrameVisibleState.HIDE; + public static WinDef.HWND poeWindow; private User32 user32 = User32.INSTANCE; private boolean shutdown = false; private volatile int delay = 100; private boolean updating = false; public void startApplication(){ + BaseConfigManager configuration = new BaseConfigManager(new MercuryDataSource()); + configuration.load(); + Configuration.set(configuration); + ConfigManager.INSTANCE.load(); new SoundNotifier(); new ChatHelper(); @@ -40,8 +47,9 @@ public void startApplication(){ UpdateClientStarter updateClientStarter = new UpdateClientStarter(); executor.execute(updateClientStarter); HistoryManager.INSTANCE.load(); + UpdateManager updateManager = new UpdateManager(); - EventRouter.CORE.registerHandler(UILoadedEvent.class, event -> { + MercuryStore.INSTANCE.uiLoadedSubject.subscribe(state -> { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override @@ -50,27 +58,28 @@ public void run() { timer.cancel(); updateClientStarter.shutdown(); if(updating){ - UpdateManager.INSTANCE.doUpdate(); + updateManager.doUpdate(); } System.exit(0); } - byte[] windowText = new byte[512]; - PointerType hwnd = user32.GetForegroundWindow(); - User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512); - if(!Native.toString(windowText).equals("Path of Exile")){ - if(APP_STATUS == FrameStates.SHOW) { - APP_STATUS = FrameStates.HIDE; - EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.HIDE)); + byte[] className = new byte[512]; + WinDef.HWND hwnd = user32.GetForegroundWindow(); + User32.INSTANCE.GetClassNameA(hwnd, className, 512); + if(!Native.toString(className).equals("POEWindowClass")){ + if(APP_STATUS == FrameVisibleState.SHOW) { + APP_STATUS = FrameVisibleState.HIDE; + MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.HIDE); } }else{ - if(APP_STATUS == FrameStates.HIDE) { + poeWindow = hwnd; + if(APP_STATUS == FrameVisibleState.HIDE) { try { Thread.sleep(delay); delay = 100; } catch (InterruptedException e) { } - APP_STATUS = FrameStates.SHOW; - EventRouter.CORE.fireEvent(new ChangeFrameVisibleEvent(FrameStates.SHOW)); + APP_STATUS = FrameVisibleState.SHOW; + MercuryStore.INSTANCE.frameVisibleSubject.onNext(FrameVisibleState.SHOW); } } } diff --git a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java index 16b08cdb..345a614d 100644 --- a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java +++ b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java @@ -2,24 +2,14 @@ import com.mercury.platform.shared.ConfigManager; import com.mercury.platform.shared.HasEventHandlers; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; -import com.mercury.platform.shared.events.custom.DndModeEvent; -import com.mercury.platform.shared.events.custom.OpenChatEvent; -import com.sun.jna.Native; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.mercury.platform.shared.store.MercuryStore; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; -import java.util.*; -import java.util.List; public class ChatHelper implements HasEventHandlers { - private final Logger logger = LogManager.getLogger(ChatHelper.class.getSimpleName()); - private User32 user32 = User32.INSTANCE; private Robot robot; public ChatHelper() { @@ -36,8 +26,6 @@ private void executeMessage(String message) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); - gameToFront(); - robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); @@ -57,8 +45,6 @@ private void executeMessage(String message) { robot.keyRelease(KeyEvent.VK_ENTER); } private void openChat(String whisper) { - gameToFront(); - StringSelection selection = new StringSelection("@" + whisper); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); @@ -81,40 +67,14 @@ private void openChat(String whisper) { robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); } - /** - * NEED REFACTORING - */ - private void gameToFront(){ - List titles = new ArrayList<>(); - titles.add("Path of Exile"); - user32.EnumWindows((hWnd, arg1) -> { - byte[] windowText = new byte[512]; - user32.GetWindowTextA(hWnd, windowText, 512); - String wText = Native.toString(windowText); - - if (wText.isEmpty()) { - return true; - } - if (titles.contains(wText)) { - user32.SetForegroundWindow(hWnd); - return false; - } - return true; - }, null); - } @Override public void initHandlers() { - EventRouter.CORE.registerHandler(ChatCommandEvent.class, event - -> executeMessage(((ChatCommandEvent)event).getMessage())); - - EventRouter.CORE.registerHandler(OpenChatEvent.class, event -> { - openChat(((OpenChatEvent) event).getWhisper()); - }); - EventRouter.CORE.registerHandler(DndModeEvent.class, event -> { - boolean dnd = ((DndModeEvent) event).isDnd(); + MercuryStore.INSTANCE.chatCommandSubject.subscribe(this::executeMessage); + MercuryStore.INSTANCE.openChatSubject.subscribe(this::openChat); + MercuryStore.INSTANCE.dndSubject.subscribe(state -> { if(ConfigManager.INSTANCE.isInGameDnd()){ - if(dnd) { + if(state) { executeMessage("/dnd " + ConfigManager.INSTANCE.getDndResponseText()); }else { executeMessage("/dnd"); diff --git a/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java b/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java index e6522f55..93e1aa94 100644 --- a/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java +++ b/app-core/src/main/java/com/mercury/platform/core/MercuryConstants.java @@ -1,7 +1,7 @@ package com.mercury.platform.core; public class MercuryConstants { - public static final String APP_VERSION = "1.0.1.2"; + public static final String APP_VERSION = "1.0.1.3"; public static final String SERVER_HOST = "exslims.ddns.net"; public static final int PORT = 5555; } diff --git a/app-core/src/main/java/com/mercury/platform/core/User32.java b/app-core/src/main/java/com/mercury/platform/core/User32.java index 9805511f..f7219e01 100644 --- a/app-core/src/main/java/com/mercury/platform/core/User32.java +++ b/app-core/src/main/java/com/mercury/platform/core/User32.java @@ -14,6 +14,7 @@ public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg); + int GetClassNameA(WinDef.HWND hwnd, byte[] lpString,int nMaxCount); WinDef.HWND SetFocus(WinDef.HWND hWnd); int GetWindowTextA(WinDef.HWND hWnd, byte[] lpString, int nMaxCount); int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount); diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java index b69d2a76..5bffeb13 100644 --- a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java +++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java @@ -1,10 +1,9 @@ package com.mercury.platform.core.misc; -import com.mercury.platform.core.AppStarter; -import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; +import com.mercury.platform.shared.store.DataTransformers; +import com.mercury.platform.shared.store.MercuryStore; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -12,46 +11,31 @@ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.FloatControl; -import java.util.Random; public class SoundNotifier { private final Logger logger = LogManager.getLogger(SoundNotifier.class); private boolean dnd = false; public SoundNotifier() { - EventRouter.CORE.registerHandler(WhisperNotificationEvent.class, event -> { - WhisperNotifierStatus status = ConfigManager.INSTANCE.getWhisperNotifier(); - if (status == WhisperNotifierStatus.ALWAYS || - ((status == WhisperNotifierStatus.ALTAB) && (AppStarter.APP_STATUS == FrameStates.HIDE))) { - play("app/notification.wav"); - } - }); - EventRouter.CORE.registerHandler(UpdateInfoEvent.class, event -> { - play("app/patch_tone.wav"); - }); - EventRouter.CORE.registerHandler(ChatFilterMessageEvent.class, event -> { - play("app/chat-filter.wav"); - }); - EventRouter.CORE.registerHandler(DndModeEvent.class, event -> { - this.dnd = ((DndModeEvent)event).isDnd(); - }); - EventRouter.CORE.registerHandler(ButtonPressedEvent.class, event -> { - String[] clicks = { - "app/sounds/click1/button-pressed-10.wav", - "app/sounds/click1/button-pressed-20.wav", - "app/sounds/click1/button-pressed-30.wav"}; - play(clicks[new Random().nextInt(3)]); - }); + MercuryStore.INSTANCE.soundSubject + .compose(DataTransformers.transformSoundData()) + .subscribe(data -> play(data.getWavPath(), data.getDb())); + MercuryStore.INSTANCE.soundSettingsSubject + .subscribe(data -> play(data.getWavPath(), data.getDb())); + MercuryStore.INSTANCE.dndSubject + .subscribe(value -> this.dnd = value); } - private void play(String wavPath){ - if(!dnd) { + private void play(String wavPath, float db){ + if(!dnd && db > -40) { ClassLoader classLoader = getClass().getClassLoader(); try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) { Clip clip = AudioSystem.getClip(); clip.open(stream); - FloatControl gainControl = - (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - gainControl.setValue(-5.0f); + if(db != 0.0) { + FloatControl gainControl = + (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + gainControl.setValue(db); + } clip.start(); } catch (Exception e) { logger.error("Cannot start playing wav file: ",e); diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java new file mode 100644 index 00000000..72d214e0 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java @@ -0,0 +1,6 @@ +package com.mercury.platform.core.misc; + + +public enum SoundType { + MESSAGE,UPDATE,CHAT_SCANNER,CLICKS +} diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java index 1315b6d9..b355e1aa 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java @@ -1,10 +1,12 @@ package com.mercury.platform.core.update.core.handlers; +import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.core.update.core.holder.ApplicationHolder; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.AlertEvent; import com.mercury.platform.shared.events.custom.ShowPatchNotesEvent; import com.mercury.platform.shared.events.custom.UpdateInfoEvent; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.update.AlreadyLatestUpdateMessage; import com.mercury.platform.update.PatchNotesDescriptor; import com.mercury.platform.update.UpdateDescriptor; @@ -19,8 +21,8 @@ public void process(Object object){ EventRouter.CORE.fireEvent(new ShowPatchNotesEvent(notes)); } if(object instanceof UpdateDescriptor){ - int nextVersion = ((UpdateDescriptor) object).getVersion(); - EventRouter.CORE.fireEvent(new UpdateInfoEvent(nextVersion)); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.UPDATE); + EventRouter.CORE.fireEvent(new UpdateInfoEvent(((UpdateDescriptor) object).getVersion())); } if(object instanceof AlreadyLatestUpdateMessage){ if(ApplicationHolder.getInstance().isManualRequest()) { diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java index e701451f..94ea7119 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java @@ -4,6 +4,7 @@ import com.mercury.platform.shared.HasEventHandlers; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; +import com.mercury.platform.shared.store.MercuryStore; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -81,12 +82,12 @@ public void parse() { @Override public void initHandlers() { - EventRouter.CORE.registerHandler(AddInterceptorEvent.class, event -> { - interceptors.add(((AddInterceptorEvent) event).getInterceptor()); + MercuryStore.INSTANCE.addInterceptorSubject.subscribe(interceptor -> { + interceptors.add(interceptor); lastMessageDate = new Date(); }); - EventRouter.CORE.registerHandler(RemoveInterceptorEvent.class, event -> { - interceptors.remove(((RemoveInterceptorEvent) event).getInterceptor()); + MercuryStore.INSTANCE.removeInterceptorSubject.subscribe(interceptor -> { + interceptors.remove(interceptor); }); } } diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java index 3de7fef7..61a8d618 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java @@ -1,7 +1,6 @@ package com.mercury.platform.core.utils.error; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.HideLoadingFrame; +import com.mercury.platform.shared.store.MercuryStore; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -10,7 +9,7 @@ public class ErrorHandler { private Logger logger = LogManager.getLogger(ErrorHandler.class.getSimpleName()); public ErrorHandler(){ Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { - EventRouter.CORE.fireEvent(new HideLoadingFrame()); + MercuryStore.INSTANCE.appLoadingSubject.onNext(false); logger.error(ExceptionUtils.getStackTrace(throwable)); }); } diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java index e1534595..5944dff8 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/IncTradeMessagesInterceptor.java @@ -1,16 +1,12 @@ package com.mercury.platform.core.utils.interceptor; +import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.core.utils.interceptor.filter.MessageFilter; import com.mercury.platform.shared.MessageParser; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.NewWhispersEvent; -import com.mercury.platform.shared.events.custom.WhisperNotificationEvent; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; import org.apache.commons.lang3.StringUtils; -/** - * Created by Константин on 11.01.2017. - */ public class IncTradeMessagesInterceptor extends MessageInterceptor { private MessageParser messageParser = new MessageParser(); @@ -18,8 +14,8 @@ public class IncTradeMessagesInterceptor extends MessageInterceptor { protected void process(String message) { Message parsedMessage = messageParser.parse(StringUtils.substringAfter(message,"@")); if(parsedMessage != null) { - EventRouter.CORE.fireEvent(new WhisperNotificationEvent()); - EventRouter.CORE.fireEvent(new NewWhispersEvent(parsedMessage)); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.MESSAGE); + MercuryStore.INSTANCE.messageSubject.onNext(parsedMessage); } } diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java index 93f5126e..22c562a2 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/OutTradeMessagesInterceptor.java @@ -4,7 +4,7 @@ import com.mercury.platform.shared.MessageParser; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.OutTradeMessageEvent; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.Message; /** * Created by Константин on 12.01.2017. diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java new file mode 100644 index 00000000..570e012f --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java @@ -0,0 +1,61 @@ +package com.mercury.platform.experimental; + +import rx.Observable; +import rx.Subscriber; +import rx.functions.Action1; + +/** + * Created by Константин on 07.04.2017. + */ +public class RxJavaBasic { + public static void main(String[] args) { + method5(); + } + public static void method1(){ + Observable observable = Observable.create(subscriber -> { + subscriber.onNext("Hello World!"); + subscriber.onCompleted(); + }); + + Subscriber subscriber = new Subscriber() { + @Override + public void onCompleted() { + + } + + @Override + public void onError(Throwable throwable) { + + } + + @Override + public void onNext(String s) { + System.out.println(s); + } + }; + observable.subscribe(subscriber); + } + public static void method2(){ + Observable observable = Observable.just("Hello world"); + Action1 onNextAction = System.out::println; + observable.subscribe(onNextAction); + } + public static void method3(){ + Observable.just("Hello world").subscribe(System.out::println); + } + + //Operators + public static void method4(){ + Observable.just("Hello world").map(s -> s + " -Dan").subscribe(System.out::println); + } + public static void method5(){ + Observable.just("Hello world") + .map(s -> s + " -Dan") + .map(String::hashCode) + .map(i -> Integer.toString(i)) + .subscribe(System.out::println); + } + public static void method6(){ + Observable.just("Hello world").subscribe(System.out::println); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java new file mode 100644 index 00000000..3a7b1077 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java @@ -0,0 +1,22 @@ +package com.mercury.platform.experimental; + +/** + * Created by Константин on 07.04.2017. + */ +public class RxJavaOperators { + public static void main(String[] args) { + + } + public static void method1(){ + + } + public static void method2(){ + + } + public static void method3(){ + + } + public static void method4(){ + + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java index 1dde8c05..36444741 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/ConfigManager.java @@ -1,10 +1,9 @@ package com.mercury.platform.shared; import com.mercury.platform.core.misc.WhisperNotifierStatus; -import com.mercury.platform.shared.pojo.FrameSettings; -import com.mercury.platform.shared.pojo.ResponseButton; -import com.mercury.platform.shared.pojo.ScaleData; -import com.mercury.platform.shared.pojo.StashTab; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.entity.ResponseButton; +import com.mercury.platform.shared.entity.StashTab; import lombok.Getter; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; @@ -23,6 +22,7 @@ */ //todo generalization @SuppressWarnings("unchecked") +@Deprecated public class ConfigManager { private Logger logger = LogManager.getLogger(ConfigManager.class); @@ -38,7 +38,6 @@ private static class ConfigManagerHolder { private List cachedButtonsConfig; private Map cachedFramesSettings; private Map minimumFrameSize; - private Map defaultFramesSettings; private Map defaultAppSettings; @Getter @@ -69,7 +68,7 @@ private static class ConfigManagerHolder { @Getter private boolean checkUpdateOnStartUp = true; @Getter - private boolean dismissAfterKick = false; + private boolean dismissAfterKick = true; @Getter private boolean showLeague = false; @Getter @@ -78,17 +77,19 @@ private static class ConfigManagerHolder { private String dndResponseText = "Response text"; @Getter private String defaultWords = "!wtb, uber, boss, perandus"; + @Getter + private String quickResponse = "invite me pls"; public ConfigManager() { minimumFrameSize = new HashMap<>(); minimumFrameSize.put("TaskBarFrame",new Dimension(109,20)); - minimumFrameSize.put("IncMessageFrame",new Dimension(315,10)); + minimumFrameSize.put("IncMessageFrame",new Dimension(360,10)); minimumFrameSize.put("OutMessageFrame",new Dimension(280,115)); minimumFrameSize.put("TestCasesFrame",new Dimension(400,100)); minimumFrameSize.put("SettingsFrame",new Dimension(540,400)); minimumFrameSize.put("HistoryFrame",new Dimension(280,400)); minimumFrameSize.put("TimerFrame",new Dimension(240,102)); - minimumFrameSize.put("ChatFilterFrame",new Dimension(400,200)); + minimumFrameSize.put("ChatFilterFrame",new Dimension(400,100)); minimumFrameSize.put("ItemsGridFrame",new Dimension(150,150)); minimumFrameSize.put("NotesFrame",new Dimension(540,100)); minimumFrameSize.put("ChatFilterSettingsFrame",new Dimension(300,200)); @@ -114,6 +115,7 @@ public ConfigManager() { defaultAppSettings.put("showLeague",false); defaultAppSettings.put("dndResponseText","Response text"); defaultAppSettings.put("defaultWords","!wtb, uber, boss, perandus"); + defaultAppSettings.put("quickResponse","invite me pls"); } @@ -158,8 +160,9 @@ public void load() { saveProperty("inGameDnd", String.valueOf(defaultAppSettings.get("inGameDnd"))); saveProperty("dndResponseText", defaultAppSettings.get("dndResponseText")); saveProperty("defaultWords", defaultAppSettings.get("defaultWords")); + saveProperty("quickResponse", defaultAppSettings.get("quickResponse")); saveProperty("scaleData", defaultAppSettings.get("scaleData")); - saveProperty("showLeague", defaultAppSettings.get("showLeague")); + saveProperty("showLeague", String.valueOf(defaultAppSettings.get("showLeague"))); } catch (Exception e) { logger.error(e); @@ -219,6 +222,7 @@ private void loadConfigFile(){ showLeague = Boolean.valueOf(loadProperty("showLeague")); dndResponseText = loadProperty("dndResponseText"); defaultWords = loadProperty("defaultWords"); + quickResponse = loadProperty("quickResponse"); } catch (Exception e) { logger.error("Error in loadConfigFile: ",e); } @@ -257,8 +261,9 @@ private String loadProperty(String key){ } }catch (Exception e){ logger.error("Error while loading property: " + key,e); + saveProperty(key,String.valueOf(defaultAppSettings.get(key))); + return String.valueOf(defaultAppSettings.get(key)); } - return null; } private void saveProperty(String token, T object){ JSONParser parser = new JSONParser(); @@ -275,7 +280,7 @@ private void saveProperty(String token, T object){ fileWriter.flush(); fileWriter.close(); } catch (Exception e) { - logger.error("Error in ConfigManager.saveProperty",e); + logger.error("Error in ConfigManager.saveProperty with \"" + token + "\" token.",e); } } @@ -394,7 +399,6 @@ public Map getScaleData(){ return scaleData; } - public void setCheckUpdateOnStartUp(boolean checkUpdateOnStartUp) { this.checkUpdateOnStartUp = checkUpdateOnStartUp; saveProperty("checkUpdateOnStartUp", String.valueOf(this.checkUpdateOnStartUp)); @@ -436,10 +440,6 @@ public void setFlowDirection(String flowDirection) { this.flowDirection = flowDirection; saveProperty("flowDirection",flowDirection); } - public void setTradeMode(String tradeMode) { - this.tradeMode = tradeMode; - saveProperty("tradeMode",tradeMode); - } public void setLimitMsgCount(int limitMsgCount) { this.limitMsgCount = limitMsgCount; saveProperty("limitMsgCount",String.valueOf(this.limitMsgCount)); @@ -470,6 +470,10 @@ public void setDefaultWords(String defaultWords) { this.defaultWords = defaultWords; saveProperty("defaultWords",defaultWords); } + public void setQuickResponse(String quickResponse) { + this.quickResponse = quickResponse; + saveProperty("quickResponse",quickResponse); + } private List getDefaultButtons(){ List defaultButtons = new ArrayList<>(); @@ -480,7 +484,7 @@ private List getDefaultButtons(){ return defaultButtons; } public Map getDefaultFramesSettings(){ - defaultFramesSettings = new HashMap<>(); + Map defaultFramesSettings = new HashMap<>(); defaultFramesSettings.put("TaskBarFrame",new FrameSettings(new Point(400, 500),new Dimension(109,20))); defaultFramesSettings.put("IncMessageFrame",new FrameSettings(new Point(700, 600),new Dimension(315,0))); defaultFramesSettings.put("OutMessageFrame",new FrameSettings(new Point(200, 500),new Dimension(280,115))); diff --git a/app-core/src/main/java/com/mercury/platform/shared/FrameStates.java b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java similarity index 77% rename from app-core/src/main/java/com/mercury/platform/shared/FrameStates.java rename to app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java index 468805a8..d5286d9f 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/FrameStates.java +++ b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java @@ -3,6 +3,6 @@ /** * Created by Константин on 09.12.2016. */ -public enum FrameStates { +public enum FrameVisibleState { SHOW,HIDE } diff --git a/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java b/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java index 2d5716ff..93f3fcef 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java @@ -1,21 +1,17 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.Message; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; /** * Created by Константин on 11.02.2017. diff --git a/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java b/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java index 8965983e..fa47eb48 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java +++ b/app-core/src/main/java/com/mercury/platform/shared/MessageParser.java @@ -1,8 +1,8 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.pojo.CurrencyMessage; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.CurrencyMessage; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; import org.apache.commons.lang3.StringUtils; import java.util.regex.Matcher; diff --git a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java index a6f726e7..c06d0100 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java @@ -6,24 +6,17 @@ import java.io.File; -/** - * Created by Константин on 21.02.2017. - */ public class UpdateManager { private final static Logger logger = LogManager.getLogger(UpdateManager.class.getSimpleName()); private final static String LOCAL_UPDATER_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\local-updater.jar"; private static final String JAR_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp\\MercuryTrade.jar"; - private static class UpdateManagerHolder { - static final UpdateManager HOLDER_INSTANCE = new UpdateManager(); - } - public static UpdateManager INSTANCE = UpdateManagerHolder.HOLDER_INSTANCE; - public void doUpdate(){ try { String path = StringUtils.substringAfter(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath(), "/"); logger.debug("Execute local updater, source path: {}",path); if(new File(JAR_FILE_PATH).exists()) { Runtime.getRuntime().exec("java -jar " + LOCAL_UPDATER_PATH + " " + "\"" + path + "\""); + System.exit(0); } } catch (Exception e1) { logger.error("Error while execute local-updater: ", e1); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java new file mode 100644 index 00000000..9215f68f --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/BaseConfigManager.java @@ -0,0 +1,49 @@ +package com.mercury.platform.shared.config; + +import com.mercury.platform.shared.config.service.ConfigurationService; +import com.mercury.platform.shared.config.service.FramesConfigurationService; +import com.mercury.platform.shared.config.service.SoundConfigurationService; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.entity.SoundDescriptor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.IOException; + + +public class BaseConfigManager implements ConfigManager { + private Logger logger = LogManager.getLogger(BaseConfigManager.class.getSimpleName()); + + private DataSource dataSource; + private ConfigurationService framesConfigurationService; + private ConfigurationService soundConfigurationService; + + public BaseConfigManager(DataSource dataSource){ + this.dataSource = dataSource; + + this.framesConfigurationService = new FramesConfigurationService(dataSource); + this.soundConfigurationService = new SoundConfigurationService(dataSource); + } + @Override + public ConfigurationService framesConfiguration() { + return framesConfigurationService; + } + @Override + public ConfigurationService soundConfiguration() { + return soundConfigurationService; + } + public void load(){ + try { + File file = new File(dataSource.getConfigurationFilePath()); + + if(!file.exists()){ + file.createNewFile(); + } + this.framesConfigurationService.load(); + this.soundConfigurationService.load(); + }catch (IOException e) { + logger.error("Error while processing file:{}",dataSource.getConfigurationFilePath(),e); + } + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java new file mode 100644 index 00000000..3ca29bda --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java @@ -0,0 +1,11 @@ +package com.mercury.platform.shared.config; + +import com.mercury.platform.shared.config.service.ConfigurationService; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.entity.SoundDescriptor; + + +public interface ConfigManager { + ConfigurationService framesConfiguration(); + ConfigurationService soundConfiguration(); +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java new file mode 100644 index 00000000..7e80bf6b --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java @@ -0,0 +1,12 @@ +package com.mercury.platform.shared.config; + +public class Configuration { + private static ConfigManager configManager; + + public static ConfigManager get() { + return configManager; + } + public static void set(ConfigManager configManager){ + Configuration.configManager = configManager; + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java b/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java new file mode 100644 index 00000000..515a88ca --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/DataSource.java @@ -0,0 +1,10 @@ +package com.mercury.platform.shared.config; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public abstract class DataSource { + private String configurationFilePath; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java b/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java new file mode 100644 index 00000000..536016f5 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/JSONHelper.java @@ -0,0 +1,53 @@ +package com.mercury.platform.shared.config; + +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Map; + +public class JSONHelper { + private Logger logger = LogManager.getLogger(JSONHelper.class.getSimpleName()); + private DataSource dataSource; + + public JSONHelper(DataSource dataSource){ + this.dataSource = dataSource; + } + public T readMapData(String key,TypeToken typeToken){ + try { + Gson gson = new Gson(); + JsonParser jsonParser = new JsonParser(); + try(JsonReader reader = new JsonReader(new FileReader(dataSource.getConfigurationFilePath()))) { + return gson.fromJson( + jsonParser.parse(reader) + .getAsJsonObject() + .get(key), + typeToken.getType()); + } + }catch (IOException e){ + logger.error(e); + return null; + }catch (IllegalStateException e1) { + return null; + } + } + public void writeMapObject(String key, Map object){ + try { + Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create(); + + try(JsonWriter writer = new JsonWriter(new FileWriter(dataSource.getConfigurationFilePath()))) { + JsonObject jsonObject = new JsonObject(); + jsonObject.add(key,gson.toJsonTree(object)); + gson.toJson(jsonObject,writer); + } + }catch (IOException e){ + logger.error(e); + } + + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java new file mode 100644 index 00000000..5cbb6e49 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryDataSource.java @@ -0,0 +1,10 @@ +package com.mercury.platform.shared.config; + +/** + * Created by Константин on 08.04.2017. + */ +public class MercuryDataSource extends DataSource { + public MercuryDataSource() { + super(System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\configuration.json"); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java new file mode 100644 index 00000000..6c97fa1b --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/BaseConfigurationService.java @@ -0,0 +1,15 @@ +package com.mercury.platform.shared.config.service; + +import com.mercury.platform.shared.config.DataSource; +import com.mercury.platform.shared.config.JSONHelper; + + +public abstract class BaseConfigurationService implements ConfigurationService{ + protected DataSource dataSource; + protected JSONHelper jsonHelper; + + protected BaseConfigurationService(DataSource dataSource){ + this.dataSource = dataSource; + this.jsonHelper = new JSONHelper(dataSource); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java new file mode 100644 index 00000000..ecfca38c --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/ConfigurationService.java @@ -0,0 +1,12 @@ +package com.mercury.platform.shared.config.service; + + +import java.io.IOException; +import java.util.Map; + +public interface ConfigurationService { + void load() throws IOException; + T get(K key); + Map getMap(); + void save(); +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java new file mode 100644 index 00000000..a446b205 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/FramesConfigurationService.java @@ -0,0 +1,33 @@ +package com.mercury.platform.shared.config.service; + +import com.mercury.platform.shared.config.DataSource; +import com.mercury.platform.shared.entity.FrameSettings; + +import java.util.Map; + + +public class FramesConfigurationService extends BaseConfigurationService { + public FramesConfigurationService(DataSource dataSource) { + super(dataSource); + } + + @Override + public void load() { + + } + + @Override + public FrameSettings get(String key) { + return null; + } + + @Override + public Map getMap() { + return null; + } + + @Override + public void save() { + + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java new file mode 100644 index 00000000..dd55f658 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/SoundConfigurationService.java @@ -0,0 +1,55 @@ +package com.mercury.platform.shared.config.service; + +import com.google.gson.reflect.TypeToken; +import com.mercury.platform.shared.config.DataSource; +import com.mercury.platform.shared.entity.SoundDescriptor; + +import java.util.*; + + +public class SoundConfigurationService extends BaseConfigurationService { + private static final String OBJECT_KEY = "sound"; + private Map data; + public SoundConfigurationService(DataSource dataSource) { + super(dataSource); + this.data = new HashMap<>(); + } + + @Override + public void load(){ + this.data = jsonHelper.readMapData(OBJECT_KEY, new TypeToken>() {}); + if(data == null) { + toDefault(); + } + } + + @Override + public SoundDescriptor get(String key) { + return this.data.computeIfAbsent(key, k -> getDefault().get(key)); + } + + @Override + public Map getMap() { + return this.data; + } + + @Override + public void save() { + jsonHelper.writeMapObject(OBJECT_KEY,this.data); + } + + private void toDefault(){ + Map defaultSt = getDefault(); + this.data = defaultSt; + jsonHelper.writeMapObject(OBJECT_KEY,defaultSt); + } + private Map getDefault(){ + Map defaultSettings = new HashMap<>(); + defaultSettings.put("notification",new SoundDescriptor("app/notification.wav",0f)); + defaultSettings.put("chat_scanner",new SoundDescriptor("app/chat-filter.wav",0f)); + defaultSettings.put("clicks",new SoundDescriptor("default",0f)); + defaultSettings.put("update",new SoundDescriptor("default",0f)); + return defaultSettings; + + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/CurrencyMessage.java b/app-core/src/main/java/com/mercury/platform/shared/entity/CurrencyMessage.java similarity index 83% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/CurrencyMessage.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/CurrencyMessage.java index f25382f6..fbb34569 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/CurrencyMessage.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/CurrencyMessage.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/FrameSettings.java b/app-core/src/main/java/com/mercury/platform/shared/entity/FrameSettings.java similarity index 81% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/FrameSettings.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/FrameSettings.java index e6331416..93a0cff9 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/FrameSettings.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/FrameSettings.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/ItemMessage.java b/app-core/src/main/java/com/mercury/platform/shared/entity/ItemMessage.java similarity index 76% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/ItemMessage.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/ItemMessage.java index c9c08832..421fb760 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/ItemMessage.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/ItemMessage.java @@ -1,6 +1,5 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/KeyData.java b/app-core/src/main/java/com/mercury/platform/shared/entity/KeyData.java new file mode 100644 index 00000000..4f868bfa --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/KeyData.java @@ -0,0 +1,13 @@ +package com.mercury.platform.shared.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class KeyData { + private String key; + private T data; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/Message.java b/app-core/src/main/java/com/mercury/platform/shared/entity/Message.java similarity index 86% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/Message.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/Message.java index 011813ba..73f31b21 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/Message.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/Message.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/ResponseButton.java b/app-core/src/main/java/com/mercury/platform/shared/entity/ResponseButton.java similarity index 92% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/ResponseButton.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/ResponseButton.java index 181caa92..a540cd9f 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/ResponseButton.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/ResponseButton.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/ScaleData.java b/app-core/src/main/java/com/mercury/platform/shared/entity/ScaleData.java similarity index 82% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/ScaleData.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/ScaleData.java index 10748c6a..13f0107f 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/ScaleData.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/ScaleData.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/SoundDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/entity/SoundDescriptor.java new file mode 100644 index 00000000..d4fd79a2 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/SoundDescriptor.java @@ -0,0 +1,13 @@ +package com.mercury.platform.shared.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SoundDescriptor { + private String wavPath; + private Float db; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/pojo/StashTab.java b/app-core/src/main/java/com/mercury/platform/shared/entity/StashTab.java similarity index 81% rename from app-core/src/main/java/com/mercury/platform/shared/pojo/StashTab.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/StashTab.java index c5adc82f..a852b2ee 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/pojo/StashTab.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/StashTab.java @@ -1,4 +1,4 @@ -package com.mercury.platform.shared.pojo; +package com.mercury.platform.shared.entity; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/AddInterceptorEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/AddInterceptorEvent.java deleted file mode 100644 index e7ee6a93..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/AddInterceptorEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.core.utils.interceptor.MessageInterceptor; -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class AddInterceptorEvent implements MercuryEvent { - private MessageInterceptor interceptor; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ButtonPressedEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/ButtonPressedEvent.java deleted file mode 100644 index 889bedc0..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ButtonPressedEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; - -/** - * Created by Константин on 01.03.2017. - */ -public class ButtonPressedEvent implements MercuryEvent { -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChangeFrameVisibleEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChangeFrameVisibleEvent.java deleted file mode 100644 index 5b32efaa..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChangeFrameVisibleEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.FrameStates; -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class ChangeFrameVisibleEvent implements MercuryEvent { - private FrameStates states; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatCommandEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatCommandEvent.java deleted file mode 100644 index a660274e..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatCommandEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class ChatCommandEvent implements MercuryEvent { - private String message; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatFilterMessageEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatFilterMessageEvent.java deleted file mode 100644 index 5568ca6b..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/ChatFilterMessageEvent.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; - - -public class ChatFilterMessageEvent implements MercuryEvent { -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/DndModeEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/DndModeEvent.java deleted file mode 100644 index fdb2d665..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/DndModeEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class DndModeEvent implements MercuryEvent { - private boolean dnd; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/HideLoadingFrame.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/HideLoadingFrame.java deleted file mode 100644 index fbcad6b0..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/HideLoadingFrame.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; - -public class HideLoadingFrame implements MercuryEvent { -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/NewWhispersEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/NewWhispersEvent.java deleted file mode 100644 index 05c87f81..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/NewWhispersEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.Message; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class NewWhispersEvent implements MercuryEvent { - private Message message; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/OpenChatEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/OpenChatEvent.java deleted file mode 100644 index 78b484d0..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/OpenChatEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class OpenChatEvent implements MercuryEvent { - private String whisper; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/OutTradeMessageEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/OutTradeMessageEvent.java index c1bf0762..43a5ef17 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/OutTradeMessageEvent.java +++ b/app-core/src/main/java/com/mercury/platform/shared/events/custom/OutTradeMessageEvent.java @@ -1,7 +1,7 @@ package com.mercury.platform.shared.events.custom; import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.Message; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/RemoveInterceptorEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/RemoveInterceptorEvent.java deleted file mode 100644 index de5b7c91..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/RemoveInterceptorEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.core.utils.interceptor.MessageInterceptor; -import com.mercury.platform.shared.events.MercuryEvent; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class RemoveInterceptorEvent implements MercuryEvent { - private MessageInterceptor interceptor; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/UILoadedEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/UILoadedEvent.java deleted file mode 100644 index 673b1128..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/UILoadedEvent.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mercury.platform.shared.events.custom; - -import com.mercury.platform.shared.events.MercuryEvent; - -public class UILoadedEvent implements MercuryEvent { -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/events/custom/WhisperNotificationEvent.java b/app-core/src/main/java/com/mercury/platform/shared/events/custom/WhisperNotificationEvent.java deleted file mode 100644 index 75569302..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/events/custom/WhisperNotificationEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.mercury.platform.shared.events.custom; - - -import com.mercury.platform.shared.events.MercuryEvent; - - -public class WhisperNotificationEvent implements MercuryEvent { -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/http/ItemGuard.java b/app-core/src/main/java/com/mercury/platform/shared/http/ItemGuard.java new file mode 100644 index 00000000..be255c2f --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/http/ItemGuard.java @@ -0,0 +1,4 @@ +package com.mercury.platform.shared.http; + +public class ItemGuard { +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/http/RequestBuilder.java b/app-core/src/main/java/com/mercury/platform/shared/http/RequestBuilder.java new file mode 100644 index 00000000..58f4786c --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/http/RequestBuilder.java @@ -0,0 +1,7 @@ +package com.mercury.platform.shared.http; + +/** + * Created by Константин on 07.04.2017. + */ +public class RequestBuilder { +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java b/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java new file mode 100644 index 00000000..abfe939c --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java @@ -0,0 +1,52 @@ +package com.mercury.platform.shared.store; + +import com.mercury.platform.core.AppStarter; +import com.mercury.platform.core.misc.SoundType; +import com.mercury.platform.core.misc.WhisperNotifierStatus; +import com.mercury.platform.shared.ConfigManager; +import com.mercury.platform.shared.FrameVisibleState; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.service.ConfigurationService; +import com.mercury.platform.shared.entity.SoundDescriptor; +import rx.Observable; + +import java.util.Random; + + +public class DataTransformers { + private static final ConfigurationService soundService = Configuration.get().soundConfiguration(); + public static Observable.Transformer transformSoundData() { + String[] clicks = { + "app/sounds/click1/button-pressed-10.wav", + "app/sounds/click1/button-pressed-20.wav", + "app/sounds/click1/button-pressed-30.wav"}; + return obs -> obs.map(soundType -> { + SoundDescriptor descriptor = new SoundDescriptor(); + switch (soundType){ + case MESSAGE:{ + SoundDescriptor desc = soundService.get("notification"); + WhisperNotifierStatus status = ConfigManager.INSTANCE.getWhisperNotifier(); + if (status == WhisperNotifierStatus.ALWAYS || + ((status == WhisperNotifierStatus.ALTAB) && (AppStarter.APP_STATUS == FrameVisibleState.HIDE))) { + return desc; + } + return new SoundDescriptor(desc.getWavPath(),-80f); + } + case CHAT_SCANNER: { + return soundService.get("chat_scanner"); + } + case CLICKS: { + descriptor.setWavPath(clicks[new Random().nextInt(3)]); + descriptor.setDb(soundService.get("clicks").getDb()); + break; + } + case UPDATE: { + descriptor.setWavPath("app/patch_tone.wav"); + descriptor.setDb(soundService.get("update").getDb()); + break; + } + } + return descriptor; + }); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStore.java b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStore.java new file mode 100644 index 00000000..86917178 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStore.java @@ -0,0 +1,28 @@ +package com.mercury.platform.shared.store; + +import com.mercury.platform.core.misc.SoundType; +import com.mercury.platform.core.utils.interceptor.MessageInterceptor; +import com.mercury.platform.shared.FrameVisibleState; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.entity.SoundDescriptor; +import rx.subjects.PublishSubject; + + +public class MercuryStore { + private static class MercuryStoreHolder { + static final MercuryStore HOLDER_INSTANCE = new MercuryStore(); + } + public static MercuryStore INSTANCE = MercuryStoreHolder.HOLDER_INSTANCE; + + public final PublishSubject soundSubject = PublishSubject.create(); + public final PublishSubject soundSettingsSubject = PublishSubject.create(); + public final PublishSubject dndSubject = PublishSubject.create(); + public final PublishSubject frameVisibleSubject = PublishSubject.create(); + public final PublishSubject uiLoadedSubject = PublishSubject.create(); + public final PublishSubject addInterceptorSubject = PublishSubject.create(); + public final PublishSubject removeInterceptorSubject = PublishSubject.create(); + public final PublishSubject chatCommandSubject = PublishSubject.create(); + public final PublishSubject openChatSubject = PublishSubject.create(); + public final PublishSubject messageSubject = PublishSubject.create(); + public final PublishSubject appLoadingSubject = PublishSubject.create(); +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/Reducer.java b/app-core/src/main/java/com/mercury/platform/shared/store/Reducer.java new file mode 100644 index 00000000..4fe761d1 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/store/Reducer.java @@ -0,0 +1,16 @@ +package com.mercury.platform.shared.store; + +import lombok.Getter; +import rx.subjects.PublishSubject; + + +public class Reducer { + @Getter + private String key; + @Getter + private PublishSubject subject; + protected Reducer(String key){ + this.key = key; + this.subject = PublishSubject.create(); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/mock/DataTransformersMock.java b/app-core/src/main/java/com/mercury/platform/shared/store/mock/DataTransformersMock.java new file mode 100644 index 00000000..003e70b1 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/store/mock/DataTransformersMock.java @@ -0,0 +1,8 @@ +package com.mercury.platform.shared.store.mock; + +/** + * Created by Константин on 08.04.2017. + */ +public class DataTransformersMock { + +} diff --git a/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java b/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java index 28970bae..6f11b6d7 100644 --- a/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java +++ b/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java @@ -1,7 +1,7 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.pojo.CurrencyMessage; -import com.mercury.platform.shared.pojo.ItemMessage; +import com.mercury.platform.shared.entity.CurrencyMessage; +import com.mercury.platform.shared.entity.ItemMessage; import org.junit.Before; import org.junit.Test; diff --git a/app-core/src/test/java/com/mercury/platform/shared/store/MercuryStoreTest.java b/app-core/src/test/java/com/mercury/platform/shared/store/MercuryStoreTest.java new file mode 100644 index 00000000..0bbfc9af --- /dev/null +++ b/app-core/src/test/java/com/mercury/platform/shared/store/MercuryStoreTest.java @@ -0,0 +1,24 @@ +package com.mercury.platform.shared.store; + +import com.mercury.platform.shared.entity.KeyData; +import com.mercury.platform.shared.entity.SoundDescriptor; +import org.junit.Test; +import rx.observers.TestSubscriber; + +import java.awt.*; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class MercuryStoreTest { + @Test + public void testSoundReducer() throws IOException { + TestSubscriber> testSubscriber = new TestSubscriber<>(); + } +} \ No newline at end of file diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java index 5c1fd2d3..c10ea946 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java @@ -1,8 +1,9 @@ package com.mercury.platform.ui.components; +import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ButtonPressedEvent; import com.mercury.platform.shared.events.custom.HideTooltipEvent; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.misc.event.ShowTooltipEvent; import com.mercury.platform.ui.components.fields.style.MercuryComboBoxUI; import com.mercury.platform.ui.components.fields.font.FontStyle; @@ -21,6 +22,7 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; import java.awt.image.BufferedImage; import java.io.IOException; @@ -83,7 +85,7 @@ protected void paintBorder(Graphics g) { @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { - EventRouter.CORE.fireEvent(new ButtonPressedEvent()); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.CLICKS); } } }); @@ -196,7 +198,7 @@ public void mousePressed(MouseEvent e) { @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { - EventRouter.CORE.fireEvent(new ButtonPressedEvent()); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.CLICKS); } } }); @@ -374,6 +376,7 @@ public JTextField getTextField(String text, FontStyle style, float fontSize){ textField.setFont(getSelectedFont(style).deriveFont(scale*fontSize)); } textField.setForeground(AppThemeColor.TEXT_DEFAULT); + textField.setCaretColor(AppThemeColor.TEXT_DEFAULT); textField.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.TEXT_DEFAULT,1), BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,3) @@ -475,6 +478,28 @@ public JSlider getSlider(int min, int max, int value){ JSlider slider = new JSlider(JSlider.HORIZONTAL,min,max,value); slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); + slider.addMouseMotionListener(new MouseMotionAdapter() { + @Override + public void mouseDragged(MouseEvent e) { + slider.getParent().repaint(); + } + }); + slider.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + slider.getParent().repaint(); + } + + @Override + public void mousePressed(MouseEvent e) { + slider.getParent().repaint(); + } + + @Override + public void mouseReleased(MouseEvent e) { + slider.getParent().repaint(); + } + }); slider.setBackground(AppThemeColor.TRANSPARENT); return slider; } @@ -517,7 +542,7 @@ public ImageIcon getImage(String iconPath){ public Dimension convertSize(Dimension initialSize){ return new Dimension((int)(initialSize.width * scale),(int)(initialSize.height*scale)); } - public JTextArea getSimpleTextAre(String text){ + public JTextArea getSimpleTextArea(String text){ JTextArea area = new JTextArea(text); area.setEditable(false); area.setWrapStyleWord(true); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java index 002371a8..6a5925c5 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java @@ -1,15 +1,11 @@ package com.mercury.platform.ui.components; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.TooltipConstants; import lombok.NonNull; import javax.swing.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; //todo generic for components constructor public class ControlsFactory { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatFilterPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatFilterPanel.java index 9609d663..3b2ca3cc 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatFilterPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatFilterPanel.java @@ -1,7 +1,8 @@ package com.mercury.platform.ui.components.panel.chat; +import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatFilterMessageEvent; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; @@ -112,7 +113,7 @@ private void addMessageToFilter(String message) { expiresMessages.put(nickname,message); EventRouter.UI.fireEvent(new PackEvent.PackChatFilter()); if(soundEnable){ - EventRouter.CORE.fireEvent(new ChatFilterMessageEvent()); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.CHAT_SCANNER); } if(scrollToBottom) { container.scrollRectToVisible(new Rectangle(0, container.getHeight() - 1, 1, 1)); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatMessagePanel.java index 52df271e..a180d948 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatMessagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatMessagePanel.java @@ -1,8 +1,7 @@ package com.mercury.platform.ui.components.panel.chat; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; -import com.mercury.platform.shared.events.custom.OpenChatEvent; +import com.mercury.platform.shared.ConfigManager; +import com.mercury.platform.shared.store.MercuryStore; 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; @@ -46,12 +45,12 @@ public void createUI() { JPanel miscPanel = componentsFactory.getTransparentPanel(new BorderLayout()); JPanel operationsPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - JButton invite = componentsFactory.getIconButton("app/invite.png", 16, AppThemeColor.SLIDE_BG, TooltipConstants.INVITE); - invite.addMouseListener(new MouseAdapter() { + JButton quickResponse = componentsFactory.getIconButton("app/chat_scanner_response.png", 17, AppThemeColor.SLIDE_BG, "Quick response"); + quickResponse.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/invite " + nickName)); + MercuryStore.INSTANCE.chatCommandSubject.onNext("@" + nickName + " " + ConfigManager.INSTANCE.getQuickResponse()); } } }); @@ -60,7 +59,7 @@ public void mousePressed(MouseEvent e) { @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { - EventRouter.CORE.fireEvent(new OpenChatEvent(nickName)); + MercuryStore.INSTANCE.openChatSubject.onNext(nickName); } } }); @@ -74,9 +73,9 @@ public void mousePressed(MouseEvent e) { nickName); nicknameLabel.setPreferredSize(new Dimension(75,nicknameLabel.getPreferredSize().height)); nicknameLabel.setBorder(null); - invite.setBorder(null); + quickResponse.setBorder(null); openChat.setBorder(null); - operationsPanel.add(invite); + operationsPanel.add(quickResponse); operationsPanel.add(openChat); JPanel nicknamePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/HtmlMessageBuilder.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/HtmlMessageBuilder.java index defe315c..2ab32b73 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/HtmlMessageBuilder.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/HtmlMessageBuilder.java @@ -17,11 +17,10 @@ public HtmlMessageBuilder() { * @param message source message * @return html equivalent */ - //RED - Navy public String build(String message) { List resultStrs = new ArrayList<>(); resultStrs.add(""); - String[] words = message.split("((?<= )|(?= )|(?<=\\.)|(?=\\.)|(?<=,)|(?<=\\?)|(?=\\?)|(?=,)|(?<=!)|(?=!)|(?<=/)|(?=/)|(?<=>)|(?=>))"); + String[] words = message.split("((?<=\\s)|(?=\\s)|(?<=\\.)|(?=\\.)|(?<=,)|(?<=\\?)|(?=\\?)|(?=,)|(?<=!)|(?=!)|(?<=/)|(?=/)|(?<=>)|(?=>))"); Arrays.stream(words).forEach(word -> { if(chunkStrings.stream().noneMatch(word::equalsIgnoreCase)){ resultStrs.add(word); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java index 274acada..cc7a69b1 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java @@ -1,14 +1,12 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.pojo.StashTab; +import com.mercury.platform.shared.entity.StashTab; import com.mercury.platform.ui.misc.TooltipConstants; -import com.mercury.platform.ui.misc.event.CloseGridItemEvent; -import com.mercury.platform.shared.pojo.ItemMessage; +import com.mercury.platform.shared.entity.ItemMessage; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.panel.misc.HasUI; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.event.ItemCellStateChangedEvent; import com.mercury.platform.ui.misc.event.RepaintEvent; import javax.swing.*; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelControllerImpl.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelControllerImpl.java index 09d6c088..e972c3db 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelControllerImpl.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelControllerImpl.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.pojo.ItemMessage; +import com.mercury.platform.shared.entity.ItemMessage; import com.mercury.platform.ui.misc.event.CloseGridItemEvent; import com.mercury.platform.ui.misc.event.ItemCellStateChangedEvent; import lombok.NonNull; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemsGridPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemsGridPanel.java index d4d7141b..5f73c512 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemsGridPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemsGridPanel.java @@ -1,8 +1,8 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.StashTab; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.StashTab; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.panel.misc.HasUI; import com.mercury.platform.ui.misc.AppThemeColor; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java index 92febb66..1ea98da6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.pojo.StashTab; +import com.mercury.platform.shared.entity.StashTab; import java.util.List; public class StashTabsContainer { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/TabInfoPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/TabInfoPanel.java index 6a63f11c..a519ff8c 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/TabInfoPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/TabInfoPanel.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.pojo.StashTab; +import com.mercury.platform.shared.entity.StashTab; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.misc.HasUI; 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 e029a27c..ecddff0d 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 @@ -5,10 +5,10 @@ import com.mercury.platform.shared.HasEventHandlers; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; -import com.mercury.platform.shared.pojo.CurrencyMessage; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; -import com.mercury.platform.shared.pojo.ResponseButton; +import com.mercury.platform.shared.entity.CurrencyMessage; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.entity.ResponseButton; 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; @@ -236,7 +236,7 @@ private JPanel getCurrencyRatePanel(){ Double currForSaleCount = message.getCurrForSaleCount(); Double curCount = message.getCurCount(); double rate = curCount / currForSaleCount; - DecimalFormat decimalFormat = new DecimalFormat("#.##"); + 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,"(")); 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 new file mode 100644 index 00000000..0225fa0b --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java @@ -0,0 +1,6 @@ +package com.mercury.platform.ui.components.panel.message; + + +public class MessagePanelBuilder { + +} 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 72bb1cd7..2e41f0af 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 @@ -1,10 +1,9 @@ package com.mercury.platform.ui.components.panel.message; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; -import com.mercury.platform.shared.events.custom.OpenChatEvent; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.misc.event.*; import lombok.NonNull; import org.apache.logging.log4j.LogManager; @@ -13,10 +12,8 @@ import javax.swing.*; import java.awt.*; import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; + //todo proxy public class NotificationMessageController implements MessagePanelController { private static final Logger log = LogManager.getLogger(NotificationMessageController.class); @@ -27,30 +24,29 @@ public NotificationMessageController(Message message){ } @Override public void performInvite() { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/invite " + message.getWhisperNickname())); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/invite " + message.getWhisperNickname()); showITH(); } @Override public void performKick() { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/kick " + message.getWhisperNickname())); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/kick " + message.getWhisperNickname()); } @Override public void performOfferTrade() { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/tradewith " + message.getWhisperNickname())); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/tradewith " + message.getWhisperNickname()); } @Override public void performOpenChat() { - EventRouter.CORE.fireEvent(new OpenChatEvent(message.getWhisperNickname())); + MercuryStore.INSTANCE.openChatSubject.onNext(message.getWhisperNickname()); } @Override public void performResponse(@NonNull String responseText) { - - EventRouter.CORE.fireEvent(new ChatCommandEvent("@" + message.getWhisperNickname() + " " + responseText)); + MercuryStore.INSTANCE.chatCommandSubject.onNext("@" + message.getWhisperNickname() + " " + responseText); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/CustomButtonSettings.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/CustomButtonSettings.java index fb194483..985b50ec 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/CustomButtonSettings.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/CustomButtonSettings.java @@ -3,7 +3,7 @@ import com.mercury.platform.shared.ConfigManager; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.CustomButtonsChangedEvent; -import com.mercury.platform.shared.pojo.ResponseButton; +import com.mercury.platform.shared.entity.ResponseButton; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; import com.mercury.platform.ui.misc.AppThemeColor; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/GeneralSettings.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/GeneralSettings.java index 9dae7cb4..ecc2ebe8 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/GeneralSettings.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/GeneralSettings.java @@ -6,7 +6,7 @@ import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.frame.ComponentFrame; +import com.mercury.platform.ui.frame.AbstractComponentFrame; import com.mercury.platform.ui.frame.titled.NotesFrame; import com.mercury.platform.ui.frame.titled.SettingsFrame; import com.mercury.platform.ui.frame.titled.TestCasesFrame; @@ -29,11 +29,11 @@ public class GeneralSettings extends ConfigurationPanel { private JSlider fadeTimeSlider; //private JComboBox secondsPicker; private JComboBox notifierStatusPicker; - private ComponentFrame owner; + private AbstractComponentFrame owner; private JCheckBox checkEnable; private JTextField gamePathField; private WrongGamePathListener poeFolderTooltipListener; - public GeneralSettings(ComponentFrame owner) { + public GeneralSettings(AbstractComponentFrame owner) { super(); this.owner = owner; createUI(); @@ -211,7 +211,7 @@ private JPanel getSettingsSlidePanel(){ componentsFactory.getIconButton("app/open-tests.png", 30, AppThemeColor.TRANSPARENT, - "Test frames"); + "Open tests"); openTests.addActionListener(action -> { FramesManager.INSTANCE.hideFrame(SettingsFrame.class); FramesManager.INSTANCE.preShowFrame(TestCasesFrame.class); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/HelpPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/HelpPanel.java index 44ad6e24..b33cebe2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/HelpPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/HelpPanel.java @@ -60,7 +60,7 @@ public void mouseClicked(MouseEvent e) { NotesLoader notesLoader = new NotesLoader(); java.util.List patchNotes = notesLoader.getPatchNotes(); if(patchNotes.size() != 0){ - NotesFrame patchNotesFrame = new NotesFrame(patchNotes,NotesFrame.NotesType.PATCH); + NotesFrame patchNotesFrame = new NotesFrame(patchNotes, NotesFrame.NotesType.PATCH); patchNotesFrame.init(); patchNotesFrame.showComponent(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SoundSettingsPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SoundSettingsPanel.java new file mode 100644 index 00000000..005d5682 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SoundSettingsPanel.java @@ -0,0 +1,190 @@ +package com.mercury.platform.ui.components.panel.settings; + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.entity.SoundDescriptor; +import com.mercury.platform.shared.store.MercuryStore; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.misc.AppThemeColor; + +import javax.swing.*; +import javax.swing.border.CompoundBorder; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.Map; + +public class SoundSettingsPanel extends ConfigurationPanel { + private Map wavPaths; + + private JSlider notificationSlider; + private JSlider chatScannerSlider; + private JSlider clicksSlider; + private JSlider updateSlider; + + public SoundSettingsPanel() { + super(); + this.wavPaths = new HashMap<>(); + this.wavPaths.put("notification","app/notification.wav"); + this.wavPaths.put("chat_scanner","app/chat-filter.wav"); + this.wavPaths.put("clicks","app/sounds/click1/button-pressed-10.wav"); + this.wavPaths.put("update","app/patch_tone.wav"); + this.createUI(); + } + + @Override + public void createUI() { + verticalScrollContainer.add(getVolumePanel()); + verticalScrollContainer.add(getSoundPickerPanel()); + } + + private JPanel getVolumePanel(){ + Map map = Configuration.get().soundConfiguration().getMap(); + + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + + JLabel volumeLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 17f, "Volume"); + volumeLabel.setBorder( + new CompoundBorder( + BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER), + BorderFactory.createEmptyBorder(3,5,3,5))); + + + JPanel container = componentsFactory.getTransparentPanel(new GridLayout(4, 2)); + container.setBackground(AppThemeColor.SETTINGS_BG); + container.setBorder(new CompoundBorder( + BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER), + BorderFactory.createEmptyBorder(3,0,3,0))); + + notificationSlider = componentsFactory.getSlider(-40, 6, map.get("notification").getDb().intValue()); + notificationSlider.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + MercuryStore.INSTANCE.soundSettingsSubject.onNext(new SoundDescriptor( + wavPaths.get("notification"), + notificationSlider.getValue() == -40 ? -80f : (float)notificationSlider.getValue() + )); + } + }); + chatScannerSlider = componentsFactory.getSlider(-40, 6, map.get("chat_scanner").getDb().intValue()); + chatScannerSlider.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + MercuryStore.INSTANCE.soundSettingsSubject.onNext(new SoundDescriptor( + wavPaths.get("chat_scanner"), + chatScannerSlider.getValue() == -40 ? -80f : (float)chatScannerSlider.getValue() + )); + } + }); + clicksSlider = componentsFactory.getSlider(-40, 6, map.get("clicks").getDb().intValue()); + clicksSlider.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + MercuryStore.INSTANCE.soundSettingsSubject.onNext(new SoundDescriptor( + wavPaths.get("clicks"), + clicksSlider.getValue() == -40 ? -80f : (float)clicksSlider.getValue() + )); + } + }); + updateSlider = componentsFactory.getSlider(-40, 6, map.get("update").getDb().intValue()); + updateSlider.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + MercuryStore.INSTANCE.soundSettingsSubject.onNext(new SoundDescriptor( + wavPaths.get("update"), + updateSlider.getValue() == -40 ? -80f : (float)updateSlider.getValue() + )); + } + }); + container.add(componentsFactory.getTextLabel("Notification:",FontStyle.REGULAR)); + container.add(notificationSlider); + container.add(componentsFactory.getTextLabel("Chat Scanner",FontStyle.REGULAR)); + container.add(chatScannerSlider); + container.add(componentsFactory.getTextLabel("Clicks",FontStyle.REGULAR)); + container.add(clicksSlider); + container.add(componentsFactory.getTextLabel("Update notification",FontStyle.REGULAR)); + container.add(updateSlider); + + root.add(volumeLabel,BorderLayout.PAGE_START); + root.add(container,BorderLayout.CENTER); + return root; + } + + private JPanel getSoundPickerPanel(){ + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + + JLabel soundLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 17f, "Sound (in next update)"); + soundLabel.setBorder( + new CompoundBorder( + BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER), + BorderFactory.createEmptyBorder(3,5,3,5))); + +// JPanel container = componentsFactory.getTransparentPanel(new GridLayout(2, 2,0,1)); +// container.setBackground(AppThemeColor.SETTINGS_BG); +// container.setBorder(new CompoundBorder( +// BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER), +// BorderFactory.createEmptyBorder(3,0,3,0))); +// +// JComboBox notificationComboBox = componentsFactory.getComboBox(new String[]{"Mercury Notification", "Mercury Chat Scanner", "Browse"}); +// notificationComboBox.addItemListener(e -> { +// switch (e.getStateChange()){ +// case ItemEvent.SELECTED: { +// if(notificationComboBox.getSelectedItem().equals("Browse")){ +// JFileChooser fileChooser = new JFileChooser(); +// fileChooser.setFileFilter(new FileNameExtensionFilter("*.wav","wav")); +// int returnVal = fileChooser.showOpenDialog(null); +// if(returnVal == JFileChooser.APPROVE_OPTION) { +// System.out.println(fileChooser.getSelectedFile().getPath()); +// } +// } +// break; +// } +// } +// }); +// +// +// JComboBox chatScannerComboBox = componentsFactory.getComboBox(new String[]{"Mercury Notification", "Mercury Chat Scanner", "Browse"}); +// +// +// container.add(componentsFactory.getTextLabel("Notification:",FontStyle.REGULAR)); +// container.add(notificationComboBox); +// container.add(componentsFactory.getTextLabel("Chat Scanner",FontStyle.REGULAR)); +// container.add(chatScannerComboBox); + root.add(soundLabel,BorderLayout.PAGE_START); +// root.add(container,BorderLayout.CENTER); + + return root; + } + + + @Override + public boolean processAndSave() { + Map map = Configuration.get().soundConfiguration().getMap(); + map.get("notification") + .setDb((float)notificationSlider.getValue()); + map.get("chat_scanner") + .setDb((float)chatScannerSlider.getValue()); + map.get("clicks") + .setDb((float)clicksSlider.getValue()); + map.get("update") + .setDb((float)updateSlider.getValue()); + Configuration.get().soundConfiguration().save(); + return true; + } + + @Override + public void restore() { + Map map = Configuration.get().soundConfiguration().getMap(); + notificationSlider.setValue( + map.get("notification").getDb().intValue()); + chatScannerSlider.setValue( + map.get("chat_scanner").getDb().intValue()); + clicksSlider.setValue( + map.get("clicks").getDb().intValue()); + updateSlider.setValue( + map.get("update").getDb().intValue()); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SupportPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SupportPanel.java index 813cc64d..0131af77 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SupportPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/SupportPanel.java @@ -1,53 +1,128 @@ package com.mercury.platform.ui.components.panel.settings; +import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; +import com.mercury.platform.ui.components.panel.VerticalScrollContainer; import com.mercury.platform.ui.components.panel.misc.HasUI; import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.event.RepaintEvent; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.IOException; +import java.awt.event.MouseWheelEvent; import java.net.URI; -import java.net.URISyntaxException; +import java.util.*; +import java.util.List; -/** - * Created by Константин on 11.02.2017. - */ public class SupportPanel extends JPanel implements HasUI{ private ComponentsFactory componentsFactory; public SupportPanel() { super(); componentsFactory = new ComponentsFactory(); - this.setBackground(AppThemeColor.TRANSPARENT); + this.setBackground(AppThemeColor.SLIDE_BG); createUI(); } @Override public void createUI() { - this.setLayout(new FlowLayout(FlowLayout.CENTER)); - JPanel donatePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + this.setLayout(new BorderLayout()); + + JPanel donatePanel = componentsFactory.getTransparentPanel(); + donatePanel.setLayout(new BoxLayout(donatePanel,BoxLayout.Y_AXIS)); + donatePanel.setBackground(AppThemeColor.SLIDE_BG); + JButton donate = componentsFactory.getIconifiedTransparentButton("app/paypal.png","Donate"); + donate.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); donate.setBackground(AppThemeColor.SLIDE_BG); donate.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + donate.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); + } + + @Override + public void mouseExited(MouseEvent e) { + donate.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + } + @Override public void mousePressed(MouseEvent e) { try { - Desktop.getDesktop().browse(new URI("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=HJVSYP4YR7V88&lc=US&item_name=MercuryTrade¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted")); - } catch (IOException e1) { - e1.printStackTrace(); - } catch (URISyntaxException e1) { + Desktop.getDesktop().browse(new URI("https://www.paypal.me/mercurytrade")); + } catch (Exception e1) { e1.printStackTrace(); } } }); - donatePanel.add(donate); - this.add(donatePanel); - JTextArea donateText = componentsFactory.getSimpleTextAre("We aimed to create a convenience tool in form of an easy-to-use application, primarily for trading purposes. If MercuryTrade successfully managed to save your time or improve your experience, you can thank us by donating and telling your friends."); + JTextArea donateText = componentsFactory.getSimpleTextArea("We aimed to create a convenience tool in form of an easy-to-use application, primarily for trading purposes. If MercuryTrade successfully managed to save your time or improve your experience, you can thank us by donating and telling your friends."); donateText.setPreferredSize(new Dimension(300,150)); JPanel donateTextPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + JPanel donateButtonPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + donateButtonPanel.setBorder(BorderFactory.createEmptyBorder(30,0,0,0)); donateTextPanel.add(donateText); - this.add(donateTextPanel); + donateButtonPanel.add(donate); + donatePanel.add(donateButtonPanel); + donatePanel.add(donateTextPanel); + this.add(donatePanel,BorderLayout.CENTER); + this.add(getDonationsPanel(),BorderLayout.LINE_END); + } + private JPanel getDonationsPanel() { + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + root.setBorder(BorderFactory.createEmptyBorder(20,0,10,20)); + root.add(componentsFactory.getTextLabel("Thanks a lot for support: "),BorderLayout.PAGE_START); + + JPanel donationsList = new VerticalScrollContainer(); + donationsList.setBackground(AppThemeColor.TRANSPARENT); + donationsList.setLayout(new BoxLayout(donationsList,BoxLayout.Y_AXIS)); + + JScrollPane scrollPane = new JScrollPane(donationsList); + scrollPane.setBorder(null); + scrollPane.setBackground(AppThemeColor.FRAME); + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane.addMouseWheelListener(new MouseAdapter() { + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + EventRouter.UI.fireEvent(new RepaintEvent.RepaintSettingFrame()); + } + }); + JScrollBar vBar = scrollPane.getVerticalScrollBar(); + vBar.setBackground(AppThemeColor.SLIDE_BG); + vBar.setUI(new MercuryScrollBarUI()); + vBar.setPreferredSize(new Dimension(14, Integer.MAX_VALUE)); + vBar.setUnitIncrement(3); + vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,2)); + vBar.addAdjustmentListener(e -> repaint()); + donationsList.getParent().setBackground(AppThemeColor.TRANSPARENT); + + getDonations().forEach(pair -> { + JPanel item = componentsFactory.getTransparentPanel(new BorderLayout()); + item.add(componentsFactory.getTextLabel(pair.name, FontStyle.REGULAR),BorderLayout.CENTER); +// item.add(componentsFactory.getTextLabel(pair.value.intValue() + "$", FontStyle.REGULAR),BorderLayout.LINE_END); + donationsList.add(item); + }); + + root.add(scrollPane,BorderLayout.CENTER); + return root; + } + private List getDonations(){ + List donations = new ArrayList<>(); + donations.add(new DonationPair("StubenZocker",0d)); + donations.add(new DonationPair("x8 Anonymus",0d)); + return donations; + } + + private class DonationPair{ + private String name; + private Double value; + + DonationPair(String name, Double value) { + this.name = name; + this.value = value; + } } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java index 0d6e7d96..0f0e1a86 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java @@ -1,9 +1,8 @@ package com.mercury.platform.ui.components.panel.taskbar; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; -import com.mercury.platform.shared.events.custom.DndModeEvent; import com.mercury.platform.shared.events.custom.NotificationEvent; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.frame.titled.chat.ChatFilterFrame; import com.mercury.platform.ui.frame.titled.container.HistoryFrame; @@ -16,14 +15,14 @@ public class MercuryTaskBarController implements TaskBarController { public void enableDND() { EventRouter.UI.fireEvent(new RepaintEvent.RepaintTaskBar()); EventRouter.UI.fireEvent(new NotificationEvent("DND on")); - EventRouter.CORE.fireEvent(new DndModeEvent(true)); + MercuryStore.INSTANCE.dndSubject.onNext(true); } @Override public void disableDND() { EventRouter.UI.fireEvent(new RepaintEvent.RepaintTaskBar()); EventRouter.UI.fireEvent(new NotificationEvent("DND off")); - EventRouter.CORE.fireEvent(new DndModeEvent(false)); + MercuryStore.INSTANCE.dndSubject.onNext(false); } @Override @@ -33,7 +32,7 @@ public void showITH() { @Override public void performHideout() { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/hideout")); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/hideout"); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/ComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java similarity index 75% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/ComponentFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java index 9056d9ea..2501bf49 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/ComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java @@ -1,7 +1,6 @@ package com.mercury.platform.ui.frame; -import com.mercury.platform.shared.pojo.FrameSettings; -import com.mercury.platform.ui.frame.movable.TaskBarFrame; +import com.mercury.platform.shared.entity.FrameSettings; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.manager.HideSettingsManager; import org.pushingpixels.trident.Timeline; @@ -13,7 +12,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; -public abstract class ComponentFrame extends OverlaidFrame{ +public abstract class AbstractComponentFrame extends AbstractOverlaidFrame { private final int HIDE_TIME = 200; private final int SHOW_TIME = 150; private final int BORDER_THICKNESS = 1; @@ -36,7 +35,7 @@ public abstract class ComponentFrame extends OverlaidFrame{ protected boolean processEResize = true; protected boolean processHideEffect = true; - protected ComponentFrame(String title) { + protected AbstractComponentFrame(String title) { super(title); } @@ -105,25 +104,25 @@ public void onLocationChange(Point location){ configManager.saveFrameLocation(this.getClass().getSimpleName(),location); } protected void onFrameDragged(Point location){ - ComponentFrame.this.setLocation(location); + AbstractComponentFrame.this.setLocation(location); } private class ResizeByWidthMouseMotionListener extends MouseMotionAdapter{ @Override public void mouseDragged(MouseEvent e) { if(EResizeSpace) { - Point frameLocation = ComponentFrame.this.getLocation(); - ComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, ComponentFrame.this.getHeight())); + Point frameLocation = AbstractComponentFrame.this.getLocation(); + AbstractComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, AbstractComponentFrame.this.getHeight())); }else if(SEResizeSpace){ - Point frameLocation = ComponentFrame.this.getLocation(); - ComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, e.getLocationOnScreen().y - frameLocation.y)); + Point frameLocation = AbstractComponentFrame.this.getLocation(); + AbstractComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, e.getLocationOnScreen().y - frameLocation.y)); } } @Override public void mouseMoved(MouseEvent e) { - int frameWidth = ComponentFrame.this.getWidth(); - int frameHeight = ComponentFrame.this.getHeight(); - Point frameLocation = ComponentFrame.this.getLocation(); + int frameWidth = AbstractComponentFrame.this.getWidth(); + int frameHeight = AbstractComponentFrame.this.getHeight(); + Point frameLocation = AbstractComponentFrame.this.getLocation(); Rectangle ERect = new Rectangle( frameLocation.x + frameWidth - (BORDER_THICKNESS + 8), frameLocation.y,BORDER_THICKNESS+8,frameHeight); @@ -133,18 +132,18 @@ public void mouseMoved(MouseEvent e) { if(processEResize && ERect.getBounds().contains(e.getLocationOnScreen())) { if(processSEResize && SERect.getBounds().contains(e.getLocationOnScreen())){ - ComponentFrame.this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR)); + AbstractComponentFrame.this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR)); SEResizeSpace = true; EResizeSpace = false; }else { - ComponentFrame.this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR)); + AbstractComponentFrame.this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR)); EResizeSpace = true; SEResizeSpace = false; } }else { EResizeSpace = false; SEResizeSpace = false; - ComponentFrame.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + AbstractComponentFrame.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } @@ -154,19 +153,19 @@ public void mouseReleased(MouseEvent e) { if(hideAnimationEnable && !isMouseWithInFrame()) { hideTimer.start(); } - Dimension size = ComponentFrame.this.getSize(); + Dimension size = AbstractComponentFrame.this.getSize(); if(EResizeSpace){ - ComponentFrame.this.setMaximumSize(size); - ComponentFrame.this.setMinimumSize(size); - if(ComponentFrame.this.getClass().getSimpleName().equals("IncMessageFrame")){ - configManager.saveFrameSize(ComponentFrame.this.getClass().getSimpleName(),new Dimension(size.width,0)); + AbstractComponentFrame.this.setMaximumSize(size); + AbstractComponentFrame.this.setMinimumSize(size); + if(AbstractComponentFrame.this.getClass().getSimpleName().equals("IncMessageFrame")){ + configManager.saveFrameSize(AbstractComponentFrame.this.getClass().getSimpleName(),new Dimension(size.width,0)); }else { - configManager.saveFrameSize(ComponentFrame.this.getClass().getSimpleName(), size); + configManager.saveFrameSize(AbstractComponentFrame.this.getClass().getSimpleName(), size); } }else if(SEResizeSpace){ - ComponentFrame.this.setMinimumSize(size); - ComponentFrame.this.setMaximumSize(size); - configManager.saveFrameSize(ComponentFrame.this.getClass().getSimpleName(),ComponentFrame.this.getSize()); + AbstractComponentFrame.this.setMinimumSize(size); + AbstractComponentFrame.this.setMaximumSize(size); + configManager.saveFrameSize(AbstractComponentFrame.this.getClass().getSimpleName(),AbstractComponentFrame.this.getSize()); } EResizeSpace = false; SEResizeSpace = false; @@ -174,14 +173,14 @@ public void mouseReleased(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { - ComponentFrame.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + AbstractComponentFrame.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } @Override public void mousePressed(MouseEvent e) { if(EResizeSpace || SEResizeSpace) { - Dimension size = configManager.getMinimumFrameSize(ComponentFrame.this.getClass().getSimpleName()); - ComponentFrame.this.setMinimumSize(size); + Dimension size = configManager.getMinimumFrameSize(AbstractComponentFrame.this.getClass().getSimpleName()); + AbstractComponentFrame.this.setMinimumSize(size); } } } @@ -199,9 +198,9 @@ public HideEffectListener(){ } @Override public void mouseEntered(MouseEvent e) { - ComponentFrame.this.repaint(); + AbstractComponentFrame.this.repaint(); hideTimer.stop(); - if(ComponentFrame.this.getOpacity() < maxOpacity) { + if(AbstractComponentFrame.this.getOpacity() < maxOpacity) { showAnimation.play(); } } @@ -220,7 +219,7 @@ public void mouseExited(MouseEvent e) { public class DraggedFrameMotionListener extends MouseAdapter { @Override public void mouseDragged(MouseEvent e) { - e.translatePoint(ComponentFrame.this.getLocation().x - x,ComponentFrame.this.getLocation().y - y); + e.translatePoint(AbstractComponentFrame.this.getLocation().x - x,AbstractComponentFrame.this.getLocation().y - y); onFrameDragged(new Point(e.getX(),e.getY())); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/OverlaidFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java similarity index 50% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/OverlaidFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java index 934cee86..450078b6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/OverlaidFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java @@ -1,11 +1,9 @@ package com.mercury.platform.ui.frame; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.HasEventHandlers; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.MercuryEventHandler; -import com.mercury.platform.shared.events.custom.ChangeFrameVisibleEvent; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.misc.AppThemeColor; @@ -14,15 +12,15 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public abstract class OverlaidFrame extends JFrame implements HasEventHandlers{ - protected FrameStates prevState; +public abstract class AbstractOverlaidFrame extends JFrame implements HasEventHandlers{ + protected FrameVisibleState prevState; protected boolean processingHideEvent = true; protected ComponentsFactory componentsFactory; protected ConfigManager configManager = ConfigManager.INSTANCE; protected LayoutManager layout; - protected OverlaidFrame(String title){ + protected AbstractOverlaidFrame(String title){ super(title); this.componentsFactory = new ComponentsFactory(); getRootPane().setOpaque(false); @@ -34,45 +32,42 @@ protected OverlaidFrame(String title){ setFocusable(false); setAlwaysOnTop(true); setVisible(false); - this.prevState = FrameStates.HIDE; + this.prevState = FrameVisibleState.HIDE; this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { - OverlaidFrame.this.repaint(); + AbstractOverlaidFrame.this.repaint(); } }); - EventRouter.CORE.registerHandler(ChangeFrameVisibleEvent.class, new MercuryEventHandler() { - @Override - public void handle(ChangeFrameVisibleEvent event) { - if(!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(()-> changeVisible(event.getStates())); - }else { - changeVisible(event.getStates()); - } + MercuryStore.INSTANCE.frameVisibleSubject.subscribe(state -> { + if(!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeLater(()-> changeVisible(state)); + }else { + changeVisible(state); } - private void changeVisible(FrameStates state){ - if (processingHideEvent) { - switch (state) { - case SHOW: { - if (prevState.equals(FrameStates.SHOW)) { - showComponent(); - } - } - break; - case HIDE: { - if (OverlaidFrame.this.isVisible()) { - prevState = FrameStates.SHOW; - }else { - prevState = FrameStates.HIDE; - } - hideComponent(); - } - break; + }); + } + protected void changeVisible(FrameVisibleState state){ + if (processingHideEvent) { + switch (state) { + case SHOW: { + if (prevState.equals(FrameVisibleState.SHOW)) { + showComponent(); } } + break; + case HIDE: { + if (AbstractOverlaidFrame.this.isVisible()) { + prevState = FrameVisibleState.SHOW; + }else { + prevState = FrameVisibleState.HIDE; + } + hideComponent(); + } + break; } - }); + } } public void init(){ this.layout = getFrameLayout(); @@ -94,7 +89,7 @@ public void hideComponent(){ this.setVisible(false); } - public void setPrevState(FrameStates prevState) { + public void setPrevState(FrameVisibleState prevState) { this.prevState = prevState; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/ScalableComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java similarity index 95% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/ScalableComponentFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java index 37ae41f5..e4fbc515 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/ScalableComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java @@ -4,7 +4,6 @@ import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.panel.misc.HasUI; import com.mercury.platform.ui.frame.setup.scale.ScaleState; -import com.mercury.platform.shared.pojo.ScaleData; import com.mercury.platform.ui.misc.event.SaveScaleEvent; import com.mercury.platform.ui.misc.event.ScaleChangeEvent; @@ -12,7 +11,7 @@ import java.awt.*; import java.util.Map; //todo need generalization -public abstract class ScalableComponentFrame extends ComponentFrame implements HasUI{ +public abstract class AbstractScalableComponentFrame extends AbstractComponentFrame implements HasUI{ protected Container mainContainer; private ScaleState scaleState = ScaleState.DEFAULT; protected ComponentsFactory stubComponentsFactory; @@ -20,7 +19,7 @@ public abstract class ScalableComponentFrame extends ComponentFrame implements H protected boolean sizeWasChanged = false; protected boolean inScaleSettings = false; - protected ScalableComponentFrame(String title) { + protected AbstractScalableComponentFrame(String title) { super(title); mainContainer = this.getContentPane(); stubComponentsFactory = new ComponentsFactory(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/MovableComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java similarity index 92% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/movable/MovableComponentFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java index 773044fb..c727e899 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/MovableComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java @@ -1,6 +1,6 @@ package com.mercury.platform.ui.frame.movable; -import com.mercury.platform.ui.frame.ScalableComponentFrame; +import com.mercury.platform.ui.frame.AbstractScalableComponentFrame; import com.mercury.platform.ui.frame.setup.location.LocationState; import com.mercury.platform.ui.misc.AppThemeColor; @@ -10,13 +10,13 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public abstract class MovableComponentFrame extends ScalableComponentFrame { +public abstract class AbstractMovableComponentFrame extends AbstractScalableComponentFrame { private MovableFrameConstraints prevConstraints; private LocationState moveState = LocationState.DEFAULT; protected boolean locationWasChanged = false; protected boolean inMoveMode = false; protected boolean enableMouseOverBorder = true; - protected MovableComponentFrame(String title) { + protected AbstractMovableComponentFrame(String title) { super(title); mainContainer = this.getContentPane(); } @@ -101,15 +101,15 @@ private JPanel setUpMoveListeners(JPanel panel){ @Override public void mouseEntered(MouseEvent e) { getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.TEXT_MESSAGE, 1)); - MovableComponentFrame.this.repaint(); + AbstractMovableComponentFrame.this.repaint(); } @Override public void mouseExited(MouseEvent e) { - if (!MovableComponentFrame.this.getBounds().contains(e.getPoint())) { + if (!AbstractMovableComponentFrame.this.getBounds().contains(e.getPoint())) { getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); } - MovableComponentFrame.this.repaint(); + AbstractMovableComponentFrame.this.repaint(); } }); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/CurrencySearchFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/CurrencySearchFrame.java index 19467490..538ee13a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/CurrencySearchFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/CurrencySearchFrame.java @@ -1,11 +1,10 @@ package com.mercury.platform.ui.frame.movable; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; 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.misc.AppThemeColor; -import com.mercury.platform.shared.pojo.ScaleData; import javax.swing.*; import java.awt.*; @@ -14,13 +13,13 @@ /** * Created by Константин on 02.03.2017. */ -public class CurrencySearchFrame extends MovableComponentFrame { +public class CurrencySearchFrame extends AbstractMovableComponentFrame { private JPanel setUpPanel; private JPanel loadingPanel; private JPanel resultPanel; public CurrencySearchFrame() { super("MT-CurrencySearchFrame"); - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } @Override 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 409f0f1c..6b6071d3 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 @@ -6,11 +6,9 @@ import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; import com.mercury.platform.ui.components.panel.HorizontalScrollContainer; import com.mercury.platform.ui.components.panel.grid.*; -import com.mercury.platform.shared.pojo.ScaleData; -import com.mercury.platform.ui.frame.ComponentFrame; import com.mercury.platform.ui.misc.event.*; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; import com.mercury.platform.ui.manager.FramesManager; @@ -22,7 +20,7 @@ import java.awt.event.*; import java.util.Map; -public class ItemsGridFrame extends MovableComponentFrame{ +public class ItemsGridFrame extends AbstractMovableComponentFrame { private ItemsGridPanel itemsGridPanel; private HorizontalScrollContainer tabsContainer; private StashTabsContainer stashTabsContainer; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/TaskBarFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/TaskBarFrame.java index fddf4f6d..e5e070bf 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/TaskBarFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/TaskBarFrame.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.frame.movable; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; @@ -10,7 +10,6 @@ import com.mercury.platform.ui.components.panel.taskbar.TaskBarController; import com.mercury.platform.ui.components.panel.taskbar.TaskBarPanel; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.shared.pojo.ScaleData; import com.mercury.platform.ui.misc.event.RepaintEvent; import com.mercury.platform.ui.misc.event.ScaleChangeEvent; import org.pushingpixels.trident.Timeline; @@ -21,7 +20,7 @@ import java.awt.event.*; import java.util.Map; -public class TaskBarFrame extends MovableComponentFrame{ +public class TaskBarFrame extends AbstractMovableComponentFrame { private Timeline collapseAnimation; private int MIN_WIDTH; private int MAX_WIDTH; @@ -34,7 +33,7 @@ public TaskBarFrame() { stubComponentsFactory.setScale(ConfigManager.INSTANCE.getScaleData().get("taskbar")); processEResize = false; processSEResize = false; - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/IncMessageFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/IncMessageFrame.java index d4549f01..77e870c5 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/IncMessageFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/IncMessageFrame.java @@ -2,11 +2,12 @@ import com.mercury.platform.core.AppStarter; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; 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; @@ -14,8 +15,8 @@ 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; -import com.mercury.platform.ui.frame.movable.MovableComponentFrame; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.movable.AbstractMovableComponentFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.frame.setup.location.LocationState; import com.mercury.platform.ui.frame.setup.scale.ScaleState; import com.mercury.platform.ui.misc.AppThemeColor; @@ -31,7 +32,7 @@ import java.util.HashMap; import java.util.Map; -public class IncMessageFrame extends MovableComponentFrame implements MessagesContainer { +public class IncMessageFrame extends AbstractMovableComponentFrame implements MessagesContainer { private Map currentMessages; private boolean wasVisible; private FlowDirections flowDirections; @@ -94,8 +95,8 @@ protected LayoutManager getFrameLayout() { @Override public void initHandlers() { - EventRouter.CORE.registerHandler(DndModeEvent.class, event -> { - this.dnd = ((DndModeEvent)event).isDnd(); + MercuryStore.INSTANCE.dndSubject.subscribe(state -> { + this.dnd = state; if(dnd){ this.setVisible(false); expandAllFrame.setVisible(false); @@ -109,14 +110,11 @@ public void initHandlers() { setUpExpandButton(); } }); - EventRouter.CORE.registerHandler(NewWhispersEvent.class, event -> { - SwingUtilities.invokeLater(()-> { - Message message = ((NewWhispersEvent) event).getMessage(); - if(!currentMessages.containsKey(message)) { - addMessage(message); - } - }); - }); + MercuryStore.INSTANCE.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { + if(!currentMessages.containsKey(message)) { + addMessage(message); + } + })); EventRouter.UI.registerHandler(CloseMessagePanelEvent.class, event -> { Message message = ((CloseMessagePanelEvent) event).getMessage(); MessagePanel panel = currentMessages.get(message); @@ -176,10 +174,10 @@ private void addMessage(Message message){ new NotificationMessageController(message), this.componentsFactory); - if (!dnd && !this.isVisible() && AppStarter.APP_STATUS == FrameStates.SHOW) { + if (!dnd && !this.isVisible() && AppStarter.APP_STATUS == FrameVisibleState.SHOW) { this.setVisible(true); } else { - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } if (flowDirections.equals(FlowDirections.UPWARDS)) { mainContainer.add(messagePanel, 1); @@ -197,7 +195,9 @@ private void addMessage(Message message){ messagePanel.setVisible(false); } if (mainContainer.getComponentCount() > limitMsgCount) { - setUpExpandButton(); + if(AppStarter.APP_STATUS == FrameVisibleState.SHOW) { + setUpExpandButton(); + } expandAllFrame.incMessageCount(); } break; @@ -207,7 +207,9 @@ private void addMessage(Message message){ messagePanel.setVisible(false); } if (mainContainer.getComponentCount() > (limitMsgCount + 1)) { - setUpExpandButton(); + if(AppStarter.APP_STATUS == FrameVisibleState.SHOW) { + setUpExpandButton(); + } expandAllFrame.incMessageCount(); } break; @@ -215,6 +217,14 @@ private void addMessage(Message message){ } } + @Override + protected void changeVisible(FrameVisibleState state) { + super.changeVisible(state); + if(state.equals(FrameVisibleState.SHOW)) { + setUpExpandButton(); + } + } + private void setUpExpandButton(){ if(!inScaleSettings && !inMoveMode && !dnd) { switch (flowDirections) { @@ -318,9 +328,8 @@ protected JPanel getPanelForPINSettings() { private void onLimitCountChange(){ expandAllFrame.resetMessageCount(); - Arrays.stream(mainContainer.getComponents()).forEach(component -> { - component.setVisible(true); - }); + Arrays.stream(mainContainer.getComponents()) + .forEach(component -> component.setVisible(true)); switch (flowDirections){ case DOWNWARDS:{ Component[] components = mainContainer.getComponents(); @@ -606,7 +615,7 @@ public void reloadMessage(MessagePanel panel1) {} return panel; } - private class ExpandAllFrame extends OverlaidFrame { + private class ExpandAllFrame extends AbstractOverlaidFrame { private int messageCount = 0; private JLabel msgCountLabel; private JButton expandButton; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/AlertFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/AlertFrame.java index b7f598ae..9a3d2d27 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/AlertFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/AlertFrame.java @@ -2,7 +2,7 @@ import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.AlertEvent; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; @@ -13,7 +13,7 @@ /** * Created by Константин on 07.03.2017. */ -public class AlertFrame extends OverlaidFrame { +public class AlertFrame extends AbstractOverlaidFrame { private JLabel messageLabel; public AlertFrame() { super("MercuryTrade"); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/MercuryLoadingFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/MercuryLoadingFrame.java index 0397ed92..4ea20539 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/MercuryLoadingFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/MercuryLoadingFrame.java @@ -1,8 +1,7 @@ package com.mercury.platform.ui.frame.other; -import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.HideLoadingFrame; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.shared.store.MercuryStore; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.misc.AppThemeColor; import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.callback.TimelineCallback; @@ -11,7 +10,7 @@ import java.awt.*; -public class MercuryLoadingFrame extends OverlaidFrame { +public class MercuryLoadingFrame extends AbstractOverlaidFrame { private Timeline hideAnimation; private Timeline showAnimation; public MercuryLoadingFrame() { @@ -52,9 +51,8 @@ public void onTimelinePulse(float durationFraction, float timelinePosition) { @Override public void initHandlers() { - EventRouter.CORE.registerHandler(HideLoadingFrame.class, e-> { - hideAnimation.play(); - }); + MercuryStore.INSTANCE.appLoadingSubject + .subscribe(state -> hideAnimation.play()); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationFrame.java index 5450ecac..e48caea2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationFrame.java @@ -4,7 +4,7 @@ import com.mercury.platform.shared.events.custom.NotificationEvent; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.misc.AppThemeColor; import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.callback.TimelineCallback; @@ -15,7 +15,7 @@ /** * Created by Константин on 29.12.2016. */ -public class NotificationFrame extends OverlaidFrame { +public class NotificationFrame extends AbstractOverlaidFrame { private JLabel messageLabel; private Timeline showAnimation; public NotificationFrame() { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/OutMessageFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/OutMessageFrame.java index ed0b7c91..22e4573a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/OutMessageFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/OutMessageFrame.java @@ -1,16 +1,16 @@ package com.mercury.platform.ui.frame.other; import com.mercury.platform.core.AppStarter; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.ChatCommandEvent; import com.mercury.platform.shared.events.custom.OutTradeMessageEvent; -import com.mercury.platform.shared.pojo.CurrencyMessage; -import com.mercury.platform.shared.pojo.ItemMessage; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.CurrencyMessage; +import com.mercury.platform.shared.entity.ItemMessage; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.ComponentFrame; +import com.mercury.platform.ui.frame.AbstractComponentFrame; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.TooltipConstants; @@ -22,7 +22,7 @@ /** * Created by Константин on 12.01.2017. */ -public class OutMessageFrame extends ComponentFrame { +public class OutMessageFrame extends AbstractComponentFrame { public OutMessageFrame() { super("MercuryTrade"); } @@ -66,7 +66,7 @@ public void mouseDragged(MouseEvent e) { hoIn.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/hideout " + message.getWhisperNickname())); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/hideout " + message.getWhisperNickname()); } }); miscPanel.add(hoIn); @@ -74,7 +74,7 @@ public void mousePressed(MouseEvent e) { hoOut.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - EventRouter.CORE.fireEvent(new ChatCommandEvent("/hideout")); + MercuryStore.INSTANCE.chatCommandSubject.onNext("/hideout"); } }); miscPanel.add(hoOut); @@ -121,11 +121,11 @@ private JPanel getCurCountPanel(Double curCount, String currency){ @Override public void initHandlers() { EventRouter.CORE.registerHandler(OutTradeMessageEvent.class, event -> { - if (!this.isVisible() && AppStarter.APP_STATUS == FrameStates.SHOW) { + if (!this.isVisible() && AppStarter.APP_STATUS == FrameVisibleState.SHOW) { this.setAlwaysOnTop(true); this.setVisible(true); } else { - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } Message message = ((OutTradeMessageEvent) event).getMessage(); addNewMessage(message); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpLocationFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpLocationFrame.java index 410be8b6..02de14ed 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpLocationFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpLocationFrame.java @@ -1,6 +1,6 @@ package com.mercury.platform.ui.frame.other; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.AppThemeColor; @@ -9,7 +9,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class SetUpLocationFrame extends OverlaidFrame { +public class SetUpLocationFrame extends AbstractOverlaidFrame { public SetUpLocationFrame() { super("MercuryTrade"); } @@ -26,7 +26,7 @@ protected void initialize() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); root.setBackground(AppThemeColor.SLIDE_BG); - root.add(componentsFactory.getSimpleTextAre("Panels UNLOCKED Move them and click Lock when done."),BorderLayout.CENTER); + root.add(componentsFactory.getSimpleTextArea("Panels UNLOCKED Move them and click Lock when done."),BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JButton restoreDefault = componentsFactory.getBorderedButton("Restore defaults"); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpScaleFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpScaleFrame.java index c4eb8204..380205dc 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpScaleFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/SetUpScaleFrame.java @@ -4,10 +4,9 @@ import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.shared.pojo.ScaleData; import com.mercury.platform.ui.misc.event.SaveScaleEvent; import com.mercury.platform.ui.misc.event.ScaleChangeEvent; @@ -17,7 +16,7 @@ import java.awt.event.MouseEvent; import java.util.Map; -public class SetUpScaleFrame extends OverlaidFrame { +public class SetUpScaleFrame extends AbstractOverlaidFrame { private Map scaleData; public SetUpScaleFrame() { super("MercuryTrade"); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/TooltipFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/TooltipFrame.java index b0a62247..e246f4a9 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/TooltipFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/TooltipFrame.java @@ -6,7 +6,7 @@ import com.mercury.platform.ui.misc.event.ShowTooltipEvent; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; @@ -15,7 +15,7 @@ /** * Created by Константин on 17.01.2017. */ -public class TooltipFrame extends OverlaidFrame { +public class TooltipFrame extends AbstractOverlaidFrame { private Timer tooltipTimer; public TooltipFrame() { super("MercuryTrade"); @@ -39,7 +39,7 @@ public void initHandlers() { JLabel tooltipLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP,16f,tooltip); this.add(tooltipLabel,BorderLayout.CENTER); }else { - JTextArea tooltipArea = componentsFactory.getSimpleTextAre(""); + JTextArea tooltipArea = componentsFactory.getSimpleTextArea(""); this.add(tooltipArea,BorderLayout.CENTER); tooltipArea.setText(tooltip); if(tooltip.toCharArray().length < 120){ diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/UpdateReadyFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/UpdateReadyFrame.java index 4f4c2002..2553f7db 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/UpdateReadyFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/UpdateReadyFrame.java @@ -2,14 +2,14 @@ import com.mercury.platform.core.AppStarter; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.CheckOutPatchNotes; import com.mercury.platform.shared.events.custom.UpdateInfoEvent; -import com.mercury.platform.shared.pojo.FrameSettings; +import com.mercury.platform.shared.entity.FrameSettings; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; @@ -17,7 +17,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class UpdateReadyFrame extends OverlaidFrame { +public class UpdateReadyFrame extends AbstractOverlaidFrame { public UpdateReadyFrame() { super("MercuryTrade"); } @@ -80,10 +80,10 @@ public void initHandlers() { if(deltaWidth < 0){ this.setLocation(tbLocation.x - Math.abs(deltaWidth), this.getLocation().y); } - if (!this.isVisible() && AppStarter.APP_STATUS == FrameStates.SHOW) { + if (!this.isVisible() && AppStarter.APP_STATUS == FrameVisibleState.SHOW) { this.setVisible(true); } else { - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } pack(); }); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java index 3ce32264..9d851e82 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java @@ -1,13 +1,13 @@ package com.mercury.platform.ui.frame.setup.location; +import com.mercury.platform.ui.frame.movable.AbstractMovableComponentFrame; import com.mercury.platform.ui.frame.other.SetUpLocationFrame; -import com.mercury.platform.ui.frame.movable.MovableComponentFrame; import com.mercury.platform.ui.frame.setup.SetUpCommander; import com.mercury.platform.ui.manager.FramesManager; import java.util.*; -public class SetUpLocationCommander extends SetUpCommander{ +public class SetUpLocationCommander extends SetUpCommander{ public SetUpLocationCommander() { super(); } @@ -31,14 +31,14 @@ public void setUpAllExclude(Class[] framesClasses) { } @Override public void setUp(Class frameClass, boolean showingSetUpFrame) { - MovableComponentFrame frame = frames.get(frameClass); + AbstractMovableComponentFrame frame = frames.get(frameClass); enableMovement(frame,showingSetUpFrame); activeFrames.add(frame); } @Override public void setOrEndUp(Class frameClass, boolean showingSetUpFrame) { - MovableComponentFrame frame = frames.get(frameClass); + AbstractMovableComponentFrame frame = frames.get(frameClass); if(frame.getMoveState().equals(LocationState.DEFAULT)){ enableMovement(frame,showingSetUpFrame); activeFrames.add(frame); @@ -56,17 +56,17 @@ public void endUpAll() { @Override public void endUp(Class frameClass) { - MovableComponentFrame frame = frames.get(frameClass); + AbstractMovableComponentFrame frame = frames.get(frameClass); disableMovement(frame); activeFrames.remove(frame); } - private void enableMovement(MovableComponentFrame frame, boolean showSetUpFrame){ + private void enableMovement(AbstractMovableComponentFrame frame, boolean showSetUpFrame){ frame.setState(LocationState.MOVING); if(showSetUpFrame){ FramesManager.INSTANCE.showFrame(SetUpLocationFrame.class); } } - private void disableMovement(MovableComponentFrame frame){ + private void disableMovement(AbstractMovableComponentFrame frame){ frame.setState(LocationState.DEFAULT); FramesManager.INSTANCE.hideFrame(SetUpLocationFrame.class); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java index 202c85e6..7fb8db0b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java @@ -1,10 +1,10 @@ package com.mercury.platform.ui.frame.setup.scale; -import com.mercury.platform.ui.frame.ScalableComponentFrame; +import com.mercury.platform.ui.frame.AbstractScalableComponentFrame; import com.mercury.platform.ui.frame.setup.SetUpCommander; -public class SetUpScaleCommander extends SetUpCommander{ +public class SetUpScaleCommander extends SetUpCommander{ public SetUpScaleCommander() { super(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TitledComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java similarity index 84% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TitledComponentFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java index 721c7049..6a54ee1d 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TitledComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java @@ -1,6 +1,6 @@ package com.mercury.platform.ui.frame.titled; -import com.mercury.platform.ui.frame.ComponentFrame; +import com.mercury.platform.ui.frame.AbstractComponentFrame; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; @@ -8,16 +8,14 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -/** - * Created by Константин on 18.01.2017. - */ -public abstract class TitledComponentFrame extends ComponentFrame { +public abstract class AbstractTitledComponentFrame extends AbstractComponentFrame { protected JPanel miscPanel; protected JButton hideButton; + protected JPanel headerPanel; private JLabel frameTitleLabel; - protected TitledComponentFrame(String title) { + protected AbstractTitledComponentFrame(String title) { super(title); - miscPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + miscPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); } @Override @@ -28,7 +26,7 @@ protected void initialize() { private void initHeaderPanel(){ if(layout instanceof BorderLayout) { - JPanel headerPanel = new JPanel(new BorderLayout()); + headerPanel = new JPanel(new BorderLayout()); headerPanel.setBackground(AppThemeColor.HEADER); headerPanel.setPreferredSize(new Dimension(100,26)); headerPanel.setBorder(BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER)); @@ -51,7 +49,7 @@ private void initHeaderPanel(){ @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { - TitledComponentFrame.this.setVisible(false); + AbstractTitledComponentFrame.this.setVisible(false); } } }); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/GamePathChooser.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/GamePathChooser.java index b71adaa7..9cc189fd 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/GamePathChooser.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/GamePathChooser.java @@ -13,7 +13,7 @@ import java.awt.event.MouseEvent; import java.io.File; -public class GamePathChooser extends TitledComponentFrame { +public class GamePathChooser extends AbstractTitledComponentFrame { private final Logger logger = LogManager.getLogger(GamePathChooser.class.getSimpleName()); private JLabel statusLabel; private String gamePath; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java index 8882ccf4..706bb1ce 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java @@ -1,14 +1,14 @@ package com.mercury.platform.ui.frame.titled; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.ChunkLoadedEvent; import com.mercury.platform.shared.events.custom.StartUpdateEvent; import com.mercury.platform.shared.events.custom.UpdateReadyEvent; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.AppThemeColor; @@ -21,7 +21,7 @@ import java.net.URI; import java.util.List; -public class NotesFrame extends TitledComponentFrame { +public class NotesFrame extends AbstractTitledComponentFrame { private List currentNotes; private ContentPanel contentPanel; private NotesType type; @@ -40,10 +40,10 @@ public NotesFrame(List notes, NotesType type) { if(type.equals(NotesType.INFO)) { boolean showOnStartUp = ConfigManager.INSTANCE.isShowOnStartUp(); if (showOnStartUp) { - prevState = FrameStates.SHOW; + prevState = FrameVisibleState.SHOW; } else { this.setVisible(false); - prevState = FrameStates.HIDE; + prevState = FrameVisibleState.HIDE; } } } @@ -156,7 +156,7 @@ public void mousePressed(MouseEvent e) { ConfigManager.INSTANCE.setShowOnStartUp(showOnStartUp.isSelected()); FramesManager.INSTANCE.enableMovementExclude(ItemsGridFrame.class); } - prevState = FrameStates.HIDE; + prevState = FrameVisibleState.HIDE; } } }); @@ -214,7 +214,7 @@ private void renderCurrentNote(){ innerContent.setPreferredSize(new Dimension(530,270)); JLabel image = componentsFactory.getIconLabel(note.getImagePath()); - JTextArea textArea = componentsFactory.getSimpleTextAre(note.getText()); + JTextArea textArea = componentsFactory.getSimpleTextArea(note.getText()); switch (note.getLayout()){ case VERTICAL:{ innerContent.setLayout(new BoxLayout(innerContent,BoxLayout.Y_AXIS)); @@ -260,7 +260,7 @@ public enum NotesType { INFO, PATCH } - private class ProgressBarFrame extends OverlaidFrame { + private class ProgressBarFrame extends AbstractOverlaidFrame { private JProgressBar progressBar; private JLabel percentLabel; private int percent; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java index 0d94008c..5c12f7ef 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java @@ -13,7 +13,7 @@ import java.util.*; import java.util.List; -public class SettingsFrame extends TitledComponentFrame { +public class SettingsFrame extends AbstractTitledComponentFrame { private List innerPanels; private boolean successfullySaved = true; public SettingsFrame(){ @@ -43,8 +43,11 @@ private void initContainer() { innerPanels.add(cbSettings); ConfigurationPanel taskBarSettings = new TaskBarSettingsPanel(); innerPanels.add(taskBarSettings); + ConfigurationPanel soundSettings = new SoundSettingsPanel(); + innerPanels.add(soundSettings); tabbedPane.addTab("General",generalSettings); + tabbedPane.addTab("Sound",soundSettings); tabbedPane.addTab("Notification panel",cbSettings); tabbedPane.addTab("Task panel",taskBarSettings); // tabbedPane.addTab("Help",new HelpPanel()); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestCasesFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestCasesFrame.java index 47a24816..dda8a82e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestCasesFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestCasesFrame.java @@ -1,21 +1,24 @@ package com.mercury.platform.ui.frame.titled; +import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.shared.MessageParser; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.*; -import com.mercury.platform.shared.pojo.Message; -import com.mercury.platform.ui.frame.titled.TitledComponentFrame; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; import javax.swing.Timer; import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; import java.util.List; -public class TestCasesFrame extends TitledComponentFrame { +public class TestCasesFrame extends AbstractTitledComponentFrame { private List items; private List currency; private List nickNames; @@ -31,7 +34,6 @@ public TestCasesFrame() { nickNames = new ArrayList<>(); offer = new ArrayList<>(); leagues = new ArrayList<>(); - items.add("Wondertrap Velvet Slippers"); items.add("Rain of Arrows"); items.add("Dreadarc Cleaver"); @@ -177,7 +179,7 @@ public void mousePressed(MouseEvent e) { random.nextInt(12) + 1, offer.get(random.nextInt(offer.size())) )); - EventRouter.CORE.fireEvent(new NewWhispersEvent(message)); + MercuryStore.INSTANCE.messageSubject.onNext(message); } }); testPanel.add(button,buttonColumn); @@ -199,7 +201,7 @@ public void mousePressed(MouseEvent e) { leagues.get(random.nextInt(leagues.size())), offer.get(random.nextInt(offer.size())) )); - EventRouter.CORE.fireEvent(new NewWhispersEvent(message)); + MercuryStore.INSTANCE.messageSubject.onNext(message); } }); testPanel.add(button1,buttonColumn); @@ -214,7 +216,6 @@ public void mousePressed(MouseEvent e) { button2.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - EventRouter.CORE.fireEvent(new WhisperNotificationEvent()); String nickname = nickNames.get(random.nextInt(nickNames.size())); Message message = parser.parse(String.format(currencyTemplate, nickname, @@ -225,7 +226,8 @@ public void mousePressed(MouseEvent e) { leagues.get(random.nextInt(leagues.size())), offer.get(random.nextInt(offer.size())) )); - EventRouter.CORE.fireEvent(new NewWhispersEvent(message)); + MercuryStore.INSTANCE.messageSubject.onNext(message); + MercuryStore.INSTANCE.soundSubject.onNext(SoundType.MESSAGE); Timer joinedTimer = new Timer(1000,null); joinedTimer.addActionListener(e1 -> { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java index dd1e69ed..1088d0fd 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java @@ -13,7 +13,7 @@ /** * Created by Константин on 06.01.2017. */ -public class TimerFrame extends TitledComponentFrame { +public class TimerFrame extends AbstractTitledComponentFrame { private Timer timeAgo; private JLabel timeLabel; private int seconds = 0; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterFrame.java index d5a2b095..2c90b014 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterFrame.java @@ -2,13 +2,13 @@ import com.mercury.platform.core.utils.interceptor.MessageInterceptor; import com.mercury.platform.core.utils.interceptor.filter.MessageFilter; +import com.mercury.platform.shared.ConfigManager; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.AddInterceptorEvent; -import com.mercury.platform.shared.events.custom.ChatFilterMessageEvent; -import com.mercury.platform.shared.events.custom.RemoveInterceptorEvent; -import com.mercury.platform.shared.pojo.FrameSettings; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.store.MercuryStore; +import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.chat.ChatFilterPanel; -import com.mercury.platform.ui.frame.titled.TitledComponentFrame; +import com.mercury.platform.ui.frame.titled.AbstractTitledComponentFrame; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.event.PackEvent; import com.mercury.platform.ui.misc.event.RepaintEvent; @@ -22,19 +22,25 @@ import java.util.*; import java.util.List; -public class ChatFilterFrame extends TitledComponentFrame{ +public class ChatFilterFrame extends AbstractTitledComponentFrame { private ChatFilterSettingsFrame settingsFrame; private ChatFilterPanel msgContainer; private MessageInterceptor interceptor; + private JPanel toolbar; private boolean soundEnable = false; private boolean scrollToBottom = true; + private boolean chatEnable = false; private JButton scrollEnd; public ChatFilterFrame() { super("MercuryTrade"); FrameSettings frameSettings = configManager.getFrameSettings(this.getClass().getSimpleName()); this.setPreferredSize(frameSettings.getFrameSize()); - this.settingsFrame = new ChatFilterSettingsFrame(this::performNewStrings); + this.settingsFrame = new ChatFilterSettingsFrame(strings -> { + if(chatEnable){ + performNewStrings(strings); + } + }); } @Override @@ -48,13 +54,73 @@ public void componentResized(ComponentEvent e) { } }); this.hideButton.setIcon(componentsFactory.getIcon("app/hide.png",14)); + this.hideButton.setBorder(BorderFactory.createEmptyBorder(0,2,0,2)); + this.headerPanel.add(getMenuButton(),BorderLayout.LINE_START); + this.miscPanel.add(getEnableButton(),0); +// this.miscPanel.add(getMinimizeButton(),1); + this.miscPanel.setBorder(BorderFactory.createEmptyBorder(-4,0,0,0)); this.settingsFrame.init(); this.msgContainer = new ChatFilterPanel(); + this.toolbar = getToolbar(); + toolbar.setVisible(false); + this.add(toolbar,BorderLayout.LINE_START); this.add(msgContainer,BorderLayout.CENTER); - this.add(getNavigationPanel(),BorderLayout.LINE_END); this.pack(); } + private JButton getEnableButton() { + JButton enableButton = componentsFactory.getBorderedButton("Start"); + enableButton.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), + BorderFactory.createMatteBorder(1,5,1,5,AppThemeColor.TRANSPARENT) + )); + enableButton.setFont(componentsFactory.getFont(FontStyle.BOLD,16f)); + enableButton.setPreferredSize(new Dimension(90,23)); + enableButton.setBackground(AppThemeColor.TRANSPARENT); + enableButton.setForeground(AppThemeColor.TEXT_SUCCESS); + + componentsFactory.setUpToggleCallbacks(enableButton, + () -> { + chatEnable = false; + if (interceptor != null) { + MercuryStore.INSTANCE.removeInterceptorSubject.onNext(interceptor); + } + enableButton.setText("Start"); + enableButton.setForeground(AppThemeColor.TEXT_SUCCESS); + repaint(); + }, + () -> { + chatEnable = true; + String chunkStr = StringUtils.deleteWhitespace(ConfigManager.INSTANCE.getDefaultWords()); + String[] split = chunkStr.split(","); + performNewStrings(split); + enableButton.setText("Stop"); + enableButton.setForeground(AppThemeColor.TEXT_IMPORTANT); + repaint(); + }, false); + return enableButton; + } + private JButton getMinimizeButton() { + JButton minimizer = componentsFactory.getIconButton("app/minimize.png", 14, AppThemeColor.FRAME_ALPHA, ""); + minimizer.addActionListener(action -> { + //todo + }); + return minimizer; + } + private JButton getMenuButton() { + JButton menu = componentsFactory.getIconButton("app/menu.png", 18, AppThemeColor.FRAME_ALPHA, "Menu"); + menu.setBorder(BorderFactory.createEmptyBorder(4,6,4,4)); + componentsFactory.setUpToggleCallbacks(menu, + () -> { + this.toolbar.setVisible(true); + repaint(); + }, + () -> { + this.toolbar.setVisible(false); + repaint(); + }, true); + return menu; + } private void performNewStrings(String[] strings){ List contains = new ArrayList<>(); List notContains = new ArrayList<>(); @@ -72,7 +138,7 @@ private void performNewStrings(String[] strings){ msgContainer.setNewChunks(Arrays.asList(strings)); if (interceptor != null) { - EventRouter.CORE.fireEvent(new RemoveInterceptorEvent(interceptor)); + MercuryStore.INSTANCE.removeInterceptorSubject.onNext(interceptor); } interceptor = new MessageInterceptor() { @Override @@ -98,7 +164,7 @@ protected MessageFilter getFilter() { }; } }; - EventRouter.CORE.fireEvent(new AddInterceptorEvent(interceptor)); + MercuryStore.INSTANCE.addInterceptorSubject.onNext(interceptor); } @Override @@ -122,7 +188,7 @@ public void initHandlers() { }); } - private JPanel getNavigationPanel(){ + private JPanel getToolbar(){ JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); @@ -138,7 +204,7 @@ private JPanel getNavigationPanel(){ "Chat Scanner settings"); edit.addActionListener( action -> this.settingsFrame.showAuxiliaryFrame( - new Point(this.getLocation().x+this.getSize().width/2,this.getLocation().y), + new Point(this.getLocation().x,this.getLocation().y), this.getPreferredSize().height)); JButton clear = componentsFactory.getIconButton( "app/clear-history.png", diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterSettingsFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterSettingsFrame.java index 95e98731..39b99e84 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterSettingsFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterSettingsFrame.java @@ -3,15 +3,16 @@ import com.mercury.platform.shared.ConfigManager; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.titled.TitledComponentFrame; +import com.mercury.platform.ui.frame.titled.AbstractTitledComponentFrame; import com.mercury.platform.ui.misc.AppThemeColor; import org.apache.commons.lang3.StringUtils; import javax.swing.*; import java.awt.*; -public class ChatFilterSettingsFrame extends TitledComponentFrame { +public class ChatFilterSettingsFrame extends AbstractTitledComponentFrame { private ChatSettingsCallback callback; + private JTextField quickResponseField; public ChatFilterSettingsFrame(ChatSettingsCallback callback) { super("MercuryTrade"); @@ -37,7 +38,7 @@ protected void initialize() { 15f, "Show messages containing the following words:"); title.setBorder(BorderFactory.createEmptyBorder(2,0,6,0)); - JTextArea words = componentsFactory.getSimpleTextAre(ConfigManager.INSTANCE.getDefaultWords()); + JTextArea words = componentsFactory.getSimpleTextArea(ConfigManager.INSTANCE.getDefaultWords()); words.setEditable(true); words.setCaretColor(AppThemeColor.TEXT_DEFAULT); words.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); @@ -48,6 +49,8 @@ protected void initialize() { JButton save = componentsFactory.getBorderedButton("Save"); save.addActionListener(action -> { ConfigManager.INSTANCE.setDefaultWords(words.getText()); + ConfigManager.INSTANCE.setQuickResponse(quickResponseField.getText()); + String chunkStr = StringUtils.deleteWhitespace(words.getText()); String[] split = chunkStr.split(","); @@ -73,10 +76,35 @@ protected void initialize() { root.add(setupArea,BorderLayout.CENTER); root.add(getMemo(),BorderLayout.LINE_END); - root.add(navBar,BorderLayout.PAGE_END); + + JPanel padding = componentsFactory.getTransparentPanel(new BorderLayout()); + padding.setBorder(BorderFactory.createEmptyBorder(0,4,4,4)); + padding.add(getResponsePanel(),BorderLayout.CENTER); + root.add(padding,BorderLayout.PAGE_END); this.add(root,BorderLayout.CENTER); + this.add(navBar,BorderLayout.PAGE_END); this.pack(); } + private JPanel getResponsePanel(){ + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + JPanel setupArea = componentsFactory.getTransparentPanel(new BorderLayout()); + setupArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); + root.setBackground(AppThemeColor.SLIDE_BG); + + JButton quickResponse = componentsFactory.getIconButton("app/chat_scanner_response.png", 18f, AppThemeColor.SLIDE_BG, "Quick response"); + quickResponseField = componentsFactory.getTextField(ConfigManager.INSTANCE.getQuickResponse(),FontStyle.REGULAR,16f); + quickResponseField.setBackground(AppThemeColor.SLIDE_BG); + quickResponseField.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.HEADER,1), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,3) + )); + setupArea.add(quickResponse,BorderLayout.LINE_START); + setupArea.add(quickResponseField,BorderLayout.CENTER); + root.add(setupArea,BorderLayout.CENTER); + return root; + } private JPanel getMemo(){ JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); 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 f84591a3..aa9e2d5c 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 @@ -4,16 +4,15 @@ import com.mercury.platform.shared.HistoryManager; import com.mercury.platform.shared.MessageParser; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.events.custom.NewWhispersEvent; -import com.mercury.platform.shared.pojo.FrameSettings; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.entity.Message; +import com.mercury.platform.shared.store.MercuryStore; 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.VerticalScrollContainer; import com.mercury.platform.ui.components.panel.message.NotificationMessageController; import com.mercury.platform.ui.components.panel.message.MessagePanelStyle; -import com.mercury.platform.ui.frame.titled.TitledComponentFrame; +import com.mercury.platform.ui.frame.titled.AbstractTitledComponentFrame; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.event.ReloadMessageEvent; import com.mercury.platform.ui.misc.event.RepaintEvent; @@ -24,7 +23,7 @@ import java.awt.event.*; -public class HistoryFrame extends TitledComponentFrame implements HistoryContainer { +public class HistoryFrame extends AbstractTitledComponentFrame implements HistoryContainer { private JPanel mainContainer; public HistoryFrame() { super("MercuryTrade"); @@ -126,20 +125,17 @@ protected String getFrameTitle() { @Override public void initHandlers() { - EventRouter.CORE.registerHandler(NewWhispersEvent.class, (MercuryEvent event) -> { - SwingUtilities.invokeLater(()-> { - Message message = ((NewWhispersEvent) event).getMessage(); - HistoryManager.INSTANCE.add(message); - MessagePanel messagePanel = new MessagePanel( - message, - MessagePanelStyle.HISTORY, - new NotificationMessageController(message), - this.componentsFactory); - mainContainer.add(messagePanel); - trimContainer(); - this.pack(); - }); - }); + MercuryStore.INSTANCE.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { + HistoryManager.INSTANCE.add(message); + MessagePanel messagePanel = new MessagePanel( + message, + MessagePanelStyle.HISTORY, + new NotificationMessageController(message), + this.componentsFactory); + mainContainer.add(messagePanel); + trimContainer(); + this.pack(); + })); EventRouter.UI.registerHandler(ReloadMessageEvent.class,event -> { onReloadMessage(((ReloadMessageEvent)event).getPanel()); }); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java b/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java index b1790a5f..5f7d99c8 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java @@ -1,24 +1,24 @@ package com.mercury.platform.ui.manager; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.shared.FrameStates; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.HasEventHandlers; import com.mercury.platform.shared.events.EventRouter; import com.mercury.platform.shared.events.custom.ShowPatchNotesEvent; import com.mercury.platform.shared.events.custom.ShutDownForUpdateEvent; import com.mercury.platform.shared.events.custom.ShutdownApplication; -import com.mercury.platform.shared.events.custom.UILoadedEvent; -import com.mercury.platform.shared.pojo.FrameSettings; -import com.mercury.platform.ui.frame.ScalableComponentFrame; -import com.mercury.platform.ui.frame.other.*; -import com.mercury.platform.ui.frame.ComponentFrame; -import com.mercury.platform.ui.frame.movable.container.IncMessageFrame; +import com.mercury.platform.shared.entity.FrameSettings; +import com.mercury.platform.shared.store.MercuryStore; +import com.mercury.platform.ui.frame.AbstractComponentFrame; +import com.mercury.platform.ui.frame.AbstractScalableComponentFrame; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; -import com.mercury.platform.ui.frame.movable.MovableComponentFrame; +import com.mercury.platform.ui.frame.movable.AbstractMovableComponentFrame; +import com.mercury.platform.ui.frame.movable.container.IncMessageFrame; +import com.mercury.platform.ui.frame.other.*; import com.mercury.platform.ui.frame.movable.TaskBarFrame; import com.mercury.platform.ui.frame.setup.scale.SetUpScaleCommander; import com.mercury.platform.ui.frame.titled.*; -import com.mercury.platform.ui.frame.OverlaidFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; import com.mercury.platform.ui.frame.setup.location.SetUpLocationCommander; import com.mercury.platform.ui.frame.other.SetUpLocationFrame; import com.mercury.platform.ui.frame.titled.chat.ChatFilterFrame; @@ -40,7 +40,7 @@ private static class FramesManagerHolder { } public static FramesManager INSTANCE = FramesManagerHolder.HOLDER_INSTANCE; - private Map framesMap; + private Map framesMap; private SetUpLocationCommander locationCommander; private SetUpScaleCommander scaleCommander; @@ -52,18 +52,18 @@ private FramesManager() { public void start(){ createTrayIcon(); - OverlaidFrame incMessageFrame = new IncMessageFrame(); + AbstractOverlaidFrame incMessageFrame = new IncMessageFrame(); framesMap.put(IncMessageFrame.class,incMessageFrame); - OverlaidFrame taskBarFrame = new TaskBarFrame(); - OverlaidFrame itemsMeshFrame = new ItemsGridFrame(); + AbstractOverlaidFrame taskBarFrame = new TaskBarFrame(); + AbstractOverlaidFrame itemsMeshFrame = new ItemsGridFrame(); framesMap.put(ItemsGridFrame.class,itemsMeshFrame); - locationCommander.addFrame((MovableComponentFrame) incMessageFrame); - locationCommander.addFrame((MovableComponentFrame) taskBarFrame); - locationCommander.addFrame((MovableComponentFrame) itemsMeshFrame); + locationCommander.addFrame((AbstractMovableComponentFrame) incMessageFrame); + locationCommander.addFrame((AbstractMovableComponentFrame) taskBarFrame); + locationCommander.addFrame((AbstractMovableComponentFrame) itemsMeshFrame); - scaleCommander.addFrame((ScalableComponentFrame) incMessageFrame); - scaleCommander.addFrame((ScalableComponentFrame) taskBarFrame); - scaleCommander.addFrame((ScalableComponentFrame) itemsMeshFrame); + scaleCommander.addFrame((AbstractScalableComponentFrame) incMessageFrame); + scaleCommander.addFrame((AbstractScalableComponentFrame) taskBarFrame); + scaleCommander.addFrame((AbstractScalableComponentFrame) itemsMeshFrame); NotesLoader notesLoader = new NotesLoader(); @@ -78,7 +78,7 @@ public void start(){ framesMap.put(MercuryLoadingFrame.class,new MercuryLoadingFrame()); List patchNotes = notesLoader.getPatchNotes(); if(ConfigManager.INSTANCE.isShowPatchNotes() && patchNotes.size() != 0){ - NotesFrame patchNotesFrame = new NotesFrame(patchNotes,NotesFrame.NotesType.PATCH); + NotesFrame patchNotesFrame = new NotesFrame(patchNotes, NotesFrame.NotesType.PATCH); patchNotesFrame.init(); } framesMap.put(ChatFilterFrame.class,new ChatFilterFrame()); @@ -96,17 +96,17 @@ public void start(){ int maxOpacity = ConfigManager.INSTANCE.getMaxOpacity(); int minOpacity = ConfigManager.INSTANCE.getMinOpacity(); framesMap.forEach((k,frame) -> { - if(frame instanceof ComponentFrame) { + if(frame instanceof AbstractComponentFrame) { if (decayTime > 0) { - ((ComponentFrame)frame).enableHideEffect(decayTime, minOpacity, maxOpacity); + ((AbstractComponentFrame)frame).enableHideEffect(decayTime, minOpacity, maxOpacity); } else { - ((ComponentFrame)frame).disableHideEffect(); + ((AbstractComponentFrame)frame).disableHideEffect(); frame.setOpacity(maxOpacity / 100f); } } }); initHandlers(); - EventRouter.CORE.fireEvent(new UILoadedEvent()); + MercuryStore.INSTANCE.uiLoadedSubject.onNext(true); } @Override public void initHandlers() { @@ -114,7 +114,7 @@ public void initHandlers() { String patchNotes = ((ShowPatchNotesEvent) handler).getPatchNotes(); NotesLoader notesLoader = new NotesLoader(); List notes = notesLoader.getPatchNotesFromString(patchNotes); - NotesFrame patchNotesFrame = new NotesFrame(notes,NotesFrame.NotesType.PATCH); + NotesFrame patchNotesFrame = new NotesFrame(notes, NotesFrame.NotesType.PATCH); patchNotesFrame.init(); patchNotesFrame.setFrameTitle("MercuryTrade v" + notesLoader.getVersionFrom(patchNotes)); patchNotesFrame.showComponent(); @@ -136,13 +136,13 @@ public void showFrame(Class frameClass){ framesMap.get(frameClass).showComponent(); } public void preShowFrame(Class frameClass){ - framesMap.get(frameClass).setPrevState(FrameStates.SHOW); + framesMap.get(frameClass).setPrevState(FrameVisibleState.SHOW); } public void hideFrame(Class frameClass){ framesMap.get(frameClass).hideComponent(); } public void hideOrShowFrame(Class frameClass){ - OverlaidFrame frame = framesMap.get(frameClass); + AbstractOverlaidFrame frame = framesMap.get(frameClass); if(frame != null && frame.isVisible()){ hideFrame(frameClass); }else { @@ -176,8 +176,8 @@ public void restoreDefaultLocation(){ FrameSettings settings = ConfigManager.INSTANCE.getDefaultFramesSettings().get(k.getSimpleName()); if(!v.getClass().equals(ItemsGridFrame.class) && settings != null){ v.setLocation(settings.getFrameLocation()); - if(v instanceof MovableComponentFrame){ - ((MovableComponentFrame) v).onLocationChange(settings.getFrameLocation()); + if(v instanceof AbstractMovableComponentFrame){ + ((AbstractMovableComponentFrame) v).onLocationChange(settings.getFrameLocation()); } } }); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java b/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java index 9b7ab0d6..e3f316fd 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.manager; import com.mercury.platform.shared.ConfigManager; -import com.mercury.platform.ui.frame.ComponentFrame; +import com.mercury.platform.ui.frame.AbstractComponentFrame; import java.util.ArrayList; import java.util.List; @@ -12,12 +12,12 @@ private static class HideSettingsManagerHolder { } public static HideSettingsManager INSTANCE = HideSettingsManagerHolder.HOLDER_INSTANCE; - private List frames; + private List frames; private HideSettingsManager() { frames = new ArrayList<>(); } - public void registerFrame(ComponentFrame frame){ + public void registerFrame(AbstractComponentFrame frame){ frames.add(frame); } public void apply(int fadeTime, int minOpacity, int maxOpacity){ diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseGridItemEvent.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseGridItemEvent.java index dfcc18cb..9aee3123 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseGridItemEvent.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseGridItemEvent.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.misc.event; import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.ItemMessage; +import com.mercury.platform.shared.entity.ItemMessage; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseMessagePanelEvent.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseMessagePanelEvent.java index 13740fd0..de16946f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseMessagePanelEvent.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/CloseMessagePanelEvent.java @@ -1,13 +1,9 @@ package com.mercury.platform.ui.misc.event; import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.Message; +import com.mercury.platform.shared.entity.Message; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.Getter; -import lombok.Setter; - -import java.awt.*; @Data @AllArgsConstructor diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/SaveScaleEvent.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/SaveScaleEvent.java index 1cc749ef..be562ba5 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/SaveScaleEvent.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/SaveScaleEvent.java @@ -1,11 +1,8 @@ package com.mercury.platform.ui.misc.event; import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.ScaleData; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.Getter; -import lombok.Setter; import java.util.Map; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/ShowItemGridEvent.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/ShowItemGridEvent.java index 7919ef7d..9ee6458f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/event/ShowItemGridEvent.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/event/ShowItemGridEvent.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.misc.event; import com.mercury.platform.shared.events.MercuryEvent; -import com.mercury.platform.shared.pojo.ItemMessage; +import com.mercury.platform.shared.entity.ItemMessage; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/app-ui/src/main/resources/app/chat_scanner_response.png b/app-ui/src/main/resources/app/chat_scanner_response.png new file mode 100644 index 00000000..a9607e7c Binary files /dev/null and b/app-ui/src/main/resources/app/chat_scanner_response.png differ diff --git a/app-ui/src/main/resources/app/menu.png b/app-ui/src/main/resources/app/menu.png new file mode 100644 index 00000000..60cc9e1e Binary files /dev/null and b/app-ui/src/main/resources/app/menu.png differ diff --git a/app-ui/src/main/resources/app/minimize.png b/app-ui/src/main/resources/app/minimize.png new file mode 100644 index 00000000..a93d15a4 Binary files /dev/null and b/app-ui/src/main/resources/app/minimize.png differ diff --git a/app-ui/src/main/resources/app/openChat.png b/app-ui/src/main/resources/app/openChat.png index ba0bb89f..0c0d50c4 100644 Binary files a/app-ui/src/main/resources/app/openChat.png and b/app-ui/src/main/resources/app/openChat.png differ diff --git a/app-ui/src/main/resources/app/paypal.png b/app-ui/src/main/resources/app/paypal.png index 4700ced8..2ee6b569 100644 Binary files a/app-ui/src/main/resources/app/paypal.png and b/app-ui/src/main/resources/app/paypal.png differ diff --git a/app-ui/src/main/resources/currency/chromatic.png b/app-ui/src/main/resources/currency/chromatic.png new file mode 100644 index 00000000..55751a85 Binary files /dev/null and b/app-ui/src/main/resources/currency/chromatic.png differ diff --git a/app-ui/src/test/java/com/mercury/platform/PackTesting.java b/app-ui/src/test/java/com/mercury/platform/PackTesting.java index 757e720c..84204a5c 100644 --- a/app-ui/src/test/java/com/mercury/platform/PackTesting.java +++ b/app-ui/src/test/java/com/mercury/platform/PackTesting.java @@ -1,17 +1,12 @@ package com.mercury.platform; -import com.mercury.platform.core.User32; import com.mercury.platform.ui.misc.AppThemeColor; -import com.sun.jna.Native; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -/** - * Created by Константин on 23.12.2016. - */ public class PackTesting { private static void createAndShowGUI() { final JFrame frame = new JFrame("HelloWorldSwing"); @@ -19,10 +14,9 @@ private static void createAndShowGUI() { frame.setMinimumSize(new Dimension(400,400)); frame.setMaximumSize(new Dimension(400,400)); frame.setLocationRelativeTo(null); - frame.setFocusable(false); - frame.setFocusableWindowState(false); frame.setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS)); - + frame.setType(Window.Type.UTILITY); + frame.setUndecorated(true); JPanel buffer = new JPanel(new FlowLayout(FlowLayout.CENTER)); buffer.setMinimumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE)); buffer.setBorder(BorderFactory.createLineBorder(AppThemeColor.TEXT_IMPORTANT)); @@ -41,6 +35,7 @@ public void mouseClicked(MouseEvent e) { } }); frame.add(buffer); + frame.add(new JTextField()); frame.add(button); frame.setVisible(true); frame.pack(); diff --git a/app-ui/src/test/java/com/mercury/platform/Test.java b/app-ui/src/test/java/com/mercury/platform/Test.java new file mode 100644 index 00000000..212316e1 --- /dev/null +++ b/app-ui/src/test/java/com/mercury/platform/Test.java @@ -0,0 +1,43 @@ +package com.mercury.platform; + +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinUser; +import com.sun.jna.win32.StdCallLibrary; + +/** + * Created by Константин on 15.04.2017. + */ +public class Test { + public static void main(String[] args) { + final User32 user32 = User32.INSTANCE; + user32.EnumWindows(new WinUser.WNDENUMPROC() { + int count = 0; + @Override + public boolean callback(WinDef.HWND hwnd, Pointer pointer) { + byte[] windowText = new byte[512]; + byte[] className = new byte[512]; + user32.GetWindowTextA(hwnd, windowText, 512); + user32.GetClassNameA(hwnd, className, 512); + String title = Native.toString(windowText); + String classN = Native.toString(className); + + // get rid of this if block if you want all windows regardless of whether + // or not they have text + if (title.isEmpty()) { + return true; + } + + System.out.println("Title: " + title + " Class name: " + classN); + return true; + } + },null); + } + public interface User32 extends StdCallLibrary { + User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); + boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg); + int GetWindowTextA(WinDef.HWND hWnd, byte[] lpString, int nMaxCount); + int GetClassNameA(WinDef.HWND hwnd, byte[] lpString,int nMaxCount); + } +} diff --git a/app/src/main/java/com/mercury/platform/AppMain.java b/app/src/main/java/com/mercury/platform/AppMain.java index ca9a7c77..a59db3b2 100644 --- a/app/src/main/java/com/mercury/platform/AppMain.java +++ b/app/src/main/java/com/mercury/platform/AppMain.java @@ -4,7 +4,7 @@ import com.mercury.platform.core.utils.FileMonitor; import com.mercury.platform.shared.ConfigManager; import com.mercury.platform.shared.events.EventRouter; -import com.mercury.platform.shared.events.custom.HideLoadingFrame; +import com.mercury.platform.shared.store.MercuryStore; import com.mercury.platform.ui.frame.other.MercuryLoadingFrame; import com.mercury.platform.ui.frame.titled.GamePathChooser; import com.mercury.platform.ui.manager.FramesManager; @@ -20,13 +20,13 @@ public static void main(String[] args) { new AppStarter().startApplication(); String gamePath = ConfigManager.INSTANCE.getGamePath(); if(gamePath.equals("") || !ConfigManager.INSTANCE.isValidGamePath(gamePath)){ - EventRouter.CORE.fireEvent(new HideLoadingFrame()); + MercuryStore.INSTANCE.appLoadingSubject.onNext(false); GamePathChooser gamePathChooser = new GamePathChooser(); gamePathChooser.init(); }else{ new FileMonitor().start(); FramesManager.INSTANCE.start(); - EventRouter.CORE.fireEvent(new HideLoadingFrame()); + MercuryStore.INSTANCE.appLoadingSubject.onNext(false); } } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index d1efa79f..c4732bd4 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,9 @@ 21.0 1.16.8 0.5.8 + 1.2.9 + 1.2.24 + 2.8.7 UTF-8 UTF-8 @@ -125,7 +128,16 @@ lombok ${lombok.version} - + + io.reactivex + rxjava + ${rxjava.version} + + + com.google.code.gson + gson + 2.8.0 + org.apache.logging.log4j log4j-core