From 4679bdad77d257d40528b62b3e96e5d3d609c204 Mon Sep 17 00:00:00 2001 From: Ruben Amendoeira Date: Sun, 22 Apr 2018 04:44:13 +0100 Subject: [PATCH] Kourend Library Plugin slight design tweak - Spaced out the item panels vertically and slightly horizontally. - Added a new header with the plugin's name, as it can be hard to know what this plugin does/is. - Restyled the reset button, it previously was a "Reset" text button, I switched it to an icon with a darker version that activates when clicked. - Added the icon images to the resource folder. - Added new method to SwingUtil that returns a darker version of an image - Used the image darkening method to give the refresh button a click feedback effect --- .../plugins/kourendlibrary/BookPanel.java | 6 +- .../kourendlibrary/KourendLibraryPanel.java | 79 ++++++++++++++++-- .../net/runelite/client/util/SwingUtil.java | 37 ++++++++ .../client/plugins/kourendlibrary/reset.png | Bin 0 -> 16069 bytes 4 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java index b819731a03..5c169aab11 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java @@ -28,6 +28,7 @@ import java.awt.Color; import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; import net.runelite.client.ui.FontManager; class BookPanel extends JPanel @@ -36,6 +37,9 @@ class BookPanel extends JPanel BookPanel(Book b) { + setBorder(new EmptyBorder(3, 3, 3, 3)); + setOpaque(false); + GroupLayout layout = new GroupLayout(this); this.setLayout(layout); @@ -74,4 +78,4 @@ class BookPanel extends JPanel { location.setForeground(target ? Color.GREEN : Color.WHITE); } -} +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java index fb894ee2a8..1afaf27961 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Abex + * Copyright (c) 2018 Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,35 +26,71 @@ package net.runelite.client.plugins.kourendlibrary; import com.google.inject.Inject; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.imageio.ImageIO; import javax.inject.Singleton; +import javax.swing.BorderFactory; import javax.swing.GroupLayout; -import javax.swing.JButton; +import javax.swing.ImageIcon; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.PluginPanel; +import net.runelite.client.util.SwingUtil; @Singleton public class KourendLibraryPanel extends PluginPanel { + private static final ImageIcon RESET_ICON; + private static final ImageIcon RESET_CLICK_ICON; + @Inject private Library library; private final HashMap bookPanels = new HashMap<>(); + static + { + try + { + synchronized (ImageIO.class) + { + BufferedImage resetIcon = ImageIO.read(KourendLibraryPanel.class.getResourceAsStream("reset.png")); + RESET_ICON = new ImageIcon(resetIcon); + RESET_CLICK_ICON = new ImageIcon(SwingUtil.grayscaleOffset(resetIcon, -100)); + } + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + void init() { GroupLayout layout = new GroupLayout(this); setLayout(layout); + setBorder(new EmptyBorder(10, 10, 10, 10)); + setBackground(ColorScheme.DARK_GRAY_COLOR); JPanel books = new JPanel(new GridBagLayout()); + books.setOpaque(false); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; @@ -70,21 +107,45 @@ public class KourendLibraryPanel extends PluginPanel c.gridy++; }); - JButton reset = new JButton("Reset"); - reset.addActionListener(e -> + JLabel reset = new JLabel(RESET_ICON); + reset.addMouseListener(new MouseAdapter() { - library.reset(); - update(); + @Override + public void mousePressed(MouseEvent mouseEvent) + { + reset.setIcon(RESET_CLICK_ICON); + library.reset(); + update(); + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) + { + reset.setIcon(RESET_ICON); + } }); + JPanel header = new JPanel(); + header.setOpaque(false); + header.setLayout(new BorderLayout()); + header.setBorder(new CompoundBorder( + BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(58, 58, 58)), + BorderFactory.createEmptyBorder(0, 0, 10, 0))); + + JLabel pluginName = new JLabel("Kourend Library Plugin"); + pluginName.setForeground(Color.WHITE); + + header.add(reset, BorderLayout.EAST); + header.add(pluginName, BorderLayout.CENTER); + layout.setHorizontalGroup(layout.createParallelGroup() .addComponent(books) - .addComponent(reset) + .addComponent(header) ); layout.setVerticalGroup(layout.createSequentialGroup() + .addComponent(header) + .addGap(10) .addComponent(books) - .addGap(4) - .addComponent(reset) ); update(); @@ -134,4 +195,4 @@ public class KourendLibraryPanel extends PluginPanel } }); } -} +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java index 41ddd1b9fb..90790cbf36 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java @@ -32,6 +32,7 @@ import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Rectangle; +import java.awt.RenderingHints; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; @@ -41,6 +42,8 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; +import java.awt.image.LookupOp; +import java.awt.image.LookupTable; import java.util.Enumeration; import java.util.concurrent.Callable; import java.util.function.BiConsumer; @@ -95,6 +98,40 @@ public class SwingUtil System.setProperty("sun.awt.noerasebackground", "true"); } + /** + * Offsets an image in the grayscale (darkens/brightens) by an offset + */ + public static BufferedImage grayscaleOffset(BufferedImage image, int offset) + { + int numComponents = image.getColorModel().getNumComponents(); + int index = numComponents - 1; + + LookupTable lookup = new LookupTable(0, numComponents) + { + @Override + public int[] lookupPixel(int[] src, int[] dest) + { + if (dest[index] != 0) + { + dest[index] = dest[index] + offset; + if (dest[index] < 0) + { + dest[index] = 0; + } + else if (dest[index] > 255) + { + dest[index] = 255; + } + } + + return dest; + } + }; + + LookupOp op = new LookupOp(lookup, new RenderingHints(null)); + return op.filter(image, null); + } + /** * Converts a given color to it's hexidecimal equivalent. */ diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png b/runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png new file mode 100644 index 0000000000000000000000000000000000000000..e94f6102a5cd22911c1e858557a9eb5c96decb4a GIT binary patch literal 16069 zcmeI3dsGuw8o0B2tiC#u%f(Fu=p4z6BtM`F$oYJivqP3 z>w{VqU*MyQU7uL1R%@-)f>l?g3P-!zR#3o4!P;8IE*#lA36F4rIiAz**?(rvfy{Tm z*WBN|-*@MqDTtUkZHW8d+z|vB5*DhB0>3ZQe}e~t|83t){T}?hXbz3DB8bN@`fmWT zdFx07;fy3Tnuv%b%0^j}C^I)qqv4t@l%6yY2x7mEFIrSmd-qoT`Pa(JBO+p=>V4`* zdV6}8mgkh@uFBn%OJ8G!$B&f@x#jQC_h>M>egG%?#F_H5<>lq(xNDay&#ljuly8oY zh&c@gmgeSuHF5lr0N`5Z!Qp5!Gr~e%Hv``Gjfz7a4VaZc~ z4JY546GBAlGp82h?I_oTU9)>I*JIO*udcRXiKjij{g54 z@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