From 9372ffdefafddaee241e14446dc4b9ce7dc4ca72 Mon Sep 17 00:00:00 2001 From: Exslims Date: Thu, 24 Aug 2017 16:05:10 +0400 Subject: [PATCH] Upwards works as it should --- .../IncomingNotificationPanel.java | 41 ++---- .../ItemIncNotificationPanel.java | 15 +- .../panel/notification/NotificationPanel.java | 23 +++ .../OutgoingNotificationPanel.java | 25 +--- .../ScannerNotificationPanel.java | 17 --- .../ui/frame/movable/NotificationFrame.java | 133 ++++++++++++++---- .../ui/frame/setup/scale/ScaleState.java | 4 +- 7 files changed, 147 insertions(+), 111 deletions(-) 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 516f231a..fcde5645 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 @@ -24,12 +24,9 @@ import java.util.Objects; public abstract class IncomingNotificationPanel extends NotificationPanel { - private PlainConfigurationService config; + protected PlainConfigurationService config; private PlainConfigurationService hotKeysConfig; - private JPanel messagePanel; private JPanel responseButtonsPanel; - private JPanel chatPanel; - private JPanel chatContainer; private Subscription chatSubscription; @Override @@ -37,24 +34,24 @@ public void onViewInit() { super.onViewInit(); this.config = Configuration.get().notificationConfiguration(); this.hotKeysConfig = Configuration.get().hotKeysConfiguration(); - this.messagePanel = this.getMessagePanel(); - this.responseButtonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2)); - this.responseButtonsPanel.setBackground(AppThemeColor.FRAME); + this.responseButtonsPanel = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER, 5, 2), AppThemeColor.FRAME); this.chatPanel = this.getChatPanel(); this.chatPanel.setVisible(false); + this.contentPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); switch (config.get().getFlowDirections()) { case DOWNWARDS: { this.add(this.getHeader(), BorderLayout.PAGE_START); - this.add(this.responseButtonsPanel, BorderLayout.PAGE_END); + this.contentPanel.add(this.responseButtonsPanel, BorderLayout.PAGE_END); break; } case UPWARDS: { this.add(this.getHeader(), BorderLayout.PAGE_END); - this.add(this.responseButtonsPanel, BorderLayout.PAGE_START); + this.contentPanel.add(this.responseButtonsPanel, BorderLayout.PAGE_START); break; } } - this.add(this.messagePanel, BorderLayout.CENTER); + this.contentPanel.add(this.getMessagePanel(), BorderLayout.CENTER); + this.add(this.contentPanel, BorderLayout.CENTER); this.updateHotKeyPool(); } @@ -95,11 +92,9 @@ private JPanel getHeader() { 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); + this.add(this.contentPanel, BorderLayout.CENTER); } else { - this.remove(this.messagePanel); - this.remove(this.responseButtonsPanel); + this.remove(this.contentPanel); this.chatPanel.setVisible(true); this.add(this.chatPanel, BorderLayout.CENTER); } @@ -302,22 +297,4 @@ private String getNicknameText() { } return result; } - - private JButton getExpandButton() { - String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); - expandButton.addActionListener(action -> { - if (this.messagePanel.isVisible()) { - this.messagePanel.setVisible(false); - this.responseButtonsPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png", 18f)); - } else { - this.messagePanel.setVisible(true); - this.responseButtonsPanel.setVisible(true); - expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); - } - SwingUtilities.getWindowAncestor(IncomingNotificationPanel.this).pack(); - }); - return expandButton; - } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemIncNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ItemIncNotificationPanel.java index 5e05bdad..7deac9ef 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 @@ -15,14 +15,12 @@ public class ItemIncNotificationPanel extends IncomingNotificationPanel { this.controller.showITH(); }); - this.labelsPanel.add(itemButton, BorderLayout.CENTER); JButton openChatButton = componentsFactory.getIconButton("app/openChat.png", 15, AppThemeColor.FRAME, TooltipConstants.OPEN_CHAT); openChatButton.addActionListener(e -> controller.performOpenChat()); @@ -42,15 +39,17 @@ protected JPanel getMessagePanel() { buttons.add(stillInterestedButton); buttons.add(openChatButton); + JPanel miscPanel = this.componentsFactory.getJPanel(new GridLayout(1, 0, 4, 0), AppThemeColor.FRAME); + miscPanel.add(itemButton); JLabel offerLabel = this.getOfferLabel(); if (offerLabel != null) { - this.labelsPanel.add(offerLabel, BorderLayout.PAGE_END); + miscPanel.add(offerLabel); } - labelsPanel.add(buttons, BorderLayout.LINE_END); + this.labelsPanel.add(miscPanel, BorderLayout.CENTER); + this.labelsPanel.add(buttons, BorderLayout.LINE_END); return labelsPanel; } - @Override public void setDuplicate(boolean duplicate) { if (duplicate) { JButton ignoreButton = componentsFactory.getIconButton("app/adr/visible_node_off.png", 15, AppThemeColor.FRAME, "Ignore item 1 hour"); 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 c117ecda..76e74c2a 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 @@ -9,6 +9,7 @@ import com.mercury.platform.ui.components.fields.font.TextAlignment; import com.mercury.platform.ui.components.panel.misc.ViewDestroy; import com.mercury.platform.ui.components.panel.misc.ViewInit; +import com.mercury.platform.ui.frame.movable.NotificationFrame; import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; import lombok.Getter; @@ -37,6 +38,9 @@ public abstract class NotificationPanel extends JPanel implements AsSubscr protected boolean blurReverse; @Setter protected boolean duplicate; + protected JPanel chatPanel; + protected JPanel chatContainer; + protected JPanel contentPanel; @Setter private float paintAlphaValue = 1f; private Subscription settingsPostSubscription; @@ -114,6 +118,25 @@ public void actionPerformed(ActionEvent e) { return root; } + protected JButton getExpandButton() { + String iconPath = "app/expand-mp.png"; + JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); + expandButton.addActionListener(action -> { + NotificationFrame frame = (NotificationFrame) SwingUtilities.getWindowAncestor(NotificationPanel.this); + if (this.contentPanel.isVisible()) { + this.contentPanel.setVisible(false); + expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png", 18f)); + frame.changeBufferSize(this.contentPanel.getPreferredSize().height); + } else { + this.contentPanel.setVisible(true); + expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); + frame.changeBufferSize(-this.contentPanel.getPreferredSize().height); + } + frame.pack(); + }); + return expandButton; + } + protected void onBlur() { this.blurEffect = true; this.setBorder(BorderFactory.createCompoundBorder( 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 04be4a51..a3871cbd 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 @@ -22,7 +22,6 @@ public abstract class OutgoingNotificationPanel config; private PlainConfigurationService hotKeysConfig; private JPanel responseButtonsPanel; - private JPanel bottomPanel; @Override public void onViewInit() { @@ -33,10 +32,10 @@ public void onViewInit() { 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.contentPanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); + this.contentPanel.add(this.getContentPanel(), BorderLayout.CENTER); + this.contentPanel.add(this.componentsFactory.wrapToSlide(this.responseButtonsPanel, AppThemeColor.FRAME), BorderLayout.LINE_END); + this.add(contentPanel, BorderLayout.CENTER); this.updateHotKeyPool(); } @@ -198,20 +197,4 @@ public void subscribe() { public void onViewDestroy() { super.onViewDestroy(); } - - private JButton getExpandButton() { - String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); - expandButton.addActionListener(action -> { - if (this.bottomPanel.isVisible()) { - this.bottomPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png", 18f)); - } else { - this.bottomPanel.setVisible(true); - expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); - } - SwingUtilities.getWindowAncestor(OutgoingNotificationPanel.this).pack(); - }); - return expandButton; - } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ScannerNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/ScannerNotificationPanel.java index e1d0d973..d286dc60 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 @@ -18,7 +18,6 @@ public class ScannerNotificationPanel extends NotificationPanel config; private PlainConfigurationService nConfig; private PlainConfigurationService hotKeysConfig; - private JPanel contentPanel; @Override public void onViewInit() { @@ -118,20 +117,4 @@ protected void updateHotKeyPool() { public void onViewDestroy() { super.onViewDestroy(); } - - private JButton getExpandButton() { - String iconPath = "app/expand-mp.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 18f, AppThemeColor.MSG_HEADER, ""); - expandButton.addActionListener(action -> { - if (this.contentPanel.isVisible()) { - this.contentPanel.setVisible(false); - expandButton.setIcon(this.componentsFactory.getIcon("app/default-mp.png", 18f)); - } else { - this.contentPanel.setVisible(true); - expandButton.setIcon(this.componentsFactory.getIcon("app/expand-mp.png", 18f)); - } - SwingUtilities.getWindowAncestor(ScannerNotificationPanel.this).pack(); - }); - return expandButton; - } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/NotificationFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/movable/NotificationFrame.java index f99413d2..1c2dc170 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 @@ -6,6 +6,7 @@ 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.NotificationDescriptor; import com.mercury.platform.shared.entity.message.NotificationType; import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.components.ComponentsFactory; @@ -28,6 +29,7 @@ public class NotificationFrame extends AbstractMovableComponentFrame { + private static int BUFFER_DEFAULT_HEIGHT = 1500; private List notificationPanels; private List currentOffers; private PlainConfigurationService config; @@ -35,7 +37,11 @@ public class NotificationFrame extends AbstractMovableComponentFrame { private JPanel container; private JPanel expandPanel; private JPanel stubExpandPanel; + private JPanel root; private boolean expanded; + private FlowDirections flowDirections; + + private JPanel buffer; @Override protected void initialize() { @@ -52,15 +58,24 @@ protected void initialize() { public void onViewInit() { this.getRootPane().setBorder(null); this.setBackground(AppThemeColor.TRANSPARENT); + this.flowDirections = this.config.get().getFlowDirections(); this.currentOffers = new ArrayList<>(); this.container = new JPanel(); this.container.setBackground(AppThemeColor.TRANSPARENT); this.container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); + + this.buffer = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.TRANSPARENT); + this.buffer.setPreferredSize(new Dimension(10, BUFFER_DEFAULT_HEIGHT)); + this.setLocation(new Point(this.getLocation().x, this.getLocation().y - BUFFER_DEFAULT_HEIGHT)); + this.expandPanel = this.getExpandPanel(); 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.stubExpandPanel.setPreferredSize(new Dimension(this.expandPanel.getPreferredSize().width, 5)); + this.root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.TRANSPARENT); + this.root.add(this.stubExpandPanel, BorderLayout.LINE_START); + this.root.add(this.container, BorderLayout.CENTER); + this.add(this.buffer, BorderLayout.CENTER); + this.add(root, BorderLayout.PAGE_END); this.setVisible(true); this.pack(); } @@ -106,7 +121,9 @@ public void subscribe() { .filter(it -> it.getData().equals(notification)) .findAny().orElse(null); this.currentOffers.remove(StringUtils.substringAfter(notification.getSourceString(), ":")); - this.removeNotification(notificationPanel); + if (notificationPanel != null) { + this.removeNotification(notificationPanel); + } }); }); MercuryStoreCore.removeScannerNotificationSubject.subscribe(message -> { @@ -125,48 +142,79 @@ public void subscribe() { }); }); MercuryStoreUI.settingsPostSubject.subscribe(state -> { - if (this.config.get().getFlowDirections().equals(FlowDirections.DOWNWARDS)) { - this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); + this.validateContainer(); + }); + } + + @SuppressWarnings("all") + private void validateContainer() { + List currentPanels = new ArrayList<>(this.notificationPanels); + currentPanels.forEach(this::removeNotification); + this.flowDirections = this.config.get().getFlowDirections(); + currentPanels.forEach(it -> { + NotificationPanel notificationPanel = null; + if (it.getData() instanceof NotificationDescriptor) { + notificationPanel = this.providersFactory.getProviderFor(((NotificationDescriptor) it.getData()).getType()) + .setData(it.getData()) + .setComponentsFactory(this.componentsFactory) + .build(); + } else { + notificationPanel = this.providersFactory.getProviderFor(NotificationType.SCANNER_MESSAGE) + .setData(it.getData()) + .setComponentsFactory(this.componentsFactory) + .build(); } + this.addNotification(notificationPanel); }); } private void addNotification(NotificationPanel notificationPanel) { this.notificationPanels.add(notificationPanel); - this.container.add(notificationPanel); + if (this.flowDirections.equals(FlowDirections.UPWARDS)) { + this.container.add( + this.componentsFactory.wrapToSlide( + notificationPanel, AppThemeColor.TRANSPARENT, 1, 1, 1, 1), 0); + } else { + this.container.add(this.componentsFactory.wrapToSlide(notificationPanel, AppThemeColor.TRANSPARENT, 1, 1, 1, 1)); + } + int delta = -notificationPanel.getParent().getPreferredSize().height; if (this.notificationPanels.size() > this.config.get().getLimitCount()) { if (!this.expanded) { - notificationPanel.setVisible(false); + notificationPanel.getParent().setVisible(false); + delta = 0; } - this.remove(this.stubExpandPanel); - this.add(this.expandPanel, BorderLayout.LINE_START); + this.root.remove(this.stubExpandPanel); + this.root.add(this.expandPanel, BorderLayout.LINE_START); + } + if (this.flowDirections.equals(FlowDirections.UPWARDS) && + this.notificationPanels.size() > 1) { + this.changeBufferSize(delta); } 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)); - } } private void removeNotification(NotificationPanel notificationPanel) { + int delta = notificationPanel.getParent().getPreferredSize().height; notificationPanel.onViewDestroy(); int limitCount = this.config.get().getLimitCount(); if (!this.expanded && this.notificationPanels.size() > limitCount) { - this.notificationPanels.get(limitCount).setVisible(true); + NotificationPanel panel = this.notificationPanels.get(limitCount); + panel.getParent().setVisible(true); + delta -= panel.getParent().getPreferredSize().height; } - this.container.remove(notificationPanel); + this.container.remove(notificationPanel.getParent()); this.notificationPanels.remove(notificationPanel); + if (this.flowDirections.equals(FlowDirections.UPWARDS) + && this.notificationPanels.size() > 0) { + this.changeBufferSize(delta); + } if (this.notificationPanels.size() - 1 < this.config.get().getLimitCount()) { - this.remove(this.expandPanel); - this.add(this.stubExpandPanel, BorderLayout.LINE_START); + this.root.remove(this.expandPanel); + this.root.add(this.stubExpandPanel, BorderLayout.LINE_START); } this.pack(); this.repaint(); - if (this.config.get().getFlowDirections().equals(FlowDirections.UPWARDS) - && this.notificationPanels.size() == 0) { - this.setLocation(this.framesConfig.get("NotificationFrame").getFrameLocation()); - } } @Override @@ -181,6 +229,12 @@ protected void onScaleLock() { super.onScaleLock(); } + public void changeBufferSize(int delta) { + if (this.flowDirections.equals(FlowDirections.UPWARDS)) { + this.buffer.setPreferredSize(new Dimension(10, this.buffer.getPreferredSize().height + delta)); + } + } + @Override protected JPanel getPanelForPINSettings() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.FRAME); @@ -196,10 +250,18 @@ protected JPanel getPanelForPINSettings() { 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.setPreferredSize(new Dimension((int) (400 * componentsFactory.getScale()), (int) (92 * componentsFactory.getScale()))); return root; } + @Override + protected void onLock() { + super.onLock(); + if (this.getLocation().y > 0) { + this.setLocation(new Point(this.getLocation().x, this.getLocation().y - BUFFER_DEFAULT_HEIGHT)); + } + } + @Override protected void registerDirectScaleHandler() { MercuryStoreUI.notificationScaleSubject.subscribe(this::changeScale); @@ -246,7 +308,7 @@ 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.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, ""); @@ -256,14 +318,25 @@ private JPanel getExpandPanel() { this.notificationPanels .stream() .skip(this.config.get().getLimitCount()) - .forEach(it -> it.setVisible(false)); + .forEach(it -> it.getParent().setVisible(false)); + if (this.flowDirections.equals(FlowDirections.UPWARDS)) { + this.changeBufferSize(this.notificationPanels + .stream() + .skip(this.config.get().getLimitCount()) + .mapToInt(it -> it.getParent().getPreferredSize().height).sum()); + } } else { expandButton.setIcon(this.componentsFactory.getIcon("app/expand-all.png", 22)); - this.notificationPanels.forEach(it -> { - if (!it.isVisible()) { - it.setVisible(true); + int delta = 0; + for (NotificationPanel it : this.notificationPanels) { + if (!it.getParent().isVisible()) { + it.getParent().setVisible(true); + delta += it.getParent().getPreferredSize().height; } - }); + } + if (this.flowDirections.equals(FlowDirections.UPWARDS)) { + this.changeBufferSize(-delta); + } } this.expanded = !this.expanded; this.pack(); @@ -271,6 +344,6 @@ private JPanel getExpandPanel() { }); expandButton.setAlignmentY(SwingConstants.CENTER); root.add(expandButton, BorderLayout.CENTER); - return root; + return this.componentsFactory.wrapToSlide(root, AppThemeColor.TRANSPARENT, 1, 1, 1, 1); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/ScaleState.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/ScaleState.java index 91bfaad5..cec5c2ff 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/ScaleState.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/setup/scale/ScaleState.java @@ -1,8 +1,6 @@ package com.mercury.platform.ui.frame.setup.scale; -/** - * Created by Константин on 24.03.2017. - */ + public enum ScaleState { DEFAULT, ENABLE }