Skip to content

Commit

Permalink
Add ability to collapse and expand notification groups
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
Zakru committed Jun 16, 2020
1 parent 2a7cf46 commit 03ec31f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
mavenCentral()
}

def runeLiteVersion = '1.6.10.1'
def runeLiteVersion = '1.6.19'

dependencies {
compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion
Expand All @@ -26,7 +26,7 @@ dependencies {
}

group = 'com.github.zakru.advancednotifications'
version = '1.1'
version = '1.1.1'
sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class NotificationGroup extends Notification implements DraggableContaine
@Setter
private String name = "Group";
@Getter
@Setter
private boolean collapsed = false;
@Getter
private final List<Notification> notifications = new ArrayList<>();

public NotificationGroup(AdvancedNotificationsPlugin plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class NotificationGroupPanel extends NotificationPanel<NotificationGroup>
private static final ImageIcon RENAME_ICON;
private static final ImageIcon RENAME_HOVER_ICON;

private static final ImageIcon COLLAPSE_ICON;
private static final ImageIcon COLLAPSE_HOVER_ICON;
private static final ImageIcon EXPAND_ICON;
private static final ImageIcon EXPAND_HOVER_ICON;

private final JTextField nameLabel;
private final JLabel rename;

Expand All @@ -36,6 +41,16 @@ public class NotificationGroupPanel extends NotificationPanel<NotificationGroup>
= ImageUtil.getResourceStreamFromClass(AdvancedNotificationsPlugin.class, "rename_icon.png");
RENAME_ICON = new ImageIcon(renameIcon);
RENAME_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(renameIcon, 0.53f));

final BufferedImage collapseIcon
= ImageUtil.getResourceStreamFromClass(AdvancedNotificationsPlugin.class, "collapse_icon.png");
COLLAPSE_ICON = new ImageIcon(collapseIcon);
COLLAPSE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(collapseIcon, 0.53f));

final BufferedImage expandIcon
= ImageUtil.getResourceStreamFromClass(AdvancedNotificationsPlugin.class, "expand_icon.png");
EXPAND_ICON = new ImageIcon(expandIcon);
EXPAND_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(expandIcon, 0.53f));
}

public NotificationGroupPanel(NotificationGroup notification, DraggableContainer container)
Expand Down Expand Up @@ -152,28 +167,57 @@ public void mouseExited(MouseEvent e)
actions.add(new EnabledButton(notification.getPlugin(), notification));
actions.add(deleteButton);

JLabel collapseOrExpand = new JLabel(notification.isCollapsed() ? EXPAND_ICON : COLLAPSE_ICON);
collapseOrExpand.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent e)
{
notification.setCollapsed(!notification.isCollapsed());
notification.getPlugin().updateConfig();
notification.getPlugin().rebuildPluginPanel();
}

@Override
public void mouseEntered(MouseEvent e)
{
collapseOrExpand.setIcon(notification.isCollapsed() ? EXPAND_HOVER_ICON : COLLAPSE_HOVER_ICON);
}

@Override
public void mouseExited(MouseEvent e)
{
collapseOrExpand.setIcon(notification.isCollapsed() ? EXPAND_ICON : COLLAPSE_ICON);
}
});

northPanel.add(collapseOrExpand, BorderLayout.WEST);
northPanel.add(nameLabel, BorderLayout.CENTER);
northPanel.add(actions, BorderLayout.EAST);

JPanel notificationView = new JPanel();
notificationView.setLayout(new BoxLayout(notificationView, BoxLayout.Y_AXIS));
notificationView.setOpaque(false);
notificationView.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
add(northPanel, BorderLayout.NORTH);

int index = 0;
notificationView.add(new DropSpace(plugin, notification, index++));
for (final Notification notif : notification.getNotifications())
if (!notification.isCollapsed())
{
NotificationPanel<?> panel = NotificationPanel.buildPanel(notification, notif);
if (panel != null)
JPanel notificationView = new JPanel();
notificationView.setLayout(new BoxLayout(notificationView, BoxLayout.Y_AXIS));
notificationView.setOpaque(false);
notificationView.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));

int index = 0;
notificationView.add(new DropSpace(plugin, notification, index++));
for (final Notification notif : notification.getNotifications())
{
notificationView.add(panel);
notificationView.add(new DropSpace(plugin, notification, index++));
NotificationPanel<?> panel = NotificationPanel.buildPanel(notification, notif);
if (panel != null)
{
notificationView.add(panel);
notificationView.add(new DropSpace(plugin, notification, index++));
}
}
}

add(northPanel, BorderLayout.NORTH);
add(notificationView, BorderLayout.CENTER);
add(notificationView, BorderLayout.CENTER);
}
}

public void resetScroll()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 03ec31f

Please sign in to comment.