diff --git a/README.md b/README.md index 9faa7229..d150bdb6 100644 --- a/README.md +++ b/README.md @@ -37,42 +37,38 @@ Feedback and suggestions: [Github](https://github.com/Exslims/MercuryTrade/issue Overseer is essentially "a customizable and nicely looking set of overlay timers": you press a button and it tracks the time since - that's it. It's obviously 100% legit as there is no interaction with the game whatsoever. It's basically a clever trick, but gets the job done. +Recently Overseer has got a new component: **Capture** - allows you to literally duplicate a part of your screen to display it somewhere else. This feature is especially neat for Vaal Skills for more convenient tracking. Also flasks, charge based abilities, UI counters etc. +   *Major feature:* **Notification**

- +

-When you receive a trade related message this notification panel pops up. It contains all the information you need to make a decision. It offers a set of fully customizable "quick response buttons" - such as "Sold" / "No" / "Wait 3m" / etc - as well as buttons to invite, kick and trade with the person who made the offer. +When you receive a trade related message or scanner message this notification panel pops up. It contains all the information you need to make a decision. It offers a set of fully customizable "quick response buttons" - such as "Sold" / "No" / "Wait 3m" / etc - as well as buttons to invite, kick and trade with the person who made the offer. There are also "?" - "Still Interested?" and a chat-history button. -

- -

+**All the buttons are hotkeyable!** -

Multiple notifications

+You can ignore an item: sold an item 5 hours ago yet people are still spamming you with trade offers? We can't filter out this from chat, but we can make MercuryTrade ignore it! Notifications for ignored items won't appear. -If you've received multiple notifications before dismissing your current one, they will stack up like a deck of cards underneath (or on top) of each other and won't clutter the screen. Notification panels can be set up to fade out after X seconds - a customizable option. + +Outgoing trade offers and messages from chat scanner to be diplayed as notifications as well. It has a different panel layout for the essentials such as "Visit Hideout" and "Leave" buttons.

- +

-

"Group" showcase: you received 5 notifications

+

Multiple notifications

+If you've received multiple notifications before dismissing your current one, they will stack up like a deck of cards underneath (or on top) of each other and won't clutter the screen.

The box on the left - "Group" - will appear if "Pre-group limit" is exceeded (this limit is also customizable). All consecutive notifications will be grouped together to save screen space. Toggling this button will expand the whole group.

-

- -

- -

Notification Panel settings (unlocked mode)

-

- +

-

Response buttons are fully customizable

+

Not only Response buttons are fully customizable, look how many things you can actually tweak to your taste!

@@ -82,21 +78,23 @@ If you've received multiple notifications before dismissing your current one, th   *Minor feature:* **History**

- +

History

Each notification you receive is stored in a separate file by **MercuryTrade**. History allows you to access that file in a useful way to interact with customers. Comes in handy if you want to reach a person you traded with some time ago or in case your client has crashed - your in-game chat will be lost, but History will not. +Use "Restore" button to bring back related notification. + #   *Major feature:* **Chat scanner**

- +

-Set up words to look for (or not!) in chat. Extremely useful for when buying something specific from chat. +Set up words to look for (or not!) in chat. Extremely useful for when buying something specific from chat, looking for Trials, specific challenged and other things you might be interested in. Works in conjunction with the notification panel. # @@ -118,22 +116,6 @@ Mercury can highlight the stash location of the item somebody's buying. You will

Item Grid set up.

- -# - -  *Minor feature:* **Accessibility status** -

- -

- -

Name will change its color accordingly

- - -**MercuryTrade** notifications have an **indication for when a person comes in or leaves your hideout** - that way you can offer a trade as soon as possible and keep track of all the people without even closing your stash. Especially useful for SuperTrade mode. - - -Important to mention: in Path of Exile when you use your stash you can't click on party frames, because they're hidden behind the stash window. **MercuryTrade** solves this inconvenience as you can interact with the person through a related notification panel. - #   *Minor feature:* **Do not Disturb** @@ -153,48 +135,3 @@ Activate this mode if you don't want to see (and hear!) anything from the applic Download and install Java on your computer, then open MercuryTrade.jar. Because the program operates on top of a Path of Exile window as an overlay, **make sure your client is not in fullscreen mode**. Upon launch you'll be greeted with a short overview of the application (identical to this ReadMe) and patch notes. Afterwards you should see **Task Panel** and **Notification Panel**. - - -
- -**Task panel**: - -

- -

- - -* (1) **Travel to Hideout**. - -* (2) **Do Not Disturb** mode button switch. - -* (3) **Chat scanner**. - -* (4) **History**. - -* (5) **Item Grid** set up. - -* (6) **Panel unlock**. - -* (7) **Scale setting**. - -* (8) **Settings**. - -* (9) **Exit**. - -
- -**Notification panel** *(unlocked mode)* - -

- -

- -
- -After you go through the overview, panels will be in "Unlocked" mode. This will allow you to reposition them to your taste. - - - - - diff --git a/app-core/pom.xml b/app-core/pom.xml index 93bd7f86..5dc20f6f 100644 --- a/app-core/pom.xml +++ b/app-core/pom.xml @@ -19,6 +19,10 @@ app-shared 1.0.0.5 + + net.jodah + expiringmap + com.1stleg jnativehook 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 536d627b..c48d80ae 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 @@ -30,6 +30,8 @@ private void executeMessage(String message) { StringSelection selection = new StringSelection(message); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); + MercuryStoreCore.blockHotkeySubject.onNext(true); + robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); @@ -48,13 +50,15 @@ private void executeMessage(String message) { robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); + MercuryStoreCore.blockHotkeySubject.onNext(false); } private void openChat(String whisper) { this.gameToFront(); StringSelection selection = new StringSelection("@" + whisper); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); - + MercuryStoreCore.blockHotkeySubject.onNext(true); + robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); @@ -72,6 +76,7 @@ private void openChat(String whisper) { robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); + MercuryStoreCore.blockHotkeySubject.onNext(false); } private void gameToFront(){ User32.INSTANCE.EnumWindows((hWnd, arg1) -> { 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 5d560e0f..ae012210 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.7.0"; + public static final String APP_VERSION = "1.0.1.8.0"; 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/utils/MessageFileHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/MessageFileHandler.java index 13e59383..c2d511c2 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 @@ -10,7 +10,6 @@ import java.io.File; import java.io.RandomAccessFile; import java.util.*; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -27,7 +26,9 @@ public MessageFileHandler(String logFilePath) { this.logFilePath = logFilePath; this.datePattern = Pattern.compile(dateRGPattern); - this.interceptors.add(new TradeMessagesInterceptor()); + this.interceptors.add(new TradeIncMessagesInterceptor()); + this.interceptors.add(new TradeOutMessagesInterceptor()); + this.interceptors.add(new PlainMessageInterceptor()); this.interceptors.add(new PlayerJoinInterceptor()); this.interceptors.add(new PlayerLeftInterceptor()); diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlainMessageInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlainMessageInterceptor.java new file mode 100644 index 00000000..9d0d51af --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlainMessageInterceptor.java @@ -0,0 +1,190 @@ +package com.mercury.platform.core.utils.interceptor; + + +import com.mercury.platform.core.utils.interceptor.filter.MessageFilter; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PlainMessageInterceptor extends MessageInterceptor{ + private List clients = new ArrayList<>(); + + public PlainMessageInterceptor() { + this.clients.add(new EngIncLocalizationMatcher()); + this.clients.add(new EngOutLocalizationMatcher()); + this.clients.add(new RuIncLocalizationMatcher()); + this.clients.add(new RuOutLocalizationMatcher()); + this.clients.add(new ArabicInLocalizationMatcher()); + this.clients.add(new ArabicOutLocalizationMatcher()); + this.clients.add(new BZIncLocalizationMatcher()); + this.clients.add(new BZOutLocalizationMatcher()); + } + + @Override + protected void process(String message) { + LocalizationMatcher localizationMatcher = this.clients.stream() + .filter(matcher -> matcher.isSuitableFor(message)) + .findAny().orElse(null); + if(localizationMatcher != null){ + localizationMatcher.processMessage(message); + } + } + + @Override + protected MessageFilter getFilter() { + return message -> + this.clients.stream() + .filter(matcher -> matcher.isSuitableFor(message)) + .findAny().orElse(null) != null; + } + private abstract class LocalizationMatcher { + public abstract boolean isSuitableFor(String message); + public abstract boolean isIncoming(); + public abstract String trimString(String message); + public void processMessage(String message){ + Pattern pattern = Pattern.compile("^(\\<.+?\\>)?\\s?(.+?):(.+)$"); + Matcher matcher = pattern.matcher(this.trimString(message)); + if(matcher.find()){ + PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); + descriptor.setNickName(matcher.group(2)); + descriptor.setMessage(matcher.group(3)); + descriptor.setIncoming(this.isIncoming()); + MercuryStoreCore.plainMessageSubject.onNext(descriptor); + } + } + } + private class EngIncLocalizationMatcher extends LocalizationMatcher { + @Override + public boolean isSuitableFor(String message) { + return message.contains("@From"); + } + + @Override + public boolean isIncoming() { + return true; + } + + @Override + public String trimString(String message) { + return StringUtils.substringAfter(message,"@From "); + } + } + private class EngOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@To"); + } + + @Override + public boolean isIncoming() { + return false; + } + + @Override + public String trimString(String message) { + return StringUtils.substringAfter(message,"@To "); + } + } + private class RuIncLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@От кого"); + } + + @Override + public boolean isIncoming() { + return true; + } + + @Override + public String trimString(String message) { + return StringUtils.substringAfter(message,"@От кого "); + } + } + private class RuOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@Кому"); + } + + @Override + public boolean isIncoming() { + return false; + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@Кому "); + } + + } + private class ArabicInLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@จาก"); + } + + @Override + public boolean isIncoming() { + return true; + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@จาก"); + } + } + private class ArabicOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@ถึง"); + } + + @Override + public boolean isIncoming() { + return false; + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@ถึง"); + } + } + private class BZIncLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@De"); + } + + @Override + public boolean isIncoming() { + return true; + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@De"); + } + } + private class BZOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@Para"); + } + + @Override + public boolean isIncoming() { + return false; + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@Para"); + } + } +} diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java similarity index 55% rename from app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeMessagesInterceptor.java rename to app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java index 1cf4cb2d..d3126b63 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeMessagesInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java @@ -5,37 +5,48 @@ import com.mercury.platform.shared.MessageParser; import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; import com.mercury.platform.shared.store.MercuryStoreCore; +import net.jodah.expiringmap.ExpiringMap; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; -public class TradeMessagesInterceptor extends MessageInterceptor { +public class TradeIncMessagesInterceptor extends MessageInterceptor { private MessageParser messageParser = new MessageParser(); - private PlainConfigurationService config; + private PlainConfigurationService config; private List clients = new ArrayList<>(); + private Map expiresMessages; - public TradeMessagesInterceptor() { + public TradeIncMessagesInterceptor() { this.config = Configuration.get().notificationConfiguration(); - this.clients.add(new EngLocalizationMatcher()); - this.clients.add(new RuLocalizationMatcher()); - this.clients.add(new ArabicLocalizationMatcher()); - this.clients.add(new BZLocalizationMatcher()); + this.clients.add(new EngIncLocalizationMatcher()); + this.clients.add(new RuIncLocalizationMatcher()); + this.clients.add(new ArabicInLocalizationMatcher()); + this.clients.add(new BZIncLocalizationMatcher()); + this.expiresMessages = ExpiringMap.builder() + .expiration(1, TimeUnit.HOURS) + .build(); + MercuryStoreCore.expiredNotificationSubject.subscribe(notificationDescriptor -> { + this.expiresMessages.put(UUID.randomUUID().toString(),StringUtils.substringAfter(notificationDescriptor.getSourceString(),":")); + }); } @Override protected void process(String message) { - if(this.config.get().isNotificationEnable()) { + if(this.config.get().isIncNotificationEnable()) { LocalizationMatcher localizationMatcher = this.clients.stream() .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null); - Message parsedMessage = messageParser.parse(localizationMatcher.trimString(message)); - if (parsedMessage != null) { - MercuryStoreCore.soundSubject.onNext(SoundType.MESSAGE); - MercuryStoreCore.messageSubject.onNext(parsedMessage); + if(localizationMatcher != null){ + localizationMatcher.processMessage(message); } } } @@ -54,8 +65,20 @@ public boolean isSuitableFor(String message){ (message.contains("wtb") && message.contains("(stash")); } public abstract String trimString(String src); + public NotificationDescriptor getDescriptor(String message){ + return messageParser.parse(this.trimString(message)); + } + public void processMessage(String message){ + NotificationDescriptor notificationDescriptor = this.getDescriptor(message); + if (notificationDescriptor != null) { + if(!expiresMessages.containsValue(StringUtils.substringAfter(notificationDescriptor.getSourceString(),":"))) { + MercuryStoreCore.soundSubject.onNext(SoundType.MESSAGE); + MercuryStoreCore.newNotificationSubject.onNext(notificationDescriptor); + } + } + } } - private class EngLocalizationMatcher extends LocalizationMatcher{ + private class EngIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@From") && super.isSuitableFor(message); @@ -66,7 +89,7 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@From"); } } - private class RuLocalizationMatcher extends LocalizationMatcher{ + private class RuIncLocalizationMatcher extends LocalizationMatcher{ @Override public boolean isSuitableFor(String message) { return message.contains("@От кого") && super.isSuitableFor(message); @@ -77,7 +100,7 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@От кого"); } } - private class ArabicLocalizationMatcher extends LocalizationMatcher{ + private class ArabicInLocalizationMatcher extends LocalizationMatcher{ @Override public boolean isSuitableFor(String message) { return message.contains("@จาก") && super.isSuitableFor(message); @@ -88,7 +111,7 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@จาก"); } } - private class BZLocalizationMatcher extends LocalizationMatcher{ + private class BZIncLocalizationMatcher extends LocalizationMatcher{ @Override public boolean isSuitableFor(String message) { return message.contains("@De") && super.isSuitableFor(message); diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeOutMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeOutMessagesInterceptor.java new file mode 100644 index 00000000..447d94c7 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeOutMessagesInterceptor.java @@ -0,0 +1,156 @@ +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.config.Configuration; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.shared.store.MercuryStoreCore; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +public class TradeOutMessagesInterceptor extends MessageInterceptor { + private MessageParser messageParser = new MessageParser(); + private PlainConfigurationService config; + private List clients = new ArrayList<>(); + + public TradeOutMessagesInterceptor() { + this.config = Configuration.get().notificationConfiguration(); + this.clients.add(new EngOutLocalizationMatcher()); + this.clients.add(new RuOutLocalizationMatcher()); + this.clients.add(new ArabicOutLocalizationMatcher()); + this.clients.add(new BZOutLocalizationMatcher()); + } + + @Override + protected void process(String message) { + if(this.config.get().isOutNotificationEnable()) { + LocalizationMatcher localizationMatcher = this.clients.stream() + .filter(matcher -> matcher.isSuitableFor(message)) + .findAny().orElse(null); + if(localizationMatcher != null){ + localizationMatcher.processMessage(message); + } + } + } + + @Override + protected MessageFilter getFilter() { + return message -> + this.clients.stream() + .filter(matcher -> matcher.isSuitableFor(message)) + .findAny().orElse(null) != null; + } + private abstract class LocalizationMatcher { + public boolean isSuitableFor(String message){ + return message.contains("Hi, I would like") || + message.contains("Hi, I'd like") || + (message.contains("wtb") && message.contains("(stash")); + } + public abstract String trimString(String src); + public NotificationDescriptor getDescriptor(String message){ + return messageParser.parse(this.trimString(message)); + } + public void processMessage(String message){ + NotificationDescriptor notificationDescriptor = this.getDescriptor(message); + if (notificationDescriptor != null) { + MercuryStoreCore.newNotificationSubject.onNext(notificationDescriptor); + } + } + } + + private class EngOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@To") && super.isSuitableFor(message); + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@To"); + } + + @Override + public NotificationDescriptor getDescriptor(String message) { + NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); + if(descriptor instanceof ItemTradeNotificationDescriptor){ + descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); + }else { + descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); + } + return descriptor; + } + } + private class RuOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@Кому") && super.isSuitableFor(message); + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@Кому"); + } + + @Override + public NotificationDescriptor getDescriptor(String message) { + NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); + if(descriptor instanceof ItemTradeNotificationDescriptor){ + descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); + }else { + descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); + } + return descriptor; + } + } + private class ArabicOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@ถึง") && super.isSuitableFor(message); + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@ถึง"); + } + + @Override + public NotificationDescriptor getDescriptor(String message) { + NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); + if(descriptor instanceof ItemTradeNotificationDescriptor){ + descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); + }else { + descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); + } + return descriptor; + } + } + private class BZOutLocalizationMatcher extends LocalizationMatcher{ + @Override + public boolean isSuitableFor(String message) { + return message.contains("@Para") && super.isSuitableFor(message); + } + + @Override + public String trimString(String src) { + return StringUtils.substringAfter(src, "@Para"); + } + + @Override + public NotificationDescriptor getDescriptor(String message) { + NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); + if(descriptor instanceof ItemTradeNotificationDescriptor){ + descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); + }else { + descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); + } + return descriptor; + } + } +} 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 08c0a117..75cbcea8 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,6 +1,6 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.json.simple.JSONArray; @@ -60,12 +60,12 @@ private void createEmptyFile(){ logger.error("Error during creating history file: ", e); } } - public void add(Message message){ + public void add(NotificationDescriptor notificationDescriptor){ JSONParser parser = new JSONParser(); try { JSONObject root = (JSONObject)parser.parse(new FileReader(HISTORY_FILE)); JSONArray msgsArray = (JSONArray) root.get("messages"); - msgsArray.add(0,message.getSourceString()); + msgsArray.add(0, notificationDescriptor.getSourceString()); root.replace("messages",msgsArray); FileWriter fileWriter = new FileWriter(HISTORY_FILE); fileWriter.write(root.toJSONString()); 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 13949b14..039954a0 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,9 +1,9 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.entity.message.CurrencyMessage; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; -import org.apache.commons.lang3.StringUtils; +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,77 +24,81 @@ public MessageParser() { this.poeTradeCurrencyPattern = Pattern.compile(poeCurrencyPattern); } - public Message parse(String fullMessage){ + public NotificationDescriptor parse(String fullMessage){ Matcher poeAppItemMatcher = poeAppItemPattern.matcher(fullMessage); if(poeAppItemMatcher.find()){ - ItemMessage message = new ItemMessage(); - message.setSourceString(fullMessage); - message.setWhisperNickname(poeAppItemMatcher.group(2)); - message.setItemName(poeAppItemMatcher.group(3)); + ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); + tradeNotification.setSourceString(fullMessage); + tradeNotification.setWhisperNickname(poeAppItemMatcher.group(2)); + tradeNotification.setItemName(poeAppItemMatcher.group(3)); if(poeAppItemMatcher.group(5) != null) { - message.setCurCount(Double.parseDouble(poeAppItemMatcher.group(5))); - message.setCurrency(poeAppItemMatcher.group(6)); + tradeNotification.setCurCount(Double.parseDouble(poeAppItemMatcher.group(5))); + tradeNotification.setCurrency(poeAppItemMatcher.group(6)); }else { - message.setCurCount(0d); - message.setCurrency("???"); + tradeNotification.setCurCount(0d); + tradeNotification.setCurrency("???"); } - message.setLeague(poeAppItemMatcher.group(7)); + tradeNotification.setLeague(poeAppItemMatcher.group(7)); if(poeAppItemMatcher.group(8) != null) { - message.setTabName(poeAppItemMatcher.group(8)); - message.setLeft(Integer.parseInt(poeAppItemMatcher.group(9))); - message.setTop(Integer.parseInt(poeAppItemMatcher.group(10))); + tradeNotification.setTabName(poeAppItemMatcher.group(8)); + tradeNotification.setLeft(Integer.parseInt(poeAppItemMatcher.group(9))); + tradeNotification.setTop(Integer.parseInt(poeAppItemMatcher.group(10))); } - message.setOffer(poeAppItemMatcher.group(11)); - return message; + tradeNotification.setOffer(poeAppItemMatcher.group(11)); + tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE); + return tradeNotification; } Matcher poeTradeStashItemMatcher = poeTradeStashItemPattern.matcher(fullMessage); if(poeTradeStashItemMatcher.find()){ - ItemMessage message = new ItemMessage(); - message.setSourceString(fullMessage); - message.setWhisperNickname(poeTradeStashItemMatcher.group(2)); - message.setItemName(poeTradeStashItemMatcher.group(3)); + ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); + tradeNotification.setSourceString(fullMessage); + tradeNotification.setWhisperNickname(poeTradeStashItemMatcher.group(2)); + tradeNotification.setItemName(poeTradeStashItemMatcher.group(3)); if(poeTradeStashItemMatcher.group(4) != null){ - message.setCurCount(Double.parseDouble(poeTradeStashItemMatcher.group(5))); - message.setCurrency(poeTradeStashItemMatcher.group(6)); + tradeNotification.setCurCount(Double.parseDouble(poeTradeStashItemMatcher.group(5))); + tradeNotification.setCurrency(poeTradeStashItemMatcher.group(6)); }else { - message.setCurCount(0d); - message.setCurrency("???"); + tradeNotification.setCurCount(0d); + tradeNotification.setCurrency("???"); } - message.setLeague(poeTradeStashItemMatcher.group(7)); - message.setTabName(poeTradeStashItemMatcher.group(8)); - message.setLeft(Integer.parseInt(poeTradeStashItemMatcher.group(9))); - message.setTop(Integer.parseInt(poeTradeStashItemMatcher.group(10))); - message.setOffer(poeTradeStashItemMatcher.group(11)); - return message; + tradeNotification.setLeague(poeTradeStashItemMatcher.group(7)); + tradeNotification.setTabName(poeTradeStashItemMatcher.group(8)); + tradeNotification.setLeft(Integer.parseInt(poeTradeStashItemMatcher.group(9))); + tradeNotification.setTop(Integer.parseInt(poeTradeStashItemMatcher.group(10))); + tradeNotification.setOffer(poeTradeStashItemMatcher.group(11)); + tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE); + return tradeNotification; } Matcher poeTradeCurrencyMatcher = poeTradeCurrencyPattern.matcher(fullMessage); if(poeTradeCurrencyMatcher.find()){ - CurrencyMessage message = new CurrencyMessage(); - message.setSourceString(fullMessage); - message.setWhisperNickname(poeTradeCurrencyMatcher.group(2)); - message.setCurrForSaleCount(Double.parseDouble(poeTradeCurrencyMatcher.group(3))); - message.setCurrForSaleTitle(poeTradeCurrencyMatcher.group(5)); - message.setCurCount(Double.parseDouble(poeTradeCurrencyMatcher.group(6))); - message.setCurrency(poeTradeCurrencyMatcher.group(8)); - message.setLeague(poeTradeCurrencyMatcher.group(9)); - message.setOffer(poeTradeCurrencyMatcher.group(10)); - return message; + CurrencyTradeNotificationDescriptor tradeNotification = new CurrencyTradeNotificationDescriptor(); + tradeNotification.setSourceString(fullMessage); + tradeNotification.setWhisperNickname(poeTradeCurrencyMatcher.group(2)); + tradeNotification.setCurrForSaleCount(Double.parseDouble(poeTradeCurrencyMatcher.group(3))); + tradeNotification.setCurrForSaleTitle(poeTradeCurrencyMatcher.group(5)); + tradeNotification.setCurCount(Double.parseDouble(poeTradeCurrencyMatcher.group(6))); + tradeNotification.setCurrency(poeTradeCurrencyMatcher.group(8)); + tradeNotification.setLeague(poeTradeCurrencyMatcher.group(9)); + tradeNotification.setOffer(poeTradeCurrencyMatcher.group(10)); + tradeNotification.setType(NotificationType.INC_CURRENCY_MESSAGE); + return tradeNotification; } Matcher poeTradeItemMatcher = poeTradeItemPattern.matcher(fullMessage); if(poeTradeItemMatcher.find()){ - ItemMessage message = new ItemMessage(); - message.setSourceString(fullMessage); - message.setWhisperNickname(poeTradeItemMatcher.group(2)); - message.setItemName(poeTradeItemMatcher.group(3)); + ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); + tradeNotification.setSourceString(fullMessage); + tradeNotification.setWhisperNickname(poeTradeItemMatcher.group(2)); + tradeNotification.setItemName(poeTradeItemMatcher.group(3)); if(poeTradeItemMatcher.group(4) != null){ - message.setCurCount(Double.parseDouble(poeTradeItemMatcher.group(5))); - message.setCurrency(poeTradeItemMatcher.group(6)); + tradeNotification.setCurCount(Double.parseDouble(poeTradeItemMatcher.group(5))); + tradeNotification.setCurrency(poeTradeItemMatcher.group(6)); }else { - message.setCurCount(0d); - message.setCurrency("???"); + tradeNotification.setCurCount(0d); + tradeNotification.setCurrency("???"); } - message.setLeague(poeTradeItemMatcher.group(7)); - return message; + tradeNotification.setLeague(poeTradeItemMatcher.group(7)); + tradeNotification.setType(NotificationType.INC_ITEM_MESSAGE); + return tradeNotification; } return null; } 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 index 1448fde5..a11a556c 100644 --- 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 @@ -11,11 +11,11 @@ public interface ConfigManager { FramesConfigurationService framesConfiguration(); PlainConfigurationService applicationConfiguration(); - PlainConfigurationService notificationConfiguration(); + PlainConfigurationService notificationConfiguration(); PlainConfigurationService scannerConfiguration(); KeyValueConfigurationService soundConfiguration(); KeyValueConfigurationService scaleConfiguration(); - KeyValueConfigurationService hotKeysConfiguration(); + PlainConfigurationService hotKeysConfiguration(); AdrConfigurationService adrConfiguration(); ListConfigurationService stashTabConfiguration(); IconBundleConfigurationService iconBundleConfiguration(); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java index e4f0c33e..89acc361 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java @@ -7,7 +7,6 @@ import com.mercury.platform.shared.config.configration.impl.adr.AdrConfigurationServiceMock; import com.mercury.platform.shared.config.descriptor.*; import com.mercury.platform.shared.config.descriptor.StashTabDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; import com.mercury.platform.shared.config.json.JSONHelper; import com.mercury.platform.shared.store.MercuryStoreCore; import org.apache.commons.io.FileUtils; @@ -30,11 +29,11 @@ public class MercuryConfigManager implements ConfigManager, AsSubscriber { private ProfileDescriptor selectedProfile; private FramesConfigurationService framesConfigurationService; private PlainConfigurationService applicationConfigurationService; - private PlainConfigurationService notificationConfigurationService; + private PlainConfigurationService notificationConfigurationService; private PlainConfigurationService scannerConfigurationService; private KeyValueConfigurationService soundConfigurationService; private KeyValueConfigurationService scaleConfigurationService; - private KeyValueConfigurationService hotKeyConfigurationService; + private PlainConfigurationService hotKeyConfigurationService; private ListConfigurationService stashTabConfigurationService; private IconBundleConfigurationService iconBundleConfigurationService; private AdrConfigurationService adrConfigurationService; @@ -57,7 +56,7 @@ public PlainConfigurationService applicationConfiguration } @Override - public PlainConfigurationService notificationConfiguration() { + public PlainConfigurationService notificationConfiguration() { return this.notificationConfigurationService; } @@ -92,7 +91,7 @@ public IconBundleConfigurationService iconBundleConfiguration() { } @Override - public KeyValueConfigurationService hotKeysConfiguration() { + public PlainConfigurationService hotKeysConfiguration() { return this.hotKeyConfigurationService; } @@ -143,7 +142,7 @@ public void load(){ this.notificationConfigurationService = new NotificationConfigurationService(selectedProfile); this.scaleConfigurationService = new ScaleConfigurationService(selectedProfile); this.stashTabConfigurationService = new StashTabConfigurationService(selectedProfile); - this.hotKeyConfigurationService = new HotKeysConfigurationService(selectedProfile); + this.hotKeyConfigurationService = new HotKeyConfigurationService(selectedProfile); this.adrConfigurationService = new AdrConfigurationServiceMock(selectedProfile); this.iconBundleConfigurationService = new IconBundleConfigurationServiceImpl(selectedProfile); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java index 9814e580..f69449b2 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java @@ -44,6 +44,7 @@ public ApplicationDescriptor getDefault() { descriptor.setCheckOutUpdate(true); descriptor.setInGameDnd(false); descriptor.setDndResponseText("Response text"); + System.out.println("qwe"); return descriptor; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/FramesConfigurationServiceImpl.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/FramesConfigurationServiceImpl.java index 2264a062..9cd009df 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/FramesConfigurationServiceImpl.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/FramesConfigurationServiceImpl.java @@ -62,13 +62,13 @@ public Dimension getMinimumSize(String frameClass) { private void initMinimumMap() { minimumFrameSize.put("TaskBarFrame",new Dimension(109,20)); - minimumFrameSize.put("MessageFrame",new Dimension(360,10)); + minimumFrameSize.put("NotificationFrame",new Dimension(320,10)); minimumFrameSize.put("OutMessageFrame",new Dimension(280,115)); minimumFrameSize.put("TestCasesFrame",new Dimension(400,100)); minimumFrameSize.put("SettingsFrame",new Dimension(600,400)); minimumFrameSize.put("HistoryFrame",new Dimension(280,400)); minimumFrameSize.put("TimerFrame",new Dimension(240,102)); - minimumFrameSize.put("ChatFilterFrame",new Dimension(400,100)); + minimumFrameSize.put("ChatScannerFrame",new Dimension(450,100)); minimumFrameSize.put("ItemsGridFrame",new Dimension(150,150)); minimumFrameSize.put("NotesFrame",new Dimension(540,100)); minimumFrameSize.put("ChatFilterSettingsFrame",new Dimension(300,200)); @@ -79,13 +79,13 @@ private void initMinimumMap() { } private void initDefaultMap() { defaultFramesSettings.put("TaskBarFrame", new FrameDescriptor(new Point(400, 500), new Dimension(109, 20))); - defaultFramesSettings.put("MessageFrame", new FrameDescriptor(new Point(700, 600), new Dimension(315, 0))); + defaultFramesSettings.put("NotificationFrame", new FrameDescriptor(new Point(700, 600), new Dimension(350, 0))); defaultFramesSettings.put("OutMessageFrame", new FrameDescriptor(new Point(200, 500), new Dimension(280, 115))); defaultFramesSettings.put("TestCasesFrame", new FrameDescriptor(new Point(1400, 500), new Dimension(400, 100))); defaultFramesSettings.put("SettingsFrame", new FrameDescriptor(new Point(600, 600), new Dimension(800,600))); defaultFramesSettings.put("HistoryFrame", new FrameDescriptor(new Point(600, 500), new Dimension(280, 400))); defaultFramesSettings.put("TimerFrame", new FrameDescriptor(new Point(400, 600), new Dimension(240, 102))); - defaultFramesSettings.put("ChatFilterFrame", new FrameDescriptor(new Point(400, 600), new Dimension(500, 300))); + defaultFramesSettings.put("ChatScannerFrame", new FrameDescriptor(new Point(400, 600), new Dimension(550, 220))); defaultFramesSettings.put("ItemsGridFrame", new FrameDescriptor(new Point(12, 79), new Dimension(641, 718))); defaultFramesSettings.put("NotesFrame", new FrameDescriptor(new Point(400, 600), new Dimension(540, 100))); defaultFramesSettings.put("ChatFilterSettingsFrame", new FrameDescriptor(new Point(400, 600), new Dimension(320, 200))); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeyConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeyConfigurationService.java new file mode 100644 index 00000000..3b8ce102 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeyConfigurationService.java @@ -0,0 +1,77 @@ +package com.mercury.platform.shared.config.configration.impl; + + +import com.mercury.platform.shared.config.configration.BaseConfigurationService; +import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.*; +import com.mercury.platform.shared.store.MercuryStoreCore; +import org.jnativehook.keyboard.NativeKeyEvent; + +import java.util.*; + +public class HotKeyConfigurationService extends BaseConfigurationService implements PlainConfigurationService { + public HotKeyConfigurationService(ProfileDescriptor selectedProfile) { + super(selectedProfile); + } + + @Override + public HotKeysSettingsDescriptor getDefault() { + HotKeysSettingsDescriptor hotKeysSettingsDescriptor = new HotKeysSettingsDescriptor(); + List incNDataList = new ArrayList<>(); + incNDataList.add(new HotKeyPair(HotKeyType.N_INVITE_PLAYER,new HotKeyDescriptor("F1", NativeKeyEvent.VC_F1,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor("F2",NativeKeyEvent.VC_F2,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_KICK_PLAYER,new HotKeyDescriptor("F3",NativeKeyEvent.VC_F3,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_STILL_INTERESTING,new HotKeyDescriptor("F4",NativeKeyEvent.VC_F4,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor("F5",NativeKeyEvent.VC_F5,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_SWITCH_CHAT,new HotKeyDescriptor("F6",NativeKeyEvent.VC_F6,false,false,false))); + incNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor("F7",NativeKeyEvent.VC_F7,false,false,false))); + + List outNDataList = new ArrayList<>(); + outNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT,new HotKeyDescriptor("F1", NativeKeyEvent.VC_F1,false,false,false))); + outNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor("F2",NativeKeyEvent.VC_F2,false,false,false))); + outNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE,new HotKeyDescriptor("F3",NativeKeyEvent.VC_F3,false,false,false))); + outNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor("F4",NativeKeyEvent.VC_F4,false,false,false))); + outNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor("F5",NativeKeyEvent.VC_F5,false,false,false))); + + List scannerNDataList = new ArrayList<>(); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_QUICK_RESPONSE,new HotKeyDescriptor("F1", NativeKeyEvent.VC_F1,false,false,false))); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT,new HotKeyDescriptor("F2", NativeKeyEvent.VC_F2,false,false,false))); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor("F3",NativeKeyEvent.VC_F3,false,false,false))); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE,new HotKeyDescriptor("F4",NativeKeyEvent.VC_F4,false,false,false))); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor("F5",NativeKeyEvent.VC_F5,false,false,false))); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor("F6",NativeKeyEvent.VC_F6,false,false,false))); + + List taskBarNDataList = new ArrayList<>(); + taskBarNDataList.add(new HotKeyPair(HotKeyType.T_TO_HIDEOUT,new HotKeyDescriptor("F1",NativeKeyEvent.VC_F1,false,false,false))); +// taskBarNDataList.add(new HotKeyPair(HotKeyType.T_DND,new HotKeyDescriptor("F2",NativeKeyEvent.VC_F2,false,false,false))); + + hotKeysSettingsDescriptor.setIncNHotKeysList(incNDataList); + hotKeysSettingsDescriptor.setOutNHotKeysList(outNDataList); + hotKeysSettingsDescriptor.setScannerNHotKeysList(scannerNDataList); + hotKeysSettingsDescriptor.setTaskBarNHotKeysList(taskBarNDataList); + return hotKeysSettingsDescriptor; + } + + @Override + public void toDefault() { + this.selectedProfile.setHotKeysSettingsDescriptor(this.getDefault()); + } + + @Override + public void validate() { + if (this.selectedProfile.getHotKeysSettingsDescriptor() == null){ + this.selectedProfile.setHotKeysSettingsDescriptor(this.getDefault()); + } + } + + @Override + public HotKeysSettingsDescriptor get() { + return this.selectedProfile.getHotKeysSettingsDescriptor(); + } + + @Override + public void set(HotKeysSettingsDescriptor descriptor) { + this.selectedProfile.setHotKeysSettingsDescriptor(descriptor); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java deleted file mode 100644 index 6971f1b8..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/HotKeysConfigurationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.mercury.platform.shared.config.configration.impl; - - -import com.mercury.platform.shared.config.configration.BaseConfigurationService; -import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; -import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; -import com.mercury.platform.shared.config.descriptor.HotKeyType; -import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; -import com.mercury.platform.shared.store.MercuryStoreCore; -import org.jnativehook.keyboard.NativeKeyEvent; - -import java.util.HashMap; -import java.util.Map; - -public class HotKeysConfigurationService extends BaseConfigurationService> implements KeyValueConfigurationService { - public HotKeysConfigurationService(ProfileDescriptor selectedProfile) { - super(selectedProfile); - } - - @Override - public Map getDefault() { - Map keyMap = new HashMap<>(); - keyMap.put(HotKeyType.INVITE_PLAYER.name(),new HotKeyDescriptor("Alt + 1", NativeKeyEvent.VC_1,'1',true,false,false)); - keyMap.put(HotKeyType.TRADE_PLAYER.name(),new HotKeyDescriptor("Alt + 2",NativeKeyEvent.VC_2,'2',true,false,false)); - keyMap.put(HotKeyType.KICK_PLAYER.name(),new HotKeyDescriptor("Alt + 3",NativeKeyEvent.VC_3,'3',true,false,false)); - keyMap.put(HotKeyType.STILL_INTERESTING.name(),new HotKeyDescriptor("Alt + 4",NativeKeyEvent.VC_4,'4',true,false,false)); - keyMap.put(HotKeyType.CLOSE_NOTIFICATION.name(),new HotKeyDescriptor("Alt + 5",NativeKeyEvent.VC_5,'5',true,false,false)); - return keyMap; - } - - @Override - public void toDefault() { - this.selectedProfile.setHotKeysDataMap(this.getDefault()); - } - - @Override - public HotKeyDescriptor get(String key) { - return this.selectedProfile.getHotKeysDataMap().computeIfAbsent(key, k -> { - this.selectedProfile.getHotKeysDataMap().put(key,this.getDefault().get(key)); - MercuryStoreCore.saveConfigSubject.onNext(true); - return this.getDefault().get(key); - }); - } - - @Override - public Map getMap() { - return this.selectedProfile.getHotKeysDataMap(); - } - - @Override - public void set(Map map) { - this.selectedProfile.setHotKeysDataMap(map); - } - - @Override - public void validate() { - if (this.selectedProfile.getHotKeysDataMap() == null){ - this.selectedProfile.setHotKeysDataMap(this.getDefault()); - } - this.getMap().values().forEach(it -> { - if(it.getTitle().equals("")){ - it.setTitle("..."); - } - }); - } -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/NotificationConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/NotificationConfigurationService.java index 112c9370..6d23c8bd 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/NotificationConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/NotificationConfigurationService.java @@ -3,7 +3,7 @@ import com.mercury.platform.shared.config.configration.BaseConfigurationService; import com.mercury.platform.shared.config.configration.PlainConfigurationService; import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; import com.mercury.platform.shared.config.descriptor.ResponseButtonDescriptor; import com.mercury.platform.shared.entity.message.FlowDirections; @@ -12,27 +12,24 @@ import java.util.List; -public class NotificationConfigurationService extends BaseConfigurationService implements PlainConfigurationService { +public class NotificationConfigurationService extends BaseConfigurationService implements PlainConfigurationService { public NotificationConfigurationService(ProfileDescriptor selectedProfile) { super(selectedProfile); } @Override - public NotificationDescriptor getDefault() { - NotificationDescriptor notificationDescriptor = new NotificationDescriptor(); + public NotificationSettingsDescriptor getDefault() { + NotificationSettingsDescriptor notificationSettingsDescriptor = new NotificationSettingsDescriptor(); List defaultButtons = new ArrayList<>(); defaultButtons.add(new ResponseButtonDescriptor(0,false,"1m","one minute", new HotKeyDescriptor())); defaultButtons.add(new ResponseButtonDescriptor(1,true,"thx","thanks",new HotKeyDescriptor())); defaultButtons.add(new ResponseButtonDescriptor(2,false,"no thx", "no thanks",new HotKeyDescriptor())); defaultButtons.add(new ResponseButtonDescriptor(3,false,"sold", "sold",new HotKeyDescriptor())); - notificationDescriptor.setButtons(defaultButtons); - notificationDescriptor.setNotificationEnable(true); - notificationDescriptor.setLimitCount(3); - notificationDescriptor.setUnfoldCount(2); - notificationDescriptor.setDismissAfterKick(true); - notificationDescriptor.setShowLeague(false); - notificationDescriptor.setFlowDirections(FlowDirections.DOWNWARDS); - return notificationDescriptor; + List defaultOutButtons = new ArrayList<>(); + defaultOutButtons.add(new ResponseButtonDescriptor(0,false,"thanks","thanks", new HotKeyDescriptor())); + notificationSettingsDescriptor.setButtons(defaultButtons); + notificationSettingsDescriptor.setOutButtons(defaultOutButtons); + return notificationSettingsDescriptor; } @Override @@ -50,15 +47,18 @@ public void validate() { it.setHotKeyDescriptor(new HotKeyDescriptor()); } }); + if(this.get().getOutButtons().size() == 0){ + this.get().getOutButtons().add(new ResponseButtonDescriptor(0,false,"thanks","thanks", new HotKeyDescriptor())); + } } @Override - public NotificationDescriptor get() { + public NotificationSettingsDescriptor get() { return this.selectedProfile.getNotificationDescriptor(); } @Override - public void set(NotificationDescriptor descriptor) { + public void set(NotificationSettingsDescriptor descriptor) { this.selectedProfile.setNotificationDescriptor(descriptor); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java index 69d6dd8c..752fe9a1 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyDescriptor.java @@ -12,7 +12,6 @@ public class HotKeyDescriptor implements Serializable{ private String title = "..."; private int virtualKeyCode; - private char keyChar; private boolean menuPressed; private boolean shiftPressed; private boolean controlPressed; diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyPair.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyPair.java new file mode 100644 index 00000000..52c165d2 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyPair.java @@ -0,0 +1,13 @@ +package com.mercury.platform.shared.config.descriptor; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +public class HotKeyPair implements Serializable{ + private HotKeyType type; + private HotKeyDescriptor descriptor; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyType.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyType.java index 682a04ae..6fa12bb9 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyType.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeyType.java @@ -1,51 +1,96 @@ package com.mercury.platform.shared.config.descriptor; +import java.io.Serializable; import java.util.Arrays; import java.util.stream.Collectors; -public enum HotKeyType { - INVITE_PLAYER { +public enum HotKeyType implements Serializable{ + N_TRADE_PLAYER { @Override public String getIconPath() { - return "app/invite.png"; + return "app/trade.png"; } }, - TRADE_PLAYER { + N_OPEN_CHAT { @Override public String getIconPath() { - return "app/trade.png"; + return "app/openChat.png"; + } + }, + N_CLOSE_NOTIFICATION { + @Override + public String getIconPath() { + return "app/close.png"; + } + }, + //Incoming notification + N_INVITE_PLAYER { + @Override + public String getIconPath() { + return "app/invite.png"; } }, - KICK_PLAYER { + N_KICK_PLAYER { @Override public String getIconPath() { return "app/kick.png"; } }, - STILL_INTERESTING { + N_STILL_INTERESTING { @Override public String getIconPath() { return "app/still-interesting.png"; } }, - CLOSE_NOTIFICATION { + N_SWITCH_CHAT { @Override public String getIconPath() { - return "app/close.png"; + return "app/chat_history.png"; + } + }, + //Outgoing/scanner notification + N_VISITE_HIDEOUT { + @Override + public String getIconPath() { + return "app/visiteHideout.png"; + } + }, + N_LEAVE { + @Override + public String getIconPath() { + return "app/leave.png"; + } + }, + N_BACK_TO_HIDEOUT { + @Override + public String getIconPath() { + return "app/backToHideout.png"; + } + }, + //scanner + N_QUICK_RESPONSE { + @Override + public String getIconPath() { + return "app/chat_scanner_response.png"; + } + }, + T_TO_HIDEOUT { + @Override + public String getIconPath() { + return "app/hideout.png"; + } + }, + T_DND { + @Override + public String getIconPath() { + return "app/visible-dnd-mode.png"; } }; -// EXPAND_ALL { -// @Override -// public String getIconPath() { -// return null; -// } -// }; - public abstract String getIconPath(); - public static boolean contains(String entry){ + public static boolean contains(HotKeyType entry){ return Arrays.stream(HotKeyType.values()) - .filter(it -> it.name().equals(entry)) + .filter(it -> it.equals(entry)) .collect(Collectors.toList()) .size() != 0; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeysSettingsDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeysSettingsDescriptor.java new file mode 100644 index 00000000..73551fab --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/HotKeysSettingsDescriptor.java @@ -0,0 +1,15 @@ +package com.mercury.platform.shared.config.descriptor; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Data +public class HotKeysSettingsDescriptor implements Serializable { + private List incNHotKeysList = new ArrayList<>(); + private List outNHotKeysList = new ArrayList<>(); + private List scannerNHotKeysList = new ArrayList<>(); + private List taskBarNHotKeysList = new ArrayList<>(); +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationDescriptor.java deleted file mode 100644 index bfe78403..00000000 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationDescriptor.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mercury.platform.shared.config.descriptor; - -import com.mercury.platform.shared.entity.message.FlowDirections; -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -@Data -public class NotificationDescriptor implements Serializable{ - private boolean notificationEnable; - private int limitCount; - private int unfoldCount; - private FlowDirections flowDirections; - private boolean dismissAfterKick; - private boolean showLeague; - private List buttons; -} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationSettingsDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationSettingsDescriptor.java new file mode 100644 index 00000000..54e469dd --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/NotificationSettingsDescriptor.java @@ -0,0 +1,24 @@ +package com.mercury.platform.shared.config.descriptor; + +import com.mercury.platform.shared.entity.message.FlowDirections; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Data +public class NotificationSettingsDescriptor implements Serializable{ + private boolean incNotificationEnable = true; + private boolean outNotificationEnable = true; + private boolean scannerNotificationEnable = true; + private int limitCount = 3; + private int unfoldCount = 2; + private FlowDirections flowDirections = FlowDirections.DOWNWARDS; + private boolean dismissAfterKick = true; + private boolean dismissAfterLeave = true; + private boolean showLeague; + private List buttons = new ArrayList<>(); + private List outButtons = new ArrayList<>(); + private String playerNickname = "Set up your nickname in settings"; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java index 94a5ec5a..e8d8c9d3 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java @@ -13,10 +13,10 @@ public class ProfileDescriptor { private Map frameDescriptorMap; private Map soundDescriptorMap; private ApplicationDescriptor applicationDescriptor; - private NotificationDescriptor notificationDescriptor; + private NotificationSettingsDescriptor notificationDescriptor; private ScannerDescriptor scannerDescriptor; private Map scaleDataMap; - private Map hotKeysDataMap; + private HotKeysSettingsDescriptor hotKeysSettingsDescriptor; private List stashTabDescriptors; private List adrProfileDescriptorList; private List iconBundleList; diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ScannerDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ScannerDescriptor.java index e73bfd48..13ef838c 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ScannerDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ScannerDescriptor.java @@ -2,8 +2,10 @@ import lombok.Data; +import java.io.Serializable; + @Data -public class ScannerDescriptor { +public class ScannerDescriptor implements Serializable{ private String words; private String responseMessage; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/MessageDeserializer.java b/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/MessageDeserializer.java index a117b4ab..24cdff64 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/MessageDeserializer.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/MessageDeserializer.java @@ -5,13 +5,13 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; import java.lang.reflect.Type; -public class MessageDeserializer implements JsonDeserializer{ +public class MessageDeserializer implements JsonDeserializer{ @Override - public Message deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + public NotificationDescriptor deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return null; } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyMessage.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyTradeNotificationDescriptor.java similarity index 72% rename from app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyMessage.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyTradeNotificationDescriptor.java index 18a38a7b..9e8af2b8 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyMessage.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/CurrencyTradeNotificationDescriptor.java @@ -5,7 +5,7 @@ @EqualsAndHashCode(callSuper = true) @Data -public class CurrencyMessage extends Message { +public class CurrencyTradeNotificationDescriptor extends TradeNotificationDescriptor { private Double currForSaleCount; private String currForSaleTitle; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemMessage.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemTradeNotificationDescriptor.java similarity index 75% rename from app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemMessage.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemTradeNotificationDescriptor.java index 9879ce13..92a10c58 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemMessage.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/ItemTradeNotificationDescriptor.java @@ -5,7 +5,7 @@ @EqualsAndHashCode(callSuper = true) @Data -public class ItemMessage extends Message { +public class ItemTradeNotificationDescriptor extends TradeNotificationDescriptor { private String itemName; private String tabName; private int left; diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDefinition.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDefinition.java new file mode 100644 index 00000000..cf71400a --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDefinition.java @@ -0,0 +1,9 @@ +package com.mercury.platform.shared.entity.message; + +import lombok.Data; + +@Data +public class NotificationDefinition { + private T payload; + private NotificationType type; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/Message.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDescriptor.java similarity index 60% rename from app-core/src/main/java/com/mercury/platform/shared/entity/message/Message.java rename to app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDescriptor.java index 1214cff9..e842b226 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/entity/message/Message.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationDescriptor.java @@ -5,12 +5,9 @@ import java.util.Date; @Data -public class Message { +public class NotificationDescriptor { private String sourceString; private Date messageDate; private String whisperNickname; - private String offer; - private Double curCount; - private String currency; - private String league; + private NotificationType type; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationType.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationType.java new file mode 100644 index 00000000..76910d53 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/NotificationType.java @@ -0,0 +1,11 @@ +package com.mercury.platform.shared.entity.message; + + +public enum NotificationType { + INC_ITEM_MESSAGE, + INC_CURRENCY_MESSAGE, + OUT_ITEM_MESSAGE, + OUT_CURRENCY_MESSAGE, + SCANNER_MESSAGE, + HISTORY +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/PlainMessageDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/PlainMessageDescriptor.java new file mode 100644 index 00000000..2e2db477 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/PlainMessageDescriptor.java @@ -0,0 +1,10 @@ +package com.mercury.platform.shared.entity.message; + +import lombok.Data; + +@Data +public class PlainMessageDescriptor { + boolean incoming; + String nickName; + String message; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/TradeNotificationDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/TradeNotificationDescriptor.java new file mode 100644 index 00000000..55b93682 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/TradeNotificationDescriptor.java @@ -0,0 +1,13 @@ +package com.mercury.platform.shared.entity.message; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class TradeNotificationDescriptor extends NotificationDescriptor { + private String offer; + private Double curCount; + private String currency; + private String league; +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java index 51090bcc..8bac84be 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java @@ -6,10 +6,20 @@ import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; +import java.awt.*; +import java.awt.event.KeyEvent; + public class MercuryNativeKeyListener implements NativeKeyListener{ private boolean menuPressed; private boolean shiftPressed; private boolean ctrlpressed; + + private boolean block; + + public MercuryNativeKeyListener() { + MercuryStoreCore.blockHotkeySubject.subscribe(state -> this.block = state); + } + @Override public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { switch (nativeKeyEvent.getKeyCode()){ @@ -26,15 +36,9 @@ public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { break; } default:{ - HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); - hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode())); - hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode()); - hotKeyDescriptor.setControlPressed(this.ctrlpressed); - hotKeyDescriptor.setShiftPressed(this.shiftPressed); - hotKeyDescriptor.setMenuPressed(this.menuPressed); - - hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor)); - MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor); + if(!this.block) { + MercuryStoreCore.hotKeySubject.onNext(this.getDescriptor(nativeKeyEvent)); + } } } } @@ -59,7 +63,6 @@ public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) { @Override public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) { - } private String getButtonText(HotKeyDescriptor descriptor){ String text = descriptor.getTitle(); @@ -71,4 +74,15 @@ private String getButtonText(HotKeyDescriptor descriptor){ text = "Ctrl + " + text; return text; } + private HotKeyDescriptor getDescriptor(NativeKeyEvent nativeKeyEvent){ + HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); + hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode())); + hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode()); + hotKeyDescriptor.setControlPressed(this.ctrlpressed); + hotKeyDescriptor.setShiftPressed(this.shiftPressed); + hotKeyDescriptor.setMenuPressed(this.menuPressed); + + hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor)); + return hotKeyDescriptor; + } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java index f2861114..8b72d5e8 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java +++ b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java @@ -7,8 +7,10 @@ import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState; import com.mercury.platform.shared.entity.message.MercuryError; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; import com.mercury.platform.shared.config.descriptor.SoundDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDefinition; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; import rx.subjects.PublishSubject; @@ -22,8 +24,8 @@ public class MercuryStoreCore { public static final PublishSubject removeInterceptorSubject = PublishSubject.create(); public static final PublishSubject chatCommandSubject = PublishSubject.create(); public static final PublishSubject openChatSubject = PublishSubject.create(); - public static final PublishSubject messageSubject = PublishSubject.create(); - public static final PublishSubject outMessageSubject = PublishSubject.create(); + public static final PublishSubject messageSubject = PublishSubject.create(); + public static final PublishSubject outMessageSubject = PublishSubject.create(); public static final PublishSubject appLoadingSubject = PublishSubject.create(); public static final PublishSubject showingDelaySubject = PublishSubject.create(); public static final PublishSubject stringAlertSubject = PublishSubject.create(); @@ -32,7 +34,7 @@ public class MercuryStoreCore { public static final PublishSubject chunkLoadedSubject = PublishSubject.create(); public static final PublishSubject buttonsChangedSubject = PublishSubject.create(); public static final PublishSubject tooltipSubject = PublishSubject.create(); - public static final PublishSubject notificationSubject = PublishSubject.create(); + public static final PublishSubject alertSubject = PublishSubject.create(); public static final PublishSubject playerJoinSubject = PublishSubject.create(); public static final PublishSubject playerLeftSubject = PublishSubject.create(); public static final PublishSubject requestPatchSubject = PublishSubject.create(); @@ -46,6 +48,15 @@ public class MercuryStoreCore { public static final PublishSubject toDefaultSubject = PublishSubject.create(); public static final PublishSubject changeProfileSubject = PublishSubject.create(); public static final PublishSubject hotKeySubject = PublishSubject.create(); + public static final PublishSubject hotKeyReleaseSubject = PublishSubject.create(); + public static final PublishSubject blockHotkeySubject = PublishSubject.create(); public static final PublishSubject errorHandlerSubject = PublishSubject.create(); public static final PublishSubject adrVisibleSubject = PublishSubject.create(); + + public static final PublishSubject newNotificationSubject = PublishSubject.create(); + public static final PublishSubject removeNotificationSubject = PublishSubject.create(); + public static final PublishSubject plainMessageSubject = PublishSubject.create(); + public static final PublishSubject newScannerMessageSubject = PublishSubject.create(); + public static final PublishSubject removeScannerNotificationSubject = PublishSubject.create(); + public static final PublishSubject expiredNotificationSubject = PublishSubject.create(); } diff --git a/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java b/app-core/src/test/java/com/mercury/platform/shared/NotificationDescriptorParserTest.java similarity index 61% rename from app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java rename to app-core/src/test/java/com/mercury/platform/shared/NotificationDescriptorParserTest.java index d042512d..f3b9c2d4 100644 --- a/app-core/src/test/java/com/mercury/platform/shared/MessageParserTest.java +++ b/app-core/src/test/java/com/mercury/platform/shared/NotificationDescriptorParserTest.java @@ -1,7 +1,7 @@ package com.mercury.platform.shared; -import com.mercury.platform.shared.entity.message.CurrencyMessage; -import com.mercury.platform.shared.entity.message.ItemMessage; +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import org.junit.Before; import org.junit.Test; @@ -10,7 +10,7 @@ /** * Created by Константин on 11.01.2017. */ -public class MessageParserTest { +public class NotificationDescriptorParserTest { private MessageParser parser; @Before public void before(){ @@ -19,14 +19,14 @@ public void before(){ @Test public void testPoeTrade() throws Exception{ - ItemMessage message1 = (ItemMessage) parser.parse("@From Pubesmannen: Hi, I would like to buy your Bronn's Lithe Cutthroat's Garb listed for 1 alteration in Hardcore Legacy (stash tab \"Maps\"; position: left 5, top 6)"); + ItemTradeNotificationDescriptor message1 = (ItemTradeNotificationDescriptor) parser.parse("@From Pubesmannen: Hi, I would like to buy your Bronn's Lithe Cutthroat's Garb listed for 1 alteration in Hardcore Legacy (stash tab \"Maps\"; position: left 5, top 6)"); assertEquals(message1.getWhisperNickname(),"Pubesmannen"); assertEquals(message1.getItemName(),"Bronn's Lithe Cutthroat's Garb"); assertEquals(message1.getCurrency(),"alteration"); assertEquals(message1.getCurCount(),new Double(1)); assertEquals(message1.getOffer(),""); - ItemMessage message2 = (ItemMessage) parser.parse("@From Pubesmannen: Hi, I would like to buy your Bronn's Lithe Cutthroat's Garb listed for 15 exalt in Legacy (stash tab \"Maps\"; position: left 5, top 6) offer 32"); + ItemTradeNotificationDescriptor message2 = (ItemTradeNotificationDescriptor) parser.parse("@From Pubesmannen: Hi, I would like to buy your Bronn's Lithe Cutthroat's Garb listed for 15 exalt in Legacy (stash tab \"Maps\"; position: left 5, top 6) offer 32"); assertEquals(message2.getWhisperNickname(),"Pubesmannen"); assertEquals(message2.getItemName(),"Bronn's Lithe Cutthroat's Garb"); assertEquals(message2.getCurrency(),"exalt"); @@ -36,7 +36,7 @@ public void testPoeTrade() throws Exception{ } @Test public void testPoeTradeNoBuyout() throws Exception{ - ItemMessage message1 = (ItemMessage) parser.parse("@From Pubesmannen: Hi, I would like to buy your level 1 4% Reduced Mana Support in Hardcore Legacy (stash tab \"qgems\"; position: left 12, top 4)"); + ItemTradeNotificationDescriptor message1 = (ItemTradeNotificationDescriptor) parser.parse("@From Pubesmannen: Hi, I would like to buy your level 1 4% Reduced Mana Support in Hardcore Legacy (stash tab \"qgems\"; position: left 12, top 4)"); assertEquals(message1.getWhisperNickname(),"Pubesmannen"); assertEquals(message1.getItemName(),"level 1 4% Reduced Mana Support"); assertEquals(message1.getCurCount(),new Double(0d)); @@ -44,7 +44,7 @@ public void testPoeTradeNoBuyout() throws Exception{ assertEquals(message1.getOffer(),""); assertEquals(message1.getLeague(),"Hardcore Legacy"); - ItemMessage message2 = (ItemMessage) parser.parse("@From Pubesmannen: Hi, I would like to buy your level 1 4% Reduced Mana Support in Hardcore (stash tab \"qgems\"; position: left 12, top 4)"); + ItemTradeNotificationDescriptor message2 = (ItemTradeNotificationDescriptor) parser.parse("@From Pubesmannen: Hi, I would like to buy your level 1 4% Reduced Mana Support in Hardcore (stash tab \"qgems\"; position: left 12, top 4)"); assertEquals(message2.getWhisperNickname(),"Pubesmannen"); assertEquals(message2.getItemName(),"level 1 4% Reduced Mana Support"); assertEquals(message2.getCurCount(),new Double(0d)); @@ -55,7 +55,7 @@ public void testPoeTradeNoBuyout() throws Exception{ @Test public void testPoeCurrency() throws Exception{ - CurrencyMessage message1 = (CurrencyMessage) parser.parse("@From tradeeer: Hi, I'd like to buy your 366 chaos for my 5 exalted in Legacy."); + CurrencyTradeNotificationDescriptor message1 = (CurrencyTradeNotificationDescriptor) parser.parse("@From tradeeer: Hi, I'd like to buy your 366 chaos for my 5 exalted in Legacy."); assertEquals(message1.getWhisperNickname(),"tradeeer"); assertEquals(message1.getCurrForSaleCount(),new Double(366)); assertEquals(message1.getCurrForSaleTitle(),"chaos"); @@ -63,7 +63,7 @@ public void testPoeCurrency() throws Exception{ assertEquals(message1.getCurCount(),new Double(5)); assertEquals(message1.getOffer(),""); - CurrencyMessage message2 = (CurrencyMessage) parser.parse("@From tradeeer: Hi, I'd like to buy your 366 chaos for my 5 exalted in Legacy. 123"); + CurrencyTradeNotificationDescriptor message2 = (CurrencyTradeNotificationDescriptor) parser.parse("@From tradeeer: Hi, I'd like to buy your 366 chaos for my 5 exalted in Legacy. 123"); assertEquals(message2.getWhisperNickname(),"tradeeer"); assertEquals(message2.getCurrForSaleCount(),new Double(366)); assertEquals(message2.getCurrForSaleTitle(),"chaos"); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrManager.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrManager.java index c8204d7c..a506954c 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrManager.java @@ -202,6 +202,7 @@ public void subscribe() { this.selectedProfile.getContents().remove(descriptor); targetFrame.dispose(); }); + this.mainPanel.setFromGroup(false); this.mainPanel.setPayload(null); this.adrManagerFrame.removeNode(descriptor); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrCaptureOutComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrCaptureOutComponentFrame.java index a3059786..eabad999 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrCaptureOutComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrCaptureOutComponentFrame.java @@ -101,6 +101,11 @@ public void onDestroy() { this.component.onDestroy(); } + @Override + public void onViewInit() { + + } + public class CaptureDraggedFrameMotionListener extends MouseAdapter { @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java index 76f4d383..b0199c2f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java @@ -402,17 +402,23 @@ public void mouseReleased(MouseEvent e) { }); return opacitySlider; } - public JSlider getFpsSlider(AdrCaptureDescriptor descriptor){ - JSlider opacitySlider = this.componentsFactory.getSlider(1,60, descriptor.getFps()); - opacitySlider.setBackground(AppThemeColor.SLIDE_BG); - opacitySlider.addMouseListener(new MouseAdapter() { + public JPanel getFpsSliderPanel(AdrCaptureDescriptor descriptor){ + JPanel fpsPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); + JLabel fpsCountLabel = this.componentsFactory.getTextLabel(String.valueOf(descriptor.getFps())); + fpsCountLabel.setPreferredSize(new Dimension(30,26)); + JSlider fpsSlider = this.componentsFactory.getSlider(1,60, descriptor.getFps()); + fpsSlider.setBackground(AppThemeColor.SLIDE_BG); + fpsSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { - descriptor.setFps(opacitySlider.getValue()); + descriptor.setFps(fpsSlider.getValue()); + fpsCountLabel.setText(String.valueOf(fpsSlider.getValue())); MercuryStoreUI.adrReloadSubject.onNext(descriptor); } }); - return opacitySlider; + fpsPanel.add(fpsCountLabel,BorderLayout.LINE_START); + fpsPanel.add(fpsSlider,BorderLayout.CENTER); + return fpsPanel; } public JTextField getFontSizeField(AdrDurationComponentDescriptor descriptor){ return this.getSmartField(descriptor.getFontSize(), new IntegerFieldValidator(4, 1000), value -> { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java index f13e4983..d66db814 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java @@ -61,10 +61,8 @@ public AdrManagerFrame(AdrProfileDescriptor selectedProfile) { UIManager.put("ComboBox.selectionForeground", AppThemeColor.ADR_POPUP_BG); UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG); } - @Override - protected void initialize() { - super.initialize(); + public void onViewInit() { this.initRootPanel(); this.hideButton.addMouseListener(new MouseAdapter() { @Override @@ -77,7 +75,6 @@ public void mousePressed(MouseEvent e) { }); this.add(this.root,BorderLayout.CENTER); this.add(this.getBottomPanel(),BorderLayout.PAGE_END); - } public void setPage(AdrPagePanel page){ if(currentPage != null){ diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrSingleComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrSingleComponentFrame.java index 12113523..fc64a639 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrSingleComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrSingleComponentFrame.java @@ -70,5 +70,11 @@ public void onDestroy() { super.onDestroy(); this.adrReloadSubscription.unsubscribe(); this.component.onDestroy(); + this.setVisible(false); + } + + @Override + public void onViewInit() { + } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrTrackerGroupFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrTrackerGroupFrame.java index fa9e734b..9a9c898a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrTrackerGroupFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrTrackerGroupFrame.java @@ -72,4 +72,9 @@ public void onDestroy() { this.adrReloadSubscription.unsubscribe(); this.trackerGroupPanel.onDestroy(); } + + @Override + public void onViewInit() { + + } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCaptureOutPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCaptureOutPanel.java index b5bf0b61..1585f3d0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCaptureOutPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCaptureOutPanel.java @@ -15,11 +15,11 @@ public AdrCaptureOutPanel(AdrCaptureDescriptor descriptor, ComponentsFactory com } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new GridLayout(1,1)); this.setPreferredSize(this.descriptor.getCaptureSize()); this.setBackground(AppThemeColor.ADR_CAPTURE_BG); - this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER,4)); + this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_GREEN,4)); MercuryStoreUI.adrRepaintSubject.onNext(true); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCapturePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCapturePanel.java index 318b4aa8..84397092 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCapturePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrCapturePanel.java @@ -21,7 +21,7 @@ public AdrCapturePanel(AdrCaptureDescriptor groupDescriptor, ComponentsFactory c } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new GridLayout(1,1)); this.setPreferredSize(this.descriptor.getSize()); this.captureLabel = new JLabel(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrComponentPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrComponentPanel.java index 6b9a0107..c940342a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrComponentPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrComponentPanel.java @@ -3,9 +3,8 @@ import com.mercury.platform.shared.AsSubscriber; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; import com.mercury.platform.shared.store.DestroySubscription; -import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.Getter; import rx.Subscription; @@ -13,7 +12,7 @@ import javax.swing.*; -public abstract class AdrComponentPanel extends JPanel implements HasUI,AsSubscriber,DestroySubscription { +public abstract class AdrComponentPanel extends JPanel implements ViewInit,AsSubscriber,DestroySubscription { @Getter protected T descriptor; protected ComponentsFactory componentsFactory; @@ -25,7 +24,7 @@ public AdrComponentPanel(T descriptor, ComponentsFactory componentsFactory) { this.descriptor = descriptor; this.componentsFactory = componentsFactory; this.subscribe(); - this.createUI(); + this.onViewInit(); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java index d291a0c4..73949db7 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java @@ -70,11 +70,11 @@ protected void onHotKeyPressed() { @Override protected void onUpdate() { this.remove(this.tracker); - this.createUI(); + this.onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new GridLayout(1,1)); this.setPreferredSize(this.descriptor.getSize()); this.tracker = new MercuryTracker(this.descriptor); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationComponentPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationComponentPanel.java index c3726a41..e943e27e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationComponentPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationComponentPanel.java @@ -5,6 +5,8 @@ import com.mercury.platform.ui.components.ComponentsFactory; import rx.Subscription; +import javax.swing.*; + public abstract class AdrDurationComponentPanel extends AdrComponentPanel{ private Subscription adrHotKeySubscription; @@ -16,11 +18,13 @@ public AdrDurationComponentPanel(T descriptor, ComponentsFactory componentsFacto public void subscribe() { super.subscribe(); this.adrHotKeySubscription = MercuryStoreCore.hotKeySubject.subscribe(hotKey -> { - if(this.descriptor.getHotKeyDescriptor() != null) { - if (this.descriptor.getHotKeyDescriptor().equals(hotKey) && !this.inSettings) { - this.onHotKeyPressed(); + SwingUtilities.invokeLater(()-> { + if(this.descriptor.getHotKeyDescriptor() != null) { + if (this.descriptor.getHotKeyDescriptor().equals(hotKey) && !this.inSettings) { + this.onHotKeyPressed(); + } } - } + }); }); } protected abstract void onHotKeyPressed(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrTrackerGroupPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrTrackerGroupPanel.java index 05995cfa..bfaab406 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrTrackerGroupPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrTrackerGroupPanel.java @@ -33,7 +33,7 @@ public void subscribe() { .collect(Collectors.toList()) .size() != this.descriptor.getCells().size()){ this.removeAll(); - this.createUI(); + this.onViewInit(); MercuryStoreCore.saveConfigSubject.onNext(true); } MercuryStoreUI.adrRepaintSubject.onNext(true); @@ -68,7 +68,7 @@ private void init(){ } @Override - public void createUI() { + public void onViewInit() { this.cells = new ArrayList<>(); this.setLayout(new GridLayout()); this.descriptor.getCells().forEach(component -> { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrCapturePagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrCapturePagePanel.java index 7cff5d34..01687e9d 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrCapturePagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrCapturePagePanel.java @@ -34,7 +34,7 @@ protected void init() { JPanel locationPanel = this.adrComponentsFactory.getLocationPanel(this.payload, false); JPanel sectorSizePanel = this.adrComponentsFactory.getCaptureSizePanel(this.payload); JPanel sectorLocationPanel = this.adrComponentsFactory.getCaptureLocationPanel(this.payload); - JSlider fpsSlider = this.adrComponentsFactory.getFpsSlider(this.payload); + JPanel fpsPanel = this.adrComponentsFactory.getFpsSliderPanel(this.payload); JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); @@ -50,17 +50,17 @@ protected void init() { generalPanel.add(titleField); generalPanel.add(sizeLabel); generalPanel.add(componentSizePanel); - generalPanel.add(locationLabel); - generalPanel.add(locationPanel); generalPanel.add(sectorSizeLabel); generalPanel.add(sectorSizePanel); + generalPanel.add(locationLabel); + generalPanel.add(locationPanel); generalPanel.add(sectorLocationLabel); generalPanel.add(sectorLocationPanel); generalPanel.add(fpsLabel); - generalPanel.add(fpsSlider); + generalPanel.add(fpsPanel); - specPanel.add(opacityLabel); - specPanel.add(opacitySlider); + generalPanel.add(opacityLabel); + generalPanel.add(opacitySlider); specPanel.setVisible(this.advancedExpanded); @@ -80,7 +80,7 @@ public void componentHidden(ComponentEvent e) { advancedPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); container.add(this.componentsFactory.wrapToSlide(generalPanel)); - container.add(this.componentsFactory.wrapToSlide(advancedPanel)); +// container.add(this.componentsFactory.wrapToSlide(advancedPanel)); container.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrMainPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrMainPagePanel.java index 4643a9fc..6cad9e0e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrMainPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrMainPagePanel.java @@ -61,7 +61,7 @@ public void mouseClicked(MouseEvent e) { } }); JPanel createCaptureComponent = this.getButton( - "app/adr/create_pb_group.png", + "app/adr/capture_icon.png", "Capture"); createCaptureComponent.addMouseListener(new MouseAdapter() { @Override @@ -108,27 +108,29 @@ public void mouseClicked(MouseEvent e) { new AdrImportDialog(importButton).setVisible(true); } }); + JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 1), AppThemeColor.FRAME); if(this.fromGroup) { switch (((AdrTrackerGroupDescriptor) this.payload).getContentType()){ case ICONS:{ - container.add(this.componentsFactory.wrapToSlide(createIcon)); + root.add(this.componentsFactory.wrapToSlide(createIcon)); break; } case PROGRESS_BARS:{ - container.add(this.componentsFactory.wrapToSlide(createPb)); + root.add(this.componentsFactory.wrapToSlide(createPb)); break; } } }else { - container.add(this.componentsFactory.wrapToSlide(createIcon)); - container.add(this.componentsFactory.wrapToSlide(createPb)); + root.add(this.componentsFactory.wrapToSlide(createIcon)); + root.add(this.componentsFactory.wrapToSlide(createPb)); } if(!this.fromGroup) { - container.add(this.componentsFactory.wrapToSlide(createIconsGroup)); - container.add(this.componentsFactory.wrapToSlide(createPbGroup)); + root.add(this.componentsFactory.wrapToSlide(createCaptureComponent)); + root.add(this.componentsFactory.wrapToSlide(createIconsGroup)); + root.add(this.componentsFactory.wrapToSlide(createPbGroup)); } -// container.add(this.componentsFactory.wrapToSlide(createCaptureComponent)); - container.add(this.componentsFactory.wrapToSlide(importButton)); + root.add(this.componentsFactory.wrapToSlide(importButton)); + container.add(root); this.add(verticalContainer,BorderLayout.CENTER); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrNodePanel.java index 5f739479..9dcb6567 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrNodePanel.java @@ -4,7 +4,7 @@ import com.mercury.platform.ui.adr.components.AdrComponentsFactory; import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.Getter; @@ -13,7 +13,7 @@ import java.awt.*; -public abstract class AdrNodePanel extends JPanel implements HasUI { +public abstract class AdrNodePanel extends JPanel implements ViewInit { @Getter protected D descriptor; protected ComponentsFactory componentsFactory = new ComponentsFactory(); @@ -34,7 +34,7 @@ public AdrNodePanel(AdrTreeNode treeNode) { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.SLIDE_BG); this.setBorder(BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER)); - this.createUI(); + this.onViewInit(); } protected abstract void update(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogCaptureNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogCaptureNodePanel.java index cfbc5874..b2ffe1f6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogCaptureNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogCaptureNodePanel.java @@ -19,7 +19,7 @@ public AdrDialogCaptureNodePanel(AdrTreeNode treeNode) { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setPreferredSize(new Dimension(180, 30)); root.setBackground(AppThemeColor.ADR_BG); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogGroupNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogGroupNodePanel.java index 0a1b7a6b..062682d9 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogGroupNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogGroupNodePanel.java @@ -30,7 +30,7 @@ protected void update() { } @Override - public void createUI() { + public void onViewInit() { this.container = this.componentsFactory.getJPanel(new GridLayout(descriptor.getCells().size(), 1)); this.container.setVisible(false); this.add(this.container,BorderLayout.CENTER); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogIconNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogIconNodePanel.java index 9c954f5a..35af0b69 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogIconNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogIconNodePanel.java @@ -26,7 +26,7 @@ protected void update() { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.ADR_BG); MercuryTracker tracker = new MercuryTracker(this.descriptor); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogPBNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogPBNodePanel.java index 98a2d8ad..63b36ec6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogPBNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogPBNodePanel.java @@ -24,7 +24,7 @@ protected void update() { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); root.setBackground(AppThemeColor.SLIDE_BG); MercuryTracker tracker = new MercuryTracker(descriptor); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrCaptureNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrCaptureNodePanel.java index 745256a7..755b27ac 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrCaptureNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrCaptureNodePanel.java @@ -18,7 +18,7 @@ public AdrCaptureNodePanel(AdrTreeNode treeNode) { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.ADR_BG); this.titleLabel = this.componentsFactory.getTextLabel(this.descriptor.getTitle()); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrGroupNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrGroupNodePanel.java index 89cab97f..67f3f5ed 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrGroupNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrGroupNodePanel.java @@ -33,7 +33,7 @@ protected void update() { @Override - public void createUI() { + public void onViewInit() { MercuryStoreUI.adrSelectSubject.subscribe(descriptor -> { if(this.descriptor.equals(descriptor)){ this.container.setVisible(true); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrIconNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrIconNodePanel.java index 3324fd4f..3dc41cad 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrIconNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrIconNodePanel.java @@ -30,7 +30,7 @@ protected void update() { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.ADR_BG); this.tracker = new MercuryTracker(this.descriptor); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrProgressBarNodePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrProgressBarNodePanel.java index 67205cff..f92ca889 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrProgressBarNodePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrProgressBarNodePanel.java @@ -31,7 +31,7 @@ protected void update() { } @Override - public void createUI() { + public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); root.setBackground(AppThemeColor.SLIDE_BG); this.tracker = new MercuryTracker(descriptor); 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 5ee670bb..a2cd2f2f 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 @@ -15,6 +15,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -45,6 +46,7 @@ public class ComponentsFactory{ private Font ITALIC_FONT; private Font REGULAR_FONT; private Font SMALLCAPS_FONT; + @Getter private Font DEFAULT_FONT; private float scale = 1f; @@ -96,13 +98,27 @@ protected void paintBorder(Graphics g) { button.setForeground(AppThemeColor.TEXT_DEFAULT); button.setFocusPainted(false); button.addMouseListener(new MouseAdapter() { + Border prevBorder; @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - MercuryStoreCore.soundSubject.onNext(SoundType.CLICKS); - } + public void mouseEntered(MouseEvent e) { + this.prevBorder = button.getBorder(); + CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), + BorderFactory.createLineBorder(button.getBackground(), 3) + ); + button.setBorder(compoundBorder); + button.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + + @Override + public void mouseExited(MouseEvent e) { + button.setBorder(prevBorder); + button.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); + button.addActionListener(action -> { + MercuryStoreCore.soundSubject.onNext(SoundType.CLICKS); + }); if(isAscii(text)){ button.setFont(getSelectedFont(fontStyle).deriveFont(scale*fontSize)); }else { @@ -150,6 +166,13 @@ public JButton getBorderedButton(String text, float fontSize){ ); return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale*fontSize); } + public JButton getBorderedButton(String text, float fontSize, Color background, Color outerBorderColor, Color innerBorderColor){ + CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(outerBorderColor, 1), + BorderFactory.createLineBorder(innerBorderColor, 3) + ); + return getButton(FontStyle.BOLD, background, compoundBorder, text, scale*fontSize); + } public Component setUpToggleCallbacks(Component button,ToggleCallback firstState, ToggleCallback secondState, boolean initialState){ button.addMouseListener(new MouseAdapter() { @@ -193,13 +216,28 @@ protected void paintBorder(Graphics g) { if(tooltip.length() > 0) { button.addMouseListener(new TooltipMouseListener(tooltip)); } + button.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + button.addActionListener(action -> { + MercuryStoreCore.soundSubject.onNext(SoundType.CLICKS); + button.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + }); button.addMouseListener(new MouseAdapter() { + Border prevBorder; @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - MercuryStoreCore.soundSubject.onNext(SoundType.CLICKS); - } + public void mouseEntered(MouseEvent e) { + prevBorder = button.getBorder(); + button.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER), + BorderFactory.createEmptyBorder(3,3,3,3))); + button.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + + @Override + public void mouseExited(MouseEvent e) { + button.setBorder(prevBorder); + button.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } + }); button.setBorder(BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,4)); button.setVerticalAlignment(SwingConstants.CENTER); @@ -331,6 +369,16 @@ public JLabel getIconLabel(String iconPath, int size){ } return iconLabel; } + public JLabel getIconLabel(String iconPath, int size, int aligment){ + JLabel iconLabel = new JLabel(); + try { + iconLabel.setIcon(getIcon(iconPath,(int)(scale*size))); + } catch (Exception e) { + return getTextLabel(StringUtils.substringBetween(iconPath,"/",".")); + } + iconLabel.setHorizontalAlignment(aligment); + return iconLabel; + } public JLabel getIconLabel(URL url, int size){ JLabel iconLabel = new JLabel(); try { @@ -407,14 +455,14 @@ public JCheckBox getCheckBox(String tooltip){ JCheckBox checkBox = new JCheckBox(); checkBox.setFocusPainted(false); checkBox.setBackground(AppThemeColor.TRANSPARENT); - checkBox.setUI(new WindowsButtonUI()); +// checkBox.setUI(new WindowsButtonUI()); checkBox.addMouseListener(new TooltipMouseListener(tooltip)); return checkBox; } public JCheckBox getCheckBox(boolean value){ JCheckBox checkBox = new JCheckBox(); checkBox.setSelected(value); - checkBox.setUI(new WindowsButtonUI()); +// checkBox.setUI(new WindowsButtonUI()); checkBox.setFocusPainted(false); checkBox.setBackground(AppThemeColor.TRANSPARENT); return checkBox; @@ -485,7 +533,7 @@ public JSlider getSlider(int min, int max, int value){ slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); // slider.setPaintLabels(true); - slider.setUI(new WindowsSliderUI(slider)); +// slider.setUI(new WindowsSliderUI(slider)); slider.setForeground(AppThemeColor.TEXT_DEFAULT); slider.setFont(REGULAR_FONT.deriveFont(15f)); slider.setRequestFocusEnabled(false); @@ -619,7 +667,7 @@ private boolean matches(char c) { public JPanel getJPanel(LayoutManager layoutManager) { JPanel panel = new JPanel(layoutManager); - panel.setBackground(AppThemeColor.FRAME_RGB); + panel.setBackground(AppThemeColor.FRAME); return panel; } public JPanel getJPanel(LayoutManager layoutManager,Color bg) { @@ -660,7 +708,7 @@ public Component add(Component comp) { return panel.add(comp); } }; - wrapper.setBackground(AppThemeColor.FRAME_RGB); + wrapper.setBackground(AppThemeColor.FRAME); wrapper.setBorder(BorderFactory.createEmptyBorder(top,left,bottom,right)); wrapper.add(panel,BorderLayout.CENTER); return wrapper; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/font/FontStyle.java b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/font/FontStyle.java index 0015f1a0..8afeffa5 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/font/FontStyle.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/font/FontStyle.java @@ -4,5 +4,5 @@ * Created by Константин on 23.12.2016. */ public enum FontStyle { - ITALIC, BOLD, REGULAR, SMALLCAPS + ITALIC, BOLD, REGULAR, SMALLCAPS,DEFAULT } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryComboBoxUI.java b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryComboBoxUI.java index 3d59fa0d..b1aec1ac 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryComboBoxUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryComboBoxUI.java @@ -13,7 +13,7 @@ public static MercuryComboBoxUI createUI(JComponent c) { } @Override protected JButton createArrowButton() { - return new ComponentsFactory().getIconButton("app/expand-combobox.png",16, AppThemeColor.FRAME_ALPHA,"Expand."); + return new ComponentsFactory().getIconButton("app/expand-combobox.png",16, AppThemeColor.HEADER,"Expand."); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryScrollBarUI.java b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryScrollBarUI.java index ffe16b0e..c37eb2c0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryScrollBarUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/style/MercuryScrollBarUI.java @@ -14,7 +14,7 @@ public MercuryScrollBarUI(Color color) { this.scrollColor = color; } public MercuryScrollBarUI() { - this.scrollColor = AppThemeColor.BUTTON; + this.scrollColor = AppThemeColor.SCROLL_BAR; } @Override 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 deleted file mode 100644 index 7fad8e30..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatFilterPanel.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.mercury.platform.ui.components.panel.chat; - -import com.mercury.platform.core.misc.SoundType; -import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; -import com.mercury.platform.ui.components.panel.VerticalScrollContainer; -import com.mercury.platform.ui.frame.titled.chat.ChatFilterFrame; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; -import net.jodah.expiringmap.ExpiringMap; -import org.apache.commons.lang3.StringUtils; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseWheelEvent; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -public class ChatFilterPanel extends JPanel { - private Map expiresMessages; - private ComponentsFactory componentsFactory; - private HtmlMessageBuilder messageBuilder; - - private boolean scrollToBottom = true; - private boolean soundEnable = false; - private JPanel container; - public ChatFilterPanel() { - this.componentsFactory = new ComponentsFactory(); - this.messageBuilder = new HtmlMessageBuilder(); - this.expiresMessages = ExpiringMap.builder() - .expiration(10, TimeUnit.SECONDS) - .build(); - container = new VerticalScrollContainer(); - container.setBackground(AppThemeColor.TRANSPARENT); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); - - this.setBackground(AppThemeColor.TRANSPARENT); - this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(2,2,2,0), - BorderFactory.createLineBorder(AppThemeColor.HEADER) - )); - - JScrollPane scrollPane = new JScrollPane(container); - 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) { - MercuryStoreUI.repaintSubject.onNext(ChatFilterFrame.class); - } - }); - scrollPane.addMouseWheelListener(e -> MercuryStoreUI.scrollToEndSubject.onNext(false)); - - container.getParent().setBackground(AppThemeColor.TRANSPARENT); - JScrollBar vBar = scrollPane.getVerticalScrollBar(); - vBar.setBackground(AppThemeColor.SLIDE_BG); - vBar.setUI(new MercuryScrollBarUI()); - vBar.setPreferredSize(new Dimension(15, Integer.MAX_VALUE)); - vBar.setUnitIncrement(3); - vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); - vBar.addAdjustmentListener(e -> { - MercuryStoreUI.repaintSubject.onNext(ChatFilterFrame.class); - }); - - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); - this.add(scrollPane); - } - public void addMessage(String stubMessage){ - String message = StringUtils.substringAfter(stubMessage,"] $"); - if(message.isEmpty()){ - message = StringUtils.substringAfter(stubMessage,"] #"); - } - - this.addMessageToFilter(message); - MercuryStoreUI.repaintSubject.onNext(ChatFilterFrame.class); - } - - public void scrollToBottom(boolean value) { - this.scrollToBottom = value; - if (scrollToBottom) { - container.scrollRectToVisible(new Rectangle(0, container.getHeight() - 1, 1, 1)); - } - } - - public void sound(boolean enable){ - this.soundEnable = enable; - } - - private void addMessageToFilter(String message) { - if(!message.isEmpty()){ - String nickname = StringUtils.substringBefore(message, ":"); - String messageContent = StringUtils.substringAfter(message, nickname + ":"); - nickname = StringUtils.deleteWhitespace(nickname); - if(nickname.contains(">")) { - nickname = StringUtils.substringAfterLast(nickname, ">"); - } - if(!expiresMessages.containsValue(message)){ - ChatMessagePanel chatMessagePanel = new ChatMessagePanel( - this.componentsFactory, - nickname, - messageBuilder.build(messageContent)); - container.add(chatMessagePanel); - trimContainer(); - expiresMessages.put(nickname,message); - MercuryStoreUI.packSubject.onNext(ChatFilterFrame.class); - if(soundEnable){ - MercuryStoreCore.soundSubject.onNext(SoundType.CHAT_SCANNER); - } - if(scrollToBottom) { - container.scrollRectToVisible(new Rectangle(0, container.getHeight() - 1, 1, 1)); - } - } - } - } - private void trimContainer(){ - if(container.getComponentCount() > 30){ - container.remove(0); - } - } - public void clear(){ - container.removeAll(); - } - public void setNewChunks(List chunks){ - this.messageBuilder.setChunkStrings(chunks); - } -} 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 74482008..fde831a0 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 @@ -7,7 +7,7 @@ import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.TooltipConstants; import lombok.NonNull; @@ -18,7 +18,7 @@ import java.awt.event.MouseEvent; -public class ChatMessagePanel extends JPanel implements HasUI{ +public class ChatMessagePanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; private PlainConfigurationService scannerService; private String message; @@ -37,11 +37,11 @@ public ChatMessagePanel( this.componentsFactory = componentsFactory; this.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); this.setBackground(AppThemeColor.TRANSPARENT); - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBorder(BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.HEADER)); root.setBackground(AppThemeColor.SLIDE_BG); 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 2ab32b73..914e55ab 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 @@ -1,12 +1,15 @@ package com.mercury.platform.ui.components.panel.chat; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class HtmlMessageBuilder { private List chunkStrings; + private String stubMessage; public HtmlMessageBuilder() { this.chunkStrings = new ArrayList<>(); @@ -18,18 +21,17 @@ public HtmlMessageBuilder() { * @return html equivalent */ public String build(String message) { - List resultStrs = new ArrayList<>(); - resultStrs.add(""); - String[] words = message.split("((?<=\\s)|(?=\\s)|(?<=\\.)|(?=\\.)|(?<=,)|(?<=\\?)|(?=\\?)|(?=,)|(?<=!)|(?=!)|(?<=/)|(?=/)|(?<=>)|(?=>))"); - Arrays.stream(words).forEach(word -> { - if(chunkStrings.stream().noneMatch(word::equalsIgnoreCase)){ - resultStrs.add(word); - }else { - resultStrs.add("" + word + ""); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(""); + this.stubMessage = message; + this.chunkStrings.forEach(it -> { + if(StringUtils.containsIgnoreCase(message,it)){ + this.stubMessage = stubMessage.replaceAll("(?i)" + it,"" + it + ""); } }); - resultStrs.add(""); - return String.join("",resultStrs); + stringBuilder.append(this.stubMessage); + stringBuilder.append(""); + return stringBuilder.toString(); } public List getChunkStrings() { 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 3a826025..c9d7dbcc 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 @@ -4,9 +4,9 @@ import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.misc.MercuryStoreUI; import com.mercury.platform.ui.misc.TooltipConstants; -import com.mercury.platform.shared.entity.message.ItemMessage; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; @@ -14,9 +14,9 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class ItemInfoPanel extends JPanel implements HasUI{ +public class ItemInfoPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; - private ItemMessage message; + private ItemTradeNotificationDescriptor message; private JPanel cell; private StashTabDescriptor stashTabDescriptor; private ItemCell itemCell; @@ -24,7 +24,7 @@ public class ItemInfoPanel extends JPanel implements HasUI{ private ItemInfoPanelController controller; - public ItemInfoPanel(ItemMessage message, ItemCell itemCell, StashTabDescriptor stashTabDescriptor, ComponentsFactory factory){ + public ItemInfoPanel(ItemTradeNotificationDescriptor message, ItemCell itemCell, StashTabDescriptor stashTabDescriptor, ComponentsFactory factory){ this.componentsFactory = factory; this.controller = new ItemInfoPanelControllerImpl(message); this.message = message; @@ -32,28 +32,28 @@ public ItemInfoPanel(ItemMessage message, ItemCell itemCell, StashTabDescriptor this.itemCell = itemCell; this.stashTabDescriptor = stashTabDescriptor; setupMouseOverListener(); - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); JLabel nicknameLabel = componentsFactory.getTextLabel(message.getWhisperNickname()); - JPanel nicknamePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + JPanel nicknamePanel = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); nicknameLabel.setForeground(AppThemeColor.TEXT_NICKNAME); nicknamePanel.add(nicknameLabel); nicknamePanel.setBorder(BorderFactory.createEmptyBorder(-6,0,-6,0)); this.add(nicknamePanel,BorderLayout.CENTER); - JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME_ALPHA, "Close"); + JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME, "Close"); hideButton.addActionListener((action)-> { controller.hidePanel(); }); this.add(hideButton,BorderLayout.LINE_END); - JPanel tabInfoPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + JPanel tabInfoPanel = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); JLabel tabLabel = componentsFactory.getTextLabel("Tab: " + message.getTabName()); tabInfoPanel.add(tabLabel); tabInfoPanel.setBorder(BorderFactory.createEmptyBorder(-8,0,-6,0)); 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 8b71528b..bf0ad91b 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,13 +1,13 @@ package com.mercury.platform.ui.components.panel.grid; -import com.mercury.platform.shared.entity.message.ItemMessage; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.NonNull; public class ItemInfoPanelControllerImpl implements ItemInfoPanelController { - private ItemMessage message; - public ItemInfoPanelControllerImpl(@NonNull ItemMessage message) { + private ItemTradeNotificationDescriptor message; + public ItemInfoPanelControllerImpl(@NonNull ItemTradeNotificationDescriptor message) { this.message = message; } @Override 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 592d8592..066d9346 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,9 +1,9 @@ package com.mercury.platform.ui.components.panel.grid; -import com.mercury.platform.shared.entity.message.ItemMessage; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import com.mercury.platform.shared.config.descriptor.StashTabDescriptor; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; @@ -17,7 +17,7 @@ import java.util.List; -public class ItemsGridPanel extends JPanel implements HasUI { +public class ItemsGridPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; private List defaultCells; private List quadCells; @@ -35,7 +35,7 @@ public ItemsGridPanel() { quadCells = new ArrayList<>(); tabButtons = new HashMap<>(); stashTabsContainer = new StashTabsContainer(); - createUI(); + onViewInit(); } public ItemsGridPanel(@NonNull ComponentsFactory factory){ super(new BorderLayout()); @@ -44,11 +44,11 @@ public ItemsGridPanel(@NonNull ComponentsFactory factory){ quadCells = new ArrayList<>(); tabButtons = new HashMap<>(); stashTabsContainer = new StashTabsContainer(); - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.setBackground(AppThemeColor.TRANSPARENT); this.setBorder(null); @@ -85,7 +85,7 @@ public void createUI() { this.setPreferredSize(this.getMaximumSize()); } - public void add(@NonNull ItemMessage message, ItemInfoPanelController controller){ + public void add(@NonNull ItemTradeNotificationDescriptor message, ItemInfoPanelController controller){ String nickname = message.getWhisperNickname(); if (!tabButtons.containsKey(nickname + message.getTabName())) { int x = message.getLeft(); @@ -108,7 +108,7 @@ public void add(@NonNull ItemMessage message, ItemInfoPanelController controller } } } - public void remove(@NonNull ItemMessage message){ + public void remove(@NonNull ItemTradeNotificationDescriptor message){ closeGridItem(message); } public void changeTabType(@NonNull ItemInfoPanel itemInfoPanel){ @@ -157,7 +157,7 @@ private Optional getCellByCoordinates(@NonNull StashTabDescriptor tab, return targetCell; } - private ItemInfoPanel createGridItem(@NonNull ItemMessage message, @NonNull ItemCell cell, @NonNull StashTabDescriptor stashTabDescriptor){ + private ItemInfoPanel createGridItem(@NonNull ItemTradeNotificationDescriptor message, @NonNull ItemCell cell, @NonNull StashTabDescriptor stashTabDescriptor){ ItemInfoPanel itemInfoPanel = new ItemInfoPanel(message,cell, stashTabDescriptor,componentsFactory); itemInfoPanel.setAlignmentY(SwingConstants.CENTER); itemInfoPanel.addMouseListener(new MouseAdapter() { @@ -175,7 +175,7 @@ public void mouseEntered(MouseEvent e) { }); return itemInfoPanel; } - private void closeGridItem(@NonNull ItemMessage message) { + private void closeGridItem(@NonNull ItemTradeNotificationDescriptor message) { String nickname = message.getWhisperNickname(); ItemInfoPanel itemInfoPanel = tabButtons.get(nickname + message.getTabName()); if (itemInfoPanel != null) { 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 9ab6c8f5..775fa19f 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 @@ -3,7 +3,7 @@ import com.mercury.platform.shared.config.descriptor.StashTabDescriptor; 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; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.NonNull; @@ -11,26 +11,26 @@ import javax.swing.*; import java.awt.*; -public class TabInfoPanel extends JPanel implements HasUI{ +public class TabInfoPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; private StashTabDescriptor stashTabDescriptor; public TabInfoPanel(@NonNull StashTabDescriptor stashTabDescriptor, @NonNull ComponentsFactory componentsFactory) { this.stashTabDescriptor = stashTabDescriptor; this.componentsFactory = componentsFactory; - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); - JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME_ALPHA, "Dismiss"); + JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME, "Dismiss"); hideButton.addActionListener((action)->{ stashTabDescriptor.setUndefined(true); MercuryStoreUI.dismissTabInfoPanelSubject.onNext(this); }); - JPanel tabInfoPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); + JPanel tabInfoPanel = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); JLabel tabLabel = componentsFactory.getTextLabel(stashTabDescriptor.getTitle()); tabLabel.setBorder(null); tabLabel.setFont(componentsFactory.getFont(FontStyle.BOLD,15f)); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java deleted file mode 100644 index 845a610b..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - -/** - * Created by Константин on 10.08.2017. - */ -public class HistoryMessagePanel { -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java deleted file mode 100644 index bc018b19..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/InMessagePanel.java +++ /dev/null @@ -1,571 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - -import com.mercury.platform.shared.AsSubscriber; -import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; -import com.mercury.platform.shared.config.descriptor.HotKeyType; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; -import com.mercury.platform.shared.entity.message.CurrencyMessage; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; -import com.mercury.platform.shared.config.descriptor.ResponseButtonDescriptor; -import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.components.panel.misc.HasUI; -import com.mercury.platform.ui.frame.movable.container.MessageFrame; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.HasHotkey; -import com.mercury.platform.ui.misc.MercuryStoreUI; -import com.mercury.platform.ui.misc.TooltipConstants; -import lombok.Getter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.swing.*; -import javax.swing.Timer; -import javax.swing.border.Border; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.text.DecimalFormat; -import java.util.*; -import java.util.List; - - -public class InMessagePanel extends JPanel implements AsSubscriber, HasUI,HasHotkey{ - private static final Logger logger = LogManager.getLogger(InMessagePanel.class.getSimpleName()); - - private ComponentsFactory componentsFactory; - private PlainConfigurationService notificationService; - private MessagePanelController controller; - private MessagePanelStyle style; - - private String whisper; - private JLabel whisperLabel; - private JButton tradeButton; - private JButton expandButton; - - @Getter - private Message message; - - private Timer timeAgo; - private String cachedTime = "0m"; - private JLabel timeLabel; - private Color cachedWhisperColor = AppThemeColor.TEXT_NICKNAME; - private JPanel whisperPanel; - private JPanel messagePanel; - private JPanel customButtonsPanel; - - private boolean expanded = false; - - private InMessagePanel(Message message, MessagePanelStyle style) { - super(new BorderLayout()); - this.message = message; - this.style = style; - this.whisper = message.getWhisperNickname(); - this.notificationService = Configuration.get().notificationConfiguration(); - if(!style.equals(MessagePanelStyle.HISTORY)) { - this.initHotKeyListeners(); - } - } - public InMessagePanel(Message message, MessagePanelStyle style, MessagePanelController controller, ComponentsFactory componentsFactory){ - this(message,style); - this.componentsFactory = componentsFactory; - this.controller = controller; - createUI(); - } - - @Override - public void createUI() { - this.setBackground(AppThemeColor.FRAME); - this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,1), - BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); - init(); - subscribe(); - setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - } - private void init(){ - this.removeAll(); - this.whisperPanel = getWhisperPanel(); - this.messagePanel = getFormattedMessagePanel(); - this.customButtonsPanel = getButtonsPanel(); - whisperPanel.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(1, 0, 1, 0, AppThemeColor.MSG_HEADER_BORDER), - BorderFactory.createEmptyBorder(-6, 0, -6, 0))); - if(style.equals(MessagePanelStyle.IN_DOWNWARDS) || - style.equals(MessagePanelStyle.HISTORY) || style.equals(MessagePanelStyle.RELOADED)) { - this.add(whisperPanel,BorderLayout.PAGE_START); - this.add(messagePanel,BorderLayout.CENTER); - this.add(customButtonsPanel,BorderLayout.PAGE_END); - }else { - this.add(customButtonsPanel,BorderLayout.PAGE_START); - this.add(messagePanel,BorderLayout.CENTER); - this.add(whisperPanel,BorderLayout.PAGE_END); - } - switch (style){ - case IN_DOWNWARDS:{ - messagePanel.setVisible(expanded); - customButtonsPanel.setVisible(expanded); - break; - } - case IN_UPWARDS:{ - messagePanel.setVisible(expanded); - customButtonsPanel.setVisible(expanded); - break; - } - case HISTORY:{ - messagePanel.setVisible(true); - customButtonsPanel.setVisible(false); - break; - } - case RELOADED:{ - messagePanel.setVisible(true); - customButtonsPanel.setVisible(true); - } - } - this.repaint(); - } - - private JPanel getFormattedMessagePanel(){ - JPanel labelsPanel = new JPanel(); - labelsPanel.setLayout(new BoxLayout(labelsPanel,BoxLayout.Y_AXIS)); - labelsPanel.setBackground(AppThemeColor.TRANSPARENT); - - JPanel tradePanel = new JPanel(new BorderLayout()); - tradePanel.setBackground(AppThemeColor.TRANSPARENT); - tradePanel.setBorder(BorderFactory.createEmptyBorder(-11,2,-11,0)); - if(message instanceof ItemMessage) { - JButton itemButton = componentsFactory.getButton( - FontStyle.BOLD, - AppThemeColor.BUTTON, - BorderFactory.createEmptyBorder(0,4,0,2), - ((ItemMessage) message).getItemName(), 17f); - - itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT); - itemButton.setBackground(AppThemeColor.TRANSPARENT); - itemButton.setHorizontalAlignment(SwingConstants.LEFT); - itemButton.setContentAreaFilled(false); - itemButton.setRolloverEnabled(false); - itemButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - controller.showITH(); - } - - @Override - public void mouseReleased(MouseEvent e) { - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - - @Override - public void mouseEntered(MouseEvent e) { - itemButton.setBorder(new CompoundBorder( - BorderFactory.createMatteBorder(0,1,0,1,AppThemeColor.BORDER), - BorderFactory.createEmptyBorder(0,3,0,1))); - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - - @Override - public void mouseExited(MouseEvent e) { - itemButton.setBorder(BorderFactory.createEmptyBorder(0,4,0,2)); - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - }); - tradePanel.add(itemButton,BorderLayout.CENTER); - }else if(message instanceof CurrencyMessage){ - JPanel fromPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - fromPanel.setBackground(AppThemeColor.TRANSPARENT); - CurrencyMessage message = (CurrencyMessage) this.message; - - String curCount = message.getCurrForSaleCount() % 1 == 0 ? - String.valueOf(message.getCurrForSaleCount().intValue()) : - String.valueOf(message.getCurrForSaleCount()); - JPanel curCountPanel = getCurrencyPanel(curCount); - JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrForSaleTitle() + ".png", 26); - JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - curPanel.setBackground(AppThemeColor.TRANSPARENT); - curPanel.add(curCountPanel); - curPanel.add(currencyLabel); - curPanel.add(getCurrencyRatePanel()); - fromPanel.add(curPanel); - tradePanel.add(fromPanel,BorderLayout.CENTER); - } - - JPanel forPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - forPanel.setBackground(AppThemeColor.TRANSPARENT); - - JLabel separator = componentsFactory.getTextLabel( - FontStyle.BOLD, - AppThemeColor.TEXT_MESSAGE, - TextAlignment.CENTER, - 18f, - "=>"); - separator.setHorizontalAlignment(SwingConstants.CENTER); - String curCount = " "; - if(message.getCurCount() > 0) { - curCount = message.getCurCount() % 1 == 0 ? - String.valueOf(message.getCurCount().intValue()) : - String.valueOf(message.getCurCount()); - } - String currency = message.getCurrency(); - if(!Objects.equals(curCount, "") && currency != null) { - JPanel curCountPanel = getCurrencyPanel(curCount); - JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + currency + ".png", 26); - JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - curPanel.setBackground(AppThemeColor.TRANSPARENT); - curPanel.add(separator); - curPanel.add(curCountPanel); - curPanel.add(currencyLabel); - forPanel.add(curPanel); - } - tradePanel.add(forPanel,BorderLayout.LINE_END); - labelsPanel.add(tradePanel); - String offer = message.getOffer(); - if(offer != null && offer.trim().length() > 0) { - JLabel offerLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 17f, offer); - offerLabel.setAlignmentY(Component.TOP_ALIGNMENT); - labelsPanel.add(offerLabel); - } - return labelsPanel; - } - private JPanel getCurrencyPanel(String curCount){ - JPanel curCountPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - curCountPanel.setBackground(AppThemeColor.TRANSPARENT); - - JLabel priceLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER,17f,null, curCount); - curCountPanel.add(priceLabel); - curCountPanel.setPreferredSize(new Dimension((int)(componentsFactory.getScale() * 40),curCountPanel.getPreferredSize().height)); - return curCountPanel; - } - private JPanel getCurrencyRatePanel(){ - CurrencyMessage message = (CurrencyMessage) this.message; - Double currForSaleCount = message.getCurrForSaleCount(); - Double curCount = message.getCurCount(); - double rate = curCount / currForSaleCount; - DecimalFormat decimalFormat = new DecimalFormat("#.####"); - JPanel ratePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - ratePanel.add(componentsFactory. - getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,"(")); - JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + message.getCurrency() + ".png", 26); - currencyLabel.setBorder(null); - ratePanel.add(currencyLabel); - ratePanel.add(componentsFactory. - getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,decimalFormat.format(rate))); - ratePanel.add(componentsFactory. - getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 18f, null,")")); - ratePanel.setBorder(BorderFactory.createEmptyBorder(-5,0,-5,0)); - return ratePanel; - } - private JPanel getWhisperPanel(){ - JPanel topPanel = new JPanel(new BorderLayout()); - topPanel.setBackground(AppThemeColor.MSG_HEADER); - - whisperLabel = componentsFactory.getTextLabel(FontStyle.BOLD,cachedWhisperColor, TextAlignment.LEFTOP,15f,getNicknameLabel()); - Border border = whisperLabel.getBorder(); - whisperLabel.setBorder(new CompoundBorder(border,new EmptyBorder(0,0,0,5))); - whisperLabel.setVerticalAlignment(SwingConstants.CENTER); - - JPanel nickNamePanel = componentsFactory.getTransparentPanel(new BorderLayout()); - if(style.equals(MessagePanelStyle.HISTORY)){ - nickNamePanel.add(whisperLabel,BorderLayout.CENTER); - }else { - JPanel buttonWrapper = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - buttonWrapper.setBorder(BorderFactory.createEmptyBorder(2,0,0,0)); - buttonWrapper.add(getExpandButton()); - if(!style.equals(MessagePanelStyle.RELOADED)) { - nickNamePanel.add(buttonWrapper, BorderLayout.LINE_START); - } - nickNamePanel.add(whisperLabel,BorderLayout.CENTER); - } - topPanel.add(nickNamePanel,BorderLayout.CENTER); - - JPanel interactionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - interactionPanel.setBorder(BorderFactory.createEmptyBorder(1,0,1,0)); - interactionPanel.setBackground(AppThemeColor.TRANSPARENT); - interactionPanel.add(getTimePanel()); - if(!style.equals(MessagePanelStyle.HISTORY)) { - JButton inviteButton = componentsFactory.getIconButton("app/invite.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.INVITE); - inviteButton.addActionListener(e -> controller.performInvite()); - JButton kickButton = componentsFactory.getIconButton("app/kick.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.KICK); - kickButton.addActionListener(e -> { - controller.performKick(); - if(this.notificationService.get().isDismissAfterKick() && !style.equals(MessagePanelStyle.RELOADED)){ - controller.performHide(); - } - }); - tradeButton = componentsFactory.getIconButton("app/trade.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE); - tradeButton.addActionListener(e -> controller.performOfferTrade()); - interactionPanel.add(inviteButton); - interactionPanel.add(kickButton); - interactionPanel.add(tradeButton); - interactionPanel.add(getStillInterestedButton()); - }else { - JButton reloadButton = componentsFactory.getIconButton("app/reload-history.png", 14, AppThemeColor.MSG_HEADER, "Restore"); - reloadButton.addActionListener(e -> controller.reloadMessage(this)); - interactionPanel.add(reloadButton); - } - JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); - openChatButton.setToolTipText("Open chat"); - openChatButton.addActionListener(e -> controller.performOpenChat()); - - interactionPanel.add(openChatButton); - JButton hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL); - hideButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - controller.performHide(); - } - } - }); - if(!style.equals(MessagePanelStyle.HISTORY) && !style.equals(MessagePanelStyle.RELOADED)) { - interactionPanel.add(hideButton); - } - - topPanel.add(interactionPanel,BorderLayout.LINE_END); - return topPanel; - } - private String getNicknameLabel(){ - String whisperNickname = message.getWhisperNickname(); - String result = whisperNickname + ":"; - if(this.notificationService.get().isShowLeague()) { - if (message.getLeague() != null) { - String league = message.getLeague().trim(); - if (league.length() == 0) { - return result; - } - if (league.contains("Hardcore")) { - if (league.equals("Hardcore")) { - result = "HC " + result; - } else { - result = String.valueOf(league.split(" ")[1].charAt(0)) + "HC " + result; - } - } else if (league.contains("Standard")) { - result = "Standard " + result; - } else { - result = String.valueOf(league.charAt(0)) + "SC " + result; - } - } - } - return result; - } - private JPanel getTimePanel(){ - JPanel panel = new JPanel(); - panel.setBackground(AppThemeColor.TRANSPARENT); - timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 14, cachedTime); - if(timeAgo == null) { - timeAgo = new Timer(60000, new ActionListener() { - private int minute = 0; - private int hours = 0; - private int day = 0; - - @Override - public void actionPerformed(ActionEvent e) { - String labelText = ""; - minute++; - if (minute > 60) { - hours++; - minute = 0; - if (hours > 24) { - day++; - hours = 0; - } - } - if (hours == 0 && day == 0) { - labelText = minute + "m"; - } else if (hours > 0) { - labelText = hours + "h " + minute + "m"; - } else if (day > 0) { - labelText = day + "d " + hours + "h " + minute + "m"; - } - timeLabel.setText(labelText); - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - }); - timeAgo.start(); - } - panel.add(timeLabel); - return panel; - } - public void disableTime(){ - if(timeAgo != null) { - timeAgo.stop(); - timeLabel.setText(""); - } - } - private JButton getExpandButton(){ - String iconPath = "app/default-mp.png"; - if(expanded){ - if(style.equals(MessagePanelStyle.IN_DOWNWARDS)){ - iconPath = "app/expand-mp.png"; - }else { - iconPath = "app/collapse-mp.png"; - } - } - expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); - expandButton.setBorder(BorderFactory.createEmptyBorder(4,4,4,0)); - expandButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - if (!messagePanel.isVisible()) { - expand(); - } else { - collapse(); - } - } - } - }); - return expandButton; - } - public void expand(){ - expanded = true; - if(style.equals(MessagePanelStyle.IN_DOWNWARDS)) { - expandButton.setIcon(componentsFactory.getIcon("app/expand-mp.png", 18f)); - messagePanel.setVisible(true); - customButtonsPanel.setVisible(true); - }else { - expandButton.setIcon(componentsFactory.getIcon("app/collapse-mp.png", 18f)); - messagePanel.setVisible(true); - customButtonsPanel.setVisible(true); - } - setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - MercuryStoreUI.expandMessageSubject.onNext(true); - MercuryStoreUI.packSubject.onNext(MessageFrame.class); - } - public void collapse(){ - expanded = false; - if(style.equals(MessagePanelStyle.IN_DOWNWARDS)) { - expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18)); - messagePanel.setVisible(false); - customButtonsPanel.setVisible(false); - }else { - expandButton.setIcon(componentsFactory.getIcon("app/default-mp.png", 18)); - messagePanel.setVisible(false); - customButtonsPanel.setVisible(false); - } - setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - MercuryStoreUI.collapseMessageSubject.onNext(true); - MercuryStoreUI.packSubject.onNext(MessageFrame.class); - } - - public boolean isExpanded() { - return expanded; - } - - public void setStyle(MessagePanelStyle style) { - this.style = style; - this.cachedTime = timeLabel.getText(); - init(); - setMaximumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - setMinimumSize(new Dimension(Integer.MAX_VALUE,getPreferredSize().height)); - } - - public MessagePanelStyle getStyle() { - return style; - } - private JPanel getButtonsPanel(){ - JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - panel.setBackground(AppThemeColor.TRANSPARENT); - initResponseButtons(panel); - return panel; - } - @Override - public void subscribe() { - MercuryStoreCore.playerJoinSubject.subscribe(nickname -> { - if(nickname.equals(whisper)){ - whisperLabel.setForeground(AppThemeColor.TEXT_SUCCESS); - cachedWhisperColor = AppThemeColor.TEXT_SUCCESS; - if(!style.equals(MessagePanelStyle.HISTORY)) { - tradeButton.setEnabled(true); - } - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - }); - MercuryStoreCore.playerLeftSubject.subscribe(nickname -> { - if (nickname.equals(whisper)) { - whisperLabel.setForeground(AppThemeColor.TEXT_DISABLE); - cachedWhisperColor = AppThemeColor.TEXT_DISABLE; - if (!style.equals(MessagePanelStyle.HISTORY)) { - tradeButton.setEnabled(false); - } - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - } - }); - MercuryStoreCore.buttonsChangedSubject.subscribe(state -> { - this.customButtonsPanel.removeAll(); - initResponseButtons(customButtonsPanel); - MercuryStoreUI.repaintSubject.onNext(MessageFrame.class); - }); - } - private void initResponseButtons(JPanel panel){ - List buttonsConfig = this.notificationService.get().getButtons(); - Collections.sort(buttonsConfig); - buttonsConfig.forEach((buttonConfig)->{ - JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(),15f); - button.addActionListener(e -> { - controller.performResponse(buttonConfig.getResponseText()); - if(buttonConfig.isClose() && !style.equals(MessagePanelStyle.RELOADED)){ - controller.performHide(); - } - }); - panel.add(button); - }); - } - private JButton getStillInterestedButton(){ - JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.STILL_INTERESTED); - - String curCount = message.getCurCount() % 1 == 0 ? - String.valueOf(message.getCurCount().intValue()) : - String.valueOf(message.getCurCount()); - String responseText = "Hi, are you still interested in "; - if(message instanceof ItemMessage){ - ItemMessage message = (ItemMessage) this.message; - if(message.getCurrency().equals("???")){ - responseText += message.getItemName() + "?"; - }else { - responseText += message.getItemName() + - " for " + curCount + " " + message.getCurrency() + "?"; - } - }else { - CurrencyMessage message = (CurrencyMessage) this.message; - String curForSaleCount = message.getCurCount() % 1 == 0 ? - String.valueOf(message.getCurrForSaleCount().intValue()) : - String.valueOf(message.getCurrForSaleCount()); - responseText += curForSaleCount + " " + message.getCurrForSaleTitle() + " for " + - curCount + " " + message.getCurrency() + "?"; - } - String finalResponseText = responseText; // hate java - stillIntButton.addActionListener( - (action)->controller.performResponse(finalResponseText) - ); - return stillIntButton; - } - - public void setComponentsFactory(ComponentsFactory componentsFactory) { - this.componentsFactory = componentsFactory; - } - - @Override - public void initHotKeyListeners() { - KeyValueConfigurationService config = Configuration.get().hotKeysConfiguration(); - MercuryStoreCore.hotKeySubject.subscribe(descriptor -> { - HotKeyDescriptor hotKeyDescriptor = config.get(HotKeyType.CLOSE_NOTIFICATION.name()); - if(descriptor.equals(hotKeyDescriptor)) { - this.controller.performHide(); - } - }); - } -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java deleted file mode 100644 index b44f42bd..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanel.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - - -import com.mercury.platform.shared.AsSubscriber; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; -import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; -import com.mercury.platform.ui.misc.HasHotkey; - -import javax.swing.*; - -public abstract class MessagePanel extends JPanel implements AsSubscriber, HasUI { - protected ComponentsFactory componentsFactory; - protected PlainConfigurationService notificationService; -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java deleted file mode 100644 index da5a667f..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelBuilder.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - - -public class MessagePanelBuilder { - private MessagePanelStyle style; -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java deleted file mode 100644 index 5fd05539..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - -import lombok.NonNull; - -public interface MessagePanelController { - void performInvite(); - void performKick(); - void performOfferTrade(); - void performOpenChat(); - void performResponse(@NonNull String responseText); - void performHide(); - - /** - * Show Item Stash Highlights - */ - void showITH(); - void reloadMessage(@NonNull InMessagePanel panel); -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java deleted file mode 100644 index 36c0bb5b..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelFactory.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - - -public class MessagePanelFactory { -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java deleted file mode 100644 index ed7d2e26..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - - -public interface MessagePanelProvider { - boolean isSuitable(MessagePanelStyle style); - -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java deleted file mode 100644 index 0c549a83..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/MessagePanelStyle.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.mercury.platform.ui.components.panel.message; - -public enum MessagePanelStyle { - OUT_MESSAGE, IN_DOWNWARDS, IN_UPWARDS,HISTORY, RELOADED -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/AfterViewInit.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/AfterViewInit.java new file mode 100644 index 00000000..0029b586 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/AfterViewInit.java @@ -0,0 +1,6 @@ +package com.mercury.platform.ui.components.panel.misc; + + +public interface AfterViewInit { + void onAfterViewInit(); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewDestroy.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewDestroy.java new file mode 100644 index 00000000..99eaf061 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewDestroy.java @@ -0,0 +1,6 @@ +package com.mercury.platform.ui.components.panel.misc; + + +public interface ViewDestroy { + void onViewDestroy(); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/HasUI.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewInit.java similarity index 53% rename from app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/HasUI.java rename to app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewInit.java index 32c09db1..00194f41 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/HasUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/ViewInit.java @@ -1,5 +1,5 @@ package com.mercury.platform.ui.components.panel.misc; -public interface HasUI { - void createUI(); +public interface ViewInit { + void onViewInit(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyIncNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyIncNotificationPanel.java new file mode 100644 index 00000000..118841f7 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyIncNotificationPanel.java @@ -0,0 +1,68 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +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.ui.misc.TooltipConstants; + +import javax.swing.*; +import java.awt.*; +import java.text.DecimalFormat; + + +public class CurrencyIncNotificationPanel extends IncomingNotificationPanel { + @Override + protected JPanel getMessagePanel() { + JPanel labelsPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + JPanel tradePanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + + tradePanel.add(this.getFromPanel(),BorderLayout.CENTER); + tradePanel.add(this.getForPanel(),BorderLayout.LINE_END); + labelsPanel.add(tradePanel,BorderLayout.CENTER); + JLabel offerLabel = this.getOfferLabel(); + if(offerLabel != null) { + labelsPanel.add(offerLabel, BorderLayout.PAGE_END); + } + return labelsPanel; + } + private JPanel getFromPanel(){ + JPanel fromPanel = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.LEFT,0,0),AppThemeColor.FRAME); + fromPanel.add(this.getCurrencyPanel(this.data.getCurrForSaleCount(),this.data.getCurrForSaleTitle())); + fromPanel.add(getCurrencyRatePanel()); + return fromPanel; + } + + private JPanel getCurrencyRatePanel(){ + Double currForSaleCount = this.data.getCurrForSaleCount(); + Double curCount = this.data.getCurCount(); + double rate = curCount / currForSaleCount; + DecimalFormat decimalFormat = new DecimalFormat("#.####"); + JPanel ratePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,"(")); + JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + this.data.getCurrency() + ".png", 26); + currencyLabel.setBorder(null); + ratePanel.add(currencyLabel); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,decimalFormat.format(rate))); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,")")); + ratePanel.setBorder(BorderFactory.createEmptyBorder(-5,0,-5,0)); + return ratePanel; + } + + @Override + protected JButton getStillInterestedButton() { + JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.STILL_INTERESTED); + stillIntButton.addActionListener(action -> { + String curCount = this.data.getCurCount().toString(); + String responseText = "Hi, are you still interested in "; + String curForSaleCount = this.data.getCurrForSaleCount().toString(); + responseText += curForSaleCount + " " + this.data.getCurrForSaleTitle() + " for " + + curCount + " " + this.data.getCurrency() + "?"; + this.controller.performResponse(responseText); + }); + return stillIntButton; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyOutNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyOutNotificationPanel.java new file mode 100644 index 00000000..ba8c3f0c --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyOutNotificationPanel.java @@ -0,0 +1,46 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +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 java.awt.*; +import java.text.DecimalFormat; + + +public class CurrencyOutNotificationPanel extends OutgoingNotificationPanel { + @Override + protected JPanel getContentPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + root.add(this.getFromPanel(),BorderLayout.LINE_START); + root.add(this.getForPanel(),BorderLayout.CENTER); + return root; + } + private JPanel getForPanel(){ + JPanel fromPanel = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.LEFT,0,0),AppThemeColor.FRAME); + fromPanel.add(this.getCurrencyPanel(this.data.getCurrForSaleCount(),this.data.getCurrForSaleTitle())); + fromPanel.add(getCurrencyRatePanel()); + return fromPanel; + } + + private JPanel getCurrencyRatePanel(){ + Double currForSaleCount = this.data.getCurrForSaleCount(); + Double curCount = this.data.getCurCount(); + double rate = curCount / currForSaleCount; + DecimalFormat decimalFormat = new DecimalFormat("#.####"); + JPanel ratePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,"(")); + JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + this.data.getCurrency() + ".png", 26); + currencyLabel.setBorder(null); + ratePanel.add(currencyLabel); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,decimalFormat.format(rate))); + ratePanel.add(componentsFactory. + getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 18f, null,")")); + ratePanel.setBorder(BorderFactory.createEmptyBorder(-5,0,-5,0)); + return ratePanel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/HistoryNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/HistoryNotificationPanel.java new file mode 100644 index 00000000..97e817ae --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/HistoryNotificationPanel.java @@ -0,0 +1,54 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.notification.controller.HistoryController; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.TooltipConstants; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.*; +import java.awt.*; + + +public class HistoryNotificationPanel extends NotificationPanel { + @Override + public void onViewInit() { + super.onViewInit(); + this.add(this.getHeader(),BorderLayout.PAGE_START); + JLabel sourceLabel = this.componentsFactory.getTextLabel(StringUtils.substringAfter(this.data.getSourceString(),":"),FontStyle.REGULAR,17f); + sourceLabel.setBackground(AppThemeColor.FRAME); + sourceLabel.setHorizontalAlignment(SwingConstants.LEFT); + sourceLabel.setVerticalAlignment(SwingConstants.TOP); + this.add(sourceLabel,BorderLayout.CENTER); + } + private JPanel getHeader(){ + JPanel root = new JPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + root.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + + JLabel nicknameLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,15f,this.data.getWhisperNickname()); + nicknameLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,5)); + root.add(nicknameLabel,BorderLayout.CENTER); + + JPanel opPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.MSG_HEADER); + JPanel interactionPanel = new JPanel(new GridLayout(1,0,4,0)); + interactionPanel.setBackground(AppThemeColor.MSG_HEADER); + JButton reloadButton = componentsFactory.getIconButton("app/reload-history.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.INVITE); + reloadButton.addActionListener(e -> { + this.controller.reload(); + }); + JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); + openChatButton.addActionListener(e -> controller.performOpenChat()); + interactionPanel.add(reloadButton); + interactionPanel.add(openChatButton); + opPanel.add(interactionPanel,BorderLayout.CENTER); + root.add(opPanel,BorderLayout.LINE_END); + return root; + } + @Override + protected void updateHotKeyPool() { + /*NOP*/ + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/IncomingNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/IncomingNotificationPanel.java new file mode 100644 index 00000000..d5d98a54 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/IncomingNotificationPanel.java @@ -0,0 +1,298 @@ +package com.mercury.platform.ui.components.panel.notification; + + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.*; +import com.mercury.platform.shared.entity.message.TradeNotificationDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.VerticalScrollContainer; +import com.mercury.platform.ui.components.panel.notification.controller.IncomingPanelController; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.TooltipConstants; +import org.apache.commons.lang3.StringUtils; +import rx.Subscription; + +import javax.swing.*; +import javax.swing.Timer; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.*; +import java.util.List; + +public abstract class IncomingNotificationPanel extends NotificationPanel{ + private PlainConfigurationService config; + private PlainConfigurationService hotKeysConfig; + private JPanel messagePanel; + private JPanel responseButtonsPanel; + private JPanel chatPanel; + private JPanel chatContainer; + private Subscription chatSubscription; + @Override + public void onViewInit() { + super.onViewInit(); + this.config = Configuration.get().notificationConfiguration(); + this.hotKeysConfig = Configuration.get().hotKeysConfiguration(); + this.add(this.getHeader(),BorderLayout.PAGE_START); + this.messagePanel = this.getMessagePanel(); + this.responseButtonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,5,2)); + this.responseButtonsPanel.setBackground(AppThemeColor.FRAME); + this.chatPanel = this.getChatPanel(); + this.chatPanel.setVisible(false); + this.add(this.messagePanel,BorderLayout.CENTER); + this.add(this.responseButtonsPanel,BorderLayout.PAGE_END); + this.updateHotKeyPool(); + } + private JPanel getHeader(){ + JPanel root = new JPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + root.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + + JPanel nickNamePanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.MSG_HEADER); + JLabel nicknameLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,15f,this.getNicknameText()); + nicknameLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,5)); + nickNamePanel.add(this.getExpandButton(),BorderLayout.LINE_START); + nickNamePanel.add(nicknameLabel,BorderLayout.CENTER); + root.add(nickNamePanel,BorderLayout.CENTER); + + JPanel opPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.MSG_HEADER); + JPanel interactionPanel = new JPanel(new GridLayout(1,0,4,0)); + interactionPanel.setBackground(AppThemeColor.MSG_HEADER); + JButton inviteButton = componentsFactory.getIconButton("app/invite.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.INVITE); + inviteButton.addActionListener(e -> { + this.controller.performInvite(); + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER_SELECTED_BORDER)); + }); + JButton kickButton = componentsFactory.getIconButton("app/kick.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.KICK); + kickButton.addActionListener(e -> { + this.controller.performKick(); + if(this.config.get().isDismissAfterKick()){ + this.controller.performHide(); + } + }); + JButton tradeButton = componentsFactory.getIconButton("app/trade.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE); + tradeButton.addActionListener(e -> { + this.controller.performOfferTrade(); + }); + JButton showChatButton = componentsFactory.getIconButton("app/chat_history.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.SWITCH_CHAT); + showChatButton.addActionListener(e -> { + if(this.chatPanel.isVisible()){ + this.chatPanel.setVisible(false); + this.remove(this.chatPanel); + this.add(this.messagePanel,BorderLayout.CENTER); + this.add(this.responseButtonsPanel,BorderLayout.PAGE_END); + }else { + this.remove(this.messagePanel); + this.remove(this.responseButtonsPanel); + this.chatPanel.setVisible(true); + this.add(this.chatPanel,BorderLayout.CENTER); + } + SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); + }); + JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); + openChatButton.addActionListener(e -> controller.performOpenChat()); + JButton hideButton = componentsFactory.getIconButton("app/close.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL); + hideButton.addActionListener(action -> { + this.controller.performHide(); + }); + JButton stillInterestedButton = getStillInterestedButton(); + interactionPanel.add(inviteButton); + interactionPanel.add(tradeButton); + interactionPanel.add(kickButton); + interactionPanel.add(stillInterestedButton); + interactionPanel.add(showChatButton); + interactionPanel.add(openChatButton); + interactionPanel.add(hideButton); + + this.interactButtonMap.put(HotKeyType.N_INVITE_PLAYER,inviteButton); + this.interactButtonMap.put(HotKeyType.N_TRADE_PLAYER,tradeButton); + this.interactButtonMap.put(HotKeyType.N_KICK_PLAYER,kickButton); + this.interactButtonMap.put(HotKeyType.N_STILL_INTERESTING,stillInterestedButton); + this.interactButtonMap.put(HotKeyType.N_SWITCH_CHAT,showChatButton); + this.interactButtonMap.put(HotKeyType.N_OPEN_CHAT,openChatButton); + this.interactButtonMap.put(HotKeyType.N_CLOSE_NOTIFICATION,hideButton); + + JPanel timePanel = this.getTimePanel(); + timePanel.setPreferredSize(new Dimension(50,26)); + opPanel.add(timePanel,BorderLayout.CENTER); + opPanel.add(interactionPanel,BorderLayout.LINE_END); + + root.add(opPanel,BorderLayout.LINE_END); + return root; + } + + @Override + protected void updateHotKeyPool() { + this.hotKeysPool.clear(); + this.interactButtonMap.forEach((type, button) -> { + HotKeyPair hotKeyPair = this.hotKeysConfig.get() + .getIncNHotKeysList() + .stream() + .filter(it -> it.getType().equals(type)) + .findAny().orElse(null); + this.hotKeysPool.put(hotKeyPair.getDescriptor(),button); + }); + this.initResponseButtonsPanel(); + Window windowAncestor = SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this); + if(windowAncestor != null) { + windowAncestor.pack(); + } + } + + @Override + public void subscribe() { + super.subscribe(); + this.chatSubscription = MercuryStoreCore.plainMessageSubject.subscribe(message -> { + if(this.data.getWhisperNickname().equals(message.getNickName())){ + this.chatContainer.add(this.componentsFactory.getTextLabel((message.isIncoming()? "From: ":"To: ") + message.getMessage())); + SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); + } + }); + } + + @Override + public void onViewDestroy() { + super.onViewDestroy(); + this.chatSubscription.unsubscribe(); + } + private JPanel getChatPanel(){ + this.chatContainer = new VerticalScrollContainer(); + this.chatContainer.setLayout(new BoxLayout(this.chatContainer,BoxLayout.Y_AXIS)); + this.chatContainer.setBackground(AppThemeColor.FRAME); + this.chatContainer.add(this.componentsFactory.getTextLabel("From:" + StringUtils.substringAfter(this.data.getSourceString(),this.data.getWhisperNickname() +":"))); + return this.componentsFactory.wrapToSlide(this.chatContainer,AppThemeColor.FRAME); + } + protected JPanel getForPanel(){ + JPanel forPanel = new JPanel(new BorderLayout()); + forPanel.setPreferredSize(new Dimension(110,36)); + forPanel.setBackground(AppThemeColor.FRAME); + JLabel separator = componentsFactory.getTextLabel( + FontStyle.BOLD, + AppThemeColor.TEXT_DEFAULT, + TextAlignment.CENTER, + 18f, + "=>"); + forPanel.add(separator,BorderLayout.CENTER); + separator.setHorizontalAlignment(SwingConstants.CENTER); + JPanel currencyPanel = this.getCurrencyPanel(this.data.getCurCount(),this.data.getCurrency()); + if(currencyPanel != null) { + forPanel.add(currencyPanel, BorderLayout.LINE_END); + } + return forPanel; + } + protected JPanel getCurrencyPanel(Double curCount, String curIconPath){ + String curCountStr = " "; + if(curCount > 0) { + curCountStr = curCount % 1 == 0 ? + String.valueOf(curCount.intValue()) : + String.valueOf(curCount); + } + if(!Objects.equals(curCountStr, "") && curIconPath != null) { + JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + curIconPath + ".png", 28); + JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + curPanel.setBackground(AppThemeColor.FRAME); + curPanel.add(this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER,17f,null, curCountStr)); + curPanel.add(currencyLabel); + return curPanel; + } + return null; + } + protected JLabel getOfferLabel(){ + String offer = this.data.getOffer(); + if(offer != null && offer.trim().length() > 0) { + JLabel offerLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 16f, offer); + offerLabel.setHorizontalAlignment(SwingConstants.CENTER); + return offerLabel; + } + return null; + } + protected abstract JPanel getMessagePanel(); + protected abstract JButton getStillInterestedButton(); + private void initResponseButtonsPanel(){ + this.responseButtonsPanel.removeAll(); + List buttonsConfig = this.config.get().getButtons(); + Collections.sort(buttonsConfig); + buttonsConfig.forEach((buttonConfig)->{ + JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(),16f,AppThemeColor.RESPONSE_BUTTON, AppThemeColor.RESPONSE_BUTTON_BORDER,AppThemeColor.RESPONSE_BUTTON); + if(buttonConfig.getTitle().length() < 10) { + button.setPreferredSize(new Dimension(60, 26)); + } + button.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + } + + @Override + public void mouseExited(MouseEvent e) { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + } + }); + button.addActionListener(action -> { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + }); + button.addActionListener(e -> { + this.controller.performResponse(buttonConfig.getResponseText()); + if(buttonConfig.isClose()){ + this.controller.performHide(); + } + }); + this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(),button); + this.responseButtonsPanel.add(button); + }); + } + private String getNicknameText(){ + String whisperNickname = data.getWhisperNickname(); + String result = whisperNickname + ":"; + if(this.config.get().isShowLeague()) { + if (data.getLeague() != null) { + String league = data.getLeague().trim(); + if (league.length() == 0) { + return result; + } + if (league.contains("Hardcore")) { + if (league.equals("Hardcore")) { + result = "HC " + result; + } else { + result = String.valueOf(league.split(" ")[1].charAt(0)) + "HC " + result; + } + } else if (league.contains("Standard")) { + result = "Standard " + result; + } else { + result = String.valueOf(league.charAt(0)) + "SC " + result; + } + } + } + return result; + } + private JButton getExpandButton(){ + String iconPath = "app/expand-mp.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + expandButton.addActionListener(action -> { + if(this.messagePanel.isVisible()){ + this.messagePanel.setVisible(false); + this.responseButtonsPanel.setVisible(false); + expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); + }else { + this.messagePanel.setVisible(true); + this.responseButtonsPanel.setVisible(true); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png",18f)); + } + SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); + }); + return expandButton; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemIncNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemIncNotificationPanel.java new file mode 100644 index 00000000..19b2d2a1 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemIncNotificationPanel.java @@ -0,0 +1,78 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +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.ui.misc.TooltipConstants; + +import javax.swing.*; +import java.awt.*; +import java.util.Objects; + + +public class ItemIncNotificationPanel extends IncomingNotificationPanel { + private JPanel labelsPanel; + @Override + protected JPanel getMessagePanel() { + this.labelsPanel = new JPanel(); + this.labelsPanel.setLayout(new BorderLayout()); + this.labelsPanel.setBackground(AppThemeColor.FRAME); + + JPanel tradePanel = new JPanel(new BorderLayout()); + tradePanel.setBackground(AppThemeColor.FRAME); + JButton itemButton = componentsFactory.getButton( + FontStyle.BOLD, + AppThemeColor.BUTTON, + BorderFactory.createEmptyBorder(0,4,0,2), + this.data.getItemName(), 16f); + + itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT); + itemButton.setBackground(AppThemeColor.TRANSPARENT); + itemButton.setHorizontalAlignment(SwingConstants.LEFT); + itemButton.setContentAreaFilled(false); + itemButton.setRolloverEnabled(false); + itemButton.addActionListener(action -> { + this.controller.showITH(); + }); + tradePanel.add(itemButton,BorderLayout.CENTER); + tradePanel.add(this.getForPanel(),BorderLayout.LINE_END); + + this.labelsPanel.add(tradePanel,BorderLayout.CENTER); + JLabel offerLabel = this.getOfferLabel(); + if(offerLabel != null) { + this.labelsPanel.add(offerLabel, BorderLayout.PAGE_END); + } + return labelsPanel; + } + + @Override + public void setDuplicate(boolean duplicate) { + if(duplicate){ + JButton ignoreButton = componentsFactory.getIconButton("app/adr/visible_node_off.png", 15, AppThemeColor.FRAME, "Ignore item 1 hour"); + ignoreButton.addActionListener(e -> { + MercuryStoreCore.expiredNotificationSubject.onNext(this.data); + this.controller.performHide(); + }); + this.labelsPanel.add(ignoreButton, BorderLayout.LINE_START); + } + } + + @Override + protected JButton getStillInterestedButton() { + JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.MSG_HEADER, TooltipConstants.STILL_INTERESTED); + stillIntButton.addActionListener(action-> { + String curCount = this.data.getCurCount().toString(); + String responseText = "Hi, are you still interested in "; + if(this.data.getCurrency().equals("???")){ + responseText += this.data.getItemName() + "?"; + }else { + responseText += this.data.getItemName() + + " for " + curCount + " " + this.data.getCurrency() + "?"; + } + this.controller.performResponse(responseText); + }); + return stillIntButton; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemOutNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemOutNotificationPanel.java new file mode 100644 index 00000000..a227f819 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemOutNotificationPanel.java @@ -0,0 +1,32 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.misc.AppThemeColor; + +import javax.swing.*; +import java.awt.*; + + +public class ItemOutNotificationPanel extends OutgoingNotificationPanel { + @Override + protected JPanel getContentPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + JButton itemButton = componentsFactory.getButton( + FontStyle.BOLD, + AppThemeColor.BUTTON, + BorderFactory.createEmptyBorder(0,4,0,2), + this.data.getItemName(), 16f); + + itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT); + itemButton.setBackground(AppThemeColor.TRANSPARENT); + itemButton.setHorizontalAlignment(SwingConstants.LEFT); + itemButton.setContentAreaFilled(false); + itemButton.setRolloverEnabled(false); + itemButton.addActionListener(action -> { + }); + root.add(this.getFromPanel(),BorderLayout.LINE_START); + root.add(itemButton,BorderLayout.CENTER); + return root; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/NotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/NotificationPanel.java new file mode 100644 index 00000000..6124fe46 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/NotificationPanel.java @@ -0,0 +1,169 @@ +package com.mercury.platform.ui.components.panel.notification; + + +import com.mercury.platform.shared.AsSubscriber; +import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; +import com.mercury.platform.shared.config.descriptor.HotKeyType; +import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.misc.ViewDestroy; +import com.mercury.platform.ui.components.panel.misc.ViewInit; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.MercuryStoreUI; +import lombok.Getter; +import lombok.Setter; +import rx.Subscription; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +public abstract class NotificationPanel extends JPanel implements AsSubscriber, ViewInit,ViewDestroy { + @Setter + @Getter + protected T data; + @Setter + protected C controller; + protected ComponentsFactory componentsFactory; + protected Map hotKeysPool = new HashMap<>(); + protected Map interactButtonMap = new HashMap<>(); + @Setter + private float paintAlphaValue = 0f; + @Setter + protected float paintBorderValue = 0f; + protected boolean blurEffect; + protected boolean blurReverse; + @Setter + protected boolean duplicate; + + private Subscription settingsPostSubscription; + + @Override + public void onViewInit() { + this.setLayout(new BorderLayout()); + this.setBackground(AppThemeColor.FRAME); + this.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createEmptyBorder(1,1,1,1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON_BORDER, 1))); + } + public void setComponentsFactory(ComponentsFactory factory){ + this.componentsFactory = factory; + this.removeAll(); + this.onViewInit(); + } + + public void onHotKeyPressed(HotKeyDescriptor descriptor){ + JButton button = this.hotKeysPool.get(descriptor); + if(button != null){ + button.doClick(); + } + } + + @Override + public void subscribe() { + this.settingsPostSubscription = MercuryStoreUI.settingsPostSubject.subscribe(state -> { + this.updateHotKeyPool(); + }); + } + protected abstract void updateHotKeyPool(); + + @Override + public void onViewDestroy() { + this.settingsPostSubscription.unsubscribe(); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,this.paintAlphaValue)); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + super.paint(g2); + if (this.paintAlphaValue < 1.0f) { + this.paintAlphaValue += 0.004; + if(this.paintAlphaValue > 1.0f){ + this.paintAlphaValue = 1.0f; + } + this.repaint(); + } + } + protected JPanel getTimePanel() { + JPanel root = new JPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + JLabel timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 14, "0m"); + Timer timeAgo = new Timer(60000, new ActionListener() { + private int minute = 0; + private int hours = 0; + private int day = 0; + + @Override + public void actionPerformed(ActionEvent e) { + String labelText = ""; + minute++; + if (minute > 60) { + hours++; + minute = 0; + if (hours > 24) { + day++; + hours = 0; + } + } + if (hours == 0 && day == 0) { + labelText = minute + "m"; + } else if (hours > 0) { + labelText = hours + "h " + minute + "m"; + } else if (day > 0) { + labelText = day + "d " + hours + "h " + minute + "m"; + } + timeLabel.setText(labelText); + } + }); + timeAgo.start(); + root.add(timeLabel,BorderLayout.CENTER); + return root; + } + protected void onBlur(){ + this.blurEffect = true; + this.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createEmptyBorder(1,1,1,1), + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1))); + this.repaint(); + } + + @Override + protected void paintBorder(Graphics g) { + if(this.blurEffect) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.paintBorderValue)); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + super.paintBorder(g2); + if(this.blurReverse){ + if (this.paintBorderValue <= 1.0f) { + this.paintBorderValue += 0.002; + if (this.paintBorderValue >= 1.0f) { + this.blurReverse = false; + this.paintBorderValue = 1.0f; + } + } + }else { + if (this.paintBorderValue >= 0f) { + this.paintBorderValue -= 0.002; + if (this.paintBorderValue <= 0f) { + this.blurReverse = true; + this.paintBorderValue = 0f; + } + } + } + this.repaint(); + }else { + super.paintBorder(g); + } + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutMessagePanel.java similarity index 59% rename from app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java rename to app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutMessagePanel.java index e617bd57..9d2792ae 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/OutMessagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutMessagePanel.java @@ -1,4 +1,4 @@ -package com.mercury.platform.ui.components.panel.message; +package com.mercury.platform.ui.components.panel.notification; /** * Created by Константин on 10.08.2017. diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutgoingNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutgoingNotificationPanel.java new file mode 100644 index 00000000..ad301615 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/OutgoingNotificationPanel.java @@ -0,0 +1,209 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.*; +import com.mercury.platform.shared.entity.message.TradeNotificationDescriptor; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.notification.controller.OutgoingPanelController; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.TooltipConstants; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.*; +import java.util.List; + +public abstract class OutgoingNotificationPanel extends NotificationPanel { + private PlainConfigurationService config; + private PlainConfigurationService hotKeysConfig; + private JPanel responseButtonsPanel; + private JPanel bottomPanel; + @Override + public void onViewInit() { + super.onViewInit(); + this.config = Configuration.get().notificationConfiguration(); + this.hotKeysConfig = Configuration.get().hotKeysConfiguration(); + this.add(this.getHeader(),BorderLayout.PAGE_START); + + this.responseButtonsPanel = new JPanel(new GridLayout(1,0,0,5)); + this.responseButtonsPanel.setBackground(AppThemeColor.FRAME); + this.bottomPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + this.bottomPanel.add(this.getContentPanel(),BorderLayout.CENTER); + this.bottomPanel.add(this.componentsFactory.wrapToSlide(this.responseButtonsPanel,AppThemeColor.FRAME),BorderLayout.LINE_END); + this.add(bottomPanel,BorderLayout.CENTER); + this.updateHotKeyPool(); + } + + private JPanel getHeader(){ + JPanel root = new JPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + + JPanel nickNamePanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.MSG_HEADER); + JLabel nicknameLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,15f,this.data.getWhisperNickname()); + nicknameLabel.setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); + nickNamePanel.add(this.getExpandButton(),BorderLayout.LINE_START); + nickNamePanel.add(nicknameLabel,BorderLayout.CENTER); + root.add(nickNamePanel,BorderLayout.CENTER); + + JPanel interactionPanel = new JPanel(new GridLayout(1,0,6,0)); + interactionPanel.setBackground(AppThemeColor.MSG_HEADER); + JButton visiteHideout = componentsFactory.getIconButton("app/visiteHideout.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.VISIT_HO); + visiteHideout.addActionListener(e -> this.controller.visitHideout()); + JButton tradeButton = componentsFactory.getIconButton("app/trade.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE); + tradeButton.addActionListener(e -> this.controller.performOfferTrade()); + JButton leaveButton = componentsFactory.getIconButton("app/leave.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.LEAVE); + leaveButton.addActionListener(e -> { + this.controller.performLeave(this.config.get().getPlayerNickname()); + if(this.config.get().isDismissAfterLeave()){ + this.controller.performHide(); + } + }); +// JButton backToHo = componentsFactory.getIconButton("app/backToHideout.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); +// backToHo.addActionListener(e -> controller.backToHideout()); + JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); + openChatButton.addActionListener(e -> controller.performOpenChat()); + JButton hideButton = componentsFactory.getIconButton("app/close.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL); + hideButton.addActionListener(action -> { + this.controller.performHide(); + }); + interactionPanel.add(visiteHideout); + interactionPanel.add(tradeButton); + interactionPanel.add(leaveButton); +// interactionPanel.add(backToHo); + interactionPanel.add(openChatButton); + interactionPanel.add(hideButton); + this.interactButtonMap.put(HotKeyType.N_VISITE_HIDEOUT,visiteHideout); + this.interactButtonMap.put(HotKeyType.N_TRADE_PLAYER,tradeButton); + this.interactButtonMap.put(HotKeyType.N_LEAVE,leaveButton); +// this.interactButtonMap.put(HotKeyType.N_BACK_TO_HIDEOUT,backToHo); + this.interactButtonMap.put(HotKeyType.N_OPEN_CHAT,openChatButton); + this.interactButtonMap.put(HotKeyType.N_CLOSE_NOTIFICATION,hideButton); + + root.add(interactionPanel,BorderLayout.LINE_END); + return root; + } + + @Override + protected void updateHotKeyPool() { + this.hotKeysPool.clear(); + this.interactButtonMap.forEach((type, button) -> { + HotKeyPair hotKeyPair = this.hotKeysConfig.get() + .getOutNHotKeysList() + .stream() + .filter(it -> it.getType().equals(type)) + .findAny().orElse(null); + this.hotKeysPool.put(hotKeyPair.getDescriptor(),button); + }); + this.initResponseButtonPanel(); + Window windowAncestor = SwingUtilities.getWindowAncestor(OutgoingNotificationPanel.this); + if(windowAncestor != null) { + windowAncestor.pack(); + } + } + + private void initResponseButtonPanel(){ + this.responseButtonsPanel.removeAll(); + List buttonsConfig = this.config.get().getOutButtons(); + Collections.sort(buttonsConfig); + buttonsConfig.forEach((buttonConfig)->{ + JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(),16f,AppThemeColor.RESPONSE_BUTTON, AppThemeColor.RESPONSE_BUTTON_BORDER,AppThemeColor.RESPONSE_BUTTON); + button.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + } + + @Override + public void mouseExited(MouseEvent e) { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + } + }); + button.addActionListener(action -> { + button.setBorder( BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) + )); + }); + button.addActionListener(e -> { + this.controller.performResponse(buttonConfig.getResponseText()); + if(buttonConfig.isClose()){ + this.controller.performHide(); + } + }); + this.responseButtonsPanel.add(button); + this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(),button); + }); + } + protected JPanel getFromPanel(){ + JPanel forPanel = new JPanel(new BorderLayout()); + forPanel.setBackground(AppThemeColor.FRAME); + JPanel currencyPanel = this.getCurrencyPanel(this.data.getCurCount(),this.data.getCurrency()); + if(currencyPanel != null) { + currencyPanel.setPreferredSize(new Dimension(70,36)); + forPanel.add(currencyPanel, BorderLayout.LINE_START); + } + JLabel separator = componentsFactory.getTextLabel( + FontStyle.BOLD, + AppThemeColor.TEXT_DEFAULT, + TextAlignment.CENTER, + 18f, + "=>"); + forPanel.add(separator,BorderLayout.CENTER); + separator.setHorizontalAlignment(SwingConstants.CENTER); + return forPanel; + } + protected JPanel getCurrencyPanel(Double curCount, String curIconPath){ + String curCountStr = " "; + if(curCount > 0) { + curCountStr = curCount % 1 == 0 ? + String.valueOf(curCount.intValue()) : + String.valueOf(curCount); + } + if(!Objects.equals(curCountStr, "") && curIconPath != null) { + JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + curIconPath + ".png", 28); + JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + curPanel.setBackground(AppThemeColor.FRAME); + curPanel.add(this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP,17f,null, curCountStr)); + curPanel.add(currencyLabel); + return curPanel; + } + return null; + } + @Override + public void subscribe() { + super.subscribe(); + } + + protected abstract JPanel getContentPanel(); + + @Override + public void onViewDestroy() { + super.onViewDestroy(); + } + private JButton getExpandButton(){ + String iconPath = "app/expand-mp.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + expandButton.addActionListener(action -> { + if(this.bottomPanel.isVisible()){ + this.bottomPanel.setVisible(false); + expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); + }else { + this.bottomPanel.setVisible(true); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png",18f)); + } + SwingUtilities.getWindowAncestor(OutgoingNotificationPanel.this).pack(); + }); + return expandButton; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ScannerNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ScannerNotificationPanel.java new file mode 100644 index 00000000..1a63361e --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ScannerNotificationPanel.java @@ -0,0 +1,133 @@ +package com.mercury.platform.ui.components.panel.notification; + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.*; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.notification.controller.ScannerPanelController; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.TooltipConstants; + +import javax.swing.*; +import java.awt.*; + + +public class ScannerNotificationPanel extends NotificationPanel { + private PlainConfigurationService config; + private PlainConfigurationService nConfig; + private PlainConfigurationService hotKeysConfig; + private JPanel contentPanel; + @Override + public void onViewInit() { + super.onViewInit(); + this.config = Configuration.get().scannerConfiguration(); + this.nConfig = Configuration.get().notificationConfiguration(); + this.hotKeysConfig = Configuration.get().hotKeysConfiguration(); + this.add(this.getHeader(),BorderLayout.PAGE_START); + JLabel sourceLabel = this.componentsFactory.getTextLabel(this.data.getMessage(),FontStyle.REGULAR,17f); + sourceLabel.setBackground(AppThemeColor.FRAME); + sourceLabel.setHorizontalAlignment(SwingConstants.LEFT); + sourceLabel.setVerticalAlignment(SwingConstants.TOP); + this.contentPanel = this.componentsFactory.wrapToSlide(sourceLabel,AppThemeColor.FRAME,2,2,2,2); + this.add(this.contentPanel,BorderLayout.CENTER); + this.updateHotKeyPool(); + } + private JPanel getHeader(){ + JPanel root = new JPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + + JPanel nickNamePanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.MSG_HEADER); + JLabel nicknameLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,15f,this.data.getNickName()); + nicknameLabel.setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); + nickNamePanel.add(this.getExpandButton(),BorderLayout.LINE_START); + nickNamePanel.add(nicknameLabel,BorderLayout.CENTER); + root.add(nickNamePanel,BorderLayout.CENTER); + + JPanel interactionPanel = new JPanel(new GridLayout(1,0,6,0)); + interactionPanel.setBackground(AppThemeColor.MSG_HEADER); + JButton inviteMeButton = componentsFactory.getIconButton("app/chat_scanner_response.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.QUICK_RESPONSE); + inviteMeButton.addActionListener(e -> this.controller.performResponse(this.config.get().getResponseMessage())); + JButton visiteHideout = componentsFactory.getIconButton("app/visiteHideout.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.VISIT_HO); + visiteHideout.addActionListener(e -> this.controller.visitHideout()); + JButton tradeButton = componentsFactory.getIconButton("app/trade.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.TRADE); + tradeButton.addActionListener(e -> this.controller.performOfferTrade()); + JButton leaveButton = componentsFactory.getIconButton("app/leave.png", 17, AppThemeColor.MSG_HEADER, TooltipConstants.LEAVE); + leaveButton.addActionListener(e -> { + this.controller.performLeave(this.nConfig.get().getPlayerNickname()); + if(this.nConfig.get().isDismissAfterLeave()){ + this.controller.performHide(); + } + }); + JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.OPEN_CHAT); + openChatButton.addActionListener(e -> this.controller.performOpenChat()); + JButton hideButton = componentsFactory.getIconButton("app/close.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.HIDE_PANEL); + hideButton.addActionListener(action -> { + this.controller.performHide(); + }); + interactionPanel.add(inviteMeButton); + interactionPanel.add(visiteHideout); + interactionPanel.add(tradeButton); + interactionPanel.add(leaveButton); +// interactionPanel.add(backToHo); + interactionPanel.add(openChatButton); + interactionPanel.add(hideButton); + + this.interactButtonMap.put(HotKeyType.N_QUICK_RESPONSE,inviteMeButton); + this.interactButtonMap.put(HotKeyType.N_VISITE_HIDEOUT,visiteHideout); + this.interactButtonMap.put(HotKeyType.N_TRADE_PLAYER,tradeButton); + this.interactButtonMap.put(HotKeyType.N_LEAVE,leaveButton); +// this.interactButtonMap.put(HotKeyType.N_BACK_TO_HIDEOUT,backToHo); + this.interactButtonMap.put(HotKeyType.N_OPEN_CHAT,openChatButton); + this.interactButtonMap.put(HotKeyType.N_CLOSE_NOTIFICATION,hideButton); + + JPanel opPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.MSG_HEADER); + JPanel timePanel = this.getTimePanel(); + timePanel.setPreferredSize(new Dimension(50,26)); + opPanel.add(timePanel,BorderLayout.CENTER); + opPanel.add(interactionPanel,BorderLayout.LINE_END); + root.add(opPanel,BorderLayout.LINE_END); + return root; + } + @Override + public void subscribe() { + super.subscribe(); + } + + @Override + protected void updateHotKeyPool() { + this.hotKeysPool.clear(); + this.interactButtonMap.forEach((type, button) -> { + HotKeyPair hotKeyPair = this.hotKeysConfig.get() + .getScannerNHotKeysList() + .stream() + .filter(it -> it.getType().equals(type)) + .findAny().orElse(null); + this.hotKeysPool.put(hotKeyPair.getDescriptor(),button); + }); + } + + @Override + public void onViewDestroy() { + super.onViewDestroy(); + } + + private JButton getExpandButton(){ + String iconPath = "app/expand-mp.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + expandButton.addActionListener(action -> { + if(this.contentPanel.isVisible()){ + this.contentPanel.setVisible(false); + expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); + }else { + this.contentPanel.setVisible(true); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png",18f)); + } + SwingUtilities.getWindowAncestor(ScannerNotificationPanel.this).pack(); + }); + return expandButton; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/HistoryController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/HistoryController.java new file mode 100644 index 00000000..6564dff7 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/HistoryController.java @@ -0,0 +1,7 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +public interface HistoryController { + void reload(); + void performOpenChat(); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/IncomingPanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/IncomingPanelController.java new file mode 100644 index 00000000..0c1ba966 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/IncomingPanelController.java @@ -0,0 +1,8 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +public interface IncomingPanelController extends NotificationController{ + void performInvite(); + void performKick(); + void showITH(); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationController.java new file mode 100644 index 00000000..11a0728c --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationController.java @@ -0,0 +1,9 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +public interface NotificationController { + void performOfferTrade(); + void performHide(); + void performOpenChat(); + void performResponse(String response); +} 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/notification/controller/NotificationIncomingController.java similarity index 51% rename from app-ui/src/main/java/com/mercury/platform/ui/components/panel/message/NotificationMessageController.java rename to app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationIncomingController.java index 12fc186c..8e094d7f 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/notification/controller/NotificationIncomingController.java @@ -1,7 +1,7 @@ -package com.mercury.platform.ui.components.panel.message; +package com.mercury.platform.ui.components.panel.notification.controller; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.NonNull; @@ -14,59 +14,53 @@ import java.awt.datatransfer.StringSelection; //todo proxy -public class NotificationMessageController implements MessagePanelController { - private static final Logger log = LogManager.getLogger(NotificationMessageController.class); - private Message message; - public NotificationMessageController(Message message){ - this.message = message; +public class NotificationIncomingController implements IncomingPanelController { + private static final Logger log = LogManager.getLogger(NotificationIncomingController.class); + private NotificationDescriptor notificationDescriptor; + public NotificationIncomingController(NotificationDescriptor notificationDescriptor){ + this.notificationDescriptor = notificationDescriptor; } @Override public void performInvite() { - MercuryStoreCore.chatCommandSubject.onNext("/invite " + message.getWhisperNickname()); + MercuryStoreCore.chatCommandSubject.onNext("/invite " + notificationDescriptor.getWhisperNickname()); showITH(); } @Override public void performKick() { - MercuryStoreCore.chatCommandSubject.onNext("/kick " + message.getWhisperNickname()); - + MercuryStoreCore.chatCommandSubject.onNext("/kick " + notificationDescriptor.getWhisperNickname()); } @Override public void performOfferTrade() { - MercuryStoreCore.chatCommandSubject.onNext("/tradewith " + message.getWhisperNickname()); + MercuryStoreCore.chatCommandSubject.onNext("/tradewith " + notificationDescriptor.getWhisperNickname()); } @Override public void performOpenChat() { - MercuryStoreCore.openChatSubject.onNext(message.getWhisperNickname()); + MercuryStoreCore.openChatSubject.onNext(notificationDescriptor.getWhisperNickname()); } @Override public void performResponse(@NonNull String responseText) { - MercuryStoreCore.chatCommandSubject.onNext("@" + message.getWhisperNickname() + " " + responseText); + MercuryStoreCore.chatCommandSubject.onNext("@" + notificationDescriptor.getWhisperNickname() + " " + responseText); } @Override public void performHide() { - closeMessagePanel(); + this.closeMessagePanel(); } @Override public void showITH() { - if(message instanceof ItemMessage) { - this.copyItemNameToClipboard(((ItemMessage) message).getItemName()); - if (((ItemMessage) message).getTabName() != null) { - MercuryStoreUI.showItemGridSubject.onNext((ItemMessage) message); + if(notificationDescriptor instanceof ItemTradeNotificationDescriptor) { + this.copyItemNameToClipboard(((ItemTradeNotificationDescriptor) notificationDescriptor).getItemName()); + if (((ItemTradeNotificationDescriptor) notificationDescriptor).getTabName() != null) { + MercuryStoreUI.showItemGridSubject.onNext((ItemTradeNotificationDescriptor) notificationDescriptor); } } } - @Override - public void reloadMessage(InMessagePanel panel) { - MercuryStoreUI.reloadMessageSubject.onNext(panel); - } - private void copyItemNameToClipboard(@NonNull String itemName){ Timer timer = new Timer(30, action -> { StringSelection selection = new StringSelection(itemName); @@ -79,7 +73,7 @@ private void copyItemNameToClipboard(@NonNull String itemName){ private void closeMessagePanel(){ Timer timer = new Timer(30, action -> { - MercuryStoreUI.closeMessage.onNext(message); + MercuryStoreCore.removeNotificationSubject.onNext(notificationDescriptor); }); timer.setRepeats(false); timer.start(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationOutgoingController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationOutgoingController.java new file mode 100644 index 00000000..8bb4d1b4 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationOutgoingController.java @@ -0,0 +1,53 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; + +import javax.swing.*; + +public class NotificationOutgoingController implements OutgoingPanelController{ + private NotificationDescriptor notificationDescriptor; + + public NotificationOutgoingController(NotificationDescriptor notificationDescriptor) { + this.notificationDescriptor = notificationDescriptor; + } + + @Override + public void visitHideout() { + MercuryStoreCore.chatCommandSubject.onNext("/hideout " + notificationDescriptor.getWhisperNickname()); + } + + @Override + public void performLeave(String nickName) { + MercuryStoreCore.chatCommandSubject.onNext("/kick " + nickName); + } + + @Override + public void performOfferTrade() { + MercuryStoreCore.chatCommandSubject.onNext("/tradewith " + notificationDescriptor.getWhisperNickname()); + } + + @Override + public void performHide() { + this.closeMessagePanel(); + } + + @Override + public void performOpenChat() { + MercuryStoreCore.openChatSubject.onNext(notificationDescriptor.getWhisperNickname()); + } + + @Override + public void performResponse(String response) { + MercuryStoreCore.chatCommandSubject.onNext("@" + notificationDescriptor.getWhisperNickname() + " " + response); + } + + private void closeMessagePanel(){ + Timer timer = new Timer(30, action -> { + MercuryStoreCore.removeNotificationSubject.onNext(notificationDescriptor); + }); + timer.setRepeats(false); + timer.start(); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationScannerController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationScannerController.java new file mode 100644 index 00000000..050f6abc --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationScannerController.java @@ -0,0 +1,52 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; + +import javax.swing.*; + +public class NotificationScannerController implements ScannerPanelController { + private PlainMessageDescriptor notificationDescriptor; + + public NotificationScannerController(PlainMessageDescriptor notificationDescriptor) { + this.notificationDescriptor = notificationDescriptor; + } + + @Override + public void visitHideout() { + MercuryStoreCore.chatCommandSubject.onNext("/hideout " + notificationDescriptor.getNickName()); + } + + @Override + public void performLeave(String nickName) { + MercuryStoreCore.chatCommandSubject.onNext("/kick " + nickName); + } + + @Override + public void performOfferTrade() { + MercuryStoreCore.chatCommandSubject.onNext("/tradewith " + notificationDescriptor.getNickName()); + } + + @Override + public void performHide() { + this.closeMessagePanel(); + } + + @Override + public void performOpenChat() { + MercuryStoreCore.openChatSubject.onNext(notificationDescriptor.getNickName()); + } + + @Override + public void performResponse(String response) { + MercuryStoreCore.chatCommandSubject.onNext("@" + notificationDescriptor.getNickName() + " " + response); + } + private void closeMessagePanel(){ + Timer timer = new Timer(30, action -> { + MercuryStoreCore.removeScannerNotificationSubject.onNext(notificationDescriptor); + }); + timer.setRepeats(false); + timer.start(); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/OutgoingPanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/OutgoingPanelController.java new file mode 100644 index 00000000..61b8265c --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/OutgoingPanelController.java @@ -0,0 +1,7 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + + +public interface OutgoingPanelController extends NotificationController{ + void visitHideout(); + void performLeave(String nickName); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/ScannerPanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/ScannerPanelController.java new file mode 100644 index 00000000..8551c90f --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/ScannerPanelController.java @@ -0,0 +1,6 @@ +package com.mercury.platform.ui.components.panel.notification.controller; + +public interface ScannerPanelController extends NotificationController{ + void visitHideout(); + void performLeave(String nickName); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/HistoryStubController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/HistoryStubController.java new file mode 100644 index 00000000..bd95b67d --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/HistoryStubController.java @@ -0,0 +1,16 @@ +package com.mercury.platform.ui.components.panel.notification.controller.stub; + +import com.mercury.platform.ui.components.panel.notification.controller.HistoryController; + + +public class HistoryStubController implements HistoryController { + @Override + public void reload() { + + } + + @Override + public void performOpenChat() { + + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/IncStubController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/IncStubController.java new file mode 100644 index 00000000..070e2552 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/IncStubController.java @@ -0,0 +1,40 @@ +package com.mercury.platform.ui.components.panel.notification.controller.stub; + +import com.mercury.platform.ui.components.panel.notification.controller.IncomingPanelController; + +public class IncStubController implements IncomingPanelController { + @Override + public void performOfferTrade() { + + } + + @Override + public void performHide() { + + } + + @Override + public void performOpenChat() { + + } + + @Override + public void performResponse(String response) { + + } + + @Override + public void performInvite() { + + } + + @Override + public void performKick() { + + } + + @Override + public void showITH() { + + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/OutStubController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/OutStubController.java new file mode 100644 index 00000000..07ad16bb --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/OutStubController.java @@ -0,0 +1,38 @@ +package com.mercury.platform.ui.components.panel.notification.controller.stub; + +import com.mercury.platform.ui.components.panel.notification.controller.OutgoingPanelController; + +/** + * Created by Константин on 20.08.2017. + */ +public class OutStubController implements OutgoingPanelController { + @Override + public void performOfferTrade() { + + } + + @Override + public void performHide() { + + } + + @Override + public void performOpenChat() { + + } + + @Override + public void performResponse(String response) { + + } + + @Override + public void visitHideout() { + + } + + @Override + public void performLeave(String nickName) { + + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/ScannerStubController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/ScannerStubController.java new file mode 100644 index 00000000..2f4fea81 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/stub/ScannerStubController.java @@ -0,0 +1,38 @@ +package com.mercury.platform.ui.components.panel.notification.controller.stub; + +import com.mercury.platform.ui.components.panel.notification.controller.ScannerPanelController; + +/** + * Created by Константин on 20.08.2017. + */ +public class ScannerStubController implements ScannerPanelController { + @Override + public void performOfferTrade() { + + } + + @Override + public void performHide() { + + } + + @Override + public void performOpenChat() { + + } + + @Override + public void performResponse(String response) { + + } + + @Override + public void visitHideout() { + + } + + @Override + public void performLeave(String nickName) { + + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyIncPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyIncPanelProvider.java new file mode 100644 index 00000000..fcd58e6d --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyIncPanelProvider.java @@ -0,0 +1,22 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.ui.components.panel.notification.CurrencyIncNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.IncomingPanelController; +import com.mercury.platform.ui.components.panel.notification.controller.NotificationIncomingController; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; + +public class CurrencyIncPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.INC_CURRENCY_MESSAGE); + } + + @Override + protected NotificationPanel getPanel() { + CurrencyIncNotificationPanel panel = new CurrencyIncNotificationPanel(); + panel.setController(new NotificationIncomingController(this.data)); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyOutPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyOutPanelProvider.java new file mode 100644 index 00000000..45fed54b --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyOutPanelProvider.java @@ -0,0 +1,22 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.CurrencyTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.ui.components.panel.notification.CurrencyOutNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.NotificationOutgoingController; +import com.mercury.platform.ui.components.panel.notification.controller.OutgoingPanelController; + + +public class CurrencyOutPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.OUT_CURRENCY_MESSAGE); + } + @Override + protected NotificationPanel getPanel() { + CurrencyOutNotificationPanel panel = new CurrencyOutNotificationPanel(); + panel.setController(new NotificationOutgoingController(this.data)); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/HistoryPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/HistoryPanelProvider.java new file mode 100644 index 00000000..fa0e5945 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/HistoryPanelProvider.java @@ -0,0 +1,33 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.panel.notification.HistoryNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.HistoryController; + + +public class HistoryPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.HISTORY); + } + + @Override + protected NotificationPanel getPanel() { + HistoryNotificationPanel panel = new HistoryNotificationPanel(); + panel.setController(new HistoryController() { + @Override + public void reload() { + MercuryStoreCore.newNotificationSubject.onNext(data); + } + + @Override + public void performOpenChat() { + MercuryStoreCore.openChatSubject.onNext(data.getWhisperNickname()); + } + }); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemIncPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemIncPanelProvider.java new file mode 100644 index 00000000..7c0ee07e --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemIncPanelProvider.java @@ -0,0 +1,23 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.ui.components.panel.notification.ItemIncNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.IncomingPanelController; +import com.mercury.platform.ui.components.panel.notification.controller.NotificationIncomingController; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; + + +public class ItemIncPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.INC_ITEM_MESSAGE); + } + + @Override + protected NotificationPanel getPanel() { + ItemIncNotificationPanel panel = new ItemIncNotificationPanel(); + panel.setController(new NotificationIncomingController(this.data)); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemOutPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemOutPanelProvider.java new file mode 100644 index 00000000..ddc21c75 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ItemOutPanelProvider.java @@ -0,0 +1,23 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.ui.components.panel.notification.ItemOutNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.NotificationOutgoingController; +import com.mercury.platform.ui.components.panel.notification.controller.OutgoingPanelController; + + +public class ItemOutPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.OUT_ITEM_MESSAGE); + } + + @Override + protected NotificationPanel getPanel() { + ItemOutNotificationPanel panel = new ItemOutNotificationPanel(); + panel.setController(new NotificationOutgoingController(this.data)); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelFactory.java new file mode 100644 index 00000000..08db85fc --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelFactory.java @@ -0,0 +1,32 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + + +import com.mercury.platform.shared.entity.message.NotificationType; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +public class NotificationPanelFactory { + private List providers = new ArrayList<>(); + + public NotificationPanelFactory() { + this.providers.add(new ItemIncPanelProvider()); + this.providers.add(new CurrencyIncPanelProvider()); + this.providers.add(new ItemOutPanelProvider()); + this.providers.add(new CurrencyOutPanelProvider()); + this.providers.add(new ScannerPanelProvider()); + this.providers.add(new HistoryPanelProvider()); + } + + public NotificationPanelProvider getProviderFor(NotificationType type){ + NotificationPanelProvider provider = this.providers.stream() + .filter(it -> it.isSuitable(type)) + .findAny().orElse(null); + if(provider != null){ + return provider; + }else { + throw new NoSuchElementException("Notification panel provider for <" + type + "> doesn't exist."); + } + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelProvider.java new file mode 100644 index 00000000..71ef7fcd --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/NotificationPanelProvider.java @@ -0,0 +1,42 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + + +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; + +public abstract class NotificationPanelProvider { + protected T data; + protected C controller; + protected ComponentsFactory componentsFactory; + + public abstract boolean isSuitable(NotificationType type); + public NotificationPanelProvider setController(C controller) { + this.controller = controller; + return this; + } + public NotificationPanelProvider setData(T data) { + this.data = data; + return this; + } + public NotificationPanelProvider setComponentsFactory(ComponentsFactory factory) { + this.componentsFactory = factory; + return this; + } + + public NotificationPanel build() { + NotificationPanel panel = this.getPanel(); + panel.setData(this.data); + if(this.controller != null){ + panel.setController(this.controller); + } + panel.setComponentsFactory(this.componentsFactory); + panel.subscribe(); + panel.onViewInit(); + this.componentsFactory = null; + this.controller = null; + return panel; + } + protected abstract NotificationPanel getPanel(); +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ScannerPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ScannerPanelProvider.java new file mode 100644 index 00000000..7a1235df --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/ScannerPanelProvider.java @@ -0,0 +1,23 @@ +package com.mercury.platform.ui.components.panel.notification.factory; + +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.ScannerNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.NotificationScannerController; +import com.mercury.platform.ui.components.panel.notification.controller.ScannerPanelController; + +public class ScannerPanelProvider extends NotificationPanelProvider { + @Override + public boolean isSuitable(NotificationType type) { + return type.equals(NotificationType.SCANNER_MESSAGE); + } + + @Override + protected NotificationPanel getPanel() { + ScannerNotificationPanel panel = new ScannerNotificationPanel(); + panel.setController(new NotificationScannerController(this.data)); + return panel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/ConfigurationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/ConfigurationPanel.java index 60c28e93..6ad50148 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/ConfigurationPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/ConfigurationPanel.java @@ -1,14 +1,9 @@ package com.mercury.platform.ui.components.panel.settings; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.configration.impl.ApplicationConfigurationService; import com.mercury.platform.ui.components.panel.TransparentPanel; -import com.mercury.platform.ui.components.panel.misc.HasUI; -import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.components.panel.misc.ViewInit; -import javax.swing.*; - -public abstract class ConfigurationPanel extends TransparentPanel implements HasUI{ +public abstract class ConfigurationPanel extends TransparentPanel implements ViewInit { public abstract boolean processAndSave(); public abstract void restore(); 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 e77bd56c..efc23d4b 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 @@ -3,7 +3,7 @@ import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.frame.titled.NotesFrame; import com.mercury.platform.ui.frame.titled.SettingsFrame; import com.mercury.platform.ui.frame.titled.TestCasesFrame; @@ -17,17 +17,17 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class HelpPanel extends JPanel implements HasUI { +public class HelpPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; public HelpPanel() { super(); componentsFactory = new ComponentsFactory(); this.setBackground(AppThemeColor.TRANSPARENT); - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton openTutorial = componentsFactory.getBorderedButton("Open tutorial"); openTutorial.addMouseListener(new MouseAdapter() { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuPanel.java index 8086984b..2959cd90 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuPanel.java @@ -2,7 +2,7 @@ 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; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.manager.routing.SettingsPage; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; @@ -12,17 +12,17 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public class MenuPanel extends JPanel implements HasUI { +public class MenuPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory = new ComponentsFactory(); public MenuPanel() { super(); this.setBackground(AppThemeColor.FRAME); this.setPreferredSize(new Dimension(220, 20)); this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, AppThemeColor.ADR_PANEL_BORDER)); - this.createUI(); + this.onViewInit(); } @Override - public void createUI() { + public void onViewInit() { JList list = new JList<>(getEntries()); list.addMouseListener(new MouseAdapter() { @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/AboutPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/AboutPagePanel.java index 5f7ecd6f..6a03b013 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/AboutPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/AboutPagePanel.java @@ -14,8 +14,8 @@ public class AboutPagePanel extends SettingsPagePanel { @Override - public void createUI() { - super.createUI(); + public void onViewInit() { + super.onViewInit(); this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); JPanel imgPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); imgPanel.add(componentsFactory.getIconLabel("app/app-icon-big.png")); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/GeneralSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/GeneralSettingsPagePanel.java index 5ca752e5..1a145bc9 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/GeneralSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/GeneralSettingsPagePanel.java @@ -6,12 +6,9 @@ import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.configration.PlainConfigurationService; import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; -import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.frame.titled.SettingsFrame; import com.mercury.platform.ui.manager.HideSettingsManager; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; @@ -27,8 +24,8 @@ public class GeneralSettingsPagePanel extends SettingsPagePanel { private JSlider minSlider; private JSlider maxSlider; @Override - public void createUI() { - super.createUI(); + public void onViewInit() { + super.onViewInit(); this.applicationConfig = Configuration.get().applicationConfiguration(); this.applicationSnapshot = CloneHelper.cloneObject(this.applicationConfig.get()); @@ -124,6 +121,6 @@ public void onSave() { public void restore() { this.applicationSnapshot = CloneHelper.cloneObject(this.applicationConfig.get()); this.removeAll(); - this.createUI(); + this.onViewInit(); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/HotKeyPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/HotKeyPanel.java new file mode 100644 index 00000000..dd79df0b --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/HotKeyPanel.java @@ -0,0 +1,61 @@ +package com.mercury.platform.ui.components.panel.settings.page; + +import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.misc.AppThemeColor; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + + +public class HotKeyPanel extends JPanel { + private HotKeyDescriptor descriptor; + private boolean hotKeyAllowed; + private ComponentsFactory componentsFactory = new ComponentsFactory(); + public HotKeyPanel(HotKeyDescriptor descriptor) { + super(new BorderLayout()); + this.descriptor = descriptor; + this.setPreferredSize(new Dimension(100,26)); + + JButton button = this.componentsFactory.getBorderedButton(this.descriptor.getTitle()); + button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 17f)); + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if(SwingUtilities.isLeftMouseButton(e)) { + button.setBackground(AppThemeColor.ADR_BG); + button.setText("Press any key"); + hotKeyAllowed = true; + button.removeMouseListener(this); + } + } + }; + button.addMouseListener(mouseAdapter); + MercuryStoreCore.hotKeySubject.subscribe(hotKey -> { + if (hotKeyAllowed) { + button.setBackground(AppThemeColor.BUTTON); + if (hotKey.getVirtualKeyCode() == 27) { + this.descriptor.setTitle("..."); + this.descriptor.setVirtualKeyCode(0); + this.descriptor.setMenuPressed(false); + this.descriptor.setShiftPressed(false); + this.descriptor.setControlPressed(false); + } else { + this.descriptor.setTitle(hotKey.getTitle()); + this.descriptor.setVirtualKeyCode(hotKey.getVirtualKeyCode()); + this.descriptor.setMenuPressed(hotKey.isMenuPressed()); + this.descriptor.setShiftPressed(hotKey.isShiftPressed()); + this.descriptor.setControlPressed(hotKey.isControlPressed()); + } + button.setText(hotKey.getTitle()); + hotKeyAllowed = false; + button.addMouseListener(mouseAdapter); + } + }); + this.add(button,BorderLayout.CENTER); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java index aa3c0ff0..7f68637e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java @@ -4,10 +4,7 @@ import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; -import com.mercury.platform.shared.config.descriptor.HotKeyType; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; -import com.mercury.platform.shared.config.descriptor.ResponseButtonDescriptor; +import com.mercury.platform.shared.config.descriptor.*; import com.mercury.platform.shared.entity.message.FlowDirections; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; @@ -18,61 +15,69 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.util.Map; +import java.util.*; +import java.util.List; public class NotificationSettingsPagePanel extends SettingsPagePanel { - private PlainConfigurationService notificationService; - private KeyValueConfigurationService hotKeyService; - private NotificationDescriptor generalSnapshot; - private Map hotKeySnapshot; - private JPanel buttonsTable; + private PlainConfigurationService notificationService; + private PlainConfigurationService hotKeyService; + private PlainConfigurationService scannerService; + private NotificationSettingsDescriptor generalSnapshot; + private List incHotKeySnapshot; + private List outHotKeySnapshot; + private List scannerHotKeySnapshot; + private ScannerDescriptor scannerSnapshot; @Override - public void createUI() { - super.createUI(); + public void onViewInit() { + super.onViewInit(); this.notificationService = Configuration.get().notificationConfiguration(); this.hotKeyService = Configuration.get().hotKeysConfiguration(); + this.scannerService = Configuration.get().scannerConfiguration(); this.generalSnapshot = CloneHelper.cloneObject(notificationService.get()); - this.hotKeySnapshot = CloneHelper.cloneObject(hotKeyService.getMap()); - - JPanel inPanel = this.adrComponentsFactory.getCounterPanel(this.getIncomingPanel(), "Incoming notification:", AppThemeColor.ADR_BG,true); + this.incHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getIncNHotKeysList()); + this.outHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getOutNHotKeysList()); + this.scannerHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getScannerNHotKeysList()); + this.scannerSnapshot = CloneHelper.cloneObject(scannerService.get()); + JPanel inPanel = this.adrComponentsFactory.getCounterPanel(this.getIncomingPanel(), "Incoming notification:", AppThemeColor.ADR_BG,false); inPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - JPanel outPanel = this.adrComponentsFactory.getCounterPanel(this.getOutgoingPanel(), "Outgoing notification:", AppThemeColor.ADR_BG,true); + JPanel outPanel = this.adrComponentsFactory.getCounterPanel(this.getOutgoingPanel(), "Outgoing notification:", AppThemeColor.ADR_BG,false); outPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - this.container.add(this.componentsFactory.wrapToSlide(inPanel)); -// this.container.add(this.componentsFactory.wrapToSlide(outPanel)); + JPanel scannerPanel = this.adrComponentsFactory.getCounterPanel(this.getChatScannerPanel(), "Chat scanner notification:", AppThemeColor.ADR_BG,false); + scannerPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); + this.container.add(this.componentsFactory.wrapToSlide(this.getGeneralPanel(),4,4,2,4)); + this.container.add(this.componentsFactory.wrapToSlide(inPanel,2,4,2,4)); + this.container.add(this.componentsFactory.wrapToSlide(outPanel,2,4,2,4)); + this.container.add(this.componentsFactory.wrapToSlide(scannerPanel,2,4,2,4)); } @Override public void onSave() { this.notificationService.set(CloneHelper.cloneObject(this.generalSnapshot)); - this.hotKeyService.set(CloneHelper.cloneObject(this.hotKeySnapshot)); + this.hotKeyService.get().setIncNHotKeysList(CloneHelper.cloneObject(this.incHotKeySnapshot)); + this.hotKeyService.get().setOutNHotKeysList(CloneHelper.cloneObject(this.outHotKeySnapshot)); + this.hotKeyService.get().setScannerNHotKeysList(CloneHelper.cloneObject(this.scannerHotKeySnapshot)); + this.scannerService.set(CloneHelper.cloneObject(this.scannerSnapshot)); + + //protect + this.scannerSnapshot = CloneHelper.cloneObject(scannerService.get()); + MercuryStoreCore.buttonsChangedSubject.onNext(true); } @Override public void restore() { - this.generalSnapshot = CloneHelper.cloneObject(notificationService.get()); - this.hotKeySnapshot = CloneHelper.cloneObject(hotKeyService.getMap()); + this.incHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getIncNHotKeysList()); + this.outHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getOutNHotKeysList()); + this.scannerHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getScannerNHotKeysList()); this.removeAll(); - this.createUI(); + this.onViewInit(); } - private JPanel getIncomingPanel() { + private JPanel getGeneralPanel(){ JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.ADR_BG); - JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isNotificationEnable()); - enabled.addActionListener(action -> { - this.generalSnapshot.setNotificationEnable(enabled.isSelected()); - }); - JCheckBox dismiss = this.componentsFactory.getCheckBox(this.generalSnapshot.isDismissAfterKick()); - dismiss.addActionListener(action -> { - this.generalSnapshot.setDismissAfterKick(dismiss.isSelected()); - }); - JCheckBox showLeague = this.componentsFactory.getCheckBox(this.generalSnapshot.isShowLeague()); - showLeague.addActionListener(action -> { - this.generalSnapshot.setShowLeague(showLeague.isSelected()); - }); + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); JComboBox flowDirectionPicker = componentsFactory.getComboBox(new String[]{"Upwards", "Downwards"}); flowDirectionPicker.addActionListener(e -> { switch ((String)flowDirectionPicker.getSelectedItem()){ @@ -86,35 +91,71 @@ private JPanel getIncomingPanel() { } } }); + JLabel limitLabel = this.componentsFactory.getTextLabel(String.valueOf(this.generalSnapshot.getLimitCount()), FontStyle.REGULAR, 16); + limitLabel.setPreferredSize(new Dimension(30,26)); JSlider limitSlider = componentsFactory.getSlider(2, 20, this.generalSnapshot.getLimitCount(),AppThemeColor.ADR_BG); limitSlider.addChangeListener(e -> { + limitLabel.setText(String.valueOf(limitSlider.getValue())); this.generalSnapshot.setLimitCount(limitSlider.getValue()); }); - JSlider unfoldSlider = componentsFactory.getSlider(0, 20, this.generalSnapshot.getUnfoldCount(),AppThemeColor.ADR_BG); - unfoldSlider.addChangeListener(e -> { - this.generalSnapshot.setUnfoldCount(unfoldSlider.getValue()); - }); flowDirectionPicker.setSelectedIndex(this.generalSnapshot.getFlowDirections().ordinal()); + propertiesPanel.add(this.componentsFactory.getTextLabel("Flow direction:", FontStyle.REGULAR,16)); + propertiesPanel.add(flowDirectionPicker); + propertiesPanel.add(this.componentsFactory.getTextLabel("Pre-group limit:", FontStyle.REGULAR,16)); + JPanel limitPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); + limitPanel.add(limitLabel,BorderLayout.LINE_START); + limitPanel.add(limitSlider,BorderLayout.CENTER); + propertiesPanel.add(limitPanel); + propertiesPanel.add(this.componentsFactory.getTextLabel("Your nickname(for leave option):", FontStyle.REGULAR,16)); + JTextField nickNameField = this.componentsFactory.getTextField(this.generalSnapshot.getPlayerNickname(), FontStyle.DEFAULT, 15f); + nickNameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + generalSnapshot.setPlayerNickname(nickNameField.getText()); + } + }); + propertiesPanel.add(nickNameField); + root.add(this.componentsFactory.wrapToSlide(propertiesPanel,AppThemeColor.ADR_BG,2,0,2,2),BorderLayout.PAGE_START); + return root; + } + + private JPanel getIncomingPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); + JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.ADR_BG); + JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isIncNotificationEnable()); + enabled.addActionListener(action -> { + this.generalSnapshot.setIncNotificationEnable(enabled.isSelected()); + }); + JCheckBox dismiss = this.componentsFactory.getCheckBox(this.generalSnapshot.isDismissAfterKick()); + dismiss.addActionListener(action -> { + this.generalSnapshot.setDismissAfterKick(dismiss.isSelected()); + }); + JCheckBox showLeague = this.componentsFactory.getCheckBox(this.generalSnapshot.isShowLeague()); + showLeague.addActionListener(action -> { + this.generalSnapshot.setShowLeague(showLeague.isSelected()); + }); propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR,16)); propertiesPanel.add(enabled); propertiesPanel.add(this.componentsFactory.getTextLabel("Close panel on kick:", FontStyle.REGULAR,16)); propertiesPanel.add(dismiss); propertiesPanel.add(this.componentsFactory.getTextLabel("Show league:", FontStyle.REGULAR,16)); propertiesPanel.add(showLeague); -// propertiesPanel.add(this.componentsFactory.getTextLabel("Flow direction:", FontStyle.REGULAR,16)); -// propertiesPanel.add(flowDirectionPicker); -// propertiesPanel.add(this.componentsFactory.getTextLabel("Pre-group limit:", FontStyle.REGULAR,16)); -// propertiesPanel.add(limitSlider); -// propertiesPanel.add(this.componentsFactory.getTextLabel("Unfold by default:", FontStyle.REGULAR,16)); -// propertiesPanel.add(unfoldSlider); root.add(propertiesPanel,BorderLayout.PAGE_START); - root.add(this.componentsFactory.wrapToSlide(this.getResponseButtonsPanel(),AppThemeColor.ADR_BG),BorderLayout.CENTER); -// root.add(this.componentsFactory.wrapToSlide(this.getInNotificationHotKeysPanel(),AppThemeColor.ADR_BG),BorderLayout.PAGE_END); + + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getResponseButtonsPanel(this.generalSnapshot.getButtons()),AppThemeColor.ADR_BG),"Response buttons:"),BorderLayout.CENTER); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getInNotificationHotKeysPanel(),AppThemeColor.ADR_BG),"Hotkeys"),BorderLayout.PAGE_END); + root.setVisible(false); return root; } - private JPanel getResponseButtonsPanel(){ + private JPanel wrapToCounter(JPanel inner, String title){ + JPanel root = this.adrComponentsFactory.getCounterPanel(inner, title, AppThemeColor.ADR_BG,false); + inner.setVisible(false); + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); + return this.componentsFactory.wrapToSlide(root,AppThemeColor.ADR_BG); + } + private JPanel getResponseButtonsPanel(List buttons){ JPanel root = this.componentsFactory.getJPanel(new BorderLayout(4,4), AppThemeColor.SETTINGS_BG); - this.buttonsTable = this.componentsFactory.getJPanel(new GridLayout(0, 1, 4, 4),AppThemeColor.SETTINGS_BG); + JPanel buttonsTable = this.componentsFactory.getJPanel(new GridLayout(0, 1, 4, 4),AppThemeColor.SETTINGS_BG); buttonsTable.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); JPanel headerPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.SETTINGS_BG); @@ -140,20 +181,22 @@ private JPanel getResponseButtonsPanel(){ miscPanel.add(closeLabel,BorderLayout.LINE_END); headerPanel.add(miscPanel,BorderLayout.LINE_END); - this.buttonsTable.add(headerPanel); + buttonsTable.add(headerPanel); - this.generalSnapshot.getButtons().forEach(it -> { - this.buttonsTable.add(this.getResponseRow(it)); + buttons.forEach(it -> { + buttonsTable.add(this.getResponseRow(it)); }); - root.add(this.buttonsTable,BorderLayout.CENTER); - JButton addButton = this.componentsFactory.getIconButton("app/add_button.png", 24, AppThemeColor.HEADER, "Add button"); - addButton.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); + root.add(buttonsTable,BorderLayout.CENTER); + JButton addButton = this.componentsFactory.getIconButton("app/add_button.png", 22, AppThemeColor.HEADER, "Add button"); + addButton.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.BORDER), + BorderFactory.createEmptyBorder(3,3,3,3))); addButton.addActionListener(action -> { ResponseButtonDescriptor descriptor = new ResponseButtonDescriptor(); - int size = this.generalSnapshot.getButtons().size(); + int size = buttons.size(); descriptor.setId(++size); - this.generalSnapshot.getButtons().add(descriptor); - this.buttonsTable.add(this.getResponseRow(descriptor)); + buttons.add(descriptor); + buttonsTable.add(this.getResponseRow(descriptor)); MercuryStoreUI.settingsRepaintSubject.onNext(true); MercuryStoreUI.settingsPackSubject.onNext(true); }); @@ -167,7 +210,6 @@ private JPanel getResponseRow(ResponseButtonDescriptor descriptor){ @Override public void focusLost(FocusEvent e) { descriptor.setTitle(titleField.getText()); - System.out.println(".qwe"); } }); titleField.setPreferredSize(new Dimension(120,26)); @@ -178,8 +220,8 @@ public void focusLost(FocusEvent e) { descriptor.setResponseText(responseField.getText()); } }); - root.add(titleField,BorderLayout.LINE_START); - root.add(responseField,BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(titleField,AppThemeColor.SETTINGS_BG,0,2,2,0),BorderLayout.LINE_START); + root.add(this.componentsFactory.wrapToSlide(responseField,AppThemeColor.SETTINGS_BG,0,0,2,0),BorderLayout.CENTER); JPanel miscPanel = this.componentsFactory.getJPanel(new BorderLayout(4, 4),AppThemeColor.SETTINGS_BG); JCheckBox checkBox = this.componentsFactory.getCheckBox(descriptor.isClose(),"Close notification panel after click?"); @@ -187,11 +229,11 @@ public void focusLost(FocusEvent e) { descriptor.setClose(checkBox.isSelected()); }); miscPanel.add(checkBox, BorderLayout.LINE_START); -// miscPanel.add(new HotKeyPanel(descriptor.getHotKeyDescriptor()),BorderLayout.CENTER); + miscPanel.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(descriptor.getHotKeyDescriptor()),AppThemeColor.SETTINGS_BG,0,0,2,0),BorderLayout.CENTER); JButton removeButton = this.componentsFactory.getIconButton("app/adr/remove_node.png", 17, AppThemeColor.SETTINGS_BG, "Remove button"); removeButton.addActionListener(action -> { - this.buttonsTable.remove(root); + root.getParent().remove(root); this.generalSnapshot.getButtons().remove(descriptor); MercuryStoreUI.settingsPackSubject.onNext(true); MercuryStoreUI.settingsRepaintSubject.onNext(true); @@ -202,77 +244,83 @@ public void focusLost(FocusEvent e) { return root; } private JPanel getInNotificationHotKeysPanel(){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 4, 4, 4),AppThemeColor.SETTINGS_BG); + JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); - this.hotKeySnapshot.forEach((key, value) -> { - if(HotKeyType.contains(key)) { - JLabel iconLabel = this.componentsFactory.getIconLabel(HotKeyType.valueOf(key).getIconPath(), 18); - iconLabel.setHorizontalAlignment(SwingConstants.CENTER); - root.add(iconLabel); - root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(value),AppThemeColor.SETTINGS_BG,1,4,1,1)); - } + this.incHotKeySnapshot.forEach(pair -> { + root.add(this.componentsFactory.getIconLabel(pair.getType().getIconPath(), 18,SwingConstants.CENTER)); + root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(pair.getDescriptor()),AppThemeColor.SETTINGS_BG,2,4,1,1)); + }); return root; } + private JPanel getOutNotificationHotKeysPanel(){ + JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); + this.outHotKeySnapshot.forEach(pair -> { + root.add(this.componentsFactory.getIconLabel(pair.getType().getIconPath(), 18,SwingConstants.CENTER)); + root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(pair.getDescriptor()),AppThemeColor.SETTINGS_BG,2,4,1,1)); + }); + return root; + } + private JPanel getScannerNotificationHotKeysPanel(){ + JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); + root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); + this.scannerHotKeySnapshot.forEach(pair-> { + root.add(this.componentsFactory.getIconLabel(pair.getType().getIconPath(), 18,SwingConstants.CENTER)); + root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(pair.getDescriptor()),AppThemeColor.SETTINGS_BG,2,4,1,1)); + + }); + return root; + } + private JPanel getOutgoingPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.ADR_BG); - JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isNotificationEnable()); + JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isOutNotificationEnable()); enabled.addActionListener(action -> { - this.generalSnapshot.setNotificationEnable(enabled.isSelected()); + this.generalSnapshot.setOutNotificationEnable(enabled.isSelected()); }); propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR,16)); propertiesPanel.add(enabled); + propertiesPanel.add(this.componentsFactory.getTextLabel("Close panel after leave:", FontStyle.REGULAR,16)); + JCheckBox closeAfterLeave = this.componentsFactory.getCheckBox(this.generalSnapshot.isDismissAfterLeave()); + closeAfterLeave.addActionListener(action -> { + this.generalSnapshot.setDismissAfterLeave(closeAfterLeave.isSelected()); + }); + propertiesPanel.add(closeAfterLeave); + root.add(propertiesPanel,BorderLayout.PAGE_START); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getResponseButtonsPanel(this.generalSnapshot.getOutButtons()),AppThemeColor.ADR_BG),"Response buttons:"),BorderLayout.CENTER); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getOutNotificationHotKeysPanel(),AppThemeColor.ADR_BG),"Hotkeys:"),BorderLayout.PAGE_END); + root.setVisible(false); return root; } - - private class HotKeyPanel extends JPanel { - private HotKeyDescriptor descriptor; - private boolean hotKeyAllowed; - private ComponentsFactory componentsFactory = new ComponentsFactory(); - public HotKeyPanel(HotKeyDescriptor descriptor) { - super(new BorderLayout()); - this.descriptor = descriptor; - this.setPreferredSize(new Dimension(130,26)); - - JButton button = this.componentsFactory.getBorderedButton(this.descriptor.getTitle()); - button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 18f)); - MouseAdapter mouseAdapter = new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - button.setBackground(AppThemeColor.ADR_BG); - button.setText("Press any key"); - hotKeyAllowed = true; - button.removeMouseListener(this); - } - } - }; - button.addMouseListener(mouseAdapter); - MercuryStoreCore.hotKeySubject.subscribe(hotKey -> { - if (hotKeyAllowed) { - button.setBackground(AppThemeColor.BUTTON); - if (hotKey.getVirtualKeyCode() == 27) { - this.descriptor.setTitle("..."); - this.descriptor.setVirtualKeyCode(0); - this.descriptor.setMenuPressed(false); - this.descriptor.setShiftPressed(false); - this.descriptor.setControlPressed(false); - } else { - this.descriptor.setTitle(hotKey.getTitle()); - this.descriptor.setVirtualKeyCode(hotKey.getVirtualKeyCode()); - this.descriptor.setMenuPressed(hotKey.isMenuPressed()); - this.descriptor.setShiftPressed(hotKey.isShiftPressed()); - this.descriptor.setControlPressed(hotKey.isControlPressed()); - this.descriptor.setKeyChar(hotKey.getKeyChar()); - } - button.setText(hotKey.getTitle()); - hotKeyAllowed = false; - button.addMouseListener(mouseAdapter); - } - }); - this.add(button,BorderLayout.CENTER); - } + private JPanel getChatScannerPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); + JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.ADR_BG); + JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isScannerNotificationEnable()); + enabled.addActionListener(action -> { + this.generalSnapshot.setScannerNotificationEnable(enabled.isSelected()); + }); + propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR,16)); + propertiesPanel.add(enabled); + JLabel quickResponseLabel = this.componentsFactory.getIconLabel(HotKeyType.N_QUICK_RESPONSE.getIconPath(), 18); + quickResponseLabel.setFont(this.componentsFactory.getFont(FontStyle.REGULAR,16)); + quickResponseLabel.setForeground(AppThemeColor.TEXT_DEFAULT); + quickResponseLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,0)); + quickResponseLabel.setText("Response message:"); + propertiesPanel.add(quickResponseLabel); + JTextField quickResponseField = this.componentsFactory.getTextField(this.scannerSnapshot.getResponseMessage(), FontStyle.BOLD, 15f); + quickResponseField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + scannerSnapshot.setResponseMessage(quickResponseField.getText()); + } + }); + propertiesPanel.add(this.componentsFactory.wrapToSlide(quickResponseField,AppThemeColor.ADR_BG,0,0,0,4)); + root.add(propertiesPanel,BorderLayout.PAGE_START); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getScannerNotificationHotKeysPanel(),AppThemeColor.ADR_BG),"Hotkeys"),BorderLayout.CENTER); + root.setVisible(false); + return root; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SettingsPagePanel.java index f874b49c..6bb478ee 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SettingsPagePanel.java @@ -4,13 +4,13 @@ import com.mercury.platform.ui.adr.components.AdrComponentsFactory; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; import java.awt.*; -public abstract class SettingsPagePanel extends JPanel implements HasUI{ +public abstract class SettingsPagePanel extends JPanel implements ViewInit { protected ComponentsFactory componentsFactory = new ComponentsFactory(); protected AdrComponentsFactory adrComponentsFactory = new AdrComponentsFactory(this.componentsFactory); protected JPanel container; @@ -19,11 +19,11 @@ public SettingsPagePanel() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); - this.createUI(); + this.onViewInit(); } @Override - public void createUI() { + public void onViewInit() { this.container = new VerticalScrollContainer(); this.container.setBackground(AppThemeColor.FRAME); this.container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SoundSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SoundSettingsPagePanel.java index 2e127160..04a3e808 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SoundSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SoundSettingsPagePanel.java @@ -28,8 +28,8 @@ public class SoundSettingsPagePanel extends SettingsPagePanel { Map soundSnapshot; KeyValueConfigurationService soundConfiguration; @Override - public void createUI() { - super.createUI(); + public void onViewInit() { + super.onViewInit(); this.wavPaths = new HashMap<>(); this.wavPaths.put("notification","app/notification.wav"); this.wavPaths.put("chat_scanner","app/chat-filter.wav"); @@ -119,6 +119,6 @@ public void onSave() { public void restore() { this.soundSnapshot = CloneHelper.cloneObject(this.soundConfiguration.getMap()); this.removeAll(); - this.createUI(); + this.onViewInit(); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SupportPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SupportPagePanel.java index 03f9c7e1..bc8f84a8 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SupportPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/SupportPagePanel.java @@ -19,7 +19,7 @@ public class SupportPagePanel extends SettingsPagePanel{ @Override - public void createUI() { + public void onViewInit() { JPanel donatePanel = componentsFactory.getTransparentPanel(); donatePanel.setBackground(AppThemeColor.ADR_BG); donatePanel.setLayout(new GridLayout(0,1,5,5)); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java index 6854396a..87633d7d 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java @@ -4,22 +4,30 @@ import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.configration.PlainConfigurationService; import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; +import com.mercury.platform.shared.config.descriptor.HotKeyPair; +import com.mercury.platform.shared.config.descriptor.HotKeysSettingsDescriptor; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.misc.AppThemeColor; import javax.swing.*; import java.awt.*; +import java.util.*; +import java.util.List; public class TaskBarSettingsPagePanel extends SettingsPagePanel { private PlainConfigurationService applicationConfig; + private PlainConfigurationService hotKeyService; + private List hotKeySnapshot; private ApplicationDescriptor applicationSnapshot; @Override - public void createUI() { - super.createUI(); + public void onViewInit() { + super.onViewInit(); this.applicationConfig = Configuration.get().applicationConfiguration(); + this.hotKeyService = Configuration.get().hotKeysConfiguration(); this.applicationSnapshot = CloneHelper.cloneObject(this.applicationConfig.get()); + this.hotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getTaskBarNHotKeysList()); JPanel root = componentsFactory.getJPanel(new GridLayout(0,2),AppThemeColor.ADR_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); @@ -35,18 +43,29 @@ public void createUI() { root.add(inGameDND); root.add(componentsFactory.getTextLabel("DND response:", FontStyle.REGULAR)); root.add(this.componentsFactory.wrapToSlide(responseField,AppThemeColor.ADR_BG)); + + JPanel hotKeysPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); + hotKeysPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); + this.hotKeySnapshot.forEach(pair -> { + root.add(this.componentsFactory.getIconLabel(pair.getType().getIconPath(), 24,SwingConstants.CENTER)); + root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(pair.getDescriptor()),AppThemeColor.SETTINGS_BG,2,4,1,1)); + + }); this.container.add(this.componentsFactory.wrapToSlide(root)); + this.container.add(this.componentsFactory.wrapToSlide(hotKeysPanel)); } @Override public void onSave() { this.applicationConfig.set(CloneHelper.cloneObject(this.applicationSnapshot)); + this.hotKeyService.get().setTaskBarNHotKeysList(CloneHelper.cloneObject(this.hotKeySnapshot)); } @Override public void restore() { this.applicationSnapshot = CloneHelper.cloneObject(this.applicationConfig.get()); + this.hotKeySnapshot = CloneHelper.cloneObject(this.hotKeyService.get().getTaskBarNHotKeysList()); this.removeAll(); - this.createUI(); + this.onViewInit(); } } 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 785d3f0d..c5961698 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 @@ -3,8 +3,8 @@ import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.frame.movable.TaskBarFrame; -import com.mercury.platform.ui.frame.titled.chat.ChatFilterFrame; -import com.mercury.platform.ui.frame.titled.container.HistoryFrame; +import com.mercury.platform.ui.frame.titled.ChatScannerFrame; +import com.mercury.platform.ui.frame.titled.HistoryFrame; import com.mercury.platform.ui.frame.titled.SettingsFrame; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.MercuryStoreUI; @@ -13,14 +13,14 @@ public class MercuryTaskBarController implements TaskBarController { @Override public void enableDND() { MercuryStoreUI.repaintSubject.onNext(TaskBarFrame.class); - MercuryStoreCore.notificationSubject.onNext("DND on"); + MercuryStoreCore.alertSubject.onNext("DND on"); MercuryStoreCore.dndSubject.onNext(true); } @Override public void disableDND() { MercuryStoreUI.repaintSubject.onNext(TaskBarFrame.class); - MercuryStoreCore.notificationSubject.onNext("DND off"); + MercuryStoreCore.alertSubject.onNext("DND off"); MercuryStoreCore.dndSubject.onNext(false); } @@ -36,7 +36,7 @@ public void performHideout() { @Override public void showChatFiler() { - FramesManager.INSTANCE.hideOrShowFrame(ChatFilterFrame.class); + FramesManager.INSTANCE.hideOrShowFrame(ChatScannerFrame.class); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarPanel.java index be03e950..17270229 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarPanel.java @@ -1,9 +1,20 @@ package com.mercury.platform.ui.components.panel.taskbar; +import com.mercury.platform.core.ProdStarter; +import com.mercury.platform.shared.FrameVisibleState; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; +import com.mercury.platform.shared.config.descriptor.HotKeyPair; +import com.mercury.platform.shared.config.descriptor.HotKeyType; +import com.mercury.platform.shared.config.descriptor.HotKeysSettingsDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.panel.misc.HasUI; +import com.mercury.platform.ui.components.panel.misc.ViewInit; +import com.mercury.platform.ui.frame.movable.TaskBarFrame; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.MercuryStoreUI; import com.mercury.platform.ui.misc.TooltipConstants; import lombok.NonNull; @@ -11,30 +22,56 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.Map; -public class TaskBarPanel extends JPanel implements HasUI{ +public class TaskBarPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; private TaskBarController controller; - public TaskBarPanel(@NonNull TaskBarController controller){ - this.controller = controller; - this.componentsFactory = new ComponentsFactory(); - createUI(); - } + private Map interactButtonMap = new HashMap<>(); + private Map hotKeysPool = new HashMap<>(); + private PlainConfigurationService hotKeysConfig; public TaskBarPanel(@NonNull TaskBarController controller, @NonNull ComponentsFactory factory){ this.controller = controller; this.componentsFactory = factory; - createUI(); - } + this.onViewInit(); + MercuryStoreCore.hotKeySubject.subscribe(hotkeyDescriptor -> { + SwingUtilities.invokeLater(() -> { + if(ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)){ + JButton button = this.hotKeysPool.get(hotkeyDescriptor); + if(button != null){ + button.doClick(); + } + } + }); + }); + MercuryStoreUI.settingsPostSubject.subscribe(state -> { + this.updateHotKeyPool(); + }); + } + private void updateHotKeyPool(){ + this.hotKeysPool.clear(); + this.interactButtonMap.forEach((type, button) -> { + HotKeyPair hotKeyPair = this.hotKeysConfig.get() + .getTaskBarNHotKeysList() + .stream() + .filter(it -> it.getType().equals(type)) + .findAny().orElse(null); + this.hotKeysPool.put(hotKeyPair.getDescriptor(),button); + }); + } @Override - public void createUI() { - this.setBackground(AppThemeColor.TRANSPARENT); + public void onViewInit() { + this.hotKeysConfig = Configuration.get().hotKeysConfiguration(); + + this.setBackground(AppThemeColor.FRAME); this.setLayout(new BoxLayout(this,BoxLayout.X_AXIS)); JButton visibleMode = componentsFactory.getIconButton( "app/visible-always-mode.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.VISIBLE_MODE); componentsFactory.setUpToggleCallbacks(visibleMode, () -> { @@ -51,7 +88,7 @@ public void createUI() { JButton itemGrid = componentsFactory.getIconButton( "app/item-grid-enable.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.ITEM_GRID); itemGrid.addMouseListener(new MouseAdapter() { @Override @@ -65,7 +102,7 @@ public void mousePressed(MouseEvent e) { JButton toHideOut = componentsFactory.getIconButton( "app/hideout.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.HIDEOUT); toHideOut.addActionListener(action -> { this.controller.performHideout(); @@ -74,37 +111,37 @@ public void mousePressed(MouseEvent e) { JButton adr = componentsFactory.getIconButton( "app/overseer_icon.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.ADR_SETTINGS); adr.addActionListener(action -> { FramesManager.INSTANCE.performAdr(); - this.repaint(); + TaskBarFrame windowAncestor = (TaskBarFrame) SwingUtilities.getWindowAncestor(TaskBarPanel.this); + windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(),windowAncestor.getHeight())); + windowAncestor.pack(); }); JButton chatFilter = componentsFactory.getIconButton( "app/chat-filter.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.CHAT_FILTER); chatFilter.addActionListener(action -> { this.controller.showChatFiler(); - this.repaint(); }); JButton historyButton = componentsFactory.getIconButton( "app/history.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.HISTORY); historyButton.addActionListener(action -> { this.controller.showHistory(); - this.repaint(); }); JButton pinButton = componentsFactory.getIconButton( "app/drag_and_drop.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.SETUP_FRAMES_LOCATION); pinButton.addMouseListener(new MouseAdapter() { @Override @@ -118,7 +155,7 @@ public void mouseClicked(MouseEvent e) { JButton scaleButton = componentsFactory.getIconButton( "app/scale-settings.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, TooltipConstants.SCALE_SETTINGS); scaleButton.addMouseListener(new MouseAdapter() { @Override @@ -132,13 +169,16 @@ public void mouseClicked(MouseEvent e) { JButton settingsButton = componentsFactory.getIconButton( "app/settings.png", 26, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, ""); settingsButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { controller.showSettings(); + TaskBarFrame windowAncestor = (TaskBarFrame) SwingUtilities.getWindowAncestor(TaskBarPanel.this); + windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(),windowAncestor.getHeight())); + windowAncestor.pack(); } } }); @@ -146,7 +186,7 @@ public void mousePressed(MouseEvent e) { JButton exitButton = componentsFactory.getIconButton( "app/exit.png", 24, - AppThemeColor.FRAME_ALPHA, + AppThemeColor.FRAME, ""); exitButton.addMouseListener(new MouseAdapter() { @Override @@ -177,6 +217,10 @@ public void mousePressed(MouseEvent e) { this.add(Box.createRigidArea(new Dimension(3, 4))); this.add(exitButton); this.add(Box.createRigidArea(new Dimension(3, 4))); + + this.interactButtonMap.put(HotKeyType.T_TO_HIDEOUT,toHideOut); +// this.interactButtonMap.put(HotKeyType.T_DND,visibleMode); + this.updateHotKeyPool(); } public int getWidthOf(int elementCount){ diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java index b6c13f5f..e7cfc2d3 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractComponentFrame.java @@ -2,6 +2,7 @@ import com.mercury.platform.shared.config.descriptor.FrameDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.manager.HideSettingsManager; import org.pushingpixels.trident.Timeline; @@ -13,7 +14,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; -public abstract class AbstractComponentFrame extends AbstractOverlaidFrame { +public abstract class AbstractComponentFrame extends AbstractOverlaidFrame implements ViewInit { private final int HIDE_TIME = 200; private final int SHOW_TIME = 150; private final int BORDER_THICKNESS = 1; @@ -162,11 +163,13 @@ public void mouseReleased(MouseEvent e) { Dimension size = AbstractComponentFrame.this.getSize(); FrameDescriptor frameDescriptor = framesConfig.getMap().get(AbstractComponentFrame.this.getClass().getSimpleName()); if(EResizeSpace){ - AbstractComponentFrame.this.setMaximumSize(size); - AbstractComponentFrame.this.setMinimumSize(size); - if(AbstractComponentFrame.this.getClass().getSimpleName().equals("MessageFrame")){ + if(AbstractComponentFrame.this.getClass().getSimpleName().equals("NotificationFrame")){ + AbstractComponentFrame.this.setMaximumSize(new Dimension(size.width,0)); + AbstractComponentFrame.this.setMinimumSize(new Dimension(size.width,0)); frameDescriptor.setFrameSize(new Dimension(size.width,0)); }else { + AbstractComponentFrame.this.setMaximumSize(size); + AbstractComponentFrame.this.setMinimumSize(size); frameDescriptor.setFrameSize(size); } onSizeChange(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java index ffdf60e7..2a7b5f50 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractOverlaidFrame.java @@ -9,6 +9,7 @@ import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.frame.other.MercuryLoadingFrame; import com.mercury.platform.ui.misc.AppThemeColor; @@ -17,7 +18,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public abstract class AbstractOverlaidFrame extends JFrame implements AsSubscriber { +public abstract class AbstractOverlaidFrame extends JFrame implements AsSubscriber,ViewInit { protected FrameVisibleState prevState; protected boolean processingHideEvent = true; @@ -51,7 +52,8 @@ public void mouseEntered(MouseEvent e) { } }); - MercuryStoreCore.frameVisibleSubject.subscribe(this::changeVisible); + MercuryStoreCore.frameVisibleSubject.subscribe(state -> + SwingUtilities.invokeLater(()-> this.changeVisible(state))); } protected void changeVisible(FrameVisibleState state){ if (this.processingHideEvent) { @@ -78,6 +80,7 @@ public void init(){ this.layout = getFrameLayout(); this.setLayout(layout); this.initialize(); + this.onViewInit(); this.subscribe(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java index 74961b66..b9ce1a2b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/AbstractScalableComponentFrame.java @@ -1,7 +1,6 @@ package com.mercury.platform.ui.frame; 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.ui.misc.MercuryStoreUI; @@ -9,12 +8,11 @@ import java.awt.*; import java.util.Map; //todo need generalization -public abstract class AbstractScalableComponentFrame extends AbstractComponentFrame implements HasUI{ +public abstract class AbstractScalableComponentFrame extends AbstractComponentFrame { protected Container mainContainer; private ScaleState scaleState = ScaleState.DEFAULT; protected ComponentsFactory stubComponentsFactory; private ScalableFrameConstraints prevConstraints; - protected boolean sizeWasChanged = false; protected boolean inScaleSettings = false; protected AbstractScalableComponentFrame() { @@ -25,7 +23,6 @@ protected AbstractScalableComponentFrame() { this.registerDirectScaleHandler(); } - protected void onScaleLock(){ this.pack(); this.repaint(); @@ -48,17 +45,8 @@ public void setState(ScaleState state){ this.scaleState = ScaleState.DEFAULT; this.setContentPane(mainContainer); this.setVisible(prevConstraints.visible); + this.processEResize = prevConstraints.processEResize; this.setBackground(prevConstraints.bgColor); - this.setLocation(prevConstraints.location); - if(sizeWasChanged){ - this.setPreferredSize(this.getSize()); - this.setMinimumSize(this.getSize()); - this.setMaximumSize(this.getSize()); - sizeWasChanged = false; - }else { - this.setMinimumSize(prevConstraints.minSize); - this.setMaximumSize(prevConstraints.maxSize); - } this.inScaleSettings = false; this.onScaleLock(); break; @@ -68,14 +56,10 @@ public void setState(ScaleState state){ this.scaleState = ScaleState.ENABLE; this.prevConstraints = new ScalableFrameConstraints( this.isVisible(), - this.getMinimumSize(), - this.getMaximumSize(), - this.getLocation(), - this.getBackground() + this.processEResize, this.getBackground() ); + this.processEResize = false; initDefaultView(); - this.setLocation(this.framesConfig.get(this.getClass().getSimpleName()).getFrameLocation()); - this.setMinimumSize(null); this.setVisible(true); this.onScaleUnlock(); break; @@ -94,21 +78,14 @@ private void initDefaultView(){ protected class ScalableFrameConstraints { private boolean visible; - private Dimension minSize; - private Dimension maxSize; - private Point location; + private boolean processEResize; private Color bgColor; ScalableFrameConstraints( - boolean visible, - Dimension minSize, - Dimension maxSize, - Point location, - Color bgColor) { + boolean visible, + boolean processEResize, Color bgColor) { this.visible = visible; - this.minSize = minSize; - this.maxSize = maxSize; - this.location = location; + this.processEResize = processEResize; this.bgColor = bgColor; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java index 4775b63e..a5ef6192 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/AbstractMovableComponentFrame.java @@ -40,9 +40,7 @@ public void setState(LocationState state){ this.isVisible(), this.getBackground(), this.getRootPane().getBorder(), - this.getLocation(), - this.getMinimumSize(), - this.getMaximumSize() + this.getLocation() ); this.processEResize = false; this.processSEResize = false; @@ -50,7 +48,6 @@ public void setState(LocationState state){ this.setBackground(panelForPin.getBackground()); this.setLocation(this.framesConfig.get(this.getClass().getSimpleName()).getFrameLocation()); this.getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); - this.setMinimumSize(null); this.setContentPane(panelForPin); this.setVisible(true); this.setAlwaysOnTop(true); @@ -66,15 +63,6 @@ public void setState(LocationState state){ this.setBackground(prevConstraints.bgColor); this.getRootPane().setBorder(prevConstraints.border); this.setLocation(prevConstraints.location); - if(sizeWasChanged){ - this.setPreferredSize(this.getSize()); - this.setMinimumSize(this.getSize()); - this.setMaximumSize(this.getSize()); - sizeWasChanged = false; - }else { - this.setMinimumSize(prevConstraints.minSize); - this.setMaximumSize(prevConstraints.maxSize); - } inMoveMode = false; this.onLock(); break; @@ -95,20 +83,20 @@ private JPanel setUpMoveListeners(JPanel panel){ panel.addMouseMotionListener(new DraggedFrameMotionListener()); panel.addMouseListener(new DraggedFrameMouseListener()); - if(enableMouseOverBorder) { + if(this.enableMouseOverBorder) { panel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { + panel.setCursor(new Cursor(Cursor.MOVE_CURSOR)); getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.TEXT_MESSAGE, 1)); - AbstractMovableComponentFrame.this.repaint(); } @Override public void mouseExited(MouseEvent e) { + panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (!AbstractMovableComponentFrame.this.getBounds().contains(e.getPoint())) { getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); } - AbstractMovableComponentFrame.this.repaint(); } }); } @@ -126,25 +114,19 @@ protected class MovableFrameConstraints { private Color bgColor; private Border border; private Point location; - private Dimension minSize; - private Dimension maxSize; MovableFrameConstraints(boolean processSEResize, boolean processEResize, boolean visible, Color bgColor, Border border, - Point location, - Dimension minSize, - Dimension maxSize) { + Point location) { this.processSEResize = processSEResize; this.processEResize = processEResize; this.visible = visible; this.bgColor = bgColor; this.border = border; this.location = location; - this.minSize = minSize; - this.maxSize = maxSize; } public void setLocation(Point location) { 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 122a8d6c..c235df96 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 @@ -120,7 +120,7 @@ protected void performScaling(Map scaleData) { } @Override - public void createUI() { + public void onViewInit() { } 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 21ea9698..d9e091d2 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,7 +6,7 @@ import com.mercury.platform.ui.components.panel.HorizontalScrollContainer; import com.mercury.platform.ui.components.panel.grid.*; import com.mercury.platform.ui.misc.MercuryStoreUI; -import com.mercury.platform.shared.entity.message.ItemMessage; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; 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; @@ -28,13 +28,17 @@ public ItemsGridFrame() { stubComponentsFactory.setScale(this.scaleConfig.get("itemcell")); enableMouseOverBorder = false; processHideEffect = false; - itemsGridPanel = new ItemsGridPanel(componentsFactory); - stashTabsContainer = new StashTabsContainer(); } @Override protected void initialize() { super.initialize(); + this.itemsGridPanel = new ItemsGridPanel(componentsFactory); + this.stashTabsContainer = new StashTabsContainer(); + } + + @Override + public void onViewInit() { this.setBackground(AppThemeColor.TRANSPARENT); this.getRootPane().setBorder(null); this.add(itemsGridPanel,BorderLayout.CENTER); @@ -54,8 +58,8 @@ public void subscribe() { } }); MercuryStoreUI.closeMessage.subscribe(message -> { - if(message instanceof ItemMessage) { - this.itemsGridPanel.remove((ItemMessage) message); + if(message instanceof ItemTradeNotificationDescriptor) { + this.itemsGridPanel.remove((ItemTradeNotificationDescriptor) message); if (itemsGridPanel.getActiveTabsCount() == 0) { this.setVisible(false); } @@ -247,7 +251,7 @@ protected JPanel defaultView(ComponentsFactory factory) { JPanel root = factory.getTransparentPanel(new BorderLayout()); root.setSize(this.getSize()); ItemsGridPanel defaultView = new ItemsGridPanel(factory); - ItemMessage message = new ItemMessage(); + ItemTradeNotificationDescriptor message = new ItemTradeNotificationDescriptor(); message.setWhisperNickname("Example1"); message.setTabName("Example"); message.setLeft(5); @@ -269,15 +273,9 @@ protected void performScaling(Map scaleData) { this.componentsFactory.setScale(scaleData.get("itemcell")); } - @Override - public void createUI() { - - } - private class ResizeByWidthMouseMotionListener extends MouseMotionAdapter { @Override public void mouseDragged(MouseEvent e) { - sizeWasChanged = true; JPanel source = (JPanel) e.getSource(); Point frameLocation = getLocation(); setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x + source.getWidth(), getHeight())); @@ -286,7 +284,6 @@ public void mouseDragged(MouseEvent e) { private class ResizeByHeightMouseMotionListener extends MouseMotionAdapter { @Override public void mouseDragged(MouseEvent e) { - sizeWasChanged = true; JPanel source = (JPanel) e.getSource(); Point frameLocation = getLocation(); setSize(new Dimension(getWidth(),e.getLocationOnScreen().y - frameLocation.y + source.getHeight())); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/NotificationFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/NotificationFrame.java new file mode 100644 index 00000000..5a0231b9 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/NotificationFrame.java @@ -0,0 +1,274 @@ +package com.mercury.platform.ui.frame.movable; + +import com.mercury.platform.core.ProdStarter; +import com.mercury.platform.core.utils.interceptor.TradeIncMessagesInterceptor; +import com.mercury.platform.shared.FrameVisibleState; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; +import com.mercury.platform.shared.entity.message.FlowDirections; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.shared.entity.message.TradeNotificationDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.ScannerNotificationPanel; +import com.mercury.platform.ui.components.panel.notification.controller.stub.IncStubController; +import com.mercury.platform.ui.components.panel.notification.controller.stub.OutStubController; +import com.mercury.platform.ui.components.panel.notification.controller.stub.ScannerStubController; +import com.mercury.platform.ui.components.panel.notification.factory.NotificationPanelFactory; +import com.mercury.platform.ui.frame.titled.TestEngine; +import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.MercuryStoreUI; +import net.jodah.expiringmap.ExpiringMap; +import net.jodah.expiringmap.ExpiringValue; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.*; +import javax.swing.Timer; +import java.awt.*; +import java.util.*; +import java.util.List; +import java.util.concurrent.TimeUnit; + + +public class NotificationFrame extends AbstractMovableComponentFrame { + private List notificationPanels; + private List currentOffers; + private PlainConfigurationService config; + private NotificationPanelFactory providersFactory; + private JPanel container; + private JPanel expandPanel; + private boolean expanded; + @Override + protected void initialize() { + super.initialize(); + this.processSEResize = false; + this.notificationPanels = new ArrayList<>(); + this.config = Configuration.get().notificationConfiguration(); + this.componentsFactory.setScale(this.scaleConfig.get("notification")); + this.stubComponentsFactory.setScale(this.scaleConfig.get("notification")); + this.providersFactory = new NotificationPanelFactory(); + } + + @Override + public void onViewInit() { + this.getRootPane().setBorder(null); + this.setBackground(AppThemeColor.TRANSPARENT); + this.currentOffers = new ArrayList<>(); + this.container = new JPanel(); + this.container.setBackground(AppThemeColor.TRANSPARENT); + this.container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + this.expandPanel = this.getExpandPanel(); + this.expandPanel.setVisible(false); + this.add(this.expandPanel,BorderLayout.LINE_START); + this.add(this.container,BorderLayout.CENTER); + this.setVisible(true); + this.pack(); + } + + @Override + @SuppressWarnings("all") + public void subscribe() { + MercuryStoreCore.newNotificationSubject.subscribe(notification -> { + SwingUtilities.invokeLater(() -> { + NotificationPanel notificationPanel = this.providersFactory.getProviderFor(notification.getType()) + .setData(notification) + .setComponentsFactory(this.componentsFactory) + .build(); + String message = StringUtils.substringAfter(notification.getSourceString(), ":"); + if(this.currentOffers.contains(message)){ + notificationPanel.setDuplicate(true); + }else { + this.currentOffers.add(message); + } + this.addNotification(notificationPanel); + if(this.notificationPanels.size() > 1 + && this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) + && !(notificationPanel instanceof ScannerNotificationPanel)){ + this.setLocation(new Point(this.getLocation().x,this.getLocation().y - notificationPanel.getSize().height)); + } + }); + }); + MercuryStoreCore.newScannerMessageSubject.subscribe(message -> { + SwingUtilities.invokeLater(()-> { + NotificationPanel notificationPanel = this.providersFactory.getProviderFor(NotificationType.SCANNER_MESSAGE) + .setData(message) + .setComponentsFactory(this.componentsFactory) + .build(); + this.addNotification(notificationPanel); + Timer packTimer = new Timer(5, action -> { + this.pack(); + if(this.notificationPanels.size() > 1 && this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS)){ + this.setLocation(new Point(this.getLocation().x,this.getLocation().y - notificationPanel.getSize().height)); + } + }); + packTimer.setRepeats(false); + packTimer.start(); + }); + }); + MercuryStoreCore.removeNotificationSubject.subscribe(notification -> { + SwingUtilities.invokeLater(() -> { + NotificationPanel notificationPanel = this.notificationPanels.stream() + .filter(it -> it.getData().equals(notification)) + .findAny().orElse(null); + this.currentOffers.remove(StringUtils.substringAfter(notification.getSourceString(), ":")); + this.removeNotification(notificationPanel); + }); + }); + MercuryStoreCore.removeScannerNotificationSubject.subscribe(message -> { + SwingUtilities.invokeLater(() -> { + NotificationPanel notificationPanel = this.notificationPanels.stream() + .filter(it -> it.getData().equals(message)) + .findAny().orElse(null); + this.removeNotification(notificationPanel); + }); + }); + MercuryStoreCore.hotKeySubject.subscribe(hotkeyDescriptor -> { + SwingUtilities.invokeLater(() -> { + if(this.notificationPanels.size() > 0 && ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)){ + this.notificationPanels.get(0).onHotKeyPressed(hotkeyDescriptor); + } + }); + }); + MercuryStoreUI.settingsPostSubject.subscribe(state -> { + if(this.config.get().getFlowDirections().equals(FlowDirections.DOWNWARDS)){ + this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); + } + }); + } + + private void addNotification(NotificationPanel notificationPanel){ + this.notificationPanels.add(notificationPanel); + this.container.add(notificationPanel); + if(this.notificationPanels.size() > this.config.get().getLimitCount()){ + if(!this.expanded) { + notificationPanel.setPaintAlphaValue(1f); + notificationPanel.setVisible(false); + } + this.expandPanel.setVisible(true); + } + this.pack(); + this.repaint(); + if(this.notificationPanels.size() > 1 + && this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) + && !(notificationPanel instanceof ScannerNotificationPanel)){ + this.setLocation(new Point(this.getLocation().x,this.getLocation().y - notificationPanel.getSize().height)); + } + } + private void removeNotification(NotificationPanel notificationPanel){ + notificationPanel.onViewDestroy(); + int limitCount = this.config.get().getLimitCount(); + if(!this.expanded && this.notificationPanels.size() > limitCount){ + this.notificationPanels.get(limitCount).setVisible(true); + } + this.container.remove(notificationPanel); + this.notificationPanels.remove(notificationPanel); + if(this.notificationPanels.size() - 1 < this.config.get().getLimitCount()){ + this.expandPanel.setVisible(false); + } + this.pack(); + this.repaint(); + if(this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) + && this.notificationPanels.size() == 0){ + this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); + } + } + + @Override + protected JPanel getPanelForPINSettings() { + JPanel panel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + JLabel textLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 22f, "Notification panel"); + textLabel.setHorizontalAlignment(SwingConstants.CENTER); + panel.add(textLabel); + panel.setPreferredSize(new Dimension((int)(400 * componentsFactory.getScale()), (int)(130*componentsFactory.getScale()))); + return panel; + } + + @Override + protected void registerDirectScaleHandler() { + MercuryStoreUI.notificationScaleSubject.subscribe(this::changeScale); + } + + @Override + protected void performScaling(Map scaleData) { + this.componentsFactory.setScale(scaleData.get("notification")); + this.notificationPanels.forEach(it -> { + it.setComponentsFactory(this.componentsFactory); + }); + this.pack(); + this.repaint(); + } + @Override + @SuppressWarnings("all") + protected JPanel defaultView(ComponentsFactory factory) { + TestEngine testEngine = new TestEngine(); + JPanel root = factory.getJPanel(new BorderLayout()); + root.setLayout(new BoxLayout(root,BoxLayout.Y_AXIS)); + + root.add(this.providersFactory + .getProviderFor(NotificationType.INC_ITEM_MESSAGE) + .setData(testEngine.getRandomItemIncMessage()) + .setComponentsFactory(factory) + .setController(new IncStubController()) + .build()); + root.add(this.providersFactory + .getProviderFor(NotificationType.OUT_ITEM_MESSAGE) + .setData(testEngine.getRandomItemOutMessage()) + .setComponentsFactory(factory) + .setController(new OutStubController()) + .build()); + root.add(this.providersFactory + .getProviderFor(NotificationType.SCANNER_MESSAGE) + .setData(testEngine.getRandomScannerMessage()) + .setComponentsFactory(factory) + .setController(new ScannerStubController()) + .build()); + Timer packTimer = new Timer(10, action -> { + this.pack(); + }); + packTimer.start(); + + return root; + } + + @Override + protected LayoutManager getFrameLayout() { + return new BorderLayout(); + } + + private JPanel getExpandPanel(){ + JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); + root.setBackground(AppThemeColor.MSG_HEADER); + root.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createMatteBorder(1,1,1,0,AppThemeColor.FRAME), + BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.RESPONSE_BUTTON_BORDER))); + String iconPath = "app/collapse-all.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath,22,AppThemeColor.MSG_HEADER,""); + expandButton.addActionListener(action -> { + if(this.expanded) { + expandButton.setIcon(this.componentsFactory.getIcon("app/collapse-all.png",22)); + this.notificationPanels + .stream() + .skip(this.config.get().getLimitCount()) + .forEach(it -> it.setVisible(false)); + }else { + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-all.png",22)); + this.notificationPanels.forEach(it -> { + if (!it.isVisible()) { + it.setVisible(true); + } + }); + } + this.expanded = !this.expanded; + this.pack(); + this.repaint(); + }); + expandButton.setAlignmentY(SwingConstants.CENTER); + root.add(expandButton,BorderLayout.CENTER); + return root; + } +} 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 033aa731..31e191c6 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 @@ -9,6 +9,7 @@ import com.mercury.platform.ui.components.panel.taskbar.TaskBarPanel; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; +import lombok.Getter; import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.ease.Spline; @@ -19,6 +20,7 @@ public class TaskBarFrame extends AbstractMovableComponentFrame { private Timeline collapseAnimation; + @Getter private int MIN_WIDTH; private int MAX_WIDTH; private MouseListener collapseListener; @@ -33,36 +35,6 @@ public TaskBarFrame() { this.prevState = FrameVisibleState.SHOW; } - @Override - protected void initialize() { - super.initialize(); - createUI(); - this.setMaximumSize(taskBarPanel.getPreferredSize()); - collapseListener = new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - TaskBarFrame.this.repaint(); - if (collapseAnimation != null) { - collapseAnimation.abort(); - } - initCollapseAnimations("expand"); - collapseAnimation.play(); - } - - @Override - public void mouseExited(MouseEvent e) { - TaskBarFrame.this.repaint(); - if(isVisible() && !withInPanel((JPanel)TaskBarFrame.this.getContentPane()) && !EResizeSpace) { - if (collapseAnimation != null) { - collapseAnimation.abort(); - } - initCollapseAnimations("collapse"); - collapseAnimation.play(); - } - } - }; - enableCollapseAnimation(); - } private void enableCollapseAnimation(){ this.setWidth(MIN_WIDTH); this.addMouseListener(collapseListener); @@ -113,13 +85,12 @@ protected void onLock() { @Override protected JPanel getPanelForPINSettings() { - disableCollapseAnimation(); - JPanel panel = componentsFactory.getTransparentPanel(); - panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); - JPanel labelPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - labelPanel.add(componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP,20f,"Task Bar")); - panel.add(labelPanel); - panel.setBackground(AppThemeColor.ADR_BG); + this.disableCollapseAnimation(); + JPanel panel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + JLabel textLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 22f, "Task Bar"); + textLabel.setHorizontalAlignment(SwingConstants.CENTER); + panel.add(textLabel); + panel.setPreferredSize(this.getPreferredSize()); return panel; } @@ -131,11 +102,11 @@ protected void registerDirectScaleHandler() { @Override protected void performScaling(Map scaleData) { this.componentsFactory.setScale(scaleData.get("taskbar")); - createUI(); + onViewInit(); } @Override - public void createUI() { + public void onViewInit() { JPanel panel = componentsFactory.getTransparentPanel(new BorderLayout()); taskBarPanel = new TaskBarPanel(new MercuryTaskBarController(),componentsFactory); panel.add(taskBarPanel, BorderLayout.CENTER); @@ -147,6 +118,32 @@ public void createUI() { this.MIN_WIDTH = taskBarPanel.getWidthOf(4); this.MAX_WIDTH = taskBarPanel.getPreferredSize().width; this.setWidth(MIN_WIDTH); + + this.setMaximumSize(taskBarPanel.getPreferredSize()); + this.collapseListener = new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + TaskBarFrame.this.repaint(); + if (collapseAnimation != null) { + collapseAnimation.abort(); + } + initCollapseAnimations("expand"); + collapseAnimation.play(); + } + + @Override + public void mouseExited(MouseEvent e) { + TaskBarFrame.this.repaint(); + if(isVisible() && !withInPanel((JPanel)TaskBarFrame.this.getContentPane()) && !EResizeSpace) { + if (collapseAnimation != null) { + collapseAnimation.abort(); + } + initCollapseAnimations("collapse"); + collapseAnimation.play(); + } + } + }; + this.enableCollapseAnimation(); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java deleted file mode 100644 index b869485c..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessageFrame.java +++ /dev/null @@ -1,775 +0,0 @@ -package com.mercury.platform.ui.frame.movable.container; - -import com.mercury.platform.core.ProdStarter; -import com.mercury.platform.shared.FrameVisibleState; -import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.NotificationDescriptor; -import com.mercury.platform.shared.entity.message.FlowDirections; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; -import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.components.panel.message.InMessagePanel; -import com.mercury.platform.ui.components.panel.message.MessagePanelController; -import com.mercury.platform.ui.components.panel.message.NotificationMessageController; -import com.mercury.platform.ui.components.panel.message.MessagePanelStyle; -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; -import com.mercury.platform.ui.misc.MercuryStoreUI; -import com.mercury.platform.ui.misc.TooltipConstants; - -import javax.swing.*; -import javax.swing.border.Border; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; -import java.util.stream.Collectors; - -public class MessageFrame extends AbstractMovableComponentFrame implements MessagesContainer { - private List currentMessages = new ArrayList<>(); - private PlainConfigurationService notificationConfig; - private boolean wasVisible; - private FlowDirections flowDirections; - private FlowDirections pikerDirection; - private boolean expanded = false; - private JPanel buffer; - private JSlider limitSlider; - private int limitMsgCount; - private JSlider unfoldSlider; - private int unfoldCount; - private int currentUnfoldCount; - - private ExpandAllFrame expandAllFrame; - - private boolean dnd = false; - public MessageFrame(){ - super(); - this.componentsFactory.setScale(this.scaleConfig.get("notification")); - this.stubComponentsFactory.setScale(this.scaleConfig.get("notification")); - this.notificationConfig = Configuration.get().notificationConfiguration(); - this.processSEResize = false; - this.flowDirections = this.notificationConfig.get().getFlowDirections(); - this.pikerDirection = this.notificationConfig.get().getFlowDirections(); - this.limitMsgCount = this.notificationConfig.get().getLimitCount(); - this.unfoldCount = this.notificationConfig.get().getUnfoldCount(); - this.currentUnfoldCount = 0; - this.expandAllFrame = new ExpandAllFrame(); - this.buffer = new JPanel(new FlowLayout(FlowLayout.CENTER)); - this.buffer.setMinimumSize(new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE)); - this.buffer.setBackground(AppThemeColor.TRANSPARENT); - } - - @Override - protected void initialize() { - super.initialize(); - this.createUI(); - } - - @Override - public void createUI() { - this.setBackground(AppThemeColor.TRANSPARENT); - this.getRootPane().setBorder(null); - if(this.currentMessages.size() > 0){ - this.currentMessages.forEach(panel -> this.mainContainer.add(panel)); - this.setVisible(true); - } - if(this.flowDirections.equals(FlowDirections.UPWARDS)){ - this.changeDirectionTo(FlowDirections.UPWARDS); - this.locationWasChanged = true; - this.changeLocation(); - } - this.expandAllFrame.init(); - } - - @Override - protected LayoutManager getFrameLayout() { - return new BoxLayout(mainContainer,BoxLayout.Y_AXIS); - } - - @Override - public void subscribe() { - MercuryStoreCore.dndSubject.subscribe(state -> { - this.dnd = state; - if(dnd){ - this.setVisible(false); - expandAllFrame.setVisible(false); - }else if(flowDirections.equals(FlowDirections.UPWARDS)){ - if(mainContainer.getComponentCount() > 1){ - this.setVisible(true); - setUpExpandButton(); - } - }else if(mainContainer.getComponentCount() > 0){ - this.setVisible(true); - setUpExpandButton(); - } - }); - MercuryStoreCore.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { - List collect = this.currentMessages.stream() - .filter(panel -> panel.getMessage().equals(message)) - .collect(Collectors.toList()); - if(collect.size() == 0) { - this.addMessage(message); - } - })); - MercuryStoreUI.closeMessage.subscribe(message -> { - List panels = this.currentMessages.stream() - .filter(panel -> panel.getMessage().equals(message)) - .collect(Collectors.toList()); - if(panels.size() > 0) { - InMessagePanel inMessagePanel = panels.get(0); - if (inMessagePanel.isExpanded()) { - this.currentUnfoldCount--; - if (this.currentUnfoldCount < 0) { - this.currentUnfoldCount = 0; - } - } - this.remove(inMessagePanel); - this.currentMessages.remove(inMessagePanel); - - if (this.currentMessages.size() == 0) { - this.setVisible(false); - } else if (this.currentMessages.size() >= this.limitMsgCount) { - if (this.currentMessages.size() == this.limitMsgCount) { - this.expandAllFrame.setVisible(false); - } - this.currentMessages.get(this.limitMsgCount - 1).setVisible(true); - this.expandAllFrame.decMessageCount(); - } - this.pack(); - this.repaint(); - this.setUpExpandButton(); - } - }); - MercuryStoreUI.expandMessageSubject.subscribe(state -> this.onExpandMessage()); - MercuryStoreUI.collapseMessageSubject.subscribe(state -> this.onCollapseMessage()); - } - - private void addMessage(Message message){ - MessagePanelStyle style = flowDirections.equals(FlowDirections.DOWNWARDS)? - MessagePanelStyle.IN_DOWNWARDS : MessagePanelStyle.IN_UPWARDS; - InMessagePanel inMessagePanel = new InMessagePanel( - message, - style, - new NotificationMessageController(message), - this.componentsFactory); - if (!dnd && !this.isVisible() && ProdStarter.APP_STATUS == FrameVisibleState.SHOW) { - this.showComponent(); - } else { - this.prevState = FrameVisibleState.SHOW; - } - if (flowDirections.equals(FlowDirections.UPWARDS)) { - this.mainContainer.add(inMessagePanel, 1); - } else { - this.mainContainer.add(inMessagePanel); - } - this.currentMessages.add(inMessagePanel); - this.pack(); - this.repaint(); - if (this.currentUnfoldCount < this.unfoldCount) { - inMessagePanel.expand(); - } - if(this.currentMessages.size() > this.limitMsgCount){ - if(!expanded) { - inMessagePanel.setVisible(false); - } - if(ProdStarter.APP_STATUS == FrameVisibleState.SHOW) { - this.setUpExpandButton(); - } - this.expandAllFrame.incMessageCount(); - } - } - - @Override - protected void changeVisible(FrameVisibleState state) { - super.changeVisible(state); - if(state.equals(FrameVisibleState.SHOW)) { - this.setUpExpandButton(); - } - } - - private void setUpExpandButton(){ - if(!inScaleSettings && !inMoveMode && !dnd) { - switch (flowDirections) { - case DOWNWARDS: { - if(this.mainContainer.getComponentCount() >= (limitMsgCount + 1)) { - if (this.mainContainer.getComponentCount() > limitMsgCount) { - Component[] components = mainContainer.getComponents(); - int height = 0; - for (int i = 0; i < limitMsgCount; i++) { - height += components[i].getPreferredSize().height; - } - this.expandAllFrame.setMinimumSize(new Dimension((int)(20 * componentsFactory.getScale()), height)); - this.expandAllFrame.setLocation(new Point(this.getLocation().x - expandAllFrame.getPreferredSize().width, - this.getLocation().y)); - this.expandAllFrame.pack(); - } - this.expandAllFrame.changeArrowDirection(); - this.expandAllFrame.setVisible(true); - } - break; - } - case UPWARDS: { - if(this.mainContainer.getComponentCount() >= (limitMsgCount + 2)) { - if (this.mainContainer.getComponentCount() > (limitMsgCount + 1)) { - Component[] components = mainContainer.getComponents(); - int height = 0; - for (int i = components.length - 1; i > components.length - (limitMsgCount + 1); i--) { - height += components[i].getPreferredSize().height; - } - Point location = mainContainer.getComponent(components.length - limitMsgCount).getLocationOnScreen(); - this.expandAllFrame.setMinimumSize(new Dimension((int)(20 * componentsFactory.getScale()), height)); - this.expandAllFrame.setLocation(new Point(this.getLocation().x - expandAllFrame.getPreferredSize().width, - location.y)); - this.expandAllFrame.pack(); - } - this.expandAllFrame.changeArrowDirection(); - this.expandAllFrame.setVisible(true); - } - break; - } - } - } - } - - @Override - protected JPanel getPanelForPINSettings() { - JPanel panel = componentsFactory.getTransparentPanel(new GridLayout(4,1)); - panel.setBackground(AppThemeColor.ADR_BG); - JPanel labelPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - labelPanel.setBackground(AppThemeColor.ADR_BG); - JLabel headerLabel = componentsFactory.getTextLabel( - FontStyle.BOLD, - this.notificationConfig.get().isNotificationEnable()?AppThemeColor.TEXT_MESSAGE:AppThemeColor.TEXT_DISABLE, - TextAlignment.CENTER, - 18f, - "Notification panel"); - labelPanel.add(headerLabel,BorderLayout.CENTER); - JButton enableButton = this.componentsFactory.getBorderedButton(this.notificationConfig.get().isNotificationEnable() ? "Switch-off" : "Switch-on"); - enableButton.addActionListener(action -> { - boolean notificationEnable = this.notificationConfig.get().isNotificationEnable(); - this.notificationConfig.get().setNotificationEnable(!notificationEnable); - if(this.notificationConfig.get().isNotificationEnable()){ - headerLabel.setForeground(AppThemeColor.TEXT_MESSAGE); - }else { - headerLabel.setForeground(AppThemeColor.TEXT_DISABLE); - } - enableButton.setText(!notificationEnable ? "Switch-off" : "Switch-on"); - MercuryStoreCore.saveConfigSubject.onNext(true); - }); - enableButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD,18f)); - enableButton.setPreferredSize(new Dimension(100,26)); - labelPanel.add(this.componentsFactory.wrapToSlide(enableButton,AppThemeColor.ADR_BG),BorderLayout.LINE_END); - panel.add(labelPanel); - JComboBox flowDirectionPicker = componentsFactory.getComboBox(new String[]{"Upwards", "Downwards"}); - flowDirectionPicker.setSelectedIndex(FlowDirections.valueOf(flowDirections.toString()).ordinal()); - flowDirectionPicker.addActionListener(e -> { - switch ((String)flowDirectionPicker.getSelectedItem()){ - case "Upwards":{ - pikerDirection = FlowDirections.UPWARDS; - break; - } - case "Downwards":{ - pikerDirection = FlowDirections.DOWNWARDS; - break; - } - } - }); - flowDirectionPicker.setSelectedIndex(flowDirections.ordinal()); - panel.add(componentsFactory.getSettingsPanel( - componentsFactory.getTextLabel("Flow direction:"),flowDirectionPicker)); - JLabel limitCount = componentsFactory.getTextLabel(String.valueOf(limitMsgCount)); - this.limitSlider = componentsFactory.getSlider(2, 20, limitMsgCount,AppThemeColor.ADR_BG); - this.limitSlider.addChangeListener(e -> { - limitCount.setText(String.valueOf(limitSlider.getValue())); - }); - panel.add(componentsFactory.getSliderSettingsPanel( - componentsFactory.getTextLabel("Pre-group limit:"), - limitCount, - limitSlider - )); - JLabel unfoldCount = componentsFactory.getTextLabel(String.valueOf(this.unfoldCount)); - this.unfoldSlider = componentsFactory.getSlider(0, 20, this.unfoldCount,AppThemeColor.ADR_BG); - this.unfoldSlider.addChangeListener(e -> { - unfoldCount.setText(String.valueOf(unfoldSlider.getValue())); - }); - panel.add(componentsFactory.getSliderSettingsPanel( - this.componentsFactory.getTextLabel("Unfold by default:"), - unfoldCount, - this.unfoldSlider - )); - panel.setPreferredSize(new Dimension((int)(400 * componentsFactory.getScale()), (int)(130*componentsFactory.getScale()))); - this.setMaximumSize(panel.getPreferredSize()); - return panel; - } - - private void onLimitCountChange(){ - this.expandAllFrame.resetMessageCount(); - Arrays.stream(mainContainer.getComponents()) - .forEach(component -> component.setVisible(true)); - this.currentMessages.stream().skip(this.limitMsgCount).forEach(panel -> { - panel.setVisible(false); - this.expandAllFrame.incMessageCount(); - }); - if(this.currentMessages.size() < this.limitMsgCount){ - this.expandAllFrame.setVisible(false); - } - } - - private void onExpandedCountChange(){ - this.currentUnfoldCount = 0; - this.currentMessages.forEach(InMessagePanel::collapse); - this.currentUnfoldCount = 0; - this.currentMessages.stream().limit(this.unfoldCount).forEach(panel -> { - panel.expand(); - this.currentUnfoldCount++; - }); - } - - @Override - public void setOpacity(float opacity) { - super.setOpacity(opacity); - this.expandAllFrame.setOpacity(opacity); - } - @Override - protected void onLock() { - this.expandAllFrame.setLocationState(LocationState.DEFAULT); - if(!this.flowDirections.equals(pikerDirection)){ - this.notificationConfig.get().setFlowDirections(this.pikerDirection); - this.changeDirectionTo(pikerDirection); - this.locationWasChanged = true; - } - if(this.limitMsgCount != this.limitSlider.getValue()) { - this.limitMsgCount = this.limitSlider.getValue(); - this.notificationConfig.get().setLimitCount(this.limitMsgCount); - this.onLimitCountChange(); - } - if(this.unfoldCount != this.unfoldSlider.getValue()) { - this.unfoldCount = this.unfoldSlider.getValue(); - this.notificationConfig.get().setUnfoldCount(this.unfoldCount); - this.onExpandedCountChange(); - } - MercuryStoreCore.saveConfigSubject.onNext(true); - this.changeLocation(); - super.onLock(); - this.setUpExpandButton(); - if(currentMessages.size() > 0){ - this.setVisible(true); - } - } - @Override - protected void onUnlock() { - super.onUnlock(); - this.setUpExpandButton(); - this.expandAllFrame.setLocationState(LocationState.MOVING); - } - - @Override - protected void onScaleLock() { - if(currentMessages.size() > 0){ - this.setVisible(true); - this.expandAllFrame.setScaleState(ScaleState.DEFAULT); - this.changeLocation(); - this.setUpExpandButton(); - this.pack(); - this.repaint(); - } - } - - @Override - protected void onScaleUnlock() { - if(currentMessages.size() > 0) { - this.setVisible(true); - } - this.expandAllFrame.setScaleState(ScaleState.ENABLE); - this.pack(); - this.repaint(); - } - - @Override - protected void onFrameDragged(Point location) { - super.onFrameDragged(location); - this.expandAllFrame.setLocation(location.x - expandAllFrame.getPreferredSize().width - 2,location.y); - } - - @Override - public void onLocationChange(Point location) { - super.onLocationChange(location); - if(this.expandAllFrame.isVisible()) { - this.expandAllFrame.setLocation(location.x - expandAllFrame.getPreferredSize().width - 2, location.y); - } - } - - private void changeDirectionTo(FlowDirections direction){ - this.wasVisible = isVisible(); - this.hideComponent(); - switch (direction) { - case DOWNWARDS:{ - this.mainContainer.remove(this.buffer); - Component[] components = this.mainContainer.getComponents(); - for (Component component : components) { - ((InMessagePanel) component).setStyle(MessagePanelStyle.IN_DOWNWARDS); - this.mainContainer.remove(component); - this.mainContainer.add(component, 0); - } - break; - } - case UPWARDS: { - this.mainContainer.add(buffer,0); - Component[] components = this.mainContainer.getComponents(); - for (int i = 1; i < components.length; i++) { - ((InMessagePanel) components[i]).setStyle(MessagePanelStyle.IN_UPWARDS); - this.mainContainer.remove(components[i]); - this.mainContainer.add(components[i], 1); - } - break; - } - } - if(this.wasVisible) { - this.showComponent(); - } - this.flowDirections = direction; - } - private void changeLocation(){ - this.wasVisible = isVisible(); - this.hideComponent(); - switch (flowDirections){ - case DOWNWARDS:{ - this.setLocation(this.framesConfig.get(this.getClass().getSimpleName()).getFrameLocation()); - break; - } - case UPWARDS:{ - if(this.locationWasChanged) { - int height = this.getLocation().y; - this.setLocation(this.getLocation().x, -1000); - this.setMinimumSize(new Dimension(this.getWidth(), height + 1000 + (int)(130*componentsFactory.getScale()))); - this.setMaximumSize(new Dimension(this.getWidth(), height + 1000 + (int)(130*componentsFactory.getScale()))); - this.locationWasChanged = false; - } - break; - } - } - if(this.wasVisible) { - this.showComponent(); - } - } - - @Override - protected Point getFrameLocation() { - if(this.flowDirections.equals(FlowDirections.UPWARDS)){ - return new Point(this.getLocationOnScreen().x,this.getLocationOnScreen().y + this.getHeight()); - } - return super.getFrameLocation(); - } - - @Override - public void onExpandMessage() { - this.pack(); - if(this.expandAllFrame.isVisible()) { - this.setUpExpandButton(); - } - this.currentUnfoldCount++; - } - - @Override - public void onCollapseMessage() { - this.pack(); - if(this.expandAllFrame.isVisible()) { - this.setUpExpandButton(); - } - this.currentUnfoldCount--; - } - - @Override - protected void performScaling(Map scaleData) { - this.wasVisible = isVisible(); - this.hideComponent(); - this.componentsFactory.setScale(scaleData.get("notification")); - this.currentMessages.forEach(panel -> { - panel.setComponentsFactory(this.componentsFactory); - panel.setStyle(panel.getStyle()); - }); - if(this.wasVisible) { - this.showComponent(); - } - this.expandAllFrame.processNewScale(); - this.changeLocation(); - this.setUpExpandButton(); - this.pack(); - this.repaint(); - } - - @Override - protected void registerDirectScaleHandler() { - MercuryStoreUI.notificationScaleSubject.subscribe(this::changeScale); - } - - @Override - protected JPanel defaultView(ComponentsFactory factory) { - ItemMessage message = new ItemMessage(); - message.setWhisperNickname("Example1"); - message.setItemName("Example example example"); - message.setCurrency("chaos"); - message.setCurCount(1000d); - message.setLeague("Standard"); - message.setOffer("Offer offer offer"); - - JPanel panel = factory.getTransparentPanel(); - panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); - panel.setBackground(AppThemeColor.FRAME); - MessagePanelController stubController = new MessagePanelController() { - @Override - public void performInvite() {} - @Override - public void performKick() {} - @Override - public void performOfferTrade() {} - @Override - public void performOpenChat() {} - @Override - public void performResponse(String responseText) {} - @Override - public void performHide() {} - @Override - public void showITH() {} - @Override - public void reloadMessage(InMessagePanel panel1) {} - }; - InMessagePanel inMessagePanel = new InMessagePanel(message, MessagePanelStyle.IN_DOWNWARDS, stubController, factory); - inMessagePanel.expand(); - panel.add(inMessagePanel); - return panel; - } - - private class ExpandAllFrame extends AbstractOverlaidFrame { - private int messageCount = 0; - private JLabel msgCountLabel; - private JButton expandButton; - private JPanel labelPanel; - private Container rootContainer; - private ExpandAllFrameConstraints prevContraints; - private boolean wasVisible; - - ExpandAllFrame() { - super(); - } - @Override - protected void initialize() { - this.rootContainer = this.getContentPane(); - this.componentsFactory = MessageFrame.this.componentsFactory; - this.setBackground(AppThemeColor.MSG_HEADER); - this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(1,1,1,0,AppThemeColor.TRANSPARENT), - BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.BORDER))); - - labelPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - labelPanel.setBackground(AppThemeColor.MSG_HEADER); - labelPanel.setPreferredSize(new Dimension((int)(10 * componentsFactory.getScale()),(int)(22 * componentsFactory.getScale()))); - labelPanel.setBorder(BorderFactory.createEmptyBorder(-4,0,0,0)); - msgCountLabel = componentsFactory.getTextLabel("+" + String.valueOf(messageCount)); - String iconPath = (flowDirections.equals(FlowDirections.DOWNWARDS))? "app/collapse-all.png" : "app/expand-all.png"; - expandButton = componentsFactory.getIconButton(iconPath,22,AppThemeColor.MSG_HEADER,""); - expandButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ - String iconPath; - if(!expanded){ - Arrays.stream(mainContainer.getComponents()).forEach(panel ->{ - if(!panel.isVisible()){ - panel.setVisible(true); - } - }); - if(flowDirections.equals(FlowDirections.DOWNWARDS)){ - iconPath = "app/expand-all.png"; - }else { - iconPath = "app/collapse-all.png"; - } - msgCountLabel.setText(""); - expanded = true; - }else { - if(flowDirections.equals(FlowDirections.DOWNWARDS)){ - iconPath = "app/collapse-all.png"; - }else { - iconPath = "app/expand-all.png"; - } - Component[] components = mainContainer.getComponents(); - if(flowDirections.equals(FlowDirections.UPWARDS)){ - for (int i = 1; i < mainContainer.getComponentCount() - limitMsgCount; i++) { - components[i].setVisible(false); - } - }else { - for (int i = 0; i < components.length; i++) { - if(i > (limitMsgCount-1)){ - components[i].setVisible(false); - } - } - } - msgCountLabel.setText("+"+String.valueOf(messageCount)); - expanded = false; - } - expandButton.setIcon(componentsFactory.getIcon(iconPath,22)); - MessageFrame.this.pack(); - } - } - }); - expandButton.setAlignmentY(SwingConstants.CENTER); - labelPanel.add(msgCountLabel); - if(flowDirections.equals(FlowDirections.DOWNWARDS)){ - rootContainer.add(expandButton,BorderLayout.CENTER); - rootContainer.add(labelPanel,BorderLayout.PAGE_END); - }else { - rootContainer.add(labelPanel, BorderLayout.PAGE_START); - rootContainer.add(expandButton, BorderLayout.CENTER); - } - this.pack(); - } - void processNewScale(){ - labelPanel.setPreferredSize(new Dimension((int)(10 * componentsFactory.getScale()),(int)(22 * componentsFactory.getScale()))); - msgCountLabel.setFont(componentsFactory.getFont(FontStyle.BOLD,15f)); - changeArrowDirection(); - } - - void incMessageCount(){ - messageCount++; - if(!expanded) { - msgCountLabel.setText("+" + String.valueOf(messageCount)); - rootContainer.repaint(); - } - - } - void decMessageCount(){ - messageCount--; - if(!expanded) { - msgCountLabel.setText("+" + String.valueOf(messageCount)); - rootContainer.repaint(); - } - } - void resetMessageCount(){ - messageCount = 0; - } - void changeArrowDirection(){ - String iconPath = ""; - if(flowDirections.equals(FlowDirections.DOWNWARDS)){ - if(!expanded){ - iconPath = "app/collapse-all.png"; - }else { - iconPath = "app/expand-all.png"; - } - }else { - if(!expanded){ - iconPath = "app/expand-all.png"; - }else { - iconPath = "app/collapse-all.png"; - } - } - expandButton.setIcon(componentsFactory.getIcon(iconPath,22)); - rootContainer.remove(labelPanel); - if(pikerDirection.equals(FlowDirections.DOWNWARDS)){ - rootContainer.add(labelPanel,BorderLayout.PAGE_END); - }else { - rootContainer.add(labelPanel, BorderLayout.PAGE_START); - } - this.pack(); - } - @Override - public void subscribe() { - - } - - void setLocationState(LocationState state){ - switch (state){ - case DEFAULT:{ - toDefaultState(); - break; - } - case MOVING:{ - prevContraints = new ExpandAllFrameConstraints( - this.isVisible(), - this.getRootPane().getBorder(), - this.getBackground() - ); - this.getRootPane().setBorder(null); - this.setBackground(AppThemeColor.FRAME); - this.setMinimumSize(null); - this.setVisible(true); - JPanel panel = componentsFactory.getTransparentPanel(new BorderLayout()); - panel.setBackground(AppThemeColor.ADR_BG); - panel.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); - JLabel infoLabel = componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_DEFAULT,TextAlignment.LEFTOP,29f,"?"); - infoLabel.setOpaque(true); - infoLabel.setBackground(AppThemeColor.ADR_BG); - infoLabel.setBorder(BorderFactory.createEmptyBorder(0,3,0,0)); - infoLabel.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - MercuryStoreCore.tooltipSubject.onNext(TooltipConstants.NOTIFICATION_SETTINGS); - } - - @Override - public void mouseExited(MouseEvent e) { - MercuryStoreCore.tooltipSubject.onNext(null); - } - }); - panel.add(infoLabel,BorderLayout.CENTER); - panel.setPreferredSize(new Dimension(this.getPreferredSize().width,MessageFrame.this.getPreferredSize().height)); - this.setLocation(MessageFrame.this.getLocation().x - this.getPreferredSize().width - 2, MessageFrame.this.getLocation().y); - this.setContentPane(panel); - this.pack(); - break; - } - } - } - private void toDefaultState(){ - this.setContentPane(rootContainer); - this.setVisible(prevContraints.visible); - this.getRootPane().setBorder(prevContraints.border); - this.setBackground(prevContraints.bgColor); - prevContraints = null; - setUpExpandButton(); - this.pack(); - } - - void setScaleState(ScaleState state){ - switch (state){ - case DEFAULT: { - toDefaultState(); - break; - } - case ENABLE:{ - prevContraints = new ExpandAllFrameConstraints( - this.isVisible(), - this.getRootPane().getBorder(), - this.getBackground() - ); - this.setVisible(false); - break; - } - } - } - - @Override - protected LayoutManager getFrameLayout() { - return new BorderLayout(); - } - - private class ExpandAllFrameConstraints { - private boolean visible; - private Border border; - private Color bgColor; - - public ExpandAllFrameConstraints(boolean visible, Border border, Color bgColor) { - this.visible = visible; - this.border = border; - this.bgColor = bgColor; - } - } - } -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessagesContainer.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessagesContainer.java deleted file mode 100644 index f512976e..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/container/MessagesContainer.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mercury.platform.ui.frame.movable.container; - -/** - * Created by Константин on 25.02.2017. - */ -public interface MessagesContainer { - void onExpandMessage(); - void onCollapseMessage(); -} 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 d158ee04..47c61b5f 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 @@ -17,6 +17,9 @@ public AlertFrame() { @Override protected void initialize() { this.getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); + } + @Override + public void onViewInit() { JPanel messagePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); messageLabel = componentsFactory.getTextLabel(""); messagePanel.add(messageLabel); 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 96109dee..83428987 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 @@ -16,19 +16,45 @@ public class MercuryLoadingFrame extends AbstractOverlaidFrame { private MercuryLoading loadingTracker; public MercuryLoadingFrame() { super(); - this.setOpacity(0f); - this.setBackground(AppThemeColor.TRANSPARENT); processingHideEvent = false; } @Override protected void initialize() { + this.setOpacity(0f); + this.setBackground(AppThemeColor.TRANSPARENT); + } + + @Override + public void subscribe() { + MercuryStoreCore.appLoadingSubject + .subscribe(state -> { + hideAnimation.play(); + }); + MercuryStoreCore.errorHandlerSubject.subscribe(error -> { + this.loadingTracker.abort(); + }); + } + + @Override + public void showComponent() { + super.showComponent(); + showAnimation.play(); + } + + @Override + protected LayoutManager getFrameLayout() { + return new FlowLayout(); + } + + @Override + public void onViewInit() { this.loadingTracker = new MercuryLoading(); this.loadingTracker.setSwapEnable(true); this.loadingTracker.setLoadingUI(new MercuryAppLoadingUI(this.loadingTracker)); this.loadingTracker.playLoop(); this.loadingTracker.setForeground(AppThemeColor.ADR_FOOTER_BG); - this.loadingTracker.setBackground(AppThemeColor.BORDER_DARK); + this.loadingTracker.setBackground(AppThemeColor.BORDER_GREEN); this.loadingTracker.setPreferredSize(new Dimension(200,200)); hideAnimation = new Timeline(this); hideAnimation.setDuration(400); @@ -55,26 +81,4 @@ public void onTimelinePulse(float durationFraction, float timelinePosition) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); } - - @Override - public void subscribe() { - MercuryStoreCore.appLoadingSubject - .subscribe(state -> { - hideAnimation.play(); - }); - MercuryStoreCore.errorHandlerSubject.subscribe(error -> { - this.loadingTracker.abort(); - }); - } - - @Override - public void showComponent() { - super.showComponent(); - showAnimation.play(); - } - - @Override - protected LayoutManager getFrameLayout() { - return new FlowLayout(); - } } 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/NotificationAlertFrame.java similarity index 64% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationAlertFrame.java index dfe8b2fb..dad36168 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/NotificationAlertFrame.java @@ -11,50 +11,30 @@ import javax.swing.*; import java.awt.*; -public class NotificationFrame extends AbstractOverlaidFrame { +public class NotificationAlertFrame extends AbstractOverlaidFrame { private JLabel messageLabel; private Timeline showAnimation; - public NotificationFrame() { + public NotificationAlertFrame() { super(); - this.setOpacity(0.9f); - this.setBackground(AppThemeColor.TRANSPARENT); } @Override protected void initialize() { - messageLabel = componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER,38,""); - - showAnimation = new Timeline(this); - showAnimation.setDuration(1400); - showAnimation.addPropertyToInterpolate("opacity", 0.9f, 0f); - showAnimation.addCallback(new TimelineCallback() { - @Override - public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { - if(newState.equals(Timeline.TimelineState.DONE)){ - NotificationFrame.this.setAlwaysOnTop(false); - NotificationFrame.this.setVisible(false); - NotificationFrame.this.setOpacity(0.9f); - messageLabel.setText(""); - } - } - @Override - public void onTimelinePulse(float durationFraction, float timelinePosition) { - } - }); - this.add(messageLabel); + this.setOpacity(0.9f); + this.setBackground(AppThemeColor.TRANSPARENT); } @Override public void subscribe() { - MercuryStoreCore.notificationSubject.subscribe(message -> { - messageLabel.setText(message); + MercuryStoreCore.alertSubject.subscribe(message -> { + this.messageLabel.setText(message); this.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); this.setAlwaysOnTop(true); this.setVisible(true); - showAnimation.abort(); - showAnimation.play(); + this.showAnimation.abort(); + this.showAnimation.play(); }); } @@ -62,4 +42,28 @@ public void subscribe() { protected LayoutManager getFrameLayout() { return new FlowLayout(); } + + @Override + public void onViewInit() { + this.messageLabel = componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER,38,""); + + this.showAnimation = new Timeline(this); + this.showAnimation.setDuration(1400); + this.showAnimation.addPropertyToInterpolate("opacity", 0.9f, 0f); + this.showAnimation.addCallback(new TimelineCallback() { + @Override + public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { + if(newState.equals(Timeline.TimelineState.DONE)){ + NotificationAlertFrame.this.setAlwaysOnTop(false); + NotificationAlertFrame.this.setVisible(false); + NotificationAlertFrame.this.setOpacity(0.9f); + messageLabel.setText(""); + } + } + @Override + public void onTimelinePulse(float durationFraction, float timelinePosition) { + } + }); + this.add(messageLabel); + } } 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 deleted file mode 100644 index e4e7f9bb..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/OutMessageFrame.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.mercury.platform.ui.frame.other; - -import com.mercury.platform.core.ProdStarter; -import com.mercury.platform.shared.FrameVisibleState; -import com.mercury.platform.shared.entity.message.CurrencyMessage; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; -import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.frame.AbstractComponentFrame; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -/** - * Created by Константин on 12.01.2017. - */ -public class OutMessageFrame extends AbstractComponentFrame { - public OutMessageFrame() { - super(); - } - - private void addNewMessage(Message message){ - JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); - root.setBackground(AppThemeColor.HEADER); - root.setBorder(BorderFactory.createEmptyBorder(-10,0,-10,0)); - JLabel whisperLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,15f,message.getWhisperNickname() + ":"); - whisperLabel.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - x = e.getX(); - y = e.getY(); - } - }); -// whisperLabel.addMouseMotionListener(new MouseAdapter() { -// @Override -// public void mouseDragged(MouseEvent e) { -// OutMessageFrame.this.setLocation(e.getLocationOnScreen().x -x,e.getLocationOnScreen().y -y); -// configManager.saveFrameLocation(OutMessageFrame.this.getClass().getSimpleName(),OutMessageFrame.this.getLocation()); -// } -// }); - - JPanel interactionPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - JPanel miscPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - miscPanel.add(componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 17f, "=>")); - if(message.getCurrency() != null) { - miscPanel.add(getCurCountPanel(message.getCurCount(),message.getCurrency())); - } - if(message instanceof CurrencyMessage){ - CurrencyMessage msg = (CurrencyMessage) message; - JPanel curCountPanel = getCurCountPanel(msg.getCurrForSaleCount(), msg.getCurrForSaleTitle()); - curCountPanel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0)); - interactionPanel.add(curCountPanel,BorderLayout.CENTER); - }else { - JLabel itemLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_IMPORTANT, TextAlignment.CENTER, 16f, ((ItemMessage)message).getItemName()); - interactionPanel.add(itemLabel,BorderLayout.CENTER); - } - JButton hoIn = componentsFactory.getIconButton("app/hideout-in.png", 16, AppThemeColor.HEADER, TooltipConstants.HO_IN); - hoIn.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - MercuryStoreCore.chatCommandSubject.onNext("/hideout " + message.getWhisperNickname()); - } - }); - miscPanel.add(hoIn); - JButton hoOut = componentsFactory.getIconButton("app/hideout-out.png", 16, AppThemeColor.HEADER, TooltipConstants.HO_OUT); - hoOut.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - MercuryStoreCore.chatCommandSubject.onNext("/hideout"); - } - }); - miscPanel.add(hoOut); - JButton hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.HEADER,TooltipConstants.HIDE_PANEL); - hideButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - OutMessageFrame.this.getContentPane().remove(root); - OutMessageFrame.this.pack(); - if(OutMessageFrame.this.getContentPane().getComponentCount() == 0){ - OutMessageFrame.this.setAlwaysOnTop(false); - OutMessageFrame.this.setVisible(false); - } - } - }); - miscPanel.add(hideButton); - - interactionPanel.add(miscPanel,BorderLayout.LINE_END); - root.add(interactionPanel,BorderLayout.LINE_END); - root.add(whisperLabel,BorderLayout.CENTER); - - this.add(root); - pack(); - } - - private JPanel getCurCountPanel(Double curCount, String currency){ - JPanel curCountPanel = new JPanel(); - curCountPanel.setPreferredSize(new Dimension(30,20)); - curCountPanel.setBackground(AppThemeColor.TRANSPARENT); - curCountPanel.setBorder(BorderFactory.createEmptyBorder(-8,0,-8,0)); - - JLabel priceLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.CENTER, 17f, String.valueOf(curCount)); - curCountPanel.add(priceLabel); - JLabel currencyLabel; - //todo - currencyLabel = componentsFactory.getIconLabel("currency/" + currency + ".png", 26); - JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - curPanel.setBackground(AppThemeColor.TRANSPARENT); - curPanel.add(curCountPanel); - curPanel.add(currencyLabel); - curPanel.setBorder(BorderFactory.createMatteBorder(4,0,0,0,AppThemeColor.TRANSPARENT)); - return curPanel; - } - @Override - public void subscribe() { - MercuryStoreCore.outMessageSubject.subscribe(message -> { - if (!this.isVisible() && ProdStarter.APP_STATUS == FrameVisibleState.SHOW) { - this.setAlwaysOnTop(true); - this.setVisible(true); - } else { - prevState = FrameVisibleState.SHOW; - } - addNewMessage(message); - }); - } - - @Override - protected LayoutManager getFrameLayout() { - return new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS); - } - - -} 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 f78b545d..27cb3e77 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 @@ -19,6 +19,10 @@ protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); + } + + @Override + public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,0,6)); 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 d4550666..174f6ea9 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 @@ -25,8 +25,11 @@ protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); - this.scaleData = this.scaleConfig.getMap(); + } + + @Override + public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,0,6)); @@ -182,4 +185,5 @@ public void subscribe() { protected LayoutManager getFrameLayout() { return new BorderLayout(); } + } 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 578bae17..b9bf6b10 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 @@ -13,10 +13,6 @@ public class TooltipFrame extends AbstractOverlaidFrame { private Timer tooltipTimer; public TooltipFrame() { super(); - this.setOpacity(this.applicationConfig.get().getMaxOpacity()/100f); - this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2))); } @Override @@ -73,4 +69,12 @@ public void subscribe() { protected LayoutManager getFrameLayout() { return new BorderLayout(); } + + @Override + public void onViewInit() { + this.setOpacity(this.applicationConfig.get().getMaxOpacity()/100f); + this.getRootPane().setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2))); + } } 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 6ab2d8d3..46d4f805 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 @@ -24,6 +24,9 @@ protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); + } + @Override + public void onViewInit() { this.add(getUpdatePanel()); this.setOpacity(this.applicationConfig.get().getMaxOpacity()/100f); this.pack(); @@ -95,5 +98,4 @@ public void subscribe() { protected LayoutManager getFrameLayout() { return new FlowLayout(FlowLayout.LEFT); } - } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java index cb0fb25f..ed307257 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/AbstractTitledComponentFrame.java @@ -15,7 +15,6 @@ public abstract class AbstractTitledComponentFrame extends AbstractComponentFram private JLabel frameTitleLabel; protected AbstractTitledComponentFrame() { super(); - this.miscPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); } @Override @@ -42,18 +41,12 @@ private void initHeaderPanel(){ this.headerPanel.add(appIcon,BorderLayout.LINE_START); this.headerPanel.add(this.frameTitleLabel, BorderLayout.CENTER); - this.miscPanel.setBackground(AppThemeColor.TRANSPARENT); - this.hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.FRAME_ALPHA, ""); - this.hideButton.setBorder(BorderFactory.createEmptyBorder(0,0,0,2)); - this.hideButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { - hideComponent(); - } - } + this.miscPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.HEADER); + this.hideButton = componentsFactory.getIconButton("app/close.png", 14, AppThemeColor.HEADER, ""); + this.hideButton.addActionListener(action -> { + this.hideComponent(); }); - this.miscPanel.add(hideButton); + this.miscPanel.add(hideButton,BorderLayout.LINE_END); this.headerPanel.add(miscPanel, BorderLayout.LINE_END); this.add(headerPanel, BorderLayout.PAGE_START); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/ChatScannerFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/ChatScannerFrame.java new file mode 100644 index 00000000..a575b510 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/ChatScannerFrame.java @@ -0,0 +1,234 @@ +package com.mercury.platform.ui.frame.titled; + +import com.mercury.platform.core.misc.SoundType; +import com.mercury.platform.core.utils.interceptor.MessageInterceptor; +import com.mercury.platform.core.utils.interceptor.filter.MessageFilter; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; +import com.mercury.platform.shared.config.descriptor.ScannerDescriptor; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.panel.chat.HtmlMessageBuilder; +import com.mercury.platform.ui.misc.AppThemeColor; +import net.jodah.expiringmap.ExpiringMap; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.util.*; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ChatScannerFrame extends AbstractTitledComponentFrame { + private PlainConfigurationService scannerService; + private PlainConfigurationService notificationConfig; + private MessageInterceptor currentInterceptor; + private Map expiresMessages; + private HtmlMessageBuilder messageBuilder; + private boolean running; + + public ChatScannerFrame() { + super(); + this.processingHideEvent = false; + this.setFocusableWindowState(true); + this.setFocusable(true); + this.setAlwaysOnTop(false); + } + + @Override + public void onViewInit() { + this.scannerService = Configuration.get().scannerConfiguration(); + this.notificationConfig = Configuration.get().notificationConfiguration(); + this.expiresMessages = ExpiringMap.builder() + .expiration(10, TimeUnit.SECONDS) + .build(); + this.messageBuilder = new HtmlMessageBuilder(); + this.initHeaderBar(); + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + JPanel setupArea = componentsFactory.getTransparentPanel(new BorderLayout()); + setupArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + + JLabel title = componentsFactory.getTextLabel( + FontStyle.REGULAR, + AppThemeColor.TEXT_DEFAULT, + TextAlignment.LEFTOP, + 15f, + "Show messages containing the following words:"); + title.setBorder(BorderFactory.createEmptyBorder(2,0,6,0)); + JTextArea words = componentsFactory.getSimpleTextArea(this.scannerService.get().getWords()); + words.setEditable(true); + words.setCaretColor(AppThemeColor.TEXT_DEFAULT); + words.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); + words.setBackground(AppThemeColor.SLIDE_BG); + + JPanel navBar = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER),AppThemeColor.FRAME); + Dimension buttonSize = new Dimension(90, 24); + JButton save = componentsFactory.getBorderedButton("Save"); + save.addActionListener(action -> { + this.scannerService.get().setWords(words.getText()); + MercuryStoreCore.saveConfigSubject.onNext(true); + + String[] split = words.getText().split(","); + this.performNewStrings(split); + this.hideComponent(); + }); + JButton cancel = componentsFactory.getBorderedButton("Cancel"); + cancel.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.BORDER), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3) + )); + cancel.setBackground(AppThemeColor.FRAME); + cancel.addActionListener(action -> { + hideComponent(); + }); + save.setPreferredSize(buttonSize); + cancel.setPreferredSize(buttonSize); + navBar.add(cancel); + navBar.add(save); + + setupArea.add(title,BorderLayout.PAGE_START); + setupArea.add(words,BorderLayout.CENTER); + + root.add(setupArea,BorderLayout.CENTER); + root.add(getMemo(),BorderLayout.LINE_END); + + this.add(root,BorderLayout.CENTER); + this.add(navBar,BorderLayout.PAGE_END); + this.pack(); + } + + private void initHeaderBar(){ + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 0, 4, 0),AppThemeColor.HEADER); + JLabel statusLabel = componentsFactory.getTextLabel( + FontStyle.BOLD, + AppThemeColor.TEXT_DEFAULT, + TextAlignment.LEFTOP, + 16f, + "Status: stopped"); + + JButton processButton = componentsFactory.getBorderedButton("Start"); + processButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD,16f)); + processButton.setPreferredSize(new Dimension(80,20)); + processButton.addActionListener(action -> { + if(this.running){ + this.running = false; + processButton.setText("Start"); + statusLabel.setText("Status: stopped"); + if (this.currentInterceptor != null) { + MercuryStoreCore.removeInterceptorSubject.onNext(this.currentInterceptor); + } + }else { + this.running = true; + processButton.setText("Stop"); + statusLabel.setText("Status: running"); + this.performNewStrings(this.scannerService.get().getWords().split(",")); + } + }); + root.add(statusLabel); + root.add(processButton); + this.miscPanel.add(root,BorderLayout.CENTER); + } + private void performNewStrings(String[] strings){ + if(this.running) { + List contains = new ArrayList<>(); + List notContains = new ArrayList<>(); + + Arrays.stream(strings).forEach(str -> { + str = str.toLowerCase().trim(); + if (!str.isEmpty()) { + if (str.contains("!")) { + notContains.add(str.replace("!", "")); + } else { + contains.add(str); + } + } + }); + if (this.currentInterceptor != null) { + MercuryStoreCore.removeInterceptorSubject.onNext(this.currentInterceptor); + } + this.currentInterceptor = new MessageInterceptor() { + @Override + protected void process(String stubMessage) { + messageBuilder.setChunkStrings(Arrays.asList(strings)); + String message = StringUtils.substringAfter(stubMessage, "] $"); + if (message.isEmpty()) { + message = StringUtils.substringAfter(stubMessage, "] #"); + } + if (!message.isEmpty()) { + Pattern pattern = Pattern.compile("^(\\<.+?\\>)?\\s?(.+?):(.+)$"); + Matcher matcher = pattern.matcher(message); + if (matcher.find() && !expiresMessages.containsValue(message)) { + PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); + descriptor.setNickName(matcher.group(2)); + descriptor.setMessage(messageBuilder.build(matcher.group(3))); + + expiresMessages.put(descriptor.getNickName(), message); + if(notificationConfig.get().isScannerNotificationEnable()) { + MercuryStoreCore.newScannerMessageSubject.onNext(descriptor); + } + MercuryStoreCore.soundSubject.onNext(SoundType.CHAT_SCANNER); + } + } + } + + @Override + protected MessageFilter getFilter() { + return message -> { + if (!message.contains("] $") && !message.contains("] #")) { + return false; + } + message = StringUtils.substringAfter(message, ":").toLowerCase(); + return notContains.stream().noneMatch(message::contains) + && contains.stream().anyMatch(message::contains); + }; + } + }; + MercuryStoreCore.addInterceptorSubject.onNext(this.currentInterceptor); + } + } + + @Override + protected void initialize() { + super.initialize(); + this.setPreferredSize(new Dimension(350,300)); + } + + private JPanel getMemo(){ + JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); + JLabel title = componentsFactory.getTextLabel( + "Memo:", + FontStyle.REGULAR); + title.setBorder(BorderFactory.createEmptyBorder(6,0,2,0)); + + + JPanel itemsPanel = componentsFactory.getTransparentPanel(); + itemsPanel.setLayout(new BoxLayout(itemsPanel,BoxLayout.Y_AXIS)); + + itemsPanel.add(componentsFactory.getTextLabel("not case sensitive",FontStyle.REGULAR,17)); + itemsPanel.add(componentsFactory.getTextLabel("! - NOT (!wtb,!wts)",FontStyle.REGULAR,17)); + itemsPanel.add(componentsFactory.getTextLabel(", - separator",FontStyle.REGULAR,17)); + root.add(title,BorderLayout.PAGE_START); + root.add(itemsPanel,BorderLayout.CENTER); + return root; + } + + @Override + protected String getFrameTitle() { + return "Chat scanner"; + } + + @Override + public void subscribe() { + + } + + @Override + protected LayoutManager getFrameLayout() { + return new BorderLayout(); + } +} 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 8f749af8..e39d87af 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 @@ -29,8 +29,7 @@ public GamePathChooser() { } @Override - protected void initialize() { - super.initialize(); + public void onViewInit() { this.removeHideButton(); this.add(getChooserPanel(),BorderLayout.CENTER); this.add(getMiscPanel(),BorderLayout.PAGE_END); 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/HistoryFrame.java similarity index 52% rename from app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryFrame.java rename to app-ui/src/main/java/com/mercury/platform/ui/frame/titled/HistoryFrame.java index b495a9be..dc6b149e 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/HistoryFrame.java @@ -1,39 +1,41 @@ -package com.mercury.platform.ui.frame.titled.container; +package com.mercury.platform.ui.frame.titled; import com.mercury.platform.shared.HistoryManager; import com.mercury.platform.shared.MessageParser; import com.mercury.platform.shared.config.descriptor.FrameDescriptor; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; -import com.mercury.platform.ui.components.panel.message.InMessagePanel; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; -import com.mercury.platform.ui.components.panel.message.NotificationMessageController; -import com.mercury.platform.ui.components.panel.message.MessagePanelStyle; -import com.mercury.platform.ui.frame.titled.AbstractTitledComponentFrame; +import com.mercury.platform.ui.components.panel.notification.NotificationPanel; +import com.mercury.platform.ui.components.panel.notification.factory.NotificationPanelFactory; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; import org.apache.commons.lang3.ArrayUtils; import javax.swing.*; import java.awt.*; import java.awt.event.*; +import java.util.*; +import java.util.List; -public class HistoryFrame extends AbstractTitledComponentFrame implements HistoryContainer { +public class HistoryFrame extends AbstractTitledComponentFrame{ private JPanel mainContainer; + private NotificationPanelFactory factory; + private List currentMessages; public HistoryFrame() { super(); FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); this.setPreferredSize(frameDescriptor.getFrameSize()); this.componentsFactory.setScale(this.scaleConfig.get("other")); } - @Override - protected void initialize() { - super.initialize(); + public void onViewInit() { + this.factory = new NotificationPanelFactory(); + this.currentMessages = new ArrayList<>(); this.mainContainer = new VerticalScrollContainer(); - this.mainContainer.setBackground(AppThemeColor.TRANSPARENT); + this.mainContainer.setBackground(AppThemeColor.FRAME); this.mainContainer.setLayout(new BoxLayout(this.mainContainer,BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(this.mainContainer); @@ -50,27 +52,26 @@ public void mouseWheelMoved(MouseWheelEvent e) { JScrollBar vBar = scrollPane.getVerticalScrollBar(); vBar.setBackground(AppThemeColor.SLIDE_BG); vBar.setUI(new MercuryScrollBarUI()); - vBar.setPreferredSize(new Dimension(14, Integer.MAX_VALUE)); + vBar.setPreferredSize(new Dimension(16, Integer.MAX_VALUE)); vBar.setUnitIncrement(3); vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,2)); vBar.addAdjustmentListener(e -> repaint()); this.add(scrollPane,BorderLayout.CENTER); - mainContainer.getParent().setBackground(AppThemeColor.TRANSPARENT); + mainContainer.getParent().setBackground(AppThemeColor.FRAME); String[] messages = HistoryManager.INSTANCE.fetchNext(10); ArrayUtils.reverse(messages); for (String message : messages) { MessageParser parser = new MessageParser(); - Message parsedMessage = parser.parse(message); - if(parsedMessage != null) { - InMessagePanel inMessagePanel = new InMessagePanel( - parsedMessage, - MessagePanelStyle.HISTORY, - new NotificationMessageController(parsedMessage), - this.componentsFactory); - inMessagePanel.disableTime(); - mainContainer.add(inMessagePanel); + NotificationDescriptor parsedNotificationDescriptor = parser.parse(message); + if(parsedNotificationDescriptor != null) { + NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) + .setData(parsedNotificationDescriptor) + .setComponentsFactory(this.componentsFactory) + .build(); + this.currentMessages.add(parsedNotificationDescriptor); + mainContainer.add(panel); } } this.miscPanel.add(getClearButton(),0); @@ -81,15 +82,14 @@ public void mouseWheelMoved(MouseWheelEvent e) { String[] nextMessages = HistoryManager.INSTANCE.fetchNext(5); for (String message : nextMessages) { MessageParser parser = new MessageParser(); - Message parsedMessage = parser.parse(message); - if(parsedMessage != null) { - InMessagePanel inMessagePanel = new InMessagePanel( - parsedMessage, - MessagePanelStyle.HISTORY, - new NotificationMessageController(parsedMessage), - this.componentsFactory); - inMessagePanel.disableTime(); - this.mainContainer.add(inMessagePanel, 0); + NotificationDescriptor parsedNotificationDescriptor = parser.parse(message); + if(parsedNotificationDescriptor != null) { + NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) + .setData(parsedNotificationDescriptor) + .setComponentsFactory(this.componentsFactory) + .build(); + this.currentMessages.add(parsedNotificationDescriptor); + mainContainer.add(panel,0); } vBar.setValue(vBar.getValue() + 100); } @@ -100,18 +100,13 @@ private JButton getClearButton(){ JButton clearHistory = componentsFactory.getIconButton("app/clear-history.png", 13, - AppThemeColor.TRANSPARENT, + AppThemeColor.HEADER, "Clear history"); - clearHistory.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - HistoryManager.INSTANCE.clear(); - mainContainer.removeAll(); - pack(); - repaint(); - } + clearHistory.addActionListener(action -> { + HistoryManager.INSTANCE.clear(); + this.mainContainer.removeAll(); + this.pack(); }); - clearHistory.setBorder(BorderFactory.createEmptyBorder(0,0,0,10)); return clearHistory; } @@ -122,18 +117,19 @@ protected String getFrameTitle() { @Override public void subscribe() { - MercuryStoreCore.messageSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { - HistoryManager.INSTANCE.add(message); - InMessagePanel inMessagePanel = new InMessagePanel( - message, - MessagePanelStyle.HISTORY, - new NotificationMessageController(message), - this.componentsFactory); - this.mainContainer.add(inMessagePanel); - this.trimContainer(); - this.pack(); + MercuryStoreCore.newNotificationSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { + if(!currentMessages.contains(message)) { + HistoryManager.INSTANCE.add(message); + NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) + .setData(message) + .setComponentsFactory(this.componentsFactory) + .build(); + mainContainer.add(panel); + this.currentMessages.add(message); + this.trimContainer(); + this.pack(); + } })); - MercuryStoreUI.reloadMessageSubject.subscribe(this::onReloadMessage); } private void trimContainer(){ if(mainContainer.getComponentCount() > 40){ @@ -143,12 +139,4 @@ private void trimContainer(){ this.pack(); } } - - @Override - public void onReloadMessage(InMessagePanel inMessagePanel) { - inMessagePanel.setStyle(MessagePanelStyle.RELOADED); - inMessagePanel.setPreferredSize(new Dimension(this.getWidth()-10, inMessagePanel.getPreferredSize().height)); - this.pack(); - this.repaint(); - } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/NotesFrame.java index db31b8be..b234f17d 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 @@ -42,10 +42,8 @@ public NotesFrame(List notes, NotesType type) { } } } - @Override - protected void initialize() { - super.initialize(); + public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); @@ -53,9 +51,12 @@ protected void initialize() { rootPanel.add(contentPanel,BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - showOnStartUp = new JCheckBox(); - showOnStartUp.setBackground(AppThemeColor.TRANSPARENT); - showOnStartUp.setSelected(this.applicationConfig.get().isShowOnStartUp()); + this.showOnStartUp = new JCheckBox(); + this.showOnStartUp.setBackground(AppThemeColor.TRANSPARENT); + this.showOnStartUp.setSelected(this.applicationConfig.get().isShowOnStartUp()); + this.showOnStartUp.addActionListener(action -> { + this.applicationConfig.get().setShowOnStartUp(showOnStartUp.isSelected()); + }); JPanel showOnStartPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); showOnStartPanel.add(showOnStartUp); @@ -92,7 +93,7 @@ private JPanel getNavBar(){ JButton donate = componentsFactory.getBorderedButton("Donate"); donate.addActionListener(action -> { 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")); + Desktop.getDesktop().browse(new URI("https://www.paypal.me/mercurytrade")); } catch (Exception e1) { e1.printStackTrace(); } @@ -148,12 +149,11 @@ public void mousePressed(MouseEvent e) { if(SwingUtilities.isLeftMouseButton(e)) { NotesFrame.this.setVisible(false); if (type.equals(NotesType.INFO)) { - applicationConfig.get().setShowOnStartUp(showOnStartUp.isSelected()); - MercuryStoreCore.saveConfigSubject.onNext(true); FramesManager.INSTANCE.enableMovementExclude(ItemsGridFrame.class); } prevState = FrameVisibleState.HIDE; } + MercuryStoreCore.saveConfigSubject.onNext(true); } }); close.setBackground(AppThemeColor.FRAME); @@ -267,10 +267,6 @@ private ProgressBarFrame() { protected void initialize() { this.setMinimumSize(new Dimension(310, 60)); this.getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); - this.add(getProgressBarPanel(),BorderLayout.CENTER); - this.pack(); - Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); } private JPanel getProgressBarPanel() { @@ -323,5 +319,13 @@ public void subscribe() { protected LayoutManager getFrameLayout() { return new BorderLayout(); } + + @Override + public void onViewInit() { + this.add(getProgressBarPanel(),BorderLayout.CENTER); + this.pack(); + Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); + this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); + } } } 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 b52eaa19..fb02afdc 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 @@ -36,6 +36,11 @@ public SettingsFrame(){ @Override protected void initialize() { super.initialize(); + this.setPreferredSize(new Dimension(1000,600)); + } + + @Override + public void onViewInit() { this.root = new JPanel(new BorderLayout()); this.menuPanel = new MenuPanel(); JPanel leftPanel = this.componentsFactory.getJPanel(new BorderLayout()); @@ -91,8 +96,8 @@ private JPanel getSaveButtonPanel(){ }); saveButton.setPreferredSize(new Dimension(110, 26)); cancelButton.setPreferredSize(new Dimension(110, 26)); - root.add(this.componentsFactory.wrapToSlide(saveButton,AppThemeColor.HEADER,2,2,2,2)); root.add(this.componentsFactory.wrapToSlide(cancelButton,AppThemeColor.HEADER,2,2,2,2)); + root.add(this.componentsFactory.wrapToSlide(saveButton,AppThemeColor.HEADER,2,2,2,2)); return root; } 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 05ec5ce3..cb7d9a5c 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,142 +1,22 @@ 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.entity.message.Message; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.misc.AppThemeColor; - import javax.swing.*; -import javax.swing.Timer; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; public class TestCasesFrame extends AbstractTitledComponentFrame { - private List items; - private List currency; - private List nickNames; - private List offer; - private List leagues; - private String poeTradeTemplate = "2017/02/11 18:40:32 9029890 951 [INFO Client 8980] @From %s: Hi, I would like to buy your %s listed for %d %s in %s (stash tab \"%d\"; position: left %d, top %d) %s"; - private String currencyTemplate = "2017/02/11 18:56:15 9973390 951 [INFO Client 8980] @From %s: Hi, I'd like to buy your %d %s for my %d %s in %s. %s"; + private TestEngine testEngine; public TestCasesFrame() { super(); - items = new ArrayList<>(); - currency = new ArrayList<>(); - nickNames = new ArrayList<>(); - offer = new ArrayList<>(); - leagues = new ArrayList<>(); - items.add("Wondertrap Velvet Slippers"); - items.add("Rain of Arrows"); - items.add("Dreadarc Cleaver"); - items.add("Three-step Assault Shagreen Boots"); - items.add("Thunderous Skies"); - items.add("Honourhome Soldier Helmet"); - items.add("Pain Breaker Blood Sceptre"); - items.add("Freeze Mine"); - items.add("The Lunaris Priestess"); - - currency.add("alteration"); - currency.add("alchemy"); - currency.add("apprentice sextant"); - currency.add("divine"); - currency.add("exalted"); - currency.add("blessed"); - currency.add("esh's breachstone"); - currency.add("eber's"); - currency.add("regal"); - currency.add("armourer's"); - currency.add("augmentation"); - currency.add("bauble"); - currency.add("blessing of chayula"); - currency.add("blessing of esh"); - currency.add("blessing of tul"); - currency.add("blessing of uul-netol"); - currency.add("blessing of xoph"); - currency.add("chance"); - currency.add("chaos"); - currency.add("chayula's breachstone"); - currency.add("chimera"); - currency.add("chisel"); - currency.add("chrome"); - currency.add("coin"); - currency.add("dawn"); - currency.add("dusk"); - currency.add("eternal"); - currency.add("fusing"); - currency.add("gcp"); - currency.add("grief"); - currency.add("hope"); - currency.add("hydra"); - currency.add("ignorance"); - currency.add("inya's"); - currency.add("jeweller's"); - currency.add("journeyman sextant"); - currency.add("master sextant"); - currency.add("midnight"); - currency.add("minotaur"); - currency.add("mirror"); - currency.add("mortal set"); - currency.add("noon"); - currency.add("offering"); - currency.add("pale court"); - currency.add("phoenix"); - currency.add("portal"); - currency.add("rage"); - currency.add("regret"); - currency.add("sacrifice set"); - currency.add("scouring"); - currency.add("shaper set"); - currency.add("silver"); - currency.add("splinter of chayula"); - currency.add("splinter of esh"); - currency.add("splinter of tul"); - currency.add("splinter of uul-netol"); - currency.add("splinter of xoph"); - currency.add("transmutation"); - currency.add("tul's breachstone"); - currency.add("uul-netol's breachstone"); - currency.add("vaal"); - currency.add("volkuur's"); - currency.add("wisdom"); - currency.add("xoph's breachstone"); - currency.add("yriel's"); - - nickNames.add("Example1"); - nickNames.add("Example2"); - nickNames.add("Example3"); - nickNames.add("Example4"); - nickNames.add("Example5"); - nickNames.add("Example6"); - - offer.add("offer"); - offer.add(" "); - offer.add(""); - offer.add(" "); - offer.add("offer offer offer offer offer"); - offer.add("offer offer offer offer offer offer offer offer"); - offer.add("offer offer"); - offer.add("offer"); - - leagues.add("Standard"); - leagues.add("Hardcore Legacy"); - leagues.add("Legacy"); - leagues.add("Hardcore"); - leagues.add("Beta Standard"); - leagues.add("Beta Hardcore"); - leagues.add("1 Week Legacy (JRE055)"); - leagues.add("1 Week Legacy HC (JRE055)"); } @Override - protected void initialize() { - super.initialize(); - add(getTestCasesPanel(), BorderLayout.CENTER); - pack(); + public void onViewInit() { + this.testEngine = new TestEngine(); + this.add(getTestCasesPanel(), BorderLayout.CENTER); + this.pack(); } @Override @@ -144,9 +24,8 @@ protected String getFrameTitle() { return "Example of usage"; } + private JPanel getTestCasesPanel(){ - MessageParser parser = new MessageParser(); - Random random = new Random(); JPanel testPanel = new JPanel(new GridBagLayout()); GridBagConstraints buttonColumn = new GridBagConstraints(); @@ -165,126 +44,56 @@ private JPanel getTestCasesPanel(){ titleColumn.insets = new Insets(3,3,3,0); JButton button = componentsFactory.getBorderedButton("Click"); - button.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - Message message = parser.parse(String.format(poeTradeTemplate, - nickNames.get(random.nextInt(nickNames.size())), - items.get(random.nextInt(items.size())), - random.nextInt(200), - currency.get(random.nextInt(currency.size())), - leagues.get(random.nextInt(leagues.size())), - random.nextInt(30), - random.nextInt(12) + 1, - random.nextInt(12) + 1, - offer.get(random.nextInt(offer.size())) - )); - MercuryStoreCore.messageSubject.onNext(message); - } + button.addActionListener(action -> { + MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomItemIncMessage()); }); + ; testPanel.add(button,buttonColumn); buttonColumn.gridy++; - JLabel textLabel = componentsFactory.getTextLabel("Random item message"); + JLabel textLabel = componentsFactory.getTextLabel("Random incoming item message"); testPanel.add(textLabel,titleColumn); titleColumn.gridy++; JButton button1 = componentsFactory.getBorderedButton("Click"); - button1.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - Message message = parser.parse(String.format(currencyTemplate, - nickNames.get(random.nextInt(nickNames.size())), - random.nextInt(200), - currency.get(random.nextInt(currency.size())), - random.nextInt(200), - currency.get(random.nextInt(currency.size())), - leagues.get(random.nextInt(leagues.size())), - offer.get(random.nextInt(offer.size())) - )); - MercuryStoreCore.messageSubject.onNext(message); - } + button1.addActionListener(action -> { + MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomCurrencyIncMessage()); }); testPanel.add(button1,buttonColumn); buttonColumn.gridy++; - JLabel textLabel1 = componentsFactory.getTextLabel("Random currency message"); + JLabel textLabel1 = componentsFactory.getTextLabel("Random incoming currency message"); testPanel.add(textLabel1,titleColumn); titleColumn.gridy++; - - - JButton button2 = componentsFactory.getBorderedButton("Click"); - button2.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - String nickname = nickNames.get(random.nextInt(nickNames.size())); - Message message = parser.parse(String.format(currencyTemplate, - nickname, - random.nextInt(200), - currency.get(random.nextInt(currency.size())), - random.nextInt(200), - currency.get(random.nextInt(currency.size())), - leagues.get(random.nextInt(leagues.size())), - offer.get(random.nextInt(offer.size())) - )); - MercuryStoreCore.messageSubject.onNext(message); - MercuryStoreCore.soundSubject.onNext(SoundType.MESSAGE); - - Timer joinedTimer = new Timer(1000,null); - joinedTimer.addActionListener(e1 -> { - MercuryStoreCore.playerJoinSubject.onNext(nickname); - joinedTimer.stop(); - }); - joinedTimer.start(); - - Timer leftTimer = new Timer(2000,null); - leftTimer.addActionListener(e1 -> { - MercuryStoreCore.playerLeftSubject.onNext(nickname); - leftTimer.stop(); - }); - leftTimer.start(); - } + JButton outItemButton = componentsFactory.getBorderedButton("Click"); + outItemButton.addActionListener(action -> { + MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomItemOutMessage()); }); - testPanel.add(button2,buttonColumn); + testPanel.add(outItemButton,buttonColumn); buttonColumn.gridy++; - JLabel textLabel2 = componentsFactory.getTextLabel("Test accessibility status"); - testPanel.add(textLabel2,titleColumn); + JLabel outItemLabel = componentsFactory.getTextLabel("Random outgoing item message"); + testPanel.add(outItemLabel,titleColumn); titleColumn.gridy++; -// JButton button3 = componentsFactory.getBorderedButton("Click"); -// button3.addMouseListener(new MouseAdapter() { -// @Override -// public void mousePressed(MouseEvent e) { -// EventRouter.CORE.fireEvent(new UpdateReadyEvent()); -// } -// }); -// testPanel.add(button3,buttonColumn); -// buttonColumn.gridy++; -// JLabel textLabel3 = componentsFactory.getTextLabel("Test update frame"); -// testPanel.add(textLabel3,titleColumn); -// titleColumn.gridy++; -// testPanel.setBackground(AppThemeColor.TRANSPARENT); + JButton outCurrencyButton = componentsFactory.getBorderedButton("Click"); + outCurrencyButton.addActionListener(action -> { + MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomCurrencyOutMessage()); + }); + testPanel.add(outCurrencyButton,buttonColumn); + buttonColumn.gridy++; + JLabel outCurrencyLabel = componentsFactory.getTextLabel("Random outgoing currency message"); + testPanel.add(outCurrencyLabel,titleColumn); + titleColumn.gridy++; + testPanel.setBackground(AppThemeColor.TRANSPARENT); -// JButton button4 = componentsFactory.getBorderedButton("Click"); -// button4.addMouseListener(new MouseAdapter() { -// @Override -// public void mousePressed(MouseEvent e) { -// Message message = parser.parse(String.format(poeTradeTemplate, -// "Example", -// items.get(random.nextInt(items.size())), -// random.nextInt(200), -// "chaos", -// random.nextInt(12) + 1, -// random.nextInt(12) + 1, -// "can sell cheaper??" -// )); -// EventRouter.CORE.fireEvent(new NewWhispersEvent(message)); -// } -// }); -// testPanel.add(button4,buttonColumn); -// buttonColumn.gridy++; -// JLabel textLabel4 = componentsFactory.getTextLabel("Placeholder"); -// testPanel.add(textLabel4,titleColumn); -// titleColumn.gridy++; + JButton chatScannerButton = componentsFactory.getBorderedButton("Click"); + chatScannerButton.addActionListener(action -> { + MercuryStoreCore.newScannerMessageSubject.onNext(this.testEngine.getRandomScannerMessage()); + }); + testPanel.add(chatScannerButton,buttonColumn); + buttonColumn.gridy++; + JLabel chatScannerLabel = componentsFactory.getTextLabel("Random chat scanner message"); + testPanel.add(chatScannerLabel,titleColumn); + titleColumn.gridy++; testPanel.setBackground(AppThemeColor.TRANSPARENT); return testPanel; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestEngine.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestEngine.java new file mode 100644 index 00000000..fa935869 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TestEngine.java @@ -0,0 +1,205 @@ +package com.mercury.platform.ui.frame.titled; + + +import com.mercury.platform.shared.MessageParser; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationType; +import com.mercury.platform.shared.entity.message.PlainMessageDescriptor; +import com.mercury.platform.ui.components.panel.chat.HtmlMessageBuilder; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +public class TestEngine { + private List items = new ArrayList<>(); + private List currency= new ArrayList<>(); + private List nickNames= new ArrayList<>(); + private List offer= new ArrayList<>(); + private List leagues= new ArrayList<>(); + private HtmlMessageBuilder messageBuilder = new HtmlMessageBuilder(); + private MessageParser parser = new MessageParser(); + private Random random = new Random(); + private String poeTradeTemplate = "%s: Hi, I would like to buy your %s listed for %d %s in %s (stash tab \"%d\"; position: left %d, top %d) %s"; + private String currencyTemplate = "%s: Hi, I'd like to buy your %d %s for my %d %s in %s. %s"; + + public TestEngine() { + this.messageBuilder.setChunkStrings(Arrays.asList("Hi","buy","listed","like")); + + items.add("Wondertrap Velvet Slippers"); + items.add("Rain of Arrows"); + items.add("Dreadarc Cleaver"); + items.add("Three-step Assault Shagreen Boots"); + items.add("Thunderous Skies"); + items.add("Honourhome Soldier Helmet"); + items.add("Pain Breaker Blood Sceptre"); + items.add("Freeze Mine"); + items.add("The Lunaris Priestess"); + + currency.add("alteration"); + currency.add("alchemy"); + currency.add("apprentice sextant"); + currency.add("divine"); + currency.add("exalted"); + currency.add("blessed"); + currency.add("esh's breachstone"); + currency.add("eber's"); + currency.add("regal"); + currency.add("armourer's"); + currency.add("augmentation"); + currency.add("bauble"); + currency.add("blessing of chayula"); + currency.add("blessing of esh"); + currency.add("blessing of tul"); + currency.add("blessing of uul-netol"); + currency.add("blessing of xoph"); + currency.add("chance"); + currency.add("chaos"); + currency.add("chayula's breachstone"); + currency.add("chimera"); + currency.add("chisel"); + currency.add("chrome"); + currency.add("coin"); + currency.add("dawn"); + currency.add("dusk"); + currency.add("eternal"); + currency.add("fusing"); + currency.add("gcp"); + currency.add("grief"); + currency.add("hope"); + currency.add("hydra"); + currency.add("ignorance"); + currency.add("inya's"); + currency.add("jeweller's"); + currency.add("journeyman sextant"); + currency.add("master sextant"); + currency.add("midnight"); + currency.add("minotaur"); + currency.add("mirror"); + currency.add("mortal set"); + currency.add("noon"); + currency.add("offering"); + currency.add("pale court"); + currency.add("phoenix"); + currency.add("portal"); + currency.add("rage"); + currency.add("regret"); + currency.add("sacrifice set"); + currency.add("scouring"); + currency.add("shaper set"); + currency.add("silver"); + currency.add("splinter of chayula"); + currency.add("splinter of esh"); + currency.add("splinter of tul"); + currency.add("splinter of uul-netol"); + currency.add("splinter of xoph"); + currency.add("transmutation"); + currency.add("tul's breachstone"); + currency.add("uul-netol's breachstone"); + currency.add("vaal"); + currency.add("volkuur's"); + currency.add("wisdom"); + currency.add("xoph's breachstone"); + currency.add("yriel's"); + + nickNames.add("Example1"); + nickNames.add("Example2"); + nickNames.add("Example3"); + nickNames.add("Example4"); + nickNames.add("Example5"); + nickNames.add("Example6"); + + offer.add("offer"); + offer.add(" "); + offer.add(""); + offer.add(" "); + offer.add("offer offer offer offer offer"); + offer.add("offer offer offer offer offer offer offer offer"); + offer.add("offer offer"); + offer.add("offer"); + + leagues.add("Standard"); + leagues.add("Hardcore Legacy"); + leagues.add("Legacy"); + leagues.add("Hardcore"); + leagues.add("Beta Standard"); + leagues.add("Beta Hardcore"); + leagues.add("1 Week Legacy (JRE055)"); + leagues.add("1 Week Legacy HC (JRE055)"); + } + public NotificationDescriptor getRandomItemIncMessage(){ + NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, + nickNames.get(random.nextInt(nickNames.size())), + items.get(random.nextInt(items.size())), + random.nextInt(200), + currency.get(random.nextInt(currency.size())), + leagues.get(random.nextInt(leagues.size())), + random.nextInt(30), + random.nextInt(12) + 1, + random.nextInt(12) + 1, + offer.get(random.nextInt(offer.size())) + )); + return notificationDescriptor; + } + public NotificationDescriptor getRandomCurrencyIncMessage(){ + NotificationDescriptor notificationDescriptor = parser.parse(String.format(currencyTemplate, + nickNames.get(random.nextInt(nickNames.size())), + random.nextInt(200) + 1, + currency.get(random.nextInt(currency.size())), + random.nextInt(200) + 1, + currency.get(random.nextInt(currency.size())), + leagues.get(random.nextInt(leagues.size())), + offer.get(random.nextInt(offer.size())) + )); + return notificationDescriptor; + } + + public NotificationDescriptor getRandomItemOutMessage(){ + NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, + nickNames.get(random.nextInt(nickNames.size())), + items.get(random.nextInt(items.size())), + random.nextInt(200), + currency.get(random.nextInt(currency.size())), + leagues.get(random.nextInt(leagues.size())), + random.nextInt(30), + random.nextInt(12) + 1, + random.nextInt(12) + 1, + offer.get(random.nextInt(offer.size())) + )); + notificationDescriptor.setType(NotificationType.OUT_ITEM_MESSAGE); + return notificationDescriptor; + } + public NotificationDescriptor getRandomCurrencyOutMessage(){ + NotificationDescriptor notificationDescriptor = parser.parse(String.format(currencyTemplate, + nickNames.get(random.nextInt(nickNames.size())), + random.nextInt(200) + 1, + currency.get(random.nextInt(currency.size())), + random.nextInt(200) + 1, + currency.get(random.nextInt(currency.size())), + leagues.get(random.nextInt(leagues.size())), + offer.get(random.nextInt(offer.size())) + )); + notificationDescriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); + return notificationDescriptor; + } + public PlainMessageDescriptor getRandomScannerMessage(){ + NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, + nickNames.get(random.nextInt(nickNames.size())), + items.get(random.nextInt(items.size())), + random.nextInt(200), + currency.get(random.nextInt(currency.size())), + leagues.get(random.nextInt(leagues.size())), + random.nextInt(30), + random.nextInt(12) + 1, + random.nextInt(12) + 1, + offer.get(random.nextInt(offer.size())) + )); + PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); + descriptor.setMessage(messageBuilder.build(StringUtils.substringAfter(notificationDescriptor.getSourceString(),notificationDescriptor.getWhisperNickname()+":"))); + descriptor.setNickName(notificationDescriptor.getWhisperNickname()); + return descriptor; + } + +} 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 d9a0572d..c6d45270 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 @@ -187,4 +187,9 @@ public void subscribe() { protected String getFrameTitle() { return "Timer"; } + + @Override + public void onViewInit() { + + } } 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 deleted file mode 100644 index 5050ce69..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterFrame.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.mercury.platform.ui.frame.titled.chat; - -import com.mercury.platform.core.utils.interceptor.MessageInterceptor; -import com.mercury.platform.core.utils.interceptor.filter.MessageFilter; -import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.FrameDescriptor; -import com.mercury.platform.shared.config.descriptor.ScannerDescriptor; -import com.mercury.platform.shared.store.MercuryStoreCore; -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.AbstractTitledComponentFrame; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; -import org.apache.commons.lang3.StringUtils; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.util.*; -import java.util.List; - -public class ChatFilterFrame extends AbstractTitledComponentFrame { - private ChatFilterSettingsFrame settingsFrame; - private PlainConfigurationService scannerService; - 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(); - this.scannerService = Configuration.get().scannerConfiguration(); - FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); - this.setPreferredSize(frameDescriptor.getFrameSize()); - this.settingsFrame = new ChatFilterSettingsFrame(strings -> { - if(chatEnable){ - performNewStrings(strings); - } - }); - } - - @Override - protected void initialize() { - super.initialize(); - - this.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - setPreferredSize(getSize()); - } - }); - 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.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) { - MercuryStoreCore.removeInterceptorSubject.onNext(interceptor); - } - enableButton.setText("Start"); - enableButton.setForeground(AppThemeColor.TEXT_SUCCESS); - repaint(); - }, - () -> { - chatEnable = true; - String chunkStr = StringUtils.deleteWhitespace(this.scannerService.get().getWords()); - 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<>(); - - Arrays.stream(strings).forEach(str -> { - str = str.toLowerCase().trim(); - if(!str.isEmpty()) { - if (str.contains("!")) { - notContains.add(str.replace("!", "")); - } else { - contains.add(str); - } - } - }); - - msgContainer.setNewChunks(Arrays.asList(strings)); - if (interceptor != null) { - MercuryStoreCore.removeInterceptorSubject.onNext(interceptor); - } - interceptor = new MessageInterceptor() { - @Override - protected void process(String message) { - msgContainer.addMessage(message); - ChatFilterFrame.this.pack(); - if(scrollToBottom){ - msgContainer.scrollToBottom(true); - } - } - - @Override - protected MessageFilter getFilter() { - return message -> { - if (!message.contains("] $") && !message.contains("] #")) { - return false; - } - message = StringUtils.substringAfter(message, ":").toLowerCase(); - return notContains.stream().noneMatch(message::contains) - && contains.stream().anyMatch(message::contains); - }; - } - }; - MercuryStoreCore.addInterceptorSubject.onNext(interceptor); - } - - @Override - protected String getFrameTitle() { - return "Mercury: Chat scanner"; - } - - @Override - public void subscribe() { - MercuryStoreUI.scrollToEndSubject.subscribe(value -> { - this.scrollToBottom = value; - if (!this.scrollToBottom) { - this.scrollEnd.setIcon(componentsFactory.getIcon("app/scroll-end-r.png", 18)); - this.msgContainer.scrollToBottom(false); - } - }); - } - - private JPanel getToolbar(){ - JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); - root.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); - - JPanel panel = componentsFactory.getTransparentPanel(); - panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); - panel.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); - panel.setBackground(AppThemeColor.SLIDE_BG); - - JButton edit = componentsFactory.getIconButton( - "app/edit.png", - 17, - AppThemeColor.TRANSPARENT, - "Chat Scanner settings"); - edit.addActionListener( - action -> this.settingsFrame.showAuxiliaryFrame( - new Point(this.getLocation().x,this.getLocation().y), - this.getPreferredSize().height)); - JButton clear = componentsFactory.getIconButton( - "app/clear-history.png", - 18, - AppThemeColor.TRANSPARENT, - "Clear all"); - clear.addActionListener(action -> { - this.msgContainer.clear(); - this.pack(); - this.repaint(); - }); - JButton sound = componentsFactory.getIconButton( - "app/sound-disable.png", - 18, - AppThemeColor.TRANSPARENT, - "Sound alert"); - sound.addActionListener(action -> { - if (soundEnable) { - sound.setIcon(componentsFactory.getIcon("app/sound-disable.png", 18)); - msgContainer.sound(false); - this.soundEnable = false; - this.repaint(); - } else { - sound.setIcon(componentsFactory.getIcon("app/sound-enable.png", 18)); - msgContainer.sound(true); - this.soundEnable = true; - this.repaint(); - } - }); - - this.scrollEnd = componentsFactory.getIconButton( - "app/scroll-end.png", - 18, - AppThemeColor.TRANSPARENT, - "Automatically scroll down"); - this.scrollEnd.addActionListener(action -> { - if (scrollToBottom) { - this.scrollEnd.setIcon(componentsFactory.getIcon("app/scroll-end-r.png", 18)); - this.scrollToBottom = false; - this.msgContainer.scrollToBottom(false); - this.repaint(); - } else { - this.scrollEnd.setIcon(componentsFactory.getIcon("app/scroll-end.png", 18)); - this.scrollToBottom = true; - this.msgContainer.scrollToBottom(true); - this.repaint(); - } - }); - - panel.add(edit); - panel.add(sound); - panel.add(this.scrollEnd); - panel.add(clear); - - root.add(panel,BorderLayout.CENTER); - return root; - } - - @Override - protected LayoutManager getFrameLayout() { - return new BorderLayout(); - } -} 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 deleted file mode 100644 index 6328ed7b..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatFilterSettingsFrame.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.mercury.platform.ui.frame.titled.chat; - -import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.configration.PlainConfigurationService; -import com.mercury.platform.shared.config.descriptor.ScannerDescriptor; -import com.mercury.platform.shared.store.MercuryStoreCore; -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.AbstractTitledComponentFrame; -import com.mercury.platform.ui.misc.AppThemeColor; -import org.apache.commons.lang3.StringUtils; - -import javax.swing.*; -import java.awt.*; - -public class ChatFilterSettingsFrame extends AbstractTitledComponentFrame { - private ChatSettingsCallback callback; - private PlainConfigurationService scannerService; - private JTextField quickResponseField; - - public ChatFilterSettingsFrame(ChatSettingsCallback callback) { - super(); - this.callback = callback; - this.scannerService = Configuration.get().scannerConfiguration(); - this.processingHideEvent = false; - this.setFocusableWindowState(true); - this.setFocusable(true); - this.setAlwaysOnTop(false); - } - - @Override - protected void initialize() { - super.initialize(); - this.setPreferredSize(new Dimension(350,300)); - JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); - JPanel setupArea = componentsFactory.getTransparentPanel(new BorderLayout()); - setupArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); - - JLabel title = componentsFactory.getTextLabel( - FontStyle.REGULAR, - AppThemeColor.TEXT_DEFAULT, - TextAlignment.LEFTOP, - 15f, - "Show messages containing the following words:"); - title.setBorder(BorderFactory.createEmptyBorder(2,0,6,0)); - JTextArea words = componentsFactory.getSimpleTextArea(this.scannerService.get().getWords()); - words.setEditable(true); - words.setCaretColor(AppThemeColor.TEXT_DEFAULT); - words.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); - words.setBackground(AppThemeColor.SLIDE_BG); - - JPanel navBar = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - Dimension buttonSize = new Dimension(90, 24); - JButton save = componentsFactory.getBorderedButton("Save"); - save.addActionListener(action -> { - this.scannerService.get().setWords(words.getText()); - this.scannerService.get().setResponseMessage(quickResponseField.getText()); - MercuryStoreCore.saveConfigSubject.onNext(true); - - String chunkStr = StringUtils.deleteWhitespace(words.getText()); - String[] split = chunkStr.split(","); - - this.callback.onHide(split); - this.hideComponent(); - }); - JButton cancel = componentsFactory.getBorderedButton("Cancel"); - cancel.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3) - )); - cancel.setBackground(AppThemeColor.FRAME); - cancel.addActionListener(action -> { - hideComponent(); - }); - save.setPreferredSize(buttonSize); - cancel.setPreferredSize(buttonSize); - navBar.add(cancel); - navBar.add(save); - - setupArea.add(title,BorderLayout.PAGE_START); - setupArea.add(words,BorderLayout.CENTER); - - root.add(setupArea,BorderLayout.CENTER); - root.add(getMemo(),BorderLayout.LINE_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"); - this.quickResponseField = componentsFactory.getTextField(this.scannerService.get().getResponseMessage(),FontStyle.REGULAR,16f); - this.quickResponseField.setBackground(AppThemeColor.SLIDE_BG); - this.quickResponseField.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.HEADER,1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,3) - )); - setupArea.add(quickResponse,BorderLayout.LINE_START); - setupArea.add(this.quickResponseField,BorderLayout.CENTER); - root.add(setupArea,BorderLayout.CENTER); - return root; - } - - private JPanel getMemo(){ - JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); - JLabel title = componentsFactory.getTextLabel( - "Memo:", - FontStyle.REGULAR); - title.setBorder(BorderFactory.createEmptyBorder(6,0,2,0)); - - - JPanel itemsPanel = componentsFactory.getTransparentPanel(); - itemsPanel.setLayout(new BoxLayout(itemsPanel,BoxLayout.Y_AXIS)); - - itemsPanel.add(componentsFactory.getTextLabel("not case sensitive",FontStyle.REGULAR,17)); - itemsPanel.add(componentsFactory.getTextLabel("! - NOT (!wtb,!wts)",FontStyle.REGULAR,17)); - itemsPanel.add(componentsFactory.getTextLabel(", - separator",FontStyle.REGULAR,17)); - root.add(title,BorderLayout.PAGE_START); - root.add(itemsPanel,BorderLayout.CENTER); - return root; - } - - public void showAuxiliaryFrame(Point location, int height) { - this.setPreferredSize(new Dimension(this.getPreferredSize().width,height)); - this.setMinimumSize(new Dimension(this.getPreferredSize().width,height)); - this.setMinimumSize(new Dimension(this.getPreferredSize().width,height)); - this.setLocation(location); - this.showComponent(); - } - - @Override - protected String getFrameTitle() { - return "Chat filter settings"; - } - - @Override - public void subscribe() { - - } - - @Override - protected LayoutManager getFrameLayout() { - return new BorderLayout(); - } -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatSettingsCallback.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatSettingsCallback.java deleted file mode 100644 index 530e4f7f..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/chat/ChatSettingsCallback.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mercury.platform.ui.frame.titled.chat; - - -public interface ChatSettingsCallback { - void onHide(String[] strings); -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java deleted file mode 100644 index f5b2be32..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/container/HistoryContainer.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mercury.platform.ui.frame.titled.container; - -import com.mercury.platform.ui.components.panel.message.InMessagePanel; - -public interface HistoryContainer { - void onReloadMessage(InMessagePanel inMessagePanel); -} 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 27dcc682..1000f988 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 @@ -11,7 +11,7 @@ import com.mercury.platform.ui.frame.AbstractScalableComponentFrame; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; import com.mercury.platform.ui.frame.movable.AbstractMovableComponentFrame; -import com.mercury.platform.ui.frame.movable.container.MessageFrame; +import com.mercury.platform.ui.frame.movable.NotificationFrame; import com.mercury.platform.ui.frame.other.*; import com.mercury.platform.ui.frame.movable.TaskBarFrame; import com.mercury.platform.ui.adr.AdrState; @@ -20,8 +20,8 @@ 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; -import com.mercury.platform.ui.frame.titled.container.HistoryFrame; +import com.mercury.platform.ui.frame.titled.ChatScannerFrame; +import com.mercury.platform.ui.frame.titled.HistoryFrame; import com.mercury.platform.ui.manager.routing.SettingsRoutManager; import com.mercury.platform.ui.misc.MercuryStoreUI; import com.mercury.platform.ui.misc.note.Note; @@ -55,8 +55,8 @@ private FramesManager() { public void start(){ this.createTrayIcon(); - AbstractOverlaidFrame incMessageFrame = new MessageFrame(); - this.framesMap.put(MessageFrame.class,incMessageFrame); + AbstractOverlaidFrame incMessageFrame = new NotificationFrame(); + this.framesMap.put(NotificationFrame.class,incMessageFrame); AbstractOverlaidFrame taskBarFrame = new TaskBarFrame(); AbstractOverlaidFrame itemsMeshFrame = new ItemsGridFrame(); this.framesMap.put(ItemsGridFrame.class,itemsMeshFrame); @@ -78,9 +78,9 @@ public void start(){ this.framesMap.put(SettingsFrame.class,settingsFrame); this.framesMap.put(TestCasesFrame.class,new TestCasesFrame()); this.framesMap.put(TooltipFrame.class,new TooltipFrame()); - this.framesMap.put(NotificationFrame.class,new NotificationFrame()); + this.framesMap.put(NotificationAlertFrame.class,new NotificationAlertFrame()); this.framesMap.put(MercuryLoadingFrame.class,new MercuryLoadingFrame()); - this.framesMap.put(ChatFilterFrame.class,new ChatFilterFrame()); + this.framesMap.put(ChatScannerFrame.class,new ChatScannerFrame()); this.framesMap.put(UpdateReadyFrame.class,new UpdateReadyFrame()); this.framesMap.put(TaskBarFrame.class,taskBarFrame); this.framesMap.put(SetUpLocationFrame.class,new SetUpLocationFrame()); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/AppThemeColor.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/AppThemeColor.java index d4192e09..acd6fc2e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/AppThemeColor.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/AppThemeColor.java @@ -3,8 +3,8 @@ import java.awt.*; public class AppThemeColor { - public static final Color BUTTON = new Color(16,91,99); - public static final Color SCROLL_BAR = new Color(44, 70, 80); + public static final Color BUTTON = new Color(52, 62, 61); + public static final Color SCROLL_BAR = new Color(71, 81, 80); public static final Color TEXT_DEFAULT = new Color(255,250,250); public static final Color TEXT_MESSAGE = new Color(255,250,213); public static final Color TEXT_MISC = new Color(219,158,54); @@ -12,8 +12,10 @@ public class AppThemeColor { public static final Color TEXT_IMPORTANT = new Color(224,86,60); public static final Color TEXT_SUCCESS = new Color(111, 173, 39); public static final Color TEXT_DISABLE = new Color(126,130,122); - public static final Color BORDER = new Color(22,126,138); - public static final Color BORDER_DARK = new Color(23, 103, 115); + public static final Color BORDER = new Color(70, 81, 80); + public static final Color BORDER_GREEN = new Color(20, 113, 122); + public static final Color BORDER_DARK = new Color(62, 73, 72); + public static final Color HEADER_SELECTED_BORDER = new Color(128, 123, 95); public static final Color FRAME = new Color(42, 44, 43,254); public static final Color FRAME_RGB = new Color(42, 44, 43); public static final Color FRAME_ALPHA = new Color(42, 44, 43,1); @@ -25,13 +27,16 @@ public class AppThemeColor { public static final Color MSG_HEADER = new Color(52, 62, 61); public static final Color MSG_HEADER_BORDER = new Color(62, 73, 72); - public static final Color ADR_SELECTED_BORDER = new Color(255,250,213); + public static final Color RESPONSE_BUTTON = new Color(52, 62, 61); + public static final Color RESPONSE_BUTTON_BORDER = new Color(70, 81, 80); + + public static final Color ADR_SELECTED_BORDER = new Color(198, 193, 154); public static final Color ADR_POPUP_BG = new Color(212, 207, 171); public static final Color ADR_MOUSE_OVER_BORDER = new Color(155, 150, 120); public static final Color ADR_DEFAULT_BORDER = new Color(62, 73, 72); public static final Color ADR_BG = new Color(45, 55, 54); public static final Color ADR_TRACKER_GROUP_BG = new Color(35, 45, 44); - public static final Color ADR_PANEL_BORDER = new Color(23, 103, 115); + public static final Color ADR_PANEL_BORDER = new Color(70, 81, 80); public static final Color ADR_TEXT_ARE_BG = new Color(50, 52, 51); public static final Color ADR_FOOTER_BG = new Color(55,65,64); public static final Color ADR_CAPTURE_BG = new Color(42, 44, 43,1); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java index 0f697b96..d6c3b4ce 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java @@ -3,13 +3,12 @@ import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; -import com.mercury.platform.shared.entity.message.ItemMessage; -import com.mercury.platform.shared.entity.message.Message; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; +import com.mercury.platform.shared.entity.message.NotificationDescriptor; import com.mercury.platform.ui.adr.routing.AdrComponentDefinition; import com.mercury.platform.ui.adr.routing.AdrPageDefinition; import com.mercury.platform.ui.components.panel.grid.ItemInfoPanel; import com.mercury.platform.ui.components.panel.grid.TabInfoPanel; -import com.mercury.platform.ui.components.panel.message.InMessagePanel; import com.mercury.platform.ui.dialog.DialogCallback; import com.mercury.platform.ui.manager.routing.SettingsPage; import rx.subjects.PublishSubject; @@ -17,13 +16,12 @@ import java.util.Map; public class MercuryStoreUI { - public static final PublishSubject closeGridItemSubject = PublishSubject.create(); - public static final PublishSubject closeMessage = PublishSubject.create(); + public static final PublishSubject closeGridItemSubject = PublishSubject.create(); + public static final PublishSubject closeMessage = PublishSubject.create(); public static final PublishSubject collapseMessageSubject = PublishSubject.create(); public static final PublishSubject dismissTabInfoPanelSubject = PublishSubject.create(); public static final PublishSubject expandMessageSubject = PublishSubject.create(); public static final PublishSubject itemCellStateSubject = PublishSubject.create(); - public static final PublishSubject reloadMessageSubject = PublishSubject.create(); //Scale public static final PublishSubject> saveScaleSubject = PublishSubject.create(); public static final PublishSubject notificationScaleSubject = PublishSubject.create(); @@ -31,7 +29,7 @@ public class MercuryStoreUI { public static final PublishSubject itemPanelScaleSubject = PublishSubject.create(); public static final PublishSubject scrollToEndSubject = PublishSubject.create(); - public static final PublishSubject showItemGridSubject = PublishSubject.create(); + public static final PublishSubject showItemGridSubject = PublishSubject.create(); public static final PublishSubject> packSubject = PublishSubject.create(); public static final PublishSubject> repaintSubject = PublishSubject.create(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/TooltipConstants.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/TooltipConstants.java index 2bdb3469..8ba1ce4b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/TooltipConstants.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/TooltipConstants.java @@ -30,6 +30,10 @@ public class TooltipConstants { public static final String TRADE = "Offer Trade"; public static final String EXPAND_COLLAPSE = "Expand / collapse"; public static final String OPEN_CHAT = "Message this player"; + public static final String SWITCH_CHAT = "Show chat history"; + public static final String VISIT_HO = "Visit player's hideout"; + public static final String LEAVE = "Leave from party"; + public static final String QUICK_RESPONSE = "Quick response"; public static final String HIDE_PANEL = "Close"; //OutMessage tooltips diff --git a/app-ui/src/main/resources/app/invite.png b/app-ui/src/main/resources/app/invite.png index 27238704..4b11cdde 100644 Binary files a/app-ui/src/main/resources/app/invite.png and b/app-ui/src/main/resources/app/invite.png differ diff --git a/app-ui/src/main/resources/notes/patch/patch-notes.json b/app-ui/src/main/resources/notes/patch/patch-notes.json index dc762584..9e37d271 100644 --- a/app-ui/src/main/resources/notes/patch/patch-notes.json +++ b/app-ui/src/main/resources/notes/patch/patch-notes.json @@ -1,9 +1,9 @@ { - "version":"1.0.1.7.0", + "version":"1.0.1.8.0", "notes":[ { "title" : "Update", - "text" : "More than 5000 unique users this week! Here is an update for you!\n-Completely reworked Settings GUI.\n-All the issues with non-English keyboard layouts should be gone. Also now you can bind absolutely any mouse / keyboard button you have.\n-Fixed an issue when you couldn't close Notification panel.\n-Now components are cleaned up properly on a profile switch.\nCheck out the Overseer channel on Discord - post your setups, share profiles and converse!\n\nStay with us as there are more mind-blowing features to come. And don't forget to support the app, judging from all the activity looks like it's probably worth some!", + "text" : "Just this week we've got more than 6000 new users which is insane. The update we're rolling out today affects every aspect of the application - basically a big rework of the core systems.\n\n- Notification panel rework (more info on reddit)\n- Overseer: new component \"Capture\".\n- All the buttons are now hotkeyable.\n- Chat scanner and history rework.\n- More responsive interface.\n\nA lot of work has been done, but that's it for today. Stay with us!", "image" : "", "layout" : "VERTICAL" } diff --git a/app/src/main/java/com/mercury/platform/AppMain.java b/app/src/main/java/com/mercury/platform/AppMain.java index b50d3398..b9acd195 100644 --- a/app/src/main/java/com/mercury/platform/AppMain.java +++ b/app/src/main/java/com/mercury/platform/AppMain.java @@ -24,6 +24,7 @@ public class AppMain { public static void main(String[] args) { System.setProperty("sun.java2d.d3d","false"); + System.setProperty("jna.nosys","true"); new ErrorHandler(); MercuryLoadingFrame mercuryLoadingFrame = new MercuryLoadingFrame(); mercuryLoadingFrame.init();