From acbdff1ff2c3dc51a8928ab38afda971b8c58fc1 Mon Sep 17 00:00:00 2001 From: Exslims Date: Wed, 23 Aug 2017 22:28:50 +0400 Subject: [PATCH] reformat code --- .../com/mercury/platform/core/ChatHelper.java | 13 +- .../com/mercury/platform/core/DevStarter.java | 1 + .../mercury/platform/core/ProdStarter.java | 26 +- .../platform/core/misc/SoundNotifier.java | 9 +- .../mercury/platform/core/misc/SoundType.java | 2 +- .../core/misc/WhisperNotifierStatus.java | 7 +- .../core/update/UpdateClientStarter.java | 13 +- .../update/bus/UpdaterClientEventBus.java | 11 +- .../update/bus/event/UpdateReceivedEvent.java | 2 +- .../bus/handlers/UpdateEventHandler.java | 3 +- .../core/update/core/UpdaterClient.java | 23 +- .../update/core/handlers/ClientHandler.java | 27 +- .../core/handlers/ResponseDispatcher.java | 9 +- .../update/core/holder/ApplicationHolder.java | 14 +- .../platform/core/utils/FileMonitor.java | 15 +- .../core/utils/MessageFileHandler.java | 9 +- .../core/utils/error/ErrorHandler.java | 3 +- .../utils/interceptor/MessageInterceptor.java | 7 +- .../interceptor/PlainMessageInterceptor.java | 40 +- .../interceptor/PlayerJoinInterceptor.java | 2 +- .../interceptor/PlayerLeftInterceptor.java | 2 +- .../TradeIncMessagesInterceptor.java | 32 +- .../TradeOutMessagesInterceptor.java | 42 ++- .../experimental/PerformanceHelper.java | 8 +- .../platform/experimental/RxJavaBasic.java | 17 +- .../experimental/RxJavaOperators.java | 12 +- .../mercury/platform/shared/CloneHelper.java | 5 +- .../platform/shared/FrameVisibleState.java | 2 +- .../platform/shared/HistoryManager.java | 43 +-- .../platform/shared/MessageParser.java | 25 +- .../platform/shared/UpdateManager.java | 7 +- .../platform/shared/config/ConfigManager.java | 17 +- .../platform/shared/config/Configuration.java | 4 +- .../shared/config/MercuryConfigManager.java | 51 +-- .../configration/AdrConfigurationService.java | 6 +- .../BaseConfigurationService.java | 9 +- .../configration/ConfigurationService.java | 2 +- .../FramesConfigurationService.java | 2 +- .../config/configration/HasDefault.java | 1 + .../IconBundleConfigurationService.java | 6 +- .../KeyValueConfigurationService.java | 6 +- .../PlainConfigurationService.java | 1 + .../impl/ApplicationConfigurationService.java | 5 +- .../impl/FramesConfigurationServiceImpl.java | 41 ++- .../impl/HotKeyConfigurationService.java | 41 ++- .../IconBundleConfigurationServiceImpl.java | 28 +- .../NotificationConfigurationService.java | 19 +- .../impl/ScaleConfigurationService.java | 16 +- .../impl/ScannerConfigurationService.java | 2 +- .../impl/SoundConfigurationService.java | 19 +- .../impl/StashTabConfigurationService.java | 2 +- .../impl/TaskBarConfigurationService.java | 2 +- .../impl/adr/AdrConfigurationServiceMock.java | 21 +- .../descriptor/ApplicationDescriptor.java | 3 +- .../config/descriptor/HotKeyDescriptor.java | 2 +- .../shared/config/descriptor/HotKeyPair.java | 2 +- .../shared/config/descriptor/HotKeyType.java | 8 +- .../NotificationSettingsDescriptor.java | 2 +- .../config/descriptor/ProfileDescriptor.java | 6 +- .../descriptor/ResponseButtonDescriptor.java | 8 +- .../config/descriptor/ScannerDescriptor.java | 2 +- .../config/descriptor/SoundDescriptor.java | 2 +- .../descriptor/adr/AdrCaptureDescriptor.java | 2 +- .../adr/AdrColoredComponentDescriptor.java | 4 +- .../adr/AdrComponentDescriptor.java | 3 +- .../adr/AdrComponentOrientation.java | 7 +- .../adr/AdrDurationComponentDescriptor.java | 10 +- .../descriptor/adr/AdrIconAlignment.java | 7 +- .../config/descriptor/adr/AdrIconType.java | 7 +- .../adr/AdrProgressBarDescriptor.java | 1 - .../descriptor/adr/AdrTrackerGroupType.java | 7 +- .../shared/config/json/JSONHelper.java | 92 ++--- .../deserializer/AdrComponentJsonAdapter.java | 14 +- .../AdrTrackerGroupDeserializer.java | 12 +- .../deserializer/MessageDeserializer.java | 2 +- .../service/PoeAppHttpSearchService.java | 192 +++++----- .../shared/entity/message/FlowDirections.java | 2 +- .../shared/entity/message/MercuryError.java | 3 +- .../hotkey/MercuryNativeKeyListener.java | 29 +- .../hotkey/MercuryNativeMouseListener.java | 2 +- .../shared/store/DataTransformers.java | 9 +- .../shared/store/MercuryStoreCore.java | 3 +- .../platform/ui/adr/AdrFrameMagnet.java | 13 +- .../mercury/platform/ui/adr/AdrManager.java | 208 +++++------ .../components/AbstractAdrComponentFrame.java | 21 +- .../ui/adr/components/AbstractAdrFrame.java | 17 +- .../AdrCaptureOutComponentFrame.java | 24 +- .../adr/components/AdrComponentsFactory.java | 343 ++++++++++-------- .../ui/adr/components/AdrManagerFrame.java | 91 +++-- .../components/AdrSingleComponentFrame.java | 6 +- .../adr/components/AdrTrackerGroupFrame.java | 10 +- .../factory/FrameProviderFactory.java | 2 +- .../factory/frame/CaptureInFrameProvider.java | 4 +- .../factory/frame/FrameProvider.java | 2 + .../factory/frame/SingleFrameProvider.java | 9 +- .../frame/TrackerGroupFrameProvider.java | 7 +- .../components/panel/AdrCaptureOutPanel.java | 5 +- .../adr/components/panel/AdrCapturePanel.java | 21 +- .../components/panel/AdrComponentPanel.java | 13 +- .../panel/AdrDurationCellPanel.java | 19 +- .../panel/AdrDurationComponentPanel.java | 8 +- .../panel/AdrTrackerGroupPanel.java | 33 +- .../panel/page/AdrCapturePagePanel.java | 14 +- .../panel/page/AdrGroupPagePanel.java | 26 +- .../panel/page/AdrIconPagePanel.java | 30 +- .../components/panel/page/AdrLoadingPage.java | 9 +- .../panel/page/AdrMainPagePanel.java | 40 +- .../components/panel/page/AdrPagePanel.java | 9 +- .../panel/page/AdrProfilePagePanel.java | 32 +- .../panel/page/AdrProgressBarPagePanel.java | 32 +- .../panel/tree/AdrMouseOverListener.java | 17 +- .../components/panel/tree/AdrNodePanel.java | 1 + .../components/panel/tree/AdrTreePanel.java | 69 ++-- .../dialog/AdrDialogCaptureNodePanel.java | 13 +- .../tree/dialog/AdrDialogGroupNodePanel.java | 21 +- .../tree/dialog/AdrDialogIconNodePanel.java | 9 +- .../tree/dialog/AdrDialogPBNodePanel.java | 7 +- .../dialog/AdrDialogTreeNodeRenderer.java | 14 +- .../panel/tree/main/AdrCaptureNodePanel.java | 15 +- .../panel/tree/main/AdrGroupNodePanel.java | 30 +- .../panel/tree/main/AdrIconNodePanel.java | 12 +- .../tree/main/AdrMainTreeNodeRenderer.java | 14 +- .../tree/main/AdrProgressBarNodePanel.java | 13 +- .../panel/tree/model/AdrTreeNode.java | 36 +- .../panel/ui/BasicMercuryIconTrackerUI.java | 35 +- .../panel/ui/IconsListCellRenderer.java | 6 +- .../components/panel/ui/MercuryLoading.java | 30 +- .../components/panel/ui/MercuryLoadingUi.java | 9 +- .../components/panel/ui/MercuryTracker.java | 49 ++- .../ui/impl/BIconVProgressBarTrackerUI.java | 12 +- .../panel/ui/impl/EllipseIconTrackerUI.java | 33 +- .../ui/impl/LIconHProgressBarTrackerUI.java | 3 +- .../ui/impl/MercuryProgressBarTrackerUI.java | 24 +- .../panel/ui/impl/ProgressBarUI.java | 4 +- .../panel/ui/impl/ProgressBarUIFactory.java | 1 + .../ui/impl/RIconHProgressBarTrackerUI.java | 2 +- .../panel/ui/impl/SquareIconTrackerUI.java | 26 +- .../ui/impl/TIconVProgressBarTrackerUI.java | 12 +- .../panel/ui/impl/VProgressBarTrackerUI.java | 7 +- .../platform/ui/adr/dialog/AdrDialog.java | 18 +- .../ui/adr/dialog/AdrExportDialog.java | 41 +-- .../ui/adr/dialog/AdrIconSelectDialog.java | 57 +-- .../ui/adr/dialog/AdrImportDialog.java | 70 ++-- .../ui/adr/dialog/AdrNewProfileDialog.java | 25 +- .../adr/routing/AdrComponentDefinition.java | 2 +- .../adr/routing/AdrComponentOperations.java | 2 +- .../adr/validator/DoubleFieldValidator.java | 7 +- .../validator/DoubleFormatFieldValidator.java | 7 +- .../ui/adr/validator/FieldValidator.java | 2 +- .../ui/adr/validator/FloatFieldValidator.java | 8 +- .../ui/adr/validator/HexFieldValidator.java | 6 +- .../adr/validator/IntegerFieldValidator.java | 8 +- .../ui/adr/validator/RangeFieldValidator.java | 2 +- .../ui/components/ComponentsFactory.java | 343 ++++++++++-------- .../ui/components/ControlsFactory.java | 4 +- .../components/fields/MercuryTabbedPane.java | 27 +- .../ui/components/fields/font/FontStyle.java | 2 +- .../fields/style/MercuryComboBoxUI.java | 5 +- .../fields/style/MercuryScrollBarUI.java | 1 + .../ui/components/panel/CollapsiblePanel.java | 15 +- .../ui/components/panel/TransparentPanel.java | 7 +- .../panel/chat/ChatMessagePanel.java | 22 +- .../panel/chat/ChatScannerController.java | 2 + .../panel/chat/HtmlMessageBuilder.java | 6 +- .../ui/components/panel/grid/ItemCell.java | 2 +- .../components/panel/grid/ItemInfoPanel.java | 31 +- .../panel/grid/ItemInfoPanelController.java | 1 + .../grid/ItemInfoPanelControllerImpl.java | 2 + .../components/panel/grid/ItemsGridPanel.java | 80 ++-- .../panel/grid/StashTabsContainer.java | 17 +- .../components/panel/grid/TabInfoPanel.java | 10 +- .../panel/misc/MercuryAppLoadingUI.java | 8 +- .../CurrencyIncNotificationPanel.java | 29 +- .../CurrencyOutNotificationPanel.java | 21 +- .../HistoryNotificationPanel.java | 28 +- .../IncomingNotificationPanel.java | 174 ++++----- .../ItemIncNotificationPanel.java | 19 +- .../ItemOutNotificationPanel.java | 6 +- .../panel/notification/NotificationPanel.java | 44 ++- .../OutgoingNotificationPanel.java | 99 ++--- .../ScannerNotificationPanel.java | 67 ++-- .../controller/HistoryController.java | 1 + .../controller/IncomingPanelController.java | 4 +- .../controller/NotificationController.java | 3 + .../NotificationIncomingController.java | 12 +- .../NotificationOutgoingController.java | 4 +- .../NotificationScannerController.java | 3 +- .../controller/OutgoingPanelController.java | 3 +- .../controller/ScannerPanelController.java | 3 +- .../factory/CurrencyIncPanelProvider.java | 4 +- .../factory/CurrencyOutPanelProvider.java | 1 + .../factory/HistoryPanelProvider.java | 2 +- .../factory/ItemIncPanelProvider.java | 4 +- .../factory/ItemOutPanelProvider.java | 2 +- .../factory/NotificationPanelFactory.java | 6 +- .../factory/NotificationPanelProvider.java | 21 +- .../factory/ScannerPanelProvider.java | 3 +- .../components/panel/settings/HelpPanel.java | 11 +- .../panel/settings/MenuListRenderer.java | 18 +- .../components/panel/settings/MenuPanel.java | 2 + .../panel/settings/page/AboutPagePanel.java | 20 +- .../page/GeneralSettingsPagePanel.java | 45 +-- .../panel/settings/page/HotKeyPanel.java | 6 +- .../page/NotificationSettingsPagePanel.java | 123 ++++--- .../settings/page/ResponseButtonsPanel.java | 61 ++-- .../settings/page/SettingsPagePanel.java | 7 +- .../settings/page/SoundSettingsPagePanel.java | 55 +-- .../panel/settings/page/SupportPagePanel.java | 65 ++-- .../page/TaskBarSettingsPagePanel.java | 15 +- .../panel/taskbar/TaskBarController.java | 9 + .../panel/taskbar/TaskBarPanel.java | 33 +- .../platform/ui/dialog/AlertDialog.java | 29 +- .../platform/ui/dialog/BaseDialog.java | 7 +- .../ui/frame/AbstractComponentFrame.java | 121 +++--- .../ui/frame/AbstractOverlaidFrame.java | 30 +- .../frame/AbstractScalableComponentFrame.java | 28 +- .../ui/frame/experimental/AdrTesting.java | 47 ++- .../AbstractMovableComponentFrame.java | 32 +- .../ui/frame/movable/CurrencySearchFrame.java | 44 +-- .../ui/frame/movable/ItemsGridFrame.java | 105 +++--- .../ui/frame/movable/NotificationFrame.java | 104 +++--- .../ui/frame/movable/TaskBarFrame.java | 88 +++-- .../platform/ui/frame/other/AlertFrame.java | 9 +- .../ui/frame/other/MercuryLoadingFrame.java | 9 +- .../frame/other/NotificationAlertFrame.java | 8 +- .../ui/frame/other/SetUpLocationFrame.java | 16 +- .../ui/frame/other/SetUpScaleFrame.java | 74 ++-- .../platform/ui/frame/other/TooltipFrame.java | 38 +- .../ui/frame/other/UpdateReadyFrame.java | 16 +- .../ui/frame/setup/SetUpCommander.java | 9 +- .../location/SetUpLocationCommander.java | 32 +- .../setup/scale/SetUpScaleCommander.java | 7 +- .../titled/AbstractTitledComponentFrame.java | 21 +- .../ui/frame/titled/ChatScannerFrame.java | 63 ++-- .../ui/frame/titled/GamePathChooser.java | 32 +- .../ui/frame/titled/HistoryFrame.java | 36 +- .../platform/ui/frame/titled/NotesFrame.java | 101 +++--- .../ui/frame/titled/SettingsFrame.java | 68 ++-- .../ui/frame/titled/TestCasesFrame.java | 29 +- .../platform/ui/frame/titled/TestEngine.java | 26 +- .../platform/ui/frame/titled/TimerFrame.java | 45 +-- .../platform/ui/manager/FramesManager.java | 132 ++++--- .../ui/manager/HideSettingsManager.java | 21 +- .../manager/routing/SettingsRoutManager.java | 16 +- .../platform/ui/misc/AppThemeColor.java | 26 +- .../platform/ui/misc/MercuryStoreUI.java | 2 +- .../platform/ui/misc/note/NotesLoader.java | 18 +- 247 files changed, 3309 insertions(+), 2800 deletions(-) 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 40810050..c7295cc7 100644 --- a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java +++ b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java @@ -2,7 +2,6 @@ import com.mercury.platform.shared.AsSubscriber; import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; import com.mercury.platform.shared.config.descriptor.TaskBarDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.sun.jna.Native; @@ -12,7 +11,6 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; -import java.util.*; public class ChatHelper implements AsSubscriber { private Robot robot; @@ -53,6 +51,7 @@ private void executeMessage(String message) { robot.keyRelease(KeyEvent.VK_ENTER); MercuryStoreCore.blockHotkeySubject.onNext(false); } + private void openChat(String whisper) { this.gameToFront(); StringSelection selection = new StringSelection("@" + whisper); @@ -79,7 +78,8 @@ private void openChat(String whisper) { robot.keyRelease(KeyEvent.VK_SPACE); MercuryStoreCore.blockHotkeySubject.onNext(false); } - private void gameToFront(){ + + private void gameToFront() { User32.INSTANCE.EnumWindows((hWnd, arg1) -> { char[] className = new char[512]; User32.INSTANCE.GetClassName(hWnd, className, 512); @@ -95,16 +95,17 @@ private void gameToFront(){ return true; }, null); } + @Override public void subscribe() { MercuryStoreCore.chatCommandSubject.subscribe(this::executeMessage); MercuryStoreCore.openChatSubject.subscribe(this::openChat); MercuryStoreCore.dndSubject.subscribe(state -> { TaskBarDescriptor config = Configuration.get().taskBarConfiguration().get(); - if(config.isInGameDnd()){ - if(state) { + if (config.isInGameDnd()) { + if (state) { executeMessage("/dnd " + config.getDndResponseText()); - }else { + } else { executeMessage("/dnd"); } } diff --git a/app-core/src/main/java/com/mercury/platform/core/DevStarter.java b/app-core/src/main/java/com/mercury/platform/core/DevStarter.java index 55575552..31e1ea0c 100644 --- a/app-core/src/main/java/com/mercury/platform/core/DevStarter.java +++ b/app-core/src/main/java/com/mercury/platform/core/DevStarter.java @@ -11,6 +11,7 @@ import com.mercury.platform.shared.config.MercuryConfigurationSource; import com.mercury.platform.shared.hotkey.HotKeysInterceptor; import com.mercury.platform.shared.store.MercuryStoreCore; + import java.util.concurrent.Executor; import java.util.concurrent.Executors; diff --git a/app-core/src/main/java/com/mercury/platform/core/ProdStarter.java b/app-core/src/main/java/com/mercury/platform/core/ProdStarter.java index fd11afa6..9af10a94 100644 --- a/app-core/src/main/java/com/mercury/platform/core/ProdStarter.java +++ b/app-core/src/main/java/com/mercury/platform/core/ProdStarter.java @@ -4,12 +4,12 @@ import com.mercury.platform.core.update.UpdateClientStarter; import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.HistoryManager; -import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState; -import com.mercury.platform.shared.hotkey.HotKeysInterceptor; import com.mercury.platform.shared.UpdateManager; -import com.mercury.platform.shared.config.MercuryConfigManager; import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.MercuryConfigManager; import com.mercury.platform.shared.config.MercuryConfigurationSource; +import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState; +import com.mercury.platform.shared.hotkey.HotKeysInterceptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.sun.jna.Native; import com.sun.jna.platform.win32.User32; @@ -29,7 +29,7 @@ public class ProdStarter { private volatile int delay = 100; private boolean updating = false; - public void startApplication(){ + public void startApplication() { MercuryConfigManager configuration = new MercuryConfigManager(new MercuryConfigurationSource()); configuration.load(); Configuration.set(configuration); @@ -48,10 +48,10 @@ public void startApplication(){ timer.schedule(new TimerTask() { @Override public void run() { - if(shutdown){ + if (shutdown) { timer.cancel(); updateClientStarter.shutdown(); - if(updating){ + if (updating) { updateManager.doUpdate(); } System.exit(0); @@ -63,19 +63,19 @@ public void run() { User32.INSTANCE.GetClassName(hwnd, className, 512); User32.INSTANCE.GetWindowText(hwnd, title, 512); - if(Native.toString(title).equals("MercuryTrade ADR")){ + if (Native.toString(title).equals("MercuryTrade ADR")) { MercuryStoreCore.adrVisibleSubject.onNext(AdrVisibleState.SHOW); - }else { + } else { MercuryStoreCore.adrVisibleSubject.onNext(AdrVisibleState.HIDE); } - if(!Native.toString(className).equals("POEWindowClass")){ - if(APP_STATUS == FrameVisibleState.SHOW) { + if (!Native.toString(className).equals("POEWindowClass")) { + if (APP_STATUS == FrameVisibleState.SHOW) { APP_STATUS = FrameVisibleState.HIDE; MercuryStoreCore.frameVisibleSubject.onNext(FrameVisibleState.HIDE); } - }else{ - if(APP_STATUS == FrameVisibleState.HIDE) { + } else { + if (APP_STATUS == FrameVisibleState.HIDE) { try { Thread.sleep(delay); delay = 100; @@ -87,7 +87,7 @@ public void run() { } } } - },0,150); + }, 0, 150); }); MercuryStoreCore.showingDelaySubject.subscribe(state -> this.delay = 300); MercuryStoreCore.shutdownAppSubject.subscribe(state -> this.shutdown = true); diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java index b7e85e9c..e05ed5dd 100644 --- a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java +++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java @@ -13,6 +13,7 @@ public class SoundNotifier { private final Logger logger = LogManager.getLogger(SoundNotifier.class); private boolean dnd = false; + public SoundNotifier() { MercuryStoreCore.soundSubject .compose(DataTransformers.transformSoundData()) @@ -23,20 +24,20 @@ public SoundNotifier() { .subscribe(value -> this.dnd = value); } - private void play(String wavPath, float db){ - if(!dnd && db > -40) { + private void play(String wavPath, float db) { + if (!dnd && db > -40) { ClassLoader classLoader = getClass().getClassLoader(); try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) { Clip clip = AudioSystem.getClip(); clip.open(stream); - if(db != 0.0) { + if (db != 0.0) { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(db); } clip.start(); } catch (Exception e) { - logger.error("Cannot start playing wav file: ",e); + logger.error("Cannot start playing wav file: ", e); } } } diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java index 72d214e0..15c3dc0e 100644 --- a/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java +++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundType.java @@ -2,5 +2,5 @@ public enum SoundType { - MESSAGE,UPDATE,CHAT_SCANNER,CLICKS + MESSAGE, UPDATE, CHAT_SCANNER, CLICKS } diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/WhisperNotifierStatus.java b/app-core/src/main/java/com/mercury/platform/core/misc/WhisperNotifierStatus.java index 415347b5..56aaf01f 100644 --- a/app-core/src/main/java/com/mercury/platform/core/misc/WhisperNotifierStatus.java +++ b/app-core/src/main/java/com/mercury/platform/core/misc/WhisperNotifierStatus.java @@ -20,13 +20,14 @@ public String asPretty() { } }; - public abstract String asPretty(); - public static WhisperNotifierStatus valueOfPretty(String s){ + public static WhisperNotifierStatus valueOfPretty(String s) { for (WhisperNotifierStatus status : WhisperNotifierStatus.values()) { - if(status.asPretty().equals(s)){ + if (status.asPretty().equals(s)) { return status; } } return null; } + + public abstract String asPretty(); } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/UpdateClientStarter.java b/app-core/src/main/java/com/mercury/platform/core/update/UpdateClientStarter.java index 63b23e7f..b2b1b55a 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/UpdateClientStarter.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/UpdateClientStarter.java @@ -15,7 +15,7 @@ /** * Created by Frost on 14.01.2017. */ -public class UpdateClientStarter implements Runnable{ +public class UpdateClientStarter implements Runnable { private static final Logger LOGGER = LogManager.getLogger(UpdateClientStarter.class.getSimpleName()); private static final String JARS_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp"; @@ -25,7 +25,7 @@ public class UpdateClientStarter implements Runnable{ public void run() { updaterClient = new UpdaterClient(MercuryConstants.SERVER_HOST, MercuryConstants.APP_VERSION, MercuryConstants.PORT); updaterClient.registerListener(handler -> { - Files.write(Paths.get(JARS_FILE_PATH + "\\MercuryTrade.jar") , handler.getBytes() , StandardOpenOption.CREATE); + Files.write(Paths.get(JARS_FILE_PATH + "\\MercuryTrade.jar"), handler.getBytes(), StandardOpenOption.CREATE); setMercuryVersion(getIncrementedVersion(MercuryConstants.APP_VERSION)); MercuryStoreCore.updateReadySubject.onNext(true); }); @@ -35,18 +35,21 @@ public void run() { LOGGER.error(e); } } + public synchronized void setMercuryVersion(String mercuryVersion) { String version = mercuryVersion.replace(".", "0"); ApplicationHolder applicationHolder = ApplicationHolder.getInstance(); applicationHolder.setVersion(Integer.valueOf(version)); } - private String getIncrementedVersion(String version){ + + private String getIncrementedVersion(String version) { String replace = version.replace(".", "0"); Integer intVersion = Integer.valueOf(replace); intVersion++; - return String.valueOf(intVersion).replace("0","."); + return String.valueOf(intVersion).replace("0", "."); } - public void shutdown(){ + + public void shutdown() { updaterClient.shutdown(); } } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/bus/UpdaterClientEventBus.java b/app-core/src/main/java/com/mercury/platform/core/update/bus/UpdaterClientEventBus.java index 753d883f..8f064117 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/bus/UpdaterClientEventBus.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/bus/UpdaterClientEventBus.java @@ -5,20 +5,19 @@ /** * Created by Frost on 25.01.2017. */ -public class UpdaterClientEventBus extends EventBus{ +public class UpdaterClientEventBus extends EventBus { private static final UpdaterClientEventBus instance = new UpdaterClientEventBus(); - - public static UpdaterClientEventBus getInstance() { - return instance; - } - private EventBus eventBus; private UpdaterClientEventBus() { this.eventBus = new EventBus(); } + public static UpdaterClientEventBus getInstance() { + return instance; + } + @Override public void register(Object object) { eventBus.register(object); diff --git a/app-core/src/main/java/com/mercury/platform/core/update/bus/event/UpdateReceivedEvent.java b/app-core/src/main/java/com/mercury/platform/core/update/bus/event/UpdateReceivedEvent.java index fe3c1cce..9cf31c1b 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/bus/event/UpdateReceivedEvent.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/bus/event/UpdateReceivedEvent.java @@ -8,7 +8,7 @@ public class UpdateReceivedEvent { private byte[] bytes; - public UpdateReceivedEvent(byte [] bytes) { + public UpdateReceivedEvent(byte[] bytes) { this.bytes = bytes; } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/bus/handlers/UpdateEventHandler.java b/app-core/src/main/java/com/mercury/platform/core/update/bus/handlers/UpdateEventHandler.java index 98130f96..e59b6b1d 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/bus/handlers/UpdateEventHandler.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/bus/handlers/UpdateEventHandler.java @@ -9,5 +9,6 @@ * Created by Frost on 25.01.2017. */ public interface UpdateEventHandler { - @Subscribe void onUpdateReceived(UpdateReceivedEvent jarFile) throws IOException; + @Subscribe + void onUpdateReceived(UpdateReceivedEvent jarFile) throws IOException; } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/UpdaterClient.java b/app-core/src/main/java/com/mercury/platform/core/update/core/UpdaterClient.java index 46340b81..0bd5c584 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/core/UpdaterClient.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/core/UpdaterClient.java @@ -25,6 +25,7 @@ public class UpdaterClient { private EventLoopGroup group; private Channel channel; private boolean connectionEstablished; + public UpdaterClient(String host, String mercuryVersion, int port) { this.host = host; this.port = port; @@ -33,22 +34,22 @@ public UpdaterClient(String host, String mercuryVersion, int port) { connectionEstablished = false; MercuryStoreCore.requestPatchSubject.subscribe(state -> { - if(!connectionEstablished){ + if (!connectionEstablished) { ApplicationHolder.getInstance().setManualRequest(false); MercuryStoreCore.stringAlertSubject.onNext("Server is currently down, please try again later."); - }else { + } else { MercuryStoreCore.checkOutPatchSubject.onNext(true); } }); } - public void start(){ + public void start() { ClientChannelInitializer clientChannelInitializer = new ClientChannelInitializer(); group = new NioEventLoopGroup(); bootstrap = new Bootstrap(); bootstrap.group(group).channel(NioSocketChannel.class) .remoteAddress(new InetSocketAddress(host, port)) - .option(ChannelOption.SO_KEEPALIVE,true) + .option(ChannelOption.SO_KEEPALIVE, true) .handler(clientChannelInitializer) ; try { @@ -58,7 +59,8 @@ public void start(){ } doConnect(); } - private void doConnect(){ + + private void doConnect() { try { ChannelFuture channelFuture = bootstrap.connect(); channelFuture.addListener(new ChannelFutureListener() { @@ -69,7 +71,7 @@ public void operationComplete(ChannelFuture future) throws Exception { future.channel().close(); future.channel().eventLoop().schedule(() -> { bootstrap.connect().addListener(this); - },new Random().nextInt(5),TimeUnit.MINUTES); + }, new Random().nextInt(5), TimeUnit.MINUTES); } else { channel = future.channel(); connectionEstablished = true; @@ -86,22 +88,27 @@ private void addCLoseDetectListener(Channel _channel) { }); } }); - }catch (Exception e){ + } catch (Exception e) { doConnect(); } } + public void shutdown() { try { if (group != null) group.shutdownGracefully().sync(); - }catch (InterruptedException e){} + } catch (InterruptedException e) { + } } + public int getMercuryVersion() { return ApplicationHolder.getInstance().getVersion(); } + public void registerListener(UpdateEventHandler handler) { UpdaterClientEventBus.getInstance().register(handler); } + public void removeListener(UpdateEventHandler handler) { UpdaterClientEventBus.getInstance().unregister(handler); } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ClientHandler.java b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ClientHandler.java index 1df15c66..46c791f6 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ClientHandler.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ClientHandler.java @@ -25,6 +25,7 @@ public class ClientHandler extends SimpleChannelInboundHandler { private ResponseDispatcher responseDispatcher; private ChannelHandlerContext context; + public ClientHandler() { chunks = new byte[0]; responseDispatcher = new ResponseDispatcher(); @@ -35,11 +36,11 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object responseDispatcher.process(object); if (object instanceof Integer) { this.length = (int) object; - this.percentDelta = getPercentOf(this.length,800 * 1024); + this.percentDelta = getPercentOf(this.length, 800 * 1024); } if (object instanceof byte[]) { byte[] bytes = (byte[]) object; - chunks = Bytes.concat(chunks,bytes); + chunks = Bytes.concat(chunks, bytes); MercuryStoreCore.chunkLoadedSubject.onNext(percentDelta); if (chunks.length == length) { UpdateReceivedEvent event = new UpdateReceivedEvent(chunks); @@ -47,16 +48,17 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object } } } - private int getPercentOf(int length, int value){ - return (value * 100)/length; + + private int getPercentOf(int length, int value) { + return (value * 100) / length; } @Override public void channelActive(ChannelHandlerContext context) throws Exception { this.context = context; - if(context != null){ - if(Configuration.get().applicationConfiguration().get().isCheckOutUpdate()) { + if (context != null) { + if (Configuration.get().applicationConfiguration().get().isCheckOutUpdate()) { LOGGER.info("Requesting update info from server"); Integer version = ApplicationHolder.getInstance().getVersion(); context.channel().writeAndFlush(new UpdateDescriptor(UpdateType.REQUEST_INFO, version)); @@ -65,15 +67,17 @@ public void channelActive(ChannelHandlerContext context) throws Exception { MercuryStoreCore.startUpdateSubject.subscribe(state -> this.getLatestUpdate()); } } - private void checkOutPatchNotes(){ + + private void checkOutPatchNotes() { Integer version = ApplicationHolder.getInstance().getVersion(); - if(context != null) { + if (context != null) { LOGGER.debug("Requesting patch notes message from server"); - context.channel().writeAndFlush(new UpdateDescriptor(UpdateType.REQUEST_PATCH_NOTES,version)); + context.channel().writeAndFlush(new UpdateDescriptor(UpdateType.REQUEST_PATCH_NOTES, version)); } } - private void getLatestUpdate(){ - if(context != null) { + + private void getLatestUpdate() { + if (context != null) { LOGGER.debug("Requesting update message from server"); Integer version = ApplicationHolder.getInstance().getVersion(); context.channel().writeAndFlush(new UpdateDescriptor(UpdateType.REQUEST_UPDATE, version)); @@ -92,5 +96,4 @@ public void exceptionCaught(ChannelHandlerContext context, Throwable cause) thro } - } diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java index 45b2a20e..e6b33fcc 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/core/handlers/ResponseDispatcher.java @@ -2,24 +2,23 @@ import com.mercury.platform.core.misc.SoundType; import com.mercury.platform.core.update.core.holder.ApplicationHolder; - import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.update.AlreadyLatestUpdateMessage; import com.mercury.platform.update.PatchNotesDescriptor; import com.mercury.platform.update.UpdateDescriptor; public class ResponseDispatcher { - public void process(Object object){ + public void process(Object object) { if (object instanceof PatchNotesDescriptor) { String notes = ((PatchNotesDescriptor) object).getJson(); MercuryStoreCore.showPatchNotesSubject.onNext(notes); } - if(object instanceof UpdateDescriptor){ + if (object instanceof UpdateDescriptor) { MercuryStoreCore.soundSubject.onNext(SoundType.UPDATE); MercuryStoreCore.updateInfoSubject.onNext(((UpdateDescriptor) object).getVersion()); } - if(object instanceof AlreadyLatestUpdateMessage){ - if(ApplicationHolder.getInstance().isManualRequest()) { + if (object instanceof AlreadyLatestUpdateMessage) { + if (ApplicationHolder.getInstance().isManualRequest()) { ApplicationHolder.getInstance().setManualRequest(false); String message = ((AlreadyLatestUpdateMessage) object).getMessage(); MercuryStoreCore.stringAlertSubject.onNext(message); diff --git a/app-core/src/main/java/com/mercury/platform/core/update/core/holder/ApplicationHolder.java b/app-core/src/main/java/com/mercury/platform/core/update/core/holder/ApplicationHolder.java index 642ad1e1..ea5fa6f0 100644 --- a/app-core/src/main/java/com/mercury/platform/core/update/core/holder/ApplicationHolder.java +++ b/app-core/src/main/java/com/mercury/platform/core/update/core/holder/ApplicationHolder.java @@ -6,6 +6,12 @@ public class ApplicationHolder { private static volatile ApplicationHolder instance; + private volatile int version; + private volatile boolean manualRequest; + + private ApplicationHolder() { + manualRequest = false; + } public static ApplicationHolder getInstance() { ApplicationHolder localInstance = instance; @@ -20,14 +26,6 @@ public static ApplicationHolder getInstance() { return localInstance; } - private volatile int version; - private volatile boolean manualRequest; - - private ApplicationHolder() { - manualRequest = false; - } - - public int getVersion() { return version; } diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/FileMonitor.java b/app-core/src/main/java/com/mercury/platform/core/utils/FileMonitor.java index 4a73dc08..ddf495dc 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/FileMonitor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/FileMonitor.java @@ -12,14 +12,14 @@ import java.io.File; public class FileMonitor { - private Logger logger = LogManager.getLogger(FileMonitor.class.getSimpleName()); - private static final long POLLING_INTERVAL = 350; + private Logger logger = LogManager.getLogger(FileMonitor.class.getSimpleName()); private MessageFileHandler fileHandler; private FileAlterationMonitor monitor; - public FileMonitor(){ + + public FileMonitor() { MercuryStoreCore.poeFolderChangedSubject.subscribe(state -> { - if(monitor != null){ + if (monitor != null) { try { monitor.stop(); } catch (Exception e) { @@ -29,14 +29,15 @@ public FileMonitor(){ } }); } - public void start(){ + + public void start() { String gamePath = Configuration.get().applicationConfiguration().get().getGamePath(); - File folder = new File(gamePath+"logs"); + File folder = new File(gamePath + "logs"); this.fileHandler = new MessageFileHandler(gamePath + "logs/Client.txt"); FileAlterationObserver observer = new FileAlterationObserver(folder); monitor = new FileAlterationMonitor(POLLING_INTERVAL); - FileAlterationListener listener = new FileAlterationListenerAdaptor(){ + FileAlterationListener listener = new FileAlterationListenerAdaptor() { @Override public void onFileChange(File file) { fileHandler.parse(); 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 c2d511c2..3927ed0a 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 @@ -9,7 +9,10 @@ import java.io.File; import java.io.RandomAccessFile; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -69,10 +72,10 @@ public void parse() { .collect(Collectors.toList()); List resultMessages = filteredMessages.stream().filter(message -> { - if(message.contains("2017") || message.contains("2018")) { //todo + if (message.contains("2017") || message.contains("2018")) { //todo Date date = new Date(StringUtils.substring(message, 0, 20)); return date.after(lastMessageDate); - }else { + } else { return false; } }).collect(Collectors.toList()); diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java index 9e534bbf..718917b9 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/error/ErrorHandler.java @@ -7,7 +7,8 @@ public class ErrorHandler { private Logger logger = LogManager.getLogger(ErrorHandler.class.getSimpleName()); - public ErrorHandler(){ + + public ErrorHandler() { Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { logger.error(ExceptionUtils.getStackTrace(throwable)); }); diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/MessageInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/MessageInterceptor.java index ea5051fa..a51db34b 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/MessageInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/MessageInterceptor.java @@ -11,13 +11,16 @@ public abstract class MessageInterceptor { public MessageInterceptor() { filter = getFilter(); } - public boolean match(String message){ - if(filter.isMatching(message)){ + + public boolean match(String message) { + if (filter.isMatching(message)) { process(message); return true; } return false; } + protected abstract void process(String message); + protected abstract MessageFilter getFilter(); } 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 index 9d0d51af..6531c748 100644 --- 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 @@ -11,7 +11,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class PlainMessageInterceptor extends MessageInterceptor{ +public class PlainMessageInterceptor extends MessageInterceptor { private List clients = new ArrayList<>(); public PlainMessageInterceptor() { @@ -30,7 +30,7 @@ protected void process(String message) { LocalizationMatcher localizationMatcher = this.clients.stream() .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null); - if(localizationMatcher != null){ + if (localizationMatcher != null) { localizationMatcher.processMessage(message); } } @@ -42,14 +42,18 @@ protected MessageFilter getFilter() { .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){ + + public void processMessage(String message) { Pattern pattern = Pattern.compile("^(\\<.+?\\>)?\\s?(.+?):(.+)$"); Matcher matcher = pattern.matcher(this.trimString(message)); - if(matcher.find()){ + if (matcher.find()) { PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); descriptor.setNickName(matcher.group(2)); descriptor.setMessage(matcher.group(3)); @@ -58,6 +62,7 @@ public void processMessage(String message){ } } } + private class EngIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { @@ -71,10 +76,11 @@ public boolean isIncoming() { @Override public String trimString(String message) { - return StringUtils.substringAfter(message,"@From "); + return StringUtils.substringAfter(message, "@From "); } } - private class EngOutLocalizationMatcher extends LocalizationMatcher{ + + private class EngOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@To"); @@ -87,10 +93,11 @@ public boolean isIncoming() { @Override public String trimString(String message) { - return StringUtils.substringAfter(message,"@To "); + return StringUtils.substringAfter(message, "@To "); } } - private class RuIncLocalizationMatcher extends LocalizationMatcher{ + + private class RuIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@От кого"); @@ -103,10 +110,11 @@ public boolean isIncoming() { @Override public String trimString(String message) { - return StringUtils.substringAfter(message,"@От кого "); + return StringUtils.substringAfter(message, "@От кого "); } } - private class RuOutLocalizationMatcher extends LocalizationMatcher{ + + private class RuOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@Кому"); @@ -123,7 +131,8 @@ public String trimString(String src) { } } - private class ArabicInLocalizationMatcher extends LocalizationMatcher{ + + private class ArabicInLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@จาก"); @@ -139,7 +148,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@จาก"); } } - private class ArabicOutLocalizationMatcher extends LocalizationMatcher{ + + private class ArabicOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@ถึง"); @@ -155,7 +165,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@ถึง"); } } - private class BZIncLocalizationMatcher extends LocalizationMatcher{ + + private class BZIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@De"); @@ -171,7 +182,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@De"); } } - private class BZOutLocalizationMatcher extends LocalizationMatcher{ + + private class BZOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@Para"); diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerJoinInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerJoinInterceptor.java index 7d2b91b0..9776f9c9 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerJoinInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerJoinInterceptor.java @@ -7,7 +7,7 @@ public class PlayerJoinInterceptor extends MessageInterceptor { @Override protected void process(String message) { - MercuryStoreCore.playerJoinSubject.onNext(StringUtils.substringBetween(message," : ", " has joined the area.")); + MercuryStoreCore.playerJoinSubject.onNext(StringUtils.substringBetween(message, " : ", " has joined the area.")); } @Override diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerLeftInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerLeftInterceptor.java index 814482ce..8c838eb5 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerLeftInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerLeftInterceptor.java @@ -8,7 +8,7 @@ public class PlayerLeftInterceptor extends MessageInterceptor { @Override protected void process(String message) { - MercuryStoreCore.playerLeftSubject.onNext(StringUtils.substringBetween(message," : ", " has left the area.")); + MercuryStoreCore.playerLeftSubject.onNext(StringUtils.substringBetween(message, " : ", " has left the area.")); } @Override diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java index d3126b63..30f76030 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/TradeIncMessagesInterceptor.java @@ -6,9 +6,7 @@ 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 net.jodah.expiringmap.ExpiringMap; import org.apache.commons.lang3.StringUtils; @@ -23,7 +21,7 @@ public class TradeIncMessagesInterceptor extends MessageInterceptor { private MessageParser messageParser = new MessageParser(); private PlainConfigurationService config; private List clients = new ArrayList<>(); - private Map expiresMessages; + private Map expiresMessages; public TradeIncMessagesInterceptor() { this.config = Configuration.get().notificationConfiguration(); @@ -35,17 +33,17 @@ public TradeIncMessagesInterceptor() { .expiration(1, TimeUnit.HOURS) .build(); MercuryStoreCore.expiredNotificationSubject.subscribe(notificationDescriptor -> { - this.expiresMessages.put(UUID.randomUUID().toString(),StringUtils.substringAfter(notificationDescriptor.getSourceString(),":")); + this.expiresMessages.put(UUID.randomUUID().toString(), StringUtils.substringAfter(notificationDescriptor.getSourceString(), ":")); }); } @Override protected void process(String message) { - if(this.config.get().isIncNotificationEnable()) { + if (this.config.get().isIncNotificationEnable()) { LocalizationMatcher localizationMatcher = this.clients.stream() .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null); - if(localizationMatcher != null){ + if (localizationMatcher != null) { localizationMatcher.processMessage(message); } } @@ -58,26 +56,31 @@ protected MessageFilter getFilter() { .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null) != null; } + private abstract class LocalizationMatcher { - public boolean isSuitableFor(String message){ + 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){ + + public NotificationDescriptor getDescriptor(String message) { return messageParser.parse(this.trimString(message)); } - public void processMessage(String message){ + + public void processMessage(String message) { NotificationDescriptor notificationDescriptor = this.getDescriptor(message); if (notificationDescriptor != null) { - if(!expiresMessages.containsValue(StringUtils.substringAfter(notificationDescriptor.getSourceString(),":"))) { + if (!expiresMessages.containsValue(StringUtils.substringAfter(notificationDescriptor.getSourceString(), ":"))) { MercuryStoreCore.soundSubject.onNext(SoundType.MESSAGE); MercuryStoreCore.newNotificationSubject.onNext(notificationDescriptor); } } } } + private class EngIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { @@ -89,7 +92,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@From"); } } - private class RuIncLocalizationMatcher extends LocalizationMatcher{ + + private class RuIncLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@От кого") && super.isSuitableFor(message); @@ -100,7 +104,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@От кого"); } } - private class ArabicInLocalizationMatcher extends LocalizationMatcher{ + + private class ArabicInLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@จาก") && super.isSuitableFor(message); @@ -111,7 +116,8 @@ public String trimString(String src) { return StringUtils.substringAfter(src, "@จาก"); } } - private class BZIncLocalizationMatcher 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 index 447d94c7..19bbaa90 100644 --- 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 @@ -1,6 +1,5 @@ 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; @@ -30,11 +29,11 @@ public TradeOutMessagesInterceptor() { @Override protected void process(String message) { - if(this.config.get().isOutNotificationEnable()) { + if (this.config.get().isOutNotificationEnable()) { LocalizationMatcher localizationMatcher = this.clients.stream() .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null); - if(localizationMatcher != null){ + if (localizationMatcher != null) { localizationMatcher.processMessage(message); } } @@ -47,17 +46,21 @@ protected MessageFilter getFilter() { .filter(matcher -> matcher.isSuitableFor(message)) .findAny().orElse(null) != null; } + private abstract class LocalizationMatcher { - public boolean isSuitableFor(String message){ + 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){ + + public NotificationDescriptor getDescriptor(String message) { return messageParser.parse(this.trimString(message)); } - public void processMessage(String message){ + + public void processMessage(String message) { NotificationDescriptor notificationDescriptor = this.getDescriptor(message); if (notificationDescriptor != null) { MercuryStoreCore.newNotificationSubject.onNext(notificationDescriptor); @@ -65,7 +68,7 @@ public void processMessage(String message){ } } - private class EngOutLocalizationMatcher extends LocalizationMatcher{ + private class EngOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@To") && super.isSuitableFor(message); @@ -79,15 +82,16 @@ public String trimString(String src) { @Override public NotificationDescriptor getDescriptor(String message) { NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); - if(descriptor instanceof ItemTradeNotificationDescriptor){ + if (descriptor instanceof ItemTradeNotificationDescriptor) { descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); - }else { + } else { descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); } return descriptor; } } - private class RuOutLocalizationMatcher extends LocalizationMatcher{ + + private class RuOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@Кому") && super.isSuitableFor(message); @@ -101,15 +105,16 @@ public String trimString(String src) { @Override public NotificationDescriptor getDescriptor(String message) { NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); - if(descriptor instanceof ItemTradeNotificationDescriptor){ + if (descriptor instanceof ItemTradeNotificationDescriptor) { descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); - }else { + } else { descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); } return descriptor; } } - private class ArabicOutLocalizationMatcher extends LocalizationMatcher{ + + private class ArabicOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@ถึง") && super.isSuitableFor(message); @@ -123,15 +128,16 @@ public String trimString(String src) { @Override public NotificationDescriptor getDescriptor(String message) { NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); - if(descriptor instanceof ItemTradeNotificationDescriptor){ + if (descriptor instanceof ItemTradeNotificationDescriptor) { descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); - }else { + } else { descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); } return descriptor; } } - private class BZOutLocalizationMatcher extends LocalizationMatcher{ + + private class BZOutLocalizationMatcher extends LocalizationMatcher { @Override public boolean isSuitableFor(String message) { return message.contains("@Para") && super.isSuitableFor(message); @@ -145,9 +151,9 @@ public String trimString(String src) { @Override public NotificationDescriptor getDescriptor(String message) { NotificationDescriptor descriptor = messageParser.parse(this.trimString(message)); - if(descriptor instanceof ItemTradeNotificationDescriptor){ + if (descriptor instanceof ItemTradeNotificationDescriptor) { descriptor.setType(NotificationType.OUT_ITEM_MESSAGE); - }else { + } else { descriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); } return descriptor; diff --git a/app-core/src/main/java/com/mercury/platform/experimental/PerformanceHelper.java b/app-core/src/main/java/com/mercury/platform/experimental/PerformanceHelper.java index 1770b5bd..04a02825 100644 --- a/app-core/src/main/java/com/mercury/platform/experimental/PerformanceHelper.java +++ b/app-core/src/main/java/com/mercury/platform/experimental/PerformanceHelper.java @@ -4,12 +4,14 @@ public class PerformanceHelper { private long currentValue = 0; private long currentTime = System.currentTimeMillis(); - public void step(String msg){ + + public void step(String msg) { this.currentValue += System.currentTimeMillis() - currentTime; this.currentTime = System.currentTimeMillis(); - System.out.println(msg + " : " +this.currentValue); + System.out.println(msg + " : " + this.currentValue); } - public void reset(){ + + public void reset() { this.currentValue = 0; this.currentTime = System.currentTimeMillis(); } diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java index 570e012f..0c52a108 100644 --- a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java +++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaBasic.java @@ -11,7 +11,8 @@ public class RxJavaBasic { public static void main(String[] args) { method5(); } - public static void method1(){ + + public static void method1() { Observable observable = Observable.create(subscriber -> { subscriber.onNext("Hello World!"); subscriber.onCompleted(); @@ -35,27 +36,31 @@ public void onNext(String s) { }; observable.subscribe(subscriber); } - public static void method2(){ + + public static void method2() { Observable observable = Observable.just("Hello world"); Action1 onNextAction = System.out::println; observable.subscribe(onNextAction); } - public static void method3(){ + + public static void method3() { Observable.just("Hello world").subscribe(System.out::println); } //Operators - public static void method4(){ + public static void method4() { Observable.just("Hello world").map(s -> s + " -Dan").subscribe(System.out::println); } - public static void method5(){ + + public static void method5() { Observable.just("Hello world") .map(s -> s + " -Dan") .map(String::hashCode) .map(i -> Integer.toString(i)) .subscribe(System.out::println); } - public static void method6(){ + + public static void method6() { Observable.just("Hello world").subscribe(System.out::println); } } diff --git a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java index 3a7b1077..eea4ca02 100644 --- a/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java +++ b/app-core/src/main/java/com/mercury/platform/experimental/RxJavaOperators.java @@ -7,16 +7,20 @@ public class RxJavaOperators { public static void main(String[] args) { } - public static void method1(){ + + public static void method1() { } - public static void method2(){ + + public static void method2() { } - public static void method3(){ + + public static void method3() { } - public static void method4(){ + + public static void method4() { } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/CloneHelper.java b/app-core/src/main/java/com/mercury/platform/shared/CloneHelper.java index f4dce66c..82bf67f7 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/CloneHelper.java +++ b/app-core/src/main/java/com/mercury/platform/shared/CloneHelper.java @@ -7,7 +7,8 @@ public class CloneHelper { private static Logger log = LogManager.getLogger("CloneHelper"); - public static T cloneObject(T source){ + + public static T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -18,7 +19,7 @@ public static T cloneObject(T source){ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); - cloned = (T)ois.readObject(); + cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java index d5286d9f..0d6e0024 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java +++ b/app-core/src/main/java/com/mercury/platform/shared/FrameVisibleState.java @@ -4,5 +4,5 @@ * Created by Константин on 09.12.2016. */ public enum FrameVisibleState { - SHOW,HIDE + SHOW, HIDE } diff --git a/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java b/app-core/src/main/java/com/mercury/platform/shared/HistoryManager.java index 75cbcea8..9106e407 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 @@ -14,28 +14,21 @@ import java.util.Arrays; public class HistoryManager { - private Logger logger = LogManager.getLogger(HistoryManager.class); - - private static class HistoryManagerHolder { - static final HistoryManager HOLDER_INSTANCE = new HistoryManager(); - } public static HistoryManager INSTANCE = HistoryManager.HistoryManagerHolder.HOLDER_INSTANCE; - private final String HISTORY_FILE = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\history.json"; - + private Logger logger = LogManager.getLogger(HistoryManager.class); private String[] messages; private int curIndex = 0; - public HistoryManager() { messages = new String[0]; } - public void load(){ + public void load() { File configFile = new File(HISTORY_FILE); if (configFile.exists()) { JSONParser parser = new JSONParser(); try { - JSONObject root = (JSONObject)parser.parse(new FileReader(HISTORY_FILE)); + JSONObject root = (JSONObject) parser.parse(new FileReader(HISTORY_FILE)); JSONArray msgsArray = (JSONArray) root.get("messages"); messages = new String[msgsArray.size()]; for (int i = 0; i < msgsArray.size(); i++) { @@ -44,11 +37,12 @@ public void load(){ } catch (Exception e) { logger.error("Error during loading history file: ", e); } - }else { + } else { createEmptyFile(); } } - private void createEmptyFile(){ + + private void createEmptyFile() { try { FileWriter fileWriter = new FileWriter(HISTORY_FILE); JSONObject root = new JSONObject(); @@ -60,13 +54,14 @@ private void createEmptyFile(){ logger.error("Error during creating history file: ", e); } } - public void add(NotificationDescriptor notificationDescriptor){ + + public void add(NotificationDescriptor notificationDescriptor) { JSONParser parser = new JSONParser(); try { - JSONObject root = (JSONObject)parser.parse(new FileReader(HISTORY_FILE)); + JSONObject root = (JSONObject) parser.parse(new FileReader(HISTORY_FILE)); JSONArray msgsArray = (JSONArray) root.get("messages"); msgsArray.add(0, notificationDescriptor.getSourceString()); - root.replace("messages",msgsArray); + root.replace("messages", msgsArray); FileWriter fileWriter = new FileWriter(HISTORY_FILE); fileWriter.write(root.toJSONString()); fileWriter.flush(); @@ -76,15 +71,16 @@ public void add(NotificationDescriptor notificationDescriptor){ logger.error("Error during adding message to history file: ", e); } } - public void clear(){ + + public void clear() { curIndex = 0; messages = new String[0]; JSONParser parser = new JSONParser(); try { - JSONObject root = (JSONObject)parser.parse(new FileReader(HISTORY_FILE)); + JSONObject root = (JSONObject) parser.parse(new FileReader(HISTORY_FILE)); JSONArray msgsArray = (JSONArray) root.get("messages"); msgsArray.clear(); - root.replace("messages",msgsArray); + root.replace("messages", msgsArray); FileWriter fileWriter = new FileWriter(HISTORY_FILE); fileWriter.write(root.toJSONString()); fileWriter.flush(); @@ -93,16 +89,21 @@ public void clear(){ logger.error("Error during creating history file: ", e); } } - public String[] fetchNext(int messagesCount){ + + public String[] fetchNext(int messagesCount) { String[] chunk = new String[0]; - if((curIndex + messagesCount) < messages.length){ + if ((curIndex + messagesCount) < messages.length) { chunk = Arrays.copyOfRange(messages, curIndex, curIndex + messagesCount); curIndex += messagesCount; - }else if((messages.length - curIndex) > 0){ + } else if ((messages.length - curIndex) > 0) { int availableCount = messages.length - curIndex; chunk = Arrays.copyOfRange(messages, curIndex, curIndex + availableCount); curIndex += availableCount; } return chunk; } + + private static class HistoryManagerHolder { + static final HistoryManager HOLDER_INSTANCE = new HistoryManager(); + } } 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 039954a0..37eb4e69 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 @@ -7,6 +7,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; + public class MessageParser { private final static String poeTradeStashTabPattern = "^(.*\\s)?(.+):.+ to buy your\\s+?(.+?)(\\s+?listed for\\s+?([\\d\\.]+?)\\s+?(.+))?\\s+?in\\s+?(.+?)\\s+?\\(stash tab \"(.*)\"; position: left (\\d+), top (\\d+)\\)\\s*?(.*)$"; private final static String poeTradePattern = "^(.*\\s)?(.+):.+ to buy your\\s+?(.+?)(\\s+?listed for\\s+?([\\d\\.]+?)\\s+?(.+))?\\s+?in\\s+?(.*?)$"; @@ -24,22 +25,22 @@ public MessageParser() { this.poeTradeCurrencyPattern = Pattern.compile(poeCurrencyPattern); } - public NotificationDescriptor parse(String fullMessage){ + public NotificationDescriptor parse(String fullMessage) { Matcher poeAppItemMatcher = poeAppItemPattern.matcher(fullMessage); - if(poeAppItemMatcher.find()){ + if (poeAppItemMatcher.find()) { ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); tradeNotification.setSourceString(fullMessage); tradeNotification.setWhisperNickname(poeAppItemMatcher.group(2)); tradeNotification.setItemName(poeAppItemMatcher.group(3)); - if(poeAppItemMatcher.group(5) != null) { + if (poeAppItemMatcher.group(5) != null) { tradeNotification.setCurCount(Double.parseDouble(poeAppItemMatcher.group(5))); tradeNotification.setCurrency(poeAppItemMatcher.group(6)); - }else { + } else { tradeNotification.setCurCount(0d); tradeNotification.setCurrency("???"); } tradeNotification.setLeague(poeAppItemMatcher.group(7)); - if(poeAppItemMatcher.group(8) != null) { + if (poeAppItemMatcher.group(8) != null) { tradeNotification.setTabName(poeAppItemMatcher.group(8)); tradeNotification.setLeft(Integer.parseInt(poeAppItemMatcher.group(9))); tradeNotification.setTop(Integer.parseInt(poeAppItemMatcher.group(10))); @@ -49,15 +50,15 @@ public NotificationDescriptor parse(String fullMessage){ return tradeNotification; } Matcher poeTradeStashItemMatcher = poeTradeStashItemPattern.matcher(fullMessage); - if(poeTradeStashItemMatcher.find()){ + if (poeTradeStashItemMatcher.find()) { ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); tradeNotification.setSourceString(fullMessage); tradeNotification.setWhisperNickname(poeTradeStashItemMatcher.group(2)); tradeNotification.setItemName(poeTradeStashItemMatcher.group(3)); - if(poeTradeStashItemMatcher.group(4) != null){ + if (poeTradeStashItemMatcher.group(4) != null) { tradeNotification.setCurCount(Double.parseDouble(poeTradeStashItemMatcher.group(5))); tradeNotification.setCurrency(poeTradeStashItemMatcher.group(6)); - }else { + } else { tradeNotification.setCurCount(0d); tradeNotification.setCurrency("???"); } @@ -70,7 +71,7 @@ public NotificationDescriptor parse(String fullMessage){ return tradeNotification; } Matcher poeTradeCurrencyMatcher = poeTradeCurrencyPattern.matcher(fullMessage); - if(poeTradeCurrencyMatcher.find()){ + if (poeTradeCurrencyMatcher.find()) { CurrencyTradeNotificationDescriptor tradeNotification = new CurrencyTradeNotificationDescriptor(); tradeNotification.setSourceString(fullMessage); tradeNotification.setWhisperNickname(poeTradeCurrencyMatcher.group(2)); @@ -84,15 +85,15 @@ public NotificationDescriptor parse(String fullMessage){ return tradeNotification; } Matcher poeTradeItemMatcher = poeTradeItemPattern.matcher(fullMessage); - if(poeTradeItemMatcher.find()){ + if (poeTradeItemMatcher.find()) { ItemTradeNotificationDescriptor tradeNotification = new ItemTradeNotificationDescriptor(); tradeNotification.setSourceString(fullMessage); tradeNotification.setWhisperNickname(poeTradeItemMatcher.group(2)); tradeNotification.setItemName(poeTradeItemMatcher.group(3)); - if(poeTradeItemMatcher.group(4) != null){ + if (poeTradeItemMatcher.group(4) != null) { tradeNotification.setCurCount(Double.parseDouble(poeTradeItemMatcher.group(5))); tradeNotification.setCurrency(poeTradeItemMatcher.group(6)); - }else { + } else { tradeNotification.setCurCount(0d); tradeNotification.setCurrency("???"); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java index c06d0100..ecc3b832 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/UpdateManager.java @@ -10,11 +10,12 @@ public class UpdateManager { private final static Logger logger = LogManager.getLogger(UpdateManager.class.getSimpleName()); private final static String LOCAL_UPDATER_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\local-updater.jar"; private static final String JAR_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp\\MercuryTrade.jar"; - public void doUpdate(){ + + public void doUpdate() { try { String path = StringUtils.substringAfter(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath(), "/"); - logger.debug("Execute local updater, source path: {}",path); - if(new File(JAR_FILE_PATH).exists()) { + logger.debug("Execute local updater, source path: {}", path); + if (new File(JAR_FILE_PATH).exists()) { Runtime.getRuntime().exec("java -jar " + LOCAL_UPDATER_PATH + " " + "\"" + path + "\""); System.exit(0); } 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 97e5bf19..63b06d52 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 @@ -2,23 +2,32 @@ import com.mercury.platform.shared.config.configration.*; 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 java.util.List; public interface ConfigManager { FramesConfigurationService framesConfiguration(); + PlainConfigurationService applicationConfiguration(); + PlainConfigurationService notificationConfiguration(); + PlainConfigurationService taskBarConfiguration(); + PlainConfigurationService scannerConfiguration(); - KeyValueConfigurationService soundConfiguration(); - KeyValueConfigurationService scaleConfiguration(); + + KeyValueConfigurationService soundConfiguration(); + + KeyValueConfigurationService scaleConfiguration(); + PlainConfigurationService hotKeysConfiguration(); + AdrConfigurationService adrConfiguration(); + ListConfigurationService stashTabConfiguration(); + IconBundleConfigurationService iconBundleConfiguration(); + List profiles(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java index ea4c0529..8018d6f4 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/Configuration.java @@ -2,10 +2,12 @@ public class Configuration { private static ConfigManager configManager; + public static ConfigManager get() { return configManager; } - public static void set(ConfigManager configManager){ + + public static void set(ConfigManager configManager) { Configuration.configManager = configManager; } } 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 fac290c9..3b046197 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 @@ -6,7 +6,6 @@ import com.mercury.platform.shared.config.configration.impl.*; 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.json.JSONHelper; import com.mercury.platform.shared.store.MercuryStoreCore; import org.apache.commons.io.FileUtils; @@ -16,7 +15,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; import java.util.List; @@ -32,8 +31,8 @@ public class MercuryConfigManager implements ConfigManager, AsSubscriber { private PlainConfigurationService notificationConfigurationService; private PlainConfigurationService taskBarConfigurationService; private PlainConfigurationService scannerConfigurationService; - private KeyValueConfigurationService soundConfigurationService; - private KeyValueConfigurationService scaleConfigurationService; + private KeyValueConfigurationService soundConfigurationService; + private KeyValueConfigurationService scaleConfigurationService; private PlainConfigurationService hotKeyConfigurationService; private ListConfigurationService stashTabConfigurationService; private IconBundleConfigurationService iconBundleConfigurationService; @@ -41,11 +40,12 @@ public class MercuryConfigManager implements ConfigManager, AsSubscriber { private List services = new ArrayList<>(); - public MercuryConfigManager(ConfigurationSource dataSource){ + public MercuryConfigManager(ConfigurationSource dataSource) { this.dataSource = dataSource; this.jsonHelper = new JSONHelper(dataSource.getConfigurationFilePath()); this.subscribe(); } + @Override public FramesConfigurationService framesConfiguration() { return this.framesConfigurationService; @@ -72,12 +72,12 @@ public PlainConfigurationService scannerConfiguration() { } @Override - public KeyValueConfigurationService soundConfiguration() { + public KeyValueConfigurationService soundConfiguration() { return this.soundConfigurationService; } @Override - public KeyValueConfigurationService scaleConfiguration() { + public KeyValueConfigurationService scaleConfiguration() { return this.scaleConfigurationService; } @@ -107,12 +107,12 @@ public List profiles() { } - public void load(){ + public void load() { try { File configFile = new File(dataSource.getConfigurationFilePath()); File configFolder = new File(dataSource.getConfigurationPath()); File iconFolder = new File(dataSource.getConfigurationPath() + "\\icons"); - if(!configFolder.exists() || !configFile.exists() || !iconFolder.exists()) { + if (!configFolder.exists() || !configFile.exists() || !iconFolder.exists()) { new File(dataSource.getConfigurationPath() + "\\temp").mkdir(); new File(dataSource.getConfigurationPath() + "\\icons").mkdir(); new File(dataSource.getConfigurationFilePath()).createNewFile(); @@ -120,24 +120,27 @@ public void load(){ ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream resourceAsStream = classLoader.getResourceAsStream("app/local-updater.jar"); File dest = new File(dataSource.getConfigurationPath() + "\\local-updater.jar"); - FileUtils.copyInputStreamToFile(resourceAsStream,dest); + FileUtils.copyInputStreamToFile(resourceAsStream, dest); } - this.profileDescriptors = this.jsonHelper.readArrayData(new TypeToken>(){}); - if(this.profileDescriptors == null){ + this.profileDescriptors = this.jsonHelper.readArrayData(new TypeToken>() { + }); + if (this.profileDescriptors == null) { this.profileDescriptors = new ArrayList<>(); ProfileDescriptor defaultProfile = this.getDefaultProfile(); this.selectedProfile = defaultProfile; this.profileDescriptors.add(defaultProfile); - this.jsonHelper.writeListObject(this.profileDescriptors,new TypeToken>(){}); - }else { + this.jsonHelper.writeListObject(this.profileDescriptors, new TypeToken>() { + }); + } else { this.selectedProfile = this.profileDescriptors.stream() .filter(ProfileDescriptor::isSelected) .findAny().orElse(null); - if(this.selectedProfile == null){ + if (this.selectedProfile == null) { ProfileDescriptor defaultProfile = this.getDefaultProfile(); this.selectedProfile = defaultProfile; this.profileDescriptors.add(defaultProfile); - this.jsonHelper.writeListObject(this.profileDescriptors,new TypeToken>(){}); + this.jsonHelper.writeListObject(this.profileDescriptors, new TypeToken>() { + }); } } @@ -168,16 +171,18 @@ public void load(){ this.services.forEach(BaseConfigurationService::validate); - this.jsonHelper.writeListObject(this.profileDescriptors,new TypeToken>(){}); - }catch (IOException e) { - logger.error("Error while processing file:{}",dataSource.getConfigurationPath(),e); + this.jsonHelper.writeListObject(this.profileDescriptors, new TypeToken>() { + }); + } catch (IOException e) { + logger.error("Error while processing file:{}", dataSource.getConfigurationPath(), e); } } @Override public void subscribe() { MercuryStoreCore.saveConfigSubject.subscribe(state -> { - this.jsonHelper.writeListObject(this.profileDescriptors,new TypeToken>(){}); + this.jsonHelper.writeListObject(this.profileDescriptors, new TypeToken>() { + }); }); MercuryStoreCore.toDefaultSubject.subscribe(state -> { this.services.forEach(BaseConfigurationService::toDefault); @@ -190,10 +195,12 @@ public void subscribe() { service.setSelectedProfile(profile); service.validate(); }); - this.jsonHelper.writeListObject(this.profileDescriptors,new TypeToken>(){}); + this.jsonHelper.writeListObject(this.profileDescriptors, new TypeToken>() { + }); }); } - private ProfileDescriptor getDefaultProfile(){ + + private ProfileDescriptor getDefaultProfile() { ProfileDescriptor defaultProfile = new ProfileDescriptor(); defaultProfile.setSelected(true); defaultProfile.setName("Profile1"); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/AdrConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/AdrConfigurationService.java index 720a0552..25c31dd8 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/AdrConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/AdrConfigurationService.java @@ -3,10 +3,14 @@ import com.mercury.platform.shared.config.descriptor.adr.*; -public interface AdrConfigurationService extends ListConfigurationService{ +public interface AdrConfigurationService extends ListConfigurationService { AdrIconDescriptor getDefaultIcon(); + AdrProgressBarDescriptor getDefaultProgressBar(); + AdrTrackerGroupDescriptor getDefaultIconGroup(); + AdrTrackerGroupDescriptor getDefaultPBGroup(); + AdrCaptureDescriptor getDefaultCapture(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/BaseConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/BaseConfigurationService.java index c5f26a83..eba712c3 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/BaseConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/BaseConfigurationService.java @@ -5,11 +5,14 @@ import lombok.Setter; -public abstract class BaseConfigurationService implements HasDefault{ - @Getter @Setter +public abstract class BaseConfigurationService implements HasDefault { + @Getter + @Setter protected ProfileDescriptor selectedProfile; - public BaseConfigurationService(ProfileDescriptor selectedProfile){ + + public BaseConfigurationService(ProfileDescriptor selectedProfile) { this.selectedProfile = selectedProfile; } + public abstract void validate(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/ConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/ConfigurationService.java index 947f0d9a..0aa731eb 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/ConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/ConfigurationService.java @@ -1,5 +1,5 @@ package com.mercury.platform.shared.config.configration; -public interface ConfigurationService{ +public interface ConfigurationService { void validate(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/FramesConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/FramesConfigurationService.java index f73edce2..06c56476 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/FramesConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/FramesConfigurationService.java @@ -5,6 +5,6 @@ import java.awt.*; -public interface FramesConfigurationService extends KeyValueConfigurationService { +public interface FramesConfigurationService extends KeyValueConfigurationService { Dimension getMinimumSize(String frameClass); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/HasDefault.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/HasDefault.java index a1f0121f..ff012174 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/HasDefault.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/HasDefault.java @@ -3,5 +3,6 @@ public interface HasDefault { T getDefault(); + void toDefault(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/IconBundleConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/IconBundleConfigurationService.java index 61652695..2e1308c3 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/IconBundleConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/IconBundleConfigurationService.java @@ -6,8 +6,12 @@ public interface IconBundleConfigurationService extends ListConfigurationService { URL getIcon(String iconPath); + List getDefaultBundle(); - Map getIconBundle(); + + Map getIconBundle(); + void addIcon(String iconPath); + void removeIcon(String iconPath); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/KeyValueConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/KeyValueConfigurationService.java index b60dc798..5b8449f2 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/KeyValueConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/KeyValueConfigurationService.java @@ -5,6 +5,8 @@ public interface KeyValueConfigurationService { T get(K key); - Map getMap(); - void set(Map map); + + Map getMap(); + + void set(Map map); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/PlainConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/PlainConfigurationService.java index 33f2e84a..85c120cc 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/PlainConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/PlainConfigurationService.java @@ -3,5 +3,6 @@ public interface PlainConfigurationService { T get(); + void set(T descriptor); } 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 198b89e8..4bd8c471 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 @@ -6,9 +6,6 @@ import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; -import java.util.HashMap; -import java.util.Map; - public class ApplicationConfigurationService extends BaseConfigurationService implements PlainConfigurationService { public ApplicationConfigurationService(ProfileDescriptor selectedProfile) { @@ -17,7 +14,7 @@ public ApplicationConfigurationService(ProfileDescriptor selectedProfile) { @Override public void validate() { - if(this.selectedProfile.getApplicationDescriptor() == null) { + if (this.selectedProfile.getApplicationDescriptor() == null) { this.selectedProfile.setApplicationDescriptor(this.getDefault()); } } 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 9cd009df..c1fff92f 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 @@ -11,9 +11,10 @@ import java.util.Map; -public class FramesConfigurationServiceImpl extends BaseConfigurationService> implements FramesConfigurationService { +public class FramesConfigurationServiceImpl extends BaseConfigurationService> implements FramesConfigurationService { private Map minimumFrameSize = new HashMap<>(); private Map defaultFramesSettings = new HashMap<>(); + public FramesConfigurationServiceImpl(ProfileDescriptor selectedProfile) { super(selectedProfile); this.initMinimumMap(); @@ -22,14 +23,15 @@ public FramesConfigurationServiceImpl(ProfileDescriptor selectedProfile) { @Override public void validate() { - if(this.selectedProfile.getFrameDescriptorMap() == null) { + if (this.selectedProfile.getFrameDescriptorMap() == null) { this.selectedProfile.setFrameDescriptorMap(this.getDefault()); } } + @Override public FrameDescriptor get(String key) { return this.selectedProfile.getFrameDescriptorMap().computeIfAbsent(key, k -> { - this.selectedProfile.getFrameDescriptorMap().put(key,this.getDefault().get(key)); + this.selectedProfile.getFrameDescriptorMap().put(key, this.getDefault().get(key)); MercuryStoreCore.saveConfigSubject.onNext(true); return this.getDefault().get(key); }); @@ -61,28 +63,29 @@ public Dimension getMinimumSize(String frameClass) { } private void initMinimumMap() { - minimumFrameSize.put("TaskBarFrame",new Dimension(109,20)); - 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("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)); - minimumFrameSize.put("GamePathChooser",new Dimension(600,30)); - minimumFrameSize.put("CurrencySearchFrame",new Dimension(400,300)); - minimumFrameSize.put("AdrManagerFrame",new Dimension(500,300)); - minimumFrameSize.put("AdrCellSettingsFrame",new Dimension(300,210)); + minimumFrameSize.put("TaskBarFrame", new Dimension(109, 20)); + 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("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)); + minimumFrameSize.put("GamePathChooser", new Dimension(600, 30)); + minimumFrameSize.put("CurrencySearchFrame", new Dimension(400, 300)); + minimumFrameSize.put("AdrManagerFrame", new Dimension(500, 300)); + minimumFrameSize.put("AdrCellSettingsFrame", new Dimension(300, 210)); } + private void initDefaultMap() { defaultFramesSettings.put("TaskBarFrame", new FrameDescriptor(new Point(400, 500), new Dimension(109, 20))); 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("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("ChatScannerFrame", new FrameDescriptor(new Point(400, 600), new Dimension(550, 220))); 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 index dbe7ab46..61a9614a 100644 --- 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 @@ -5,7 +5,8 @@ import com.mercury.platform.shared.config.configration.PlainConfigurationService; import com.mercury.platform.shared.config.descriptor.*; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public class HotKeyConfigurationService extends BaseConfigurationService implements PlainConfigurationService { public HotKeyConfigurationService(ProfileDescriptor selectedProfile) { @@ -16,28 +17,28 @@ public HotKeyConfigurationService(ProfileDescriptor selectedProfile) { public HotKeysSettingsDescriptor getDefault() { HotKeysSettingsDescriptor hotKeysSettingsDescriptor = new HotKeysSettingsDescriptor(); List incNDataList = new ArrayList<>(); - incNDataList.add(new HotKeyPair(HotKeyType.N_INVITE_PLAYER,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_KICK_PLAYER,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_STILL_INTERESTING,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_SWITCH_CHAT,new HotKeyDescriptor())); - incNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_INVITE_PLAYER, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_KICK_PLAYER, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_STILL_INTERESTING, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_SWITCH_CHAT, new HotKeyDescriptor())); + incNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION, new HotKeyDescriptor())); List outNDataList = new ArrayList<>(); - outNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT,new HotKeyDescriptor())); - outNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor())); - outNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE,new HotKeyDescriptor())); - outNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor())); - outNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor())); + outNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT, new HotKeyDescriptor())); + outNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER, new HotKeyDescriptor())); + outNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE, new HotKeyDescriptor())); + outNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT, new HotKeyDescriptor())); + outNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION, new HotKeyDescriptor())); List scannerNDataList = new ArrayList<>(); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_QUICK_RESPONSE,new HotKeyDescriptor())); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT,new HotKeyDescriptor())); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER,new HotKeyDescriptor())); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE,new HotKeyDescriptor())); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT,new HotKeyDescriptor())); - scannerNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION,new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_QUICK_RESPONSE, new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_VISITE_HIDEOUT, new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_TRADE_PLAYER, new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_LEAVE, new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_OPEN_CHAT, new HotKeyDescriptor())); + scannerNDataList.add(new HotKeyPair(HotKeyType.N_CLOSE_NOTIFICATION, new HotKeyDescriptor())); hotKeysSettingsDescriptor.setIncNHotKeysList(incNDataList); hotKeysSettingsDescriptor.setOutNHotKeysList(outNDataList); @@ -52,7 +53,7 @@ public void toDefault() { @Override public void validate() { - if (this.selectedProfile.getHotKeysSettingsDescriptor() == null){ + if (this.selectedProfile.getHotKeysSettingsDescriptor() == null) { this.selectedProfile.setHotKeysSettingsDescriptor(this.getDefault()); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/IconBundleConfigurationServiceImpl.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/IconBundleConfigurationServiceImpl.java index 34c25afb..1fb5dcae 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/IconBundleConfigurationServiceImpl.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/IconBundleConfigurationServiceImpl.java @@ -17,8 +17,9 @@ import java.util.stream.Collectors; public class IconBundleConfigurationServiceImpl extends BaseConfigurationService> implements IconBundleConfigurationService { - private Map iconBundle = new HashMap<>(); private static final String ICONS_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\icons\\"; + private Map iconBundle = new HashMap<>(); + public IconBundleConfigurationServiceImpl(ProfileDescriptor selectedProfile) { super(selectedProfile); } @@ -26,7 +27,7 @@ public IconBundleConfigurationServiceImpl(ProfileDescriptor selectedProfile) { @Override public URL getIcon(String iconPath) { URL url = this.iconBundle.get(iconPath); - if(url == null){ + if (url == null) { url = this.iconBundle.get("default_icon.png"); } return url; @@ -45,25 +46,27 @@ public void addIcon(String iconPath) { File file = new File(ICONS_PATH + iconName); BufferedImage image = ImageIO.read(url); - ImageIO.write(image,"png",file); + ImageIO.write(image, "png", file); this.getEntities().add(iconName); this.iconBundle.put(iconName, url); } catch (IOException e) { MercuryStoreCore.errorHandlerSubject.onNext( - new MercuryError("Error while add icon: " + iconPath,e)); + new MercuryError("Error while add icon: " + iconPath, e)); } } @Override public void removeIcon(String iconPath) { } + @Override public List getDefault() { return new ArrayList<>(); } + @Override - public List getDefaultBundle(){ - return Arrays.stream(new String[] { + public List getDefaultBundle() { + return Arrays.stream(new String[]{ "default_icon.png", "Abyssal_Cry_skill_icon.png", "Ancestral_Protector_skill_icon.png", @@ -187,30 +190,31 @@ public List getEntities() { @Override public void validate() { - if(this.selectedProfile.getIconBundleList() == null){ + if (this.selectedProfile.getIconBundleList() == null) { this.selectedProfile.setIconBundleList(this.getDefault()); } this.initIconBundle(this.iconBundle); } - private void initIconBundle(Map iconBundle){ + + private void initIconBundle(Map iconBundle) { this.getDefaultBundle().forEach(it -> { URL resource = this.getClass().getClassLoader().getResource("app/adr/icons/" + it); - if(resource != null) { + if (resource != null) { iconBundle.put(it, resource); } }); this.getEntities().forEach(it -> { try { - if(new File(ICONS_PATH + it).exists()) { + if (new File(ICONS_PATH + it).exists()) { URL resource = new URL("file:///" + ICONS_PATH + it); iconBundle.put(it, resource); - }else { + } else { URL resource = this.getClass().getClassLoader().getResource("app/adr/icons/" + "default_icon.png"); iconBundle.put(it, resource); } } catch (MalformedURLException e) { MercuryStoreCore.errorHandlerSubject.onNext( - new MercuryError("Error while initializing icon: " + it,e)); + new MercuryError("Error while initializing icon: " + it, e)); } }); } 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 6d23c8bd..d7db23f6 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 @@ -6,7 +6,6 @@ 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; import java.util.ArrayList; import java.util.List; @@ -21,12 +20,12 @@ public NotificationConfigurationService(ProfileDescriptor selectedProfile) { 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())); + 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())); List defaultOutButtons = new ArrayList<>(); - defaultOutButtons.add(new ResponseButtonDescriptor(0,false,"thanks","thanks", new HotKeyDescriptor())); + defaultOutButtons.add(new ResponseButtonDescriptor(0, false, "thanks", "thanks", new HotKeyDescriptor())); notificationSettingsDescriptor.setButtons(defaultButtons); notificationSettingsDescriptor.setOutButtons(defaultOutButtons); return notificationSettingsDescriptor; @@ -39,16 +38,16 @@ public void toDefault() { @Override public void validate() { - if(this.selectedProfile.getNotificationDescriptor() == null) { + if (this.selectedProfile.getNotificationDescriptor() == null) { this.selectedProfile.setNotificationDescriptor(this.getDefault()); } this.get().getButtons().forEach(it -> { - if(it.getHotKeyDescriptor() == null) { + if (it.getHotKeyDescriptor() == null) { it.setHotKeyDescriptor(new HotKeyDescriptor()); } }); - if(this.get().getOutButtons().size() == 0){ - this.get().getOutButtons().add(new ResponseButtonDescriptor(0,false,"thanks","thanks", new HotKeyDescriptor())); + if (this.get().getOutButtons().size() == 0) { + this.get().getOutButtons().add(new ResponseButtonDescriptor(0, false, "thanks", "thanks", new HotKeyDescriptor())); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScaleConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScaleConfigurationService.java index 5574df35..c3594772 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScaleConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScaleConfigurationService.java @@ -9,14 +9,14 @@ import java.util.Map; -public class ScaleConfigurationService extends BaseConfigurationService> implements KeyValueConfigurationService { +public class ScaleConfigurationService extends BaseConfigurationService> implements KeyValueConfigurationService { public ScaleConfigurationService(ProfileDescriptor selectedProfile) { super(selectedProfile); } @Override public void validate() { - if(this.selectedProfile.getScaleDataMap() == null) { + if (this.selectedProfile.getScaleDataMap() == null) { this.selectedProfile.setScaleDataMap(this.getDefault()); } } @@ -24,7 +24,7 @@ public void validate() { @Override public Float get(String key) { return this.selectedProfile.getScaleDataMap().computeIfAbsent(key, k -> { - this.selectedProfile.getScaleDataMap().put(key,this.getDefault().get(key)); + this.selectedProfile.getScaleDataMap().put(key, this.getDefault().get(key)); MercuryStoreCore.saveConfigSubject.onNext(true); return this.getDefault().get(key); }); @@ -32,11 +32,11 @@ public Float get(String key) { @Override public Map getDefault() { - Map scaleData = new HashMap<>(); - scaleData.put("notification",1f); - scaleData.put("taskbar",1f); - scaleData.put("itemcell",1f); - scaleData.put("other",1f); + Map scaleData = new HashMap<>(); + scaleData.put("notification", 1f); + scaleData.put("taskbar", 1f); + scaleData.put("itemcell", 1f); + scaleData.put("other", 1f); return scaleData; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScannerConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScannerConfigurationService.java index 7a75eb0d..0ead59b0 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScannerConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ScannerConfigurationService.java @@ -25,7 +25,7 @@ public void toDefault() { @Override public void validate() { - if(this.selectedProfile.getScannerDescriptor() == null){ + if (this.selectedProfile.getScannerDescriptor() == null) { this.selectedProfile.setScannerDescriptor(this.getDefault()); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/SoundConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/SoundConfigurationService.java index ef48e781..648444dd 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/SoundConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/SoundConfigurationService.java @@ -6,17 +6,18 @@ import com.mercury.platform.shared.config.descriptor.SoundDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; -import java.util.*; +import java.util.HashMap; +import java.util.Map; -public class SoundConfigurationService extends BaseConfigurationService> implements KeyValueConfigurationService { +public class SoundConfigurationService extends BaseConfigurationService> implements KeyValueConfigurationService { public SoundConfigurationService(ProfileDescriptor selectedProfile) { super(selectedProfile); } @Override public void validate() { - if(this.selectedProfile.getSoundDescriptorMap() == null) { + if (this.selectedProfile.getSoundDescriptorMap() == null) { this.selectedProfile.setSoundDescriptorMap(this.getDefault()); } } @@ -24,7 +25,7 @@ public void validate() { @Override public SoundDescriptor get(String key) { return this.selectedProfile.getSoundDescriptorMap().computeIfAbsent(key, k -> { - this.selectedProfile.getSoundDescriptorMap().put(key,this.getDefault().get(key)); + this.selectedProfile.getSoundDescriptorMap().put(key, this.getDefault().get(key)); MercuryStoreCore.saveConfigSubject.onNext(true); return this.getDefault().get(key); }); @@ -42,11 +43,11 @@ public void set(Map map) { @Override public Map getDefault() { - Map defaultSettings = new HashMap<>(); - defaultSettings.put("notification",new SoundDescriptor("app/notification.wav",0f)); - defaultSettings.put("chat_scanner",new SoundDescriptor("app/chat-filter.wav",0f)); - defaultSettings.put("clicks",new SoundDescriptor("default",0f)); - defaultSettings.put("update",new SoundDescriptor("default",0f)); + Map defaultSettings = new HashMap<>(); + defaultSettings.put("notification", new SoundDescriptor("app/notification.wav", 0f)); + defaultSettings.put("chat_scanner", new SoundDescriptor("app/chat-filter.wav", 0f)); + defaultSettings.put("clicks", new SoundDescriptor("default", 0f)); + defaultSettings.put("update", new SoundDescriptor("default", 0f)); return defaultSettings; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/StashTabConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/StashTabConfigurationService.java index 3c6dca5b..f4467fd4 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/StashTabConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/StashTabConfigurationService.java @@ -25,7 +25,7 @@ public void toDefault() { @Override public void validate() { - if(this.selectedProfile.getStashTabDescriptors() == null) { + if (this.selectedProfile.getStashTabDescriptors() == null) { this.selectedProfile.setStashTabDescriptors(this.getDefault()); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/TaskBarConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/TaskBarConfigurationService.java index 0782fbe3..6cb54742 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/TaskBarConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/TaskBarConfigurationService.java @@ -32,7 +32,7 @@ public void set(TaskBarDescriptor descriptor) { @Override public void validate() { - if(this.selectedProfile.getTaskBarDescriptor() == null){ + if (this.selectedProfile.getTaskBarDescriptor() == null) { this.selectedProfile.setTaskBarDescriptor(this.getDefault()); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/adr/AdrConfigurationServiceMock.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/adr/AdrConfigurationServiceMock.java index 4c68e058..2ed6cd9b 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/adr/AdrConfigurationServiceMock.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/adr/AdrConfigurationServiceMock.java @@ -5,7 +5,6 @@ import com.mercury.platform.shared.config.configration.BaseConfigurationService; import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; import com.mercury.platform.shared.config.descriptor.adr.*; -import com.mercury.platform.shared.config.descriptor.adr.AdrCaptureDescriptor; import com.mercury.platform.shared.config.json.JSONHelper; import java.awt.*; @@ -15,6 +14,7 @@ public class AdrConfigurationServiceMock extends BaseConfigurationService> implements AdrConfigurationService { private List currentProfiles; + public AdrConfigurationServiceMock(ProfileDescriptor selectedProfile) { super(selectedProfile); } @@ -37,12 +37,13 @@ public void toDefault() { @Override public void validate() { - this.currentProfiles = Arrays.stream(new AdrProfileDescriptor[]{this.getShowCaseProfile(),this.getDefaultProfile("Default profile")}).collect(Collectors.toList()); - if(this.selectedProfile.getAdrProfileDescriptorList() == null){ + this.currentProfiles = Arrays.stream(new AdrProfileDescriptor[]{this.getShowCaseProfile(), this.getDefaultProfile("Default profile")}).collect(Collectors.toList()); + if (this.selectedProfile.getAdrProfileDescriptorList() == null) { this.selectedProfile.setAdrProfileDescriptorList(this.getDefault()); } } - private AdrProfileDescriptor getDefaultProfile(String profileName){ + + private AdrProfileDescriptor getDefaultProfile(String profileName) { AdrProfileDescriptor profileDescriptor = new AdrProfileDescriptor(); profileDescriptor.setProfileName(profileName); profileDescriptor.setSelected(true); @@ -62,7 +63,7 @@ public AdrProgressBarDescriptor getDefaultProgressBar() { progressBar.setTitle("progress bar"); progressBar.setSize(new Dimension(240, 30)); progressBar.setType(AdrComponentType.PROGRESS_BAR); - progressBar.setForegroundColor(new Color(22,126,138)); + progressBar.setForegroundColor(new Color(22, 126, 138)); return progressBar; } @@ -78,18 +79,20 @@ public AdrTrackerGroupDescriptor getDefaultIconGroup() { public AdrTrackerGroupDescriptor getDefaultPBGroup() { AdrTrackerGroupDescriptor groupDescriptor = this.getDefaultGroup(); groupDescriptor.setTitle("progress bar group"); - groupDescriptor.setSize(new Dimension(240,30)); + groupDescriptor.setSize(new Dimension(240, 30)); groupDescriptor.setContentType(AdrTrackerGroupContentType.PROGRESS_BARS); return groupDescriptor; } - private AdrTrackerGroupDescriptor getDefaultGroup(){ + + private AdrTrackerGroupDescriptor getDefaultGroup() { AdrTrackerGroupDescriptor groupDescriptor = new AdrTrackerGroupDescriptor(); groupDescriptor.setTitle("group"); groupDescriptor.setType(AdrComponentType.TRACKER_GROUP); groupDescriptor.setOrientation(AdrComponentOrientation.VERTICAL); return groupDescriptor; } - private AdrProfileDescriptor getShowCaseProfile(){ + + private AdrProfileDescriptor getShowCaseProfile() { AdrProfileDescriptor profileDescriptor = new AdrProfileDescriptor(); profileDescriptor.setProfileName("Showcase"); profileDescriptor.setSelected(false); @@ -103,7 +106,7 @@ public AdrCaptureDescriptor getDefaultCapture() { AdrCaptureDescriptor descriptor = new AdrCaptureDescriptor(); descriptor.setTitle("Capture"); descriptor.setType(AdrComponentType.CAPTURE); - descriptor.setCaptureLocation(new Point(descriptor.getLocation().x + 80,descriptor.getLocation().y)); + descriptor.setCaptureLocation(new Point(descriptor.getLocation().x + 80, descriptor.getLocation().y)); return descriptor; } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ApplicationDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ApplicationDescriptor.java index 997a4d47..4f46b375 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ApplicationDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ApplicationDescriptor.java @@ -4,10 +4,9 @@ import lombok.Data; import java.io.Serializable; -import java.util.Map; @Data -public class ApplicationDescriptor implements Serializable{ +public class ApplicationDescriptor implements Serializable { private WhisperNotifierStatus notifierStatus; private int minOpacity; private int maxOpacity; 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 752fe9a1..3c2bcde1 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 @@ -9,7 +9,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class HotKeyDescriptor implements Serializable{ +public class HotKeyDescriptor implements Serializable { private String title = "..."; private int virtualKeyCode; private boolean menuPressed; 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 index 52c165d2..a1903e0d 100644 --- 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 @@ -7,7 +7,7 @@ @Data @AllArgsConstructor -public class HotKeyPair implements Serializable{ +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 6fa12bb9..cd4958b7 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 @@ -5,7 +5,7 @@ import java.util.Arrays; import java.util.stream.Collectors; -public enum HotKeyType implements Serializable{ +public enum HotKeyType implements Serializable { N_TRADE_PLAYER { @Override public String getIconPath() { @@ -87,11 +87,13 @@ public String getIconPath() { return "app/visible-dnd-mode.png"; } }; - public abstract String getIconPath(); - public static boolean contains(HotKeyType entry){ + + public static boolean contains(HotKeyType entry) { return Arrays.stream(HotKeyType.values()) .filter(it -> it.equals(entry)) .collect(Collectors.toList()) .size() != 0; } + + public abstract String getIconPath(); } 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 index 54e469dd..3d7fc56a 100644 --- 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 @@ -8,7 +8,7 @@ import java.util.List; @Data -public class NotificationSettingsDescriptor implements Serializable{ +public class NotificationSettingsDescriptor implements Serializable { private boolean incNotificationEnable = true; private boolean outNotificationEnable = true; private boolean scannerNotificationEnable = true; 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 76a781b1..dbd7b4de 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 @@ -10,13 +10,13 @@ public class ProfileDescriptor { private String name; private boolean selected; - private Map frameDescriptorMap; - private Map soundDescriptorMap; + private Map frameDescriptorMap; + private Map soundDescriptorMap; private ApplicationDescriptor applicationDescriptor; private NotificationSettingsDescriptor notificationDescriptor; private TaskBarDescriptor taskBarDescriptor; private ScannerDescriptor scannerDescriptor; - private Map scaleDataMap; + private Map scaleDataMap; private HotKeysSettingsDescriptor hotKeysSettingsDescriptor; private List stashTabDescriptors; private List adrProfileDescriptorList; diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ResponseButtonDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ResponseButtonDescriptor.java index 74fad744..5e7bf82d 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ResponseButtonDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ResponseButtonDescriptor.java @@ -9,7 +9,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class ResponseButtonDescriptor implements Comparable,Serializable{ +public class ResponseButtonDescriptor implements Comparable, Serializable { private long id; private boolean close; private String title = "label"; @@ -18,11 +18,11 @@ public class ResponseButtonDescriptor implements Comparable o.getId()) { + if (this.getId() > o.getId()) { return 1; - }else if(this.getId() < o.getId()){ + } else if (this.getId() < o.getId()) { return -1; - }else { + } else { return 0; } } 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 13ef838c..bfc94515 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 @@ -5,7 +5,7 @@ import java.io.Serializable; @Data -public class ScannerDescriptor implements Serializable{ +public class ScannerDescriptor implements Serializable { private String words; private String responseMessage; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java index d9632bea..89aa9ce1 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java @@ -9,7 +9,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class SoundDescriptor implements Serializable{ +public class SoundDescriptor implements Serializable { private String wavPath; private Float db; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java index 42104258..2aacb954 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrCaptureDescriptor.java @@ -10,6 +10,6 @@ @Data public class AdrCaptureDescriptor extends AdrColoredComponentDescriptor implements Serializable { private int fps = 5; - private Dimension captureSize = new Dimension(64,64); + private Dimension captureSize = new Dimension(64, 64); private Point captureLocation; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrColoredComponentDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrColoredComponentDescriptor.java index 9b7b6395..c6469f05 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrColoredComponentDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrColoredComponentDescriptor.java @@ -8,9 +8,9 @@ @EqualsAndHashCode(callSuper = true) @Data -public class AdrColoredComponentDescriptor extends AdrComponentDescriptor implements Serializable{ +public class AdrColoredComponentDescriptor extends AdrComponentDescriptor implements Serializable { private Color backgroundColor = new Color(59, 59, 59); private Color foregroundColor = new Color(59, 59, 59, 190); - private Color borderColor = new Color(16,110,99); + private Color borderColor = new Color(16, 110, 99); private int thickness = 1; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentDescriptor.java index b45995fa..aa70e54e 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentDescriptor.java @@ -1,7 +1,6 @@ package com.mercury.platform.shared.config.descriptor.adr; -import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,7 +13,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class AdrComponentDescriptor implements Serializable{ +public class AdrComponentDescriptor implements Serializable { private String componentId = UUID.randomUUID().toString(); private String title = "component"; private AdrComponentType type; diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentOrientation.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentOrientation.java index 64adde8a..e7e2afe2 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentOrientation.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrComponentOrientation.java @@ -15,13 +15,14 @@ public String asPretty() { } }; - public abstract String asPretty(); - public static AdrComponentOrientation valueOfPretty(String s){ + public static AdrComponentOrientation valueOfPretty(String s) { for (AdrComponentOrientation orientation : AdrComponentOrientation.values()) { - if(orientation.asPretty().equals(s)){ + if (orientation.asPretty().equals(s)) { return orientation; } } return null; } + + public abstract String asPretty(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java index db0d5d71..3cc93b5b 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java @@ -16,7 +16,7 @@ public class AdrDurationComponentDescriptor extends AdrColoredComponentDescripto private Double duration = 3.4d; private Double delay = 0d; private float outlineThickness = 0.2f; - private Color outlineColor = new Color(45, 55, 54,180); + private Color outlineColor = new Color(45, 55, 54, 180); private int fontSize = 28; private boolean textEnable = true; private boolean iconEnable = true; @@ -25,12 +25,12 @@ public class AdrDurationComponentDescriptor extends AdrColoredComponentDescripto private boolean invertMask; private boolean invertTimer; private String textFormat = "0.0"; - private Color lowValueTextColor = new Color(224,86,60); - private Color mediumValueTextColor = new Color(255,211,78); - private Color defaultValueTextColor = new Color(255,250,213); + private Color lowValueTextColor = new Color(224, 86, 60); + private Color mediumValueTextColor = new Color(255, 211, 78); + private Color defaultValueTextColor = new Color(255, 250, 213); private Double lowValueTextThreshold = 1d; private Double mediumValueTextThreshold = 3d; private Double defaultValueTextThreshold = 5d; - private Insets insets = new Insets(0,0,0,0); + private Insets insets = new Insets(0, 0, 0, 0); private boolean bindToTextColor; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconAlignment.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconAlignment.java index 7842b0fa..d02e5d51 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconAlignment.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconAlignment.java @@ -27,13 +27,14 @@ public String asPretty() { } }; - public abstract String asPretty(); - public static AdrIconAlignment valueOfPretty(String s){ + public static AdrIconAlignment valueOfPretty(String s) { for (AdrIconAlignment adrIconAlignment : AdrIconAlignment.values()) { - if(adrIconAlignment.asPretty().equals(s)){ + if (adrIconAlignment.asPretty().equals(s)) { return adrIconAlignment; } } return null; } + + public abstract String asPretty(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconType.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconType.java index 406c0dfd..c5b28fa4 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconType.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrIconType.java @@ -15,13 +15,14 @@ public String asPretty() { } }; - public abstract String asPretty(); - public static AdrIconType valueOfPretty(String s){ + public static AdrIconType valueOfPretty(String s) { for (AdrIconType iconType : AdrIconType.values()) { - if(iconType.asPretty().equals(s)){ + if (iconType.asPretty().equals(s)) { return iconType; } } return null; } + + public abstract String asPretty(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrProgressBarDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrProgressBarDescriptor.java index da501b97..bac78b83 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrProgressBarDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrProgressBarDescriptor.java @@ -3,7 +3,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; -import java.awt.*; import java.io.Serializable; @EqualsAndHashCode(callSuper = true) diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrTrackerGroupType.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrTrackerGroupType.java index 4ee03d80..d429a771 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrTrackerGroupType.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrTrackerGroupType.java @@ -15,13 +15,14 @@ public String asPretty() { } }; - public abstract String asPretty(); - public static AdrTrackerGroupType valueOfPretty(String s){ + public static AdrTrackerGroupType valueOfPretty(String s) { for (AdrTrackerGroupType adrTrackerGroupType : AdrTrackerGroupType.values()) { - if(adrTrackerGroupType.asPretty().equals(s)){ + if (adrTrackerGroupType.asPretty().equals(s)) { return adrTrackerGroupType; } } return null; } + + public abstract String asPretty(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/json/JSONHelper.java b/app-core/src/main/java/com/mercury/platform/shared/config/json/JSONHelper.java index c2c3e274..09442cff 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/json/JSONHelper.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/json/JSONHelper.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.awt.*; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -25,105 +24,114 @@ public class JSONHelper { private Logger logger = LogManager.getLogger(JSONHelper.class.getSimpleName()); private String dataSource; - public JSONHelper(String dataSource){ + public JSONHelper(String dataSource) { this.dataSource = dataSource; } - public JSONHelper(){ + + public JSONHelper() { this.dataSource = dataSource; } - public List readArrayData(TypeToken> typeToken){ + + public static List getJsonAsObject(String jsonStr) { + try { + Gson gson = new GsonBuilder() + .registerTypeAdapter(AdrComponentDescriptor.class, new AdrComponentJsonAdapter()) + .create(); + JsonParser jsonParser = new JsonParser(); + return gson.fromJson( + jsonParser.parse(jsonStr), + new TypeToken>() { + }.getType()); + } catch (IllegalStateException | JsonSyntaxException e) { + MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing string: " + jsonStr, e)); + return null; + } + } + + public List readArrayData(TypeToken> typeToken) { try { Gson gson = new GsonBuilder() - .registerTypeHierarchyAdapter(AdrTrackerGroupDescriptor.class,new AdrTrackerGroupDeserializer()) - .registerTypeHierarchyAdapter(AdrComponentDescriptor.class,new AdrComponentJsonAdapter()) + .registerTypeHierarchyAdapter(AdrTrackerGroupDescriptor.class, new AdrTrackerGroupDeserializer()) + .registerTypeHierarchyAdapter(AdrComponentDescriptor.class, new AdrComponentJsonAdapter()) .create(); JsonParser jsonParser = new JsonParser(); - try(JsonReader reader = new JsonReader(new FileReader(dataSource))) { + try (JsonReader reader = new JsonReader(new FileReader(dataSource))) { return gson.fromJson( jsonParser.parse(reader), typeToken.getType()); } - }catch (IOException | IllegalStateException | JsonSyntaxException e){ + } catch (IOException | IllegalStateException | JsonSyntaxException e) { logger.error(e); return null; } } - public T readMapData(String key,TypeToken typeToken){ + + public T readMapData(String key, TypeToken typeToken) { try { Gson gson = new Gson(); JsonParser jsonParser = new JsonParser(); - try(JsonReader reader = new JsonReader(new FileReader(dataSource))) { + try (JsonReader reader = new JsonReader(new FileReader(dataSource))) { return gson.fromJson( jsonParser.parse(reader) .getAsJsonObject() .get(key), typeToken.getType()); } - }catch (IOException | IllegalStateException e){ + } catch (IOException | IllegalStateException e) { logger.error(e); return null; } } - public void writeMapObject(String key, Map object){ + + public void writeMapObject(String key, Map object) { try { Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create(); - try(JsonWriter writer = new JsonWriter(new FileWriter(dataSource))) { + try (JsonWriter writer = new JsonWriter(new FileWriter(dataSource))) { JsonObject jsonObject = new JsonObject(); - jsonObject.add(key,gson.toJsonTree(object)); - gson.toJson(jsonObject,writer); + jsonObject.add(key, gson.toJsonTree(object)); + gson.toJson(jsonObject, writer); } - }catch (IOException e){ + } catch (IOException e) { logger.error(e); } } - public void writeListObject(List object, TypeToken> typeToken){ + + public void writeListObject(List object, TypeToken> typeToken) { try { Gson gson = new GsonBuilder() - .registerTypeAdapter(AdrComponentDescriptor.class,new AdrComponentJsonAdapter()) + .registerTypeAdapter(AdrComponentDescriptor.class, new AdrComponentJsonAdapter()) .create(); - try(JsonWriter writer = new JsonWriter(new FileWriter(dataSource))) { - gson.toJson(object,typeToken.getType(),writer); + try (JsonWriter writer = new JsonWriter(new FileWriter(dataSource))) { + gson.toJson(object, typeToken.getType(), writer); } - }catch (IOException e){ + } catch (IOException e) { logger.error(e); } } - public List getJsonAsObjectFromFile(String filePath){ + + public List getJsonAsObjectFromFile(String filePath) { try { Gson gson = new GsonBuilder() - .registerTypeAdapter(AdrComponentDescriptor.class,new AdrComponentJsonAdapter()) + .registerTypeAdapter(AdrComponentDescriptor.class, new AdrComponentJsonAdapter()) .create(); JsonParser jsonParser = new JsonParser(); - try(JsonReader reader = new JsonReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(filePath)))) { + try (JsonReader reader = new JsonReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(filePath)))) { return gson.fromJson( jsonParser.parse(reader), - new TypeToken>(){}.getType()); + new TypeToken>() { + }.getType()); } catch (IOException e) { - MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing from file:",e)); + MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing from file:", e)); } - }catch (IllegalStateException | JsonSyntaxException e){ - MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing from file:",e)); + } catch (IllegalStateException | JsonSyntaxException e) { + MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing from file:", e)); return null; } return null; } - public static List getJsonAsObject(String jsonStr){ - try { - Gson gson = new GsonBuilder() - .registerTypeAdapter(AdrComponentDescriptor.class,new AdrComponentJsonAdapter()) - .create(); - JsonParser jsonParser = new JsonParser(); - return gson.fromJson( - jsonParser.parse(jsonStr), - new TypeToken>(){}.getType()); - }catch (IllegalStateException | JsonSyntaxException e){ - MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing string: " + jsonStr,e)); - return null; - } - } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/AdrComponentJsonAdapter.java b/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/AdrComponentJsonAdapter.java index b259e57a..3027f165 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/AdrComponentJsonAdapter.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/json/deserializer/AdrComponentJsonAdapter.java @@ -11,10 +11,10 @@ public class AdrComponentJsonAdapter implements JsonDeserializer>(){}.getType())); + switch (AdrTrackerGroupContentType.valueOf(jsonObj.getAsString())) { + case PROGRESS_BARS: { + descriptor.setCells(gson.fromJson(cellsObj, new TypeToken>() { + }.getType())); break; } - case ICONS:{ - descriptor.setCells(gson.fromJson(cellsObj,new TypeToken>(){}.getType())); + case ICONS: { + descriptor.setCells(gson.fromJson(cellsObj, new TypeToken>() { + }.getType())); } } return descriptor; 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 24cdff64..09c563ba 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 @@ -9,7 +9,7 @@ import java.lang.reflect.Type; -public class MessageDeserializer implements JsonDeserializer{ +public class MessageDeserializer implements JsonDeserializer { @Override 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/config/service/PoeAppHttpSearchService.java b/app-core/src/main/java/com/mercury/platform/shared/config/service/PoeAppHttpSearchService.java index 05e2232c..3c3298c9 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/service/PoeAppHttpSearchService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/service/PoeAppHttpSearchService.java @@ -14,11 +14,93 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; public class PoeAppHttpSearchService extends HttpItemSearchService { + public static void main(String[] args) { + PoeAppHttpSearchService searchService = new PoeAppHttpSearchService(); + searchService.test(); + } + + public static List getFormData() { + List nvp = new ArrayList<>(); + nvp.add(new BasicNameValuePair("league", "Legacy")); + nvp.add(new BasicNameValuePair("type", "")); + nvp.add(new BasicNameValuePair("base", "")); + nvp.add(new BasicNameValuePair("name", "")); + nvp.add(new BasicNameValuePair("dmg_min", "")); + nvp.add(new BasicNameValuePair("dmg_max", "")); + nvp.add(new BasicNameValuePair("aps_min", "")); + nvp.add(new BasicNameValuePair("aps_max", "")); + nvp.add(new BasicNameValuePair("crit_min", "")); + nvp.add(new BasicNameValuePair("crit_max", "")); + nvp.add(new BasicNameValuePair("dps_min", "")); + nvp.add(new BasicNameValuePair("dps_max", "")); + nvp.add(new BasicNameValuePair("edps_min", "")); + nvp.add(new BasicNameValuePair("edps_max", "")); + nvp.add(new BasicNameValuePair("pdps_min", "")); + nvp.add(new BasicNameValuePair("pdps_max", "")); + nvp.add(new BasicNameValuePair("armour_min", "")); + nvp.add(new BasicNameValuePair("armour_max", "")); + nvp.add(new BasicNameValuePair("evasion_min", "")); + nvp.add(new BasicNameValuePair("evasion_max", "")); + nvp.add(new BasicNameValuePair("shield_min", "")); + nvp.add(new BasicNameValuePair("shield_max", "")); + nvp.add(new BasicNameValuePair("block_min", "")); + nvp.add(new BasicNameValuePair("block_max", "")); + nvp.add(new BasicNameValuePair("sockets_min", "")); + nvp.add(new BasicNameValuePair("sockets_max", "")); + nvp.add(new BasicNameValuePair("link_min", "")); + nvp.add(new BasicNameValuePair("link_max", "")); + nvp.add(new BasicNameValuePair("sockets_r", "")); + nvp.add(new BasicNameValuePair("sockets_g", "")); + nvp.add(new BasicNameValuePair("sockets_b", "")); + nvp.add(new BasicNameValuePair("sockets_w", "")); + nvp.add(new BasicNameValuePair("linked_r", "")); + nvp.add(new BasicNameValuePair("linked_g", "")); + nvp.add(new BasicNameValuePair("linked_b", "")); + nvp.add(new BasicNameValuePair("linked_w", "")); + nvp.add(new BasicNameValuePair("rlevel_min", "")); + nvp.add(new BasicNameValuePair("rlevel_max", "")); + nvp.add(new BasicNameValuePair("rstr_min", "")); + nvp.add(new BasicNameValuePair("rstr_max", "")); + nvp.add(new BasicNameValuePair("rdex_min", "")); + nvp.add(new BasicNameValuePair("rdex_max", "")); + nvp.add(new BasicNameValuePair("rint_min", "")); + nvp.add(new BasicNameValuePair("rint_max", "")); + nvp.add(new BasicNameValuePair("mod_name", "")); + nvp.add(new BasicNameValuePair("mod_min", "")); + nvp.add(new BasicNameValuePair("mod_max", "")); + nvp.add(new BasicNameValuePair("group_type", "And")); + nvp.add(new BasicNameValuePair("group_min", "")); + nvp.add(new BasicNameValuePair("group_max", "")); + nvp.add(new BasicNameValuePair("group_count", "1")); + nvp.add(new BasicNameValuePair("q_min", "")); + nvp.add(new BasicNameValuePair("q_max", "")); + nvp.add(new BasicNameValuePair("level_min", "")); + nvp.add(new BasicNameValuePair("level_max", "")); + nvp.add(new BasicNameValuePair("mapq_min", "")); + nvp.add(new BasicNameValuePair("mapq_max", "")); + nvp.add(new BasicNameValuePair("rarity", "")); + nvp.add(new BasicNameValuePair("seller", "exslims")); + nvp.add(new BasicNameValuePair("thread", "")); + nvp.add(new BasicNameValuePair("identified", "")); + nvp.add(new BasicNameValuePair("corrupted", "")); + nvp.add(new BasicNameValuePair("online", "")); + nvp.add(new BasicNameValuePair("buyout", "")); + nvp.add(new BasicNameValuePair("altart", "")); + nvp.add(new BasicNameValuePair("capquality", "")); + nvp.add(new BasicNameValuePair("buyout_min", "")); + nvp.add(new BasicNameValuePair("buyout_max", "")); + nvp.add(new BasicNameValuePair("buyout_currency", "")); + nvp.add(new BasicNameValuePair("crafted", "")); + nvp.add(new BasicNameValuePair("ilvl_min", "")); + nvp.add(new BasicNameValuePair("buyout_currency", "")); + nvp.add(new BasicNameValuePair("ilvl_max", "")); + return nvp; + } + @Override public String test() { DefaultHttpClient httpClient = new DefaultHttpClient(); @@ -52,100 +134,18 @@ public String test() { return null; } - public static void main(String[] args) { - PoeAppHttpSearchService searchService = new PoeAppHttpSearchService(); - searchService.test(); - } - - private void setRequestHeaders(HttpPost request){ - request.addHeader(new BasicHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")); - request.addHeader(new BasicHeader("Accept-Encoding","gzip, deflate")); - request.addHeader(new BasicHeader("Accept-Language","ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4")); - request.addHeader(new BasicHeader("Cache-Control","max-age=0")); - request.addHeader(new BasicHeader("Connection","keep-alive")); - request.addHeader(new BasicHeader("Content-Type","application/x-www-form-urlencoded")); - request.addHeader(new BasicHeader("Cookie","color=dark; live_notify_sound=0; live_notify_browser=0; live_frequency=5; _gat=1; _ga=GA1.2.1401167521.1452005585; league=Legacy")); - request.addHeader(new BasicHeader("Host","poe.trade")); - request.addHeader(new BasicHeader("Origin","http://poe.trade")); - request.addHeader(new BasicHeader("Referer","http://poe.trade/")); - request.addHeader(new BasicHeader("Upgrade-Insecure-Requests","1")); - request.addHeader(new BasicHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36")); - } - public static List getFormData(){ - List nvp = new ArrayList<>(); - nvp.add(new BasicNameValuePair("league","Legacy")); - nvp.add(new BasicNameValuePair("type","")); - nvp.add(new BasicNameValuePair("base","")); - nvp.add(new BasicNameValuePair("name","")); - nvp.add(new BasicNameValuePair("dmg_min","")); - nvp.add(new BasicNameValuePair("dmg_max","")); - nvp.add(new BasicNameValuePair("aps_min","")); - nvp.add(new BasicNameValuePair("aps_max","")); - nvp.add(new BasicNameValuePair("crit_min","")); - nvp.add(new BasicNameValuePair("crit_max","")); - nvp.add(new BasicNameValuePair("dps_min","")); - nvp.add(new BasicNameValuePair("dps_max","")); - nvp.add(new BasicNameValuePair("edps_min","")); - nvp.add(new BasicNameValuePair("edps_max","")); - nvp.add(new BasicNameValuePair("pdps_min","")); - nvp.add(new BasicNameValuePair("pdps_max","")); - nvp.add(new BasicNameValuePair("armour_min","")); - nvp.add(new BasicNameValuePair("armour_max","")); - nvp.add(new BasicNameValuePair("evasion_min","")); - nvp.add(new BasicNameValuePair("evasion_max","")); - nvp.add(new BasicNameValuePair("shield_min","")); - nvp.add(new BasicNameValuePair("shield_max","")); - nvp.add(new BasicNameValuePair("block_min","")); - nvp.add(new BasicNameValuePair("block_max","")); - nvp.add(new BasicNameValuePair("sockets_min","")); - nvp.add(new BasicNameValuePair("sockets_max","")); - nvp.add(new BasicNameValuePair("link_min","")); - nvp.add(new BasicNameValuePair("link_max","")); - nvp.add(new BasicNameValuePair("sockets_r","")); - nvp.add(new BasicNameValuePair("sockets_g","")); - nvp.add(new BasicNameValuePair("sockets_b","")); - nvp.add(new BasicNameValuePair("sockets_w","")); - nvp.add(new BasicNameValuePair("linked_r","")); - nvp.add(new BasicNameValuePair("linked_g","")); - nvp.add(new BasicNameValuePair("linked_b","")); - nvp.add(new BasicNameValuePair("linked_w","")); - nvp.add(new BasicNameValuePair("rlevel_min","")); - nvp.add(new BasicNameValuePair("rlevel_max","")); - nvp.add(new BasicNameValuePair("rstr_min","")); - nvp.add(new BasicNameValuePair("rstr_max","")); - nvp.add(new BasicNameValuePair("rdex_min","")); - nvp.add(new BasicNameValuePair("rdex_max","")); - nvp.add(new BasicNameValuePair("rint_min","")); - nvp.add(new BasicNameValuePair("rint_max","")); - nvp.add(new BasicNameValuePair("mod_name","")); - nvp.add(new BasicNameValuePair("mod_min","")); - nvp.add(new BasicNameValuePair("mod_max","")); - nvp.add(new BasicNameValuePair("group_type","And")); - nvp.add(new BasicNameValuePair("group_min","")); - nvp.add(new BasicNameValuePair("group_max","")); - nvp.add(new BasicNameValuePair("group_count","1")); - nvp.add(new BasicNameValuePair("q_min","")); - nvp.add(new BasicNameValuePair("q_max","")); - nvp.add(new BasicNameValuePair("level_min","")); - nvp.add(new BasicNameValuePair("level_max","")); - nvp.add(new BasicNameValuePair("mapq_min","")); - nvp.add(new BasicNameValuePair("mapq_max","")); - nvp.add(new BasicNameValuePair("rarity","")); - nvp.add(new BasicNameValuePair("seller","exslims")); - nvp.add(new BasicNameValuePair("thread","")); - nvp.add(new BasicNameValuePair("identified","")); - nvp.add(new BasicNameValuePair("corrupted","")); - nvp.add(new BasicNameValuePair("online","")); - nvp.add(new BasicNameValuePair("buyout","")); - nvp.add(new BasicNameValuePair("altart","")); - nvp.add(new BasicNameValuePair("capquality","")); - nvp.add(new BasicNameValuePair("buyout_min","")); - nvp.add(new BasicNameValuePair("buyout_max","")); - nvp.add(new BasicNameValuePair("buyout_currency","")); - nvp.add(new BasicNameValuePair("crafted","")); - nvp.add(new BasicNameValuePair("ilvl_min","")); - nvp.add(new BasicNameValuePair("buyout_currency","")); - nvp.add(new BasicNameValuePair("ilvl_max","")); - return nvp; + private void setRequestHeaders(HttpPost request) { + request.addHeader(new BasicHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")); + request.addHeader(new BasicHeader("Accept-Encoding", "gzip, deflate")); + request.addHeader(new BasicHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4")); + request.addHeader(new BasicHeader("Cache-Control", "max-age=0")); + request.addHeader(new BasicHeader("Connection", "keep-alive")); + request.addHeader(new BasicHeader("Content-Type", "application/x-www-form-urlencoded")); + request.addHeader(new BasicHeader("Cookie", "color=dark; live_notify_sound=0; live_notify_browser=0; live_frequency=5; _gat=1; _ga=GA1.2.1401167521.1452005585; league=Legacy")); + request.addHeader(new BasicHeader("Host", "poe.trade")); + request.addHeader(new BasicHeader("Origin", "http://poe.trade")); + request.addHeader(new BasicHeader("Referer", "http://poe.trade/")); + request.addHeader(new BasicHeader("Upgrade-Insecure-Requests", "1")); + request.addHeader(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36")); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/FlowDirections.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/FlowDirections.java index 94cf6d8d..0f6e7f15 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/entity/message/FlowDirections.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/FlowDirections.java @@ -2,6 +2,6 @@ import java.io.Serializable; -public enum FlowDirections implements Serializable{ +public enum FlowDirections implements Serializable { UPWARDS, DOWNWARDS } diff --git a/app-core/src/main/java/com/mercury/platform/shared/entity/message/MercuryError.java b/app-core/src/main/java/com/mercury/platform/shared/entity/message/MercuryError.java index 0fc0af4e..f3730193 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/entity/message/MercuryError.java +++ b/app-core/src/main/java/com/mercury/platform/shared/entity/message/MercuryError.java @@ -8,7 +8,8 @@ public class MercuryError { private String errorMessage; private Throwable stackTrace; - public MercuryError(Throwable stackTrace){ + + public MercuryError(Throwable stackTrace) { this.stackTrace = stackTrace; } } 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 8bac84be..20736160 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,7 @@ import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; -import java.awt.*; -import java.awt.event.KeyEvent; - -public class MercuryNativeKeyListener implements NativeKeyListener{ +public class MercuryNativeKeyListener implements NativeKeyListener { private boolean menuPressed; private boolean shiftPressed; private boolean ctrlpressed; @@ -22,8 +19,8 @@ public MercuryNativeKeyListener() { @Override public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { - switch (nativeKeyEvent.getKeyCode()){ - case 42 : { + switch (nativeKeyEvent.getKeyCode()) { + case 42: { this.shiftPressed = true; break; } @@ -35,8 +32,8 @@ public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { this.menuPressed = true; break; } - default:{ - if(!this.block) { + default: { + if (!this.block) { MercuryStoreCore.hotKeySubject.onNext(this.getDescriptor(nativeKeyEvent)); } } @@ -45,8 +42,8 @@ public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { @Override public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) { - switch (nativeKeyEvent.getKeyCode()){ - case 42 : { + switch (nativeKeyEvent.getKeyCode()) { + case 42: { this.shiftPressed = false; break; } @@ -64,17 +61,19 @@ public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) { @Override public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) { } - private String getButtonText(HotKeyDescriptor descriptor){ + + private String getButtonText(HotKeyDescriptor descriptor) { String text = descriptor.getTitle(); - if(descriptor.isShiftPressed()) + if (descriptor.isShiftPressed()) text = "Shift + " + text; - if(descriptor.isMenuPressed()) + if (descriptor.isMenuPressed()) text = "Alt + " + text; - if(descriptor.isControlPressed()) + if (descriptor.isControlPressed()) text = "Ctrl + " + text; return text; } - private HotKeyDescriptor getDescriptor(NativeKeyEvent nativeKeyEvent){ + + private HotKeyDescriptor getDescriptor(NativeKeyEvent nativeKeyEvent) { HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode())); hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode()); diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java index 3d1a2f49..9c6bebec 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.java @@ -15,7 +15,7 @@ public void nativeMousePressed(NativeMouseEvent nativeMouseEvent) { HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); hotKeyDescriptor.setVirtualKeyCode(nativeMouseEvent.getButton() + 10000); hotKeyDescriptor.setTitle(this.getModifiersText(nativeMouseEvent.getButton())); - if(!hotKeyDescriptor.getTitle().equals("Mouse left")) { + if (!hotKeyDescriptor.getTitle().equals("Mouse left")) { MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor); } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java b/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java index 1209abbf..e35dc875 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java +++ b/app-core/src/main/java/com/mercury/platform/shared/store/DataTransformers.java @@ -13,7 +13,8 @@ public class DataTransformers { - private static final KeyValueConfigurationService soundService = Configuration.get().soundConfiguration(); + private static final KeyValueConfigurationService soundService = Configuration.get().soundConfiguration(); + public static Observable.Transformer transformSoundData() { String[] clicks = { "app/sounds/click1/button-pressed-10.wav", @@ -21,15 +22,15 @@ public static Observable.Transformer transformSoundD "app/sounds/click1/button-pressed-30.wav"}; return obs -> obs.map(soundType -> { SoundDescriptor descriptor = new SoundDescriptor(); - switch (soundType){ - case MESSAGE:{ + switch (soundType) { + case MESSAGE: { SoundDescriptor desc = soundService.get("notification"); WhisperNotifierStatus status = Configuration.get().applicationConfiguration().get().getNotifierStatus(); if (status == WhisperNotifierStatus.ALWAYS || ((status == WhisperNotifierStatus.ALTAB) && (ProdStarter.APP_STATUS == FrameVisibleState.HIDE))) { return desc; } - return new SoundDescriptor(desc.getWavPath(),-80f); + return new SoundDescriptor(desc.getWavPath(), -80f); } case CHAT_SCANNER: { return soundService.get("chat_scanner"); 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 8b72d5e8..3232196b 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 @@ -5,11 +5,10 @@ import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; +import com.mercury.platform.shared.config.descriptor.SoundDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState; import com.mercury.platform.shared.entity.message.MercuryError; 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; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrFrameMagnet.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrFrameMagnet.java index bcc2c0f9..c47c2cbd 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrFrameMagnet.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/AdrFrameMagnet.java @@ -9,26 +9,27 @@ import java.util.stream.Collectors; public class AdrFrameMagnet { - private static class AdrFrameMagnetHolder { - static final AdrFrameMagnet HOLDER_INSTANCE = new AdrFrameMagnet(); - } public static AdrFrameMagnet INSTANCE = AdrFrameMagnetHolder.HOLDER_INSTANCE; @Setter private List descriptors; @Setter private int delta; - public void obtainApproxFrameLocation(Point source, AdrComponentDescriptor sourceDescriptor){ + public void obtainApproxFrameLocation(Point source, AdrComponentDescriptor sourceDescriptor) { this.descriptors .stream() .filter(descriptor -> !descriptor.equals(sourceDescriptor)) .collect(Collectors.toList()).forEach(descriptor -> { - if((descriptor.getLocation().x + descriptor.getSize().width + delta) > source.x) { + if ((descriptor.getLocation().x + descriptor.getSize().width + delta) > source.x) { source.x = descriptor.getLocation().x + descriptor.getSize().width; - if((descriptor.getLocation().y + descriptor.getSize().height + delta) > source.y) { + if ((descriptor.getLocation().y + descriptor.getSize().height + delta) > source.y) { source.y = descriptor.getLocation().y + descriptor.getSize().height; } } }); } + + private static class AdrFrameMagnetHolder { + static final AdrFrameMagnet HOLDER_INSTANCE = new AdrFrameMagnet(); + } } 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 a506954c..f8c456b7 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 @@ -6,23 +6,22 @@ import com.mercury.platform.shared.config.configration.AdrConfigurationService; import com.mercury.platform.shared.config.descriptor.adr.*; import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.adr.components.*; +import com.mercury.platform.ui.adr.components.AbstractAdrFrame; +import com.mercury.platform.ui.adr.components.AdrCaptureOutComponentFrame; +import com.mercury.platform.ui.adr.components.AdrManagerFrame; import com.mercury.platform.ui.adr.components.factory.FrameProviderFactory; -import com.mercury.platform.ui.adr.components.factory.frame.FrameProvider; import com.mercury.platform.ui.adr.components.panel.AdrCaptureOutPanel; -import com.mercury.platform.ui.adr.components.panel.AdrCapturePanel; import com.mercury.platform.ui.adr.components.panel.page.*; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.Getter; import javax.swing.*; -import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class AdrManager implements AsSubscriber{ +public class AdrManager implements AsSubscriber { private List frames = new ArrayList<>(); private AdrProfileDescriptor selectedProfile; private AdrConfigurationService config; @@ -41,7 +40,8 @@ public class AdrManager implements AsSubscriber{ private FrameProviderFactory frameProviderFactory; @Getter private AdrState state = AdrState.DEFAULT; - public void load(){ + + public void load() { this.config = Configuration.get().adrConfiguration(); this.frameProviderFactory = new FrameProviderFactory(); @@ -71,12 +71,14 @@ public void load(){ this.mainPanel.setPayload(null); this.adrManagerFrame.setPage(this.mainPanel); } - public void enableSettings(){ + + public void enableSettings() { this.state = AdrState.SETTINGS; this.frames.forEach(AbstractAdrFrame::enableSettings); this.adrManagerFrame.showComponent(); } - public void disableSettings(){ + + public void disableSettings() { this.state = AdrState.DEFAULT; this.adrManagerFrame.hideComponent(); this.frames.forEach(AbstractAdrFrame::disableSettings); @@ -86,14 +88,14 @@ public void disableSettings(){ @SuppressWarnings("all") public void subscribe() { MercuryStoreUI.adrStateSubject.subscribe(definition -> { - switch (definition.getState()){ + switch (definition.getState()) { case MAIN: { this.mainPanel.setFromGroup(definition.getPayload() != null); this.mainPanel.setPayload((AdrComponentDescriptor) definition.getPayload()); this.adrManagerFrame.setPage(this.mainPanel); break; } - case PROFILES_SETTINGS:{ + case PROFILES_SETTINGS: { this.profileSettingsPanel.setPayload(this.config.getEntities()); this.adrManagerFrame.setPage(this.profileSettingsPanel); break; @@ -101,94 +103,94 @@ public void subscribe() { } }); MercuryStoreUI.adrComponentStateSubject.subscribe(definition -> { - switch (definition.getOperations()){ - case NEW_COMPONENT:{ - if(definition.getDescriptor() instanceof AdrTrackerGroupDescriptor){ - this.selectedProfile.getContents().add(definition.getDescriptor()); - AbstractAdrFrame frame = this.frameProviderFactory - .getProviderFor(definition.getDescriptor()) - .getFrame(true); - this.frames.add(frame); - this.groupSettingsPanel.setPayload((AdrTrackerGroupDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.groupSettingsPanel); - } - if(definition.getDescriptor() instanceof AdrDurationComponentDescriptor){ - if(definition.getParent() == null){ - this.selectedProfile.getContents().add(definition.getDescriptor()); - AbstractAdrFrame componentFrame = this.frameProviderFactory - .getProviderFor(definition.getDescriptor()) - .getFrame(true); - this.frames.add(componentFrame); - }else { - ((AdrTrackerGroupDescriptor)definition.getParent()).getCells().add(definition.getDescriptor()); - } - if(definition.getDescriptor() instanceof AdrIconDescriptor){ - this.iconSettingsPanel.setFromGroup(definition.getParent() != null); - this.iconSettingsPanel.setPayload((AdrIconDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.iconSettingsPanel); - }else { - this.progressBarSettingsPanel.setFromGroup(definition.getParent() != null); - this.progressBarSettingsPanel.setPayload((AdrProgressBarDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.progressBarSettingsPanel); - } - } - if(definition.getDescriptor() instanceof AdrCaptureDescriptor){ - AdrCaptureDescriptor descriptor = (AdrCaptureDescriptor) definition.getDescriptor(); - this.frames.add(this.frameProviderFactory.getProviderFor(descriptor).getFrame(true)); + switch (definition.getOperations()) { + case NEW_COMPONENT: { + if (definition.getDescriptor() instanceof AdrTrackerGroupDescriptor) { + this.selectedProfile.getContents().add(definition.getDescriptor()); + AbstractAdrFrame frame = this.frameProviderFactory + .getProviderFor(definition.getDescriptor()) + .getFrame(true); + this.frames.add(frame); + this.groupSettingsPanel.setPayload((AdrTrackerGroupDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.groupSettingsPanel); + } + if (definition.getDescriptor() instanceof AdrDurationComponentDescriptor) { + if (definition.getParent() == null) { + this.selectedProfile.getContents().add(definition.getDescriptor()); + AbstractAdrFrame componentFrame = this.frameProviderFactory + .getProviderFor(definition.getDescriptor()) + .getFrame(true); + this.frames.add(componentFrame); + } else { + ((AdrTrackerGroupDescriptor) definition.getParent()).getCells().add(definition.getDescriptor()); + } + if (definition.getDescriptor() instanceof AdrIconDescriptor) { + this.iconSettingsPanel.setFromGroup(definition.getParent() != null); + this.iconSettingsPanel.setPayload((AdrIconDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.iconSettingsPanel); + } else { + this.progressBarSettingsPanel.setFromGroup(definition.getParent() != null); + this.progressBarSettingsPanel.setPayload((AdrProgressBarDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.progressBarSettingsPanel); + } + } + if (definition.getDescriptor() instanceof AdrCaptureDescriptor) { + AdrCaptureDescriptor descriptor = (AdrCaptureDescriptor) definition.getDescriptor(); + this.frames.add(this.frameProviderFactory.getProviderFor(descriptor).getFrame(true)); - AdrCaptureOutComponentFrame outFrame = new AdrCaptureOutComponentFrame((AdrCaptureDescriptor) descriptor); - outFrame.setPanel(new AdrCaptureOutPanel((AdrCaptureDescriptor) descriptor,new ComponentsFactory())); - outFrame.init(); - outFrame.showComponent(); - outFrame.enableSettings(); - this.frames.add(outFrame); + AdrCaptureOutComponentFrame outFrame = new AdrCaptureOutComponentFrame((AdrCaptureDescriptor) descriptor); + outFrame.setPanel(new AdrCaptureOutPanel((AdrCaptureDescriptor) descriptor, new ComponentsFactory())); + outFrame.init(); + outFrame.showComponent(); + outFrame.enableSettings(); + this.frames.add(outFrame); - this.captureSettingsPanel.setPayload((AdrCaptureDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.captureSettingsPanel); + this.captureSettingsPanel.setPayload((AdrCaptureDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.captureSettingsPanel); - this.selectedProfile.getContents().add(definition.getDescriptor()); - } - this.adrManagerFrame.addNewNode(definition.getDescriptor(),definition.getParent()); - MercuryStoreUI.adrSelectSubject.onNext(definition.getDescriptor()); - MercuryStoreCore.saveConfigSubject.onNext(true); - MercuryStoreUI.adrPostOperationsComponentSubject.onNext(definition.getDescriptor()); - break; - } - case EDIT_COMPONENT:{ - if(definition.getDescriptor() instanceof AdrTrackerGroupDescriptor){ - this.groupSettingsPanel.setPayload((AdrTrackerGroupDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.groupSettingsPanel); - } - if(definition.getDescriptor() instanceof AdrIconDescriptor){ - this.iconSettingsPanel.setFromGroup(definition.isFromGroup()); - this.iconSettingsPanel.setPayload((AdrIconDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.iconSettingsPanel); - } - if(definition.getDescriptor() instanceof AdrProgressBarDescriptor){ - this.progressBarSettingsPanel.setFromGroup(definition.isFromGroup()); - this.progressBarSettingsPanel.setPayload((AdrProgressBarDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.progressBarSettingsPanel); - } - if(definition.getDescriptor() instanceof AdrCaptureDescriptor){ - this.captureSettingsPanel.setPayload((AdrCaptureDescriptor) definition.getDescriptor()); - this.adrManagerFrame.setPage(this.captureSettingsPanel); - } - break; - } - case DUPLICATE_COMPONENT:{ - this.adrManagerFrame.duplicateNode(definition.getDescriptor()); - MercuryStoreUI.adrSelectSubject.onNext(definition.getDescriptor()); - MercuryStoreCore.saveConfigSubject.onNext(true); - MercuryStoreUI.adrPostOperationsComponentSubject.onNext(definition.getDescriptor()); - break; - } - case NEW_FROM_IMPORT:{ - this.selectedProfile.getContents().addAll(definition.getDescriptors()); - MercuryStoreCore.saveConfigSubject.onNext(true); - this.selectProfile(this.selectedProfile.getProfileName()); - break; - } - } + this.selectedProfile.getContents().add(definition.getDescriptor()); + } + this.adrManagerFrame.addNewNode(definition.getDescriptor(), definition.getParent()); + MercuryStoreUI.adrSelectSubject.onNext(definition.getDescriptor()); + MercuryStoreCore.saveConfigSubject.onNext(true); + MercuryStoreUI.adrPostOperationsComponentSubject.onNext(definition.getDescriptor()); + break; + } + case EDIT_COMPONENT: { + if (definition.getDescriptor() instanceof AdrTrackerGroupDescriptor) { + this.groupSettingsPanel.setPayload((AdrTrackerGroupDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.groupSettingsPanel); + } + if (definition.getDescriptor() instanceof AdrIconDescriptor) { + this.iconSettingsPanel.setFromGroup(definition.isFromGroup()); + this.iconSettingsPanel.setPayload((AdrIconDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.iconSettingsPanel); + } + if (definition.getDescriptor() instanceof AdrProgressBarDescriptor) { + this.progressBarSettingsPanel.setFromGroup(definition.isFromGroup()); + this.progressBarSettingsPanel.setPayload((AdrProgressBarDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.progressBarSettingsPanel); + } + if (definition.getDescriptor() instanceof AdrCaptureDescriptor) { + this.captureSettingsPanel.setPayload((AdrCaptureDescriptor) definition.getDescriptor()); + this.adrManagerFrame.setPage(this.captureSettingsPanel); + } + break; + } + case DUPLICATE_COMPONENT: { + this.adrManagerFrame.duplicateNode(definition.getDescriptor()); + MercuryStoreUI.adrSelectSubject.onNext(definition.getDescriptor()); + MercuryStoreCore.saveConfigSubject.onNext(true); + MercuryStoreUI.adrPostOperationsComponentSubject.onNext(definition.getDescriptor()); + break; + } + case NEW_FROM_IMPORT: { + this.selectedProfile.getContents().addAll(definition.getDescriptors()); + MercuryStoreCore.saveConfigSubject.onNext(true); + this.selectProfile(this.selectedProfile.getProfileName()); + break; + } + } }); MercuryStoreUI.adrRemoveComponentSubject.subscribe(descriptor -> { List targetFrames = @@ -236,7 +238,8 @@ public void subscribe() { MercuryStoreCore.saveConfigSubject.onNext(true); }); } - private void selectProfile(String profileName){ + + private void selectProfile(String profileName) { this.adrManagerFrame.setPage(this.loadingPage); this.loadingPage.playLoop(); AdrProfileDescriptor selectedProfile = this.config.getEntities() @@ -267,7 +270,8 @@ protected void done() { this.adrManagerFrame.setSelectedProfile(selectedProfile); MercuryStoreCore.saveConfigSubject.onNext(true); } - private void initComponents(boolean showSettings){ + + private void initComponents(boolean showSettings) { MercuryStoreUI.onDestroySubject.onNext(true); this.frames.forEach(it -> { it.onDestroy(); @@ -277,19 +281,19 @@ private void initComponents(boolean showSettings){ }); this.frames.clear(); this.selectedProfile.getContents().forEach(component -> { - if(component instanceof AdrCaptureDescriptor){ + if (component instanceof AdrCaptureDescriptor) { this.frames.add(this.frameProviderFactory.getProviderFor(component).getFrame(showSettings)); AdrCaptureOutComponentFrame outFrame = new AdrCaptureOutComponentFrame((AdrCaptureDescriptor) component); - outFrame.setPanel(new AdrCaptureOutPanel((AdrCaptureDescriptor) component,new ComponentsFactory())); + outFrame.setPanel(new AdrCaptureOutPanel((AdrCaptureDescriptor) component, new ComponentsFactory())); outFrame.init(); - if(showSettings) { + if (showSettings) { outFrame.showComponent(); outFrame.enableSettings(); - }else { + } else { outFrame.disableSettings(); } this.frames.add(outFrame); - }else { + } else { this.frames.add(this.frameProviderFactory.getProviderFor(component).getFrame(showSettings)); } }); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrComponentFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrComponentFrame.java index 977b5574..5ca6fca3 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrComponentFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrComponentFrame.java @@ -5,7 +5,6 @@ import com.mercury.platform.ui.adr.components.panel.tree.AdrMouseOverListener; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; -import rx.Subscription; import javax.swing.*; import java.awt.*; @@ -13,13 +12,12 @@ import java.awt.event.MouseEvent; -public abstract class AbstractAdrComponentFrame extends AbstractAdrFrame{ - private int x; - private int y; - +public abstract class AbstractAdrComponentFrame extends AbstractAdrFrame { protected DraggedFrameMouseListener mouseListener; protected DraggedFrameMotionListener motionListener; protected AdrMouseOverListener mouseOverListener; + private int x; + private int y; public AbstractAdrComponentFrame(T descriptor) { super(descriptor); @@ -27,7 +25,7 @@ public AbstractAdrComponentFrame(T descriptor) { this.mouseListener = new DraggedFrameMouseListener(); this.motionListener = new DraggedFrameMotionListener(); - this.mouseOverListener = new AdrMouseOverListener<>(this.getRootPane(),this.descriptor,false); + this.mouseOverListener = new AdrMouseOverListener<>(this.getRootPane(), this.descriptor, false); } @@ -55,23 +53,24 @@ public void onDestroy() { @Override protected LayoutManager getFrameLayout() { - return new GridLayout(1,1); + return new GridLayout(1, 1); } public class DraggedFrameMotionListener extends MouseAdapter { @Override public void mouseDragged(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { e.translatePoint(AbstractAdrComponentFrame.this.getLocation().x - x, AbstractAdrComponentFrame.this.getLocation().y - y); Point point = e.getPoint(); AbstractAdrComponentFrame.this.setLocation(point); } } } - public class DraggedFrameMouseListener extends MouseAdapter{ + + public class DraggedFrameMouseListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { x = e.getX(); y = e.getY(); } @@ -79,7 +78,7 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); if (getLocationOnScreen().y + getSize().height > dimension.height) { setLocation(getLocationOnScreen().x, dimension.height - getSize().height); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrFrame.java index 34e09184..4a911e8f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AbstractAdrFrame.java @@ -16,10 +16,10 @@ import java.awt.*; -public abstract class AbstractAdrFrame extends AbstractOverlaidFrame implements DestroySubscription{ - private int settingWl; +public abstract class AbstractAdrFrame extends AbstractOverlaidFrame implements DestroySubscription { @Getter protected T descriptor; + private int settingWl; private WinDef.HWND componentHwnd; private Subscription adrRepaintSubscription; @@ -30,6 +30,13 @@ protected AbstractAdrFrame(T descriptor) { this.descriptor = descriptor; AWTUtilities.setWindowOpaque(this, false); } + + private static WinDef.HWND getHWnd(Component w) { + WinDef.HWND hwnd = new WinDef.HWND(); + hwnd.setPointer(Native.getComponentPointer(w)); + return hwnd; + } + @Override protected void initialize() { this.setLocation(descriptor.getLocation()); @@ -66,11 +73,6 @@ private void setTransparent(Component w) { WinUser.WS_EX_TRANSPARENT; User32.INSTANCE.SetWindowLong(componentHwnd, WinUser.GWL_EXSTYLE, transparentWl); } - private static WinDef.HWND getHWnd(Component w) { - WinDef.HWND hwnd = new WinDef.HWND(); - hwnd.setPointer(Native.getComponentPointer(w)); - return hwnd; - } @Override public void onDestroy() { @@ -83,6 +85,7 @@ public void onDestroy() { public void enableSettings() { User32.INSTANCE.SetWindowLong(componentHwnd, WinUser.GWL_EXSTYLE, settingWl); } + public void disableSettings() { this.showComponent(); setTransparent(this); 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 eabad999..f7f6f182 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 @@ -14,7 +14,7 @@ import java.awt.event.MouseEvent; -public class AdrCaptureOutComponentFrame extends AbstractAdrFrame{ +public class AdrCaptureOutComponentFrame extends AbstractAdrFrame { private int x; private int y; @Getter @@ -25,12 +25,13 @@ public class AdrCaptureOutComponentFrame extends AbstractAdrFrame(this.getRootPane(),this.descriptor,false); + this.mouseOverListener = new AdrMouseOverListener<>(this.getRootPane(), this.descriptor, false); } @Override @@ -40,22 +41,23 @@ public void setPanel(AdrComponentPanel panel) { @Override protected LayoutManager getFrameLayout() { - return new GridLayout(1,1); + return new GridLayout(1, 1); } @Override protected void initialize() { this.setLocation(descriptor.getCaptureLocation()); this.componentsFactory.setScale(descriptor.getScale()); - this.setLayout(new GridLayout(1,1)); + this.setLayout(new GridLayout(1, 1)); this.add(this.component); this.pack(); } + @Override public void subscribe() { super.subscribe(); this.adrReloadSubscription = MercuryStoreUI.adrReloadSubject.subscribe(descriptor -> { - if(descriptor.equals(this.descriptor)){ + if (descriptor.equals(this.descriptor)) { this.setLocation(this.descriptor.getCaptureLocation()); this.setPreferredSize(this.descriptor.getCaptureSize()); this.repaint(); @@ -63,6 +65,7 @@ public void subscribe() { } }); } + @Override public void enableSettings() { super.enableSettings(); @@ -89,7 +92,7 @@ public void disableSettings() { this.component.removeMouseListener(this.mouseOverListener); this.component.removeMouseMotionListener(this.motionListener); - this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); this.pack(); this.repaint(); } @@ -110,17 +113,18 @@ public void onViewInit() { public class CaptureDraggedFrameMotionListener extends MouseAdapter { @Override public void mouseDragged(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { e.translatePoint(AdrCaptureOutComponentFrame.this.getLocation().x - x, AdrCaptureOutComponentFrame.this.getLocation().y - y); Point point = e.getPoint(); AdrCaptureOutComponentFrame.this.setLocation(point); } } } - public class CaptureDraggedFrameMouseListener extends MouseAdapter{ + + public class CaptureDraggedFrameMouseListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { x = e.getX(); y = e.getY(); } @@ -128,7 +132,7 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); if (getLocationOnScreen().y + getSize().height > dimension.height) { setLocation(getLocationOnScreen().x, dimension.height - getSize().height); 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 9d440bdd..7edb56e3 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 @@ -17,7 +17,6 @@ import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.dialog.AlertDialog; import com.mercury.platform.ui.dialog.DialogCallback; -import com.mercury.platform.ui.adr.dialog.AdrIconSelectDialog; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; import com.mercury.platform.ui.misc.TooltipConstants; @@ -39,30 +38,30 @@ public AdrComponentsFactory(ComponentsFactory componentsFactory) { this.config = Configuration.get().iconBundleConfiguration(); } - public JPanel getComponentSizePanel(AdrComponentDescriptor descriptor, boolean fromGroup){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4,4,0)); + public JPanel getComponentSizePanel(AdrComponentDescriptor descriptor, boolean fromGroup) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JLabel widthLabel = this.componentsFactory.getTextLabel("Width:"); JLabel heightLabel = this.componentsFactory.getTextLabel("Height:"); - JTextField widthField = this.getSmartField(descriptor.getSize().width, new IntegerFieldValidator(10,2000), value -> { + JTextField widthField = this.getSmartField(descriptor.getSize().width, new IntegerFieldValidator(10, 2000), value -> { descriptor.setSize(new Dimension(value, descriptor.getSize().height)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setSize(descriptor.getSize())); } MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JTextField heightField = this.getSmartField(descriptor.getSize().height, new IntegerFieldValidator(10,1000), value -> { - descriptor.setSize(new Dimension(descriptor.getSize().width,value)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + JTextField heightField = this.getSmartField(descriptor.getSize().height, new IntegerFieldValidator(10, 1000), value -> { + descriptor.setSize(new Dimension(descriptor.getSize().width, value)); + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setSize(descriptor.getSize())); } MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); MercuryStoreUI.adrUpdateSubject.subscribe(source -> { - if(source.equals(descriptor)){ + if (source.equals(descriptor)) { widthField.setText(String.valueOf(descriptor.getSize().width)); heightField.setText(String.valueOf(descriptor.getSize().height)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setSize(descriptor.getSize())); } } @@ -73,24 +72,24 @@ public JPanel getComponentSizePanel(AdrComponentDescriptor descriptor, boolean f root.add(heightLabel); root.add(heightField); - if(fromGroup){ + if (fromGroup) { widthField.setEnabled(false); heightField.setEnabled(false); } return root; } - public JPanel getCaptureSizePanel(AdrCaptureDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4,4,0)); + public JPanel getCaptureSizePanel(AdrCaptureDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JLabel widthLabel = this.componentsFactory.getTextLabel("Width:"); JLabel heightLabel = this.componentsFactory.getTextLabel("Height:"); - JTextField widthField = this.getSmartField(descriptor.getCaptureSize().width, new IntegerFieldValidator(10,2000), value -> { + JTextField widthField = this.getSmartField(descriptor.getCaptureSize().width, new IntegerFieldValidator(10, 2000), value -> { descriptor.setCaptureSize(new Dimension(value, descriptor.getCaptureSize().height)); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JTextField heightField = this.getSmartField(descriptor.getCaptureSize().height, new IntegerFieldValidator(10,1000), value -> { - descriptor.setCaptureSize(new Dimension(descriptor.getCaptureSize().width,value)); + JTextField heightField = this.getSmartField(descriptor.getCaptureSize().height, new IntegerFieldValidator(10, 1000), value -> { + descriptor.setCaptureSize(new Dimension(descriptor.getCaptureSize().width, value)); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); @@ -101,21 +100,21 @@ public JPanel getCaptureSizePanel(AdrCaptureDescriptor descriptor){ return root; } - public JPanel getLocationPanel(AdrComponentDescriptor descriptor, boolean fromGroup){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4,4,0)); + public JPanel getLocationPanel(AdrComponentDescriptor descriptor, boolean fromGroup) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JLabel xLabel = this.componentsFactory.getTextLabel("X:"); JLabel yLabel = this.componentsFactory.getTextLabel("Y:"); - JTextField xField = this.getSmartField(descriptor.getLocation().x,new IntegerFieldValidator(0,10000),value -> { + JTextField xField = this.getSmartField(descriptor.getLocation().x, new IntegerFieldValidator(0, 10000), value -> { descriptor.setLocation(new Point(value, descriptor.getLocation().y)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setLocation(descriptor.getLocation())); } MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JTextField yField = this.getSmartField(descriptor.getLocation().y,new IntegerFieldValidator(0,5000),value -> { - descriptor.setLocation(new Point(descriptor.getLocation().x,value)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + JTextField yField = this.getSmartField(descriptor.getLocation().y, new IntegerFieldValidator(0, 5000), value -> { + descriptor.setLocation(new Point(descriptor.getLocation().x, value)); + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setLocation(descriptor.getLocation())); } MercuryStoreUI.adrReloadSubject.onNext(descriptor); @@ -126,33 +125,33 @@ public JPanel getLocationPanel(AdrComponentDescriptor descriptor, boolean fromGr root.add(yField); MercuryStoreUI.adrUpdateSubject.subscribe(source -> { - if(source.equals(descriptor)){ + if (source.equals(descriptor)) { xField.setText(String.valueOf(descriptor.getLocation().x)); yField.setText(String.valueOf(descriptor.getLocation().y)); - if(descriptor instanceof AdrTrackerGroupDescriptor){ + if (descriptor instanceof AdrTrackerGroupDescriptor) { ((AdrTrackerGroupDescriptor) descriptor).getCells().forEach(item -> item.setLocation(descriptor.getLocation())); } } }); - if(fromGroup){ + if (fromGroup) { xField.setEnabled(false); yField.setEnabled(false); } return root; } - public JPanel getCaptureLocationPanel(AdrCaptureDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4,4,0)); + public JPanel getCaptureLocationPanel(AdrCaptureDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JLabel xLabel = this.componentsFactory.getTextLabel("X:"); JLabel yLabel = this.componentsFactory.getTextLabel("Y:"); - JTextField xField = this.getSmartField(descriptor.getCaptureLocation().x,new IntegerFieldValidator(0,10000),value -> { + JTextField xField = this.getSmartField(descriptor.getCaptureLocation().x, new IntegerFieldValidator(0, 10000), value -> { descriptor.setCaptureLocation(new Point(value, descriptor.getCaptureLocation().y)); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JTextField yField = this.getSmartField(descriptor.getCaptureLocation().y,new IntegerFieldValidator(0,5000),value -> { - descriptor.setCaptureLocation(new Point(descriptor.getCaptureLocation().x,value)); + JTextField yField = this.getSmartField(descriptor.getCaptureLocation().y, new IntegerFieldValidator(0, 5000), value -> { + descriptor.setCaptureLocation(new Point(descriptor.getCaptureLocation().x, value)); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); root.add(xLabel); @@ -161,7 +160,7 @@ public JPanel getCaptureLocationPanel(AdrCaptureDescriptor descriptor){ root.add(yField); MercuryStoreUI.adrUpdateSubject.subscribe(source -> { - if(source.equals(descriptor)){ + if (source.equals(descriptor)) { xField.setText(String.valueOf(descriptor.getCaptureLocation().x)); yField.setText(String.valueOf(descriptor.getCaptureLocation().y)); } @@ -175,7 +174,7 @@ public JButton getHotKeyButton(AdrDurationComponentDescriptor descriptor) { MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { button.setBackground(AppThemeColor.SLIDE_BG); button.setText("Press any key"); allowed = true; @@ -201,22 +200,22 @@ public void mousePressed(MouseEvent e) { return button; } - public JPanel getHotKeyPanel(AdrDurationComponentDescriptor descriptor){ + public JPanel getHotKeyPanel(AdrDurationComponentDescriptor descriptor) { JButton hotKeyButton = this.getHotKeyButton(descriptor); JPanel hotKeyPanel = this.componentsFactory.getJPanel(new BorderLayout()); hotKeyPanel.setBackground(AppThemeColor.SLIDE_BG); - JCheckBox refreshBox = this.componentsFactory.getCheckBox(descriptor.isHotKeyRefresh(),"Always refresh?"); + JCheckBox refreshBox = this.componentsFactory.getCheckBox(descriptor.isHotKeyRefresh(), "Always refresh?"); refreshBox.addActionListener(state -> { descriptor.setHotKeyRefresh(refreshBox.isSelected()); MercuryStoreUI.adrReloadSubject.onNext(descriptor); MercuryStoreUI.adrManagerPack.onNext(true); }); - hotKeyPanel.add(refreshBox,BorderLayout.LINE_START); - hotKeyPanel.add(hotKeyButton,BorderLayout.CENTER); + hotKeyPanel.add(refreshBox, BorderLayout.LINE_START); + hotKeyPanel.add(hotKeyButton, BorderLayout.CENTER); return hotKeyPanel; } - public JPanel getInsetsPanel(AdrDurationComponentDescriptor descriptor){ + public JPanel getInsetsPanel(AdrDurationComponentDescriptor descriptor) { JLabel topLabel = this.componentsFactory.getTextLabel("T:"); JLabel leftLabel = this.componentsFactory.getTextLabel("L:"); JLabel bottomLabel = this.componentsFactory.getTextLabel("B:"); @@ -242,41 +241,42 @@ public JPanel getInsetsPanel(AdrDurationComponentDescriptor descriptor){ descriptor.setInsets(new Insets(currentInsets.top, currentInsets.left, currentInsets.bottom, value)); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1,8,4,0)); + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 8, 4, 0)); root.setBackground(AppThemeColor.ADR_BG); root.add(topLabel); - root.add(this.componentsFactory.wrapToSlide(topField,AppThemeColor.ADR_BG)); + root.add(this.componentsFactory.wrapToSlide(topField, AppThemeColor.ADR_BG)); root.add(leftLabel); - root.add(this.componentsFactory.wrapToSlide(leftField,AppThemeColor.ADR_BG)); + root.add(this.componentsFactory.wrapToSlide(leftField, AppThemeColor.ADR_BG)); root.add(bottomLabel); - root.add(this.componentsFactory.wrapToSlide(bottomField,AppThemeColor.ADR_BG)); + root.add(this.componentsFactory.wrapToSlide(bottomField, AppThemeColor.ADR_BG)); root.add(rightLabel); - root.add(this.componentsFactory.wrapToSlide(rightField,AppThemeColor.ADR_BG)); + root.add(this.componentsFactory.wrapToSlide(rightField, AppThemeColor.ADR_BG)); return root; } - public JPanel getIconSelectPanel(AdrDurationComponentDescriptor descriptor){ + public JPanel getIconSelectPanel(AdrDurationComponentDescriptor descriptor) { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.ADR_BG); JLabel iconLabel = this.componentsFactory.getIconLabel(this.config.getIcon(descriptor.getIconPath()), 26); JLabel iconPathLabel = this.componentsFactory.getTextLabel(descriptor.getIconPath()); root.add(iconLabel, BorderLayout.LINE_START); - root.add(iconPathLabel,BorderLayout.CENTER); + root.add(iconPathLabel, BorderLayout.CENTER); JButton selectIcon = this.componentsFactory.getBorderedButton("Select"); selectIcon.addActionListener(action -> { MercuryStoreUI.adrOpenIconSelectSubject.onNext(selectedIconPath -> { descriptor.setIconPath(selectedIconPath); - iconLabel.setIcon(this.componentsFactory.getIcon(this.config.getIcon(selectedIconPath),26)); + iconLabel.setIcon(this.componentsFactory.getIcon(this.config.getIcon(selectedIconPath), 26)); iconPathLabel.setText(descriptor.getIconPath()); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); }); - root.add(selectIcon,BorderLayout.LINE_END); + root.add(selectIcon, BorderLayout.LINE_END); return root; } - private JPanel getTextColorPanel(AdrDurationComponentDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1,7,2,0)); + + private JPanel getTextColorPanel(AdrDurationComponentDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 7, 2, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JColorChooser colorChooser = getColorChooser(); @@ -293,8 +293,8 @@ private JPanel getTextColorPanel(AdrDurationComponentDescriptor descriptor){ mediumValuePanel.setBackground(descriptor.getMediumValueTextColor()); lowValuePanel.setBackground(descriptor.getLowValueTextColor()); - JLabel conditionLabel = this.componentsFactory.getTextLabel("<",FontStyle.BOLD,24); - JLabel conditionLabel1 = this.componentsFactory.getTextLabel("<",FontStyle.BOLD,24); + JLabel conditionLabel = this.componentsFactory.getTextLabel("<", FontStyle.BOLD, 24); + JLabel conditionLabel1 = this.componentsFactory.getTextLabel("<", FontStyle.BOLD, 24); conditionLabel.setBorder(null); conditionLabel1.setBorder(null); conditionLabel.setHorizontalAlignment(SwingConstants.CENTER); @@ -309,7 +309,7 @@ private JPanel getTextColorPanel(AdrDurationComponentDescriptor descriptor){ new DoubleFieldValidator(0.1, 1000.0), descriptor::setDefaultValueTextThreshold); - defaultValuePanel.addMouseListener(new ColorChooserMouseListener(defaultValuePanel){ + defaultValuePanel.addMouseListener(new ColorChooserMouseListener(defaultValuePanel) { @Override public void mouseClicked(MouseEvent e) { colorChooser.setColor(descriptor.getDefaultValueTextColor()); @@ -325,7 +325,7 @@ public void mouseClicked(MouseEvent e) { dialog.setVisible(true); } }); - mediumValuePanel.addMouseListener(new ColorChooserMouseListener(mediumValuePanel){ + mediumValuePanel.addMouseListener(new ColorChooserMouseListener(mediumValuePanel) { @Override public void mouseClicked(MouseEvent e) { colorChooser.setColor(descriptor.getMediumValueTextColor()); @@ -341,7 +341,7 @@ public void mouseClicked(MouseEvent e) { dialog.setVisible(true); } }); - lowValuePanel.addMouseListener(new ColorChooserMouseListener(lowValuePanel){ + lowValuePanel.addMouseListener(new ColorChooserMouseListener(lowValuePanel) { @Override public void mouseClicked(MouseEvent e) { colorChooser.setColor(descriptor.getLowValueTextColor()); @@ -357,21 +357,21 @@ public void mouseClicked(MouseEvent e) { dialog.setVisible(true); } }); - root.add(this.componentsFactory.wrapToSlide(lowValuePanel,AppThemeColor.ADR_BG,4,0,4,0)); + root.add(this.componentsFactory.wrapToSlide(lowValuePanel, AppThemeColor.ADR_BG, 4, 0, 4, 0)); root.add(conditionLabel); - root.add(this.componentsFactory.wrapToSlide(mediumThreshold,AppThemeColor.ADR_BG,4,0,4,0)); - root.add(this.componentsFactory.wrapToSlide(mediumValuePanel,AppThemeColor.ADR_BG,4,0,4,0)); + root.add(this.componentsFactory.wrapToSlide(mediumThreshold, AppThemeColor.ADR_BG, 4, 0, 4, 0)); + root.add(this.componentsFactory.wrapToSlide(mediumValuePanel, AppThemeColor.ADR_BG, 4, 0, 4, 0)); root.add(conditionLabel1); - root.add(this.componentsFactory.wrapToSlide(defaultThreshold,AppThemeColor.ADR_BG,4,0,4,0)); - root.add(this.componentsFactory.wrapToSlide(defaultValuePanel,AppThemeColor.ADR_BG,4,0,4,0)); + root.add(this.componentsFactory.wrapToSlide(defaultThreshold, AppThemeColor.ADR_BG, 4, 0, 4, 0)); + root.add(this.componentsFactory.wrapToSlide(defaultValuePanel, AppThemeColor.ADR_BG, 4, 0, 4, 0)); return root; } - public JComboBox getTextFormatBox(AdrDurationComponentDescriptor descriptor){ - JComboBox textFormatBox = this.componentsFactory.getComboBox(new String[]{"0", "0.0","0.00","0.000"}); + public JComboBox getTextFormatBox(AdrDurationComponentDescriptor descriptor) { + JComboBox textFormatBox = this.componentsFactory.getComboBox(new String[]{"0", "0.0", "0.00", "0.000"}); textFormatBox.setSelectedItem(descriptor.getTextFormat()); textFormatBox.addItemListener(e -> { - if(e.getStateChange() == ItemEvent.SELECTED) { + if (e.getStateChange() == ItemEvent.SELECTED) { descriptor.setTextFormat((String) textFormatBox.getSelectedItem()); MercuryStoreUI.adrUpdateSubject.onNext(descriptor); MercuryStoreUI.adrReloadSubject.onNext(descriptor); @@ -379,8 +379,9 @@ public JComboBox getTextFormatBox(AdrDurationComponentDescriptor descriptor){ }); return textFormatBox; } - public JTextField getTitleField(AdrComponentDescriptor descriptor){ - JTextField titleField = this.componentsFactory.getTextField(descriptor.getTitle(), FontStyle.REGULAR,18); + + public JTextField getTitleField(AdrComponentDescriptor descriptor) { + JTextField titleField = this.componentsFactory.getTextField(descriptor.getTitle(), FontStyle.REGULAR, 18); titleField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { @@ -390,8 +391,9 @@ public void focusLost(FocusEvent e) { }); return titleField; } - public JSlider getOpacitySlider(AdrComponentDescriptor descriptor){ - JSlider opacitySlider = this.componentsFactory.getSlider(20,100, (int) (descriptor.getOpacity() * 100)); + + public JSlider getOpacitySlider(AdrComponentDescriptor descriptor) { + JSlider opacitySlider = this.componentsFactory.getSlider(20, 100, (int) (descriptor.getOpacity() * 100)); opacitySlider.setBackground(AppThemeColor.SLIDE_BG); opacitySlider.addMouseListener(new MouseAdapter() { @Override @@ -402,11 +404,12 @@ public void mouseReleased(MouseEvent e) { }); return opacitySlider; } - public JPanel getFpsSliderPanel(AdrCaptureDescriptor descriptor){ + + 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()); + 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 @@ -416,29 +419,33 @@ public void mouseReleased(MouseEvent e) { MercuryStoreUI.adrReloadSubject.onNext(descriptor); } }); - fpsPanel.add(fpsCountLabel,BorderLayout.LINE_START); - fpsPanel.add(fpsSlider,BorderLayout.CENTER); + fpsPanel.add(fpsCountLabel, BorderLayout.LINE_START); + fpsPanel.add(fpsSlider, BorderLayout.CENTER); return fpsPanel; } - public JTextField getFontSizeField(AdrDurationComponentDescriptor descriptor){ + + public JTextField getFontSizeField(AdrDurationComponentDescriptor descriptor) { return this.getSmartField(descriptor.getFontSize(), new IntegerFieldValidator(4, 1000), value -> { descriptor.setFontSize(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JTextField getDurationField(AdrDurationComponentDescriptor descriptor){ + + public JTextField getDurationField(AdrDurationComponentDescriptor descriptor) { return this.getSmartField(descriptor.getDuration(), new DoubleFieldValidator(0.1, 1000.0), value -> { descriptor.setDuration(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JTextField getDelayField(AdrDurationComponentDescriptor descriptor){ + + public JTextField getDelayField(AdrDurationComponentDescriptor descriptor) { return this.getSmartField(descriptor.getDelay(), new DoubleFieldValidator(0.0, 1000.0), value -> { descriptor.setDelay(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JPanel getBackgroundColorPanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getBackgroundColorPanel(AdrDurationComponentDescriptor descriptor) { return this.getHexColorPickerPanel( descriptor::getBackgroundColor, color -> { @@ -446,25 +453,27 @@ public JPanel getBackgroundColorPanel(AdrDurationComponentDescriptor descriptor) MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JPanel getTextOutlinePanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getTextOutlinePanel(AdrDurationComponentDescriptor descriptor) { JPanel textPanel = this.componentsFactory.getJPanel(new BorderLayout()); textPanel.setBackground(AppThemeColor.SLIDE_BG); JTextField outlineThicknessField = this.getSmartField(descriptor.getOutlineThickness(), new FloatFieldValidator(0f, 20f), value -> { descriptor.setOutlineThickness(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - outlineThicknessField.setPreferredSize(new Dimension(40,20)); + outlineThicknessField.setPreferredSize(new Dimension(40, 20)); JPanel outlineColor = this.getHexColorPickerPanel( descriptor::getOutlineColor, color -> { descriptor.setOutlineColor(color); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - textPanel.add(this.componentsFactory.wrapToSlide(outlineThicknessField,AppThemeColor.ADR_BG,6,6,6,4),BorderLayout.LINE_START); - textPanel.add(outlineColor,BorderLayout.CENTER); + textPanel.add(this.componentsFactory.wrapToSlide(outlineThicknessField, AppThemeColor.ADR_BG, 6, 6, 6, 4), BorderLayout.LINE_START); + textPanel.add(outlineColor, BorderLayout.CENTER); return textPanel; } - public JPanel getForegroundColorPanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getForegroundColorPanel(AdrDurationComponentDescriptor descriptor) { return this.getHexColorPickerPanel( descriptor::getForegroundColor, color -> { @@ -472,7 +481,8 @@ public JPanel getForegroundColorPanel(AdrDurationComponentDescriptor descriptor) MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JCheckBox getAlwaysVisibleBox(AdrDurationComponentDescriptor descriptor){ + + public JCheckBox getAlwaysVisibleBox(AdrDurationComponentDescriptor descriptor) { JCheckBox alwaysVisibleBox = this.componentsFactory.getCheckBox(descriptor.isAlwaysVisible()); alwaysVisibleBox.addActionListener(action -> { descriptor.setAlwaysVisible(alwaysVisibleBox.isSelected()); @@ -480,7 +490,8 @@ public JCheckBox getAlwaysVisibleBox(AdrDurationComponentDescriptor descriptor){ }); return alwaysVisibleBox; } - public JCheckBox getInvertTimerBox(AdrDurationComponentDescriptor descriptor){ + + public JCheckBox getInvertTimerBox(AdrDurationComponentDescriptor descriptor) { JCheckBox invertTimerBox = this.componentsFactory.getCheckBox(descriptor.isInvertTimer()); invertTimerBox.addActionListener(action -> { descriptor.setInvertTimer(invertTimerBox.isSelected()); @@ -488,7 +499,8 @@ public JCheckBox getInvertTimerBox(AdrDurationComponentDescriptor descriptor){ }); return invertTimerBox; } - public JCheckBox getInvertMaskBox(AdrDurationComponentDescriptor descriptor){ + + public JCheckBox getInvertMaskBox(AdrDurationComponentDescriptor descriptor) { JCheckBox invertMaskBox = this.componentsFactory.getCheckBox(descriptor.isInvertMask()); invertMaskBox.addActionListener(action -> { descriptor.setInvertMask(invertMaskBox.isSelected()); @@ -496,26 +508,29 @@ public JCheckBox getInvertMaskBox(AdrDurationComponentDescriptor descriptor){ }); return invertMaskBox; } - public JCheckBox getMaskEnableBox(AdrDurationComponentDescriptor descriptor){ + + public JCheckBox getMaskEnableBox(AdrDurationComponentDescriptor descriptor) { JCheckBox animationBox = this.componentsFactory.getCheckBox(descriptor.isMaskEnable()); animationBox.addActionListener(e -> descriptor.setMaskEnable(animationBox.isSelected())); return animationBox; } - public JPanel getExTextColorPanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getExTextColorPanel(AdrDurationComponentDescriptor descriptor) { JPanel textColorPanel = this.getTextColorPanel(descriptor); JPanel textPanel = this.componentsFactory.getJPanel(new BorderLayout()); textPanel.setBackground(AppThemeColor.SLIDE_BG); - JCheckBox textEnableBox = this.componentsFactory.getCheckBox(descriptor.isTextEnable(),"Is text enable?"); + JCheckBox textEnableBox = this.componentsFactory.getCheckBox(descriptor.isTextEnable(), "Is text enable?"); textEnableBox.addActionListener(state -> { descriptor.setTextEnable(textEnableBox.isSelected()); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - textPanel.add(textEnableBox,BorderLayout.LINE_START); - textPanel.add(textColorPanel,BorderLayout.CENTER); + textPanel.add(textEnableBox, BorderLayout.LINE_START); + textPanel.add(textColorPanel, BorderLayout.CENTER); return textPanel; } - public JPanel getBorderColorPanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getBorderColorPanel(AdrDurationComponentDescriptor descriptor) { return this.getBorderColorPanel( descriptor, color -> { @@ -523,11 +538,12 @@ public JPanel getBorderColorPanel(AdrDurationComponentDescriptor descriptor){ MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); } - public JComboBox getPbOrientationBox(AdrProgressBarDescriptor descriptor){ + + public JComboBox getPbOrientationBox(AdrProgressBarDescriptor descriptor) { JComboBox pbOrientation = this.componentsFactory.getComboBox(new String[]{"Horizontal", "Vertical"}); pbOrientation.setSelectedIndex(descriptor.getOrientation().ordinal()); pbOrientation.addItemListener(e -> { - if(e.getStateChange() == ItemEvent.SELECTED) { + if (e.getStateChange() == ItemEvent.SELECTED) { this.swapSize(descriptor); descriptor.setOrientation(AdrComponentOrientation.valueOfPretty((String) pbOrientation.getSelectedItem())); MercuryStoreUI.adrUpdateSubject.onNext(descriptor); @@ -536,25 +552,28 @@ public JComboBox getPbOrientationBox(AdrProgressBarDescriptor descriptor){ }); return pbOrientation; } + private void swapSize(AdrProgressBarDescriptor payload) { - payload.setSize(new Dimension(payload.getSize().height,payload.getSize().width)); + payload.setSize(new Dimension(payload.getSize().height, payload.getSize().width)); } - public JPanel getIconPanel(AdrDurationComponentDescriptor descriptor){ + + public JPanel getIconPanel(AdrDurationComponentDescriptor descriptor) { JPanel iconSelectPanel = this.getIconSelectPanel(descriptor); JPanel iconPanel = this.componentsFactory.getJPanel(new BorderLayout()); iconPanel.setBackground(AppThemeColor.SLIDE_BG); - JCheckBox iconEnableBox = this.componentsFactory.getCheckBox(descriptor.isIconEnable(),"Is icon enable?"); + JCheckBox iconEnableBox = this.componentsFactory.getCheckBox(descriptor.isIconEnable(), "Is icon enable?"); iconEnableBox.addActionListener(state -> { descriptor.setIconEnable(iconEnableBox.isSelected()); MercuryStoreUI.adrReloadSubject.onNext(descriptor); MercuryStoreUI.adrManagerPack.onNext(true); }); - iconPanel.add(iconEnableBox,BorderLayout.LINE_START); - iconPanel.add(iconSelectPanel,BorderLayout.CENTER); + iconPanel.add(iconEnableBox, BorderLayout.LINE_START); + iconPanel.add(iconSelectPanel, BorderLayout.CENTER); return iconPanel; } - public JComboBox getIconAlignment(AdrProgressBarDescriptor descriptor){ - JComboBox iconAlignment = this.componentsFactory.getComboBox(new String[]{"Left","Right","Top","Bottom"}); + + public JComboBox getIconAlignment(AdrProgressBarDescriptor descriptor) { + JComboBox iconAlignment = this.componentsFactory.getComboBox(new String[]{"Left", "Right", "Top", "Bottom"}); iconAlignment.setSelectedItem(descriptor.getIconAlignment().asPretty()); iconAlignment.addItemListener(e -> { descriptor.setIconAlignment(AdrIconAlignment.valueOfPretty((String) iconAlignment.getSelectedItem())); @@ -563,12 +582,13 @@ public JComboBox getIconAlignment(AdrProgressBarDescriptor descriptor){ }); return iconAlignment; } - public JPanel getColorPickerPanel(ValueBinder binder, DialogCallback callback){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1,1,6,0)); + + public JPanel getColorPickerPanel(ValueBinder binder, DialogCallback callback) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 1, 6, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JColorChooser colorChooser = getColorChooser(); JPanel colorPanel = new JPanel(); - colorPanel.addMouseListener(new ColorChooserMouseListener(colorPanel){ + colorPanel.addMouseListener(new ColorChooserMouseListener(colorPanel) { @Override public void mouseClicked(MouseEvent e) { colorChooser.setColor(binder.getValue()); @@ -577,9 +597,9 @@ public void mouseClicked(MouseEvent e) { true, colorChooser, action -> { - callback.onAction(colorChooser.getColor()); - colorPanel.setBackground(colorChooser.getColor()); - }, + callback.onAction(colorChooser.getColor()); + colorPanel.setBackground(colorChooser.getColor()); + }, null); dialog.setVisible(true); } @@ -592,12 +612,13 @@ public void mouseClicked(MouseEvent e) { JPanel wrapper = this.componentsFactory.getJPanel(new BorderLayout()); wrapper.setBackground(AppThemeColor.SLIDE_BG); - wrapper.setBorder(BorderFactory.createEmptyBorder(6,0,6,0)); - wrapper.add(root,BorderLayout.CENTER); + wrapper.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 0)); + wrapper.add(root, BorderLayout.CENTER); return wrapper; } - public JPanel getHexColorPickerPanel(ValueBinder colorBinder, DialogCallback callback){ - JPanel root = this.componentsFactory.getJPanel(new BorderLayout(6,0)); + + public JPanel getHexColorPickerPanel(ValueBinder colorBinder, DialogCallback callback) { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(6, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JColorChooser colorChooser = getColorChooser(); JPanel colorPanel = new JPanel(); @@ -609,8 +630,8 @@ public JPanel getHexColorPickerPanel(ValueBinder colorBinder, DialogCallb callback.onAction(decoded); colorPanel.setBackground(decoded); }); - hexField.setPreferredSize(new Dimension(76,26)); - colorPanel.addMouseListener(new ColorChooserMouseListener(colorPanel){ + hexField.setPreferredSize(new Dimension(76, 26)); + colorPanel.addMouseListener(new ColorChooserMouseListener(colorPanel) { @Override public void mouseClicked(MouseEvent e) { colorChooser.setColor(colorBinder.getValue()); @@ -631,24 +652,24 @@ public void mouseClicked(MouseEvent e) { colorPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK)); colorPanel.setBackground(colorBinder.getValue()); - root.add(hexField,BorderLayout.LINE_START); - root.add(colorPanel,BorderLayout.CENTER); + root.add(hexField, BorderLayout.LINE_START); + root.add(colorPanel, BorderLayout.CENTER); JPanel wrapper = this.componentsFactory.getJPanel(new BorderLayout()); wrapper.setBackground(AppThemeColor.SLIDE_BG); - wrapper.setBorder(BorderFactory.createEmptyBorder(6,0,6,0)); - wrapper.add(root,BorderLayout.CENTER); + wrapper.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 0)); + wrapper.add(root, BorderLayout.CENTER); return wrapper; } - public JTextField getSmartField(T value, FieldValidator validator, FieldValueListener listener){ - JTextField field = this.componentsFactory.getTextField(String.valueOf(value),FontStyle.REGULAR,16f); + public JTextField getSmartField(T value, FieldValidator validator, FieldValueListener listener) { + JTextField field = this.componentsFactory.getTextField(String.valueOf(value), FontStyle.REGULAR, 16f); field.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - if(validator.validate(field.getText())){ + if (validator.validate(field.getText())) { listener.onAction(validator.getValue()); - }else { + } else { field.setText(String.valueOf(value)); } } @@ -663,31 +684,31 @@ public void focusLost(FocusEvent e) { return field; } - public JPanel getBorderColorPanel(AdrDurationComponentDescriptor descriptor, DialogCallback callback){ + public JPanel getBorderColorPanel(AdrDurationComponentDescriptor descriptor, DialogCallback callback) { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.SLIDE_BG); - JCheckBox checkBox = this.componentsFactory.getCheckBox(descriptor.isBindToTextColor(),"Bind to text color?"); + JCheckBox checkBox = this.componentsFactory.getCheckBox(descriptor.isBindToTextColor(), "Bind to text color?"); checkBox.addActionListener(e -> descriptor.setBindToTextColor(checkBox.isSelected())); JPanel colorPickerPanel = this.getHexColorPickerPanel(descriptor::getBorderColor, value -> { checkBox.setSelected(false); callback.onAction(value); }); - root.add(checkBox,BorderLayout.LINE_START); - root.add(colorPickerPanel,BorderLayout.CENTER); + root.add(checkBox, BorderLayout.LINE_START); + root.add(colorPickerPanel, BorderLayout.CENTER); return root; } - public JPanel getGapPanel(AdrTrackerGroupDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4,4,0)); + public JPanel getGapPanel(AdrTrackerGroupDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); JLabel hGap = this.componentsFactory.getTextLabel("hGap:"); JLabel vGap = this.componentsFactory.getTextLabel("vGap:"); - JTextField hGapField = this.getSmartField(descriptor.getHGap(),new IntegerFieldValidator(0,200),value -> { + JTextField hGapField = this.getSmartField(descriptor.getHGap(), new IntegerFieldValidator(0, 200), value -> { descriptor.setHGap(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); - JTextField vGapField = this.getSmartField(descriptor.getVGap(),new IntegerFieldValidator(0,200),value -> { + JTextField vGapField = this.getSmartField(descriptor.getVGap(), new IntegerFieldValidator(0, 200), value -> { descriptor.setVGap(value); MercuryStoreUI.adrReloadSubject.onNext(descriptor); }); @@ -698,15 +719,16 @@ public JPanel getGapPanel(AdrTrackerGroupDescriptor descriptor){ root.add(vGapField); return root; } + public JPopupMenu getContextMenu(AdrTreeNode treeNode) { JPopupMenu contextMenu = this.componentsFactory.getContextPanel(); contextMenu.setBackground(AppThemeColor.ADR_BG); contextMenu.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); contextMenu.setForeground(AppThemeColor.TEXT_DEFAULT); - if(treeNode.getParent().getData() != null){ + if (treeNode.getParent().getData() != null) { JMenuItem moveOut = this.componentsFactory.getMenuItem("Move out"); - moveOut.setBorder(BorderFactory.createMatteBorder(1,0,0,0,AppThemeColor.ADR_DEFAULT_BORDER)); + moveOut.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, AppThemeColor.ADR_DEFAULT_BORDER)); moveOut.addActionListener(action -> { MercuryStoreUI.adrRemoveComponentSubject.onNext(treeNode.getData()); MercuryStoreUI.adrComponentStateSubject.onNext( @@ -729,9 +751,9 @@ public void mouseExited(MouseEvent e) { contextMenu.add(moveOut); } treeNode.getParent().forEach(neighbor -> { - if(neighbor.getData() instanceof AdrTrackerGroupDescriptor) { + if (neighbor.getData() instanceof AdrTrackerGroupDescriptor) { JMenuItem moveTo = this.componentsFactory.getMenuItem("Move to " + neighbor.getData().getTitle()); - moveTo.setBorder(BorderFactory.createMatteBorder(1,0,0,0,AppThemeColor.ADR_DEFAULT_BORDER)); + moveTo.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, AppThemeColor.ADR_DEFAULT_BORDER)); moveTo.addActionListener(action -> { MercuryStoreUI.adrRemoveComponentSubject.onNext(treeNode.getData()); MercuryStoreUI.adrComponentStateSubject.onNext( @@ -751,15 +773,15 @@ public void mouseExited(MouseEvent e) { contextMenu.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); - switch (((AdrTrackerGroupDescriptor)neighbor.getData()).getContentType()){ - case ICONS:{ - if(treeNode.getData() instanceof AdrIconDescriptor){ + switch (((AdrTrackerGroupDescriptor) neighbor.getData()).getContentType()) { + case ICONS: { + if (treeNode.getData() instanceof AdrIconDescriptor) { contextMenu.add(moveTo); } break; } case PROGRESS_BARS: { - if(treeNode.getData() instanceof AdrProgressBarDescriptor){ + if (treeNode.getData() instanceof AdrProgressBarDescriptor) { contextMenu.add(moveTo); } break; @@ -768,7 +790,7 @@ public void mouseExited(MouseEvent e) { } }); JMenuItem export = this.componentsFactory.getMenuItem("Share"); - export.setBorder(BorderFactory.createMatteBorder(1,0,0,0,AppThemeColor.ADR_DEFAULT_BORDER)); + export.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, AppThemeColor.ADR_DEFAULT_BORDER)); export.addActionListener(action -> { MercuryStoreUI.adrExportSubject.onNext(treeNode.getData()); }); @@ -779,15 +801,15 @@ public void mouseExited(MouseEvent e) { public JPanel getRightComponentOperationsPanel(AdrComponentDescriptor descriptor) { JButton removeButton = this.componentsFactory.getIconButton("app/adr/remove_node.png", 14, AppThemeColor.SLIDE_BG, TooltipConstants.ADR_REMOVE_BUTTON); removeButton.addActionListener(action -> { - new AlertDialog(this.getRemoveCallback(descriptor),"Do you want to delete \"" + descriptor.getTitle() + "\"component?",removeButton).setVisible(true); + new AlertDialog(this.getRemoveCallback(descriptor), "Do you want to delete \"" + descriptor.getTitle() + "\"component?", removeButton).setVisible(true); }); JButton visibleButton = this.componentsFactory.getIconButton("app/adr/visible_node_on.png", 14, AppThemeColor.SLIDE_BG, TooltipConstants.ADR_VISIBLE_BUTTON); visibleButton.addActionListener(action -> { - if(descriptor.isVisible()){ - visibleButton.setIcon(this.componentsFactory.getIcon("app/adr/visible_node_off.png",14)); + if (descriptor.isVisible()) { + visibleButton.setIcon(this.componentsFactory.getIcon("app/adr/visible_node_off.png", 14)); descriptor.setVisible(false); - }else { - visibleButton.setIcon(this.componentsFactory.getIcon("app/adr/visible_node_on.png",14)); + } else { + visibleButton.setIcon(this.componentsFactory.getIcon("app/adr/visible_node_on.png", 14)); descriptor.setVisible(true); } MercuryStoreUI.adrReloadSubject.onNext(descriptor); @@ -798,11 +820,12 @@ public JPanel getRightComponentOperationsPanel(AdrComponentDescriptor descriptor buttonsPanel.add(visibleButton); return buttonsPanel; } + public JPanel getLeftComponentOperationsPanel(AdrTreeNode treeNode) { JButton duplicateButton = this.componentsFactory.getIconButton("app/adr/duplicate_node.png", 14, AppThemeColor.SLIDE_BG, TooltipConstants.ADR_DUPLICATE_BUTTON); duplicateButton.addActionListener(action -> { AdrComponentDescriptor cloned = CloneHelper.cloneObject(treeNode.getData()); - if(cloned != null) { + if (cloned != null) { cloned.setComponentId(UUID.randomUUID().toString()); cloned.setLocation(new Point(new Random().nextInt(500), new Random().nextInt(500))); MercuryStoreUI.adrComponentStateSubject.onNext( @@ -814,7 +837,7 @@ public JPanel getLeftComponentOperationsPanel(AdrTreeNode { JPopupMenu contextMenu = this.getContextMenu(treeNode); - contextMenu.show(moveButton,8,8); + contextMenu.show(moveButton, 8, 8); }); JPanel buttonsPanel = this.componentsFactory.getJPanel(new GridLayout(2, 2)); buttonsPanel.setBackground(AppThemeColor.SLIDE_BG); @@ -823,38 +846,39 @@ public JPanel getLeftComponentOperationsPanel(AdrTreeNode { - if(targetPanel.isVisible()){ - expandButton.setIcon(this.componentsFactory.getIcon("app/adr/expand_icon.png",16)); + if (targetPanel.isVisible()) { + expandButton.setIcon(this.componentsFactory.getIcon("app/adr/expand_icon.png", 16)); targetPanel.setVisible(false); - }else { - expandButton.setIcon(this.componentsFactory.getIcon("app/adr/collapse_icon.png",16)); + } else { + expandButton.setIcon(this.componentsFactory.getIcon("app/adr/collapse_icon.png", 16)); targetPanel.setVisible(true); } MercuryStoreUI.adrManagerRepaint.onNext(true); //todo }); return expandButton; } - public String getGroupTypeIconPath(AdrTrackerGroupDescriptor descriptor){ + + public String getGroupTypeIconPath(AdrTrackerGroupDescriptor descriptor) { String iconPath = "app/adr/static_group_icon.png"; switch (descriptor.getGroupType()) { case STATIC: { @@ -868,19 +892,20 @@ public String getGroupTypeIconPath(AdrTrackerGroupDescriptor descriptor){ } return iconPath; } - public DialogCallback getRemoveCallback(AdrComponentDescriptor descriptor){ + + public DialogCallback getRemoveCallback(AdrComponentDescriptor descriptor) { return success -> { - if(success) { + if (success) { MercuryStoreUI.adrRemoveComponentSubject.onNext(descriptor); MercuryStoreUI.adrManagerPack.onNext(true); } }; } - private JColorChooser getColorChooser(){ + private JColorChooser getColorChooser() { JColorChooser colorChooser = new JColorChooser(); String type = UIManager.getString("ColorChooser.hsvNameText", colorChooser.getLocale()); - for (AbstractColorChooserPanel p: colorChooser.getChooserPanels()) { + for (AbstractColorChooserPanel p : colorChooser.getChooserPanels()) { if (!p.getDisplayName().equals(type)) { colorChooser.removeChooserPanel(p); } 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 d66db814..cf9ef7ae 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 @@ -6,8 +6,8 @@ import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.adr.components.panel.page.AdrPagePanel; -import com.mercury.platform.ui.adr.components.panel.tree.main.AdrMainTreeNodeRenderer; import com.mercury.platform.ui.adr.components.panel.tree.AdrTreePanel; +import com.mercury.platform.ui.adr.components.panel.tree.main.AdrMainTreeNodeRenderer; import com.mercury.platform.ui.adr.dialog.AdrExportDialog; import com.mercury.platform.ui.adr.dialog.AdrIconSelectDialog; import com.mercury.platform.ui.adr.dialog.AdrNewProfileDialog; @@ -31,7 +31,7 @@ import java.util.List; import java.util.stream.Collectors; -public class AdrManagerFrame extends AbstractTitledComponentFrame{ +public class AdrManagerFrame extends AbstractTitledComponentFrame { private JPanel currentPage; private JPanel root; private AdrTreePanel tree; @@ -40,6 +40,7 @@ public class AdrManagerFrame extends AbstractTitledComponentFrame{ private AdrIconSelectDialog iconSelectDialog; @Getter private AdrProfileDescriptor selectedProfile; + public AdrManagerFrame(AdrProfileDescriptor selectedProfile) { super(); this.processingHideEvent = false; @@ -48,50 +49,53 @@ public AdrManagerFrame(AdrProfileDescriptor selectedProfile) { this.setFocusableWindowState(true); this.setAlwaysOnTop(false); this.selectedProfile = selectedProfile; - this.exportDialog = new AdrExportDialog(this,new ArrayList<>()); + this.exportDialog = new AdrExportDialog(this, new ArrayList<>()); this.iconSelectDialog = new AdrIconSelectDialog(); this.iconSelectDialog.setLocationRelativeTo(null); FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); this.setPreferredSize(frameDescriptor.getFrameSize()); UIManager.put("MenuItem.background", AppThemeColor.ADR_BG); UIManager.put("MenuItem.selectionBackground", AppThemeColor.ADR_POPUP_BG); - UIManager.put("Menu.contentMargins", new InsetsUIResource(2,0,2,0)); + UIManager.put("Menu.contentMargins", new InsetsUIResource(2, 0, 2, 0)); UIManager.put("MenuItem.opaque", true); UIManager.put("ComboBox.selectionBackground", AppThemeColor.HEADER); UIManager.put("ComboBox.selectionForeground", AppThemeColor.ADR_POPUP_BG); - UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG); + UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG); } + @Override public void onViewInit() { this.initRootPanel(); this.hideButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { MercuryStoreCore.showingDelaySubject.onNext(true); FramesManager.INSTANCE.performAdr(); } } }); - this.add(this.root,BorderLayout.CENTER); - this.add(this.getBottomPanel(),BorderLayout.PAGE_END); + this.add(this.root, BorderLayout.CENTER); + this.add(this.getBottomPanel(), BorderLayout.PAGE_END); } - public void setPage(AdrPagePanel page){ - if(currentPage != null){ + + public void setPage(AdrPagePanel page) { + if (currentPage != null) { this.root.remove(currentPage); } - this.root.add(page,BorderLayout.CENTER); + this.root.add(page, BorderLayout.CENTER); this.currentPage = page; this.pack(); this.repaint(); } - private void initRootPanel(){ + + private void initRootPanel() { this.root = componentsFactory.getTransparentPanel(new BorderLayout()); this.root.setBackground(AppThemeColor.FRAME); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBackground(AppThemeColor.FRAME); - leftPanel.setBorder(BorderFactory.createMatteBorder(0,0,0,1,AppThemeColor.BORDER)); + leftPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, AppThemeColor.BORDER)); this.tree = new AdrTreePanel( this.selectedProfile.getContents(), new AdrMainTreeNodeRenderer()); @@ -99,17 +103,17 @@ private void initRootPanel(){ JButton addComponent = this.componentsFactory.getButton("New"); addComponent.setBackground(AppThemeColor.FRAME); - addComponent.setFont(this.componentsFactory.getFont(FontStyle.BOLD,20f)); + addComponent.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 20f)); addComponent.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(2,2,2,2), - BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.BORDER))); + BorderFactory.createEmptyBorder(2, 2, 2, 2), + BorderFactory.createMatteBorder(1, 1, 1, 1, AppThemeColor.BORDER))); addComponent.addActionListener(action -> { MercuryStoreUI.adrSelectSubject.onNext(null); - MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.MAIN,null)); + MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.MAIN, null)); }); - leftPanel.add(addComponent,BorderLayout.PAGE_START); - leftPanel.add(this.tree,BorderLayout.CENTER); - this.root.add(leftPanel,BorderLayout.LINE_START); + leftPanel.add(addComponent, BorderLayout.PAGE_START); + leftPanel.add(this.tree, BorderLayout.CENTER); + this.root.add(leftPanel, BorderLayout.LINE_START); } @Override @@ -131,11 +135,12 @@ public void subscribe() { }); } - public void setSelectedProfile(AdrProfileDescriptor profile){ + public void setSelectedProfile(AdrProfileDescriptor profile) { this.selectedProfile = profile; this.tree.updateTree(profile.getContents()); } - public void onProfileLoaded(){ + + public void onProfileLoaded() { this.profileSelector.setEnabled(true); } @@ -145,30 +150,35 @@ protected String getFrameTitle() { } public void addNewNode(AdrComponentDescriptor descriptor, AdrComponentDescriptor parent) { - this.tree.addNode(descriptor,parent); + this.tree.addNode(descriptor, parent); this.pack(); this.repaint(); } + public void removeNode(AdrComponentDescriptor descriptor) { this.tree.removeNode(descriptor); this.pack(); this.repaint(); } - public void duplicateNode(AdrComponentDescriptor descriptor){ + + public void duplicateNode(AdrComponentDescriptor descriptor) { this.tree.duplicateNode(descriptor); this.pack(); this.repaint(); } + public void removeProfileFromSelect(AdrProfileDescriptor profile) { this.profileSelector.removeItem(profile.getProfileName()); } + public void addProfileToSelect(String profileName) { this.profileSelector.removeItem("Create new"); this.profileSelector.addItem(profileName); this.profileSelector.addItem("Create new"); this.profileSelector.setSelectedItem(profileName); } - public void onProfileRename(List entities){ + + public void onProfileRename(List entities) { this.profileSelector.removeAllItems(); List profilesNames = entities .stream() @@ -179,9 +189,10 @@ public void onProfileRename(List entities){ this.profileSelector.setSelectedItem(this.selectedProfile.getProfileName()); this.repaint(); } - private JPanel getBottomPanel(){ + + private JPanel getBottomPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.setBorder(BorderFactory.createMatteBorder(1,0,0,0,AppThemeColor.MSG_HEADER_BORDER)); + root.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, AppThemeColor.MSG_HEADER_BORDER)); root.setBackground(AppThemeColor.ADR_FOOTER_BG); JPanel profilePanel = this.componentsFactory.getJPanel(new GridLayout(1, 3)); profilePanel.setBackground(AppThemeColor.ADR_FOOTER_BG); @@ -193,21 +204,21 @@ private JPanel getBottomPanel(){ .collect(Collectors.toList()); profilesNames.add("Create new"); this.profileSelector = this.componentsFactory.getComboBox(profilesNames.toArray(new String[0])); - this.profileSelector.setPreferredSize(new Dimension(120,20)); + this.profileSelector.setPreferredSize(new Dimension(120, 20)); this.profileSelector.setBorder(BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER)); this.profileSelector.setSelectedItem(this.selectedProfile.getProfileName()); this.profileSelector.addItemListener(e -> { - if(e.getStateChange() == ItemEvent.SELECTED) { - if(!profileSelector.getSelectedItem().equals("Create new")) { - if(!profileSelector.getSelectedItem().equals(this.selectedProfile.getProfileName())) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (!profileSelector.getSelectedItem().equals("Create new")) { + if (!profileSelector.getSelectedItem().equals(this.selectedProfile.getProfileName())) { profileSelector.setEnabled(false); MercuryStoreUI.adrSelectProfileSubject.onNext((String) profileSelector.getSelectedItem()); } - }else { + } else { profileSelector.setSelectedItem(this.selectedProfile.getProfileName()); new AdrNewProfileDialog( MercuryStoreUI.adrNewProfileSubject::onNext, - profileSelector,profilesNames).setVisible(true); + profileSelector, profilesNames).setVisible(true); } } }); @@ -221,7 +232,7 @@ private JPanel getBottomPanel(){ profilePanel.add(exportButton); JPanel bottomPanel = this.componentsFactory.getJPanel(new BorderLayout()); bottomPanel.setBackground(AppThemeColor.ADR_FOOTER_BG); - profilePanel.add(this.componentsFactory.getTextLabel("Selected profile: "),BorderLayout.LINE_START); + profilePanel.add(this.componentsFactory.getTextLabel("Selected profile: "), BorderLayout.LINE_START); profilePanel.add(profileSelector); // JButton reloadButton = this.componentsFactory.getIconButton("app/adr/export_node.png", 15, AppThemeColor.FRAME, TooltipConstants.ADR_EXPORT_BUTTON); // reloadButton.addActionListener(action -> { @@ -230,15 +241,15 @@ private JPanel getBottomPanel(){ // profilePanel.add(reloadButton); JButton profileSettingsButton = this.componentsFactory.getIconButton("app/adr/profile_settings_icon.png", 18, AppThemeColor.FRAME, TooltipConstants.ADR_EXPORT_BUTTON); profileSettingsButton.addActionListener(action -> { - MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.PROFILES_SETTINGS,null)); + MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.PROFILES_SETTINGS, null)); }); profileSettingsButton.setBackground(AppThemeColor.ADR_FOOTER_BG); - bottomPanel.add(exportButton,BorderLayout.LINE_START); - bottomPanel.add(profilePanel,BorderLayout.CENTER); - bottomPanel.add(profileSettingsButton,BorderLayout.LINE_END); + bottomPanel.add(exportButton, BorderLayout.LINE_START); + bottomPanel.add(profilePanel, BorderLayout.CENTER); + bottomPanel.add(profileSettingsButton, BorderLayout.LINE_END); - root.add(bottomPanel,BorderLayout.LINE_START); - root.add(profileSettingsButton,BorderLayout.LINE_END); + root.add(bottomPanel, BorderLayout.LINE_START); + root.add(profileSettingsButton, BorderLayout.LINE_END); return root; } } 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 fc64a639..aab74ca3 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 @@ -7,13 +7,13 @@ import rx.Subscription; import javax.swing.*; -import java.awt.*; public class AdrSingleComponentFrame extends AbstractAdrComponentFrame { @Getter private AdrComponentPanel component; private Subscription adrReloadSubscription; + public AdrSingleComponentFrame(AdrComponentDescriptor descriptor) { super(descriptor); } @@ -34,7 +34,7 @@ protected void initialize() { public void subscribe() { super.subscribe(); this.adrReloadSubscription = MercuryStoreUI.adrReloadSubject.subscribe(descriptor -> { - if(descriptor.equals(this.descriptor)){ + if (descriptor.equals(this.descriptor)) { this.setOpacity(this.descriptor.getOpacity()); this.setLocation(descriptor.getLocation()); this.setPreferredSize(this.descriptor.getSize()); @@ -60,7 +60,7 @@ public void disableSettings() { this.component.removeMouseListener(this.mouseListener); this.component.removeMouseMotionListener(this.motionListener); this.component.removeMouseListener(this.mouseOverListener); - this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); this.pack(); this.repaint(); } 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 9a9c898a..e577bf6f 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 @@ -1,6 +1,6 @@ package com.mercury.platform.ui.adr.components; -import com.mercury.platform.shared.config.descriptor.adr.*; +import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; import com.mercury.platform.ui.adr.components.panel.AdrComponentPanel; import com.mercury.platform.ui.adr.components.panel.AdrTrackerGroupPanel; import com.mercury.platform.ui.misc.MercuryStoreUI; @@ -8,19 +8,19 @@ import rx.Subscription; import javax.swing.*; -import java.awt.*; public class AdrTrackerGroupFrame extends AbstractAdrComponentFrame { private AdrTrackerGroupPanel trackerGroupPanel; private Subscription adrReloadSubscription; + public AdrTrackerGroupFrame(@NonNull AdrTrackerGroupDescriptor descriptor) { super(descriptor); } @Override public void setPanel(AdrComponentPanel panel) { - this.trackerGroupPanel = new AdrTrackerGroupPanel(this.descriptor,this.componentsFactory); + this.trackerGroupPanel = new AdrTrackerGroupPanel(this.descriptor, this.componentsFactory); } @Override @@ -34,7 +34,7 @@ protected void initialize() { public void subscribe() { super.subscribe(); this.adrReloadSubscription = MercuryStoreUI.adrReloadSubject.subscribe(descriptor -> { - if(descriptor.equals(this.descriptor)){ + if (descriptor.equals(this.descriptor)) { this.setLocation(descriptor.getLocation()); this.setOpacity(this.descriptor.getOpacity()); this.repaint(); @@ -61,7 +61,7 @@ public void disableSettings() { this.trackerGroupPanel.removeMouseListener(this.mouseListener); this.trackerGroupPanel.removeMouseListener(this.mouseOverListener); this.trackerGroupPanel.removeMouseMotionListener(this.motionListener); - this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + this.getRootPane().setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); this.pack(); this.repaint(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/FrameProviderFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/FrameProviderFactory.java index 0dcf8051..6ccc1211 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/FrameProviderFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/FrameProviderFactory.java @@ -17,7 +17,7 @@ public FrameProviderFactory() { this.providers.add(new CaptureInFrameProvider()); } - public FrameProvider getProviderFor(AdrComponentDescriptor descriptor){ + public FrameProvider getProviderFor(AdrComponentDescriptor descriptor) { return this.providers .stream() .filter(it -> it.isSuitable(descriptor)) diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/CaptureInFrameProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/CaptureInFrameProvider.java index 947af6e0..902429de 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/CaptureInFrameProvider.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/CaptureInFrameProvider.java @@ -1,8 +1,8 @@ package com.mercury.platform.ui.adr.components.factory.frame; +import com.mercury.platform.shared.config.descriptor.adr.AdrCaptureDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentType; -import com.mercury.platform.shared.config.descriptor.adr.AdrCaptureDescriptor; import com.mercury.platform.ui.adr.components.panel.AdrCapturePanel; import com.mercury.platform.ui.adr.components.panel.AdrComponentPanel; import com.mercury.platform.ui.components.ComponentsFactory; @@ -17,6 +17,6 @@ public boolean isSuitable(AdrComponentDescriptor descriptor) { @Override public AdrComponentPanel getPanel() { - return new AdrCapturePanel((AdrCaptureDescriptor) this.descriptor,new ComponentsFactory()); + return new AdrCapturePanel((AdrCaptureDescriptor) this.descriptor, new ComponentsFactory()); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/FrameProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/FrameProvider.java index 151ca55a..ed48780c 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/FrameProvider.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/FrameProvider.java @@ -7,6 +7,8 @@ public interface FrameProvider { boolean isSuitable(AdrComponentDescriptor descriptor); + AbstractAdrFrame getFrame(boolean showSettings); + AdrComponentPanel getPanel(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/SingleFrameProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/SingleFrameProvider.java index b49bcd9a..77184bca 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/SingleFrameProvider.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/SingleFrameProvider.java @@ -8,17 +8,18 @@ import com.mercury.platform.ui.adr.components.panel.AdrDurationCellPanel; import com.mercury.platform.ui.components.ComponentsFactory; -public abstract class SingleFrameProvider implements FrameProvider{ +public abstract class SingleFrameProvider implements FrameProvider { protected AdrComponentDescriptor descriptor; + @Override public AbstractAdrFrame getFrame(boolean showSettings) { AdrSingleComponentFrame frame = new AdrSingleComponentFrame(descriptor); frame.setPanel(this.getPanel()); frame.init(); - if(showSettings) { + if (showSettings) { frame.showComponent(); frame.enableSettings(); - }else { + } else { frame.disableSettings(); } return frame; @@ -26,6 +27,6 @@ public AbstractAdrFrame getFrame(boolean showSettings) { @Override public AdrComponentPanel getPanel() { - return new AdrDurationCellPanel((AdrDurationComponentDescriptor) this.descriptor,new ComponentsFactory()); + return new AdrDurationCellPanel((AdrDurationComponentDescriptor) this.descriptor, new ComponentsFactory()); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/TrackerGroupFrameProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/TrackerGroupFrameProvider.java index 877e60c3..61ea794a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/TrackerGroupFrameProvider.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/factory/frame/TrackerGroupFrameProvider.java @@ -12,6 +12,7 @@ public class TrackerGroupFrameProvider implements FrameProvider { private AdrComponentDescriptor descriptor; + @Override public boolean isSuitable(AdrComponentDescriptor descriptor) { this.descriptor = descriptor; @@ -24,10 +25,10 @@ public AbstractAdrFrame getFrame(boolean showSettings) { new AdrTrackerGroupFrame((AdrTrackerGroupDescriptor) descriptor); adrTrackerGroupFrame.setPanel(this.getPanel()); adrTrackerGroupFrame.init(); - if(showSettings) { + if (showSettings) { adrTrackerGroupFrame.showComponent(); adrTrackerGroupFrame.enableSettings(); - }else { + } else { adrTrackerGroupFrame.disableSettings(); } return adrTrackerGroupFrame; @@ -35,6 +36,6 @@ public AbstractAdrFrame getFrame(boolean showSettings) { @Override public AdrComponentPanel getPanel() { - return new AdrTrackerGroupPanel((AdrTrackerGroupDescriptor) this.descriptor,new ComponentsFactory()); + return new AdrTrackerGroupPanel((AdrTrackerGroupDescriptor) this.descriptor, new ComponentsFactory()); } } 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 1585f3d0..3c17933c 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 @@ -16,12 +16,13 @@ public AdrCaptureOutPanel(AdrCaptureDescriptor descriptor, ComponentsFactory com @Override public void onViewInit() { - this.setLayout(new GridLayout(1,1)); + this.setLayout(new GridLayout(1, 1)); this.setPreferredSize(this.descriptor.getCaptureSize()); this.setBackground(AppThemeColor.ADR_CAPTURE_BG); - this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_GREEN,4)); + this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_GREEN, 4)); MercuryStoreUI.adrRepaintSubject.onNext(true); } + @Override public void enableSettings() { super.enableSettings(); 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 84397092..30d0eb6f 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 @@ -13,27 +13,28 @@ import java.awt.image.BufferedImage; -public class AdrCapturePanel extends AdrComponentPanel{ +public class AdrCapturePanel extends AdrComponentPanel { private Timeline progressTl; private JLabel captureLabel; + public AdrCapturePanel(AdrCaptureDescriptor groupDescriptor, ComponentsFactory componentsFactory) { super(groupDescriptor, componentsFactory); } @Override public void onViewInit() { - this.setLayout(new GridLayout(1,1)); + this.setLayout(new GridLayout(1, 1)); this.setPreferredSize(this.descriptor.getSize()); this.captureLabel = new JLabel(); this.setBackground(AppThemeColor.ADR_CAPTURE_BG); - this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER,1)); + this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); this.progressTl = new Timeline(this); - this.progressTl.addPropertyToInterpolate("captureCount",0,this.descriptor.getFps()); - this.captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(),descriptor.getSize().width,descriptor.getSize().height))); - this.progressTl.addCallback(new TimelineCallbackAdapter(){ + this.progressTl.addPropertyToInterpolate("captureCount", 0, this.descriptor.getFps()); + this.captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(), descriptor.getSize().width, descriptor.getSize().height))); + this.progressTl.addCallback(new TimelineCallbackAdapter() { @Override public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { - captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(),descriptor.getSize().width,descriptor.getSize().height))); + captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(), descriptor.getSize().width, descriptor.getSize().height))); } }); this.progressTl.setDuration(1000 / this.descriptor.getFps()); @@ -56,6 +57,7 @@ public void disableSettings() { this.progressTl.playLoop(Timeline.RepeatBehavior.LOOP); this.setVisible(this.descriptor.isVisible()); } + @Override public void onSelect() { this.progressTl.playLoop(Timeline.RepeatBehavior.LOOP); @@ -76,12 +78,13 @@ protected void onUpdate() { public void setCaptureCount(int captureCount) { } - private BufferedImage getCapture(){ + + private BufferedImage getCapture() { try { Robot robot = new Robot(); Dimension size = this.descriptor.getCaptureSize(); Point location = this.descriptor.getCaptureLocation(); - return robot.createScreenCapture(new Rectangle(location.x +5, location.y+5, size.width-10, size.height-10)); + return robot.createScreenCapture(new Rectangle(location.x + 5, location.y + 5, size.width - 10, size.height - 10)); } catch (AWTException e) { e.printStackTrace(); } 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 c940342a..85641dcd 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 @@ -12,7 +12,7 @@ import javax.swing.*; -public abstract class AdrComponentPanel extends JPanel implements ViewInit,AsSubscriber,DestroySubscription { +public abstract class AdrComponentPanel extends JPanel implements ViewInit, AsSubscriber, DestroySubscription { @Getter protected T descriptor; protected ComponentsFactory componentsFactory; @@ -20,6 +20,7 @@ public abstract class AdrComponentPanel extend private Subscription adrReloadSubscription; private Subscription adrSelectSubscription; + public AdrComponentPanel(T descriptor, ComponentsFactory componentsFactory) { this.descriptor = descriptor; this.componentsFactory = componentsFactory; @@ -30,15 +31,15 @@ public AdrComponentPanel(T descriptor, ComponentsFactory componentsFactory) { @Override public void subscribe() { this.adrReloadSubscription = MercuryStoreUI.adrReloadSubject.subscribe(it -> { - if(this.descriptor.equals(it)){ + if (this.descriptor.equals(it)) { this.onUpdate(); this.onSelect(); } }); this.adrSelectSubscription = MercuryStoreUI.adrSelectSubject.subscribe(it -> { - if(this.descriptor.equals(it)){ + if (this.descriptor.equals(it)) { this.onSelect(); - }else { + } else { this.onUnSelect(); } }); @@ -47,11 +48,15 @@ public void subscribe() { public void enableSettings() { this.inSettings = true; } + public void disableSettings() { this.inSettings = false; } + public abstract void onSelect(); + public abstract void onUnSelect(); + protected abstract void onUpdate(); @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 73949db7..0f0a8f5c 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 @@ -13,10 +13,11 @@ import java.awt.*; import java.util.Random; -public class AdrDurationCellPanel extends AdrDurationComponentPanel{ +public class AdrDurationCellPanel extends AdrDurationComponentPanel { private MercuryTracker tracker; + public AdrDurationCellPanel(AdrDurationComponentDescriptor cellDescriptor, ComponentsFactory componentsFactory) { - super(cellDescriptor,componentsFactory); + super(cellDescriptor, componentsFactory); this.setBackground(AppThemeColor.TRANSPARENT); this.setBorder(null); this.setVisible(false); @@ -55,13 +56,13 @@ public void onUnSelect() { protected void onHotKeyPressed() { this.tracker.setStringPainted(descriptor.isTextEnable()); this.tracker.setMaskPainted(descriptor.isMaskEnable()); - if(this.descriptor.isHotKeyRefresh()) { + if (this.descriptor.isHotKeyRefresh()) { this.tracker.abort(); } this.tracker.play(); - if(this.getParent() instanceof AdrTrackerGroupPanel){ + if (this.getParent() instanceof AdrTrackerGroupPanel) { AdrTrackerGroupPanel parent = (AdrTrackerGroupPanel) this.getParent(); - if(parent.getDescriptor().getGroupType().equals(AdrTrackerGroupType.DYNAMIC)) { + if (parent.getDescriptor().getGroupType().equals(AdrTrackerGroupType.DYNAMIC)) { parent.setComponentZOrder(this, parent.getComponentCount() - 1); } } @@ -75,7 +76,7 @@ protected void onUpdate() { @Override public void onViewInit() { - this.setLayout(new GridLayout(1,1)); + this.setLayout(new GridLayout(1, 1)); this.setPreferredSize(this.descriptor.getSize()); this.tracker = new MercuryTracker(this.descriptor); this.add(this.tracker); @@ -83,14 +84,14 @@ public void onViewInit() { @Override public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { if (newState.equals(Timeline.TimelineState.IDLE) && !inSettings) { - if(!descriptor.isAlwaysVisible()) { + if (!descriptor.isAlwaysVisible()) { setVisible(false); - }else { + } else { tracker.setStringPainted(!descriptor.isAlwaysVisible()); tracker.setMaskPainted(!descriptor.isAlwaysVisible()); } MercuryStoreUI.adrRepaintSubject.onNext(true); - }else if(newState.equals(Timeline.TimelineState.PLAYING_FORWARD)){ + } else if (newState.equals(Timeline.TimelineState.PLAYING_FORWARD)) { setVisible(true); JFrame parent = (JFrame) SwingUtilities.getWindowAncestor(AdrDurationCellPanel.this); parent.pack(); 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 e943e27e..d5a96757 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 @@ -8,8 +8,9 @@ import javax.swing.*; -public abstract class AdrDurationComponentPanel extends AdrComponentPanel{ +public abstract class AdrDurationComponentPanel extends AdrComponentPanel { private Subscription adrHotKeySubscription; + public AdrDurationComponentPanel(T descriptor, ComponentsFactory componentsFactory) { super(descriptor, componentsFactory); } @@ -18,8 +19,8 @@ public AdrDurationComponentPanel(T descriptor, ComponentsFactory componentsFacto public void subscribe() { super.subscribe(); this.adrHotKeySubscription = MercuryStoreCore.hotKeySubject.subscribe(hotKey -> { - SwingUtilities.invokeLater(()-> { - if(this.descriptor.getHotKeyDescriptor() != null) { + SwingUtilities.invokeLater(() -> { + if (this.descriptor.getHotKeyDescriptor() != null) { if (this.descriptor.getHotKeyDescriptor().equals(hotKey) && !this.inSettings) { this.onHotKeyPressed(); } @@ -27,6 +28,7 @@ public void subscribe() { }); }); } + protected abstract void onHotKeyPressed(); @Override 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 bfaab406..0cfdedc7 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 @@ -11,13 +11,14 @@ import javax.swing.*; import java.awt.*; -import java.util.*; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class AdrTrackerGroupPanel extends AdrComponentPanel { private List cells; private Subscription adrPostOpSubscription; + public AdrTrackerGroupPanel(AdrTrackerGroupDescriptor descriptor, ComponentsFactory componentsFactory) { super(descriptor, componentsFactory); this.setBackground(AppThemeColor.TRANSPARENT); @@ -28,10 +29,10 @@ public AdrTrackerGroupPanel(AdrTrackerGroupDescriptor descriptor, ComponentsFact public void subscribe() { super.subscribe(); this.adrPostOpSubscription = MercuryStoreUI.adrPostOperationsComponentSubject.subscribe(target -> { - if(this.cells.stream() + if (this.cells.stream() .map(AdrComponentPanel::getDescriptor) .collect(Collectors.toList()) - .size() != this.descriptor.getCells().size()){ + .size() != this.descriptor.getCells().size()) { this.removeAll(); this.onViewInit(); MercuryStoreCore.saveConfigSubject.onNext(true); @@ -40,21 +41,21 @@ public void subscribe() { }); } - private void init(){ - switch (this.descriptor.getOrientation()){ - case VERTICAL:{ - if(this.descriptor.getGroupType().equals(AdrTrackerGroupType.STATIC)) { - this.setLayout(new GridLayout(0, 1,this.descriptor.getHGap(),this.descriptor.getVGap())); - }else { - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + private void init() { + switch (this.descriptor.getOrientation()) { + case VERTICAL: { + if (this.descriptor.getGroupType().equals(AdrTrackerGroupType.STATIC)) { + this.setLayout(new GridLayout(0, 1, this.descriptor.getHGap(), this.descriptor.getVGap())); + } else { + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); } break; } - case HORIZONTAL:{ - if(this.descriptor.getGroupType().equals(AdrTrackerGroupType.STATIC)) { - this.setLayout(new GridLayout(1,0,this.descriptor.getHGap(),this.descriptor.getVGap())); - }else { - this.setLayout(new BoxLayout(this,BoxLayout.X_AXIS)); + case HORIZONTAL: { + if (this.descriptor.getGroupType().equals(AdrTrackerGroupType.STATIC)) { + this.setLayout(new GridLayout(1, 0, this.descriptor.getHGap(), this.descriptor.getVGap())); + } else { + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); } break; } @@ -75,7 +76,7 @@ public void onViewInit() { AdrDurationCellPanel adrDurationCellPanel = new AdrDurationCellPanel((AdrDurationComponentDescriptor) component, this.componentsFactory); this.add(adrDurationCellPanel); this.cells.add(adrDurationCellPanel); - if(inSettings){ + if (inSettings) { adrDurationCellPanel.enableSettings(); } }); 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 01687e9d..4c3adee5 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 @@ -17,7 +17,7 @@ public class AdrCapturePagePanel extends AdrPagePanel { protected void init() { JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); JLabel titleLabel = this.componentsFactory.getTextLabel("Title:"); @@ -36,15 +36,15 @@ protected void init() { JPanel sectorLocationPanel = this.adrComponentsFactory.getCaptureLocationPanel(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)); + JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); + JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); generalPanel.setBackground(AppThemeColor.SLIDE_BG); generalPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4,2,4,2))); + BorderFactory.createEmptyBorder(4, 2, 4, 2))); specPanel.setBackground(AppThemeColor.SLIDE_BG); - specPanel.setBorder(BorderFactory.createEmptyBorder(0,0,4,2)); + specPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 2)); generalPanel.add(titleLabel); generalPanel.add(titleField); @@ -76,7 +76,7 @@ public void componentHidden(ComponentEvent e) { } }); - JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG,this.advancedExpanded); + JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG, this.advancedExpanded); advancedPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); container.add(this.componentsFactory.wrapToSlide(generalPanel)); @@ -87,6 +87,6 @@ public void mousePressed(MouseEvent e) { requestFocus(); } }); - this.add(verticalContainer,BorderLayout.CENTER); + this.add(verticalContainer, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrGroupPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrGroupPagePanel.java index 95533b78..7974b995 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrGroupPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrGroupPagePanel.java @@ -19,7 +19,7 @@ public class AdrGroupPagePanel extends AdrPagePanel { protected void init() { JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); JLabel titleLabel = this.componentsFactory.getTextLabel("Title:"); @@ -29,14 +29,14 @@ protected void init() { JLabel paddingLabel = this.componentsFactory.getTextLabel("Component's padding:"); JLabel groupTypeLabel = this.componentsFactory.getTextLabel("Group's type:"); String sizeText = "Icon's size:"; - if(this.payload.getContentType().equals(AdrTrackerGroupContentType.PROGRESS_BARS)){ + if (this.payload.getContentType().equals(AdrTrackerGroupContentType.PROGRESS_BARS)) { sizeText = "Progress bar's size:"; } JLabel sizeLabel = this.componentsFactory.getTextLabel(sizeText); JLabel groupOrientationLabel = this.componentsFactory.getTextLabel("Group's orientation:"); JLabel pbOrientationLabel = this.componentsFactory.getTextLabel("Progress bar's orientation:"); - JTextField titleField = this.componentsFactory.getTextField(this.payload.getTitle(), FontStyle.BOLD,16); + JTextField titleField = this.componentsFactory.getTextField(this.payload.getTitle(), FontStyle.BOLD, 16); titleField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { @@ -46,7 +46,7 @@ public void focusLost(FocusEvent e) { }); JPanel locationPanel = this.adrComponentsFactory.getLocationPanel(this.payload, this.fromGroup); JPanel paddingPanel = this.adrComponentsFactory.getGapPanel(this.payload); - JSlider opacitySlider = this.componentsFactory.getSlider(20,100, (int) (this.payload.getOpacity() * 100)); + JSlider opacitySlider = this.componentsFactory.getSlider(20, 100, (int) (this.payload.getOpacity() * 100)); opacitySlider.setBackground(AppThemeColor.SLIDE_BG); opacitySlider.addMouseListener(new MouseAdapter() { @Override @@ -57,7 +57,7 @@ public void mouseReleased(MouseEvent e) { } }); - JComboBox groupType = this.componentsFactory.getComboBox(new String[]{"Dynamic","Static"}); + JComboBox groupType = this.componentsFactory.getComboBox(new String[]{"Dynamic", "Static"}); groupType.setSelectedIndex(this.payload.getGroupType().ordinal()); groupType.addItemListener(e -> { this.payload.setGroupType(AdrTrackerGroupType.valueOfPretty((String) groupType.getSelectedItem())); @@ -66,7 +66,7 @@ public void mouseReleased(MouseEvent e) { JComboBox pbOrientation = this.componentsFactory.getComboBox(new String[]{"Horizontal", "Vertical"}); pbOrientation.setSelectedIndex(this.payload.getOrientation().ordinal()); pbOrientation.addItemListener(e -> { - if(e.getStateChange() == ItemEvent.SELECTED) { + if (e.getStateChange() == ItemEvent.SELECTED) { AdrComponentOrientation selected = AdrComponentOrientation.valueOfPretty((String) pbOrientation.getSelectedItem()); Dimension dimension = new Dimension(this.payload.getSize().height, this.payload.getSize().width); this.payload.setSize(dimension); @@ -78,22 +78,22 @@ public void mouseReleased(MouseEvent e) { MercuryStoreUI.adrReloadSubject.onNext(this.payload); } }); - JPanel iconSizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload,this.fromGroup); + JPanel iconSizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload, this.fromGroup); JComboBox groupOrientation = this.componentsFactory.getComboBox(new String[]{"Horizontal", "Vertical"}); groupOrientation.setSelectedIndex(this.payload.getOrientation().ordinal()); groupOrientation.addItemListener(e -> { this.payload.setOrientation(AdrComponentOrientation.valueOfPretty((String) groupOrientation.getSelectedItem())); MercuryStoreUI.adrReloadSubject.onNext(this.payload); }); - JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); - JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); + JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); + JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); generalPanel.setBackground(AppThemeColor.ADR_BG); generalPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER), - BorderFactory.createEmptyBorder(4,2,4,2))); + BorderFactory.createEmptyBorder(4, 2, 4, 2))); specPanel.setBackground(AppThemeColor.SLIDE_BG); - specPanel.setBorder(BorderFactory.createEmptyBorder(0,0,4,2)); + specPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 2)); generalPanel.add(titleLabel); generalPanel.add(titleField); generalPanel.add(locationLabel); @@ -127,7 +127,7 @@ public void componentHidden(ComponentEvent e) { } }); - JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG,this.advancedExpanded); + JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG, this.advancedExpanded); advancedPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); container.add(this.componentsFactory.wrapToSlide(generalPanel)); container.add(this.componentsFactory.wrapToSlide(advancedPanel)); @@ -137,6 +137,6 @@ public void mousePressed(MouseEvent e) { requestFocus(); } }); - this.add(verticalContainer,BorderLayout.CENTER); + this.add(verticalContainer, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java index eb691a0a..d8aa26ec 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java @@ -1,17 +1,15 @@ package com.mercury.platform.ui.adr.components.panel.page; import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; -import com.mercury.platform.ui.adr.validator.DoubleFieldValidator; -import com.mercury.platform.ui.adr.validator.DoubleFormatFieldValidator; -import com.mercury.platform.ui.adr.validator.IntegerFieldValidator; -import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class AdrIconPagePanel extends AdrPagePanel { @@ -19,7 +17,7 @@ public class AdrIconPagePanel extends AdrPagePanel { protected void init() { JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); JLabel titleLabel = this.componentsFactory.getTextLabel("Title:"); @@ -45,7 +43,7 @@ protected void init() { JTextField titleField = this.adrComponentsFactory.getTitleField(this.payload); JSlider opacitySlider = this.adrComponentsFactory.getOpacitySlider(this.payload); - JPanel iconSizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload,this.fromGroup); + JPanel iconSizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload, this.fromGroup); JPanel hotKeyPanel = this.adrComponentsFactory.getHotKeyPanel(this.payload); JPanel locationPanel = this.adrComponentsFactory.getLocationPanel(this.payload, this.fromGroup); JPanel iconSelectPanel = this.adrComponentsFactory.getIconPanel(this.payload); @@ -64,19 +62,19 @@ protected void init() { JPanel borderColorPanel = this.adrComponentsFactory.getBorderColorPanel(this.payload); - JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); - JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); + JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); + JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); generalPanel.setBackground(AppThemeColor.SLIDE_BG); generalPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4,2,4,2))); + BorderFactory.createEmptyBorder(4, 2, 4, 2))); specPanel.setBackground(AppThemeColor.SLIDE_BG); - specPanel.setBorder(BorderFactory.createEmptyBorder(0,0,4,2)); + specPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 2)); generalPanel.add(titleLabel); generalPanel.add(titleField); - if(!this.fromGroup) { + if (!this.fromGroup) { generalPanel.add(locationLabel); generalPanel.add(locationPanel); generalPanel.add(sizeLabel); @@ -89,7 +87,7 @@ protected void init() { generalPanel.add(durationLabel); generalPanel.add(durationField); - if(!this.fromGroup) { + if (!this.fromGroup) { specPanel.add(opacityLabel); specPanel.add(opacitySlider); } @@ -132,7 +130,7 @@ public void componentHidden(ComponentEvent e) { } }); - JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG,this.advancedExpanded); + JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG, this.advancedExpanded); advancedPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); container.add(this.componentsFactory.wrapToSlide(generalPanel)); @@ -143,7 +141,7 @@ public void mousePressed(MouseEvent e) { requestFocus(); } }); - this.add(verticalContainer,BorderLayout.CENTER); + this.add(verticalContainer, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrLoadingPage.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrLoadingPage.java index 7b5f02a1..5250ecd0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrLoadingPage.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrLoadingPage.java @@ -6,8 +6,9 @@ import java.awt.*; -public class AdrLoadingPage extends AdrPagePanel{ +public class AdrLoadingPage extends AdrPagePanel { private MercuryLoading mercuryLoading; + public AdrLoadingPage() { super(); this.mercuryLoading = new MercuryLoading(); @@ -17,10 +18,12 @@ public AdrLoadingPage() { @Override protected void init() { } - public void playLoop(){ + + public void playLoop() { this.mercuryLoading.playLoop(); } - public void abort(){ + + public void abort() { this.mercuryLoading.abort(); } } 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 6cad9e0e..2b46c1e3 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 @@ -2,7 +2,10 @@ import com.mercury.platform.shared.config.configration.AdrConfigurationService; -import com.mercury.platform.shared.config.descriptor.adr.*; +import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; import com.mercury.platform.ui.adr.dialog.AdrImportDialog; import com.mercury.platform.ui.adr.routing.AdrComponentDefinition; import com.mercury.platform.ui.adr.routing.AdrComponentOperations; @@ -20,6 +23,7 @@ public class AdrMainPagePanel extends AdrPagePanel { private AdrConfigurationService config; + public AdrMainPagePanel(AdrConfigurationService config) { super(); this.config = config; @@ -27,15 +31,15 @@ public AdrMainPagePanel(AdrConfigurationService config) { @Override protected void init() { - if(this.fromGroup){ + if (this.fromGroup) { JLabel header = this.componentsFactory.getTextLabel(this.payload.getTitle() + " >", FontStyle.REGULAR, 20); - header.setBorder(BorderFactory.createEmptyBorder(4,6,0,4)); + header.setBorder(BorderFactory.createEmptyBorder(4, 6, 0, 4)); this.add(header, BorderLayout.PAGE_START); } JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME_RGB); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); - container.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); + container.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); JPanel createIconsGroup = this.getButton( @@ -45,7 +49,7 @@ protected void init() { @Override public void mouseClicked(MouseEvent e) { MercuryStoreUI.adrComponentStateSubject.onNext( - new AdrComponentDefinition(config.getDefaultIconGroup(), AdrComponentOperations.NEW_COMPONENT,payload) + new AdrComponentDefinition(config.getDefaultIconGroup(), AdrComponentOperations.NEW_COMPONENT, payload) ); } }); @@ -56,7 +60,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { MercuryStoreUI.adrComponentStateSubject.onNext( - new AdrComponentDefinition(config.getDefaultPBGroup(), AdrComponentOperations.NEW_COMPONENT,payload) + new AdrComponentDefinition(config.getDefaultPBGroup(), AdrComponentOperations.NEW_COMPONENT, payload) ); } }); @@ -67,7 +71,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { MercuryStoreUI.adrComponentStateSubject.onNext( - new AdrComponentDefinition(config.getDefaultCapture(), AdrComponentOperations.NEW_COMPONENT,payload) + new AdrComponentDefinition(config.getDefaultCapture(), AdrComponentOperations.NEW_COMPONENT, payload) ); } }); @@ -109,29 +113,29 @@ public void mouseClicked(MouseEvent e) { } }); JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 1), AppThemeColor.FRAME); - if(this.fromGroup) { - switch (((AdrTrackerGroupDescriptor) this.payload).getContentType()){ - case ICONS:{ + if (this.fromGroup) { + switch (((AdrTrackerGroupDescriptor) this.payload).getContentType()) { + case ICONS: { root.add(this.componentsFactory.wrapToSlide(createIcon)); break; } - case PROGRESS_BARS:{ + case PROGRESS_BARS: { root.add(this.componentsFactory.wrapToSlide(createPb)); break; } } - }else { + } else { root.add(this.componentsFactory.wrapToSlide(createIcon)); root.add(this.componentsFactory.wrapToSlide(createPb)); } - if(!this.fromGroup) { + if (!this.fromGroup) { root.add(this.componentsFactory.wrapToSlide(createCaptureComponent)); root.add(this.componentsFactory.wrapToSlide(createIconsGroup)); root.add(this.componentsFactory.wrapToSlide(createPbGroup)); } root.add(this.componentsFactory.wrapToSlide(importButton)); container.add(root); - this.add(verticalContainer,BorderLayout.CENTER); + this.add(verticalContainer, BorderLayout.CENTER); } private JPanel getButton(String iconPath, String title) { @@ -139,12 +143,12 @@ private JPanel getButton(String iconPath, String title) { root.setBackground(AppThemeColor.SLIDE_BG); JLabel iconLabel = this.componentsFactory.getIconLabel(iconPath, 64); iconLabel.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(4,4,4,4), + BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK) )); iconLabel.setBackground(AppThemeColor.FRAME_RGB); - root.add(iconLabel,BorderLayout.LINE_START); - root.add(this.componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,20,title),BorderLayout.CENTER); + root.add(iconLabel, BorderLayout.LINE_START); + root.add(this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP, 20, title), BorderLayout.CENTER); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK)); root.addMouseListener(new MouseAdapter() { @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrPagePanel.java index 1cf0311d..1fe11c50 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrPagePanel.java @@ -8,23 +8,24 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; public abstract class AdrPagePanel extends JPanel { - @Getter @Setter + @Getter + @Setter protected boolean fromGroup; protected T payload; protected ComponentsFactory componentsFactory = new ComponentsFactory(); protected boolean advancedExpanded; protected AdrComponentsFactory adrComponentsFactory = new AdrComponentsFactory(this.componentsFactory); + public AdrPagePanel() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); } protected abstract void init(); - public void setPayload(T payload){ + + public void setPayload(T payload) { this.adrComponentsFactory = new AdrComponentsFactory(this.componentsFactory); this.payload = payload; this.removeAll(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProfilePagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProfilePagePanel.java index 82d4b1e9..b231a12e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProfilePagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProfilePagePanel.java @@ -2,7 +2,6 @@ import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; import com.mercury.platform.ui.adr.validator.FieldValidator; -import com.mercury.platform.ui.adr.validator.ProfileNameValidator; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; import com.mercury.platform.ui.dialog.AlertDialog; @@ -23,16 +22,16 @@ public class AdrProfilePagePanel extends AdrPagePanel protected void init() { JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); - JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout( 0, 1,0,6)); + JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 1, 0, 6)); generalPanel.setBackground(AppThemeColor.ADR_BG); generalPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4,2,4,2))); + BorderFactory.createEmptyBorder(4, 2, 4, 2))); this.payload.forEach(it -> { - generalPanel.add(this.componentsFactory.wrapToSlide(this.getProfilePanel(it),AppThemeColor.ADR_BG,2,2,2,4)); + generalPanel.add(this.componentsFactory.wrapToSlide(this.getProfilePanel(it), AppThemeColor.ADR_BG, 2, 2, 2, 4)); }); container.add(this.componentsFactory.wrapToSlide(generalPanel)); container.addMouseListener(new MouseAdapter() { @@ -42,12 +41,13 @@ public void mousePressed(MouseEvent e) { } }); JLabel header = this.componentsFactory.getTextLabel("Profiles:", FontStyle.REGULAR, 20); - header.setBorder(BorderFactory.createEmptyBorder(4,6,0,4)); - this.add(header,BorderLayout.PAGE_START); - this.add(verticalContainer,BorderLayout.CENTER); + header.setBorder(BorderFactory.createEmptyBorder(4, 6, 0, 4)); + this.add(header, BorderLayout.PAGE_START); + this.add(verticalContainer, BorderLayout.CENTER); } - private JPanel getProfilePanel(AdrProfileDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new BorderLayout(6,0)); + + private JPanel getProfilePanel(AdrProfileDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(6, 0)); root.setBackground(AppThemeColor.ADR_BG); JTextField profileNameField = this.adrComponentsFactory.getSmartField(descriptor.getProfileName(), new FieldValidator() { @Override @@ -55,7 +55,7 @@ public boolean validate(String value) { List existingNames = payload.stream() .map(AdrProfileDescriptor::getProfileName) .collect(Collectors.toList()); - if(!existingNames.contains(value)){ + if (!existingNames.contains(value)) { this.value = value; } return !existingNames.contains(value); @@ -67,20 +67,20 @@ public boolean validate(String value) { JButton removeButton = this.componentsFactory.getIconButton("app/adr/remove_node.png", 16, AppThemeColor.FRAME, TooltipConstants.ADR_EXPORT_BUTTON); removeButton.addActionListener(action -> { new AlertDialog(success -> { - if(success) { + if (success) { MercuryStoreUI.adrRemoveProfileSubject.onNext(descriptor); this.removeAll(); this.init(); MercuryStoreUI.adrManagerRepaint.onNext(true); } - },"Do you want to delete this profile?",this).setVisible(true); + }, "Do you want to delete this profile?", this).setVisible(true); }); - if(descriptor.isSelected()) { + if (descriptor.isSelected()) { removeButton.setEnabled(false); } removeButton.setBackground(AppThemeColor.ADR_BG); - root.add(profileNameField,BorderLayout.CENTER); - root.add(removeButton,BorderLayout.LINE_END); + root.add(profileNameField, BorderLayout.CENTER); + root.add(removeButton, BorderLayout.LINE_END); return root; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java index 23d6bba6..ce9c88f2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java @@ -1,26 +1,22 @@ package com.mercury.platform.ui.adr.components.panel.page; -import com.mercury.platform.shared.config.descriptor.adr.AdrComponentOrientation; -import com.mercury.platform.shared.config.descriptor.adr.AdrIconAlignment; import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; -import com.mercury.platform.ui.adr.validator.DoubleFieldValidator; -import com.mercury.platform.ui.adr.validator.DoubleFormatFieldValidator; -import com.mercury.platform.ui.adr.validator.IntegerFieldValidator; -import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class AdrProgressBarPagePanel extends AdrPagePanel { @Override protected void init() { JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.FRAME); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); JLabel titleLabel = this.componentsFactory.getTextLabel("Title:"); @@ -47,7 +43,7 @@ protected void init() { JTextField titleField = this.adrComponentsFactory.getTitleField(this.payload); JSlider opacitySlider = this.adrComponentsFactory.getOpacitySlider(this.payload); - JPanel sizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload,this.fromGroup); + JPanel sizePanel = this.adrComponentsFactory.getComponentSizePanel(this.payload, this.fromGroup); JComboBox pbOrientation = this.adrComponentsFactory.getPbOrientationBox(this.payload); JPanel locationPanel = this.adrComponentsFactory.getLocationPanel(this.payload, this.fromGroup); JPanel hotKeyPanel = this.adrComponentsFactory.getHotKeyPanel(this.payload); @@ -66,19 +62,19 @@ protected void init() { JPanel borderColorPanel = this.adrComponentsFactory.getBorderColorPanel(this.payload); JPanel textColorPanel = this.adrComponentsFactory.getExTextColorPanel(this.payload); - JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); - JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2,0,6)); + JPanel generalPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); + JPanel specPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 0, 6)); generalPanel.setBackground(AppThemeColor.ADR_BG); generalPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4,2,4,2))); + BorderFactory.createEmptyBorder(4, 2, 4, 2))); specPanel.setBackground(AppThemeColor.ADR_BG); - specPanel.setBorder(BorderFactory.createEmptyBorder(0,0,4,2)); + specPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 2)); generalPanel.add(titleLabel); generalPanel.add(titleField); - if(!this.fromGroup) { + if (!this.fromGroup) { generalPanel.add(locationLabel); generalPanel.add(locationPanel); generalPanel.add(sizeLabel); @@ -91,7 +87,7 @@ protected void init() { generalPanel.add(durationLabel); generalPanel.add(durationField); - if(!this.fromGroup) { + if (!this.fromGroup) { specPanel.add(opacityLabel); specPanel.add(opacitySlider); } @@ -136,7 +132,7 @@ public void componentHidden(ComponentEvent e) { } }); - JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG,this.advancedExpanded); + JPanel advancedPanel = this.adrComponentsFactory.getCounterPanel(specPanel, "Advanced:", AppThemeColor.ADR_BG, this.advancedExpanded); advancedPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); container.add(this.componentsFactory.wrapToSlide(generalPanel)); @@ -147,6 +143,6 @@ public void mousePressed(MouseEvent e) { requestFocus(); } }); - this.add(verticalContainer,BorderLayout.CENTER); + this.add(verticalContainer, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrMouseOverListener.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrMouseOverListener.java index d8860c31..da74835b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrMouseOverListener.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrMouseOverListener.java @@ -15,7 +15,7 @@ import java.awt.event.MouseEvent; -public class AdrMouseOverListener extends MouseAdapter implements DestroySubscription{ +public class AdrMouseOverListener extends MouseAdapter implements DestroySubscription { private JComponent source; private T descriptor; private Cursor overCursor = new Cursor(Cursor.HAND_CURSOR); @@ -32,19 +32,20 @@ public AdrMouseOverListener(JComponent source, T descriptor, boolean fromGroup) this.source = source; this.descriptor = descriptor; this.adrSelectSubscription = MercuryStoreUI.adrSelectSubject.subscribe(selected -> { - if(!descriptor.equals(selected)){ - this.source.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + if (!descriptor.equals(selected)) { + this.source.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); this.clicked = false; - }else { + } else { this.source.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER)); this.clicked = true; } }); } + @Override public void mouseClicked(MouseEvent e) { this.source.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER)); - if(this.processSelect) { + if (this.processSelect) { this.clicked = !this.clicked; this.source.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER)); MercuryStoreUI.adrSelectSubject.onNext(this.descriptor); @@ -58,7 +59,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseEntered(MouseEvent e) { - if(!this.clicked) { + if (!this.clicked) { this.source.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, AppThemeColor.ADR_MOUSE_OVER_BORDER)); } this.source.setCursor(this.overCursor); @@ -66,8 +67,8 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { - if(!this.clicked) { - this.source.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + if (!this.clicked) { + this.source.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); } this.source.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } 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 9dcb6567..9b930890 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 @@ -36,5 +36,6 @@ public AdrNodePanel(AdrTreeNode treeNode) { this.setBorder(BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER)); this.onViewInit(); } + protected abstract void update(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrTreePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrTreePanel.java index a3e9f184..617f1ca6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrTreePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/AdrTreePanel.java @@ -1,6 +1,8 @@ package com.mercury.platform.ui.adr.components.panel.tree; -import com.mercury.platform.shared.config.descriptor.adr.*; +import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrComponentType; +import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.adr.components.panel.ui.MercuryLoading; import com.mercury.platform.ui.components.ComponentsFactory; @@ -14,55 +16,59 @@ import java.awt.*; import java.util.List; -public class AdrTreePanel extends JPanel{ - @Getter @Setter +public class AdrTreePanel extends JPanel { + @Getter + @Setter private AdrTreeNodeRenderer renderer; private ComponentsFactory componentsFactory = new ComponentsFactory(); @Getter private List descriptors; private JPanel container; - private SwingWorker worker; + private SwingWorker worker; private MercuryLoading mercuryLoading; private JScrollPane verticalContainer; private AdrTreeNode treeModel; + public AdrTreePanel(List descriptors, AdrTreeNodeRenderer renderer) { super(new BorderLayout()); this.renderer = renderer; this.setBackground(AppThemeColor.FRAME_RGB); - this.setPreferredSize(new Dimension(240,10)); + this.setPreferredSize(new Dimension(240, 10)); this.descriptors = descriptors; this.container = new VerticalScrollContainer(); this.container.setBackground(AppThemeColor.FRAME_RGB); - this.container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + this.container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); this.verticalContainer = this.componentsFactory.getVerticalContainer(container); this.mercuryLoading = new MercuryLoading(); mercuryLoading.playLoop(); - this.add(mercuryLoading,BorderLayout.CENTER); + this.add(mercuryLoading, BorderLayout.CENTER); } - private void createTreeModel(AdrTreeNode parent, List source){ + + private void createTreeModel(AdrTreeNode parent, List source) { source.forEach(it -> { AdrTreeNode treeNode = parent.addChild(it); JPanel viewOf = this.renderer.getViewOf(treeNode); treeNode.setPanel(viewOf); - if(it.getType().equals(AdrComponentType.TRACKER_GROUP)){ - this.createTreeModel(treeNode,((AdrTrackerGroupDescriptor)it).getCells()); + if (it.getType().equals(AdrComponentType.TRACKER_GROUP)) { + this.createTreeModel(treeNode, ((AdrTrackerGroupDescriptor) it).getCells()); } }); } - public void updateTree(){ - if(this.worker != null && !this.worker.isDone()) { + + public void updateTree() { + if (this.worker != null && !this.worker.isDone()) { return; } this.remove(this.verticalContainer); this.container.removeAll(); this.mercuryLoading.playLoop(); - this.add(this.mercuryLoading,BorderLayout.CENTER); + this.add(this.mercuryLoading, BorderLayout.CENTER); this.worker = new SwingWorker() { @Override protected Void doInBackground() throws Exception { - treeModel = new AdrTreeNode<>(null,container); - createTreeModel(treeModel,descriptors); + treeModel = new AdrTreeNode<>(null, container); + createTreeModel(treeModel, descriptors); return null; } @@ -70,50 +76,55 @@ protected Void doInBackground() throws Exception { protected void done() { mercuryLoading.abort(); remove(mercuryLoading); - add(verticalContainer,BorderLayout.CENTER); + add(verticalContainer, BorderLayout.CENTER); MercuryStoreUI.adrManagerPack.onNext(true); } }; this.worker.execute(); } - public void updateTree(List descriptors){ + + public void updateTree(List descriptors) { this.descriptors = descriptors; this.updateTree(); } - public void addNode(AdrComponentDescriptor descriptor, AdrComponentDescriptor parentDescriptor){ - this.addNodeHierarchy(this.treeModel,descriptor,parentDescriptor); + + public void addNode(AdrComponentDescriptor descriptor, AdrComponentDescriptor parentDescriptor) { + this.addNodeHierarchy(this.treeModel, descriptor, parentDescriptor); } + private void addNodeHierarchy(AdrTreeNode parent, AdrComponentDescriptor descriptor, - AdrComponentDescriptor parentDescriptor){ - if(parentDescriptor == null){ + AdrComponentDescriptor parentDescriptor) { + if (parentDescriptor == null) { AdrTreeNode node = parent.addChild(descriptor); JPanel viewOf = this.renderer.getViewOf(node); node.setPanel(viewOf); - }else { + } else { parent.forEach(it -> { - if(parentDescriptor.equals(it.getData())){ + if (parentDescriptor.equals(it.getData())) { AdrTreeNode node = it.addChild(descriptor); JPanel viewOf = this.renderer.getViewOf(node); node.setPanel(viewOf); } - this.addNodeHierarchy(it,descriptor,parentDescriptor); + this.addNodeHierarchy(it, descriptor, parentDescriptor); }); } } - public void removeNode(AdrComponentDescriptor descriptor){ - this.removeNode(this.treeModel,descriptor); + public void removeNode(AdrComponentDescriptor descriptor) { + this.removeNode(this.treeModel, descriptor); MercuryStoreUI.adrManagerPack.onNext(true); } - private void removeNode(AdrTreeNode node, AdrComponentDescriptor descriptor){ + + private void removeNode(AdrTreeNode node, AdrComponentDescriptor descriptor) { node.removeChild(descriptor); node.forEach(it -> { it.removeChild(descriptor); - this.removeNode(it,descriptor); + this.removeNode(it, descriptor); }); } - public void duplicateNode(AdrComponentDescriptor descriptor){ + + public void duplicateNode(AdrComponentDescriptor descriptor) { this.treeModel.duplicateChild(descriptor); } } 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 b2ffe1f6..176f1dc8 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 @@ -11,8 +11,9 @@ import java.awt.*; -public class AdrDialogCaptureNodePanel extends AdrNodePanel{ +public class AdrDialogCaptureNodePanel extends AdrNodePanel { private JLabel titleLabel; + public AdrDialogCaptureNodePanel(AdrTreeNode treeNode) { super(treeNode); this.mouseListener.setProcessSelect(false); @@ -26,13 +27,13 @@ public void onViewInit() { this.titleLabel = this.componentsFactory.getTextLabel(this.descriptor.getTitle()); this.titleLabel.setForeground(AppThemeColor.TEXT_DEFAULT); this.titleLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR, 16)); - this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,0)); + this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); - JLabel iconLabel = this.componentsFactory.getIconLabel("app/adr/capture_icon.png",44); + JLabel iconLabel = this.componentsFactory.getIconLabel("app/adr/capture_icon.png", 44); - root.add(iconLabel,BorderLayout.LINE_START); - root.add(titleLabel,BorderLayout.CENTER); - this.add(root,BorderLayout.CENTER); + root.add(iconLabel, BorderLayout.LINE_START); + root.add(titleLabel, BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); } @Override 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 062682d9..ade1561c 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 @@ -7,13 +7,12 @@ import com.mercury.platform.ui.components.fields.font.FontStyle; 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 java.awt.*; -public class AdrDialogGroupNodePanel extends AdrNodePanel{ +public class AdrDialogGroupNodePanel extends AdrNodePanel { private JLabel groupLabel; private JPanel container; @@ -33,8 +32,8 @@ protected void update() { public void onViewInit() { this.container = this.componentsFactory.getJPanel(new GridLayout(descriptor.getCells().size(), 1)); this.container.setVisible(false); - this.add(this.container,BorderLayout.CENTER); - this.add(this.getTopPanel(),BorderLayout.PAGE_START); + this.add(this.container, BorderLayout.CENTER); + this.add(this.getTopPanel(), BorderLayout.PAGE_START); } @Override @@ -42,15 +41,15 @@ public Component add(Component comp) { return this.container.add(comp); } - private JPanel getTopPanel(){ + private JPanel getTopPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); JButton expandButton = this.componentsFactory.getIconButton("app/adr/node_expand.png", 16, AppThemeColor.FRAME, ""); expandButton.addActionListener(action -> { - if(this.container.isVisible()){ - expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_expand.png",16)); + if (this.container.isVisible()) { + expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_expand.png", 16)); this.container.setVisible(false); - }else { - expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png",16)); + } else { + expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png", 16)); this.container.setVisible(true); } MercuryStoreUI.adrManagerPack.onNext(true); @@ -65,8 +64,8 @@ private JPanel getTopPanel(){ this.groupLabel.setPreferredSize(new Dimension(170, 30)); this.groupLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 2)); - root.add(expandButton,BorderLayout.LINE_START); - root.add(this.groupLabel,BorderLayout.CENTER); + root.add(expandButton, BorderLayout.LINE_START); + root.add(this.groupLabel, BorderLayout.CENTER); return root; } } 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 35af0b69..a37dffe5 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 @@ -8,7 +8,6 @@ import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; import javax.swing.*; import java.awt.*; @@ -39,9 +38,9 @@ public void onViewInit() { JLabel titleLabel = this.componentsFactory.getTextLabel(this.descriptor.getTitle()); titleLabel.setForeground(AppThemeColor.TEXT_DEFAULT); titleLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR, 16)); - titleLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,0)); - root.add(tracker,BorderLayout.LINE_START); - root.add(titleLabel,BorderLayout.CENTER); - this.add(root,BorderLayout.CENTER); + titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); + root.add(tracker, BorderLayout.LINE_START); + root.add(titleLabel, BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); } } 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 63b36ec6..f6accd72 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 @@ -7,12 +7,11 @@ import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.adr.components.panel.ui.MercuryTracker; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; import javax.swing.*; import java.awt.*; -public class AdrDialogPBNodePanel extends AdrNodePanel{ +public class AdrDialogPBNodePanel extends AdrNodePanel { public AdrDialogPBNodePanel(AdrTreeNode treeNode) { super(treeNode); this.mouseListener.setProcessSelect(false); @@ -28,10 +27,10 @@ public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); root.setBackground(AppThemeColor.SLIDE_BG); MercuryTracker tracker = new MercuryTracker(descriptor); - tracker.setValue((int) ((descriptor.getDuration()/2) * 1000)); + tracker.setValue((int) ((descriptor.getDuration() / 2) * 1000)); tracker.setPreferredSize(new Dimension(180, 30)); tracker.setShowCase(true); root.add(tracker); - this.add(root,BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogTreeNodeRenderer.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogTreeNodeRenderer.java index ba8f1738..c0bcac24 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogTreeNodeRenderer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/dialog/AdrDialogTreeNodeRenderer.java @@ -1,9 +1,6 @@ package com.mercury.platform.ui.adr.components.panel.tree.dialog; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; import com.mercury.platform.ui.adr.components.panel.tree.AdrTreeNodeRenderer; import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.components.ComponentsFactory; @@ -11,21 +8,22 @@ import javax.swing.*; -public class AdrDialogTreeNodeRenderer implements AdrTreeNodeRenderer{ +public class AdrDialogTreeNodeRenderer implements AdrTreeNodeRenderer { private ComponentsFactory componentsFactory = new ComponentsFactory(); + @Override public JPanel getViewOf(AdrTreeNode node) { - switch (node.getData().getType()){ - case ICON:{ + switch (node.getData().getType()) { + case ICON: { return this.componentsFactory.wrapToAdrSlide(new AdrDialogIconNodePanel(node), 2, 4, 2, 4); } - case PROGRESS_BAR:{ + case PROGRESS_BAR: { return this.componentsFactory.wrapToAdrSlide(new AdrDialogPBNodePanel(node), 2, 4, 2, 4); } case TRACKER_GROUP: { return this.componentsFactory.wrapToAdrSlide(new AdrDialogGroupNodePanel(node), 2, 4, 2, 4); } - case CAPTURE:{ + case CAPTURE: { return this.componentsFactory.wrapToAdrSlide(new AdrDialogCaptureNodePanel(node), 2, 4, 2, 4); } } 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 755b27ac..3b8dae97 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 @@ -13,6 +13,7 @@ public class AdrCaptureNodePanel extends AdrNodePanel { private JLabel titleLabel; + public AdrCaptureNodePanel(AdrTreeNode treeNode) { super(treeNode); } @@ -24,16 +25,16 @@ public void onViewInit() { this.titleLabel = this.componentsFactory.getTextLabel(this.descriptor.getTitle()); this.titleLabel.setForeground(AppThemeColor.TEXT_DEFAULT); this.titleLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR, 16)); - this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,0)); + this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); - JLabel iconLabel = this.componentsFactory.getIconLabel("app/adr/capture_icon.png",44); + JLabel iconLabel = this.componentsFactory.getIconLabel("app/adr/capture_icon.png", 44); - root.add(iconLabel,BorderLayout.LINE_START); - root.add(titleLabel,BorderLayout.CENTER); - this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode),BorderLayout.LINE_START); + root.add(iconLabel, BorderLayout.LINE_START); + root.add(titleLabel, BorderLayout.CENTER); + this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode), BorderLayout.LINE_START); this.add(this.adrComponentsFactory - .getRightComponentOperationsPanel(this.descriptor),BorderLayout.LINE_END); - this.add(root,BorderLayout.CENTER); + .getRightComponentOperationsPanel(this.descriptor), BorderLayout.LINE_END); + this.add(root, BorderLayout.CENTER); } @Override 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 67f3f5ed..64decaef 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 @@ -35,16 +35,16 @@ protected void update() { @Override public void onViewInit() { MercuryStoreUI.adrSelectSubject.subscribe(descriptor -> { - if(this.descriptor.equals(descriptor)){ + if (this.descriptor.equals(descriptor)) { this.container.setVisible(true); - this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png",16)); + this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png", 16)); } }); this.container = this.componentsFactory.getJPanel(new GridLayout(0, 1)); this.container.setVisible(false); - this.add(this.container,BorderLayout.CENTER); - this.add(this.getTopPanel(),BorderLayout.PAGE_START); + this.add(this.container, BorderLayout.CENTER); + this.add(this.getTopPanel(), BorderLayout.PAGE_START); } @Override @@ -57,30 +57,30 @@ public void remove(Component comp) { this.container.remove(comp); } - private JPanel getTopPanel(){ + private JPanel getTopPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); this.expandButton = this.componentsFactory.getIconButton("app/adr/node_expand.png", 16, AppThemeColor.FRAME, ""); this.expandButton.addActionListener(action -> { - if(this.container.isVisible()){ - this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_expand.png",16)); + if (this.container.isVisible()) { + this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_expand.png", 16)); this.container.setVisible(false); - }else { - this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png",16)); + } else { + this.expandButton.setIcon(this.componentsFactory.getIcon("app/adr/node_collapse.png", 16)); this.container.setVisible(true); } MercuryStoreUI.adrManagerPack.onNext(true); }); JButton removeButton = this.componentsFactory.getIconButton("app/adr/remove_node.png", 14, AppThemeColor.FRAME, TooltipConstants.ADR_REMOVE_BUTTON); removeButton.addActionListener(action -> new AlertDialog(success -> { - if(success) { + if (success) { MercuryStoreUI.adrRemoveComponentSubject.onNext(descriptor); MercuryStoreUI.adrManagerPack.onNext(true); } - },"Do you want to delete this component?",this).setVisible(true)); + }, "Do you want to delete this component?", this).setVisible(true)); JButton addButton = this.componentsFactory.getIconButton("app/adr/add_node.png", 14, AppThemeColor.FRAME, TooltipConstants.ADR_ADD_BUTTON); addButton.addActionListener(action -> { MercuryStoreUI.adrSelectSubject.onNext(this.descriptor); - MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.MAIN,this.descriptor)); + MercuryStoreUI.adrStateSubject.onNext(new AdrPageDefinition<>(AdrPageState.MAIN, this.descriptor)); }); JButton exportButton = this.componentsFactory.getIconButton("app/adr/export_node.png", 14, AppThemeColor.FRAME, TooltipConstants.ADR_EXPORT_BUTTON); exportButton.addActionListener(action -> { @@ -100,9 +100,9 @@ private JPanel getTopPanel(){ this.groupLabel.setPreferredSize(new Dimension(170, 30)); this.groupLabel.setIcon(componentsFactory.getIcon(this.adrComponentsFactory.getGroupTypeIconPath(this.descriptor), 36)); this.groupLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 2)); - root.add(this.expandButton,BorderLayout.LINE_START); - root.add(this.groupLabel,BorderLayout.CENTER); - root.add(buttonsPanel,BorderLayout.LINE_END); + root.add(this.expandButton, BorderLayout.LINE_START); + root.add(this.groupLabel, BorderLayout.CENTER); + root.add(buttonsPanel, BorderLayout.LINE_END); return root; } } 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 3dc41cad..387ea3af 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 @@ -43,12 +43,12 @@ public void onViewInit() { this.titleLabel = this.componentsFactory.getTextLabel(this.descriptor.getTitle()); this.titleLabel.setForeground(AppThemeColor.TEXT_DEFAULT); this.titleLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR, 16)); - this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0,4,0,0)); - root.add(tracker,BorderLayout.LINE_START); - root.add(this.titleLabel,BorderLayout.CENTER); - this.add(root,BorderLayout.CENTER); - this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode),BorderLayout.LINE_START); + this.titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); + root.add(tracker, BorderLayout.LINE_START); + root.add(this.titleLabel, BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); + this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode), BorderLayout.LINE_START); this.add(this.adrComponentsFactory - .getRightComponentOperationsPanel(this.descriptor),BorderLayout.LINE_END); + .getRightComponentOperationsPanel(this.descriptor), BorderLayout.LINE_END); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrMainTreeNodeRenderer.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrMainTreeNodeRenderer.java index 595aa0d8..f16c5a7c 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrMainTreeNodeRenderer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/main/AdrMainTreeNodeRenderer.java @@ -1,9 +1,6 @@ package com.mercury.platform.ui.adr.components.panel.tree.main; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; import com.mercury.platform.ui.adr.components.panel.tree.AdrTreeNodeRenderer; import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.components.ComponentsFactory; @@ -13,20 +10,21 @@ public class AdrMainTreeNodeRenderer implements AdrTreeNodeRenderer { private ComponentsFactory componentsFactory = new ComponentsFactory(); + @Override public JPanel getViewOf(AdrTreeNode treeNode) { - switch (treeNode.getData().getType()){ - case ICON:{ + switch (treeNode.getData().getType()) { + case ICON: { return this.componentsFactory.wrapToAdrSlide(new AdrIconNodePanel(treeNode), 2, 4, 2, 4); } - case PROGRESS_BAR:{ + case PROGRESS_BAR: { return this.componentsFactory.wrapToAdrSlide(new AdrProgressBarNodePanel(treeNode), 2, 4, 2, 4); } case TRACKER_GROUP: { return this.componentsFactory.wrapToAdrSlide(new AdrGroupNodePanel(treeNode), 2, 4, 2, 4); } - case CAPTURE:{ - return this.componentsFactory.wrapToSlide(new AdrCaptureNodePanel(treeNode),2,4,2,4); + case CAPTURE: { + return this.componentsFactory.wrapToSlide(new AdrCaptureNodePanel(treeNode), 2, 4, 2, 4); } } return new JPanel(); 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 f92ca889..d4bf5b5f 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 @@ -5,13 +5,9 @@ import com.mercury.platform.ui.adr.components.panel.tree.AdrNodePanel; import com.mercury.platform.ui.adr.components.panel.tree.model.AdrTreeNode; import com.mercury.platform.ui.adr.components.panel.ui.MercuryTracker; -import com.mercury.platform.ui.adr.routing.AdrComponentDefinition; -import com.mercury.platform.ui.adr.routing.AdrComponentOperations; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.dialog.DialogCallback; import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; @@ -19,6 +15,7 @@ public class AdrProgressBarNodePanel extends AdrNodePanel { private MercuryTracker tracker; + public AdrProgressBarNodePanel(AdrTreeNode treeNode) { super(treeNode); } @@ -35,16 +32,16 @@ public void onViewInit() { JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); root.setBackground(AppThemeColor.SLIDE_BG); this.tracker = new MercuryTracker(descriptor); - this.tracker.setValue((int) ((descriptor.getDuration()/2) * 1000)); + this.tracker.setValue((int) ((descriptor.getDuration() / 2) * 1000)); this.tracker.setFont(new ComponentsFactory().getFont(FontStyle.BOLD, 20)); this.tracker.setPreferredSize(new Dimension(150, 36)); this.tracker.setShowCase(true); this.tracker.setBackground(AppThemeColor.ADR_TEXT_ARE_BG); this.setPreferredSize(new Dimension(150, 48)); root.add(this.tracker); - this.add(root,BorderLayout.CENTER); - this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode),BorderLayout.LINE_START); + this.add(root, BorderLayout.CENTER); + this.add(this.adrComponentsFactory.getLeftComponentOperationsPanel(this.treeNode), BorderLayout.LINE_START); this.add(this.adrComponentsFactory - .getRightComponentOperationsPanel(this.descriptor),BorderLayout.LINE_END); + .getRightComponentOperationsPanel(this.descriptor), BorderLayout.LINE_END); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/model/AdrTreeNode.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/model/AdrTreeNode.java index e5af91c2..c4d2263b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/model/AdrTreeNode.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/tree/model/AdrTreeNode.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.function.Consumer; -public class AdrTreeNode implements Iterable>{ +public class AdrTreeNode implements Iterable> { @Getter private JPanel panel; @Getter @@ -26,55 +26,61 @@ public AdrTreeNode(T data, JPanel panel) { this.panel = panel; this.children = new ArrayList<>(); } - public void setPanel(JPanel panel){ - if(this.parent.getPanel() != null){ + + public void setPanel(JPanel panel) { + if (this.parent.getPanel() != null) { parent.getPanel().remove(this.panel); this.panel = panel; parent.getPanel().add(panel); } } - public AdrTreeNode addChild(T data, JPanel panel){ + + public AdrTreeNode addChild(T data, JPanel panel) { AdrTreeNode childNode = new AdrTreeNode<>(data, panel); childNode.parent = this; this.panel.add(panel); this.children.add(childNode); return childNode; } - public AdrTreeNode addChild(T data){ + + public AdrTreeNode addChild(T data) { AdrTreeNode childNode = new AdrTreeNode<>(data, panel); childNode.parent = this; this.children.add(childNode); return childNode; } - public void removeChild(T data){ + + public void removeChild(T data) { new ArrayList<>(this.children).forEach(it -> { - if(it.getData().equals(data)){ - if(this.data != null && this.data.getType().equals(AdrComponentType.TRACKER_GROUP)){ - ((AdrTrackerGroupDescriptor)this.data).getCells().remove(data); + if (it.getData().equals(data)) { + if (this.data != null && this.data.getType().equals(AdrComponentType.TRACKER_GROUP)) { + ((AdrTrackerGroupDescriptor) this.data).getCells().remove(data); } this.panel.remove(it.getPanel()); this.children.remove(it); } }); } - public void duplicateChild(AdrComponentDescriptor descriptor){ + + public void duplicateChild(AdrComponentDescriptor descriptor) { this.forEach(it -> { - if(it.getData().equals(descriptor)){ + if (it.getData().equals(descriptor)) { try { - AdrTreeNode clone = (AdrTreeNode)it.clone(); + AdrTreeNode clone = (AdrTreeNode) it.clone(); this.children.add(clone); this.panel.add(clone.getPanel()); } catch (CloneNotSupportedException e) { e.printStackTrace(); } - }else { + } else { it.duplicateChild(descriptor); } }); } - public boolean contains(T data){ + + public boolean contains(T data) { for (AdrTreeNode child : this.children) { - if(child.getData().equals(data)){ + if (child.getData().equals(data)) { return true; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/BasicMercuryIconTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/BasicMercuryIconTrackerUI.java index a49237c8..57ce19d9 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/BasicMercuryIconTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/BasicMercuryIconTrackerUI.java @@ -4,36 +4,32 @@ import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentOrientation; import com.mercury.platform.shared.config.descriptor.adr.AdrDurationComponentDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; -import com.mercury.platform.ui.misc.AppThemeColor; -import lombok.Getter; import lombok.Setter; import sun.swing.SwingUtilities2; import javax.swing.*; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicProgressBarUI; import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; -import java.awt.geom.AffineTransform; import java.text.DecimalFormat; -public abstract class BasicMercuryIconTrackerUI extends ComponentUI{ +public abstract class BasicMercuryIconTrackerUI extends ComponentUI { @Setter protected T descriptor; @Setter protected MercuryTracker tracker; protected IconBundleConfigurationService config; - protected BasicMercuryIconTrackerUI(){ + protected BasicMercuryIconTrackerUI() { this.config = Configuration.get().iconBundleConfiguration(); } + @Override public Dimension getPreferredSize(JComponent c) { Dimension dimension = super.getPreferredSize(c); - if(dimension == null){ + if (dimension == null) { dimension = new Dimension(150, 26); } int value = Math.max(dimension.width, dimension.height); @@ -43,7 +39,7 @@ public Dimension getPreferredSize(JComponent c) { protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull) { - if(descriptor.isTextEnable() && tracker.isStringPainted()) { + if (descriptor.isTextEnable() && tracker.isStringPainted()) { float value = tracker.getValue() / 1000f; Graphics2D g2 = this.prepareAdapter(g); @@ -55,7 +51,7 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int g2.setColor(this.getColorByValue()); SwingUtilities2.drawString(tracker, g2, progressString, renderLocation.x, renderLocation.y); - if(this.descriptor.getOutlineThickness() > 0) { + if (this.descriptor.getOutlineThickness() > 0) { FontRenderContext frc = g2.getFontRenderContext(); TextLayout textTl = new TextLayout(progressString, tracker.getFont(), frc); Shape outline = textTl.getOutline(null); @@ -70,13 +66,14 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int } } } - protected void paintBorder(Graphics g){ + + protected void paintBorder(Graphics g) { int thickness = descriptor.getThickness(); - if(thickness > 0) { + if (thickness > 0) { Graphics2D g2 = this.prepareAdapter(g); g2.setColor(getColorByValue()); Stroke oldStroke = g2.getStroke(); - if(!descriptor.isBindToTextColor()) { + if (!descriptor.isBindToTextColor()) { g2.setPaint(this.descriptor.getBorderColor()); } g2.setStroke(new BasicStroke(thickness)); @@ -84,7 +81,8 @@ protected void paintBorder(Graphics g){ g2.setStroke(oldStroke); } } - private Color getColorByValue(){ + + private Color getColorByValue() { float value = tracker.getValue() / 1000f; if (value >= descriptor.getDefaultValueTextThreshold()) { return this.descriptor.getDefaultValueTextColor(); @@ -96,20 +94,20 @@ private Color getColorByValue(){ } protected Point getStringPlacement(Graphics g, String progressString, - int x,int y,int width,int height) { + int x, int y, int width, int height) { FontMetrics fontSizer = SwingUtilities2.getFontMetrics(tracker, g, tracker.getFont()); int stringWidth = SwingUtilities2.stringWidth(tracker, fontSizer, progressString); if (descriptor.getOrientation() == AdrComponentOrientation.HORIZONTAL) { - return new Point(x + Math.round(width/2 - stringWidth/2), + return new Point(x + Math.round(width / 2 - stringWidth / 2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2)); } else { - return new Point(x + ((width - + return new Point(x + ((width - fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2), @@ -119,7 +117,8 @@ protected Point getStringPlacement(Graphics g, String progressString, fontSizer.getDescent()) / 2)); } } - protected Graphics2D prepareAdapter(Graphics g){ + + protected Graphics2D prepareAdapter(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/IconsListCellRenderer.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/IconsListCellRenderer.java index 4ab06b68..f3d135aa 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/IconsListCellRenderer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/IconsListCellRenderer.java @@ -9,15 +9,15 @@ import java.awt.*; - public class IconsListCellRenderer implements ListCellRenderer { private ComponentsFactory componentsFactory = new ComponentsFactory(); private IconBundleConfigurationService config = Configuration.get().iconBundleConfiguration(); + @Override public Component getListCellRendererComponent(JList list, String value, int index, boolean isSelected, boolean cellHasFocus) { JLabel iconLabel = this.componentsFactory.getIconLabel(this.config.getIcon(value), 64); - iconLabel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); - if(isSelected){ + iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + if (isSelected) { iconLabel.setBorder(BorderFactory.createLineBorder(AppThemeColor.TEXT_MESSAGE)); } return iconLabel; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoading.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoading.java index 0b5580d4..b91b0617 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoading.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoading.java @@ -1,4 +1,5 @@ package com.mercury.platform.ui.adr.components.panel.ui; + import com.mercury.platform.ui.misc.AppThemeColor; import lombok.Getter; import lombok.Setter; @@ -14,9 +15,11 @@ public class MercuryLoading extends JComponent { @Getter private int value; - @Setter @Getter + @Setter + @Getter private int maximum; - @Setter @Getter + @Setter + @Getter private int minimum; private Timeline progressTl; @Setter @@ -41,11 +44,13 @@ public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.Tim } }); } + public void setValue(int value) { this.value = value; this.updateUI(); } - public void setLoadingUI(ComponentUI componentUI){ + + public void setLoadingUI(ComponentUI componentUI) { this.setUI(componentUI); } @@ -54,24 +59,29 @@ public void updateUI() { setUI(this.ui); } - public float getPercentComplete(){ + public float getPercentComplete() { long span = maximum - minimum; return (value - minimum) / (span * 1f); } - public void abort(){ + + public void abort() { this.progressTl.abort(); } - public void playLoop(){ + + public void playLoop() { this.progressTl.playLoop(Timeline.RepeatBehavior.LOOP); } - public void play(){ + + public void play() { this.progressTl.play(); } - public void cancel(){ + + public void cancel() { this.progressTl.cancel(); } - public void swapColors(){ - if(swapEnable) { + + public void swapColors() { + if (swapEnable) { Color temp = new Color(this.getBackground().getRGB()); this.setBackground(this.getForeground()); this.setForeground(temp); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoadingUi.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoadingUi.java index af438147..ecc9d35b 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoadingUi.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryLoadingUi.java @@ -15,8 +15,9 @@ public MercuryLoadingUi(MercuryLoading component) { this.component = component; } - @Override public void paint(Graphics g, JComponent c) { - if(component.getWidth() == 0){ + @Override + public void paint(Graphics g, JComponent c) { + if (component.getWidth() == 0) { return; } @@ -30,8 +31,8 @@ public MercuryLoadingUi(MercuryLoading component) { double innerR = outerR * .78; double pointX = component.getWidth() * .5; double pointY = component.getHeight() * .5; - Shape inner = new Ellipse2D.Double(pointX - innerR, pointY - innerR, innerR * 2, innerR * 2); - Shape outer = new Ellipse2D.Double(pointX - outerR, pointY - outerR, size, size); + Shape inner = new Ellipse2D.Double(pointX - innerR, pointY - innerR, innerR * 2, innerR * 2); + Shape outer = new Ellipse2D.Double(pointX - outerR, pointY - outerR, size, size); Shape sector = new Arc2D.Double(pointX - outerR, pointY - outerR, size, size, 90 - degree, degree, Arc2D.PIE); Area foreground = new Area(sector); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java index 59e3b15b..29161e4e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java @@ -1,7 +1,10 @@ package com.mercury.platform.ui.adr.components.panel.ui; -import com.mercury.platform.shared.config.descriptor.adr.*; -import com.mercury.platform.ui.adr.components.panel.ui.impl.*; +import com.mercury.platform.shared.config.descriptor.adr.AdrDurationComponentDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; +import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; +import com.mercury.platform.ui.adr.components.panel.ui.impl.ProgressBarUI; +import com.mercury.platform.ui.adr.components.panel.ui.impl.SquareIconTrackerUI; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.misc.AppThemeColor; @@ -16,17 +19,23 @@ public class MercuryTracker extends JComponent { @Getter private int value; - @Setter @Getter + @Setter + @Getter private int maximum; - @Setter @Getter + @Setter + @Getter private int minimum; - @Setter @Getter + @Setter + @Getter private AdrDurationComponentDescriptor descriptor; - @Setter @Getter + @Setter + @Getter private boolean stringPainted = true; - @Setter @Getter + @Setter + @Getter private boolean maskPainted = true; - @Setter @Getter + @Setter + @Getter private boolean showCase = false; private Timeline progressTl; @@ -41,14 +50,15 @@ public MercuryTracker(AdrDurationComponentDescriptor descriptor) { this.progressTl = new Timeline(this); this.progressTl.setInitialDelay((long) (descriptor.getDelay() * 1000)); this.progressTl.setDuration((int) (descriptor.getDuration() * 1000)); - if(this.descriptor.isInvertTimer()) { + if (this.descriptor.isInvertTimer()) { this.setValue((int) (this.descriptor.getDuration() * 1000)); this.progressTl.addPropertyToInterpolate("value", 0, this.getMaximum()); - }else { + } else { this.setValue(0); this.progressTl.addPropertyToInterpolate("value", this.getMaximum(), 0); } } + private void initUI() { BasicMercuryIconTrackerUI ui; if (descriptor instanceof AdrIconDescriptor) { @@ -61,7 +71,7 @@ private void initUI() { this.setUI(ui); } - public void setUI(BasicMercuryIconTrackerUI ui){ + public void setUI(BasicMercuryIconTrackerUI ui) { super.setUI(ui); } @@ -76,23 +86,28 @@ public void updateUI() { setUI(this.ui); } - public float getPercentComplete(){ + public float getPercentComplete() { long span = maximum - minimum; return (value - minimum) / (span * 1f); } - public void addTimelineCallback(TimelineCallback callback){ + + public void addTimelineCallback(TimelineCallback callback) { this.progressTl.addCallback(callback); } - public void abort(){ + + public void abort() { this.progressTl.abort(); } - public void playLoop(){ + + public void playLoop() { this.progressTl.playLoop(Timeline.RepeatBehavior.LOOP); } - public void play(){ + + public void play() { this.progressTl.play(); } - public void cancel(){ + + public void cancel() { this.progressTl.cancel(); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/BIconVProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/BIconVProgressBarTrackerUI.java index 04a66e81..ab2d2553 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/BIconVProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/BIconVProgressBarTrackerUI.java @@ -8,11 +8,11 @@ import java.io.IOException; -public class BIconVProgressBarTrackerUI extends VProgressBarTrackerUI{ +public class BIconVProgressBarTrackerUI extends VProgressBarTrackerUI { @Override protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Insets insets) { - if(tracker.isShowCase()){ - super.paintShapes(g,barRectWidth,barRectHeight,insets); + if (tracker.isShowCase()) { + super.paintShapes(g, barRectWidth, barRectHeight, insets); return; } Graphics2D g2 = this.prepareAdapter(g); @@ -20,15 +20,15 @@ protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Inse int iconY = barRectHeight - barRectWidth; int sectorX = 0; int sectorY = (int) ((barRectHeight - barRectWidth) * (1f - this.tracker.getPercentComplete())); - if(this.descriptor.isInvertMask()){ + if (this.descriptor.isInvertMask()) { sectorY = (int) ((barRectHeight - barRectWidth) * this.tracker.getPercentComplete()); } float sectorHeight = barRectHeight - sectorY - barRectWidth; - Shape outer = new Rectangle2D.Double(0, 0,barRectWidth, barRectHeight); + Shape outer = new Rectangle2D.Double(0, 0, barRectWidth, barRectHeight); Shape sector = new Rectangle2D.Double(insets.left + sectorX, insets.top + sectorY, barRectWidth - insets.right * 2, sectorHeight - insets.bottom * 2); try { BufferedImage read = ImageIO.read(this.config.getIcon(descriptor.getIconPath())); - g2.drawImage(read,iconX,iconY,tracker.getWidth(),tracker.getWidth(),null); + g2.drawImage(read, iconX, iconY, tracker.getWidth(), tracker.getWidth(), null); } catch (IOException e) { e.printStackTrace(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/EllipseIconTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/EllipseIconTrackerUI.java index 29d99156..77beda1f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/EllipseIconTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/EllipseIconTrackerUI.java @@ -13,11 +13,11 @@ import java.io.IOException; -public class EllipseIconTrackerUI extends BasicMercuryIconTrackerUI{ +public class EllipseIconTrackerUI extends BasicMercuryIconTrackerUI { @Override public void paint(Graphics g, JComponent c) { Insets b = tracker.getInsets(); - int barRectWidth = tracker.getWidth(); + int barRectWidth = tracker.getWidth(); int barRectHeight = tracker.getHeight(); if (barRectWidth <= 0 || barRectHeight <= 0) { return; @@ -26,7 +26,7 @@ public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.setColor(tracker.getBackground()); - g2.fillRect(0,0,barRectWidth,barRectHeight); + g2.fillRect(0, 0, barRectWidth, barRectHeight); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -38,8 +38,8 @@ public void paint(Graphics g, JComponent c) { g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); double degree = 360 * (1f - tracker.getPercentComplete()); double sz = Math.max(barRectWidth, barRectHeight) - 2; - Shape outer = new Ellipse2D.Double(1, 1, sz, sz); - Shape sector = new Arc2D.Double(-sz, -sz, sz *3, sz *3, 90 - degree, degree, Arc2D.PIE); + Shape outer = new Ellipse2D.Double(1, 1, sz, sz); + Shape sector = new Arc2D.Double(-sz, -sz, sz * 3, sz * 3, 90 - degree, degree, Arc2D.PIE); Area foreground = new Area(sector); Area background = new Area(outer); @@ -47,36 +47,37 @@ public void paint(Graphics g, JComponent c) { foreground.intersect(background); g2.setPaint(new Color(59, 59, 59)); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.7f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); try { - BufferedImage read = ImageIO.read(getClass().getClassLoader().getResource("app/adr/icons/" +descriptor.getIconPath() + ".png")); + BufferedImage read = ImageIO.read(getClass().getClassLoader().getResource("app/adr/icons/" + descriptor.getIconPath() + ".png")); - Shape imageEllipse = new Ellipse2D.Double(1, 1, sz, sz); + Shape imageEllipse = new Ellipse2D.Double(1, 1, sz, sz); g2.setClip(imageEllipse); - g2.drawImage(read,0,0,(int)sz,(int)sz,null); + g2.drawImage(read, 0, 0, (int) sz, (int) sz, null); g2.setClip(null); } catch (IOException e) { e.printStackTrace(); } - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.7f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.fill(foreground); - this.paintOvalBorder(g,barRectWidth,barRectHeight); + this.paintOvalBorder(g, barRectWidth, barRectHeight); g2.dispose(); this.paintString(g, 0, 0, barRectWidth, barRectHeight, 0); } - private void paintOvalBorder(Graphics g,int width, int height){ + + private void paintOvalBorder(Graphics g, int width, int height) { int thickness = descriptor.getThickness(); - if(thickness > 0) { + if (thickness > 0) { Graphics2D g2 = (Graphics2D) g; Stroke oldStroke = g2.getStroke(); - if(!descriptor.isBindToTextColor()) { + if (!descriptor.isBindToTextColor()) { g2.setPaint(this.descriptor.getBorderColor()); } - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC,1f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1f)); g2.setStroke(new BasicStroke(thickness + 1)); - g2.drawOval(1,1,width-1 ,height-1); + g2.drawOval(1, 1, width - 1, height - 1); g2.setStroke(oldStroke); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/LIconHProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/LIconHProgressBarTrackerUI.java index af8a3bc3..50e61664 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/LIconHProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/LIconHProgressBarTrackerUI.java @@ -1,7 +1,6 @@ package com.mercury.platform.ui.adr.components.panel.ui.impl; - import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.Area; @@ -21,7 +20,7 @@ protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Inse Shape sector = new Rectangle2D.Double(tracker.getHeight() + insets.left, insets.top, sectorWidth - insets.right * 2, barRectHeight - insets.bottom * 2); try { BufferedImage read = ImageIO.read(this.config.getIcon(descriptor.getIconPath())); - g2.drawImage(read,iconX,iconY,tracker.getHeight(),tracker.getHeight(),null); + g2.drawImage(read, iconX, iconY, tracker.getHeight(), tracker.getHeight(), null); } catch (IOException e) { e.printStackTrace(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/MercuryProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/MercuryProgressBarTrackerUI.java index 635c08bd..af04e416 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/MercuryProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/MercuryProgressBarTrackerUI.java @@ -13,27 +13,28 @@ public class MercuryProgressBarTrackerUI extends BasicMercuryIconTrackerUI { @Override public void paint(Graphics g, JComponent c) { - if(!tracker.isShowCase()){ - if(!descriptor.isVisible()) { + if (!tracker.isShowCase()) { + if (!descriptor.isVisible()) { return; } } Insets insets = descriptor.getInsets(); - int barRectWidth = tracker.getWidth(); + int barRectWidth = tracker.getWidth(); int barRectHeight = tracker.getHeight(); if (barRectWidth <= 0 || barRectHeight <= 0) { return; } Graphics2D g2 = this.prepareAdapter(g); - g2.fillRect(0,0,barRectWidth,barRectHeight); - this.paintShapes(g,barRectWidth,barRectHeight,insets); + g2.fillRect(0, 0, barRectWidth, barRectHeight); + this.paintShapes(g, barRectWidth, barRectHeight, insets); this.paintBorder(g); } + protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Insets insets) { Graphics2D g2 = (Graphics2D) g.create(); float sectorWidth = barRectWidth * tracker.getPercentComplete(); - Shape outer = new Rectangle2D.Double(0, 0,barRectWidth, barRectHeight); + Shape outer = new Rectangle2D.Double(0, 0, barRectWidth, barRectHeight); Shape sector = new Rectangle2D.Double(insets.left, insets.top, sectorWidth - insets.right * 2, barRectHeight - insets.bottom * 2); Area foreground = new Area(sector); Area background = new Area(outer); @@ -44,17 +45,18 @@ protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Inse g2.dispose(); this.paintString(g, 0, 0, barRectWidth, barRectHeight, 0); } + @Override - protected Graphics2D prepareAdapter(Graphics g){ + protected Graphics2D prepareAdapter(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); - if(this.tracker.isShowCase()){ - if (descriptor.getBackgroundColor().getAlpha() < 10){ + if (this.tracker.isShowCase()) { + if (descriptor.getBackgroundColor().getAlpha() < 10) { g2.setColor(AppThemeColor.ADR_TEXT_ARE_BG); - }else { + } else { g2.setColor(descriptor.getBackgroundColor()); } - }else { + } else { g2.setColor(descriptor.getBackgroundColor()); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUI.java index 29b30807..6efaa7fa 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUI.java @@ -25,7 +25,7 @@ public boolean isSuitable(AdrProgressBarDescriptor descriptor) { return descriptor.isIconEnable() && descriptor.getIconAlignment().equals(AdrIconAlignment.RIGHT) && descriptor.getOrientation().equals(AdrComponentOrientation.HORIZONTAL); - } + } @Override public MercuryProgressBarTrackerUI getUI() { @@ -81,7 +81,7 @@ public MercuryProgressBarTrackerUI getUI() { } }; - public static MercuryProgressBarTrackerUI getUIBy(AdrProgressBarDescriptor descriptor){ + public static MercuryProgressBarTrackerUI getUIBy(AdrProgressBarDescriptor descriptor) { for (ProgressBarUI progressBarUI : ProgressBarUI.values()) { if (progressBarUI.isSuitable(descriptor)) { return progressBarUI.getUI(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUIFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUIFactory.java index 1ade15d9..6c1c199d 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUIFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/ProgressBarUIFactory.java @@ -5,5 +5,6 @@ public interface ProgressBarUIFactory { boolean isSuitable(AdrProgressBarDescriptor descriptor); + MercuryProgressBarTrackerUI getUI(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/RIconHProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/RIconHProgressBarTrackerUI.java index 4c7b0a0c..06c77d65 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/RIconHProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/RIconHProgressBarTrackerUI.java @@ -20,7 +20,7 @@ protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Inse Shape sector = new Rectangle2D.Double(insets.left, insets.top, sectorWidth - insets.right * 2, barRectHeight - insets.bottom * 2); try { BufferedImage read = ImageIO.read(this.config.getIcon(descriptor.getIconPath())); - g2.drawImage(read,iconX,iconY,tracker.getHeight(),tracker.getHeight(),null); + g2.drawImage(read, iconX, iconY, tracker.getHeight(), tracker.getHeight(), null); } catch (IOException e) { e.printStackTrace(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/SquareIconTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/SquareIconTrackerUI.java index 7a250e82..0e0000c0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/SquareIconTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/SquareIconTrackerUI.java @@ -17,33 +17,33 @@ public class SquareIconTrackerUI extends BasicMercuryIconTrackerUI { @Override public void paint(Graphics g, JComponent c) { - if(!tracker.isShowCase()){ - if(!descriptor.isVisible()) { + if (!tracker.isShowCase()) { + if (!descriptor.isVisible()) { return; } } - int barRectWidth = tracker.getWidth(); + int barRectWidth = tracker.getWidth(); int barRectHeight = tracker.getHeight(); if (barRectWidth <= 0 || barRectHeight <= 0) { return; } Graphics2D g2 = (Graphics2D) g.create(); - g2.setComposite(AlphaComposite.getInstance(descriptor.getBackgroundColor().getAlpha() == 0? AlphaComposite.CLEAR : AlphaComposite.SRC)); - if(this.tracker.isShowCase()){ - if (descriptor.getBackgroundColor().getAlpha() < 10){ + g2.setComposite(AlphaComposite.getInstance(descriptor.getBackgroundColor().getAlpha() == 0 ? AlphaComposite.CLEAR : AlphaComposite.SRC)); + if (this.tracker.isShowCase()) { + if (descriptor.getBackgroundColor().getAlpha() < 10) { g2.setColor(AppThemeColor.ADR_TEXT_ARE_BG); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); - }else { + } else { g2.setColor(descriptor.getBackgroundColor()); } - }else { + } else { g2.setColor(descriptor.getBackgroundColor()); } - g2.fillRect(0,0,barRectWidth,barRectHeight); + g2.fillRect(0, 0, barRectWidth, barRectHeight); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double sz = Math.max(barRectWidth, barRectHeight); - if(descriptor.isIconEnable()) { + if (descriptor.isIconEnable()) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); try { BufferedImage read = ImageIO.read(this.config.getIcon(descriptor.getIconPath())); @@ -53,11 +53,11 @@ public void paint(Graphics g, JComponent c) { e.printStackTrace(); } } - if(tracker.isMaskPainted() && descriptor.isMaskEnable() && !tracker.isShowCase()) { + if (tracker.isMaskPainted() && descriptor.isMaskEnable() && !tracker.isShowCase()) { double degree; - if(descriptor.isInvertMask()) { + if (descriptor.isInvertMask()) { degree = 360 * tracker.getPercentComplete(); - }else { + } else { degree = 360 * (1f - tracker.getPercentComplete()); } Shape outer = new Rectangle2D.Double(0, 0, sz, sz); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/TIconVProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/TIconVProgressBarTrackerUI.java index d9641e0d..097bb825 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/TIconVProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/TIconVProgressBarTrackerUI.java @@ -8,11 +8,11 @@ import java.awt.image.BufferedImage; import java.io.IOException; -public class TIconVProgressBarTrackerUI extends VProgressBarTrackerUI{ +public class TIconVProgressBarTrackerUI extends VProgressBarTrackerUI { @Override protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Insets insets) { - if(tracker.isShowCase()){ - super.paintShapes(g,barRectWidth,barRectHeight,insets); + if (tracker.isShowCase()) { + super.paintShapes(g, barRectWidth, barRectHeight, insets); return; } Graphics2D g2 = (Graphics2D) g.create(); @@ -20,15 +20,15 @@ protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Inse int iconY = 0; int sectorX = 0; int sectorY = (int) ((barRectHeight - barRectWidth) * (1f - this.tracker.getPercentComplete())) + barRectWidth; - if(this.descriptor.isInvertMask()){ + if (this.descriptor.isInvertMask()) { sectorY = (int) ((barRectHeight - barRectWidth) * this.tracker.getPercentComplete()) + barRectWidth; } float sectorHeight = barRectHeight - sectorY; - Shape outer = new Rectangle2D.Double(0, 0,barRectWidth, barRectHeight); + Shape outer = new Rectangle2D.Double(0, 0, barRectWidth, barRectHeight); Shape sector = new Rectangle2D.Double(insets.left + sectorX, insets.top + sectorY, barRectWidth - insets.right * 2, sectorHeight - insets.bottom * 2); try { BufferedImage read = ImageIO.read(this.config.getIcon(descriptor.getIconPath())); - g2.drawImage(read,iconX,iconY,tracker.getWidth(),tracker.getWidth(),null); + g2.drawImage(read, iconX, iconY, tracker.getWidth(), tracker.getWidth(), null); } catch (IOException e) { e.printStackTrace(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/VProgressBarTrackerUI.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/VProgressBarTrackerUI.java index 6d4501c4..880786a2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/VProgressBarTrackerUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/impl/VProgressBarTrackerUI.java @@ -7,13 +7,14 @@ public class VProgressBarTrackerUI extends MercuryProgressBarTrackerUI { protected void paintShapes(Graphics g, int barRectWidth, int barRectHeight, Insets insets) { int sectorX = 0; - int sectorY = (int) (barRectHeight * (1f - this.tracker.getPercentComplete()));; - if(this.descriptor.isInvertMask()){ + int sectorY = (int) (barRectHeight * (1f - this.tracker.getPercentComplete())); + ; + if (this.descriptor.isInvertMask()) { sectorY = 0; } Graphics2D g2 = this.prepareAdapter(g); float sectorHeight = barRectHeight * tracker.getPercentComplete(); - Shape outer = new Rectangle2D.Double(0, 0,barRectWidth, barRectHeight); + Shape outer = new Rectangle2D.Double(0, 0, barRectWidth, barRectHeight); Shape sector = new Rectangle2D.Double(insets.left + sectorX, insets.top + sectorY, barRectWidth - insets.right * 2, sectorHeight - insets.bottom * 2); Area foreground = new Area(sector); Area background = new Area(outer); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrDialog.java index ff6c84ad..4b034327 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrDialog.java @@ -7,13 +7,12 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -public abstract class AdrDialog extends JDialog{ +public abstract class AdrDialog extends JDialog { protected ComponentsFactory componentsFactory = new ComponentsFactory(); @Getter protected T payload; + public AdrDialog(Component relative, T payload) { this.payload = payload; this.setModal(true); @@ -21,18 +20,21 @@ public AdrDialog(Component relative, T payload) { this.setLayout(new BorderLayout()); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setBackground(AppThemeColor.FRAME_RGB); - this.getRootPane().setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); + this.getRootPane().setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); this.createView(); this.pack(); this.setLocationRelativeTo(relative); } + private void createView() { - this.setPreferredSize(new Dimension(600,500)); + this.setPreferredSize(new Dimension(600, 500)); JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.add(this.getDataPanel(),BorderLayout.CENTER); - root.add(this.getViewPanel(),BorderLayout.LINE_END); - this.add(this.componentsFactory.wrapToSlide(root),BorderLayout.CENTER); + root.add(this.getDataPanel(), BorderLayout.CENTER); + root.add(this.getViewPanel(), BorderLayout.LINE_END); + this.add(this.componentsFactory.wrapToSlide(root), BorderLayout.CENTER); } + protected abstract JPanel getDataPanel(); + protected abstract JPanel getViewPanel(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrExportDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrExportDialog.java index 6031550a..a0530d2d 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrExportDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrExportDialog.java @@ -3,15 +3,12 @@ import com.google.gson.Gson; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; -import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; -import com.mercury.platform.ui.adr.components.panel.tree.*; +import com.mercury.platform.ui.adr.components.panel.tree.AdrTreePanel; import com.mercury.platform.ui.adr.components.panel.tree.dialog.AdrDialogTreeNodeRenderer; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; -import com.mercury.platform.ui.misc.TooltipConstants; -import rx.Subscription; import javax.swing.*; import java.awt.*; @@ -19,14 +16,13 @@ import java.awt.event.ComponentEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.util.*; import java.util.List; public class AdrExportDialog extends AdrDialog> { private JTextArea jsonArea; private AdrTreePanel adrTree; - public AdrExportDialog(Component relative, List descriptor){ + public AdrExportDialog(Component relative, List descriptor) { super(relative, descriptor); this.setTitle("Export manager"); this.setModal(false); @@ -36,7 +32,7 @@ public AdrExportDialog(Component relative, List descript this.repaint(); }); MercuryStoreUI.adrExportSubject.subscribe(other -> { - if(!this.isVisible()){ + if (!this.isVisible()) { this.setVisible(true); this.setLocationRelativeTo(null); } @@ -57,6 +53,7 @@ public void windowClosed(WindowEvent e) { }); } + public void postConstruct() { this.jsonArea.setText(this.getPayloadAsJson()); this.adrTree.setVisible(true); @@ -66,47 +63,49 @@ public void postConstruct() { } @Override - protected JPanel getDataPanel(){ + protected JPanel getDataPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); root.setBackground(AppThemeColor.ADR_BG); - JLabel header = this.componentsFactory.getTextLabel("Data (Ctrl + A for copy):", FontStyle.BOLD,18); + JLabel header = this.componentsFactory.getTextLabel("Data (Ctrl + A for copy):", FontStyle.BOLD, 18); header.setForeground(AppThemeColor.TEXT_NICKNAME); - root.add(header,BorderLayout.PAGE_START); + root.add(header, BorderLayout.PAGE_START); JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.ADR_BG); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); this.jsonArea = this.componentsFactory.getSimpleTextArea(""); this.jsonArea.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); - this.jsonArea.setMinimumSize(new Dimension(450,550)); + this.jsonArea.setMinimumSize(new Dimension(450, 550)); this.jsonArea.setBackground(AppThemeColor.ADR_TEXT_ARE_BG); - container.add(this.jsonArea,AppThemeColor.ADR_BG); - root.add(this.componentsFactory.wrapToSlide(verticalContainer,AppThemeColor.ADR_BG,0,5,4,0),BorderLayout.CENTER); + container.add(this.jsonArea, AppThemeColor.ADR_BG); + root.add(this.componentsFactory.wrapToSlide(verticalContainer, AppThemeColor.ADR_BG, 0, 5, 4, 0), BorderLayout.CENTER); return this.componentsFactory.wrapToSlide(root); } + @Override - protected JPanel getViewPanel(){ + protected JPanel getViewPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.setPreferredSize(new Dimension(240,100)); + root.setPreferredSize(new Dimension(240, 100)); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); root.setBackground(AppThemeColor.FRAME_RGB); JPanel headerPanel = this.componentsFactory.getJPanel(new BorderLayout()); headerPanel.setBackground(AppThemeColor.ADR_BG); - JLabel header = this.componentsFactory.getTextLabel("View:", FontStyle.BOLD,18); + JLabel header = this.componentsFactory.getTextLabel("View:", FontStyle.BOLD, 18); header.setForeground(AppThemeColor.TEXT_NICKNAME); - headerPanel.add(header,BorderLayout.CENTER); - root.add(headerPanel,BorderLayout.PAGE_START); + headerPanel.add(header, BorderLayout.CENTER); + root.add(headerPanel, BorderLayout.PAGE_START); this.adrTree = new AdrTreePanel(this.payload, new AdrDialogTreeNodeRenderer()); this.adrTree.setVisible(false); - root.add(this.componentsFactory.wrapToSlide(this.adrTree,AppThemeColor.FRAME_RGB),BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(this.adrTree, AppThemeColor.FRAME_RGB), BorderLayout.CENTER); return this.componentsFactory.wrapToSlide(root); } - private String getPayloadAsJson(){ + + private String getPayloadAsJson() { return new Gson().toJson(this.payload); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java index beeb66ee..d1c2982c 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java @@ -13,13 +13,13 @@ import javax.swing.*; import java.awt.*; -import java.util.*; import java.util.List; import java.util.stream.Collectors; -public class AdrIconSelectDialog extends BaseDialog { +public class AdrIconSelectDialog extends BaseDialog { private JList iconsList; private IconBundleConfigurationService config; + public AdrIconSelectDialog() { super(null, null, null); this.setTitle("Select icon"); @@ -28,7 +28,7 @@ public AdrIconSelectDialog() { @Override protected void createView() { this.config = Configuration.get().iconBundleConfiguration(); - this.setPreferredSize(new Dimension(530,400)); + this.setPreferredSize(new Dimension(530, 400)); VerticalScrollContainer container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.SLIDE_BG); @@ -44,47 +44,48 @@ protected void createView() { this.iconsList.setCellRenderer(new IconsListCellRenderer()); this.iconsList.setLayoutOrientation(JList.HORIZONTAL_WRAP); - container.add(this.iconsList,BorderLayout.CENTER); + container.add(this.iconsList, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK)); - this.add(this.getFilterPanel(),BorderLayout.PAGE_START); - this.add(scrollPane,BorderLayout.CENTER); - this.add(this.getBottomPanel(),BorderLayout.PAGE_END); + this.add(this.getFilterPanel(), BorderLayout.PAGE_START); + this.add(scrollPane, BorderLayout.CENTER); + this.add(this.getBottomPanel(), BorderLayout.PAGE_END); } - public void setSelectedIcon(String iconPath){ - this.iconsList.setSelectedValue(iconPath,true); + + public void setSelectedIcon(String iconPath) { + this.iconsList.setSelectedValue(iconPath, true); } - private JPanel getFilterPanel(){ + private JPanel getFilterPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.add(this.componentsFactory.getTextLabel("Filter:"),BorderLayout.LINE_START); + root.add(this.componentsFactory.getTextLabel("Filter:"), BorderLayout.LINE_START); JTextField filterField = this.componentsFactory.getTextField("Filter:", FontStyle.REGULAR, 15); filterField.addActionListener(action -> { List entities = this.config.getDefaultBundle(); entities.addAll(this.config.getEntities()); - if(filterField.getText().equals("")){ + if (filterField.getText().equals("")) { this.iconsList.setListData(entities.toArray()); - }else { + } else { List collect = entities.stream() .filter(name -> StringUtils.containsIgnoreCase(name, filterField.getText())) .collect(Collectors.toList()); this.iconsList.setListData(collect.toArray()); } }); - root.add(filterField,BorderLayout.CENTER); + root.add(filterField, BorderLayout.CENTER); root.setBackground(AppThemeColor.SLIDE_BG); root.setBorder( BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4,0,4,4))); + BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), + BorderFactory.createEmptyBorder(4, 0, 4, 4))); JButton addIconButton = this.componentsFactory.getBorderedButton("Add icon"); - addIconButton.setPreferredSize(new Dimension(100,26)); + addIconButton.setPreferredSize(new Dimension(100, 26)); addIconButton.addActionListener(action -> { - FileDialog dialog = new FileDialog(this,"Choose icon", FileDialog.LOAD); + FileDialog dialog = new FileDialog(this, "Choose icon", FileDialog.LOAD); dialog.setFile("*.png"); dialog.setVisible(true); dialog.toFront(); - if(this.isValidIconPath(dialog.getFile())){ + if (this.isValidIconPath(dialog.getFile())) { this.config.addIcon(dialog.getDirectory() + dialog.getFile()); Object selectedValue = this.iconsList.getSelectedValue(); List entities = this.config.getDefaultBundle(); @@ -94,23 +95,24 @@ private JPanel getFilterPanel(){ MercuryStoreCore.saveConfigSubject.onNext(true); } }); - root.add(this.componentsFactory.wrapToSlide(addIconButton,AppThemeColor.ADR_BG),BorderLayout.LINE_END); + root.add(this.componentsFactory.wrapToSlide(addIconButton, AppThemeColor.ADR_BG), BorderLayout.LINE_END); JPanel wrapper = this.componentsFactory.wrapToSlide(root); - wrapper.setBorder(BorderFactory.createEmptyBorder(4,0,4,0)); + wrapper.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); return wrapper; } - private JPanel getBottomPanel(){ + + private JPanel getBottomPanel() { JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); JButton selectButton = this.componentsFactory.getBorderedButton("Select"); - selectButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD,15f)); - JButton cancelButton = componentsFactory.getButton( + selectButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 15f)); + JButton cancelButton = componentsFactory.getButton( FontStyle.BOLD, AppThemeColor.FRAME_RGB, BorderFactory.createLineBorder(AppThemeColor.BORDER), "Cancel", 15f); - selectButton.setPreferredSize(new Dimension(128,26)); - cancelButton.setPreferredSize(new Dimension(128,26)); + selectButton.setPreferredSize(new Dimension(128, 26)); + cancelButton.setPreferredSize(new Dimension(128, 26)); selectButton.addActionListener(action -> { this.callback.onAction((String) this.iconsList.getSelectedValue()); this.setVisible(false); @@ -120,7 +122,8 @@ private JPanel getBottomPanel(){ root.add(cancelButton); return root; } - private boolean isValidIconPath(String name){ + + private boolean isValidIconPath(String name) { return name != null && (name.endsWith(".png")); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrImportDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrImportDialog.java index 91a6db65..961e7a34 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrImportDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrImportDialog.java @@ -10,7 +10,6 @@ import com.mercury.platform.shared.config.descriptor.adr.AdrProfileDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupDescriptor; import com.mercury.platform.shared.config.json.deserializer.AdrComponentJsonAdapter; -import com.mercury.platform.shared.config.json.deserializer.AdrTrackerGroupDeserializer; import com.mercury.platform.shared.entity.message.MercuryError; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.adr.components.panel.tree.AdrTreePanel; @@ -21,22 +20,23 @@ import com.mercury.platform.ui.components.panel.VerticalScrollContainer; 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.util.*; +import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; -public class AdrImportDialog extends AdrDialog{ +public class AdrImportDialog extends AdrDialog { private JTextArea jsonArea; private AdrTreePanel adrTree; private JPanel viewPanel; private JPanel treePanel; private JLabel errorLabel; - public AdrImportDialog(Component relative){ + + public AdrImportDialog(Component relative) { super(relative, null); this.setTitle("Import manager"); @@ -47,24 +47,24 @@ public AdrImportDialog(Component relative){ } @Override - protected JPanel getDataPanel(){ + protected JPanel getDataPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); root.setBackground(AppThemeColor.ADR_BG); - JLabel header = this.componentsFactory.getTextLabel("Data (Ctrl + V for paste):", FontStyle.BOLD,18); + JLabel header = this.componentsFactory.getTextLabel("Data (Ctrl + V for paste):", FontStyle.BOLD, 18); header.setForeground(AppThemeColor.TEXT_NICKNAME); - root.add(header,BorderLayout.PAGE_START); + root.add(header, BorderLayout.PAGE_START); JPanel container = new VerticalScrollContainer(); container.setBackground(AppThemeColor.ADR_BG); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(container); this.jsonArea = this.componentsFactory.getSimpleTextArea(""); this.jsonArea.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); this.jsonArea.addCaretListener(e -> { this.viewPanel.remove(this.errorLabel); - this.viewPanel.add(this.treePanel,BorderLayout.CENTER); + this.viewPanel.add(this.treePanel, BorderLayout.CENTER); this.adrTree.setVisible(false); List jsonAsObject = this.getJsonAsObject(this.jsonArea.getText()); this.adrTree.updateTree(jsonAsObject); @@ -72,42 +72,43 @@ protected JPanel getDataPanel(){ this.pack(); this.repaint(); }); - this.jsonArea.setMinimumSize(new Dimension(450,550)); + this.jsonArea.setMinimumSize(new Dimension(450, 550)); this.jsonArea.setEditable(true); - this.jsonArea.setPreferredSize(new Dimension(450,550)); + this.jsonArea.setPreferredSize(new Dimension(450, 550)); this.jsonArea.setBackground(AppThemeColor.ADR_TEXT_ARE_BG); - container.add(this.jsonArea,AppThemeColor.ADR_BG); - root.add(this.componentsFactory.wrapToSlide(verticalContainer,AppThemeColor.ADR_BG,0,5,4,0),BorderLayout.CENTER); + container.add(this.jsonArea, AppThemeColor.ADR_BG); + root.add(this.componentsFactory.wrapToSlide(verticalContainer, AppThemeColor.ADR_BG, 0, 5, 4, 0), BorderLayout.CENTER); return this.componentsFactory.wrapToSlide(root); } + @Override - protected JPanel getViewPanel(){ + protected JPanel getViewPanel() { this.viewPanel = this.componentsFactory.getJPanel(new BorderLayout()); - this.viewPanel.setPreferredSize(new Dimension(240,100)); + this.viewPanel.setPreferredSize(new Dimension(240, 100)); this.viewPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); this.viewPanel.setBackground(AppThemeColor.FRAME_RGB); - this.errorLabel = this.componentsFactory.getIconLabel("app/error_icon.png",26); + this.errorLabel = this.componentsFactory.getIconLabel("app/error_icon.png", 26); this.errorLabel.setText("Some errors occurred.."); - this.errorLabel.setFont(this.componentsFactory.getFont(FontStyle.REGULAR,16)); + this.errorLabel.setFont(this.componentsFactory.getFont(FontStyle.REGULAR, 16)); this.errorLabel.setForeground(AppThemeColor.TEXT_DEFAULT); JPanel headerPanel = this.componentsFactory.getJPanel(new BorderLayout()); headerPanel.setBackground(AppThemeColor.ADR_BG); - JLabel header = this.componentsFactory.getTextLabel("View:", FontStyle.BOLD,18); + JLabel header = this.componentsFactory.getTextLabel("View:", FontStyle.BOLD, 18); header.setForeground(AppThemeColor.TEXT_NICKNAME); - headerPanel.add(header,BorderLayout.CENTER); - this.viewPanel.add(headerPanel,BorderLayout.PAGE_START); + headerPanel.add(header, BorderLayout.CENTER); + this.viewPanel.add(headerPanel, BorderLayout.PAGE_START); this.adrTree = new AdrTreePanel(new ArrayList<>(), new AdrDialogTreeNodeRenderer()); this.adrTree.setVisible(false); this.treePanel = this.componentsFactory.wrapToSlide(this.adrTree, AppThemeColor.FRAME_RGB); - this.viewPanel.add(this.treePanel,BorderLayout.CENTER); + this.viewPanel.add(this.treePanel, BorderLayout.CENTER); JPanel buttonsPanel = this.componentsFactory.getJPanel(new GridLayout(2, 1, 0, 6)); JButton importToCurrent = this.componentsFactory.getBorderedButton("Import to current profile"); importToCurrent.addActionListener(action -> { List descriptors = this.adrTree.getDescriptors(); - if(descriptors != null) { + if (descriptors != null) { AdrComponentDefinition definition = this.prepareDefinition(descriptors); MercuryStoreUI.adrComponentStateSubject.onNext(definition); this.setVisible(false); @@ -138,14 +139,15 @@ protected JPanel getViewPanel(){ }); buttonsPanel.add(importToCurrent); buttonsPanel.add(createAndImport); - this.viewPanel.add(this.componentsFactory.wrapToSlide(buttonsPanel),BorderLayout.PAGE_END); + this.viewPanel.add(this.componentsFactory.wrapToSlide(buttonsPanel), BorderLayout.PAGE_END); return this.componentsFactory.wrapToSlide(viewPanel); } - private AdrComponentDefinition prepareDefinition(List descriptors){ + + private AdrComponentDefinition prepareDefinition(List descriptors) { descriptors.forEach(it -> { it.setComponentId(UUID.randomUUID().toString()); - if(it instanceof AdrTrackerGroupDescriptor){ - ((AdrTrackerGroupDescriptor) it).getCells().forEach(cell-> cell.setComponentId(UUID.randomUUID().toString())); + if (it instanceof AdrTrackerGroupDescriptor) { + ((AdrTrackerGroupDescriptor) it).getCells().forEach(cell -> cell.setComponentId(UUID.randomUUID().toString())); } }); AdrComponentDefinition definition = new AdrComponentDefinition(); @@ -153,21 +155,23 @@ private AdrComponentDefinition prepareDefinition(List de definition.setOperations(AdrComponentOperations.NEW_FROM_IMPORT); return definition; } - private List getJsonAsObject(String jsonStr){ + + private List getJsonAsObject(String jsonStr) { try { Gson gson = new GsonBuilder() - .registerTypeAdapter(AdrComponentDescriptor.class,new AdrComponentJsonAdapter()) + .registerTypeAdapter(AdrComponentDescriptor.class, new AdrComponentJsonAdapter()) .create(); JsonParser jsonParser = new JsonParser(); return gson.fromJson( jsonParser.parse(jsonStr), - new TypeToken>(){}.getType()); - }catch (IllegalStateException | JsonSyntaxException e){ + new TypeToken>() { + }.getType()); + } catch (IllegalStateException | JsonSyntaxException e) { this.viewPanel.remove(this.treePanel); - this.viewPanel.add(this.errorLabel,BorderLayout.CENTER); + this.viewPanel.add(this.errorLabel, BorderLayout.CENTER); this.pack(); this.repaint(); - MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing string: " + jsonStr,e)); + MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError("Error while importing string: " + jsonStr, e)); return null; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrNewProfileDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrNewProfileDialog.java index c7bd617d..08cb8df2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrNewProfileDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrNewProfileDialog.java @@ -14,7 +14,8 @@ public class AdrNewProfileDialog extends BaseDialog> { private AdrComponentsFactory adrComponentsFactory; - public AdrNewProfileDialog(DialogCallback callback, Component relative, List payload) { + + public AdrNewProfileDialog(DialogCallback callback, Component relative, List payload) { super(callback, relative, payload); this.setTitle("Create new profile"); this.setResizable(false); @@ -29,19 +30,19 @@ protected void createView() { ProfileNameValidator profileNameValidator = new ProfileNameValidator(this.payload); JTextField nameField = this.componentsFactory.getTextField("", FontStyle.REGULAR, 16f); - nameField.setPreferredSize(new Dimension(300,20)); + nameField.setPreferredSize(new Dimension(300, 20)); JPanel fieldPanel = this.componentsFactory.getJPanel(new BorderLayout()); - fieldPanel.add(this.componentsFactory.getTextLabel("Profile name: "),BorderLayout.LINE_START); - fieldPanel.add(nameField,BorderLayout.CENTER); + fieldPanel.add(this.componentsFactory.getTextLabel("Profile name: "), BorderLayout.LINE_START); + fieldPanel.add(nameField, BorderLayout.CENTER); fieldPanel.setBackground(AppThemeColor.ADR_BG); JPanel buttonsPanel = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); buttonsPanel.setBackground(AppThemeColor.ADR_BG); JButton createButton = this.componentsFactory.getBorderedButton("Create"); - createButton.setPreferredSize(new Dimension(100,26)); - createButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD,16f)); + createButton.setPreferredSize(new Dimension(100, 26)); + createButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 16f)); createButton.addActionListener(action -> { - if(!nameField.getText().isEmpty() && profileNameValidator.validate(nameField.getText())){ + if (!nameField.getText().isEmpty() && profileNameValidator.validate(nameField.getText())) { this.callback.onAction(nameField.getText()); this.setVisible(false); this.dispose(); @@ -53,15 +54,15 @@ protected void createView() { BorderFactory.createLineBorder(AppThemeColor.BORDER), "Cancel", 16f); - cancelButton.setPreferredSize(new Dimension(100,26)); + cancelButton.setPreferredSize(new Dimension(100, 26)); cancelButton.addActionListener(action -> { - this.setVisible(false); + this.setVisible(false); }); buttonsPanel.add(createButton); buttonsPanel.add(cancelButton); - root.add(this.componentsFactory.wrapToSlide(fieldPanel,AppThemeColor.ADR_BG),BorderLayout.CENTER); - root.add(this.componentsFactory.wrapToSlide(buttonsPanel,AppThemeColor.ADR_BG),BorderLayout.PAGE_END); - this.add(root,BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(fieldPanel, AppThemeColor.ADR_BG), BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(buttonsPanel, AppThemeColor.ADR_BG), BorderLayout.PAGE_END); + this.add(root, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentDefinition.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentDefinition.java index 58734e95..caa24b89 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentDefinition.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentDefinition.java @@ -1,7 +1,6 @@ package com.mercury.platform.ui.adr.routing; import com.mercury.platform.shared.config.descriptor.adr.AdrComponentDescriptor; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -21,6 +20,7 @@ public AdrComponentDefinition(AdrComponentDescriptor descriptor, AdrComponentOpe this.operations = operations; this.fromGroup = fromGroup; } + public AdrComponentDefinition(AdrComponentDescriptor descriptor, AdrComponentOperations operations, AdrComponentDescriptor parent) { this.descriptor = descriptor; this.operations = operations; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentOperations.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentOperations.java index 495cc720..dbb857be 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentOperations.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/routing/AdrComponentOperations.java @@ -1,7 +1,7 @@ package com.mercury.platform.ui.adr.routing; -public enum AdrComponentOperations { +public enum AdrComponentOperations { NEW_COMPONENT, EDIT_COMPONENT, DUPLICATE_COMPONENT, diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFieldValidator.java index 3649e41e..34441465 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFieldValidator.java @@ -6,13 +6,14 @@ public class DoubleFieldValidator extends RangeFieldValidator { public DoubleFieldValidator(Double min, Double max) { super(min, max); } + @Override public boolean validate(String value) { String decimalPattern = "(?=.)([+-]?([0-9]*)(\\.([0-9]+))?)"; - boolean numeric = Pattern.matches(decimalPattern,value); - if(numeric){ + boolean numeric = Pattern.matches(decimalPattern, value); + if (numeric) { this.value = Double.parseDouble(value); - if(this.value >= min && this.value <= max){ + if (this.value >= min && this.value <= max) { return true; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFormatFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFormatFieldValidator.java index 33cf9f54..c17c38f3 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFormatFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/DoubleFormatFieldValidator.java @@ -3,16 +3,17 @@ import java.util.Arrays; import java.util.List; -public class DoubleFormatFieldValidator extends FieldValidator { +public class DoubleFormatFieldValidator extends FieldValidator { @Override public boolean validate(String value) { - if(validPatterns().contains(value)){ + if (validPatterns().contains(value)) { this.value = value; return true; } return false; } - private List validPatterns(){ + + private List validPatterns() { return Arrays.asList( "0", "0.0", diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FieldValidator.java index 522c6f49..9156ed3f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FieldValidator.java @@ -3,7 +3,7 @@ import lombok.Getter; -public abstract class FieldValidator { +public abstract class FieldValidator { @Getter protected T value; diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FloatFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FloatFieldValidator.java index f5f24a71..1317e692 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FloatFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/FloatFieldValidator.java @@ -3,7 +3,7 @@ import java.util.regex.Pattern; -public class FloatFieldValidator extends RangeFieldValidator { +public class FloatFieldValidator extends RangeFieldValidator { public FloatFieldValidator(Float min, Float max) { super(min, max); } @@ -11,10 +11,10 @@ public FloatFieldValidator(Float min, Float max) { @Override public boolean validate(String value) { String decimalPattern = "(?=.)([+-]?([0-9]*)(\\.([0-9]+))?)"; - boolean numeric = Pattern.matches(decimalPattern,value); - if(numeric){ + boolean numeric = Pattern.matches(decimalPattern, value); + if (numeric) { this.value = Float.parseFloat(value); - if(this.value >= min && this.value <= max){ + if (this.value >= min && this.value <= max) { return true; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/HexFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/HexFieldValidator.java index b717055c..87d8af73 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/HexFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/HexFieldValidator.java @@ -3,13 +3,13 @@ import java.util.regex.Pattern; -public class HexFieldValidator extends FieldValidator { +public class HexFieldValidator extends FieldValidator { @Override public boolean validate(String value) { String hexPattern = "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"; value = value.toLowerCase(); - boolean hex = Pattern.matches(hexPattern,value); - if(hex){ + boolean hex = Pattern.matches(hexPattern, value); + if (hex) { this.value = value; return true; } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/IntegerFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/IntegerFieldValidator.java index 000c309e..368a43b0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/IntegerFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/IntegerFieldValidator.java @@ -2,17 +2,17 @@ import org.apache.commons.lang3.StringUtils; -public class IntegerFieldValidator extends RangeFieldValidator { +public class IntegerFieldValidator extends RangeFieldValidator { public IntegerFieldValidator(int min, int max) { - super(min,max); + super(min, max); } @Override public boolean validate(String value) { boolean numeric = StringUtils.isNumeric(value); - if(numeric){ + if (numeric) { this.value = Integer.parseInt(value); - if(this.value >= min && this.value <= max){ + if (this.value >= min && this.value <= max) { return true; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/RangeFieldValidator.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/RangeFieldValidator.java index 5985f050..32e7f1a2 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/RangeFieldValidator.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/validator/RangeFieldValidator.java @@ -3,7 +3,7 @@ import lombok.Getter; //todo -public abstract class RangeFieldValidator extends FieldValidator { +public abstract class RangeFieldValidator extends FieldValidator { @Getter protected T max; @Getter 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 a2cd2f2f..522945cc 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/ComponentsFactory.java @@ -1,17 +1,14 @@ package com.mercury.platform.ui.components; import com.mercury.platform.core.misc.SoundType; -import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; -import com.mercury.platform.ui.components.fields.style.MercuryComboBoxUI; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.fields.font.TextAlignment; +import com.mercury.platform.ui.components.fields.style.MercuryComboBoxUI; import com.mercury.platform.ui.components.fields.style.MercuryScrollBarUI; import com.mercury.platform.ui.components.panel.misc.ToggleCallback; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; -import com.sun.java.swing.plaf.windows.WindowsButtonUI; -import com.sun.java.swing.plaf.windows.WindowsSliderUI; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -39,7 +36,7 @@ /** * Factory for each element which uses in application */ -public class ComponentsFactory{ +public class ComponentsFactory { private final static Logger log = LogManager.getLogger(ComponentsFactory.class); private Font BOLD_FONT; @@ -57,19 +54,19 @@ public ComponentsFactory() { // UIManager.getDefaults().put("Slider.horizontalThumbIcon",this.getImage("app/slider_thumb.png")); UIManager.put("ComboBox.selectionBackground", AppThemeColor.HEADER); UIManager.put("ComboBox.selectionForeground", AppThemeColor.ADR_POPUP_BG); - UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG); + UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG); } /** * Loading all application fonts */ - private void loadFonts(){ + private void loadFonts() { try { BOLD_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("font/Fontin-Bold.ttf")); ITALIC_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("font/Fontin-Italic.ttf")); REGULAR_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("font/Fontin-Regular.ttf")); SMALLCAPS_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("font/Fontin-SmallCaps.ttf")); - DEFAULT_FONT = new Font("Tahoma", Font.BOLD, (int)(scale*16)); + DEFAULT_FONT = new Font("Tahoma", Font.BOLD, (int) (scale * 16)); } catch (Exception e) { log.error(e); @@ -78,18 +75,19 @@ private void loadFonts(){ /** * Get button with custom params - * @param fontStyle path of exile font type + * + * @param fontStyle path of exile font type * @param background button background - * @param border button border - * @param text default text - * @param fontSize font size + * @param border button border + * @param text default text + * @param fontSize font size * @return JButton object */ - public JButton getButton(FontStyle fontStyle, Color background, Border border, String text, float fontSize){ - JButton button = new JButton(text){ + public JButton getButton(FontStyle fontStyle, Color background, Border border, String text, float fontSize) { + JButton button = new JButton(text) { @Override protected void paintBorder(Graphics g) { - if(!this.getModel().isPressed()) { + if (!this.getModel().isPressed()) { super.paintBorder(g); } } @@ -99,6 +97,7 @@ protected void paintBorder(Graphics g) { button.setFocusPainted(false); button.addMouseListener(new MouseAdapter() { Border prevBorder; + @Override public void mouseEntered(MouseEvent e) { this.prevBorder = button.getBorder(); @@ -119,14 +118,14 @@ public void mouseExited(MouseEvent e) { button.addActionListener(action -> { MercuryStoreCore.soundSubject.onNext(SoundType.CLICKS); }); - if(isAscii(text)){ - button.setFont(getSelectedFont(fontStyle).deriveFont(scale*fontSize)); - }else { - button.setFont(DEFAULT_FONT.deriveFont(scale*fontSize)); + if (isAscii(text)) { + button.setFont(getSelectedFont(fontStyle).deriveFont(scale * fontSize)); + } else { + button.setFont(DEFAULT_FONT.deriveFont(scale * fontSize)); } button.setBorder(border); - button.addChangeListener(e->{ - if(!button.getModel().isPressed()){ + button.addChangeListener(e -> { + if (!button.getModel().isPressed()) { button.setBackground(button.getBackground()); } }); @@ -135,54 +134,59 @@ public void mouseExited(MouseEvent e) { /** * Get button with default properties + * * @param text text on button * @return Default app button */ - public JButton getButton(String text){ + public JButton getButton(String text) { CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 1), BorderFactory.createLineBorder(AppThemeColor.BUTTON, 3) ); - return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale*14f); + return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale * 14f); } /** * Get bordered button with default properties. + * * @param text text on button * @return Default bordered app button */ - public JButton getBorderedButton(String text){ + public JButton getBorderedButton(String text) { CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), BorderFactory.createLineBorder(AppThemeColor.BUTTON, 3) ); - return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale*14f); + return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale * 14f); } - public JButton getBorderedButton(String text, float fontSize){ + + public JButton getBorderedButton(String text, float fontSize) { CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), BorderFactory.createLineBorder(AppThemeColor.BUTTON, 3) ); - return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale*fontSize); + return getButton(FontStyle.BOLD, AppThemeColor.BUTTON, compoundBorder, text, scale * fontSize); } - public JButton getBorderedButton(String text, float fontSize, Color background, Color outerBorderColor, Color innerBorderColor){ + + 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); + return getButton(FontStyle.BOLD, background, compoundBorder, text, scale * fontSize); } - public Component setUpToggleCallbacks(Component button,ToggleCallback firstState, ToggleCallback secondState, boolean initialState){ + public Component setUpToggleCallbacks(Component button, ToggleCallback firstState, ToggleCallback secondState, boolean initialState) { button.addMouseListener(new MouseAdapter() { private boolean state = initialState; + @Override public void mouseClicked(MouseEvent e) { - if(state){ + if (state) { firstState.onToggle(); state = false; - }else { + } else { secondState.onToggle(); state = true; } @@ -193,42 +197,44 @@ public void mouseClicked(MouseEvent e) { /** * Get button with icon + * * @param iconPath icon path from maven resources * @param iconSize icon size * @return JButton object with icon */ - public JButton getIconButton(String iconPath, float iconSize, Color background, String tooltip){ - JButton button = new JButton(""){ + public JButton getIconButton(String iconPath, float iconSize, Color background, String tooltip) { + JButton button = new JButton("") { @Override protected void paintBorder(Graphics g) { - if(!this.getModel().isPressed()) { + if (!this.getModel().isPressed()) { super.paintBorder(g); } } }; button.setBackground(background); button.setFocusPainted(false); - button.addChangeListener(e->{ - if(!button.getModel().isPressed()){ + button.addChangeListener(e -> { + if (!button.getModel().isPressed()) { button.setBackground(button.getBackground()); } }); - if(tooltip.length() > 0) { + if (tooltip.length() > 0) { button.addMouseListener(new TooltipMouseListener(tooltip)); } - button.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + 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.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); }); button.addMouseListener(new MouseAdapter() { Border prevBorder; + @Override public void mouseEntered(MouseEvent e) { prevBorder = button.getBorder(); button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER), - BorderFactory.createEmptyBorder(3,3,3,3))); + BorderFactory.createEmptyBorder(3, 3, 3, 3))); button.setCursor(new Cursor(Cursor.HAND_CURSOR)); } @@ -239,50 +245,53 @@ public void mouseExited(MouseEvent e) { } }); - button.setBorder(BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,4)); + button.setBorder(BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 4)); button.setVerticalAlignment(SwingConstants.CENTER); BufferedImage icon = null; try { BufferedImage buttonIcon = ImageIO.read(getClass().getClassLoader().getResource(iconPath)); - icon = Scalr.resize(buttonIcon, (int)(scale*iconSize)); + icon = Scalr.resize(buttonIcon, (int) (scale * iconSize)); } catch (IOException e) { e.printStackTrace(); } - if(icon != null){ + if (icon != null) { button.setIcon(new ImageIcon(icon)); } return button; } - public JButton getIconifiedTransparentButton(String iconPath, String tooltip){ + public JButton getIconifiedTransparentButton(String iconPath, String tooltip) { JButton iconButton = getIconButton(iconPath, 10, AppThemeColor.FRAME_RGB, tooltip); iconButton.setIcon(getImage(iconPath)); return iconButton; } + /** * Get bordered default button with icon + * * @param iconPath icon path from maven resources * @param iconSize icon size * @return bordered JButton with icon */ - public JButton getBorderedIconButton(String iconPath, int iconSize, String tooltip){ + public JButton getBorderedIconButton(String iconPath, int iconSize, String tooltip) { CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), BorderFactory.createLineBorder(AppThemeColor.BUTTON, 2) ); - JButton iconButton = getIconButton(iconPath, iconSize, AppThemeColor.FRAME_ALPHA,tooltip); + JButton iconButton = getIconButton(iconPath, iconSize, AppThemeColor.FRAME_ALPHA, tooltip); iconButton.setBorder(BorderFactory.createLineBorder(AppThemeColor.BUTTON, 2)); return iconButton; } /** * Get icon button with custom size - * @param iconPath icon path from maven resources - * @param iconSize icon size + * + * @param iconPath icon path from maven resources + * @param iconSize icon size * @param buttonSize button size (its only preferred) * @return JButton with icon */ - public JButton getIconButton(String iconPath, int iconSize, Dimension buttonSize, String tooltip){ + public JButton getIconButton(String iconPath, int iconSize, Dimension buttonSize, String tooltip) { JButton iconButton = getIconButton(iconPath, iconSize, AppThemeColor.FRAME_ALPHA, tooltip); iconButton.setPreferredSize(buttonSize); //todo scale iconButton.setSize(buttonSize); @@ -291,25 +300,26 @@ public JButton getIconButton(String iconPath, int iconSize, Dimension buttonSize /** * Get label with custom params + * * @param fontStyle path of exile font type - * @param frColor foreground color + * @param frColor foreground color * @param alignment font alignment - * @param size font size - * @param text initial text on font + * @param size font size + * @param text initial text on font * @return JLabel object */ - public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment alignment, float size, String text){ + public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment alignment, float size, String text) { JLabel label = new JLabel(text); - if(isAscii(text)){ - label.setFont(getSelectedFont(fontStyle).deriveFont(scale*size)); - }else { - label.setFont(DEFAULT_FONT.deriveFont(scale*size)); + if (isAscii(text)) { + label.setFont(getSelectedFont(fontStyle).deriveFont(scale * size)); + } else { + label.setFont(DEFAULT_FONT.deriveFont(scale * size)); } label.setForeground(frColor); Border border = label.getBorder(); - label.setBorder(new CompoundBorder(border,new EmptyBorder(0,5,0,5))); + label.setBorder(new CompoundBorder(border, new EmptyBorder(0, 5, 0, 5))); - if(alignment != null) { + if (alignment != null) { switch (alignment) { case LEFTOP: { label.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -320,7 +330,7 @@ public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment ali label.setAlignmentX(Component.RIGHT_ALIGNMENT); label.setAlignmentY(Component.TOP_ALIGNMENT); } - case CENTER:{ + case CENTER: { label.setAlignmentX(Component.CENTER_ALIGNMENT); label.setAlignmentY(Component.TOP_ALIGNMENT); } @@ -330,7 +340,7 @@ public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment ali return label; } - public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment alignment, float size, Border border,String text){ + public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment alignment, float size, Border border, String text) { JLabel textLabel = getTextLabel(fontStyle, frColor, alignment, size, text); textLabel.setBorder(border); return textLabel; @@ -338,83 +348,93 @@ public JLabel getTextLabel(FontStyle fontStyle, Color frColor, TextAlignment ali /** * Get default label + * * @param text font text * @return JLabel object */ - public JLabel getTextLabel(String text){ - return getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_DEFAULT,TextAlignment.LEFTOP,scale*15f,text); + public JLabel getTextLabel(String text) { + return getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, scale * 15f, text); } - public JLabel getTextLabel(String text, FontStyle style){ - return getTextLabel(style,AppThemeColor.TEXT_DEFAULT,TextAlignment.LEFTOP,scale*15f,text); + + public JLabel getTextLabel(String text, FontStyle style) { + return getTextLabel(style, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, scale * 15f, text); } - public JLabel getTextLabel(String text, FontStyle style,Color color){ - return getTextLabel(style,color,TextAlignment.LEFTOP,scale*15f,text); + + public JLabel getTextLabel(String text, FontStyle style, Color color) { + return getTextLabel(style, color, TextAlignment.LEFTOP, scale * 15f, text); } - public JLabel getTextLabel(String text, FontStyle style, float size){ - return getTextLabel(style,AppThemeColor.TEXT_DEFAULT,TextAlignment.LEFTOP,size,text); + + public JLabel getTextLabel(String text, FontStyle style, float size) { + return getTextLabel(style, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, size, text); } /** * Get label with icon + * * @param iconPath icon path from maven resources - * @param size icon size + * @param size icon size * @return JLabel object with icon */ - public JLabel getIconLabel(String iconPath, int size){ + public JLabel getIconLabel(String iconPath, int size) { JLabel iconLabel = new JLabel(); try { - iconLabel.setIcon(getIcon(iconPath,(int)(scale*size))); + iconLabel.setIcon(getIcon(iconPath, (int) (scale * size))); } catch (Exception e) { - return getTextLabel(StringUtils.substringBetween(iconPath,"/",".")); + return getTextLabel(StringUtils.substringBetween(iconPath, "/", ".")); } return iconLabel; } - public JLabel getIconLabel(String iconPath, int size, int aligment){ + + public JLabel getIconLabel(String iconPath, int size, int aligment) { JLabel iconLabel = new JLabel(); try { - iconLabel.setIcon(getIcon(iconPath,(int)(scale*size))); + iconLabel.setIcon(getIcon(iconPath, (int) (scale * size))); } catch (Exception e) { - return getTextLabel(StringUtils.substringBetween(iconPath,"/",".")); + return getTextLabel(StringUtils.substringBetween(iconPath, "/", ".")); } iconLabel.setHorizontalAlignment(aligment); return iconLabel; } - public JLabel getIconLabel(URL url, int size){ + + public JLabel getIconLabel(URL url, int size) { JLabel iconLabel = new JLabel(); try { - iconLabel.setIcon(getIcon(url,(int)(scale*size))); + iconLabel.setIcon(getIcon(url, (int) (scale * size))); } catch (Exception e) { - return getTextLabel(StringUtils.substringBetween(url.getPath(),"/",".")); + return getTextLabel(StringUtils.substringBetween(url.getPath(), "/", ".")); } return iconLabel; } - public JLabel getIconLabel(String iconPath, int size, String tooltip){ + + public JLabel getIconLabel(String iconPath, int size, String tooltip) { JLabel iconLabel = new JLabel(); try { - iconLabel.setIcon(getIcon(iconPath,(int)(scale*size))); + iconLabel.setIcon(getIcon(iconPath, (int) (scale * size))); } catch (Exception e) { - return getTextLabel(StringUtils.substringBetween(iconPath,"/",".")); + return getTextLabel(StringUtils.substringBetween(iconPath, "/", ".")); } iconLabel.addMouseListener(new TooltipMouseListener(tooltip)); return iconLabel; } - public JLabel getIconLabel(String iconPath){ + + public JLabel getIconLabel(String iconPath) { JLabel iconLabel = new JLabel(); try { BufferedImage buttonIcon = ImageIO.read(getClass().getClassLoader().getResource(iconPath)); iconLabel.setIcon(new ImageIcon(buttonIcon)); } catch (Exception e) { - return getTextLabel(StringUtils.substringBetween(iconPath,"/",".")); + return getTextLabel(StringUtils.substringBetween(iconPath, "/", ".")); } return iconLabel; } - public JTextField getTextField(String text){ - JTextField textField = getTextField(text,null,scale*16); + public JTextField getTextField(String text) { + JTextField textField = getTextField(text, null, scale * 16); textField.setFont(DEFAULT_FONT); return textField; } - public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer value){ + + public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer value) { NumberFormat format = NumberFormat.getInstance(); NumberFormatter formatter = new NumberFormatter(format); formatter.setValueClass(Integer.class); @@ -425,33 +445,34 @@ public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer JFormattedTextField field = new JFormattedTextField(formatter); field.setValue(value); - field.setFont(REGULAR_FONT.deriveFont(scale*18)); + field.setFont(REGULAR_FONT.deriveFont(scale * 18)); field.setFocusLostBehavior(JFormattedTextField.PERSIST); field.setForeground(AppThemeColor.TEXT_DEFAULT); field.setCaretColor(AppThemeColor.TEXT_DEFAULT); field.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER,1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,3) + BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3) )); field.setBackground(AppThemeColor.HEADER); return field; } - public JTextField getTextField(String text, FontStyle style, float fontSize){ + + public JTextField getTextField(String text, FontStyle style, float fontSize) { JTextField textField = new JTextField(text); - if(style != null) { - textField.setFont(getSelectedFont(style).deriveFont(scale*fontSize)); + if (style != null) { + textField.setFont(getSelectedFont(style).deriveFont(scale * fontSize)); } textField.setForeground(AppThemeColor.TEXT_DEFAULT); textField.setCaretColor(AppThemeColor.TEXT_DEFAULT); textField.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER,1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,3) + BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3) )); textField.setBackground(AppThemeColor.HEADER); return textField; } - public JCheckBox getCheckBox(String tooltip){ + public JCheckBox getCheckBox(String tooltip) { JCheckBox checkBox = new JCheckBox(); checkBox.setFocusPainted(false); checkBox.setBackground(AppThemeColor.TRANSPARENT); @@ -459,7 +480,8 @@ public JCheckBox getCheckBox(String tooltip){ checkBox.addMouseListener(new TooltipMouseListener(tooltip)); return checkBox; } - public JCheckBox getCheckBox(boolean value){ + + public JCheckBox getCheckBox(boolean value) { JCheckBox checkBox = new JCheckBox(); checkBox.setSelected(value); // checkBox.setUI(new WindowsButtonUI()); @@ -467,20 +489,23 @@ public JCheckBox getCheckBox(boolean value){ checkBox.setBackground(AppThemeColor.TRANSPARENT); return checkBox; } - public JCheckBox getCheckBox(boolean value,String tooltip){ + + public JCheckBox getCheckBox(boolean value, String tooltip) { JCheckBox checkBox = this.getCheckBox(tooltip); checkBox.setSelected(value); return checkBox; } - public Font getFontByLang(String text,FontStyle style){ - if(style != null) { - if(isAscii(text)){ + + public Font getFontByLang(String text, FontStyle style) { + if (style != null) { + if (isAscii(text)) { return getSelectedFont(style); } } return DEFAULT_FONT; } - public JPanel getSliderSettingsPanel(JLabel titleLabel, JLabel countLabel, JSlider slider){ + + public JPanel getSliderSettingsPanel(JLabel titleLabel, JLabel countLabel, JSlider slider) { Dimension elementsSize = convertSize(new Dimension(160, 30)); Dimension countSize = convertSize(new Dimension(40, 30)); titleLabel.setPreferredSize(elementsSize); @@ -504,32 +529,36 @@ public JPanel getSliderSettingsPanel(JLabel titleLabel, JLabel countLabel, JSlid countGc.gridx = 1; sliderGc.gridx = 2; - panel.add(titleLabel,titleGc); - panel.add(countLabel,countGc); - panel.add(slider,sliderGc); + panel.add(titleLabel, titleGc); + panel.add(countLabel, countGc); + panel.add(slider, sliderGc); return panel; } - public JPanel getSettingsPanel(JLabel titleLabel, Component component){ - JPanel panel = getTransparentPanel(new GridLayout(1,2)); + + public JPanel getSettingsPanel(JLabel titleLabel, Component component) { + JPanel panel = getTransparentPanel(new GridLayout(1, 2)); panel.setBackground(AppThemeColor.ADR_BG); panel.add(titleLabel); panel.add(component); return panel; } - public Font getFont(FontStyle style, float fontSize){ + + public Font getFont(FontStyle style, float fontSize) { return getSelectedFont(style).deriveFont(scale * fontSize); } - public JComboBox getComboBox(String[] child){ + + public JComboBox getComboBox(String[] child) { JComboBox comboBox = new JComboBox<>(child); comboBox.setBackground(AppThemeColor.HEADER); comboBox.setForeground(AppThemeColor.TEXT_DEFAULT); - comboBox.setFont(BOLD_FONT.deriveFont(scale*16f)); - comboBox.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER,1)); + comboBox.setFont(BOLD_FONT.deriveFont(scale * 16f)); + comboBox.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); comboBox.setUI(MercuryComboBoxUI.createUI(comboBox)); return comboBox; } - public JSlider getSlider(int min, int max, int value){ - JSlider slider = new JSlider(JSlider.HORIZONTAL,min,max,value); + + public JSlider getSlider(int min, int max, int value) { + JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, value); slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); // slider.setPaintLabels(true); @@ -546,13 +575,14 @@ public void mouseDragged(MouseEvent e) { slider.setBackground(AppThemeColor.FRAME); return slider; } - public JSlider getSlider(int min, int max, int value, Color background){ - JSlider slider = this.getSlider(min,max,value); + + public JSlider getSlider(int min, int max, int value, Color background) { + JSlider slider = this.getSlider(min, max, value); slider.setBackground(background); return slider; } - public JScrollPane getVerticalContainer(JPanel container){ + public JScrollPane getVerticalContainer(JPanel container) { JScrollPane scrollPane = new JScrollPane(container); scrollPane.setBorder(null); scrollPane.setBackground(AppThemeColor.FRAME); @@ -566,47 +596,52 @@ public JScrollPane getVerticalContainer(JPanel container){ vBar.setUI(new MercuryScrollBarUI()); vBar.setPreferredSize(new Dimension(15, Integer.MAX_VALUE)); vBar.setUnitIncrement(3); - vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + vBar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); return scrollPane; } - public JPanel getTransparentPanel(LayoutManager layout){ + + public JPanel getTransparentPanel(LayoutManager layout) { JPanel panel = new JPanel(layout); panel.setBackground(AppThemeColor.TRANSPARENT); return panel; } - public JPanel getTransparentPanel(){ + + public JPanel getTransparentPanel() { JPanel panel = new JPanel(); panel.setBackground(AppThemeColor.TRANSPARENT); return panel; } - public JPanel getBorderedTransparentPanel(Border border, LayoutManager layout){ + public JPanel getBorderedTransparentPanel(Border border, LayoutManager layout) { JPanel panel = new JPanel(layout); panel.setBackground(AppThemeColor.TRANSPARENT); panel.setBorder(border); return panel; } - public ImageIcon getIcon(String iconPath, float size){ + + public ImageIcon getIcon(String iconPath, float size) { BufferedImage icon = null; try { BufferedImage buttonIcon = ImageIO.read(getClass().getClassLoader().getResource(iconPath)); - icon = Scalr.resize(buttonIcon, (int)(scale * size)); + icon = Scalr.resize(buttonIcon, (int) (scale * size)); } catch (IOException e) { log.error(e); } return new ImageIcon(icon); } - public ImageIcon getIcon(URL iconPath, float size){ + + public ImageIcon getIcon(URL iconPath, float size) { BufferedImage icon = null; try { BufferedImage buttonIcon = ImageIO.read(iconPath); - icon = Scalr.resize(buttonIcon, (int)(scale * size)); + icon = Scalr.resize(buttonIcon, (int) (scale * size)); } catch (IOException e) { log.error(e); } return new ImageIcon(icon); } - public ImageIcon getImage(String iconPath){ + + public ImageIcon getImage(String iconPath) { BufferedImage icon = null; try { icon = ImageIO.read(getClass().getClassLoader().getResource(iconPath)); @@ -615,17 +650,19 @@ public ImageIcon getImage(String iconPath){ } return new ImageIcon(icon); } - public Dimension convertSize(Dimension initialSize){ - return new Dimension((int)(initialSize.width * scale),(int)(initialSize.height*scale)); + + public Dimension convertSize(Dimension initialSize) { + return new Dimension((int) (initialSize.width * scale), (int) (initialSize.height * scale)); } - public JTextArea getSimpleTextArea(String text){ + + public JTextArea getSimpleTextArea(String text) { JTextArea area = new JTextArea(text); area.setEditable(false); area.setWrapStyleWord(true); area.setLineWrap(true); area.setBackground(AppThemeColor.TRANSPARENT); area.setBorder(null); - area.setFont(REGULAR_FONT.deriveFont(scale*16f)); + area.setFont(REGULAR_FONT.deriveFont(scale * 16f)); area.setForeground(AppThemeColor.TEXT_DEFAULT); return area; } @@ -638,7 +675,7 @@ public void setScale(float scale) { this.scale = scale; } - private Font getSelectedFont(FontStyle fontStyle){ + private Font getSelectedFont(FontStyle fontStyle) { switch (fontStyle) { case BOLD: return BOLD_FONT; @@ -651,8 +688,9 @@ private Font getSelectedFont(FontStyle fontStyle){ } return DEFAULT_FONT; } - private boolean isAscii(CharSequence sequence){ - if(sequence != null) { + + private boolean isAscii(CharSequence sequence) { + if (sequence != null) { for (int i = sequence.length() - 1; i >= 0; i--) { if (!matches(sequence.charAt(i))) { return false; @@ -661,6 +699,7 @@ private boolean isAscii(CharSequence sequence){ } return true; } + private boolean matches(char c) { return c <= '\u007f'; } @@ -670,33 +709,39 @@ public JPanel getJPanel(LayoutManager layoutManager) { panel.setBackground(AppThemeColor.FRAME); return panel; } - public JPanel getJPanel(LayoutManager layoutManager,Color bg) { + + public JPanel getJPanel(LayoutManager layoutManager, Color bg) { JPanel panel = new JPanel(layoutManager); panel.setBackground(bg); return panel; } - public JPanel wrapToSlide(JComponent panel){ + + public JPanel wrapToSlide(JComponent panel) { JPanel wrapper = this.getJPanel(new BorderLayout()); - wrapper.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); - wrapper.add(panel,BorderLayout.CENTER); + wrapper.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + wrapper.add(panel, BorderLayout.CENTER); return wrapper; } - public JPanel wrapToSlide(JComponent panel,Color bg){ + + public JPanel wrapToSlide(JComponent panel, Color bg) { JPanel wrapper = this.wrapToSlide(panel); wrapper.setBackground(bg); return wrapper; } - public JPanel wrapToSlide(JComponent panel,Color bg,int top,int left,int bottom,int righ){ - JPanel wrapper = this.wrapToSlide(panel,top,left,bottom,righ); + + public JPanel wrapToSlide(JComponent panel, Color bg, int top, int left, int bottom, int righ) { + JPanel wrapper = this.wrapToSlide(panel, top, left, bottom, righ); wrapper.setBackground(bg); return wrapper; } - public JPanel wrapToSlide(JComponent panel,int top,int left,int bottom,int right){ + + public JPanel wrapToSlide(JComponent panel, int top, int left, int bottom, int right) { JPanel wrapper = this.wrapToSlide(panel); - wrapper.setBorder(BorderFactory.createEmptyBorder(top,left,bottom,right)); + wrapper.setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right)); return wrapper; } - public JPanel wrapToAdrSlide(JComponent panel,int top,int left,int bottom,int right){ + + public JPanel wrapToAdrSlide(JComponent panel, int top, int left, int bottom, int right) { JPanel wrapper = new JPanel(new BorderLayout()) { @Override public void remove(Component comp) { @@ -709,8 +754,8 @@ public Component add(Component comp) { } }; wrapper.setBackground(AppThemeColor.FRAME); - wrapper.setBorder(BorderFactory.createEmptyBorder(top,left,bottom,right)); - wrapper.add(panel,BorderLayout.CENTER); + wrapper.setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right)); + wrapper.add(panel, BorderLayout.CENTER); return wrapper; } @@ -718,20 +763,21 @@ public JPopupMenu getContextPanel() { JPopupMenu contextMenu = new JPopupMenu(); contextMenu.setBackground(AppThemeColor.FRAME); contextMenu.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); - contextMenu.setFont(REGULAR_FONT.deriveFont(scale*16f)); + contextMenu.setFont(REGULAR_FONT.deriveFont(scale * 16f)); contextMenu.setForeground(AppThemeColor.TEXT_DEFAULT); return contextMenu; } public JMenuItem getMenuItem(String text) { JMenuItem menuItem = new JMenuItem(text); - menuItem.setFont(REGULAR_FONT.deriveFont(scale*16f)); + menuItem.setFont(REGULAR_FONT.deriveFont(scale * 16f)); menuItem.setForeground(AppThemeColor.TEXT_DEFAULT); return menuItem; } + public JMenuItem getMenu(String text) { JMenu menu = new JMenu(text); - menu.setFont(REGULAR_FONT.deriveFont(scale*16f)); + menu.setFont(REGULAR_FONT.deriveFont(scale * 16f)); menu.setForeground(AppThemeColor.TEXT_DEFAULT); return menu; } @@ -741,6 +787,7 @@ public JMenuItem getMenu(String text) { @AllArgsConstructor private class TooltipMouseListener extends MouseAdapter { private String tooltip; + @Override public void mouseEntered(MouseEvent e) { MercuryStoreCore.tooltipSubject.onNext(tooltip); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java index 6a5925c5..c34366a3 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java @@ -10,9 +10,11 @@ //todo generic for components constructor public class ControlsFactory { private ComponentsFactory componentsFactory; - public ControlsFactory(@NonNull ComponentsFactory factory){ + + public ControlsFactory(@NonNull ComponentsFactory factory) { this.componentsFactory = factory; } + public void getInviteButton(float iconSize) { JButton invite = componentsFactory.getIconButton( "app/invite.png", diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/MercuryTabbedPane.java b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/MercuryTabbedPane.java index 3f501b67..406aa98f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/fields/MercuryTabbedPane.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/fields/MercuryTabbedPane.java @@ -8,17 +8,18 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.*; +import java.util.ArrayList; import java.util.List; -public class MercuryTabbedPane extends JPanel{ +public class MercuryTabbedPane extends JPanel { private ComponentsFactory componentsFactory; private List headerButtons; private JFrame owner; private JPanel headersPanel; private JPanel tabPanel; - public MercuryTabbedPane(JFrame owner){ + + public MercuryTabbedPane(JFrame owner) { this.owner = owner; this.setBackground(AppThemeColor.TRANSPARENT); this.setLayout(new BorderLayout()); @@ -26,26 +27,26 @@ public MercuryTabbedPane(JFrame owner){ headerButtons = new ArrayList<>(); componentsFactory = new ComponentsFactory(); headersPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - headersPanel.setBorder(BorderFactory.createEmptyBorder(0,0,-5,0)); + headersPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, -5, 0)); tabPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - this.add(headersPanel,BorderLayout.PAGE_START); - this.add(tabPanel,BorderLayout.CENTER); + this.add(headersPanel, BorderLayout.PAGE_START); + this.add(tabPanel, BorderLayout.CENTER); } - public void addTab(String title, JPanel component){ + public void addTab(String title, JPanel component) { component.setBackground(AppThemeColor.SLIDE_BG); JButton tabButton = componentsFactory.getButton( FontStyle.BOLD, AppThemeColor.TRANSPARENT, - BorderFactory.createMatteBorder(1,1,0,1,AppThemeColor.HEADER), - title,15f); - tabButton.setPreferredSize(new Dimension(tabButton.getPreferredSize().width + 14,30)); + BorderFactory.createMatteBorder(1, 1, 0, 1, AppThemeColor.HEADER), + title, 15f); + tabButton.setPreferredSize(new Dimension(tabButton.getPreferredSize().width + 14, 30)); tabButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { tabButton.setBackground(AppThemeColor.SLIDE_BG); headerButtons.forEach(button -> { @@ -60,9 +61,9 @@ public void mousePressed(MouseEvent e) { } } }); - if(headerButtons.size() == 0){ + if (headerButtons.size() == 0) { tabButton.setBackground(AppThemeColor.SLIDE_BG); - tabPanel.add(component,BorderLayout.CENTER); + tabPanel.add(component, BorderLayout.CENTER); } headerButtons.add(tabButton); 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 8afeffa5..ccc027d1 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,DEFAULT + 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 b1aec1ac..3096b491 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 @@ -12,8 +12,9 @@ public static MercuryComboBoxUI createUI(JComponent c) { return new MercuryComboBoxUI(); } - @Override protected JButton createArrowButton() { - return new ComponentsFactory().getIconButton("app/expand-combobox.png",16, AppThemeColor.HEADER,"Expand."); + @Override + protected JButton createArrowButton() { + 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 c37eb2c0..fb93048f 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 @@ -13,6 +13,7 @@ public class MercuryScrollBarUI extends BasicScrollBarUI { public MercuryScrollBarUI(Color color) { this.scrollColor = color; } + public MercuryScrollBarUI() { this.scrollColor = AppThemeColor.SCROLL_BAR; } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java index 21c55380..00e12e67 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java @@ -27,13 +27,13 @@ public CollapsiblePanel(String title, InnerPanel innerPanel, JFrame owner, boole this.componentsFactory = new ComponentsFactory(); this.setBackground(AppThemeColor.TRANSPARENT); - this.setBorder(BorderFactory.createMatteBorder(1,0,1,0,AppThemeColor.BORDER)); + this.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, AppThemeColor.BORDER)); this.setLayout(new BorderLayout()); createUI(); } private void createUI() { - JPanel header = componentsFactory.getBorderedTransparentPanel(BorderFactory.createEmptyBorder(-4,0,-4,0),new FlowLayout(FlowLayout.LEFT)); + JPanel header = componentsFactory.getBorderedTransparentPanel(BorderFactory.createEmptyBorder(-4, 0, -4, 0), new FlowLayout(FlowLayout.LEFT)); header.add(getExpandButton()); header.add(componentsFactory.getTextLabel(title)); @@ -42,16 +42,17 @@ private void createUI() { this.add(header, BorderLayout.PAGE_START); this.add(innerPanel, BorderLayout.CENTER); } - private JButton getExpandButton(){ - String iconPath = expand ? "app/collapse.png":"app/expand.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 16,AppThemeColor.FRAME_ALPHA, TooltipConstants.EXPAND_COLLAPSE); + + private JButton getExpandButton() { + String iconPath = expand ? "app/collapse.png" : "app/expand.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath, 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.EXPAND_COLLAPSE); expandButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(!innerPanel.isVisible()) { + if (!innerPanel.isVisible()) { expandButton.setIcon(componentsFactory.getIcon("app/collapse.png", 16)); innerPanel.setVisible(true); - }else { + } else { expandButton.setIcon(componentsFactory.getIcon("app/expand.png", 16)); innerPanel.setVisible(false); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/TransparentPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/TransparentPanel.java index be391608..ee19ade1 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/TransparentPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/TransparentPanel.java @@ -13,6 +13,7 @@ public abstract class TransparentPanel extends JPanel { protected ComponentsFactory componentsFactory; protected VerticalScrollContainer verticalScrollContainer; + public TransparentPanel() { this.componentsFactory = new ComponentsFactory(); @@ -21,7 +22,7 @@ public TransparentPanel() { this.setBorder(null); this.verticalScrollContainer = new VerticalScrollContainer(); verticalScrollContainer.setBackground(AppThemeColor.SLIDE_BG); - verticalScrollContainer.setLayout(new BoxLayout(verticalScrollContainer,BoxLayout.Y_AXIS)); + verticalScrollContainer.setLayout(new BoxLayout(verticalScrollContainer, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(verticalScrollContainer); @@ -42,9 +43,9 @@ public void mouseWheelMoved(MouseWheelEvent e) { vBar.setUI(new MercuryScrollBarUI()); vBar.setPreferredSize(new Dimension(14, Integer.MAX_VALUE)); vBar.setUnitIncrement(3); - vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,2)); + vBar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 2)); vBar.addAdjustmentListener(e -> repaint()); - this.add(scrollPane,BorderLayout.CENTER); + this.add(scrollPane, BorderLayout.CENTER); } } 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 fde831a0..b5feb387 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 @@ -35,7 +35,7 @@ public ChatMessagePanel( this.message = message; this.componentsFactory = componentsFactory; - this.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); + this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); this.setBackground(AppThemeColor.TRANSPARENT); onViewInit(); } @@ -43,7 +43,7 @@ public ChatMessagePanel( @Override public void onViewInit() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); - root.setBorder(BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.HEADER)); + root.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, AppThemeColor.HEADER)); root.setBackground(AppThemeColor.SLIDE_BG); JPanel miscPanel = componentsFactory.getTransparentPanel(new BorderLayout()); @@ -53,7 +53,7 @@ public void onViewInit() { quickResponse.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { MercuryStoreCore.chatCommandSubject.onNext("@" + nickName + " " + scannerService.get().getResponseMessage()); } } @@ -62,7 +62,7 @@ public void mousePressed(MouseEvent e) { openChat.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { MercuryStoreCore.openChatSubject.onNext(nickName); } } @@ -75,7 +75,7 @@ public void mousePressed(MouseEvent e) { TextAlignment.LEFTOP, 15f, nickName); - nicknameLabel.setPreferredSize(new Dimension(75,nicknameLabel.getPreferredSize().height)); + nicknameLabel.setPreferredSize(new Dimension(75, nicknameLabel.getPreferredSize().height)); nicknameLabel.setBorder(null); quickResponse.setBorder(null); openChat.setBorder(null); @@ -85,17 +85,17 @@ public void mousePressed(MouseEvent e) { JPanel nicknamePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); nicknamePanel.add(nicknameLabel); - miscPanel.add(operationsPanel,BorderLayout.LINE_START); - miscPanel.add(nicknamePanel,BorderLayout.CENTER); - nicknamePanel.setMaximumSize(new Dimension(75,30)); + miscPanel.add(operationsPanel, BorderLayout.LINE_START); + miscPanel.add(nicknamePanel, BorderLayout.CENTER); + nicknamePanel.setMaximumSize(new Dimension(75, 30)); JLabel messageLabel = new JLabel(message); messageLabel.setBackground(AppThemeColor.TRANSPARENT); messageLabel.setBorder(null); - messageLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR,16f)); + messageLabel.setFont(componentsFactory.getFont(FontStyle.REGULAR, 16f)); messageLabel.setForeground(AppThemeColor.TEXT_DEFAULT); - root.add(miscPanel,BorderLayout.LINE_START); + root.add(miscPanel, BorderLayout.LINE_START); root.add(messageLabel, BorderLayout.CENTER); - this.add(root,BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatScannerController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatScannerController.java index 5f5aed8b..2b47dcf0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatScannerController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/chat/ChatScannerController.java @@ -5,6 +5,8 @@ */ public interface ChatScannerController { void clearChat(); + void enableSound(); + void setupChunks(); } 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 914e55ab..becc9378 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 @@ -4,7 +4,6 @@ import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class HtmlMessageBuilder { @@ -17,6 +16,7 @@ public HtmlMessageBuilder() { /** * Building HTML equivalent message with highlighting matched chunks + * * @param message source message * @return html equivalent */ @@ -25,8 +25,8 @@ public String build(String message) { stringBuilder.append(""); this.stubMessage = message; this.chunkStrings.forEach(it -> { - if(StringUtils.containsIgnoreCase(message,it)){ - this.stubMessage = stubMessage.replaceAll("(?i)" + it,"" + it + ""); + if (StringUtils.containsIgnoreCase(message, it)) { + this.stubMessage = stubMessage.replaceAll("(?i)" + it, "" + it + ""); } }); stringBuilder.append(this.stubMessage); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemCell.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemCell.java index 20503413..7c613354 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemCell.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemCell.java @@ -7,7 +7,7 @@ @Data @AllArgsConstructor -public class ItemCell{ +public class ItemCell { private int x; private int y; private JPanel cell; 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 c9d7dbcc..5d149068 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanel.java @@ -1,13 +1,13 @@ package com.mercury.platform.ui.components.panel.grid; import com.mercury.platform.shared.config.descriptor.StashTabDescriptor; -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.ItemTradeNotificationDescriptor; import com.mercury.platform.ui.components.ComponentsFactory; 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; +import com.mercury.platform.ui.misc.TooltipConstants; import javax.swing.*; import java.awt.*; @@ -24,7 +24,7 @@ public class ItemInfoPanel extends JPanel implements ViewInit { private ItemInfoPanelController controller; - public ItemInfoPanel(ItemTradeNotificationDescriptor 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; @@ -44,25 +44,25 @@ public void onViewInit() { 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); + nicknamePanel.setBorder(BorderFactory.createEmptyBorder(-6, 0, -6, 0)); + this.add(nicknamePanel, BorderLayout.CENTER); JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME, "Close"); - hideButton.addActionListener((action)-> { + hideButton.addActionListener((action) -> { controller.hidePanel(); }); - this.add(hideButton,BorderLayout.LINE_END); + this.add(hideButton, BorderLayout.LINE_END); 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)); - if(stashTabDescriptor.isUndefined()) { + tabInfoPanel.setBorder(BorderFactory.createEmptyBorder(-8, 0, -6, 0)); + if (stashTabDescriptor.isUndefined()) { JCheckBox isItQuad = componentsFactory.getCheckBox(TooltipConstants.IS_IT_QUAD); - isItQuad.setPreferredSize(new Dimension(16,16)); + isItQuad.setPreferredSize(new Dimension(16, 16)); tabInfoPanel.add(isItQuad); - isItQuad.addActionListener(action->{ + isItQuad.addActionListener(action -> { stashTabDescriptor.setQuad(isItQuad.isSelected()); if (timer != null && timer.isRunning()) { timer.stop(); @@ -72,10 +72,11 @@ public void onViewInit() { }); } - this.add(tabInfoPanel,BorderLayout.PAGE_END); + this.add(tabInfoPanel, BorderLayout.PAGE_END); this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); } - private void setupMouseOverListener(){ + + private void setupMouseOverListener() { this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { @@ -88,7 +89,7 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { - if(!getBounds().contains(e.getPoint())) { + if (!getBounds().contains(e.getPoint())) { setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); } timer = new Timer(1500, null); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelController.java index 2551e00c..45693036 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/ItemInfoPanelController.java @@ -5,5 +5,6 @@ //todo public interface ItemInfoPanelController { void hidePanel(); + void changeTabType(@NonNull ItemInfoPanel panel); } 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 bf0ad91b..385d4897 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 @@ -7,9 +7,11 @@ public class ItemInfoPanelControllerImpl implements ItemInfoPanelController { private ItemTradeNotificationDescriptor message; + public ItemInfoPanelControllerImpl(@NonNull ItemTradeNotificationDescriptor message) { this.message = message; } + @Override public void hidePanel() { MercuryStoreUI.closeGridItemSubject.onNext(message); 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 066d9346..39371bd3 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,7 +1,7 @@ package com.mercury.platform.ui.components.panel.grid; -import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import com.mercury.platform.shared.config.descriptor.StashTabDescriptor; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.panel.misc.ViewInit; import com.mercury.platform.ui.frame.movable.ItemsGridFrame; @@ -21,7 +21,7 @@ public class ItemsGridPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; private List defaultCells; private List quadCells; - private Map tabButtons; + private Map tabButtons; private StashTabsContainer stashTabsContainer; private JPanel navBar; @@ -37,7 +37,8 @@ public ItemsGridPanel() { stashTabsContainer = new StashTabsContainer(); onViewInit(); } - public ItemsGridPanel(@NonNull ComponentsFactory factory){ + + public ItemsGridPanel(@NonNull ComponentsFactory factory) { super(new BorderLayout()); this.componentsFactory = factory; defaultCells = new ArrayList<>(); @@ -52,7 +53,7 @@ public void onViewInit() { this.setBackground(AppThemeColor.TRANSPARENT); this.setBorder(null); - defaultGrid = componentsFactory.getTransparentPanel(new GridLayout(12,12)); + defaultGrid = componentsFactory.getTransparentPanel(new GridLayout(12, 12)); defaultGrid.setBorder(null); for (int y = 0; y < 12; y++) { for (int x = 0; x < 12; x++) { @@ -61,7 +62,7 @@ public void onViewInit() { defaultGrid.add(gridCell.getCell()); } } - quadTabGrid = componentsFactory.getTransparentPanel(new GridLayout(24,24)); + quadTabGrid = componentsFactory.getTransparentPanel(new GridLayout(24, 24)); quadTabGrid.setBorder(null); for (int y = 0; y < 24; y++) { for (int x = 0; x < 24; x++) { @@ -72,34 +73,34 @@ public void onViewInit() { } JPanel rightPanel = componentsFactory.getTransparentPanel(new BorderLayout()); rightPanel.setBackground(AppThemeColor.TRANSPARENT); - rightPanel.setPreferredSize(new Dimension(18,668)); + rightPanel.setPreferredSize(new Dimension(18, 668)); JPanel downPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - downPanel.setBorder(BorderFactory.createEmptyBorder(-10,0,0,0)); + downPanel.setBorder(BorderFactory.createEmptyBorder(-10, 0, 0, 0)); downPanel.setBackground(AppThemeColor.TRANSPARENT); - downPanel.setPreferredSize(new Dimension(661,16)); + downPanel.setPreferredSize(new Dimension(661, 16)); - this.add(getHeaderPanel(),BorderLayout.PAGE_START); + this.add(getHeaderPanel(), BorderLayout.PAGE_START); this.add(defaultGrid, BorderLayout.CENTER); - this.add(rightPanel,BorderLayout.LINE_END); - this.add(downPanel,BorderLayout.PAGE_END); + this.add(rightPanel, BorderLayout.LINE_END); + this.add(downPanel, BorderLayout.PAGE_END); this.setPreferredSize(this.getMaximumSize()); } - public void add(@NonNull ItemTradeNotificationDescriptor 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(); int y = message.getTop(); StashTabDescriptor stashTabDescriptor; - if(stashTabsContainer.containsTab(message.getTabName())) { + if (stashTabsContainer.containsTab(message.getTabName())) { stashTabDescriptor = stashTabsContainer.getStashTab(message.getTabName()); - }else { - stashTabDescriptor = new StashTabDescriptor(message.getTabName(),false,true); + } else { + stashTabDescriptor = new StashTabDescriptor(message.getTabName(), false, true); } Optional cellByCoordinates = getCellByCoordinates(stashTabDescriptor, x, y); - if(cellByCoordinates.isPresent()) { + if (cellByCoordinates.isPresent()) { ItemInfoPanel cellHeader = createGridItem(message, cellByCoordinates.get(), stashTabDescriptor); - if(controller != null){ + if (controller != null) { cellHeader.setController(controller); } navBar.add(cellHeader); @@ -108,10 +109,12 @@ public void add(@NonNull ItemTradeNotificationDescriptor message, ItemInfoPanelC } } } - public void remove(@NonNull ItemTradeNotificationDescriptor message){ + + public void remove(@NonNull ItemTradeNotificationDescriptor message) { closeGridItem(message); } - public void changeTabType(@NonNull ItemInfoPanel itemInfoPanel){ + + public void changeTabType(@NonNull ItemInfoPanel itemInfoPanel) { ItemCell itemCell = itemInfoPanel.getItemCell(); int x = itemCell.getX(); int y = itemCell.getY(); @@ -119,31 +122,33 @@ public void changeTabType(@NonNull ItemInfoPanel itemInfoPanel){ cellByCoordinates.ifPresent(itemCell1 -> itemInfoPanel.setCell(itemCell1.getCell())); MercuryStoreUI.repaintSubject.onNext(ItemsGridFrame.class); } - public int getActiveTabsCount(){ + + public int getActiveTabsCount() { return navBar.getComponentCount(); } - private ItemCell getGridCell(int x, int y){ + + private ItemCell getGridCell(int x, int y) { JPanel cellPanel = new JPanel(); cellPanel.setOpaque(true); cellPanel.setBackground(AppThemeColor.TRANSPARENT); - return new ItemCell(x+1,y+1,cellPanel); + return new ItemCell(x + 1, y + 1, cellPanel); } - private JPanel getHeaderPanel(){ + private JPanel getHeaderPanel() { JPanel root = componentsFactory.getTransparentPanel(); - root.setLayout(new BoxLayout(root,BoxLayout.Y_AXIS)); + root.setLayout(new BoxLayout(root, BoxLayout.Y_AXIS)); navBar = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - navBar.setBorder(BorderFactory.createEmptyBorder(20,0,26,0)); + navBar.setBorder(BorderFactory.createEmptyBorder(20, 0, 26, 0)); root.add(navBar); return root; } - private Optional getCellByCoordinates(@NonNull StashTabDescriptor tab, int x, int y){ + private Optional getCellByCoordinates(@NonNull StashTabDescriptor tab, int x, int y) { Optional targetCell; - if(x > 12 || y > 12) { + if (x > 12 || y > 12) { tab.setQuad(true); } - if(tab.isQuad()){ + if (tab.isQuad()) { targetCell = quadCells .stream() .filter(cell -> (cell.getX() == x && cell.getY() == y)) @@ -157,29 +162,30 @@ private Optional getCellByCoordinates(@NonNull StashTabDescriptor tab, return targetCell; } - private ItemInfoPanel createGridItem(@NonNull ItemTradeNotificationDescriptor message, @NonNull ItemCell cell, @NonNull StashTabDescriptor stashTabDescriptor){ - ItemInfoPanel itemInfoPanel = new ItemInfoPanel(message,cell, stashTabDescriptor,componentsFactory); + 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() { @Override public void mouseEntered(MouseEvent e) { - if(stashTabDescriptor.isQuad()){ - remove(((BorderLayout)getLayout()).getLayoutComponent(BorderLayout.CENTER)); - add(quadTabGrid,BorderLayout.CENTER); - }else { - remove(((BorderLayout)getLayout()).getLayoutComponent(BorderLayout.CENTER)); - add(defaultGrid,BorderLayout.CENTER); + if (stashTabDescriptor.isQuad()) { + remove(((BorderLayout) getLayout()).getLayoutComponent(BorderLayout.CENTER)); + add(quadTabGrid, BorderLayout.CENTER); + } else { + remove(((BorderLayout) getLayout()).getLayoutComponent(BorderLayout.CENTER)); + add(defaultGrid, BorderLayout.CENTER); } MercuryStoreUI.repaintSubject.onNext(ItemsGridFrame.class); } }); return itemInfoPanel; } + private void closeGridItem(@NonNull ItemTradeNotificationDescriptor message) { String nickname = message.getWhisperNickname(); ItemInfoPanel itemInfoPanel = tabButtons.get(nickname + message.getTabName()); if (itemInfoPanel != null) { - if(itemInfoPanel.getStashTabDescriptor().isUndefined()){ + if (itemInfoPanel.getStashTabDescriptor().isUndefined()) { itemInfoPanel.getStashTabDescriptor().setUndefined(false); stashTabsContainer.addTab(itemInfoPanel.getStashTabDescriptor()); stashTabsContainer.save(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java index 9c1c6a27..b4b6a38e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/grid/StashTabsContainer.java @@ -6,29 +6,36 @@ import com.mercury.platform.shared.store.MercuryStoreCore; import java.util.List; + public class StashTabsContainer { private ListConfigurationService stashTabConfig; + public StashTabsContainer() { this.stashTabConfig = Configuration.get().stashTabConfiguration(); } - public void addTab(StashTabDescriptor tab){ + + public void addTab(StashTabDescriptor tab) { this.stashTabConfig.getEntities().add(tab); this.save(); } - public void save(){ + + public void save() { MercuryStoreCore.saveConfigSubject.onNext(true); } public List getStashTabDescriptors() { return this.stashTabConfig.getEntities(); } - public boolean containsTab(String tabTitle){ + + public boolean containsTab(String tabTitle) { return this.stashTabConfig.getEntities().stream().anyMatch(tab -> tab.getTitle().equals(tabTitle)); } - public StashTabDescriptor getStashTab(String tabTitle){ + + public StashTabDescriptor getStashTab(String tabTitle) { return this.stashTabConfig.getEntities().stream().filter(tab -> tab.getTitle().equals(tabTitle)).findFirst().get(); } - public void removeTab(StashTabDescriptor tab){ + + public void removeTab(StashTabDescriptor tab) { this.stashTabConfig.getEntities().remove(tab); this.save(); } 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 775fa19f..ad934df5 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 @@ -26,25 +26,25 @@ public void onViewInit() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); JButton hideButton = componentsFactory.getIconButton("app/close.png", 12, AppThemeColor.FRAME, "Dismiss"); - hideButton.addActionListener((action)->{ + hideButton.addActionListener((action) -> { stashTabDescriptor.setUndefined(true); MercuryStoreUI.dismissTabInfoPanelSubject.onNext(this); }); JPanel tabInfoPanel = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); JLabel tabLabel = componentsFactory.getTextLabel(stashTabDescriptor.getTitle()); tabLabel.setBorder(null); - tabLabel.setFont(componentsFactory.getFont(FontStyle.BOLD,15f)); + tabLabel.setFont(componentsFactory.getFont(FontStyle.BOLD, 15f)); tabInfoPanel.add(tabLabel); JCheckBox isItQuad = componentsFactory.getCheckBox("Is it Quad?"); isItQuad.setSelected(stashTabDescriptor.isQuad()); - isItQuad.setPreferredSize(new Dimension(16,16)); - isItQuad.addActionListener(action->{ + isItQuad.setPreferredSize(new Dimension(16, 16)); + isItQuad.addActionListener(action -> { stashTabDescriptor.setQuad(isItQuad.isSelected()); }); tabInfoPanel.add(isItQuad); tabInfoPanel.add(hideButton); - this.add(tabInfoPanel,BorderLayout.PAGE_END); + this.add(tabInfoPanel, BorderLayout.PAGE_END); this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1)); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/MercuryAppLoadingUI.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/MercuryAppLoadingUI.java index bb3d7cda..923a9156 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/MercuryAppLoadingUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/misc/MercuryAppLoadingUI.java @@ -14,14 +14,14 @@ import java.awt.image.BufferedImage; import java.io.IOException; -public class MercuryAppLoadingUI extends ComponentUI{ +public class MercuryAppLoadingUI extends ComponentUI { private MercuryLoading component; public MercuryAppLoadingUI(MercuryLoading component) { this.component = component; } - public ImageIcon getIcon(String iconPath, int size){ + public ImageIcon getIcon(String iconPath, int size) { BufferedImage icon = null; try { BufferedImage buttonIcon = ImageIO.read(getClass().getClassLoader().getResource(iconPath)); @@ -31,7 +31,9 @@ public ImageIcon getIcon(String iconPath, int size){ } return new ImageIcon(icon); } - @Override public void paint(Graphics g, JComponent c) { + + @Override + public void paint(Graphics g, JComponent c) { if (component.getWidth() == 0) { return; } 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 index 118841f7..9af2af1c 100644 --- 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 @@ -14,41 +14,42 @@ 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); + 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); + 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) { + 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())); + + 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(){ + 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,"(")); + 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))); + 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)); + 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/CurrencyOutNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/CurrencyOutNotificationPanel.java index ba8c3f0c..8c8cc7cb 100644 --- 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 @@ -14,33 +14,34 @@ public class CurrencyOutNotificationPanel extends OutgoingNotificationPanel { +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); + 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); + this.add(sourceLabel, BorderLayout.CENTER); } - private JPanel getHeader(){ + + private JPanel getHeader() { JPanel root = new JPanel(new BorderLayout()); root.setBackground(AppThemeColor.MSG_HEADER); - root.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + 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); + 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)); + 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 -> { @@ -43,10 +44,11 @@ private JPanel getHeader(){ openChatButton.addActionListener(e -> controller.performOpenChat()); interactionPanel.add(reloadButton); interactionPanel.add(openChatButton); - opPanel.add(interactionPanel,BorderLayout.CENTER); - root.add(opPanel,BorderLayout.LINE_END); + 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 index 6db610e3..516f231a 100644 --- 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 @@ -2,7 +2,6 @@ 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; @@ -17,14 +16,14 @@ 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.Collections; import java.util.List; +import java.util.Objects; -public abstract class IncomingNotificationPanel extends NotificationPanel{ +public abstract class IncomingNotificationPanel extends NotificationPanel { private PlainConfigurationService config; private PlainConfigurationService hotKeysConfig; private JPanel messagePanel; @@ -32,46 +31,48 @@ public abstract class IncomingNotificationPanel { @@ -81,7 +82,7 @@ private JPanel getHeader(){ JButton kickButton = componentsFactory.getIconButton("app/kick.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.KICK); kickButton.addActionListener(e -> { this.controller.performKick(); - if(this.config.get().isDismissAfterKick()){ + if (this.config.get().isDismissAfterKick()) { this.controller.performHide(); } }); @@ -91,16 +92,16 @@ private JPanel getHeader(){ }); JButton showChatButton = componentsFactory.getIconButton("app/chat_history.png", 15, AppThemeColor.MSG_HEADER, TooltipConstants.SWITCH_CHAT); showChatButton.addActionListener(e -> { - if(this.chatPanel.isVisible()){ + 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.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); + this.add(this.chatPanel, BorderLayout.CENTER); } SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); }); @@ -120,19 +121,19 @@ private JPanel getHeader(){ interactionPanel.add(hideButton); this.interactButtonMap.clear(); - 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); + 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(); - opPanel.add(timePanel,BorderLayout.CENTER); - opPanel.add(interactionPanel,BorderLayout.LINE_END); + opPanel.add(timePanel, BorderLayout.CENTER); + opPanel.add(interactionPanel, BorderLayout.LINE_END); - root.add(opPanel,BorderLayout.LINE_END); + root.add(opPanel, BorderLayout.LINE_END); return root; } @@ -145,13 +146,13 @@ protected void updateHotKeyPool() { .stream() .filter(it -> it.getType().equals(type)) .findAny().orElse(null); - if(!hotKeyPair.getDescriptor().getTitle().equals("...")) { + if (!hotKeyPair.getDescriptor().getTitle().equals("...")) { this.hotKeysPool.put(hotKeyPair.getDescriptor(), button); } }); this.initResponseButtonsPanel(); Window windowAncestor = SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this); - if(windowAncestor != null) { + if (windowAncestor != null) { windowAncestor.pack(); } } @@ -160,10 +161,10 @@ protected void updateHotKeyPool() { 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(); - } + if (this.data.getWhisperNickname().equals(message.getNickName())) { + this.chatContainer.add(this.componentsFactory.getTextLabel((message.isIncoming() ? "From: " : "To: ") + message.getMessage())); + SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); + } }); } @@ -172,14 +173,16 @@ public void onViewDestroy() { super.onViewDestroy(); this.chatSubscription.unsubscribe(); } - private JPanel getChatPanel(){ + + private JPanel getChatPanel() { this.chatContainer = new VerticalScrollContainer(); - this.chatContainer.setLayout(new BoxLayout(this.chatContainer,BoxLayout.Y_AXIS)); + 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); + 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(){ + + protected JPanel getForPanel() { JPanel forPanel = new JPanel(new BorderLayout()); // forPanel.setPreferredSize(new Dimension((int) (110 * this.componentsFactory.getScale()),(int) (36 * this.componentsFactory.getScale()))); forPanel.setBackground(AppThemeColor.MSG_HEADER); @@ -189,90 +192,96 @@ protected JPanel getForPanel(){ TextAlignment.CENTER, 18f, "=>"); - forPanel.add(separator,BorderLayout.CENTER); + forPanel.add(separator, BorderLayout.CENTER); separator.setHorizontalAlignment(SwingConstants.CENTER); - JPanel currencyPanel = this.getCurrencyPanel(this.data.getCurCount(),this.data.getCurrency()); - if(currencyPanel != null) { + 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){ + + protected JPanel getCurrencyPanel(Double curCount, String curIconPath) { String curCountStr = " "; - if(curCount > 0) { + if (curCount > 0) { curCountStr = curCount % 1 == 0 ? String.valueOf(curCount.intValue()) : String.valueOf(curCount); } - if(!Objects.equals(curCountStr, "") && curIconPath != null) { + if (!Objects.equals(curCountStr, "") && curIconPath != null) { JLabel currencyLabel = componentsFactory.getIconLabel("currency/" + curIconPath + ".png", 26); - JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT,4,0)); - curPanel.setPreferredSize(new Dimension((int)(this.componentsFactory.getScale() * 66),(int)(this.componentsFactory.getScale() * 26))); + JPanel curPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 4, 0)); + curPanel.setPreferredSize(new Dimension((int) (this.componentsFactory.getScale() * 66), (int) (this.componentsFactory.getScale() * 26))); curPanel.setBackground(AppThemeColor.MSG_HEADER); - curPanel.add(this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER,17f,null, curCountStr)); + 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(){ + + protected JLabel getOfferLabel() { String offer = this.data.getOffer(); - if(offer != null && offer.trim().length() > 0) { + 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(){ + + 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); - button.setBorder( BorderFactory.createCompoundBorder( + buttonsConfig.forEach((buttonConfig) -> { + JButton button = componentsFactory.getBorderedButton(buttonConfig.getTitle(), 16f, AppThemeColor.RESPONSE_BUTTON, AppThemeColor.RESPONSE_BUTTON_BORDER, AppThemeColor.RESPONSE_BUTTON); + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON_BORDER, 1), - BorderFactory.createMatteBorder(3,9,3,9, AppThemeColor.RESPONSE_BUTTON) + BorderFactory.createMatteBorder(3, 9, 3, 9, AppThemeColor.RESPONSE_BUTTON) )); button.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { - button.setBorder( BorderFactory.createCompoundBorder( + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), - BorderFactory.createMatteBorder(3,9,3,9, AppThemeColor.RESPONSE_BUTTON) + BorderFactory.createMatteBorder(3, 9, 3, 9, AppThemeColor.RESPONSE_BUTTON) )); } @Override public void mouseExited(MouseEvent e) { - button.setBorder( BorderFactory.createCompoundBorder( + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON_BORDER, 1), - BorderFactory.createMatteBorder(3,9,3,9, AppThemeColor.RESPONSE_BUTTON) + BorderFactory.createMatteBorder(3, 9, 3, 9, AppThemeColor.RESPONSE_BUTTON) )); } }); button.addActionListener(action -> { - button.setBorder( BorderFactory.createCompoundBorder( + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), - BorderFactory.createMatteBorder(3,9,3,9, AppThemeColor.RESPONSE_BUTTON) + BorderFactory.createMatteBorder(3, 9, 3, 9, AppThemeColor.RESPONSE_BUTTON) )); }); button.addActionListener(e -> { this.controller.performResponse(buttonConfig.getResponseText()); - if(buttonConfig.isClose()){ + if (buttonConfig.isClose()) { this.controller.performHide(); } }); - this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(),button); + this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(), button); this.responseButtonsPanel.add(button); }); } - private String getNicknameText(){ + + private String getNicknameText() { String whisperNickname = data.getWhisperNickname(); String result = whisperNickname + ":"; - if(this.config.get().isShowLeague()) { + if (this.config.get().isShowLeague()) { if (data.getLeague() != null) { String league = data.getLeague().trim(); if (league.length() == 0) { @@ -293,18 +302,19 @@ private String getNicknameText(){ } return result; } - private JButton getExpandButton(){ + + private JButton getExpandButton() { String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); expandButton.addActionListener(action -> { - if(this.messagePanel.isVisible()){ + if (this.messagePanel.isVisible()) { this.messagePanel.setVisible(false); this.responseButtonsPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); - }else { + 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)); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); } SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); }); 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 index 9255c947..5e05bdad 100644 --- 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 @@ -3,17 +3,16 @@ 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(); @@ -23,7 +22,7 @@ protected JPanel getMessagePanel() { JButton itemButton = componentsFactory.getButton( FontStyle.BOLD, AppThemeColor.BUTTON, - BorderFactory.createEmptyBorder(0,4,0,2), + BorderFactory.createEmptyBorder(0, 4, 0, 2), this.data.getItemName(), 16f); itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT); @@ -34,7 +33,7 @@ protected JPanel getMessagePanel() { itemButton.addActionListener(action -> { this.controller.showITH(); }); - this.labelsPanel.add(itemButton,BorderLayout.CENTER); + this.labelsPanel.add(itemButton, BorderLayout.CENTER); JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.FRAME, TooltipConstants.OPEN_CHAT); openChatButton.addActionListener(e -> controller.performOpenChat()); @@ -44,16 +43,16 @@ protected JPanel getMessagePanel() { buttons.add(openChatButton); JLabel offerLabel = this.getOfferLabel(); - if(offerLabel != null) { + if (offerLabel != null) { this.labelsPanel.add(offerLabel, BorderLayout.PAGE_END); } - labelsPanel.add(buttons,BorderLayout.LINE_END); + labelsPanel.add(buttons, BorderLayout.LINE_END); return labelsPanel; } @Override public void setDuplicate(boolean duplicate) { - if(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); @@ -66,12 +65,12 @@ public void setDuplicate(boolean duplicate) { @Override protected JButton getStillInterestedButton() { JButton stillIntButton = componentsFactory.getIconButton("app/still-interesting.png", 14, AppThemeColor.FRAME, TooltipConstants.STILL_INTERESTED); - stillIntButton.addActionListener(action-> { + stillIntButton.addActionListener(action -> { String curCount = this.data.getCurCount().toString(); String responseText = "Hi, are you still interested in "; - if(this.data.getCurrency().equals("???")){ + if (this.data.getCurrency().equals("???")) { responseText += this.data.getItemName() + "?"; - }else { + } else { responseText += this.data.getItemName() + " for " + curCount + " " + this.data.getCurrency() + "?"; } 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 index a227f819..84f3cc6e 100644 --- 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 @@ -15,7 +15,7 @@ protected JPanel getContentPanel() { JButton itemButton = componentsFactory.getButton( FontStyle.BOLD, AppThemeColor.BUTTON, - BorderFactory.createEmptyBorder(0,4,0,2), + BorderFactory.createEmptyBorder(0, 4, 0, 2), this.data.getItemName(), 16f); itemButton.setForeground(AppThemeColor.TEXT_IMPORTANT); @@ -25,8 +25,8 @@ protected JPanel getContentPanel() { itemButton.setRolloverEnabled(false); itemButton.addActionListener(action -> { }); - root.add(this.getFromPanel(),BorderLayout.LINE_START); - root.add(itemButton,BorderLayout.CENTER); + 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 index 896d0a8c..c117ecda 100644 --- 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 @@ -22,24 +22,23 @@ import java.util.HashMap; import java.util.Map; -public abstract class NotificationPanel extends JPanel implements AsSubscriber, ViewInit,ViewDestroy { +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 = 1f; + protected Map hotKeysPool = new HashMap<>(); + protected Map interactButtonMap = new HashMap<>(); @Setter protected float paintBorderValue = 0f; protected boolean blurEffect; protected boolean blurReverse; @Setter protected boolean duplicate; - + @Setter + private float paintAlphaValue = 1f; private Subscription settingsPostSubscription; @Override @@ -47,18 +46,19 @@ public void onViewInit() { this.setLayout(new BorderLayout()); this.setBackground(AppThemeColor.FRAME); this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(1,1,1,1), + BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER, 1))); } - public void setComponentsFactory(ComponentsFactory factory){ + + public void setComponentsFactory(ComponentsFactory factory) { this.componentsFactory = factory; this.removeAll(); this.onViewInit(); } - public void onHotKeyPressed(HotKeyDescriptor descriptor){ + public void onHotKeyPressed(HotKeyDescriptor descriptor) { JButton button = this.hotKeysPool.get(descriptor); - if(button != null){ + if (button != null) { button.doClick(); } } @@ -69,6 +69,7 @@ public void subscribe() { this.updateHotKeyPool(); }); } + protected abstract void updateHotKeyPool(); @Override @@ -79,26 +80,28 @@ public void onViewDestroy() { @Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,this.paintAlphaValue)); + 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){ + if (this.paintAlphaValue > 1.0f) { this.paintAlphaValue = 1.0f; } this.repaint(); } } + protected JPanel getTimePanel() { JPanel root = new JPanel(new BorderLayout()); - root.setPreferredSize(new Dimension((int) (46 * this.componentsFactory.getScale()),(int) (26 * this.componentsFactory.getScale()))); + root.setPreferredSize(new Dimension((int) (46 * this.componentsFactory.getScale()), (int) (26 * this.componentsFactory.getScale()))); root.setBackground(AppThemeColor.MSG_HEADER); JLabel timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 14, "0s"); Timer timeAgo = new Timer(1000, new ActionListener() { private int seconds = 0; + @Override public void actionPerformed(ActionEvent e) { seconds++; @@ -107,27 +110,28 @@ public void actionPerformed(ActionEvent e) { } }); timeAgo.start(); - root.add(timeLabel,BorderLayout.CENTER); + root.add(timeLabel, BorderLayout.CENTER); return root; } - protected void onBlur(){ + + protected void onBlur() { this.blurEffect = true; this.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(1,1,1,1), + BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1))); this.repaint(); } @Override protected void paintBorder(Graphics g) { - if(this.blurEffect) { + 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.blurReverse) { if (this.paintBorderValue <= 1.0f) { this.paintBorderValue += 0.002; if (this.paintBorderValue >= 1.0f) { @@ -135,7 +139,7 @@ protected void paintBorder(Graphics g) { this.paintBorderValue = 1.0f; } } - }else { + } else { if (this.paintBorderValue >= 0f) { this.paintBorderValue -= 0.002; if (this.paintBorderValue <= 0f) { @@ -145,7 +149,7 @@ protected void paintBorder(Graphics g) { } } this.repaint(); - }else { + } else { super.paintBorder(g); } } 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 index 94a8834d..04be4a51 100644 --- 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 @@ -1,7 +1,6 @@ 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; @@ -15,42 +14,44 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.*; +import java.util.Collections; import java.util.List; +import java.util.Objects; -public abstract class OutgoingNotificationPanel extends NotificationPanel { +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.add(this.getHeader(), BorderLayout.PAGE_START); - this.responseButtonsPanel = new JPanel(new GridLayout(1,0,0,5)); + 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.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(){ + 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); + 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)); + 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()); @@ -59,7 +60,7 @@ private JPanel getHeader(){ 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()){ + if (this.config.get().isDismissAfterLeave()) { this.controller.performHide(); } }); @@ -78,14 +79,14 @@ private JPanel getHeader(){ interactionPanel.add(openChatButton); interactionPanel.add(hideButton); this.interactButtonMap.clear(); - 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_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); + this.interactButtonMap.put(HotKeyType.N_OPEN_CHAT, openChatButton); + this.interactButtonMap.put(HotKeyType.N_CLOSE_NOTIFICATION, hideButton); - root.add(interactionPanel,BorderLayout.LINE_END); + root.add(interactionPanel, BorderLayout.LINE_END); return root; } @@ -98,27 +99,27 @@ protected void updateHotKeyPool() { .stream() .filter(it -> it.getType().equals(type)) .findAny().orElse(null); - if(!hotKeyPair.getDescriptor().getTitle().equals("...")) { + if (!hotKeyPair.getDescriptor().getTitle().equals("...")) { this.hotKeysPool.put(hotKeyPair.getDescriptor(), button); } }); this.initResponseButtonPanel(); Window windowAncestor = SwingUtilities.getWindowAncestor(OutgoingNotificationPanel.this); - if(windowAncestor != null) { + if (windowAncestor != null) { windowAncestor.pack(); } } - private void initResponseButtonPanel(){ + 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); + 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( + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) )); @@ -126,34 +127,35 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { - button.setBorder( BorderFactory.createCompoundBorder( + button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON_BORDER, 1), BorderFactory.createLineBorder(AppThemeColor.RESPONSE_BUTTON, 3) )); } }); button.addActionListener(action -> { - button.setBorder( BorderFactory.createCompoundBorder( + 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()){ + if (buttonConfig.isClose()) { this.controller.performHide(); } }); this.responseButtonsPanel.add(button); - this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(),button); + this.hotKeysPool.put(buttonConfig.getHotKeyDescriptor(), button); }); } - protected JPanel getFromPanel(){ + + 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)); + 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( @@ -162,27 +164,29 @@ protected JPanel getFromPanel(){ TextAlignment.CENTER, 18f, "=>"); - forPanel.add(separator,BorderLayout.CENTER); + forPanel.add(separator, BorderLayout.CENTER); separator.setHorizontalAlignment(SwingConstants.CENTER); return forPanel; } - protected JPanel getCurrencyPanel(Double curCount, String curIconPath){ + + protected JPanel getCurrencyPanel(Double curCount, String curIconPath) { String curCountStr = " "; - if(curCount > 0) { + if (curCount > 0) { curCountStr = curCount % 1 == 0 ? String.valueOf(curCount.intValue()) : String.valueOf(curCount); } - if(!Objects.equals(curCountStr, "") && curIconPath != null) { + 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(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(); @@ -194,16 +198,17 @@ public void subscribe() { public void onViewDestroy() { super.onViewDestroy(); } - private JButton getExpandButton(){ + + private JButton getExpandButton() { String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); expandButton.addActionListener(action -> { - if(this.bottomPanel.isVisible()){ + if (this.bottomPanel.isVisible()) { this.bottomPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); - }else { + 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)); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); } SwingUtilities.getWindowAncestor(OutgoingNotificationPanel.this).pack(); }); 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 index cad39509..e1d0d973 100644 --- 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 @@ -1,10 +1,8 @@ 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; @@ -16,38 +14,40 @@ import java.awt.*; -public class ScannerNotificationPanel extends NotificationPanel { +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); + 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.contentPanel = this.componentsFactory.wrapToSlide(sourceLabel, AppThemeColor.FRAME, 2, 2, 2, 2); + this.add(this.contentPanel, BorderLayout.CENTER); this.updateHotKeyPool(); } - private JPanel getHeader(){ + + 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); + 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)); + 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())); @@ -58,7 +58,7 @@ private JPanel getHeader(){ 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()){ + if (this.nConfig.get().isDismissAfterLeave()) { this.controller.performHide(); } }); @@ -77,22 +77,23 @@ private JPanel getHeader(){ interactionPanel.add(hideButton); this.interactButtonMap.clear(); - 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_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); + 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 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); + 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(); @@ -107,7 +108,7 @@ protected void updateHotKeyPool() { .stream() .filter(it -> it.getType().equals(type)) .findAny().orElse(null); - if(!hotKeyPair.getDescriptor().getTitle().equals("...")) { + if (!hotKeyPair.getDescriptor().getTitle().equals("...")) { this.hotKeysPool.put(hotKeyPair.getDescriptor(), button); } }); @@ -118,16 +119,16 @@ public void onViewDestroy() { super.onViewDestroy(); } - private JButton getExpandButton(){ + private JButton getExpandButton() { String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER,""); + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); expandButton.addActionListener(action -> { - if(this.contentPanel.isVisible()){ + if (this.contentPanel.isVisible()) { this.contentPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png",18f)); - }else { + 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)); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); } SwingUtilities.getWindowAncestor(ScannerNotificationPanel.this).pack(); }); 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 index 6564dff7..f975d852 100644 --- 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 @@ -3,5 +3,6 @@ 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 index 0c1ba966..52908e8a 100644 --- 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 @@ -1,8 +1,10 @@ package com.mercury.platform.ui.components.panel.notification.controller; -public interface IncomingPanelController extends NotificationController{ +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 index 11a0728c..cba0047d 100644 --- 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 @@ -3,7 +3,10 @@ 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/notification/controller/NotificationIncomingController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationIncomingController.java index 7e43e4c8..28dd0033 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationIncomingController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/controller/NotificationIncomingController.java @@ -18,9 +18,11 @@ public class NotificationIncomingController implements IncomingPanelController { private static final Logger log = LogManager.getLogger(NotificationIncomingController.class); private NotificationDescriptor notificationDescriptor; - public NotificationIncomingController(NotificationDescriptor notificationDescriptor){ + + public NotificationIncomingController(NotificationDescriptor notificationDescriptor) { this.notificationDescriptor = notificationDescriptor; } + @Override public void performInvite() { MercuryStoreCore.chatCommandSubject.onNext("/invite " + notificationDescriptor.getWhisperNickname()); @@ -54,7 +56,7 @@ public void performHide() { @Override public void showITH() { - if(notificationDescriptor instanceof ItemTradeNotificationDescriptor) { + if (notificationDescriptor instanceof ItemTradeNotificationDescriptor) { this.copyItemNameToClipboard(((ItemTradeNotificationDescriptor) notificationDescriptor).getItemName()); if (((ItemTradeNotificationDescriptor) notificationDescriptor).getTabName() != null) { MercuryStoreUI.showItemGridSubject.onNext((ItemTradeNotificationDescriptor) notificationDescriptor); @@ -62,13 +64,13 @@ public void showITH() { } } - private void copyItemNameToClipboard(@NonNull String itemName){ + private void copyItemNameToClipboard(@NonNull String itemName) { Timer timer = new Timer(30, action -> { try { StringSelection selection = new StringSelection(itemName); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); - }catch (IllegalStateException e){ + } catch (IllegalStateException e) { MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError(e)); } }); @@ -76,7 +78,7 @@ private void copyItemNameToClipboard(@NonNull String itemName){ timer.start(); } - private void closeMessagePanel(){ + private void closeMessagePanel() { Timer timer = new Timer(30, action -> { MercuryStoreCore.removeNotificationSubject.onNext(notificationDescriptor); }); 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 index 8bb4d1b4..6881e266 100644 --- 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 @@ -6,7 +6,7 @@ import javax.swing.*; -public class NotificationOutgoingController implements OutgoingPanelController{ +public class NotificationOutgoingController implements OutgoingPanelController { private NotificationDescriptor notificationDescriptor; public NotificationOutgoingController(NotificationDescriptor notificationDescriptor) { @@ -43,7 +43,7 @@ public void performResponse(String response) { MercuryStoreCore.chatCommandSubject.onNext("@" + notificationDescriptor.getWhisperNickname() + " " + response); } - private void closeMessagePanel(){ + private void closeMessagePanel() { Timer timer = new Timer(30, action -> { MercuryStoreCore.removeNotificationSubject.onNext(notificationDescriptor); }); 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 index 050f6abc..7e55969c 100644 --- 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 @@ -42,7 +42,8 @@ public void performOpenChat() { public void performResponse(String response) { MercuryStoreCore.chatCommandSubject.onNext("@" + notificationDescriptor.getNickName() + " " + response); } - private void closeMessagePanel(){ + + private void closeMessagePanel() { Timer timer = new Timer(30, action -> { MercuryStoreCore.removeScannerNotificationSubject.onNext(notificationDescriptor); }); 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 index 61b8265c..f3f0f590 100644 --- 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 @@ -1,7 +1,8 @@ package com.mercury.platform.ui.components.panel.notification.controller; -public interface OutgoingPanelController extends NotificationController{ +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 index 8551c90f..ae41039e 100644 --- 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 @@ -1,6 +1,7 @@ package com.mercury.platform.ui.components.panel.notification.controller; -public interface ScannerPanelController extends NotificationController{ +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/factory/CurrencyIncPanelProvider.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/factory/CurrencyIncPanelProvider.java index fcd58e6d..9a98d31c 100644 --- 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 @@ -3,11 +3,11 @@ 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.NotificationPanel; 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 { +public class CurrencyIncPanelProvider extends NotificationPanelProvider { @Override public boolean isSuitable(NotificationType type) { return type.equals(NotificationType.INC_CURRENCY_MESSAGE); 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 index 45fed54b..37995b7b 100644 --- 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 @@ -13,6 +13,7 @@ public class CurrencyOutPanelProvider extends NotificationPanelProvider getPanel() { CurrencyOutNotificationPanel panel = new CurrencyOutNotificationPanel(); 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 index fa0e5945..1f72e7ce 100644 --- 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 @@ -8,7 +8,7 @@ import com.mercury.platform.ui.components.panel.notification.controller.HistoryController; -public class HistoryPanelProvider extends NotificationPanelProvider { +public class HistoryPanelProvider extends NotificationPanelProvider { @Override public boolean isSuitable(NotificationType type) { return type.equals(NotificationType.HISTORY); 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 index 7c0ee07e..4e626d52 100644 --- 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 @@ -3,12 +3,12 @@ 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.NotificationPanel; 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 { +public class ItemIncPanelProvider extends NotificationPanelProvider { @Override public boolean isSuitable(NotificationType type) { return type.equals(NotificationType.INC_ITEM_MESSAGE); 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 index ddc21c75..1163082a 100644 --- 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 @@ -8,7 +8,7 @@ import com.mercury.platform.ui.components.panel.notification.controller.OutgoingPanelController; -public class ItemOutPanelProvider extends NotificationPanelProvider { +public class ItemOutPanelProvider extends NotificationPanelProvider { @Override public boolean isSuitable(NotificationType type) { return type.equals(NotificationType.OUT_ITEM_MESSAGE); 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 index 08db85fc..0332747e 100644 --- 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 @@ -19,13 +19,13 @@ public NotificationPanelFactory() { this.providers.add(new HistoryPanelProvider()); } - public NotificationPanelProvider getProviderFor(NotificationType type){ + public NotificationPanelProvider getProviderFor(NotificationType type) { NotificationPanelProvider provider = this.providers.stream() .filter(it -> it.isSuitable(type)) .findAny().orElse(null); - if(provider != null){ + if (provider != null) { return provider; - }else { + } 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 index 71ef7fcd..db988e76 100644 --- 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 @@ -1,34 +1,36 @@ 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 { +public abstract class NotificationPanelProvider { protected T data; protected C controller; protected ComponentsFactory componentsFactory; public abstract boolean isSuitable(NotificationType type); - public NotificationPanelProvider setController(C controller) { + + public NotificationPanelProvider setController(C controller) { this.controller = controller; return this; } - public NotificationPanelProvider setData(T data) { + + public NotificationPanelProvider setData(T data) { this.data = data; return this; } - public NotificationPanelProvider setComponentsFactory(ComponentsFactory factory) { + + public NotificationPanelProvider setComponentsFactory(ComponentsFactory factory) { this.componentsFactory = factory; return this; } - public NotificationPanel build() { - NotificationPanel panel = this.getPanel(); + public NotificationPanel build() { + NotificationPanel panel = this.getPanel(); panel.setData(this.data); - if(this.controller != null){ + if (this.controller != null) { panel.setController(this.controller); } panel.setComponentsFactory(this.componentsFactory); @@ -38,5 +40,6 @@ public NotificationPanel build() { this.controller = null; return panel; } - protected abstract NotificationPanel getPanel(); + + 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 index 7a1235df..4028347b 100644 --- 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 @@ -1,6 +1,5 @@ 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; @@ -8,7 +7,7 @@ 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 { +public class ScannerPanelProvider extends NotificationPanelProvider { @Override public boolean isSuitable(NotificationType type) { return type.equals(NotificationType.SCANNER_MESSAGE); 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 efc23d4b..95543c2a 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 @@ -19,6 +19,7 @@ public class HelpPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory; + public HelpPanel() { super(); componentsFactory = new ComponentsFactory(); @@ -33,7 +34,7 @@ public void onViewInit() { openTutorial.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ + if (SwingUtilities.isLeftMouseButton(e)) { FramesManager.INSTANCE.hideFrame(SettingsFrame.class); FramesManager.INSTANCE.preShowFrame(NotesFrame.class); } @@ -43,7 +44,7 @@ public void mouseClicked(MouseEvent e) { openTests.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ + if (SwingUtilities.isLeftMouseButton(e)) { FramesManager.INSTANCE.hideFrame(SettingsFrame.class); FramesManager.INSTANCE.preShowFrame(TestCasesFrame.class); MercuryStoreCore.frameVisibleSubject.onNext(FrameVisibleState.SHOW); @@ -54,10 +55,10 @@ public void mouseClicked(MouseEvent e) { patchNotes.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ + if (SwingUtilities.isLeftMouseButton(e)) { NotesLoader notesLoader = new NotesLoader(); java.util.List patchNotes = notesLoader.getPatchNotes(); - if(patchNotes.size() != 0){ + if (patchNotes.size() != 0) { NotesFrame patchNotesFrame = new NotesFrame(patchNotes, NotesFrame.NotesType.PATCH); patchNotesFrame.init(); patchNotesFrame.showComponent(); @@ -69,7 +70,7 @@ public void mouseClicked(MouseEvent e) { updateEvent.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ + if (SwingUtilities.isLeftMouseButton(e)) { MercuryStoreCore.updateInfoSubject.onNext(123); FramesManager.INSTANCE.hideFrame(SettingsFrame.class); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuListRenderer.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuListRenderer.java index 437352b4..c01b3f8a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuListRenderer.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/MenuListRenderer.java @@ -1,7 +1,6 @@ package com.mercury.platform.ui.components.panel.settings; - import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.misc.AppThemeColor; @@ -11,24 +10,25 @@ public class MenuListRenderer extends JButton implements ListCellRenderer { private ComponentsFactory componentsFactory = new ComponentsFactory(); + @Override public Component getListCellRendererComponent(JList list, MenuEntry value, int index, boolean isSelected, boolean cellHasFocus) { JButton button = this.componentsFactory.getButton(value.getText()); button.setForeground(AppThemeColor.TEXT_DEFAULT); button.setHorizontalAlignment(SwingConstants.LEFT); button.setBackground(AppThemeColor.FRAME); - button.setFont(this.componentsFactory.getFont(FontStyle.BOLD,16f)); - button.setPreferredSize(new Dimension(220,50)); + button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 16f)); + button.setPreferredSize(new Dimension(220, 50)); button.setIcon(value.getImageIcon()); - if(isSelected){ + if (isSelected) { button.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEmptyBorder(0,14,0,0), - BorderFactory.createMatteBorder(0,0,0,4,AppThemeColor.TEXT_DEFAULT))); + BorderFactory.createEmptyBorder(0, 14, 0, 0), + BorderFactory.createMatteBorder(0, 0, 0, 4, AppThemeColor.TEXT_DEFAULT))); button.setBackground(AppThemeColor.ADR_BG); - }else { + } else { button.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(0,0,0,1,AppThemeColor.ADR_PANEL_BORDER), - BorderFactory.createEmptyBorder(0,10,0,3))); + BorderFactory.createMatteBorder(0, 0, 0, 1, AppThemeColor.ADR_PANEL_BORDER), + BorderFactory.createEmptyBorder(0, 10, 0, 3))); } button.addActionListener(action -> { value.getAction().onClick(); 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 2959cd90..cbbdfdc9 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 @@ -14,6 +14,7 @@ public class MenuPanel extends JPanel implements ViewInit { private ComponentsFactory componentsFactory = new ComponentsFactory(); + public MenuPanel() { super(); this.setBackground(AppThemeColor.FRAME); @@ -21,6 +22,7 @@ public MenuPanel() { this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, AppThemeColor.ADR_PANEL_BORDER)); this.onViewInit(); } + @Override public void onViewInit() { JList list = new JList<>(getEntries()); 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 6a03b013..4a23c849 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 @@ -16,27 +16,27 @@ public class AboutPagePanel extends SettingsPagePanel { @Override public void onViewInit() { super.onViewInit(); - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + 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")); // this.add(imgPanel,BorderLayout.CENTER); this.container.add(this.componentsFactory.wrapToSlide(getInfoPanel())); } - private JPanel getInfoPanel(){ + private JPanel getInfoPanel() { JPanel panel = componentsFactory.getTransparentPanel(); panel.setBackground(AppThemeColor.ADR_BG); panel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JPanel titlePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - titlePanel.add(componentsFactory.getTextLabel("MercuryTrade", FontStyle.REGULAR,15)); + titlePanel.add(componentsFactory.getTextLabel("MercuryTrade", FontStyle.REGULAR, 15)); panel.add(titlePanel); JPanel versionPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - versionPanel.add(componentsFactory.getTextLabel("App version: " + MercuryConstants.APP_VERSION, FontStyle.REGULAR,15)); + versionPanel.add(componentsFactory.getTextLabel("App version: " + MercuryConstants.APP_VERSION, FontStyle.REGULAR, 15)); panel.add(versionPanel); - JLabel redditButton = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP,16f,"Reddit"); + JLabel redditButton = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP, 16f, "Reddit"); redditButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -57,7 +57,7 @@ public void mouseExited(MouseEvent e) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); - JLabel githubButton = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP,16f,"Github"); + JLabel githubButton = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP, 16f, "Github"); githubButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -67,6 +67,7 @@ public void mouseClicked(MouseEvent e) { e1.printStackTrace(); } } + @Override public void mouseEntered(MouseEvent e) { setCursor(new Cursor(Cursor.HAND_CURSOR)); @@ -78,7 +79,7 @@ public void mouseExited(MouseEvent e) { } }); - JLabel discordButton = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP,16f,"Discord"); + JLabel discordButton = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP, 16f, "Discord"); discordButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -88,6 +89,7 @@ public void mouseClicked(MouseEvent e) { e1.printStackTrace(); } } + @Override public void mouseEntered(MouseEvent e) { setCursor(new Cursor(Cursor.HAND_CURSOR)); @@ -100,7 +102,7 @@ public void mouseExited(MouseEvent e) { }); JPanel feedbackPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - feedbackPanel.add(componentsFactory.getTextLabel("Feedback & Suggestions: ", FontStyle.REGULAR,15)); + feedbackPanel.add(componentsFactory.getTextLabel("Feedback & Suggestions: ", FontStyle.REGULAR, 15)); feedbackPanel.add(redditButton); feedbackPanel.add(githubButton); feedbackPanel.add(discordButton); 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 1a145bc9..3418c646 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 @@ -23,13 +23,14 @@ public class GeneralSettingsPagePanel extends SettingsPagePanel { private JSlider minSlider; private JSlider maxSlider; + @Override public void onViewInit() { super.onViewInit(); this.applicationConfig = Configuration.get().applicationConfiguration(); this.applicationSnapshot = CloneHelper.cloneObject(this.applicationConfig.get()); - JPanel root = componentsFactory.getJPanel(new GridLayout(0,2,4,4)); + JPanel root = componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4)); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); root.setBackground(AppThemeColor.ADR_BG); @@ -37,32 +38,32 @@ public void onViewInit() { checkEnable.addActionListener(action -> { this.applicationSnapshot.setCheckOutUpdate(checkEnable.isSelected()); }); - JSlider fadeTimeSlider = this.componentsFactory.getSlider(0,10, this.applicationSnapshot.getFadeTime(),AppThemeColor.SLIDE_BG); + JSlider fadeTimeSlider = this.componentsFactory.getSlider(0, 10, this.applicationSnapshot.getFadeTime(), AppThemeColor.SLIDE_BG); fadeTimeSlider.addChangeListener(e -> { this.applicationSnapshot.setFadeTime(fadeTimeSlider.getValue()); }); - this.minSlider = this.componentsFactory.getSlider(40,100,this.applicationSnapshot.getMinOpacity(),AppThemeColor.SLIDE_BG); + this.minSlider = this.componentsFactory.getSlider(40, 100, this.applicationSnapshot.getMinOpacity(), AppThemeColor.SLIDE_BG); this.minSlider.addChangeListener(e -> { - if(!(this.minSlider.getValue() > this.maxSlider.getValue())) { + if (!(this.minSlider.getValue() > this.maxSlider.getValue())) { this.applicationSnapshot.setMinOpacity(this.minSlider.getValue()); - }else { - minSlider.setValue(minSlider.getValue()-1); + } else { + minSlider.setValue(minSlider.getValue() - 1); } }); - this.maxSlider = this.componentsFactory.getSlider(40,100,this.applicationSnapshot.getMaxOpacity(),AppThemeColor.SLIDE_BG); + this.maxSlider = this.componentsFactory.getSlider(40, 100, this.applicationSnapshot.getMaxOpacity(), AppThemeColor.SLIDE_BG); this.maxSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { - if(minSlider.getValue() > maxSlider.getValue()){ + if (minSlider.getValue() > maxSlider.getValue()) { minSlider.setValue(maxSlider.getValue()); } applicationSnapshot.setMaxOpacity(maxSlider.getValue()); } }); - JComboBox notifierStatusPicker = this.componentsFactory.getComboBox(new String[]{"Always play a sound", "Only when tabbed out","Never"}); + JComboBox notifierStatusPicker = this.componentsFactory.getComboBox(new String[]{"Always play a sound", "Only when tabbed out", "Never"}); notifierStatusPicker.setSelectedItem(this.applicationSnapshot.getNotifierStatus().asPretty()); notifierStatusPicker.addActionListener(action -> { this.applicationSnapshot.setNotifierStatus(WhisperNotifierStatus.valueOfPretty((String) notifierStatusPicker.getSelectedItem())); @@ -70,8 +71,8 @@ public void mouseReleased(MouseEvent e) { JTextField gamePathField = this.componentsFactory.getTextField(this.applicationSnapshot.getGamePath()); gamePathField.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER,1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2) + BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 2) )); gamePathField.addKeyListener(new KeyAdapter() { @Override @@ -80,7 +81,7 @@ public void keyTyped(KeyEvent e) { } }); - JPanel poeFolderPanel = componentsFactory.getTransparentPanel(new BorderLayout(4,4)); + JPanel poeFolderPanel = componentsFactory.getTransparentPanel(new BorderLayout(4, 4)); poeFolderPanel.add(gamePathField, BorderLayout.CENTER); JButton changeButton = this.componentsFactory.getBorderedButton("Change"); poeFolderPanel.add(changeButton, BorderLayout.LINE_END); @@ -89,31 +90,31 @@ public void keyTyped(KeyEvent e) { fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); changeButton.addActionListener(e -> { int returnVal = fileChooser.showOpenDialog(this); - if(returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) { gamePathField.setText(fileChooser.getSelectedFile().getPath()); applicationSnapshot.setGamePath(fileChooser.getSelectedFile().getPath()); } }); - root.add(this.componentsFactory.getTextLabel("Notify me when an update is available", FontStyle.REGULAR,16)); + root.add(this.componentsFactory.getTextLabel("Notify me when an update is available", FontStyle.REGULAR, 16)); root.add(checkEnable); - root.add(this.componentsFactory.getTextLabel("Component fade out time: ", FontStyle.REGULAR,16)); + root.add(this.componentsFactory.getTextLabel("Component fade out time: ", FontStyle.REGULAR, 16)); root.add(fadeTimeSlider); - root.add(this.componentsFactory.getTextLabel("Min opacity: ", FontStyle.REGULAR,16)); + root.add(this.componentsFactory.getTextLabel("Min opacity: ", FontStyle.REGULAR, 16)); root.add(this.minSlider); - root.add(this.componentsFactory.getTextLabel("Max opacity: ", FontStyle.REGULAR,16)); + root.add(this.componentsFactory.getTextLabel("Max opacity: ", FontStyle.REGULAR, 16)); root.add(this.maxSlider); - root.add(this.componentsFactory.getTextLabel("Notification sound alerts: ", FontStyle.REGULAR,16)); - root.add(this.componentsFactory.wrapToSlide(notifierStatusPicker,AppThemeColor.ADR_BG,0,0,0,2)); - root.add(this.componentsFactory.getTextLabel("Path of Exile folder: ", FontStyle.REGULAR,16)); - root.add(this.componentsFactory.wrapToSlide(poeFolderPanel,AppThemeColor.ADR_BG,0,0,2,2)); + root.add(this.componentsFactory.getTextLabel("Notification sound alerts: ", FontStyle.REGULAR, 16)); + root.add(this.componentsFactory.wrapToSlide(notifierStatusPicker, AppThemeColor.ADR_BG, 0, 0, 0, 2)); + root.add(this.componentsFactory.getTextLabel("Path of Exile folder: ", FontStyle.REGULAR, 16)); + root.add(this.componentsFactory.wrapToSlide(poeFolderPanel, AppThemeColor.ADR_BG, 0, 0, 2, 2)); this.container.add(this.componentsFactory.wrapToSlide(root)); } @Override public void onSave() { - HideSettingsManager.INSTANCE.apply(applicationSnapshot.getFadeTime(),applicationSnapshot.getMinOpacity(),applicationSnapshot.getMaxOpacity()); + HideSettingsManager.INSTANCE.apply(applicationSnapshot.getFadeTime(), applicationSnapshot.getMinOpacity(), applicationSnapshot.getMaxOpacity()); this.applicationConfig.set(CloneHelper.cloneObject(this.applicationSnapshot)); } 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 index dba963d3..fee1b217 100644 --- 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 @@ -19,7 +19,7 @@ public class HotKeyPanel extends JPanel { public HotKeyPanel(HotKeyDescriptor descriptor) { super(new BorderLayout()); this.descriptor = descriptor; - this.setPreferredSize(new Dimension(110,26)); + this.setPreferredSize(new Dimension(110, 26)); ComponentsFactory componentsFactory = new ComponentsFactory(); JButton button = componentsFactory.getBorderedButton(this.descriptor.getTitle()); @@ -27,7 +27,7 @@ public HotKeyPanel(HotKeyDescriptor descriptor) { MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { button.setBackground(AppThemeColor.ADR_BG); button.setText("Press any key"); hotKeyAllowed = true; @@ -57,6 +57,6 @@ public void mousePressed(MouseEvent e) { button.addMouseListener(mouseAdapter); } }); - this.add(button,BorderLayout.CENTER); + 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 cf1e9ac3..962b0c5f 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 @@ -2,20 +2,18 @@ import com.mercury.platform.shared.CloneHelper; 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.config.descriptor.HotKeyPair; +import com.mercury.platform.shared.config.descriptor.HotKeysSettingsDescriptor; +import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor; import com.mercury.platform.shared.entity.message.FlowDirections; -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 com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; -import java.awt.event.*; -import java.util.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.util.List; public class NotificationSettingsPagePanel extends SettingsPagePanel { @@ -35,16 +33,16 @@ public void onViewInit() { this.incHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getIncNHotKeysList()); this.outHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getOutNHotKeysList()); this.scannerHotKeySnapshot = CloneHelper.cloneObject(hotKeyService.get().getScannerNHotKeysList()); - JPanel inPanel = this.adrComponentsFactory.getCounterPanel(this.getIncomingPanel(), "Incoming notification:", AppThemeColor.ADR_BG,false); + 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,false); + JPanel outPanel = this.adrComponentsFactory.getCounterPanel(this.getOutgoingPanel(), "Outgoing notification:", AppThemeColor.ADR_BG, false); outPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - JPanel scannerPanel = this.adrComponentsFactory.getCounterPanel(this.getChatScannerPanel(), "Chat scanner notification:", AppThemeColor.ADR_BG,false); + 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)); + 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 @@ -65,39 +63,39 @@ public void restore() { this.onViewInit(); } - private JPanel getGeneralPanel(){ + 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); + JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.ADR_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); JComboBox flowDirectionPicker = componentsFactory.getComboBox(new String[]{"Upwards", "Downwards"}); flowDirectionPicker.addActionListener(e -> { - switch ((String)flowDirectionPicker.getSelectedItem()){ - case "Upwards":{ + switch ((String) flowDirectionPicker.getSelectedItem()) { + case "Upwards": { this.generalSnapshot.setFlowDirections(FlowDirections.UPWARDS); break; } - case "Downwards":{ + case "Downwards": { this.generalSnapshot.setFlowDirections(FlowDirections.DOWNWARDS); break; } } }); 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); + 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()); }); flowDirectionPicker.setSelectedIndex(this.generalSnapshot.getFlowDirections().ordinal()); - propertiesPanel.add(this.componentsFactory.getTextLabel("Flow direction:", FontStyle.REGULAR,16)); + 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(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); + 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)); + 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 @@ -106,13 +104,13 @@ public void focusLost(FocusEvent e) { } }); propertiesPanel.add(nickNameField); - root.add(this.componentsFactory.wrapToSlide(propertiesPanel,AppThemeColor.ADR_BG,2,0,2,2),BorderLayout.PAGE_START); + 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); + 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()); @@ -125,52 +123,56 @@ private JPanel getIncomingPanel() { showLeague.addActionListener(action -> { this.generalSnapshot.setShowLeague(showLeague.isSelected()); }); - propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR,16)); + 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(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(this.componentsFactory.getTextLabel("Show league:", FontStyle.REGULAR, 16)); propertiesPanel.add(showLeague); - root.add(propertiesPanel,BorderLayout.PAGE_START); + root.add(propertiesPanel, BorderLayout.PAGE_START); ResponseButtonsPanel responseButtonsPanel = new ResponseButtonsPanel(this.generalSnapshot.getButtons()); responseButtonsPanel.onViewInit(); - root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(responseButtonsPanel,AppThemeColor.ADR_BG),"Response buttons:"),BorderLayout.CENTER); - root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getInNotificationHotKeysPanel(),AppThemeColor.ADR_BG),"Hotkeys"),BorderLayout.PAGE_END); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(responseButtonsPanel, 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 wrapToCounter(JPanel inner, String title){ - JPanel root = this.adrComponentsFactory.getCounterPanel(inner, title, AppThemeColor.ADR_BG,false); + + 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); + return this.componentsFactory.wrapToSlide(root, AppThemeColor.ADR_BG); } - private JPanel getInNotificationHotKeysPanel(){ - JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); + + private JPanel getInNotificationHotKeysPanel() { + JPanel root = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.SETTINGS_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); 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)); + 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); + + 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)); + 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); + + 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)); + 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; @@ -178,14 +180,14 @@ private JPanel getScannerNotificationHotKeysPanel(){ 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); + JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.ADR_BG); JCheckBox enabled = this.componentsFactory.getCheckBox(this.generalSnapshot.isOutNotificationEnable()); enabled.addActionListener(action -> { this.generalSnapshot.setOutNotificationEnable(enabled.isSelected()); }); - propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR,16)); + propertiesPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR, 16)); propertiesPanel.add(enabled); - propertiesPanel.add(this.componentsFactory.getTextLabel("Close panel after leave:", FontStyle.REGULAR,16)); + 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()); @@ -194,20 +196,21 @@ private JPanel getOutgoingPanel() { ResponseButtonsPanel responseButtonsPanel = new ResponseButtonsPanel(this.generalSnapshot.getOutButtons()); responseButtonsPanel.onViewInit(); - root.add(propertiesPanel,BorderLayout.PAGE_START); - root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(responseButtonsPanel,AppThemeColor.ADR_BG),"Response buttons:"),BorderLayout.CENTER); - root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(this.getOutNotificationHotKeysPanel(),AppThemeColor.ADR_BG),"Hotkeys:"),BorderLayout.PAGE_END); + root.add(propertiesPanel, BorderLayout.PAGE_START); + root.add(this.wrapToCounter(this.componentsFactory.wrapToSlide(responseButtonsPanel, 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 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); + 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(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)); @@ -223,8 +226,8 @@ private JPanel getChatScannerPanel() { // } // }); // 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.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/ResponseButtonsPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/ResponseButtonsPanel.java index 8c0ddd62..f2eaf6f9 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/ResponseButtonsPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/ResponseButtonsPanel.java @@ -11,57 +11,57 @@ import java.awt.*; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; -import java.util.*; import java.util.List; public class ResponseButtonsPanel extends JPanel implements ViewInit { private List buttons; private ComponentsFactory componentsFactory = new ComponentsFactory(); + public ResponseButtonsPanel(List buttons) { - super(new BorderLayout(4,4)); + super(new BorderLayout(4, 4)); this.buttons = buttons; } @Override public void onViewInit() { this.setBackground(AppThemeColor.SETTINGS_BG); - JPanel 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); + JPanel headerPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.SETTINGS_BG); - JLabel titleLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, null,15f,"Label"); + JLabel titleLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, null, 15f, "Label"); titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setPreferredSize(new Dimension(120,26)); - JLabel valueLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, null,15f,"Response text"); + titleLabel.setPreferredSize(new Dimension(120, 26)); + JLabel valueLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, null, 15f, "Response text"); valueLabel.setHorizontalAlignment(SwingConstants.CENTER); - JLabel hotKeyLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, null,15f,""); + JLabel hotKeyLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, null, 15f, ""); hotKeyLabel.setHorizontalAlignment(SwingConstants.CENTER); - hotKeyLabel.setPreferredSize(new Dimension(130,20)); + hotKeyLabel.setPreferredSize(new Dimension(130, 20)); - JLabel closeLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, null,15f,""); + JLabel closeLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, null, 15f, ""); closeLabel.setHorizontalAlignment(SwingConstants.CENTER); - headerPanel.add(titleLabel,BorderLayout.LINE_START); - headerPanel.add(valueLabel,BorderLayout.CENTER); + headerPanel.add(titleLabel, BorderLayout.LINE_START); + headerPanel.add(valueLabel, BorderLayout.CENTER); - JPanel miscPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.SETTINGS_BG); - miscPanel.add(hotKeyLabel,BorderLayout.CENTER); - miscPanel.add(closeLabel,BorderLayout.LINE_END); - headerPanel.add(miscPanel,BorderLayout.LINE_END); + JPanel miscPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.SETTINGS_BG); + miscPanel.add(hotKeyLabel, BorderLayout.CENTER); + miscPanel.add(closeLabel, BorderLayout.LINE_END); + headerPanel.add(miscPanel, BorderLayout.LINE_END); buttonsTable.add(headerPanel); buttons.forEach(it -> { buttonsTable.add(this.getResponseRow(it)); }); - this.add(buttonsTable,BorderLayout.CENTER); + this.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))); + BorderFactory.createEmptyBorder(3, 3, 3, 3))); addButton.addActionListener(action -> { ResponseButtonDescriptor descriptor = new ResponseButtonDescriptor(); int size = buttons.size(); @@ -71,11 +71,12 @@ public void onViewInit() { MercuryStoreUI.settingsRepaintSubject.onNext(true); MercuryStoreUI.settingsPackSubject.onNext(true); }); - this.add(buttonsTable,BorderLayout.CENTER); - this.add(addButton,BorderLayout.PAGE_END); + this.add(buttonsTable, BorderLayout.CENTER); + this.add(addButton, BorderLayout.PAGE_END); } - private JPanel getResponseRow(ResponseButtonDescriptor descriptor){ - JPanel root = this.componentsFactory.getJPanel(new BorderLayout(4,4), AppThemeColor.SETTINGS_BG); + + private JPanel getResponseRow(ResponseButtonDescriptor descriptor) { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(4, 4), AppThemeColor.SETTINGS_BG); JTextField titleField = this.componentsFactory.getTextField(descriptor.getTitle(), FontStyle.REGULAR, 15f); titleField.addFocusListener(new FocusAdapter() { @Override @@ -83,7 +84,7 @@ public void focusLost(FocusEvent e) { descriptor.setTitle(titleField.getText()); } }); - titleField.setPreferredSize(new Dimension(120,26)); + titleField.setPreferredSize(new Dimension(120, 26)); JTextField responseField = this.componentsFactory.getTextField(descriptor.getResponseText(), FontStyle.REGULAR, 15f); responseField.addFocusListener(new FocusAdapter() { @Override @@ -91,16 +92,16 @@ public void focusLost(FocusEvent e) { descriptor.setResponseText(responseField.getText()); } }); - 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); + 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?"); + JPanel miscPanel = this.componentsFactory.getJPanel(new BorderLayout(4, 4), AppThemeColor.SETTINGS_BG); + JCheckBox checkBox = this.componentsFactory.getCheckBox(descriptor.isClose(), "Close notification panel after click?"); checkBox.addActionListener(action -> { descriptor.setClose(checkBox.isSelected()); }); miscPanel.add(checkBox, BorderLayout.LINE_START); - miscPanel.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(descriptor.getHotKeyDescriptor()),AppThemeColor.SETTINGS_BG,0,0,2,0),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 -> { @@ -109,9 +110,9 @@ public void focusLost(FocusEvent e) { MercuryStoreUI.settingsPackSubject.onNext(true); MercuryStoreUI.settingsRepaintSubject.onNext(true); }); - miscPanel.add(removeButton,BorderLayout.LINE_END); + miscPanel.add(removeButton, BorderLayout.LINE_END); - root.add(miscPanel,BorderLayout.LINE_END); + root.add(miscPanel, BorderLayout.LINE_END); 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 6bb478ee..895e6068 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 @@ -26,11 +26,12 @@ public SettingsPagePanel() { public void onViewInit() { this.container = new VerticalScrollContainer(); this.container.setBackground(AppThemeColor.FRAME); - this.container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); - JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer( this.container); - this.add(verticalContainer,BorderLayout.CENTER); + this.container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); + JScrollPane verticalContainer = this.componentsFactory.getVerticalContainer(this.container); + this.add(verticalContainer, BorderLayout.CENTER); } public abstract void onSave(); + public abstract void restore(); } 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 89516f96..f7e41c29 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 @@ -18,7 +18,7 @@ import java.util.Map; public class SoundSettingsPagePanel extends SettingsPagePanel { - private Map wavPaths; + private Map wavPaths; private JSlider notificationSlider; private JSlider chatScannerSlider; @@ -26,78 +26,79 @@ public class SoundSettingsPagePanel extends SettingsPagePanel { private JSlider updateSlider; private Map soundSnapshot; - private KeyValueConfigurationService soundConfiguration; + private KeyValueConfigurationService soundConfiguration; + @Override 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"); - this.wavPaths.put("clicks","app/sounds/click1/button-pressed-10.wav"); - this.wavPaths.put("update","app/patch_tone.wav"); + this.wavPaths.put("notification", "app/notification.wav"); + this.wavPaths.put("chat_scanner", "app/chat-filter.wav"); + this.wavPaths.put("clicks", "app/sounds/click1/button-pressed-10.wav"); + this.wavPaths.put("update", "app/patch_tone.wav"); this.soundConfiguration = Configuration.get().soundConfiguration(); this.soundSnapshot = CloneHelper.cloneObject(this.soundConfiguration.getMap()); JPanel vPanel = this.getVolumePanel(); - JPanel volumePanel = this.adrComponentsFactory.getCounterPanel(vPanel, "Volume:", AppThemeColor.ADR_BG,true); + JPanel volumePanel = this.adrComponentsFactory.getCounterPanel(vPanel, "Volume:", AppThemeColor.ADR_BG, true); volumePanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); this.container.add(this.componentsFactory.wrapToSlide(volumePanel)); } - private JPanel getVolumePanel(){ - JPanel container = componentsFactory.getTransparentPanel(new GridLayout(0, 2,0,4)); + private JPanel getVolumePanel() { + JPanel container = componentsFactory.getTransparentPanel(new GridLayout(0, 2, 0, 4)); container.setBackground(AppThemeColor.ADR_BG); container.setBorder(new CompoundBorder( - BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER), - BorderFactory.createEmptyBorder(3,0,3,0))); + BorderFactory.createMatteBorder(0, 0, 1, 0, AppThemeColor.MSG_HEADER_BORDER), + BorderFactory.createEmptyBorder(3, 0, 3, 0))); - notificationSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("notification").getDb().intValue(),AppThemeColor.SETTINGS_BG); + notificationSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("notification").getDb().intValue(), AppThemeColor.SETTINGS_BG); notificationSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { MercuryStoreCore.soundSettingsSubject.onNext(new SoundDescriptor( wavPaths.get("notification"), - notificationSlider.getValue() == -40 ? -80f : (float)notificationSlider.getValue() + notificationSlider.getValue() == -40 ? -80f : (float) notificationSlider.getValue() )); } }); - chatScannerSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("chat_scanner").getDb().intValue(),AppThemeColor.SETTINGS_BG); + chatScannerSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("chat_scanner").getDb().intValue(), AppThemeColor.SETTINGS_BG); chatScannerSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { MercuryStoreCore.soundSettingsSubject.onNext(new SoundDescriptor( wavPaths.get("chat_scanner"), - chatScannerSlider.getValue() == -40 ? -80f : (float)chatScannerSlider.getValue() + chatScannerSlider.getValue() == -40 ? -80f : (float) chatScannerSlider.getValue() )); } }); - clicksSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("clicks").getDb().intValue(),AppThemeColor.SETTINGS_BG); + clicksSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("clicks").getDb().intValue(), AppThemeColor.SETTINGS_BG); clicksSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { MercuryStoreCore.soundSettingsSubject.onNext(new SoundDescriptor( wavPaths.get("clicks"), - clicksSlider.getValue() == -40 ? -80f : (float)clicksSlider.getValue() + clicksSlider.getValue() == -40 ? -80f : (float) clicksSlider.getValue() )); } }); - updateSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("update").getDb().intValue(),AppThemeColor.SETTINGS_BG); + updateSlider = componentsFactory.getSlider(-40, 6, soundSnapshot.get("update").getDb().intValue(), AppThemeColor.SETTINGS_BG); updateSlider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { MercuryStoreCore.soundSettingsSubject.onNext(new SoundDescriptor( wavPaths.get("update"), - updateSlider.getValue() == -40 ? -80f : (float)updateSlider.getValue() + updateSlider.getValue() == -40 ? -80f : (float) updateSlider.getValue() )); } }); - container.add(componentsFactory.getTextLabel("Notification:",FontStyle.REGULAR,16)); + container.add(componentsFactory.getTextLabel("Notification:", FontStyle.REGULAR, 16)); container.add(notificationSlider); - container.add(componentsFactory.getTextLabel("Chat Scanner",FontStyle.REGULAR,16)); + container.add(componentsFactory.getTextLabel("Chat Scanner", FontStyle.REGULAR, 16)); container.add(chatScannerSlider); - container.add(componentsFactory.getTextLabel("Clicks",FontStyle.REGULAR,16)); + container.add(componentsFactory.getTextLabel("Clicks", FontStyle.REGULAR, 16)); container.add(clicksSlider); - container.add(componentsFactory.getTextLabel("Update notification",FontStyle.REGULAR,16)); + container.add(componentsFactory.getTextLabel("Update notification", FontStyle.REGULAR, 16)); container.add(updateSlider); return container; } @@ -105,13 +106,13 @@ public void mouseReleased(MouseEvent e) { @Override public void onSave() { soundSnapshot.get("notification") - .setDb((float)notificationSlider.getValue()); + .setDb((float) notificationSlider.getValue()); soundSnapshot.get("chat_scanner") - .setDb((float)chatScannerSlider.getValue()); + .setDb((float) chatScannerSlider.getValue()); soundSnapshot.get("clicks") - .setDb((float)clicksSlider.getValue()); + .setDb((float) clicksSlider.getValue()); soundSnapshot.get("update") - .setDb((float)updateSlider.getValue()); + .setDb((float) updateSlider.getValue()); this.soundConfiguration.set(CloneHelper.cloneObject(this.soundSnapshot)); } 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 bc8f84a8..59ec79e0 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 @@ -14,19 +14,19 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.net.URI; -import java.util.*; +import java.util.ArrayList; import java.util.List; -public class SupportPagePanel extends SettingsPagePanel{ +public class SupportPagePanel extends SettingsPagePanel { @Override public void onViewInit() { JPanel donatePanel = componentsFactory.getTransparentPanel(); donatePanel.setBackground(AppThemeColor.ADR_BG); - donatePanel.setLayout(new GridLayout(0,1,5,5)); + donatePanel.setLayout(new GridLayout(0, 1, 5, 5)); donatePanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - JButton donate = componentsFactory.getIconifiedTransparentButton("app/paypal.png","Donate"); - donate.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + JButton donate = componentsFactory.getIconifiedTransparentButton("app/paypal.png", "Donate"); + donate.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); donate.setBackground(AppThemeColor.SLIDE_BG); donate.addMouseListener(new MouseAdapter() { @Override @@ -36,7 +36,7 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { - donate.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); + donate.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); } @Override @@ -49,29 +49,29 @@ public void mousePressed(MouseEvent e) { } }); JTextArea donateText = componentsFactory.getSimpleTextArea("We aimed to create a convenience tool in form of an easy-to-use application, primarily for trading purposes. If MercuryTrade successfully managed to save your time or improve your experience, you can thank us by donating or telling your friends. If you want your name to be featured in our in-app Hall of Fame please provide this information within the transaction!"); - donateText.setPreferredSize(new Dimension(300,150)); + donateText.setPreferredSize(new Dimension(300, 150)); JPanel donateButtonPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - donateButtonPanel.setBorder(BorderFactory.createEmptyBorder(60,0,0,0)); + donateButtonPanel.setBorder(BorderFactory.createEmptyBorder(60, 0, 0, 0)); donateButtonPanel.add(donate); donatePanel.add(donateButtonPanel); - donatePanel.add(this.componentsFactory.wrapToSlide(donateText,AppThemeColor.ADR_BG,4,14,4,14)); + donatePanel.add(this.componentsFactory.wrapToSlide(donateText, AppThemeColor.ADR_BG, 4, 14, 4, 14)); JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); root.setBackground(AppThemeColor.FRAME); - root.add(this.componentsFactory.wrapToSlide(donatePanel),BorderLayout.CENTER); - root.add(this.componentsFactory.wrapToSlide(getDonationsPanel()),BorderLayout.LINE_END); - this.add(root,BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(donatePanel), BorderLayout.CENTER); + root.add(this.componentsFactory.wrapToSlide(getDonationsPanel()), BorderLayout.LINE_END); + this.add(root, BorderLayout.CENTER); } private JPanel getDonationsPanel() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBackground(AppThemeColor.ADR_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); - root.add(componentsFactory.getTextLabel("Thanks a lot for support:"),BorderLayout.PAGE_START); + root.add(componentsFactory.getTextLabel("Thanks a lot for support:"), BorderLayout.PAGE_START); JPanel donationsList = new VerticalScrollContainer(); donationsList.setBackground(AppThemeColor.TRANSPARENT); - donationsList.setLayout(new BoxLayout(donationsList,BoxLayout.Y_AXIS)); + donationsList.setLayout(new BoxLayout(donationsList, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(donationsList); scrollPane.setBorder(null); @@ -89,38 +89,29 @@ public void mouseWheelMoved(MouseWheelEvent e) { vBar.setUI(new MercuryScrollBarUI()); vBar.setPreferredSize(new Dimension(14, Integer.MAX_VALUE)); vBar.setUnitIncrement(3); - vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,2)); + vBar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 2)); vBar.addAdjustmentListener(e -> repaint()); donationsList.getParent().setBackground(AppThemeColor.TRANSPARENT); getDonations().forEach(pair -> { JPanel item = componentsFactory.getTransparentPanel(new BorderLayout()); - item.add(componentsFactory.getTextLabel(pair.name, FontStyle.REGULAR,pair.color),BorderLayout.CENTER); + item.add(componentsFactory.getTextLabel(pair.name, FontStyle.REGULAR, pair.color), BorderLayout.CENTER); donationsList.add(item); }); - root.add(scrollPane,BorderLayout.CENTER); + root.add(scrollPane, BorderLayout.CENTER); return root; } - private List getDonations(){ + + private List getDonations() { List donations = new ArrayList<>(); - donations.add(new DonationPair("222Craft",AppThemeColor.TEXT_DEFAULT)); - donations.add(new DonationPair("Blightsand",AppThemeColor.TEXT_DEFAULT)); - donations.add(new DonationPair("StubenZocker",AppThemeColor.TEXT_DEFAULT)); - donations.add(new DonationPair("SirKultan",AppThemeColor.TEXT_DEFAULT)); + donations.add(new DonationPair("222Craft", AppThemeColor.TEXT_DEFAULT)); + donations.add(new DonationPair("Blightsand", AppThemeColor.TEXT_DEFAULT)); + donations.add(new DonationPair("StubenZocker", AppThemeColor.TEXT_DEFAULT)); + donations.add(new DonationPair("SirKultan", AppThemeColor.TEXT_DEFAULT)); return donations; } - private class DonationPair{ - private String name; - private Color color; - - DonationPair(String name, Color color) { - this.name = name; - this.color = color; - } - } - @Override public void onSave() { @@ -130,4 +121,14 @@ public void onSave() { public void restore() { } + + private class DonationPair { + private String name; + private Color color; + + DonationPair(String name, Color color) { + this.name = name; + this.color = color; + } + } } 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 a46af653..bc9acbb2 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 @@ -3,17 +3,12 @@ import com.mercury.platform.shared.CloneHelper; 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.shared.config.descriptor.TaskBarDescriptor; 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 { @@ -26,7 +21,7 @@ public void onViewInit() { this.taskBarService = Configuration.get().taskBarConfiguration(); this.taskBarSnapshot = CloneHelper.cloneObject(this.taskBarService.get()); - JPanel root = componentsFactory.getJPanel(new GridLayout(0,2),AppThemeColor.ADR_BG); + JPanel root = componentsFactory.getJPanel(new GridLayout(0, 2), AppThemeColor.ADR_BG); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); JTextField responseField = componentsFactory.getTextField(this.taskBarSnapshot.getDndResponseText(), FontStyle.REGULAR, 16f); @@ -39,12 +34,12 @@ public void onViewInit() { root.add(componentsFactory.getTextLabel("Enable in-game dnd:", FontStyle.REGULAR)); root.add(inGameDND); root.add(componentsFactory.getTextLabel("DND response:", FontStyle.REGULAR)); - root.add(this.componentsFactory.wrapToSlide(responseField,AppThemeColor.ADR_BG)); + root.add(this.componentsFactory.wrapToSlide(responseField, AppThemeColor.ADR_BG)); - JPanel hotKeysPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4),AppThemeColor.SETTINGS_BG); + JPanel hotKeysPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.SETTINGS_BG); hotKeysPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); - root.add(this.componentsFactory.getIconLabel("app/hideout.png", 24,SwingConstants.CENTER)); - root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(this.taskBarSnapshot.getHideoutHotkey()),AppThemeColor.SETTINGS_BG,2,4,1,1)); + root.add(this.componentsFactory.getIconLabel("app/hideout.png", 24, SwingConstants.CENTER)); + root.add(this.componentsFactory.wrapToSlide(new HotKeyPanel(this.taskBarSnapshot.getHideoutHotkey()), AppThemeColor.SETTINGS_BG, 2, 4, 1, 1)); this.container.add(this.componentsFactory.wrapToSlide(root)); this.container.add(this.componentsFactory.wrapToSlide(hotKeysPanel)); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarController.java index 7df54fbb..93a5b75e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/TaskBarController.java @@ -5,13 +5,22 @@ */ public interface TaskBarController { void enableDND(); + void disableDND(); + void showITH(); + void performHideout(); + void showChatFiler(); + void showHistory(); + void openPINSettings(); + void openScaleSettings(); + void showSettings(); + void exit(); } 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 da59cff0..7ea9a147 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 @@ -4,14 +4,13 @@ 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.*; +import com.mercury.platform.shared.config.descriptor.TaskBarDescriptor; 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.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; @@ -19,35 +18,35 @@ 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 ViewInit { private ComponentsFactory componentsFactory; private TaskBarController controller; private PlainConfigurationService taskBarService; private JButton toHideout; - public TaskBarPanel(@NonNull TaskBarController controller, @NonNull ComponentsFactory factory){ + + public TaskBarPanel(@NonNull TaskBarController controller, @NonNull ComponentsFactory factory) { this.controller = controller; this.componentsFactory = factory; this.onViewInit(); MercuryStoreCore.hotKeySubject.subscribe(hotkeyDescriptor -> { SwingUtilities.invokeLater(() -> { - if(ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)){ - if(this.taskBarService.get().getHideoutHotkey().equals(hotkeyDescriptor)){ + if (ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)) { + if (this.taskBarService.get().getHideoutHotkey().equals(hotkeyDescriptor)) { this.toHideout.doClick(); } } }); }); } + @Override public void onViewInit() { this.taskBarService = Configuration.get().taskBarConfiguration(); this.setBackground(AppThemeColor.FRAME); - this.setLayout(new BoxLayout(this,BoxLayout.X_AXIS)); + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); JButton visibleMode = componentsFactory.getIconButton( "app/visible-always-mode.png", @@ -74,7 +73,7 @@ public void onViewInit() { itemGrid.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { controller.showITH(); } } @@ -96,7 +95,7 @@ public void mousePressed(MouseEvent e) { adr.addActionListener(action -> { FramesManager.INSTANCE.performAdr(); TaskBarFrame windowAncestor = (TaskBarFrame) SwingUtilities.getWindowAncestor(TaskBarPanel.this); - windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(),windowAncestor.getHeight())); + windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(), windowAncestor.getHeight())); windowAncestor.pack(); }); @@ -126,7 +125,7 @@ public void mousePressed(MouseEvent e) { pinButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { controller.openPINSettings(); } } @@ -140,7 +139,7 @@ public void mouseClicked(MouseEvent e) { scaleButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { controller.openScaleSettings(); } } @@ -154,10 +153,10 @@ public void mouseClicked(MouseEvent e) { settingsButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { controller.showSettings(); TaskBarFrame windowAncestor = (TaskBarFrame) SwingUtilities.getWindowAncestor(TaskBarPanel.this); - windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(),windowAncestor.getHeight())); + windowAncestor.setSize(new Dimension(windowAncestor.getMIN_WIDTH(), windowAncestor.getHeight())); windowAncestor.pack(); } } @@ -171,7 +170,7 @@ public void mousePressed(MouseEvent e) { exitButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { controller.exit(); } } @@ -199,8 +198,8 @@ public void mousePressed(MouseEvent e) { this.add(Box.createRigidArea(new Dimension(3, 4))); } - public int getWidthOf(int elementCount){ - int size = this.getPreferredSize().width / (this.getComponentCount()/2); + public int getWidthOf(int elementCount) { + int size = this.getPreferredSize().width / (this.getComponentCount() / 2); return size * elementCount + 3; } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/dialog/AlertDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/dialog/AlertDialog.java index 5906e86e..5e36af63 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/dialog/AlertDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/dialog/AlertDialog.java @@ -8,11 +8,12 @@ import java.awt.*; -public class AlertDialog extends BaseDialog { +public class AlertDialog extends BaseDialog { public AlertDialog(DialogCallback callback, String text, Component relative) { - super(callback,relative,text); + super(callback, relative, text); } - protected void createView(){ + + protected void createView() { this.setLayout(new BorderLayout()); this.getRootPane().setBackground(AppThemeColor.FRAME_RGB); JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); @@ -20,31 +21,31 @@ protected void createView(){ root.setBorder(BorderFactory.createLineBorder(AppThemeColor.MSG_HEADER_BORDER)); JLabel header = this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_NICKNAME, TextAlignment.CENTER, 18f, this.payload); header.setBackground(AppThemeColor.FRAME_RGB); - root.add(header,BorderLayout.CENTER); + root.add(header, BorderLayout.CENTER); JPanel miscPanel = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); miscPanel.setBackground(AppThemeColor.SLIDE_BG); - miscPanel.setBorder(BorderFactory.createEmptyBorder(0,50,0,50)); - JButton okButton = this.componentsFactory.getBorderedButton("Yes",16); - okButton.setPreferredSize(new Dimension(120,26)); + miscPanel.setBorder(BorderFactory.createEmptyBorder(0, 50, 0, 50)); + JButton okButton = this.componentsFactory.getBorderedButton("Yes", 16); + okButton.setPreferredSize(new Dimension(120, 26)); okButton.addActionListener(action -> { - this.callback.onAction(true); - this.setVisible(false); - this.dispose(); + this.callback.onAction(true); + this.setVisible(false); + this.dispose(); }); - JButton cancelButton = this.componentsFactory.getBorderedButton("No",16); + JButton cancelButton = this.componentsFactory.getBorderedButton("No", 16); cancelButton.addActionListener(action -> { this.callback.onAction(false); this.setVisible(false); this.dispose(); }); - cancelButton.setPreferredSize(new Dimension(120,26)); + cancelButton.setPreferredSize(new Dimension(120, 26)); miscPanel.add(okButton); miscPanel.add(cancelButton); - root.add(miscPanel,BorderLayout.PAGE_END); + root.add(miscPanel, BorderLayout.PAGE_END); this.setResizable(false); - this.add(root,BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/dialog/BaseDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/dialog/BaseDialog.java index 5b790196..ae911071 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/dialog/BaseDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/dialog/BaseDialog.java @@ -3,17 +3,17 @@ import com.mercury.platform.ui.components.ComponentsFactory; import com.mercury.platform.ui.misc.AppThemeColor; -import lombok.Getter; import lombok.Setter; import javax.swing.*; import java.awt.*; -public abstract class BaseDialog extends JDialog { +public abstract class BaseDialog extends JDialog { @Setter protected DialogCallback callback; protected P payload; protected ComponentsFactory componentsFactory = new ComponentsFactory(); + public BaseDialog(DialogCallback callback, Component relative, P payload) { this.payload = payload; this.callback = callback; @@ -22,10 +22,11 @@ public BaseDialog(DialogCallback callback, Component relative, P payload) { this.setLayout(new BorderLayout()); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setBackground(AppThemeColor.FRAME_RGB); - this.getRootPane().setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); + this.getRootPane().setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); this.createView(); this.pack(); this.setLocationRelativeTo(relative); } + protected abstract void createView(); } 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 e7cfc2d3..399800b7 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 @@ -3,12 +3,11 @@ 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 com.mercury.platform.ui.misc.AppThemeColor; import org.pushingpixels.trident.Timeline; import javax.swing.*; -import javax.swing.Timer; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -18,31 +17,28 @@ public abstract class AbstractComponentFrame extends AbstractOverlaidFrame imple private final int HIDE_TIME = 200; private final int SHOW_TIME = 150; private final int BORDER_THICKNESS = 1; - private int HIDE_DELAY = 1000; - private float minOpacity = 1f; - private float maxOpacity = 1f; - protected int x; protected int y; protected boolean EResizeSpace = false; protected boolean SEResizeSpace = false; - + protected boolean processSEResize = true; + protected boolean processEResize = true; + protected boolean processHideEffect = true; + private int HIDE_DELAY = 1000; + private float minOpacity = 1f; + private float maxOpacity = 1f; private Timeline hideAnimation; private Timeline showAnimation; private Timer hideTimer; private HideEffectListener hideEffectListener; private boolean hideAnimationEnable = false; - protected boolean processSEResize = true; - protected boolean processEResize = true; - protected boolean processHideEffect = true; - protected AbstractComponentFrame() { super(); } @Override - protected void initialize(){ + protected void initialize() { this.initAnimationTimers(); this.setVisible(false); @@ -51,22 +47,23 @@ protected void initialize(){ HideSettingsManager.INSTANCE.registerFrame(this); FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); - if(frameDescriptor != null) { + if (frameDescriptor != null) { this.setLocation(frameDescriptor.getFrameLocation()); this.setSize(frameDescriptor.getFrameSize()); this.setMinimumSize(frameDescriptor.getFrameSize()); this.setMaximumSize(frameDescriptor.getFrameSize()); } this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 2), BorderFactory.createLineBorder(AppThemeColor.BORDER, BORDER_THICKNESS))); } - protected Point getFrameLocation(){ + + protected Point getFrameLocation() { return this.getLocationOnScreen(); } - public void disableHideEffect(){ - if(this.processHideEffect) { + public void disableHideEffect() { + if (this.processHideEffect) { this.setOpacity(maxOpacity); this.hideAnimationEnable = false; if (this.hideEffectListener != null) { @@ -74,14 +71,15 @@ public void disableHideEffect(){ } } } - public void enableHideEffect(int delay, int minOpacity, int maxOpacity){ - if(processHideEffect) { + + public void enableHideEffect(int delay, int minOpacity, int maxOpacity) { + if (processHideEffect) { this.HIDE_DELAY = delay * 1000; this.minOpacity = minOpacity / 100f; this.maxOpacity = maxOpacity / 100f; //this.setOpacity(minOpacity / 100f); this.setOpacity(maxOpacity / 100f); - if(this.hideEffectListener != null) { + if (this.hideEffectListener != null) { this.removeMouseListener(hideEffectListener); this.showAnimation.abort(); this.hideAnimation.abort(); @@ -93,38 +91,48 @@ public void enableHideEffect(int delay, int minOpacity, int maxOpacity){ } } - private void initAnimationTimers(){ + private void initAnimationTimers() { this.showAnimation = new Timeline(this); this.showAnimation.setDuration(SHOW_TIME); this.showAnimation.addPropertyToInterpolate("opacity", this.minOpacity, this.maxOpacity); this.hideAnimation = new Timeline(this); this.hideAnimation.setDuration(HIDE_TIME); - this.hideAnimation.addPropertyToInterpolate("opacity",this.maxOpacity,this.minOpacity); + this.hideAnimation.addPropertyToInterpolate("opacity", this.maxOpacity, this.minOpacity); } - public void onLocationChange(Point location){ + + public void onLocationChange(Point location) { FrameDescriptor frameDescriptor = this.framesConfig.getMap().get(this.getClass().getSimpleName()); frameDescriptor.setFrameLocation(location); MercuryStoreCore.saveConfigSubject.onNext(true); } - public void onSizeChange(){ + + public void onSizeChange() { MercuryStoreCore.saveConfigSubject.onNext(true); } - protected void onFrameDragged(Point location){ + + protected void onFrameDragged(Point location) { this.setLocation(location); } - private class ResizeByWidthMouseMotionListener extends MouseMotionAdapter{ + @Override + public Dimension getPreferredSize() { + Dimension preferredSize = super.getPreferredSize(); + return new Dimension(this.getMaximumSize().width, preferredSize.height); + } + + private class ResizeByWidthMouseMotionListener extends MouseMotionAdapter { @Override public void mouseDragged(MouseEvent e) { - if(EResizeSpace) { + if (EResizeSpace) { Point frameLocation = AbstractComponentFrame.this.getLocation(); AbstractComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, AbstractComponentFrame.this.getHeight())); - }else if(SEResizeSpace){ + } else if (SEResizeSpace) { Point frameLocation = AbstractComponentFrame.this.getLocation(); AbstractComponentFrame.this.setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x, e.getLocationOnScreen().y - frameLocation.y)); } } + @Override public void mouseMoved(MouseEvent e) { int frameWidth = AbstractComponentFrame.this.getWidth(); @@ -132,48 +140,49 @@ public void mouseMoved(MouseEvent e) { Point frameLocation = AbstractComponentFrame.this.getLocation(); Rectangle ERect = new Rectangle( frameLocation.x + frameWidth - (BORDER_THICKNESS + 8), - frameLocation.y,BORDER_THICKNESS+8,frameHeight); + frameLocation.y, BORDER_THICKNESS + 8, frameHeight); Rectangle SERect = new Rectangle( frameLocation.x + frameWidth - (BORDER_THICKNESS + 8), - frameLocation.y + frameHeight - (BORDER_THICKNESS + 8),BORDER_THICKNESS+8,8); + frameLocation.y + frameHeight - (BORDER_THICKNESS + 8), BORDER_THICKNESS + 8, 8); - if(processEResize && ERect.getBounds().contains(e.getLocationOnScreen())) { - if(processSEResize && SERect.getBounds().contains(e.getLocationOnScreen())){ + if (processEResize && ERect.getBounds().contains(e.getLocationOnScreen())) { + if (processSEResize && SERect.getBounds().contains(e.getLocationOnScreen())) { AbstractComponentFrame.this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR)); SEResizeSpace = true; EResizeSpace = false; - }else { + } else { AbstractComponentFrame.this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR)); EResizeSpace = true; SEResizeSpace = false; } - }else { + } else { EResizeSpace = false; SEResizeSpace = false; AbstractComponentFrame.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } - private class ResizeByWidthMouseListener extends MouseAdapter{ + + private class ResizeByWidthMouseListener extends MouseAdapter { @Override public void mouseReleased(MouseEvent e) { - if(hideAnimationEnable && !isMouseWithInFrame()) { + if (hideAnimationEnable && !isMouseWithInFrame()) { hideTimer.start(); } Dimension size = AbstractComponentFrame.this.getSize(); FrameDescriptor frameDescriptor = framesConfig.getMap().get(AbstractComponentFrame.this.getClass().getSimpleName()); - if(EResizeSpace){ - 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 { + if (EResizeSpace) { + 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(); - }else if(SEResizeSpace){ + } else if (SEResizeSpace) { AbstractComponentFrame.this.setMinimumSize(size); AbstractComponentFrame.this.setMaximumSize(size); frameDescriptor.setFrameSize(AbstractComponentFrame.this.getSize()); @@ -190,7 +199,7 @@ public void mouseExited(MouseEvent e) { @Override public void mousePressed(MouseEvent e) { - if(EResizeSpace || SEResizeSpace) { + if (EResizeSpace || SEResizeSpace) { Dimension size = framesConfig.getMinimumSize(AbstractComponentFrame.this.getClass().getSimpleName()); AbstractComponentFrame.this.setMinimumSize(size); } @@ -201,25 +210,26 @@ public void mousePressed(MouseEvent e) { * Listeners for hide&show animation on frame */ private class HideEffectListener extends MouseAdapter { - public HideEffectListener(){ - hideTimer = new Timer(HIDE_DELAY,listener ->{ + public HideEffectListener() { + hideTimer = new Timer(HIDE_DELAY, listener -> { showAnimation.abort(); hideAnimation.play(); }); hideTimer.setRepeats(false); } + @Override public void mouseEntered(MouseEvent e) { AbstractComponentFrame.this.repaint(); hideTimer.stop(); - if(AbstractComponentFrame.this.getOpacity() < maxOpacity) { + if (AbstractComponentFrame.this.getOpacity() < maxOpacity) { showAnimation.play(); } } @Override public void mouseExited(MouseEvent e) { - if(!isMouseWithInFrame() && !EResizeSpace){ // NEEDS WORK + if (!isMouseWithInFrame() && !EResizeSpace) { // NEEDS WORK hideTimer.start(); } } @@ -231,11 +241,12 @@ public void mouseExited(MouseEvent e) { public class DraggedFrameMotionListener extends MouseAdapter { @Override public void mouseDragged(MouseEvent e) { - e.translatePoint(AbstractComponentFrame.this.getLocation().x - x,AbstractComponentFrame.this.getLocation().y - y); - onFrameDragged(new Point(e.getX(),e.getY())); + e.translatePoint(AbstractComponentFrame.this.getLocation().x - x, AbstractComponentFrame.this.getLocation().y - y); + onFrameDragged(new Point(e.getX(), e.getY())); } } - public class DraggedFrameMouseListener extends MouseAdapter{ + + public class DraggedFrameMouseListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { x = e.getX(); @@ -245,16 +256,10 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); - if(getLocationOnScreen().y + getSize().height > dimension.height){ + if (getLocationOnScreen().y + getSize().height > dimension.height) { setLocation(getLocationOnScreen().x, dimension.height - getSize().height); } onLocationChange(getLocation()); } } - - @Override - public Dimension getPreferredSize() { - Dimension preferredSize = super.getPreferredSize(); - return new Dimension(this.getMaximumSize().width,preferredSize.height); - } } 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 2a7b5f50..5500fbdf 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 @@ -1,7 +1,7 @@ package com.mercury.platform.ui.frame; -import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.AsSubscriber; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.configration.FramesConfigurationService; import com.mercury.platform.shared.config.configration.KeyValueConfigurationService; @@ -18,19 +18,20 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -public abstract class AbstractOverlaidFrame extends JFrame implements AsSubscriber,ViewInit { +public abstract class AbstractOverlaidFrame extends JFrame implements AsSubscriber, ViewInit { protected FrameVisibleState prevState; protected boolean processingHideEvent = true; protected ComponentsFactory componentsFactory = new ComponentsFactory(); protected FramesConfigurationService framesConfig; protected PlainConfigurationService applicationConfig; - protected KeyValueConfigurationService scaleConfig; + protected KeyValueConfigurationService scaleConfig; protected LayoutManager layout; - protected AbstractOverlaidFrame(){ + + protected AbstractOverlaidFrame() { super("MercuryTrade"); - if(!this.getClass().equals(MercuryLoadingFrame.class)) { + if (!this.getClass().equals(MercuryLoadingFrame.class)) { this.framesConfig = Configuration.get().framesConfiguration(); this.applicationConfig = Configuration.get().applicationConfiguration(); this.scaleConfig = Configuration.get().scaleConfiguration(); @@ -53,9 +54,10 @@ public void mouseEntered(MouseEvent e) { }); MercuryStoreCore.frameVisibleSubject.subscribe(state -> - SwingUtilities.invokeLater(()-> this.changeVisible(state))); + SwingUtilities.invokeLater(() -> this.changeVisible(state))); } - protected void changeVisible(FrameVisibleState state){ + + protected void changeVisible(FrameVisibleState state) { if (this.processingHideEvent) { switch (state) { case SHOW: { @@ -67,7 +69,7 @@ protected void changeVisible(FrameVisibleState state){ case HIDE: { if (AbstractOverlaidFrame.this.isVisible()) { this.prevState = FrameVisibleState.SHOW; - }else { + } else { this.prevState = FrameVisibleState.HIDE; } this.hideComponent(); @@ -76,7 +78,8 @@ protected void changeVisible(FrameVisibleState state){ } } } - public void init(){ + + public void init() { this.layout = getFrameLayout(); this.setLayout(layout); this.initialize(); @@ -85,16 +88,19 @@ public void init(){ } protected abstract LayoutManager getFrameLayout(); + protected abstract void initialize(); - protected boolean isMouseWithInFrame(){ + protected boolean isMouseWithInFrame() { return this.getBounds().contains(MouseInfo.getPointerInfo().getLocation()); } - public void showComponent(){ + + public void showComponent() { this.setAlwaysOnTop(true); this.setVisible(true); } - public void hideComponent(){ + + public void hideComponent() { this.setVisible(false); } 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 ce90a895..2ee44399 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 @@ -7,13 +7,14 @@ import javax.swing.*; import java.awt.*; import java.util.Map; + //todo need generalization public abstract class AbstractScalableComponentFrame extends AbstractComponentFrame { protected Container mainContainer; - private ScaleState scaleState = ScaleState.DEFAULT; protected ComponentsFactory stubComponentsFactory; - private ScalableFrameConstraints prevConstraints; protected boolean inScaleSettings = false; + private ScaleState scaleState = ScaleState.DEFAULT; + private ScalableFrameConstraints prevConstraints; protected AbstractScalableComponentFrame() { super(); @@ -23,25 +24,28 @@ protected AbstractScalableComponentFrame() { this.registerDirectScaleHandler(); } - protected void onScaleLock(){ + protected void onScaleLock() { this.pack(); this.repaint(); } - protected void onScaleUnlock(){ + + protected void onScaleUnlock() { this.repaint(); this.pack(); } protected abstract void registerDirectScaleHandler(); - protected abstract void performScaling(Map scaleData); - protected void changeScale(float scale){ + protected abstract void performScaling(Map scaleData); + + protected void changeScale(float scale) { this.stubComponentsFactory.setScale(scale); this.initDefaultView(); } - public void setState(ScaleState state){ - switch (state){ - case DEFAULT:{ + + public void setState(ScaleState state) { + switch (state) { + case DEFAULT: { this.scaleState = ScaleState.DEFAULT; this.setContentPane(mainContainer); this.setVisible(prevConstraints.visible); @@ -64,14 +68,16 @@ public void setState(ScaleState state){ } } } - private void initDefaultView(){ - if(scaleState.equals(ScaleState.ENABLE)){ + + private void initDefaultView() { + if (scaleState.equals(ScaleState.ENABLE)) { JPanel panel = defaultView(stubComponentsFactory); this.setContentPane(panel); this.repaint(); this.pack(); } } + protected abstract JPanel defaultView(ComponentsFactory factory); protected class ScalableFrameConstraints { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/experimental/AdrTesting.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/experimental/AdrTesting.java index 0bda96c4..cfcf1d48 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/experimental/AdrTesting.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/experimental/AdrTesting.java @@ -9,7 +9,6 @@ import javax.swing.*; import javax.swing.plaf.basic.BasicProgressBarUI; import java.awt.*; -import java.awt.geom.AffineTransform; import java.awt.geom.Arc2D; import java.awt.geom.Area; import java.awt.geom.Rectangle2D; @@ -21,25 +20,28 @@ public class AdrTesting extends JPanel { protected final JProgressBar progress1 = new JProgressBar() { - @Override public void updateUI() { + @Override + public void updateUI() { super.updateUI(); setUI(new ProgressCircleUI()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); } }; protected final JProgressBar progress2 = new JProgressBar() { - @Override public void updateUI() { + @Override + public void updateUI() { super.updateUI(); setUI(new ProgressCircleUI()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); } }; + public AdrTesting() { super(new BorderLayout()); progress2.setStringPainted(true); progress1.setBackground(AppThemeColor.TRANSPARENT); progress1.setBorder(null); - progress2.setFont(new ComponentsFactory().getFont(FontStyle.BOLD,82)); + progress2.setFont(new ComponentsFactory().getFont(FontStyle.BOLD, 82)); progress2.setForeground(AppThemeColor.TEXT_DEFAULT); JSlider slider = new JSlider(); @@ -51,7 +53,8 @@ public AdrTesting() { JButton b = (JButton) e.getSource(); b.setEnabled(false); SwingWorker worker = new Task() { - @Override public void done() { + @Override + public void done() { if (b.isDisplayable()) { b.setEnabled(true); } @@ -71,13 +74,16 @@ public AdrTesting() { add(button, BorderLayout.SOUTH); setPreferredSize(new Dimension(320, 240)); } + public static void main(String... args) { EventQueue.invokeLater(new Runnable() { - @Override public void run() { + @Override + public void run() { createAndShowGUI(); } }); } + public static void createAndShowGUI() { JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); @@ -91,7 +97,8 @@ public static void createAndShowGUI() { } class ProgressCircleUI extends BasicProgressBarUI { - @Override public Dimension getPreferredSize(JComponent c) { + @Override + public Dimension getPreferredSize(JComponent c) { Dimension d = super.getPreferredSize(c); int v = Math.max(d.width, d.height); d.setSize(v, v); @@ -100,7 +107,7 @@ class ProgressCircleUI extends BasicProgressBarUI { @Override protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b) { - Graphics2D g2 = (Graphics2D)g; + Graphics2D g2 = (Graphics2D) g; String progressString = String.valueOf(progressBar.getValue()); g2.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2, progressString, @@ -116,10 +123,11 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int g2.setClip(oldClip); } - @Override public void paint(Graphics g, JComponent c) { + @Override + public void paint(Graphics g, JComponent c) { //public void paintDeterminate(Graphics g, JComponent c) { Insets b = progressBar.getInsets(); // area for border - int barRectWidth = progressBar.getWidth() - b.right - b.left; + int barRectWidth = progressBar.getWidth() - b.right - b.left; int barRectHeight = progressBar.getHeight() - b.top - b.bottom; if (barRectWidth <= 0 || barRectHeight <= 0) { return; @@ -130,8 +138,8 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int double degree = 360 * progressBar.getPercentComplete(); double sz = Math.max(barRectWidth, barRectHeight); - Shape outer = new Rectangle2D.Double(0, 0, sz, sz); - Shape sector = new Arc2D.Double(-sz, -sz, sz *3, sz *3, 90 - degree, degree, Arc2D.PIE); + Shape outer = new Rectangle2D.Double(0, 0, sz, sz); + Shape sector = new Arc2D.Double(-sz, -sz, sz * 3, sz * 3, 90 - degree, degree, Arc2D.PIE); Area foreground = new Area(sector); Area background = new Area(outer); @@ -139,17 +147,17 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int foreground.intersect(background); g2.setPaint(new Color(0x505050)); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.7f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.fill(background); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); try { BufferedImage read = ImageIO.read(getClass().getClassLoader().getResource("app/adr/vessel_vinktar.png")); - g2.drawImage(read,0,0,(int)sz,(int)sz,null); + g2.drawImage(read, 0, 0, (int) sz, (int) sz, null); } catch (IOException e) { e.printStackTrace(); } - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.7f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.fill(foreground); g2.dispose(); @@ -163,7 +171,9 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int class Task extends SwingWorker { private final Random rnd = new Random(); - @Override public String doInBackground() { + + @Override + public String doInBackground() { int current = 0; int lengthOfTask = 200; while (current <= lengthOfTask && !isCancelled()) { @@ -181,11 +191,14 @@ class Task extends SwingWorker { class ProgressListener implements PropertyChangeListener { private final JProgressBar progressBar; + protected ProgressListener(JProgressBar progressBar) { this.progressBar = progressBar; this.progressBar.setValue(0); } - @Override public void propertyChange(PropertyChangeEvent e) { + + @Override + public void propertyChange(PropertyChangeEvent e) { String strPropertyName = e.getPropertyName(); if ("progress".equals(strPropertyName)) { progressBar.setIndeterminate(false); 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 a5ef6192..89317f6c 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 @@ -11,27 +11,31 @@ import java.awt.event.MouseEvent; public abstract class AbstractMovableComponentFrame extends AbstractScalableComponentFrame { - private MovableFrameConstraints prevConstraints; - private LocationState moveState = LocationState.DEFAULT; protected boolean locationWasChanged = false; protected boolean inMoveMode = false; protected boolean enableMouseOverBorder = true; + private MovableFrameConstraints prevConstraints; + private LocationState moveState = LocationState.DEFAULT; + protected AbstractMovableComponentFrame() { super(); } - protected void onUnlock(){ + protected void onUnlock() { this.pack(); this.repaint(); } - protected void onLock(){ + + protected void onLock() { this.repaint(); this.pack(); } + protected abstract JPanel getPanelForPINSettings(); - public void setState(LocationState state){ - switch (state){ - case MOVING:{ + + public void setState(LocationState state) { + switch (state) { + case MOVING: { this.moveState = LocationState.MOVING; inMoveMode = true; this.prevConstraints = new MovableFrameConstraints( @@ -73,17 +77,17 @@ public void setState(LocationState state){ @Override public void onLocationChange(Point location) { super.onLocationChange(location); - if(inMoveMode) { + if (inMoveMode) { prevConstraints.location = location; locationWasChanged = true; } } - private JPanel setUpMoveListeners(JPanel panel){ + private JPanel setUpMoveListeners(JPanel panel) { panel.addMouseMotionListener(new DraggedFrameMotionListener()); panel.addMouseListener(new DraggedFrameMouseListener()); - if(this.enableMouseOverBorder) { + if (this.enableMouseOverBorder) { panel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { @@ -129,12 +133,12 @@ protected class MovableFrameConstraints { this.location = location; } - public void setLocation(Point location) { - this.location = location; - } - public Point getLocation() { return location; } + + public void setLocation(Point location) { + this.location = 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 c235df96..0c63062f 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 @@ -17,6 +17,7 @@ public class CurrencySearchFrame extends AbstractMovableComponentFrame { private JPanel setUpPanel; private JPanel loadingPanel; private JPanel resultPanel; + public CurrencySearchFrame() { super(); prevState = FrameVisibleState.SHOW; @@ -28,50 +29,51 @@ protected void initialize() { loadingPanel = getLoadingPanel(); setUpPanel = componentsFactory.getTransparentPanel(new BorderLayout()); setUpPanel.setBackground(AppThemeColor.FRAME); - setUpPanel.setLayout(new BoxLayout(setUpPanel,BoxLayout.Y_AXIS)); + setUpPanel.setLayout(new BoxLayout(setUpPanel, BoxLayout.Y_AXIS)); JPanel navBar = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.RIGHT)); JPanel topPanel = componentsFactory.getTransparentPanel(new BorderLayout()); JButton search = componentsFactory.getBorderedButton("Search"); - search.setPreferredSize(new Dimension(90,24)); + search.setPreferredSize(new Dimension(90, 24)); componentsFactory.setUpToggleCallbacks(search, () -> { this.removeAll(); - this.add(setUpPanel,BorderLayout.CENTER); + this.add(setUpPanel, BorderLayout.CENTER); this.pack(); this.repaint(); search.setText("Search"); }, () -> { this.removeAll(); - this.add(loadingPanel,BorderLayout.CENTER); + this.add(loadingPanel, BorderLayout.CENTER); this.pack(); this.repaint(); search.setText("Back"); }, false - ); + ); navBar.add(search); JPanel wantTitlePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - wantTitlePanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,22f,"What do you want:")); - topPanel.add(navBar,BorderLayout.LINE_END); - topPanel.add(wantTitlePanel,BorderLayout.CENTER); + wantTitlePanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP, 22f, "What do you want:")); + topPanel.add(navBar, BorderLayout.LINE_END); + topPanel.add(wantTitlePanel, BorderLayout.CENTER); JPanel downPanel = componentsFactory.getTransparentPanel(new BorderLayout()); JPanel haveTitlePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - haveTitlePanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP,22f,"What do you have:")); - downPanel.add(haveTitlePanel,BorderLayout.CENTER); + haveTitlePanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_NICKNAME, TextAlignment.LEFTOP, 22f, "What do you have:")); + downPanel.add(haveTitlePanel, BorderLayout.CENTER); setUpPanel.add(topPanel); setUpPanel.add(downPanel); - this.add(setUpPanel,BorderLayout.CENTER); + this.add(setUpPanel, BorderLayout.CENTER); this.pack(); } - private JPanel getLoadingPanel(){ + + private JPanel getLoadingPanel() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); JLabel loadingIcon = componentsFactory.getIconLabel("app/reload.gif"); - root.add(loadingIcon,BorderLayout.CENTER); + root.add(loadingIcon, BorderLayout.CENTER); return root; } @@ -89,8 +91,8 @@ protected LayoutManager getFrameLayout() { protected JPanel getPanelForPINSettings() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); JPanel labelPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - labelPanel.add(componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP,20f,"Currency searcher")); - root.setPreferredSize(new Dimension(600,300)); + labelPanel.add(componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MESSAGE, TextAlignment.LEFTOP, 20f, "Currency searcher")); + root.setPreferredSize(new Dimension(600, 300)); JLabel leftArrow = componentsFactory.getIconLabel("app/arrows/left-arrow.png", 68); JPanel upPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JLabel upArrow = componentsFactory.getIconLabel("app/arrows/up-arrow.png", 62); @@ -100,11 +102,11 @@ protected JPanel getPanelForPINSettings() { JPanel downPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); downPanel.add(downArrow); - root.add(leftArrow,BorderLayout.LINE_START); - root.add(upPanel,BorderLayout.PAGE_START); - root.add(rightArrow,BorderLayout.LINE_END); - root.add(downPanel,BorderLayout.PAGE_END); - root.add(labelPanel,BorderLayout.CENTER); + root.add(leftArrow, BorderLayout.LINE_START); + root.add(upPanel, BorderLayout.PAGE_START); + root.add(rightArrow, BorderLayout.LINE_END); + root.add(downPanel, BorderLayout.PAGE_END); + root.add(labelPanel, BorderLayout.CENTER); root.setBackground(AppThemeColor.FRAME); return root; } @@ -115,7 +117,7 @@ protected void registerDirectScaleHandler() { } @Override - protected void performScaling(Map scaleData) { + protected void performScaling(Map scaleData) { } 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 3c9f9bb5..f1789b6f 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 @@ -1,16 +1,16 @@ package com.mercury.platform.ui.frame.movable; +import com.mercury.platform.shared.entity.message.ItemTradeNotificationDescriptor; 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.fields.style.MercuryScrollBarUI; 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.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; import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.NonNull; import javax.swing.*; @@ -22,6 +22,7 @@ public class ItemsGridFrame extends AbstractMovableComponentFrame { private ItemsGridPanel itemsGridPanel; private HorizontalScrollContainer tabsContainer; private StashTabsContainer stashTabsContainer; + public ItemsGridFrame() { super(); componentsFactory.setScale(this.scaleConfig.get("itemcell")); @@ -41,7 +42,7 @@ protected void initialize() { public void onViewInit() { this.setBackground(AppThemeColor.TRANSPARENT); this.getRootPane().setBorder(null); - this.add(itemsGridPanel,BorderLayout.CENTER); + this.add(itemsGridPanel, BorderLayout.CENTER); this.setPreferredSize(this.getMaximumSize()); this.pack(); } @@ -49,16 +50,16 @@ public void onViewInit() { @Override public void subscribe() { MercuryStoreUI.showItemGridSubject.subscribe(message -> { - if(this.applicationConfig.get().isItemsGridEnable()) { + if (this.applicationConfig.get().isItemsGridEnable()) { if (itemsGridPanel.getActiveTabsCount() == 0) { this.setVisible(true); } - this.itemsGridPanel.add(message,null); + this.itemsGridPanel.add(message, null); this.pack(); } }); MercuryStoreCore.removeNotificationSubject.subscribe(message -> { - if(message instanceof ItemTradeNotificationDescriptor) { + if (message instanceof ItemTradeNotificationDescriptor) { this.itemsGridPanel.remove((ItemTradeNotificationDescriptor) message); if (itemsGridPanel.getActiveTabsCount() == 0) { this.setVisible(false); @@ -78,10 +79,11 @@ public void subscribe() { this.pack(); }); } + @Override protected void onLock() { super.onLock(); - if(itemsGridPanel.getActiveTabsCount() > 0){ + if (itemsGridPanel.getActiveTabsCount() > 0) { this.setVisible(true); } } @@ -92,7 +94,7 @@ protected JPanel getPanelForPINSettings() { JPanel topPanel = componentsFactory.getTransparentPanel(new BorderLayout()); topPanel.setBackground(AppThemeColor.FRAME); JPanel headerPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - JPanel defaultGridPanel = componentsFactory.getTransparentPanel(new GridLayout(12,12)); + JPanel defaultGridPanel = componentsFactory.getTransparentPanel(new GridLayout(12, 12)); defaultGridPanel.setBorder(null); for (int x = 0; x < 12; x++) { for (int y = 0; y < 12; y++) { @@ -101,7 +103,7 @@ protected JPanel getPanelForPINSettings() { } defaultGridPanel.setBackground(AppThemeColor.FRAME_ALPHA); - JPanel quadGridPanel = componentsFactory.getTransparentPanel(new GridLayout(24,24)); + JPanel quadGridPanel = componentsFactory.getTransparentPanel(new GridLayout(24, 24)); quadGridPanel.setBorder(null); for (int x = 0; x < 24; x++) { for (int y = 0; y < 24; y++) { @@ -112,14 +114,14 @@ protected JPanel getPanelForPINSettings() { JPanel labelPanel = componentsFactory.getTransparentPanel(new BorderLayout()); JComboBox tabType = componentsFactory.getComboBox(new String[]{"1x1", "4x4"}); tabType.addItemListener(e -> { - if(e.getStateChange() == ItemEvent.SELECTED){ - String item = (String)e.getItem(); - if(item.equals("4x4")){ + if (e.getStateChange() == ItemEvent.SELECTED) { + String item = (String) e.getItem(); + if (item.equals("4x4")) { panel.remove(defaultGridPanel); panel.add(quadGridPanel, BorderLayout.CENTER); this.pack(); this.repaint(); - }else { + } else { panel.remove(quadGridPanel); panel.add(defaultGridPanel, BorderLayout.CENTER); this.pack(); @@ -127,17 +129,17 @@ protected JPanel getPanelForPINSettings() { } } }); - tabType.setPreferredSize(new Dimension((int)(componentsFactory.getScale() * 70),tabType.getHeight())); + tabType.setPreferredSize(new Dimension((int) (componentsFactory.getScale() * 70), tabType.getHeight())); - labelPanel.add(this.componentsFactory.wrapToSlide(tabType,AppThemeColor.FRAME),BorderLayout.LINE_START); - Color titleColor = this.applicationConfig.get().isItemsGridEnable()?AppThemeColor.TEXT_NICKNAME:AppThemeColor.TEXT_DISABLE; + labelPanel.add(this.componentsFactory.wrapToSlide(tabType, AppThemeColor.FRAME), BorderLayout.LINE_START); + Color titleColor = this.applicationConfig.get().isItemsGridEnable() ? AppThemeColor.TEXT_NICKNAME : AppThemeColor.TEXT_DISABLE; JLabel titleLabel = componentsFactory.getTextLabel(FontStyle.BOLD, titleColor, TextAlignment.LEFTOP, 20f, "Align this grid(approximately)"); - labelPanel.add(titleLabel,BorderLayout.CENTER); + labelPanel.add(titleLabel, BorderLayout.CENTER); headerPanel.add(labelPanel, BorderLayout.CENTER); - String title = (this.applicationConfig.get().isItemsGridEnable())?"Disable" : "Enable"; + String title = (this.applicationConfig.get().isItemsGridEnable()) ? "Disable" : "Enable"; JButton disableButton = componentsFactory.getBorderedButton(title); - disableButton.setPreferredSize(new Dimension((int)(90*componentsFactory.getScale()),(int)(24*componentsFactory.getScale()))); + disableButton.setPreferredSize(new Dimension((int) (90 * componentsFactory.getScale()), (int) (24 * componentsFactory.getScale()))); componentsFactory.setUpToggleCallbacks(disableButton, () -> { disableButton.setText("Enable"); @@ -150,13 +152,13 @@ protected JPanel getPanelForPINSettings() { titleLabel.setForeground(AppThemeColor.TEXT_NICKNAME); applicationConfig.get().setItemsGridEnable(true); repaint(); - },this.applicationConfig.get().isItemsGridEnable()); - JButton hideButton = componentsFactory.getBorderedButton("Save"); - hideButton.setPreferredSize(new Dimension((int)(90*componentsFactory.getScale()),(int)(24*componentsFactory.getScale()))); + }, this.applicationConfig.get().isItemsGridEnable()); + JButton hideButton = componentsFactory.getBorderedButton("Save"); + hideButton.setPreferredSize(new Dimension((int) (90 * componentsFactory.getScale()), (int) (24 * componentsFactory.getScale()))); hideButton.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { stashTabsContainer.save(); MercuryStoreCore.saveConfigSubject.onNext(true); FramesManager.INSTANCE.disableMovement(ItemsGridFrame.class); @@ -168,7 +170,7 @@ public void mousePressed(MouseEvent e) { disablePanel.add(hideButton); JPanel savedTabsPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - savedTabsPanel.setPreferredSize(new Dimension(50,(int)(56*componentsFactory.getScale()))); + savedTabsPanel.setPreferredSize(new Dimension(50, (int) (56 * componentsFactory.getScale()))); tabsContainer = new HorizontalScrollContainer(); tabsContainer.setLayout(new FlowLayout(FlowLayout.LEFT)); tabsContainer.setBackground(AppThemeColor.TRANSPARENT); @@ -188,26 +190,26 @@ public void mouseWheelMoved(MouseWheelEvent e) { hBar.setUI(new MercuryScrollBarUI()); hBar.setPreferredSize(new Dimension(Integer.MAX_VALUE, 16)); hBar.setUnitIncrement(3); - hBar.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); + hBar.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); hBar.addAdjustmentListener(e -> repaint()); - savedTabsPanel.add(scrollPane,BorderLayout.CENTER); + savedTabsPanel.add(scrollPane, BorderLayout.CENTER); tabsContainer.getParent().setBackground(AppThemeColor.TRANSPARENT); stashTabsContainer.getStashTabDescriptors().forEach(stashTab -> { - TabInfoPanel tabInfoPanel = new TabInfoPanel(stashTab,componentsFactory); + TabInfoPanel tabInfoPanel = new TabInfoPanel(stashTab, componentsFactory); tabsContainer.add(tabInfoPanel); }); - headerPanel.add(disablePanel,BorderLayout.LINE_END); - topPanel.add(headerPanel,BorderLayout.PAGE_START); - topPanel.add(savedTabsPanel,BorderLayout.CENTER); - panel.add(topPanel,BorderLayout.PAGE_START); - panel.add(defaultGridPanel,BorderLayout.CENTER); + headerPanel.add(disablePanel, BorderLayout.LINE_END); + topPanel.add(headerPanel, BorderLayout.PAGE_START); + topPanel.add(savedTabsPanel, BorderLayout.CENTER); + panel.add(topPanel, BorderLayout.PAGE_START); + panel.add(defaultGridPanel, BorderLayout.CENTER); setUpResizePanels(panel); return panel; } - private JPanel getCellPlaceholder(){ + private JPanel getCellPlaceholder() { JPanel cell = new JPanel(); cell.setOpaque(true); cell.setBackground(AppThemeColor.TRANSPARENT); @@ -215,25 +217,25 @@ private JPanel getCellPlaceholder(){ return cell; } - private void setUpResizePanels(JPanel root){ - JLabel rightArrow = componentsFactory.getIconLabel("app/default-mp.png",16); //todo + private void setUpResizePanels(JPanel root) { + JLabel rightArrow = componentsFactory.getIconLabel("app/default-mp.png", 16); //todo JPanel rightPanel = componentsFactory.getTransparentPanel(new BorderLayout()); rightPanel.setBackground(AppThemeColor.FRAME); - rightPanel.add(rightArrow,BorderLayout.CENTER); + rightPanel.add(rightArrow, BorderLayout.CENTER); - rightPanel.addMouseListener(new ArrowMouseListener(rightPanel,new Cursor(Cursor.E_RESIZE_CURSOR))); + rightPanel.addMouseListener(new ArrowMouseListener(rightPanel, new Cursor(Cursor.E_RESIZE_CURSOR))); rightPanel.addMouseMotionListener(new ResizeByWidthMouseMotionListener()); - JLabel downArrow = componentsFactory.getIconLabel("app/expand-mp.png",16); //todo + JLabel downArrow = componentsFactory.getIconLabel("app/expand-mp.png", 16); //todo JPanel downPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - downPanel.setBorder(BorderFactory.createEmptyBorder(-10,0,0,0)); + downPanel.setBorder(BorderFactory.createEmptyBorder(-10, 0, 0, 0)); downPanel.setBackground(AppThemeColor.FRAME); downPanel.add(downArrow); downPanel.addMouseListener(new ArrowMouseListener(downPanel, new Cursor(Cursor.N_RESIZE_CURSOR))); downPanel.addMouseMotionListener(new ResizeByHeightMouseMotionListener()); - root.add(rightPanel,BorderLayout.LINE_END); - root.add(downPanel,BorderLayout.PAGE_END); + root.add(rightPanel, BorderLayout.LINE_END); + root.add(downPanel, BorderLayout.PAGE_END); } @Override @@ -259,17 +261,20 @@ protected JPanel defaultView(ComponentsFactory factory) { ItemInfoPanelController controller = new ItemInfoPanelController() { @Override - public void hidePanel() {} + public void hidePanel() { + } + @Override - public void changeTabType(@NonNull ItemInfoPanel panel) {} + public void changeTabType(@NonNull ItemInfoPanel panel) { + } }; - defaultView.add(message,controller); - root.add(defaultView,BorderLayout.CENTER); + defaultView.add(message, controller); + root.add(defaultView, BorderLayout.CENTER); return root; } @Override - protected void performScaling(Map scaleData) { + protected void performScaling(Map scaleData) { this.componentsFactory.setScale(scaleData.get("itemcell")); } @@ -281,14 +286,16 @@ public void mouseDragged(MouseEvent e) { setSize(new Dimension(e.getLocationOnScreen().x - frameLocation.x + source.getWidth(), getHeight())); } } + private class ResizeByHeightMouseMotionListener extends MouseMotionAdapter { @Override public void mouseDragged(MouseEvent e) { JPanel source = (JPanel) e.getSource(); Point frameLocation = getLocation(); - setSize(new Dimension(getWidth(),e.getLocationOnScreen().y - frameLocation.y + source.getHeight())); + setSize(new Dimension(getWidth(), e.getLocationOnScreen().y - frameLocation.y + source.getHeight())); } } + private class ArrowMouseListener extends MouseAdapter { private JPanel panel; private Cursor cursor; 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 index 6d5bda08..f99413d2 100644 --- 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 @@ -1,39 +1,30 @@ 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 javax.swing.border.Border; import java.awt.*; -import java.util.*; +import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; +import java.util.Map; public class NotificationFrame extends AbstractMovableComponentFrame { @@ -45,6 +36,7 @@ public class NotificationFrame extends AbstractMovableComponentFrame { private JPanel expandPanel; private JPanel stubExpandPanel; private boolean expanded; + @Override protected void initialize() { super.initialize(); @@ -63,12 +55,12 @@ public void onViewInit() { this.currentOffers = new ArrayList<>(); this.container = new JPanel(); this.container.setBackground(AppThemeColor.TRANSPARENT); - this.container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); + this.container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); this.expandPanel = this.getExpandPanel(); - this.stubExpandPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.TRANSPARENT); + this.stubExpandPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.TRANSPARENT); this.stubExpandPanel.setPreferredSize(this.expandPanel.getPreferredSize()); this.add(this.stubExpandPanel, BorderLayout.LINE_START); - this.add(this.container,BorderLayout.CENTER); + this.add(this.container, BorderLayout.CENTER); this.setVisible(true); this.pack(); } @@ -83,16 +75,16 @@ public void subscribe() { .setComponentsFactory(this.componentsFactory) .build(); String message = StringUtils.substringAfter(notification.getSourceString(), ":"); - if(this.currentOffers.contains(message)){ + if (this.currentOffers.contains(message)) { notificationPanel.setDuplicate(true); - }else { + } else { this.currentOffers.add(message); } this.addNotification(notificationPanel); }); }); MercuryStoreCore.newScannerMessageSubject.subscribe(message -> { - SwingUtilities.invokeLater(()-> { + SwingUtilities.invokeLater(() -> { NotificationPanel notificationPanel = this.providersFactory.getProviderFor(NotificationType.SCANNER_MESSAGE) .setData(message) .setComponentsFactory(this.componentsFactory) @@ -100,8 +92,8 @@ public void subscribe() { 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)); + 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); @@ -127,51 +119,52 @@ public void subscribe() { }); MercuryStoreCore.hotKeySubject.subscribe(hotkeyDescriptor -> { SwingUtilities.invokeLater(() -> { - if(this.notificationPanels.size() > 0 && ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)){ + 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)){ + if (this.config.get().getFlowDirections().equals(FlowDirections.DOWNWARDS)) { this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); } }); } - private void addNotification(NotificationPanel notificationPanel){ + private void addNotification(NotificationPanel notificationPanel) { this.notificationPanels.add(notificationPanel); this.container.add(notificationPanel); - if(this.notificationPanels.size() > this.config.get().getLimitCount()){ - if(!this.expanded) { + if (this.notificationPanels.size() > this.config.get().getLimitCount()) { + if (!this.expanded) { notificationPanel.setVisible(false); } this.remove(this.stubExpandPanel); - this.add(this.expandPanel,BorderLayout.LINE_START); + this.add(this.expandPanel, BorderLayout.LINE_START); } this.pack(); this.repaint(); - 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)); + 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)); } } - private void removeNotification(NotificationPanel notificationPanel){ + + private void removeNotification(NotificationPanel notificationPanel) { notificationPanel.onViewDestroy(); int limitCount = this.config.get().getLimitCount(); - if(!this.expanded && this.notificationPanels.size() > limitCount){ + 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()){ + if (this.notificationPanels.size() - 1 < this.config.get().getLimitCount()) { this.remove(this.expandPanel); - this.add(this.stubExpandPanel,BorderLayout.LINE_START); + this.add(this.stubExpandPanel, BorderLayout.LINE_START); } this.pack(); this.repaint(); - if(this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) - && this.notificationPanels.size() == 0){ + if (this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) + && this.notificationPanels.size() == 0) { this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); } } @@ -181,29 +174,29 @@ protected void onScaleLock() { JPanel var = this.expandPanel; this.expandPanel = this.getExpandPanel(); this.stubExpandPanel.setPreferredSize(this.expandPanel.getPreferredSize()); - if(this.notificationPanels.size() > this.config.get().getLimitCount()){ + if (this.notificationPanels.size() > this.config.get().getLimitCount()) { this.remove(var); - this.add(this.expandPanel,BorderLayout.LINE_START); + this.add(this.expandPanel, BorderLayout.LINE_START); } super.onScaleLock(); } @Override protected JPanel getPanelForPINSettings() { - JPanel root = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); - JPanel panel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); - panel.setBorder(BorderFactory.createMatteBorder(0,1,0,0,AppThemeColor.BORDER)); + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + JPanel panel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + panel.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, AppThemeColor.BORDER)); JLabel textLabel = this.componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 22f, "Notification panel"); textLabel.setHorizontalAlignment(SwingConstants.CENTER); - panel.add(textLabel,BorderLayout.CENTER); + panel.add(textLabel, BorderLayout.CENTER); - JPanel limitPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + JPanel limitPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); limitPanel.setPreferredSize(this.expandPanel.getPreferredSize()); - JLabel expandIconLabel = componentsFactory.getIconLabel("app/expand_button_pin.png",24,SwingConstants.CENTER); + JLabel expandIconLabel = componentsFactory.getIconLabel("app/expand_button_pin.png", 24, SwingConstants.CENTER); limitPanel.add(expandIconLabel, BorderLayout.CENTER); - root.add(panel,BorderLayout.CENTER); - root.add(limitPanel,BorderLayout.LINE_START); - root.setPreferredSize(new Dimension((int)(400 * componentsFactory.getScale()), (int)(110*componentsFactory.getScale()))); + root.add(panel, BorderLayout.CENTER); + root.add(limitPanel, BorderLayout.LINE_START); + root.setPreferredSize(new Dimension((int) (400 * componentsFactory.getScale()), (int) (110 * componentsFactory.getScale()))); return root; } @@ -221,12 +214,13 @@ protected void performScaling(Map scaleData) { 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.setLayout(new BoxLayout(root, BoxLayout.Y_AXIS)); root.add(this.providersFactory .getProviderFor(NotificationType.INC_ITEM_MESSAGE) @@ -248,23 +242,23 @@ protected LayoutManager getFrameLayout() { return new BorderLayout(); } - private JPanel getExpandPanel(){ + 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.MSG_HEADER_BORDER))); + BorderFactory.createMatteBorder(1, 1, 1, 0, AppThemeColor.FRAME), + BorderFactory.createMatteBorder(1, 1, 1, 1, AppThemeColor.MSG_HEADER_BORDER))); String iconPath = "app/collapse-all.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath,22,AppThemeColor.MSG_HEADER,""); + 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)); + 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)); + } else { + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-all.png", 22)); this.notificationPanels.forEach(it -> { if (!it.isVisible()) { it.setVisible(true); @@ -276,7 +270,7 @@ private JPanel getExpandPanel(){ this.repaint(); }); expandButton.setAlignmentY(SwingConstants.CENTER); - root.add(expandButton,BorderLayout.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 31e191c6..875255fa 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 @@ -15,7 +15,9 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.Map; public class TaskBarFrame extends AbstractMovableComponentFrame { @@ -35,14 +37,16 @@ public TaskBarFrame() { this.prevState = FrameVisibleState.SHOW; } - private void enableCollapseAnimation(){ + private void enableCollapseAnimation() { this.setWidth(MIN_WIDTH); this.addMouseListener(collapseListener); } - private void disableCollapseAnimation(){ + + private void disableCollapseAnimation() { this.setWidth(MAX_WIDTH); this.removeMouseListener(collapseListener); } + @Override protected LayoutManager getFrameLayout() { return new BorderLayout(); @@ -51,30 +55,33 @@ protected LayoutManager getFrameLayout() { @Override public void subscribe() { } - private void initCollapseAnimations(String state){ + + private void initCollapseAnimations(String state) { collapseAnimation = new Timeline(this); - switch (state){ - case "expand":{ - collapseAnimation.addPropertyToInterpolate("width",this.getWidth(),MAX_WIDTH); + switch (state) { + case "expand": { + collapseAnimation.addPropertyToInterpolate("width", this.getWidth(), MAX_WIDTH); break; } - case "collapse":{ - collapseAnimation.addPropertyToInterpolate("width",this.getWidth(),MIN_WIDTH); + case "collapse": { + collapseAnimation.addPropertyToInterpolate("width", this.getWidth(), MIN_WIDTH); } } collapseAnimation.setEase(new Spline(1f)); collapseAnimation.setDuration(150); } - private boolean withInPanel(JPanel panel){ - return new Rectangle(panel.getLocationOnScreen(),panel.getSize()).contains(MouseInfo.getPointerInfo().getLocation()); + + private boolean withInPanel(JPanel panel) { + return new Rectangle(panel.getLocationOnScreen(), panel.getSize()).contains(MouseInfo.getPointerInfo().getLocation()); } /** * For 'trident' property animations + * * @param width next width */ - public void setWidth(int width){ - this.setSize(new Dimension(width,this.getHeight())); + public void setWidth(int width) { + this.setSize(new Dimension(width, this.getHeight())); } @Override @@ -86,7 +93,7 @@ protected void onLock() { @Override protected JPanel getPanelForPINSettings() { this.disableCollapseAnimation(); - JPanel panel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.FRAME); + 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); @@ -100,7 +107,7 @@ protected void registerDirectScaleHandler() { } @Override - protected void performScaling(Map scaleData) { + protected void performScaling(Map scaleData) { this.componentsFactory.setScale(scaleData.get("taskbar")); onViewInit(); } @@ -108,7 +115,7 @@ protected void performScaling(Map scaleData) { @Override public void onViewInit() { JPanel panel = componentsFactory.getTransparentPanel(new BorderLayout()); - taskBarPanel = new TaskBarPanel(new MercuryTaskBarController(),componentsFactory); + taskBarPanel = new TaskBarPanel(new MercuryTaskBarController(), componentsFactory); panel.add(taskBarPanel, BorderLayout.CENTER); panel.setBackground(AppThemeColor.FRAME); mainContainer = panel; @@ -134,7 +141,7 @@ public void mouseEntered(MouseEvent e) { @Override public void mouseExited(MouseEvent e) { TaskBarFrame.this.repaint(); - if(isVisible() && !withInPanel((JPanel)TaskBarFrame.this.getContentPane()) && !EResizeSpace) { + if (isVisible() && !withInPanel((JPanel) TaskBarFrame.this.getContentPane()) && !EResizeSpace) { if (collapseAnimation != null) { collapseAnimation.abort(); } @@ -150,35 +157,54 @@ public void mouseExited(MouseEvent e) { protected JPanel defaultView(ComponentsFactory factory) { TaskBarController controller = new TaskBarController() { @Override - public void enableDND() {} + public void enableDND() { + } + @Override - public void disableDND() {} + public void disableDND() { + } + @Override - public void showITH() {} + public void showITH() { + } + @Override - public void performHideout() {} + public void performHideout() { + } + @Override - public void showChatFiler() {} + public void showChatFiler() { + } + @Override - public void showHistory() {} + public void showHistory() { + } + @Override - public void openPINSettings() {} + public void openPINSettings() { + } + @Override - public void openScaleSettings() {} + public void openScaleSettings() { + } + @Override - public void showSettings() {} + public void showSettings() { + } + @Override - public void exit() {} + public void exit() { + } }; JPanel panel = factory.getTransparentPanel(new BorderLayout()); TaskBarPanel taskBarPanel = new TaskBarPanel(controller, factory); - panel.add(new TaskBarPanel(controller,factory), BorderLayout.CENTER); + panel.add(new TaskBarPanel(controller, factory), BorderLayout.CENTER); panel.setBackground(AppThemeColor.FRAME); this.MIN_WIDTH = taskBarPanel.getWidthOf(4); this.MAX_WIDTH = taskBarPanel.getPreferredSize().width; - this.setSize(new Dimension(MIN_WIDTH,this.getHeight())); - this.setMinimumSize(new Dimension(MIN_WIDTH,taskBarPanel.getHeight())); - this.setMaximumSize(new Dimension(MAX_WIDTH,taskBarPanel.getHeight())); + this.setSize(new Dimension(MIN_WIDTH, this.getHeight())); + this.setMinimumSize(new Dimension(MIN_WIDTH, taskBarPanel.getHeight())); + this.setMaximumSize(new Dimension(MAX_WIDTH, taskBarPanel.getHeight())); return panel; } } 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 47c61b5f..0a97e1b5 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 @@ -11,13 +11,16 @@ public class AlertFrame extends AbstractOverlaidFrame { private JLabel messageLabel; + public AlertFrame() { super(); } + @Override protected void initialize() { this.getRootPane().setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); } + @Override public void onViewInit() { JPanel messagePanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); @@ -34,8 +37,8 @@ public void mousePressed(MouseEvent e) { }); close.setPreferredSize(new Dimension(80, 26)); closePanel.add(close); - this.add(messagePanel,BorderLayout.CENTER); - this.add(closePanel,BorderLayout.PAGE_END); + this.add(messagePanel, BorderLayout.CENTER); + this.add(closePanel, BorderLayout.PAGE_END); this.pack(); } @@ -47,7 +50,7 @@ public void subscribe() { this.pack(); this.setVisible(true); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); + 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/other/MercuryLoadingFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/MercuryLoadingFrame.java index 83428987..a2e98ba7 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 @@ -7,6 +7,7 @@ import com.mercury.platform.ui.misc.AppThemeColor; import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.callback.TimelineCallback; + import java.awt.*; @@ -14,6 +15,7 @@ public class MercuryLoadingFrame extends AbstractOverlaidFrame { private Timeline hideAnimation; private Timeline showAnimation; private MercuryLoading loadingTracker; + public MercuryLoadingFrame() { super(); processingHideEvent = false; @@ -55,19 +57,20 @@ public void onViewInit() { this.loadingTracker.playLoop(); this.loadingTracker.setForeground(AppThemeColor.ADR_FOOTER_BG); this.loadingTracker.setBackground(AppThemeColor.BORDER_GREEN); - this.loadingTracker.setPreferredSize(new Dimension(200,200)); + this.loadingTracker.setPreferredSize(new Dimension(200, 200)); hideAnimation = new Timeline(this); hideAnimation.setDuration(400); hideAnimation.addPropertyToInterpolate("opacity", 1f, 0f); hideAnimation.addCallback(new TimelineCallback() { @Override public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { - if(newState.equals(Timeline.TimelineState.DONE)){ + if (newState.equals(Timeline.TimelineState.DONE)) { setAlwaysOnTop(false); setVisible(false); loadingTracker.abort(); } } + @Override public void onTimelinePulse(float durationFraction, float timelinePosition) { } @@ -79,6 +82,6 @@ public void onTimelinePulse(float durationFraction, float timelinePosition) { this.add(this.loadingTracker); this.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); + 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/other/NotificationAlertFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationAlertFrame.java index dad36168..c6b507af 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationAlertFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/NotificationAlertFrame.java @@ -14,6 +14,7 @@ public class NotificationAlertFrame extends AbstractOverlaidFrame { private JLabel messageLabel; private Timeline showAnimation; + public NotificationAlertFrame() { super(); } @@ -30,7 +31,7 @@ public void subscribe() { 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.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2); this.setAlwaysOnTop(true); this.setVisible(true); this.showAnimation.abort(); @@ -45,7 +46,7 @@ protected LayoutManager getFrameLayout() { @Override public void onViewInit() { - this.messageLabel = componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER,38,""); + this.messageLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_DEFAULT, TextAlignment.CENTER, 38, ""); this.showAnimation = new Timeline(this); this.showAnimation.setDuration(1400); @@ -53,13 +54,14 @@ public void onViewInit() { 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)){ + 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) { } 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 27cb3e77..cce30ce5 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 @@ -17,7 +17,7 @@ public SetUpLocationFrame() { @Override protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 2), BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); } @@ -25,12 +25,12 @@ protected void initialize() { public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,0,6)); + rootPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 0, 6)); JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); root.setBackground(AppThemeColor.SLIDE_BG); - root.add(componentsFactory.getSimpleTextArea("Panels UNLOCKED Move them and click Lock when done."),BorderLayout.CENTER); + root.add(componentsFactory.getSimpleTextArea("Panels UNLOCKED Move them and click Lock when done."), BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JButton restoreDefault = componentsFactory.getBorderedButton("Restore defaults"); @@ -60,13 +60,13 @@ public void mousePressed(MouseEvent e) { miscPanel.add(restoreDefault); miscPanel.add(lock); - rootPanel.add(root,BorderLayout.CENTER); - this.add(rootPanel,BorderLayout.CENTER); - this.add(miscPanel,BorderLayout.PAGE_END); - this.setPreferredSize(new Dimension(300,100)); + rootPanel.add(root, BorderLayout.CENTER); + this.add(rootPanel, BorderLayout.CENTER); + this.add(miscPanel, BorderLayout.PAGE_END); + this.setPreferredSize(new Dimension(300, 100)); this.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/4-this.getSize().height/2); + this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 4 - this.getSize().height / 2); } @Override 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 174f6ea9..cf75fb59 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 @@ -15,7 +15,8 @@ import java.util.Map; public class SetUpScaleFrame extends AbstractOverlaidFrame { - private Map scaleData; + private Map scaleData; + public SetUpScaleFrame() { super(); } @@ -23,7 +24,7 @@ public SetUpScaleFrame() { @Override protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), + BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 2), BorderFactory.createLineBorder(AppThemeColor.BORDER, 1))); this.scaleData = this.scaleConfig.getMap(); } @@ -32,15 +33,15 @@ protected void initialize() { public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,0,6)); + rootPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 0, 6)); JPanel header = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); - header.add(componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP,18f,"Scale settings")); + header.add(componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 18f, "Scale settings")); JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); root.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); root.setBackground(AppThemeColor.SLIDE_BG); - root.add(getScaleSettingsPanel(),BorderLayout.CENTER); + root.add(getScaleSettingsPanel(), BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JButton cancel = componentsFactory.getBorderedButton("Cancel"); @@ -71,24 +72,24 @@ public void mousePressed(MouseEvent e) { miscPanel.add(cancel); miscPanel.add(save); - rootPanel.add(root,BorderLayout.CENTER); - this.add(header,BorderLayout.PAGE_START); - this.add(rootPanel,BorderLayout.CENTER); - this.add(miscPanel,BorderLayout.PAGE_END); + rootPanel.add(root, BorderLayout.CENTER); + this.add(header, BorderLayout.PAGE_START); + this.add(rootPanel, BorderLayout.CENTER); + this.add(miscPanel, BorderLayout.PAGE_END); this.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/4-this.getSize().height/2); + this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 4 - this.getSize().height / 2); } - private JPanel getScaleSettingsPanel(){ - JPanel root = componentsFactory.getTransparentPanel(new GridLayout(3,1)); + private JPanel getScaleSettingsPanel() { + JPanel root = componentsFactory.getTransparentPanel(new GridLayout(3, 1)); JLabel notificationLabel = componentsFactory.getTextLabel( FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 17f, "Notification panel: "); - JSlider notificationSlider = componentsFactory.getSlider(9,15, (int) (scaleData.get("notification")*10)); + JSlider notificationSlider = componentsFactory.getSlider(9, 15, (int) (scaleData.get("notification") * 10)); JLabel notificationValue = componentsFactory.getTextLabel( FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, @@ -96,16 +97,17 @@ private JPanel getScaleSettingsPanel(){ 17f, String.valueOf(notificationSlider.getValue() * 10) + "%"); notificationValue.setBorder(null); - notificationSlider.addChangeListener((event)-> repaint()); + notificationSlider.addChangeListener((event) -> repaint()); notificationSlider.addMouseListener(new MouseAdapter() { private int prevValue = 10; + @Override public void mouseReleased(MouseEvent e) { - if(notificationSlider.getValue() != prevValue){ + if (notificationSlider.getValue() != prevValue) { prevValue = notificationSlider.getValue(); - notificationValue.setText(String.valueOf(notificationSlider.getValue() * 10)+ "%"); - scaleData.put("notification",notificationSlider.getValue()/10f); - MercuryStoreUI.notificationScaleSubject.onNext(notificationSlider.getValue()/10f); + notificationValue.setText(String.valueOf(notificationSlider.getValue() * 10) + "%"); + scaleData.put("notification", notificationSlider.getValue() / 10f); + MercuryStoreUI.notificationScaleSubject.onNext(notificationSlider.getValue() / 10f); repaint(); } } @@ -118,24 +120,25 @@ public void mouseReleased(MouseEvent e) { 17f, "Task panel: "); - JSlider taskBarSlider = componentsFactory.getSlider(9,15, (int) (scaleData.get("taskbar")*10)); + JSlider taskBarSlider = componentsFactory.getSlider(9, 15, (int) (scaleData.get("taskbar") * 10)); JLabel taskBarValue = componentsFactory.getTextLabel( FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 17f, - String.valueOf(taskBarSlider.getValue() * 10)+ "%"); + String.valueOf(taskBarSlider.getValue() * 10) + "%"); taskBarValue.setBorder(null); - taskBarSlider.addChangeListener((event)-> repaint()); + taskBarSlider.addChangeListener((event) -> repaint()); taskBarSlider.addMouseListener(new MouseAdapter() { private int prevValue = 10; + @Override public void mouseReleased(MouseEvent e) { - if(taskBarSlider.getValue() != prevValue){ + if (taskBarSlider.getValue() != prevValue) { prevValue = taskBarSlider.getValue(); - taskBarValue.setText(String.valueOf(taskBarSlider.getValue() * 10)+ "%"); - scaleData.put("taskbar",taskBarSlider.getValue()/10f); - MercuryStoreUI.taskBarScaleSubject.onNext(taskBarSlider.getValue()/10f); + taskBarValue.setText(String.valueOf(taskBarSlider.getValue() * 10) + "%"); + scaleData.put("taskbar", taskBarSlider.getValue() / 10f); + MercuryStoreUI.taskBarScaleSubject.onNext(taskBarSlider.getValue() / 10f); repaint(); } } @@ -147,32 +150,33 @@ public void mouseReleased(MouseEvent e) { TextAlignment.LEFTOP, 17f, "Item cell panel: "); - JSlider itemInfoSlider = componentsFactory.getSlider(9,15, (int) (scaleData.get("itemcell") * 10)); + JSlider itemInfoSlider = componentsFactory.getSlider(9, 15, (int) (scaleData.get("itemcell") * 10)); JLabel itemInfoValue = componentsFactory.getTextLabel( FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 17f, - String.valueOf(itemInfoSlider.getValue() * 10)+ "%"); + String.valueOf(itemInfoSlider.getValue() * 10) + "%"); itemInfoValue.setBorder(null); - itemInfoSlider.addChangeListener((event)-> repaint()); + itemInfoSlider.addChangeListener((event) -> repaint()); itemInfoSlider.addMouseListener(new MouseAdapter() { private int prevValue = 10; + @Override public void mouseReleased(MouseEvent e) { - if(itemInfoSlider.getValue() != prevValue){ + if (itemInfoSlider.getValue() != prevValue) { prevValue = itemInfoSlider.getValue(); - itemInfoValue.setText(String.valueOf(itemInfoSlider.getValue() * 10)+ "%"); - scaleData.put("itemcell",itemInfoSlider.getValue()/10f); - MercuryStoreUI.itemPanelScaleSubject.onNext(itemInfoSlider.getValue()/10f); + itemInfoValue.setText(String.valueOf(itemInfoSlider.getValue() * 10) + "%"); + scaleData.put("itemcell", itemInfoSlider.getValue() / 10f); + MercuryStoreUI.itemPanelScaleSubject.onNext(itemInfoSlider.getValue() / 10f); repaint(); } } }); - root.add(componentsFactory.getSliderSettingsPanel(notificationLabel,notificationValue,notificationSlider)); - root.add(componentsFactory.getSliderSettingsPanel(taskBarLabel,taskBarValue,taskBarSlider)); - root.add(componentsFactory.getSliderSettingsPanel(itemInfoLabel,itemInfoValue,itemInfoSlider)); + root.add(componentsFactory.getSliderSettingsPanel(notificationLabel, notificationValue, notificationSlider)); + root.add(componentsFactory.getSliderSettingsPanel(taskBarLabel, taskBarValue, taskBarSlider)); + root.add(componentsFactory.getSliderSettingsPanel(itemInfoLabel, itemInfoValue, itemInfoSlider)); return root; } 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 b9bf6b10..f2c5d3d4 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 @@ -11,6 +11,7 @@ public class TooltipFrame extends AbstractOverlaidFrame { private Timer tooltipTimer; + public TooltipFrame() { super(); } @@ -19,26 +20,27 @@ public TooltipFrame() { protected void initialize() { this.componentsFactory.setScale(1.1f); } + @Override public void subscribe() { MercuryStoreCore.tooltipSubject.subscribe(tooltip -> { - if(tooltip != null){ + if (tooltip != null) { this.getContentPane().removeAll(); this.setPreferredSize(null); - if(tooltip.toCharArray().length < 85){ - JLabel tooltipLabel = componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP,16f,tooltip); - this.add(tooltipLabel,BorderLayout.CENTER); - }else { + if (tooltip.toCharArray().length < 85) { + JLabel tooltipLabel = componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 16f, tooltip); + this.add(tooltipLabel, BorderLayout.CENTER); + } else { JTextArea tooltipArea = componentsFactory.getSimpleTextArea(""); - this.add(tooltipArea,BorderLayout.CENTER); + this.add(tooltipArea, BorderLayout.CENTER); tooltipArea.setText(tooltip); - if(tooltip.toCharArray().length < 120){ - if(tooltip.toCharArray().length < 85){ + if (tooltip.toCharArray().length < 120) { + if (tooltip.toCharArray().length < 85) { this.setPreferredSize(new Dimension(320, 55)); - }else { + } else { this.setPreferredSize(new Dimension(320, 75)); } - }else { + } else { this.setPreferredSize(new Dimension(320, 145)); } } @@ -47,17 +49,17 @@ public void subscribe() { this.tooltipTimer = new Timer(500, e -> { Point cursorPoint = MouseInfo.getPointerInfo().getLocation(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - if(cursorPoint.y + this.getPreferredSize().height > dim.height){ - this.setLocation(cursorPoint.x + 4,cursorPoint.y - this.getPreferredSize().height); - }else { - this.setLocation(new Point(cursorPoint.x + 4,cursorPoint.y)); + if (cursorPoint.y + this.getPreferredSize().height > dim.height) { + this.setLocation(cursorPoint.x + 4, cursorPoint.y - this.getPreferredSize().height); + } else { + this.setLocation(new Point(cursorPoint.x + 4, cursorPoint.y)); } this.tooltipTimer.stop(); setVisible(true); }); this.tooltipTimer.start(); - }else { - if(tooltipTimer != null) { + } else { + if (tooltipTimer != null) { this.tooltipTimer.stop(); this.setVisible(false); } @@ -72,9 +74,9 @@ protected LayoutManager getFrameLayout() { @Override public void onViewInit() { - this.setOpacity(this.applicationConfig.get().getMaxOpacity()/100f); + this.setOpacity(this.applicationConfig.get().getMaxOpacity() / 100f); this.getRootPane().setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.BORDER, 1), - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2))); + 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 46d4f805..07efe82e 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 @@ -22,16 +22,18 @@ public UpdateReadyFrame() { @Override protected void initialize() { this.getRootPane().setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT,2), + 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.setOpacity(this.applicationConfig.get().getMaxOpacity() / 100f); this.pack(); } - private JPanel getUpdatePanel(){ + + private JPanel getUpdatePanel() { JPanel panel = componentsFactory.getTransparentPanel(); panel.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel label = componentsFactory.getTextLabel( @@ -76,13 +78,13 @@ public void subscribe() { FrameDescriptor tbSettings = this.framesConfig.get("TaskBarFrame"); Point tbLocation = tbSettings.getFrameLocation(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - if(tbLocation.y + 30 + this.getHeight() > dim.height){ - this.setLocation(tbLocation.x,tbLocation.y - 44); - }else { + if (tbLocation.y + 30 + this.getHeight() > dim.height) { + this.setLocation(tbLocation.x, tbLocation.y - 44); + } else { this.setLocation(tbLocation.x, tbLocation.y + 44); } int deltaWidth = dim.width - (this.getLocation().x + this.getWidth()); - if(deltaWidth < 0){ + if (deltaWidth < 0) { this.setLocation(tbLocation.x - Math.abs(deltaWidth), this.getLocation().y); } if (!this.isVisible() && ProdStarter.APP_STATUS == FrameVisibleState.SHOW) { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/SetUpCommander.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/SetUpCommander.java index 562d8d2b..41fcf9c0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/SetUpCommander.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/SetUpCommander.java @@ -6,7 +6,7 @@ import java.util.Map; public abstract class SetUpCommander { - protected Map frames; + protected Map frames; protected List activeFrames; public SetUpCommander() { @@ -14,12 +14,17 @@ public SetUpCommander() { this.activeFrames = new ArrayList<>(); } - public void addFrame(T frame){ + public void addFrame(T frame) { frames.put(frame.getClass(), frame); } + public abstract void setUpAll(); + public abstract void setUpAllExclude(Class... framesClasses); + public abstract void setOrEndUp(Class frameClass, boolean showingSetUpFrame); + public abstract void endUpAll(); + public abstract void endUp(Class frameClass); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java index b371fcbb..96dcebd8 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/location/SetUpLocationCommander.java @@ -5,16 +5,18 @@ import com.mercury.platform.ui.frame.setup.SetUpCommander; import com.mercury.platform.ui.manager.FramesManager; -import java.util.*; +import java.util.Arrays; +import java.util.List; -public class SetUpLocationCommander extends SetUpCommander{ +public class SetUpLocationCommander extends SetUpCommander { public SetUpLocationCommander() { super(); } + @Override - public void setUpAll(){ - this.frames.forEach((title,frame)->{ - this.enableMovement(frame,true); + public void setUpAll() { + this.frames.forEach((title, frame) -> { + this.enableMovement(frame, true); this.activeFrames.add(frame); }); } @@ -22,9 +24,9 @@ public void setUpAll(){ @Override public void setUpAllExclude(Class[] framesClasses) { List framesList = Arrays.asList(framesClasses); - this.frames.forEach((title, frame)->{ - if(!framesList.contains(title)) { - this.enableMovement(frame,true); + this.frames.forEach((title, frame) -> { + if (!framesList.contains(title)) { + this.enableMovement(frame, true); this.activeFrames.add(frame); } }); @@ -33,10 +35,10 @@ public void setUpAllExclude(Class[] framesClasses) { @Override public void setOrEndUp(Class frameClass, boolean showingSetUpFrame) { AbstractMovableComponentFrame frame = frames.get(frameClass); - if(frame.getMoveState().equals(LocationState.DEFAULT)){ - this.enableMovement(frame,showingSetUpFrame); + if (frame.getMoveState().equals(LocationState.DEFAULT)) { + this.enableMovement(frame, showingSetUpFrame); this.activeFrames.add(frame); - }else { + } else { this.disableMovement(frame); this.activeFrames.remove(frame); } @@ -54,13 +56,15 @@ public void endUp(Class frameClass) { this.disableMovement(frame); this.activeFrames.remove(frame); } - private void enableMovement(AbstractMovableComponentFrame frame, boolean showSetUpFrame){ + + private void enableMovement(AbstractMovableComponentFrame frame, boolean showSetUpFrame) { frame.setState(LocationState.MOVING); - if(showSetUpFrame){ + if (showSetUpFrame) { FramesManager.INSTANCE.showFrame(SetUpLocationFrame.class); } } - private void disableMovement(AbstractMovableComponentFrame frame){ + + private void disableMovement(AbstractMovableComponentFrame frame) { frame.setState(LocationState.DEFAULT); FramesManager.INSTANCE.hideFrame(SetUpLocationFrame.class); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java index 2c93769d..69239c63 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/SetUpScaleCommander.java @@ -4,13 +4,14 @@ import com.mercury.platform.ui.frame.AbstractScalableComponentFrame; import com.mercury.platform.ui.frame.setup.SetUpCommander; -public class SetUpScaleCommander extends SetUpCommander{ +public class SetUpScaleCommander extends SetUpCommander { public SetUpScaleCommander() { super(); } + @Override public void setUpAll() { - this.frames.forEach((k,v) -> { + this.frames.forEach((k, v) -> { v.setState(ScaleState.ENABLE); }); } @@ -27,7 +28,7 @@ public void setOrEndUp(Class frameClass, boolean showingSetUpFrame) { @Override public void endUpAll() { - this.frames.forEach((k,v) -> { + this.frames.forEach((k, v) -> { v.setState(ScaleState.DEFAULT); }); } 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 ed307257..3d7153ba 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 @@ -5,14 +5,13 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; public abstract class AbstractTitledComponentFrame extends AbstractComponentFrame { protected JPanel miscPanel; protected JButton hideButton; protected JPanel headerPanel; private JLabel frameTitleLabel; + protected AbstractTitledComponentFrame() { super(); } @@ -23,12 +22,12 @@ protected void initialize() { this.initHeaderPanel(); } - private void initHeaderPanel(){ - if(layout instanceof BorderLayout) { + private void initHeaderPanel() { + if (layout instanceof BorderLayout) { this.headerPanel = new JPanel(new BorderLayout()); this.headerPanel.setBackground(AppThemeColor.HEADER); - this.headerPanel.setPreferredSize(new Dimension(100,26)); - this.headerPanel.setBorder(BorderFactory.createMatteBorder(0,0,1,0,AppThemeColor.MSG_HEADER_BORDER)); + this.headerPanel.setPreferredSize(new Dimension(100, 26)); + this.headerPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, AppThemeColor.MSG_HEADER_BORDER)); JLabel appIcon = componentsFactory.getIconLabel("app/app-icon.png", 16); this.frameTitleLabel = componentsFactory.getTextLabel(getFrameTitle()); @@ -37,25 +36,27 @@ private void initHeaderPanel(){ this.frameTitleLabel.addMouseListener(new DraggedFrameMouseListener()); this.frameTitleLabel.addMouseMotionListener(new DraggedFrameMotionListener()); - appIcon.setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); - this.headerPanel.add(appIcon,BorderLayout.LINE_START); + appIcon.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); + this.headerPanel.add(appIcon, BorderLayout.LINE_START); this.headerPanel.add(this.frameTitleLabel, BorderLayout.CENTER); - this.miscPanel = this.componentsFactory.getJPanel(new BorderLayout(),AppThemeColor.HEADER); + 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,BorderLayout.LINE_END); + this.miscPanel.add(hideButton, BorderLayout.LINE_END); this.headerPanel.add(miscPanel, BorderLayout.LINE_END); this.add(headerPanel, BorderLayout.PAGE_START); } } + protected abstract String getFrameTitle(); public void setFrameTitle(String title) { this.frameTitleLabel.setText(title); } + protected void removeHideButton() { this.miscPanel.remove(hideButton); } 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 index a575b510..1e87f16b 100644 --- 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 @@ -18,8 +18,10 @@ import javax.swing.*; import java.awt.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -28,7 +30,7 @@ public class ChatScannerFrame extends AbstractTitledComponentFrame { private PlainConfigurationService scannerService; private PlainConfigurationService notificationConfig; private MessageInterceptor currentInterceptor; - private Map expiresMessages; + private Map expiresMessages; private HtmlMessageBuilder messageBuilder; private boolean running; @@ -51,7 +53,7 @@ public void onViewInit() { this.initHeaderBar(); JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); JPanel setupArea = componentsFactory.getTransparentPanel(new BorderLayout()); - setupArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + setupArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); JLabel title = componentsFactory.getTextLabel( FontStyle.REGULAR, @@ -59,14 +61,14 @@ public void onViewInit() { TextAlignment.LEFTOP, 15f, "Show messages containing the following words:"); - title.setBorder(BorderFactory.createEmptyBorder(2,0,6,0)); + 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); + JPanel navBar = componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER), AppThemeColor.FRAME); Dimension buttonSize = new Dimension(90, 24); JButton save = componentsFactory.getBorderedButton("Save"); save.addActionListener(action -> { @@ -91,19 +93,19 @@ public void onViewInit() { navBar.add(cancel); navBar.add(save); - setupArea.add(title,BorderLayout.PAGE_START); - setupArea.add(words,BorderLayout.CENTER); + setupArea.add(title, BorderLayout.PAGE_START); + setupArea.add(words, BorderLayout.CENTER); - root.add(setupArea,BorderLayout.CENTER); - root.add(getMemo(),BorderLayout.LINE_END); + root.add(setupArea, BorderLayout.CENTER); + root.add(getMemo(), BorderLayout.LINE_END); - this.add(root,BorderLayout.CENTER); - this.add(navBar,BorderLayout.PAGE_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); + 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, @@ -112,17 +114,17 @@ private void initHeaderBar(){ "Status: stopped"); JButton processButton = componentsFactory.getBorderedButton("Start"); - processButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD,16f)); - processButton.setPreferredSize(new Dimension(80,20)); + processButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 16f)); + processButton.setPreferredSize(new Dimension(80, 20)); processButton.addActionListener(action -> { - if(this.running){ + if (this.running) { this.running = false; processButton.setText("Start"); statusLabel.setText("Status: stopped"); if (this.currentInterceptor != null) { MercuryStoreCore.removeInterceptorSubject.onNext(this.currentInterceptor); } - }else { + } else { this.running = true; processButton.setText("Stop"); statusLabel.setText("Status: running"); @@ -131,10 +133,11 @@ private void initHeaderBar(){ }); root.add(statusLabel); root.add(processButton); - this.miscPanel.add(root,BorderLayout.CENTER); + this.miscPanel.add(root, BorderLayout.CENTER); } - private void performNewStrings(String[] strings){ - if(this.running) { + + private void performNewStrings(String[] strings) { + if (this.running) { List contains = new ArrayList<>(); List notContains = new ArrayList<>(); @@ -168,7 +171,7 @@ protected void process(String stubMessage) { descriptor.setMessage(messageBuilder.build(matcher.group(3))); expiresMessages.put(descriptor.getNickName(), message); - if(notificationConfig.get().isScannerNotificationEnable()) { + if (notificationConfig.get().isScannerNotificationEnable()) { MercuryStoreCore.newScannerMessageSubject.onNext(descriptor); } MercuryStoreCore.soundSubject.onNext(SoundType.CHAT_SCANNER); @@ -195,25 +198,25 @@ protected MessageFilter getFilter() { @Override protected void initialize() { super.initialize(); - this.setPreferredSize(new Dimension(350,300)); + this.setPreferredSize(new Dimension(350, 300)); } - private JPanel getMemo(){ + private JPanel getMemo() { JPanel root = componentsFactory.getTransparentPanel(new BorderLayout()); JLabel title = componentsFactory.getTextLabel( "Memo:", FontStyle.REGULAR); - title.setBorder(BorderFactory.createEmptyBorder(6,0,2,0)); + title.setBorder(BorderFactory.createEmptyBorder(6, 0, 2, 0)); JPanel itemsPanel = componentsFactory.getTransparentPanel(); - itemsPanel.setLayout(new BoxLayout(itemsPanel,BoxLayout.Y_AXIS)); + 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); + 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; } 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 e39d87af..4313f64a 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 @@ -31,27 +31,28 @@ public GamePathChooser() { @Override public void onViewInit() { this.removeHideButton(); - this.add(getChooserPanel(),BorderLayout.CENTER); - this.add(getMiscPanel(),BorderLayout.PAGE_END); + this.add(getChooserPanel(), BorderLayout.CENTER); + this.add(getMiscPanel(), BorderLayout.PAGE_END); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); + this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2); this.pack(); this.setVisible(true); } - private JPanel getChooserPanel(){ + + private JPanel getChooserPanel() { JPanel panel = componentsFactory.getTransparentPanel(new BorderLayout()); this.statusLabel = componentsFactory.getTextLabel(""); this.statusLabel.setHorizontalAlignment(SwingConstants.CENTER); this.statusLabel.setForeground(AppThemeColor.TEXT_IMPORTANT); - panel.add(this.statusLabel,BorderLayout.CENTER); + panel.add(this.statusLabel, BorderLayout.CENTER); JPanel chooserPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); JTextField textField = componentsFactory.getTextField("Example: \"C:/Path of Exile\""); - textField.setPreferredSize(new Dimension(450,26)); - textField.setMinimumSize(new Dimension(450,26)); + textField.setPreferredSize(new Dimension(450, 26)); + textField.setMinimumSize(new Dimension(450, 26)); textField.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { @@ -66,7 +67,7 @@ public void mousePressed(MouseEvent e) { JButton selectButton = componentsFactory.getBorderedButton("Select"); selectButton.addActionListener(e -> { int returnVal = fileChooser.showOpenDialog(GamePathChooser.this); - if(returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) { this.gamePath = fileChooser.getSelectedFile().getPath(); textField.setText(gamePath); this.repaint(); @@ -74,11 +75,11 @@ public void mousePressed(MouseEvent e) { } }); chooserPanel.add(selectButton); - panel.add(chooserPanel,BorderLayout.PAGE_START); + panel.add(chooserPanel, BorderLayout.PAGE_START); return panel; } - private JPanel getMiscPanel(){ + private JPanel getMiscPanel() { JPanel miscPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JButton cancelButton = componentsFactory.getButton( FontStyle.BOLD, @@ -87,16 +88,16 @@ private JPanel getMiscPanel(){ "Cancel", 16f); cancelButton.addActionListener(action -> { - if(!this.readyToStart) { + if (!this.readyToStart) { System.exit(0); } }); - cancelButton.setPreferredSize(new Dimension(120,26)); + cancelButton.setPreferredSize(new Dimension(120, 26)); JButton saveButton = componentsFactory.getBorderedButton("Save"); saveButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(!readyToStart) { + if (!readyToStart) { if (isValidGamePath(gamePath)) { readyToStart = true; statusLabel.setText("Success!"); @@ -123,12 +124,13 @@ public void mouseClicked(MouseEvent e) { } } }); - saveButton.setPreferredSize(new Dimension(120,26)); + saveButton.setPreferredSize(new Dimension(120, 26)); miscPanel.add(saveButton); miscPanel.add(cancelButton); return miscPanel; } - private boolean isValidGamePath(String gamePath){ + + private boolean isValidGamePath(String gamePath) { File file = new File(gamePath + File.separator + "logs" + File.separator + "Client.txt"); return file.exists(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/HistoryFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/HistoryFrame.java index dc6b149e..110975ae 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/HistoryFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/HistoryFrame.java @@ -15,28 +15,32 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.*; -import java.util.*; +import java.awt.event.AdjustmentEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseWheelEvent; +import java.util.ArrayList; import java.util.List; -public class HistoryFrame extends AbstractTitledComponentFrame{ +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 public void onViewInit() { this.factory = new NotificationPanelFactory(); this.currentMessages = new ArrayList<>(); this.mainContainer = new VerticalScrollContainer(); this.mainContainer.setBackground(AppThemeColor.FRAME); - this.mainContainer.setLayout(new BoxLayout(this.mainContainer,BoxLayout.Y_AXIS)); + this.mainContainer.setLayout(new BoxLayout(this.mainContainer, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(this.mainContainer); scrollPane.setBorder(null); @@ -54,10 +58,10 @@ public void mouseWheelMoved(MouseWheelEvent e) { vBar.setUI(new MercuryScrollBarUI()); vBar.setPreferredSize(new Dimension(16, Integer.MAX_VALUE)); vBar.setUnitIncrement(3); - vBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,2)); + vBar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 2)); vBar.addAdjustmentListener(e -> repaint()); - this.add(scrollPane,BorderLayout.CENTER); + this.add(scrollPane, BorderLayout.CENTER); mainContainer.getParent().setBackground(AppThemeColor.FRAME); String[] messages = HistoryManager.INSTANCE.fetchNext(10); @@ -65,7 +69,7 @@ public void mouseWheelMoved(MouseWheelEvent e) { for (String message : messages) { MessageParser parser = new MessageParser(); NotificationDescriptor parsedNotificationDescriptor = parser.parse(message); - if(parsedNotificationDescriptor != null) { + if (parsedNotificationDescriptor != null) { NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) .setData(parsedNotificationDescriptor) .setComponentsFactory(this.componentsFactory) @@ -74,7 +78,7 @@ public void mouseWheelMoved(MouseWheelEvent e) { mainContainer.add(panel); } } - this.miscPanel.add(getClearButton(),0); + this.miscPanel.add(getClearButton(), 0); this.pack(); vBar.setValue(vBar.getMaximum()); vBar.addAdjustmentListener((AdjustmentEvent e) -> { @@ -83,20 +87,21 @@ public void mouseWheelMoved(MouseWheelEvent e) { for (String message : nextMessages) { MessageParser parser = new MessageParser(); NotificationDescriptor parsedNotificationDescriptor = parser.parse(message); - if(parsedNotificationDescriptor != null) { + if (parsedNotificationDescriptor != null) { NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) .setData(parsedNotificationDescriptor) .setComponentsFactory(this.componentsFactory) .build(); this.currentMessages.add(parsedNotificationDescriptor); - mainContainer.add(panel,0); + mainContainer.add(panel, 0); } vBar.setValue(vBar.getValue() + 100); } } }); } - private JButton getClearButton(){ + + private JButton getClearButton() { JButton clearHistory = componentsFactory.getIconButton("app/clear-history.png", 13, @@ -117,8 +122,8 @@ protected String getFrameTitle() { @Override public void subscribe() { - MercuryStoreCore.newNotificationSubject.subscribe(message -> SwingUtilities.invokeLater(()-> { - if(!currentMessages.contains(message)) { + MercuryStoreCore.newNotificationSubject.subscribe(message -> SwingUtilities.invokeLater(() -> { + if (!currentMessages.contains(message)) { HistoryManager.INSTANCE.add(message); NotificationPanel panel = this.factory.getProviderFor(NotificationType.HISTORY) .setData(message) @@ -131,8 +136,9 @@ public void subscribe() { } })); } - private void trimContainer(){ - if(mainContainer.getComponentCount() > 40){ + + private void trimContainer() { + if (mainContainer.getComponentCount() > 40) { for (int i = 0; i < 5; i++) { mainContainer.remove(0); } 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 b234f17d..93e52950 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 @@ -25,6 +25,7 @@ public class NotesFrame extends AbstractTitledComponentFrame { private boolean lastNote = false; private JCheckBox showOnStartUp; + public NotesFrame(List notes, NotesType type) { super(); this.currentNotes = notes; @@ -33,7 +34,7 @@ public NotesFrame(List notes, NotesType type) { this.processSEResize = false; this.progressBarFrame = new ProgressBarFrame(); this.progressBarFrame.init(); - if(type.equals(NotesType.INFO)) { + if (type.equals(NotesType.INFO)) { if (this.applicationConfig.get().isShowOnStartUp()) { this.prevState = FrameVisibleState.SHOW; } else { @@ -42,13 +43,14 @@ public NotesFrame(List notes, NotesType type) { } } } + @Override public void onViewInit() { JPanel rootPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - rootPanel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); + rootPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); this.contentPanel = new ContentPanel(); - rootPanel.add(contentPanel,BorderLayout.CENTER); + rootPanel.add(contentPanel, BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(new BorderLayout()); this.showOnStartUp = new JCheckBox(); @@ -60,19 +62,20 @@ public void onViewInit() { JPanel showOnStartPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); showOnStartPanel.add(showOnStartUp); - showOnStartPanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR,AppThemeColor.TEXT_DEFAULT,TextAlignment.LEFTOP,15f,"Show on StartUp")); - if(type.equals(NotesType.INFO)) { + showOnStartPanel.add(componentsFactory.getTextLabel(FontStyle.REGULAR, AppThemeColor.TEXT_DEFAULT, TextAlignment.LEFTOP, 15f, "Show on StartUp")); + if (type.equals(NotesType.INFO)) { miscPanel.add(showOnStartPanel, BorderLayout.CENTER); } - miscPanel.add(getNavBar(),BorderLayout.PAGE_END); - rootPanel.add(miscPanel,BorderLayout.PAGE_END); - this.add(rootPanel,BorderLayout.CENTER); + miscPanel.add(getNavBar(), BorderLayout.PAGE_END); + rootPanel.add(miscPanel, BorderLayout.PAGE_END); + this.add(rootPanel, BorderLayout.CENTER); this.removeHideButton(); this.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); + this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2); } - private JPanel getNavBar(){ + + private JPanel getNavBar() { JPanel navBar = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.RIGHT)); Dimension dimension = new Dimension(80, 26); @@ -109,7 +112,7 @@ private JPanel getNavBar(){ next.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { contentPanel.next(); if (!contentPanel.hasNext()) { lastNote = true; @@ -131,7 +134,7 @@ public void mousePressed(MouseEvent e) { previous.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { contentPanel.prev(); if (lastNote) { navBar.remove(close); @@ -146,7 +149,7 @@ public void mousePressed(MouseEvent e) { close.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { NotesFrame.this.setVisible(false); if (type.equals(NotesType.INFO)) { FramesManager.INSTANCE.enableMovementExclude(ItemsGridFrame.class); @@ -165,19 +168,20 @@ public void mousePressed(MouseEvent e) { next.setPreferredSize(componentsFactory.convertSize(dimension)); close.setPreferredSize(componentsFactory.convertSize(dimension)); - if(type.equals(NotesType.PATCH)){ + if (type.equals(NotesType.PATCH)) { navBar.add(donate); navBar.add(gitHub); navBar.add(download); } - if(currentNotes.size() == 1){ + if (currentNotes.size() == 1) { navBar.add(close); - }else { + } else { navBar.add(previous); navBar.add(next); } return navBar; } + @Override public void subscribe() { @@ -188,81 +192,90 @@ protected String getFrameTitle() { return "Welcome to MercuryTrade"; } - private class ContentPanel extends JPanel{ + public enum NotesType { + INFO, + PATCH + } + + private class ContentPanel extends JPanel { private int noteIndex = 0; private JLabel titleLabel; + private ContentPanel() { super(new BorderLayout()); this.setBackground(AppThemeColor.TRANSPARENT); - titleLabel = componentsFactory.getTextLabel(FontStyle.BOLD,AppThemeColor.TEXT_MISC, TextAlignment.LEFTOP,20f,""); + titleLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.LEFTOP, 20f, ""); titleLabel.setBorder(null); renderCurrentNote(); } - private void renderCurrentNote(){ + + private void renderCurrentNote() { this.removeAll(); Note note = currentNotes.get(noteIndex); titleLabel.setText(note.getTitle()); JPanel innerContent = new JPanel(new BorderLayout()); innerContent.setBackground(AppThemeColor.SLIDE_BG); innerContent.setBorder(BorderFactory.createLineBorder(AppThemeColor.HEADER)); - innerContent.setPreferredSize(new Dimension(530,270)); + innerContent.setPreferredSize(new Dimension(530, 270)); JLabel image = componentsFactory.getIconLabel(note.getImagePath()); JTextArea textArea = componentsFactory.getSimpleTextArea(note.getText()); - switch (note.getLayout()){ - case VERTICAL:{ - innerContent.setLayout(new BoxLayout(innerContent,BoxLayout.Y_AXIS)); + switch (note.getLayout()) { + case VERTICAL: { + innerContent.setLayout(new BoxLayout(innerContent, BoxLayout.Y_AXIS)); break; } - case HORIZONTAL:{ + case HORIZONTAL: { innerContent.setLayout(new FlowLayout(FlowLayout.LEFT)); - textArea.setPreferredSize(new Dimension(160,200)); + textArea.setPreferredSize(new Dimension(160, 200)); break; } } - textArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); + textArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); JPanel imgPanel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.CENTER)); JPanel textPanel = componentsFactory.getTransparentPanel(new BorderLayout()); - textPanel.add(textArea,BorderLayout.CENTER); + textPanel.add(textArea, BorderLayout.CENTER); imgPanel.add(image); innerContent.add(imgPanel); innerContent.add(textPanel); - this.add(titleLabel,BorderLayout.PAGE_START); - this.add(innerContent,BorderLayout.CENTER); + this.add(titleLabel, BorderLayout.PAGE_START); + this.add(innerContent, BorderLayout.CENTER); NotesFrame.this.pack(); NotesFrame.this.repaint(); } - void next(){ - if(noteIndex < currentNotes.size()-1){ + + void next() { + if (noteIndex < currentNotes.size() - 1) { noteIndex++; renderCurrentNote(); } } - boolean hasNext(){ - return noteIndex < currentNotes.size()-1; + + boolean hasNext() { + return noteIndex < currentNotes.size() - 1; } - void prev(){ - if(noteIndex > 0){ + + void prev() { + if (noteIndex > 0) { noteIndex--; renderCurrentNote(); } } } - public enum NotesType { - INFO, - PATCH - } + private class ProgressBarFrame extends AbstractOverlaidFrame { private JProgressBar progressBar; private JLabel percentLabel; private int percent; private JButton restart; + private ProgressBarFrame() { super(); percent = 0; } + @Override protected void initialize() { this.setMinimumSize(new Dimension(310, 60)); @@ -278,10 +291,10 @@ private JPanel getProgressBarPanel() { this.progressBar.setPreferredSize(new Dimension(300, 26)); this.progressBar.setBackground(AppThemeColor.MSG_HEADER); this.progressBar.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER)); - this.progressBar.setFont(componentsFactory.getFontByLang("0",FontStyle.ITALIC)); + this.progressBar.setFont(componentsFactory.getFontByLang("0", FontStyle.ITALIC)); barPanel.add(progressBar); - root.add(barPanel,BorderLayout.CENTER); + root.add(barPanel, BorderLayout.CENTER); this.percentLabel = componentsFactory.getTextLabel(percent + "%"); @@ -295,7 +308,7 @@ private JPanel getProgressBarPanel() { bottomBar.add(this.restart); this.restart.setEnabled(false); this.restart.setPreferredSize(new Dimension(80, 26)); - root.add(bottomBar,BorderLayout.PAGE_END); + root.add(bottomBar, BorderLayout.PAGE_END); return root; } @@ -322,10 +335,10 @@ protected LayoutManager getFrameLayout() { @Override public void onViewInit() { - this.add(getProgressBarPanel(),BorderLayout.CENTER); + 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); + 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 38ce8b8a..cf931b6d 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 @@ -5,7 +5,7 @@ import com.mercury.platform.shared.config.descriptor.FrameDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.components.panel.settings.*; +import com.mercury.platform.ui.components.panel.settings.MenuPanel; import com.mercury.platform.ui.manager.FramesManager; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; @@ -16,13 +16,13 @@ import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; public class SettingsFrame extends AbstractTitledComponentFrame { private JPanel currentPanel; private MenuPanel menuPanel; private JPanel root; - public SettingsFrame(){ + + public SettingsFrame() { super(); this.setFocusable(true); this.setFocusableWindowState(true); @@ -30,13 +30,13 @@ public SettingsFrame(){ this.processingHideEvent = false; this.processHideEffect = false; // FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); - this.setPreferredSize(new Dimension(1000,600)); + this.setPreferredSize(new Dimension(1000, 600)); } @Override protected void initialize() { super.initialize(); - this.setPreferredSize(new Dimension(1000,600)); + this.setPreferredSize(new Dimension(1000, 600)); } @Override @@ -44,11 +44,11 @@ public void onViewInit() { this.root = new JPanel(new BorderLayout()); this.menuPanel = new MenuPanel(); JPanel leftPanel = this.componentsFactory.getJPanel(new BorderLayout()); - leftPanel.add(this.menuPanel,BorderLayout.CENTER); - leftPanel.add(this.getOperationsButtons(),BorderLayout.PAGE_END); - this.add(leftPanel,BorderLayout.LINE_START); - this.add(this.root,BorderLayout.CENTER); - this.add(this.getBottomPanel(),BorderLayout.PAGE_END); + leftPanel.add(this.menuPanel, BorderLayout.CENTER); + leftPanel.add(this.getOperationsButtons(), BorderLayout.PAGE_END); + this.add(leftPanel, BorderLayout.LINE_START); + this.add(this.root, BorderLayout.CENTER); + this.add(this.getBottomPanel(), BorderLayout.PAGE_END); this.pack(); } @@ -59,25 +59,27 @@ public void onSizeChange() { this.setPreferredSize(frameDescriptor.getFrameSize()); } - public void setContentPanel(JPanel panel){ - if(currentPanel != null){ + public void setContentPanel(JPanel panel) { + if (currentPanel != null) { this.root.remove(currentPanel); } - this.root.add(panel,BorderLayout.CENTER); + this.root.add(panel, BorderLayout.CENTER); this.currentPanel = panel; this.pack(); this.repaint(); } - private JPanel getBottomPanel(){ + + private JPanel getBottomPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.setBorder(BorderFactory.createMatteBorder(1,0,0,0,AppThemeColor.MSG_HEADER_BORDER)); + root.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, AppThemeColor.MSG_HEADER_BORDER)); root.setBackground(AppThemeColor.ADR_FOOTER_BG); root.add(this.getSaveButtonPanel(), BorderLayout.LINE_END); return root; } - private JPanel getSaveButtonPanel(){ - JPanel root = componentsFactory.getTransparentPanel(new GridLayout(1,0)); - JButton saveButton = componentsFactory.getBorderedButton("Save",16); + + private JPanel getSaveButtonPanel() { + JPanel root = componentsFactory.getTransparentPanel(new GridLayout(1, 0)); + JButton saveButton = componentsFactory.getBorderedButton("Save", 16); saveButton.addActionListener(e -> { MercuryStoreUI.settingsSaveSubject.onNext(true); MercuryStoreCore.showingDelaySubject.onNext(true); @@ -96,15 +98,15 @@ private JPanel getSaveButtonPanel(){ }); saveButton.setPreferredSize(new Dimension(110, 26)); cancelButton.setPreferredSize(new Dimension(110, 26)); - root.add(this.componentsFactory.wrapToSlide(cancelButton,AppThemeColor.HEADER,2,2,2,2)); - 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; } - private JPanel getOperationsButtons(){ - JPanel root = componentsFactory.getTransparentPanel(new GridLayout(0,1,4,2)); - root.setBorder(BorderFactory.createMatteBorder(0,0,0,1,AppThemeColor.BORDER)); - JButton openTutorial = this.getOperationButton("Open tutorial","app/tutorial.png"); + private JPanel getOperationsButtons() { + JPanel root = componentsFactory.getTransparentPanel(new GridLayout(0, 1, 4, 2)); + root.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, AppThemeColor.BORDER)); + JButton openTutorial = this.getOperationButton("Open tutorial", "app/tutorial.png"); openTutorial.addActionListener(action -> { FramesManager.INSTANCE.hideFrame(SettingsFrame.class); FramesManager.INSTANCE.preShowFrame(NotesFrame.class); @@ -114,7 +116,7 @@ private JPanel getOperationsButtons(){ ApplicationHolder.getInstance().setManualRequest(true); MercuryStoreCore.requestPatchSubject.onNext(true); }); - JButton openTests = this.getOperationButton("Open tests","app/open-tests.png"); + JButton openTests = this.getOperationButton("Open tests", "app/open-tests.png"); openTests.addActionListener(action -> { FramesManager.INSTANCE.hideFrame(SettingsFrame.class); FramesManager.INSTANCE.showFrame(TestCasesFrame.class); @@ -128,10 +130,10 @@ private JPanel getOperationsButtons(){ patchNotes.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if(SwingUtilities.isLeftMouseButton(e)){ + if (SwingUtilities.isLeftMouseButton(e)) { NotesLoader notesLoader = new NotesLoader(); java.util.List patchNotes = notesLoader.getPatchNotes(); - if(patchNotes.size() != 0){ + if (patchNotes.size() != 0) { NotesFrame patchNotesFrame = new NotesFrame(patchNotes, NotesFrame.NotesType.PATCH); patchNotesFrame.init(); patchNotesFrame.showComponent(); @@ -143,17 +145,17 @@ public void mouseClicked(MouseEvent e) { return root; } - private JButton getOperationButton(String title, String iconPath){ + private JButton getOperationButton(String title, String iconPath) { JButton button = this.componentsFactory.getButton(title); - button.setPreferredSize(new Dimension(210,35)); + button.setPreferredSize(new Dimension(210, 35)); button.setForeground(AppThemeColor.TEXT_DEFAULT); button.setHorizontalAlignment(SwingConstants.LEFT); button.setBackground(AppThemeColor.ADR_BG); - button.setFont(this.componentsFactory.getFont(FontStyle.BOLD,16f)); - button.setIcon(this.componentsFactory.getIcon(iconPath,22)); + button.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 16f)); + button.setIcon(this.componentsFactory.getIcon(iconPath, 22)); button.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(1,1,1,1,AppThemeColor.ADR_PANEL_BORDER), - BorderFactory.createEmptyBorder(2,10,2,2))); + BorderFactory.createMatteBorder(1, 1, 1, 1, AppThemeColor.ADR_PANEL_BORDER), + BorderFactory.createEmptyBorder(2, 10, 2, 2))); return button; } 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 cb7d9a5c..bec85d61 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 @@ -2,6 +2,7 @@ import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.misc.AppThemeColor; + import javax.swing.*; import java.awt.*; @@ -25,7 +26,7 @@ protected String getFrameTitle() { } - private JPanel getTestCasesPanel(){ + private JPanel getTestCasesPanel() { JPanel testPanel = new JPanel(new GridBagLayout()); GridBagConstraints buttonColumn = new GridBagConstraints(); @@ -40,48 +41,48 @@ private JPanel getTestCasesPanel(){ buttonColumn.gridx = 0; titleColumn.gridy = 0; titleColumn.gridx = 1; - buttonColumn.insets = new Insets(3,3,3,0); - titleColumn.insets = new Insets(3,3,3,0); + buttonColumn.insets = new Insets(3, 3, 3, 0); + titleColumn.insets = new Insets(3, 3, 3, 0); JButton button = componentsFactory.getBorderedButton("Click"); button.addActionListener(action -> { MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomItemIncMessage()); }); - ; - testPanel.add(button,buttonColumn); + ; + testPanel.add(button, buttonColumn); buttonColumn.gridy++; JLabel textLabel = componentsFactory.getTextLabel("Random incoming item message"); - testPanel.add(textLabel,titleColumn); + testPanel.add(textLabel, titleColumn); titleColumn.gridy++; JButton button1 = componentsFactory.getBorderedButton("Click"); button1.addActionListener(action -> { MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomCurrencyIncMessage()); }); - testPanel.add(button1,buttonColumn); + testPanel.add(button1, buttonColumn); buttonColumn.gridy++; JLabel textLabel1 = componentsFactory.getTextLabel("Random incoming currency message"); - testPanel.add(textLabel1,titleColumn); + testPanel.add(textLabel1, titleColumn); titleColumn.gridy++; JButton outItemButton = componentsFactory.getBorderedButton("Click"); outItemButton.addActionListener(action -> { MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomItemOutMessage()); }); - testPanel.add(outItemButton,buttonColumn); + testPanel.add(outItemButton, buttonColumn); buttonColumn.gridy++; JLabel outItemLabel = componentsFactory.getTextLabel("Random outgoing item message"); - testPanel.add(outItemLabel,titleColumn); + testPanel.add(outItemLabel, titleColumn); titleColumn.gridy++; JButton outCurrencyButton = componentsFactory.getBorderedButton("Click"); outCurrencyButton.addActionListener(action -> { MercuryStoreCore.newNotificationSubject.onNext(this.testEngine.getRandomCurrencyOutMessage()); }); - testPanel.add(outCurrencyButton,buttonColumn); + testPanel.add(outCurrencyButton, buttonColumn); buttonColumn.gridy++; JLabel outCurrencyLabel = componentsFactory.getTextLabel("Random outgoing currency message"); - testPanel.add(outCurrencyLabel,titleColumn); + testPanel.add(outCurrencyLabel, titleColumn); titleColumn.gridy++; testPanel.setBackground(AppThemeColor.TRANSPARENT); @@ -89,10 +90,10 @@ private JPanel getTestCasesPanel(){ chatScannerButton.addActionListener(action -> { MercuryStoreCore.newScannerMessageSubject.onNext(this.testEngine.getRandomScannerMessage()); }); - testPanel.add(chatScannerButton,buttonColumn); + testPanel.add(chatScannerButton, buttonColumn); buttonColumn.gridy++; JLabel chatScannerLabel = componentsFactory.getTextLabel("Random chat scanner message"); - testPanel.add(chatScannerLabel,titleColumn); + testPanel.add(chatScannerLabel, titleColumn); titleColumn.gridy++; testPanel.setBackground(AppThemeColor.TRANSPARENT); 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 index fa935869..8a816e8f 100644 --- 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 @@ -15,10 +15,10 @@ 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 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(); @@ -26,7 +26,7 @@ public class TestEngine { 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")); + this.messageBuilder.setChunkStrings(Arrays.asList("Hi", "buy", "listed", "like")); items.add("Wondertrap Velvet Slippers"); items.add("Rain of Arrows"); @@ -129,7 +129,8 @@ public TestEngine() { leagues.add("1 Week Legacy (JRE055)"); leagues.add("1 Week Legacy HC (JRE055)"); } - public NotificationDescriptor getRandomItemIncMessage(){ + + public NotificationDescriptor getRandomItemIncMessage() { NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, nickNames.get(random.nextInt(nickNames.size())), items.get(random.nextInt(items.size())), @@ -143,7 +144,8 @@ public NotificationDescriptor getRandomItemIncMessage(){ )); return notificationDescriptor; } - public NotificationDescriptor getRandomCurrencyIncMessage(){ + + public NotificationDescriptor getRandomCurrencyIncMessage() { NotificationDescriptor notificationDescriptor = parser.parse(String.format(currencyTemplate, nickNames.get(random.nextInt(nickNames.size())), random.nextInt(200) + 1, @@ -156,7 +158,7 @@ public NotificationDescriptor getRandomCurrencyIncMessage(){ return notificationDescriptor; } - public NotificationDescriptor getRandomItemOutMessage(){ + public NotificationDescriptor getRandomItemOutMessage() { NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, nickNames.get(random.nextInt(nickNames.size())), items.get(random.nextInt(items.size())), @@ -171,7 +173,8 @@ public NotificationDescriptor getRandomItemOutMessage(){ notificationDescriptor.setType(NotificationType.OUT_ITEM_MESSAGE); return notificationDescriptor; } - public NotificationDescriptor getRandomCurrencyOutMessage(){ + + public NotificationDescriptor getRandomCurrencyOutMessage() { NotificationDescriptor notificationDescriptor = parser.parse(String.format(currencyTemplate, nickNames.get(random.nextInt(nickNames.size())), random.nextInt(200) + 1, @@ -184,7 +187,8 @@ public NotificationDescriptor getRandomCurrencyOutMessage(){ notificationDescriptor.setType(NotificationType.OUT_CURRENCY_MESSAGE); return notificationDescriptor; } - public PlainMessageDescriptor getRandomScannerMessage(){ + + public PlainMessageDescriptor getRandomScannerMessage() { NotificationDescriptor notificationDescriptor = parser.parse(String.format(poeTradeTemplate, nickNames.get(random.nextInt(nickNames.size())), items.get(random.nextInt(items.size())), @@ -197,7 +201,7 @@ public PlainMessageDescriptor getRandomScannerMessage(){ offer.get(random.nextInt(offer.size())) )); PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); - descriptor.setMessage(messageBuilder.build(StringUtils.substringAfter(notificationDescriptor.getSourceString(),notificationDescriptor.getWhisperNickname()+":"))); + 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 c6d45270..198fc2d0 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 @@ -21,6 +21,7 @@ public class TimerFrame extends AbstractTitledComponentFrame { private int hours = 0; private int mapCount = 0; private int chaosSpend = 0; + public TimerFrame() { super(); } @@ -29,27 +30,27 @@ public TimerFrame() { protected void initialize() { super.initialize(); JPanel root = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - JButton play = componentsFactory.getIconButton("app/timer-play.png", 16,AppThemeColor.FRAME_ALPHA, TooltipConstants.PLAY); + JButton play = componentsFactory.getIconButton("app/timer-play.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.PLAY); play.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { getNewTimer().start(); } }); - JButton pause = componentsFactory.getIconButton("app/timer-pause.png", 16,AppThemeColor.FRAME_ALPHA,TooltipConstants.PAUSE); + JButton pause = componentsFactory.getIconButton("app/timer-pause.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.PAUSE); pause.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(timeAgo != null){ + if (timeAgo != null) { timeAgo.stop(); } } }); - JButton stop = componentsFactory.getIconButton("app/timer-stop.png", 16,AppThemeColor.FRAME_ALPHA,TooltipConstants.STOP); + JButton stop = componentsFactory.getIconButton("app/timer-stop.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.STOP); stop.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(timeAgo != null){ + if (timeAgo != null) { timeAgo.stop(); seconds = 0; minutes = 0; @@ -59,11 +60,11 @@ public void mousePressed(MouseEvent e) { }); JLabel mapCountLabel = componentsFactory.getTextLabel("Map count: 0"); JLabel chaosSpendLabel = componentsFactory.getTextLabel("Chaos spend: 0"); - JButton reset = componentsFactory.getIconButton("app/timer-reset.png", 16,AppThemeColor.FRAME_ALPHA, TooltipConstants.RESET); + JButton reset = componentsFactory.getIconButton("app/timer-reset.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.RESET); reset.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(timeAgo != null){ + if (timeAgo != null) { timeAgo.stop(); } timeLabel.setText("00:00:00"); @@ -82,10 +83,10 @@ public void mousePressed(MouseEvent e) { root.add(pause); root.add(stop); root.add(reset); - this.add(root,BorderLayout.CENTER); + this.add(root, BorderLayout.CENTER); JPanel miscPanel = componentsFactory.getTransparentPanel(null); - miscPanel.setLayout(new BoxLayout(miscPanel,BoxLayout.Y_AXIS)); + miscPanel.setLayout(new BoxLayout(miscPanel, BoxLayout.Y_AXIS)); JPanel mapCountPanel = getIncrementRow(mapCountLabel, new MouseAdapter() { @Override @@ -97,7 +98,7 @@ public void mousePressed(MouseEvent e) { }, new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if(mapCount > 0) { + if (mapCount > 0) { mapCount--; mapCountLabel.setText("Map count: " + mapCount); TimerFrame.this.repaint(); @@ -124,10 +125,11 @@ public void mousePressed(MouseEvent e) { miscPanel.add(mapCountPanel); miscPanel.add(chaosSpendPanel); - this.add(miscPanel,BorderLayout.PAGE_END); + this.add(miscPanel, BorderLayout.PAGE_END); this.pack(); } - private Timer getNewTimer(){ + + private Timer getNewTimer() { timeAgo = new Timer(1000, e -> { String labelText = ""; seconds++; @@ -139,9 +141,9 @@ private Timer getNewTimer(){ minutes = 0; } } - String secLabel = ((seconds/10.0) >= 1f)?String.valueOf(seconds) : "0" + seconds; - String minLabel = ((minutes/10.0) >= 1f)?String.valueOf(minutes) : "0" + minutes; - String hLabel = ((hours/10.0) >= 1f)?String.valueOf(hours) : "0" + hours; + String secLabel = ((seconds / 10.0) >= 1f) ? String.valueOf(seconds) : "0" + seconds; + String minLabel = ((minutes / 10.0) >= 1f) ? String.valueOf(minutes) : "0" + minutes; + String hLabel = ((hours / 10.0) >= 1f) ? String.valueOf(hours) : "0" + hours; if (minutes == 0 && hours == 0) { labelText = "00:00:" + secLabel; } else if (minutes > 0) { @@ -154,11 +156,12 @@ private Timer getNewTimer(){ }); return timeAgo; } - private JPanel getIncrementRow(JLabel label, MouseAdapter plusListener, MouseAdapter minusListener){ + + private JPanel getIncrementRow(JLabel label, MouseAdapter plusListener, MouseAdapter minusListener) { JPanel panel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - JButton plus = componentsFactory.getIconButton("app/invite.png", 14,AppThemeColor.FRAME_ALPHA,""); + JButton plus = componentsFactory.getIconButton("app/invite.png", 14, AppThemeColor.FRAME_ALPHA, ""); plus.addMouseListener(plusListener); - JButton minus = componentsFactory.getIconButton("app/kick.png", 14,AppThemeColor.FRAME_ALPHA,""); + JButton minus = componentsFactory.getIconButton("app/kick.png", 14, AppThemeColor.FRAME_ALPHA, ""); minus.addMouseListener(minusListener); panel.add(label); panel.add(plus); @@ -166,15 +169,15 @@ private JPanel getIncrementRow(JLabel label, MouseAdapter plusListener, MouseAda return panel; } - private JPanel getTimePanel(){ + private JPanel getTimePanel() { JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); panel.setBackground(AppThemeColor.TRANSPARENT); timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 18, "00:00:00"); timeLabel.setVerticalAlignment(SwingConstants.CENTER); timeLabel.setHorizontalAlignment(SwingConstants.CENTER); panel.setBorder(BorderFactory.createLineBorder(AppThemeColor.BUTTON, 1)); - panel.setMinimumSize(new Dimension(100,30)); - panel.setPreferredSize(new Dimension(100,30)); + panel.setMinimumSize(new Dimension(100, 30)); + panel.setPreferredSize(new Dimension(100, 30)); panel.add(timeLabel); return panel; } 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 1000f988..2fa62141 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/manager/FramesManager.java @@ -1,27 +1,24 @@ package com.mercury.platform.ui.manager; -import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.AsSubscriber; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.config.Configuration; import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; import com.mercury.platform.shared.config.descriptor.FrameDescriptor; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.adr.AdrManager; +import com.mercury.platform.ui.adr.AdrState; import com.mercury.platform.ui.frame.AbstractComponentFrame; +import com.mercury.platform.ui.frame.AbstractOverlaidFrame; 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.ItemsGridFrame; 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; +import com.mercury.platform.ui.frame.other.*; +import com.mercury.platform.ui.frame.setup.location.SetUpLocationCommander; import com.mercury.platform.ui.frame.setup.scale.SetUpScaleCommander; import com.mercury.platform.ui.frame.titled.*; -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.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; @@ -31,35 +28,32 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; -import java.util.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class FramesManager implements AsSubscriber { - private static class FramesManagerHolder { - static final FramesManager HOLDER_INSTANCE = new FramesManager(); - } public static FramesManager INSTANCE = FramesManagerHolder.HOLDER_INSTANCE; - - private Map framesMap; + private Map framesMap; private SetUpLocationCommander locationCommander; private SetUpScaleCommander scaleCommander; private AdrManager adrManager; private TrayIcon trayIcon; - private FramesManager() { this.framesMap = new HashMap<>(); this.locationCommander = new SetUpLocationCommander(); this.scaleCommander = new SetUpScaleCommander(); this.adrManager = new AdrManager(); } - public void start(){ + + public void start() { this.createTrayIcon(); AbstractOverlaidFrame incMessageFrame = new NotificationFrame(); - this.framesMap.put(NotificationFrame.class,incMessageFrame); + this.framesMap.put(NotificationFrame.class, incMessageFrame); AbstractOverlaidFrame taskBarFrame = new TaskBarFrame(); AbstractOverlaidFrame itemsMeshFrame = new ItemsGridFrame(); - this.framesMap.put(ItemsGridFrame.class,itemsMeshFrame); + this.framesMap.put(ItemsGridFrame.class, itemsMeshFrame); this.locationCommander.addFrame((AbstractMovableComponentFrame) incMessageFrame); this.locationCommander.addFrame((AbstractMovableComponentFrame) taskBarFrame); this.locationCommander.addFrame((AbstractMovableComponentFrame) itemsMeshFrame); @@ -73,29 +67,29 @@ public void start(){ List notesOnFirstStart = notesLoader.getNotesOnFirstStart(); this.framesMap.put(NotesFrame.class, new NotesFrame(notesOnFirstStart, NotesFrame.NotesType.INFO)); - this.framesMap.put(HistoryFrame.class,new HistoryFrame()); + this.framesMap.put(HistoryFrame.class, new HistoryFrame()); SettingsFrame settingsFrame = new SettingsFrame(); - this.framesMap.put(SettingsFrame.class,settingsFrame); - this.framesMap.put(TestCasesFrame.class,new TestCasesFrame()); - this.framesMap.put(TooltipFrame.class,new TooltipFrame()); - this.framesMap.put(NotificationAlertFrame.class,new NotificationAlertFrame()); - this.framesMap.put(MercuryLoadingFrame.class,new MercuryLoadingFrame()); - 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()); - this.framesMap.put(SetUpScaleFrame.class,new SetUpScaleFrame()); - this.framesMap.put(AlertFrame.class,new AlertFrame()); - - this.framesMap.forEach((k,v)-> v.init()); + this.framesMap.put(SettingsFrame.class, settingsFrame); + this.framesMap.put(TestCasesFrame.class, new TestCasesFrame()); + this.framesMap.put(TooltipFrame.class, new TooltipFrame()); + this.framesMap.put(NotificationAlertFrame.class, new NotificationAlertFrame()); + this.framesMap.put(MercuryLoadingFrame.class, new MercuryLoadingFrame()); + 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()); + this.framesMap.put(SetUpScaleFrame.class, new SetUpScaleFrame()); + this.framesMap.put(AlertFrame.class, new AlertFrame()); + + this.framesMap.forEach((k, v) -> v.init()); ApplicationDescriptor config = Configuration.get().applicationConfiguration().get(); - this.framesMap.forEach((k,frame) -> { - if(frame instanceof AbstractComponentFrame) { + this.framesMap.forEach((k, frame) -> { + if (frame instanceof AbstractComponentFrame) { if (config.getFadeTime() > 0) { - ((AbstractComponentFrame)frame).enableHideEffect(config.getFadeTime(), config.getMinOpacity(), config.getMaxOpacity()); + ((AbstractComponentFrame) frame).enableHideEffect(config.getFadeTime(), config.getMinOpacity(), config.getMaxOpacity()); } else { - ((AbstractComponentFrame)frame).disableHideEffect(); + ((AbstractComponentFrame) frame).disableHideEffect(); frame.setOpacity(config.getMaxOpacity() / 100f); } } @@ -105,6 +99,7 @@ public void start(){ this.adrManager.load(); MercuryStoreCore.uiLoadedSubject.onNext(true); } + @Override public void subscribe() { MercuryStoreCore.showPatchNotesSubject.subscribe(json -> { @@ -118,72 +113,85 @@ public void subscribe() { MercuryStoreUI.packSubject.subscribe(className -> this.framesMap.get(className).pack()); MercuryStoreUI.repaintSubject.subscribe(className -> this.framesMap.get(className).repaint()); } + public void exit() { - this.framesMap.forEach((k,v) -> v.setVisible(false)); + this.framesMap.forEach((k, v) -> v.setVisible(false)); MercuryStoreCore.shutdownAppSubject.onNext(true); } + public void exitForUpdate() { - this.framesMap.forEach((k,v) -> v.setVisible(false)); + this.framesMap.forEach((k, v) -> v.setVisible(false)); MercuryStoreCore.shutdownForUpdateSubject.onNext(true); } - public void showFrame(Class frameClass){ + + public void showFrame(Class frameClass) { this.framesMap.get(frameClass).showComponent(); } - public void preShowFrame(Class frameClass){ + + public void preShowFrame(Class frameClass) { this.framesMap.get(frameClass).setPrevState(FrameVisibleState.SHOW); } - public void hideFrame(Class frameClass){ + + public void hideFrame(Class frameClass) { this.framesMap.get(frameClass).hideComponent(); } - public void hideOrShowFrame(Class frameClass){ + + public void hideOrShowFrame(Class frameClass) { AbstractOverlaidFrame frame = this.framesMap.get(frameClass); - if(frame != null && frame.isVisible()){ + if (frame != null && frame.isVisible()) { hideFrame(frameClass); - }else { + } else { showFrame(frameClass); } } - public void enableMovementExclude(Class... frames){ + + public void enableMovementExclude(Class... frames) { this.locationCommander.setUpAllExclude(frames); } - public void enableOrDisableMovementDirect(Class frameClass){ - this.locationCommander.setOrEndUp(frameClass,false); + + public void enableOrDisableMovementDirect(Class frameClass) { + this.locationCommander.setOrEndUp(frameClass, false); } - public void disableMovement(){ + + public void disableMovement() { this.locationCommander.endUpAll(); } - public void disableMovement(Class frameClass){ + + public void disableMovement(Class frameClass) { this.locationCommander.endUp(frameClass); } - public void enableScale(){ + public void enableScale() { this.showFrame(SetUpScaleFrame.class); this.scaleCommander.setUpAll(); } - public void disableScale(){ + public void disableScale() { this.hideFrame(SetUpScaleFrame.class); this.scaleCommander.endUpAll(); } + public void performAdr() { - if(this.adrManager.getState().equals(AdrState.DEFAULT)) { + if (this.adrManager.getState().equals(AdrState.DEFAULT)) { this.adrManager.enableSettings(); - }else { + } else { this.adrManager.disableSettings(); } } - public void restoreDefaultLocation(){ - this.framesMap.forEach((k,v) -> { + + public void restoreDefaultLocation() { + this.framesMap.forEach((k, v) -> { FrameDescriptor settings = Configuration.get().framesConfiguration().get(k.getSimpleName()); - if(!v.getClass().equals(ItemsGridFrame.class) && settings != null){ + if (!v.getClass().equals(ItemsGridFrame.class) && settings != null) { v.setLocation(settings.getFrameLocation()); - if(v instanceof AbstractMovableComponentFrame){ + if (v instanceof AbstractMovableComponentFrame) { ((AbstractMovableComponentFrame) v).onLocationChange(settings.getFrameLocation()); } } }); } - private void createTrayIcon(){ + + private void createTrayIcon() { PopupMenu trayMenu = new PopupMenu(); MenuItem exit = new MenuItem("Exit"); exit.addActionListener(e -> { @@ -202,7 +210,7 @@ private void createTrayIcon(){ } catch (IOException e) { e.printStackTrace(); } - this.trayIcon = new TrayIcon(icon,"MercuryTrade",trayMenu); + this.trayIcon = new TrayIcon(icon, "MercuryTrade", trayMenu); this.trayIcon.setImageAutoSize(true); SystemTray tray = SystemTray.getSystemTray(); @@ -212,4 +220,8 @@ private void createTrayIcon(){ e.printStackTrace(); } } + + private static class FramesManagerHolder { + static final FramesManager HOLDER_INSTANCE = new FramesManager(); + } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java b/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java index 2696c950..2a773a5e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/manager/HideSettingsManager.java @@ -9,15 +9,14 @@ import java.util.List; public class HideSettingsManager { - private static class HideSettingsManagerHolder { - static final HideSettingsManager HOLDER_INSTANCE = new HideSettingsManager(); - } public static HideSettingsManager INSTANCE = HideSettingsManagerHolder.HOLDER_INSTANCE; private List frames = new ArrayList<>(); - public void registerFrame(AbstractComponentFrame frame){ + + public void registerFrame(AbstractComponentFrame frame) { this.frames.add(frame); } - public void apply(int fadeTime, int minOpacity, int maxOpacity){ + + public void apply(int fadeTime, int minOpacity, int maxOpacity) { ApplicationDescriptor config = Configuration.get().applicationConfiguration().get(); config.setMaxOpacity(maxOpacity); config.setMinOpacity(minOpacity); @@ -25,12 +24,16 @@ public void apply(int fadeTime, int minOpacity, int maxOpacity){ MercuryStoreCore.saveConfigSubject.onNext(true); this.frames.forEach(frame -> { - if(fadeTime > 0){ - frame.enableHideEffect(fadeTime,minOpacity,maxOpacity); - }else { + if (fadeTime > 0) { + frame.enableHideEffect(fadeTime, minOpacity, maxOpacity); + } else { frame.disableHideEffect(); - frame.setOpacity(maxOpacity/100f); + frame.setOpacity(maxOpacity / 100f); } }); } + + private static class HideSettingsManagerHolder { + static final HideSettingsManager HOLDER_INSTANCE = new HideSettingsManager(); + } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/manager/routing/SettingsRoutManager.java b/app-ui/src/main/java/com/mercury/platform/ui/manager/routing/SettingsRoutManager.java index d80ae68a..de081e84 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/manager/routing/SettingsRoutManager.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/manager/routing/SettingsRoutManager.java @@ -6,7 +6,7 @@ import com.mercury.platform.ui.frame.titled.SettingsFrame; import com.mercury.platform.ui.misc.MercuryStoreUI; -public class SettingsRoutManager implements AsSubscriber{ +public class SettingsRoutManager implements AsSubscriber { private SettingsPagePanel generalSettings; private SettingsPagePanel soundSettings; private SettingsPagePanel notificationSettings; @@ -35,28 +35,28 @@ public SettingsRoutManager(SettingsFrame settingsFrame) { @Override public void subscribe() { MercuryStoreUI.settingsStateSubject.subscribe(state -> { - switch (state){ - case GENERAL_SETTINGS:{ + switch (state) { + case GENERAL_SETTINGS: { this.settingsFrame.setContentPanel(this.generalSettings); break; } - case SOUND_SETTING:{ + case SOUND_SETTING: { this.settingsFrame.setContentPanel(this.soundSettings); break; } - case NOTIFICATION_SETTINGS:{ + case NOTIFICATION_SETTINGS: { this.settingsFrame.setContentPanel(this.notificationSettings); break; } - case TASK_BAR_SETTINGS:{ + case TASK_BAR_SETTINGS: { this.settingsFrame.setContentPanel(this.taskBarSettings); break; } - case SUPPORT:{ + case SUPPORT: { this.settingsFrame.setContentPanel(this.supportPanel); break; } - case ABOUT:{ + case ABOUT: { this.settingsFrame.setContentPanel(this.aboutPanel); break; } 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 d3220b79..0df10659 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 @@ -5,23 +5,23 @@ public class AppThemeColor { 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); - public static final Color TEXT_NICKNAME = new Color(255,211,78); - public static final Color TEXT_IMPORTANT = new Color(224,86,60); + 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); + public static final Color TEXT_NICKNAME = new Color(255, 211, 78); + 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 TEXT_DISABLE = new Color(126, 130, 122); 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 = 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); - public static final Color TRANSPARENT = new Color(0,0,0,0); - public static final Color HEADER = new Color(55,65,64); - public static final Color ITEM_HL = new Color(55,65,64,200); + public static final Color FRAME_ALPHA = new Color(42, 44, 43, 1); + public static final Color TRANSPARENT = new Color(0, 0, 0, 0); + public static final Color HEADER = new Color(55, 65, 64); + public static final Color ITEM_HL = new Color(55, 65, 64, 200); public static final Color SLIDE_BG = new Color(45, 55, 54); public static final Color SETTINGS_BG = new Color(41, 52, 51); public static final Color MSG_HEADER = new Color(52, 62, 61); @@ -38,6 +38,6 @@ public class AppThemeColor { public static final Color ADR_TRACKER_GROUP_BG = new Color(35, 45, 44); 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); + 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 d6c3b4ce..d7fba864 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 @@ -23,7 +23,7 @@ public class MercuryStoreUI { public static final PublishSubject expandMessageSubject = PublishSubject.create(); public static final PublishSubject itemCellStateSubject = PublishSubject.create(); //Scale - public static final PublishSubject> saveScaleSubject = PublishSubject.create(); + public static final PublishSubject> saveScaleSubject = PublishSubject.create(); public static final PublishSubject notificationScaleSubject = PublishSubject.create(); public static final PublishSubject taskBarScaleSubject = PublishSubject.create(); public static final PublishSubject itemPanelScaleSubject = PublishSubject.create(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/note/NotesLoader.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/note/NotesLoader.java index d8e65d4c..b5db0d6f 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/note/NotesLoader.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/note/NotesLoader.java @@ -7,35 +7,41 @@ import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -import java.io.*; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class NotesLoader { private final Logger logger = LogManager.getLogger(NotesLoader.class.getSimpleName()); + public NotesLoader() { } - public List getNotesOnFirstStart(){ + + public List getNotesOnFirstStart() { return getNotes("notes/first/first-start.json"); } - public List getPatchNotesFromString(String source){ + + public List getPatchNotesFromString(String source) { return getNotesFromString(source); } - public List getPatchNotes(){ + + public List getPatchNotes() { return getNotes("notes/patch/patch-notes.json"); } + public String getVersionFrom(String source) { String version = ""; JSONParser parser = new JSONParser(); try { JSONObject root = (JSONObject) parser.parse(source); - version = (String)root.get("version"); + version = (String) root.get("version"); } catch (ParseException e) { e.printStackTrace(); } return version; } + private List getNotes(String filePath) { List notes = new ArrayList<>(); JSONParser parser = new JSONParser(); @@ -48,6 +54,7 @@ private List getNotes(String filePath) { } return notes; } + private List getNotesFromString(String source) { List notes = new ArrayList<>(); JSONParser parser = new JSONParser(); @@ -60,6 +67,7 @@ private List getNotesFromString(String source) { } return notes; } + private List getNotesList(JSONArray notesArray) { List notes = new ArrayList<>(); for (JSONObject next : (Iterable) notesArray) {