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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Book, BookPanel> 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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user