Move IconTextField common icons to IconTextField.Icon class
To unify the access to the icons that are anyway residing near IconTextField, move the declarations to IconTextField.Icon class. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -96,7 +96,6 @@ public class ConfigPanel extends PluginPanel
|
|||||||
private static final int OFFSET = 6;
|
private static final int OFFSET = 6;
|
||||||
private static final ImageIcon BACK_ICON;
|
private static final ImageIcon BACK_ICON;
|
||||||
private static final ImageIcon BACK_ICON_HOVER;
|
private static final ImageIcon BACK_ICON_HOVER;
|
||||||
private static final ImageIcon SEARCH;
|
|
||||||
|
|
||||||
private static final String RUNELITE_GROUP_NAME = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).value();
|
private static final String RUNELITE_GROUP_NAME = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).value();
|
||||||
private static final String PINNED_PLUGINS_CONFIG_KEY = "pinnedPlugins";
|
private static final String PINNED_PLUGINS_CONFIG_KEY = "pinnedPlugins";
|
||||||
@@ -109,9 +108,9 @@ public class ConfigPanel extends PluginPanel
|
|||||||
private final ScheduledExecutorService executorService;
|
private final ScheduledExecutorService executorService;
|
||||||
private final RuneLiteConfig runeLiteConfig;
|
private final RuneLiteConfig runeLiteConfig;
|
||||||
private final ChatColorConfig chatColorConfig;
|
private final ChatColorConfig chatColorConfig;
|
||||||
private final IconTextField searchBar = new IconTextField();
|
|
||||||
private final List<PluginListItem> pluginList = new ArrayList<>();
|
private final List<PluginListItem> pluginList = new ArrayList<>();
|
||||||
|
|
||||||
|
private final IconTextField searchBar = new IconTextField();
|
||||||
private final JPanel topPanel;
|
private final JPanel topPanel;
|
||||||
private final JPanel mainPanel;
|
private final JPanel mainPanel;
|
||||||
private final JScrollPane scrollPane;
|
private final JScrollPane scrollPane;
|
||||||
@@ -124,7 +123,6 @@ public class ConfigPanel extends PluginPanel
|
|||||||
final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png");
|
final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png");
|
||||||
BACK_ICON = new ImageIcon(backIcon);
|
BACK_ICON = new ImageIcon(backIcon);
|
||||||
BACK_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(backIcon, -100));
|
BACK_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(backIcon, -100));
|
||||||
SEARCH = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,
|
ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,
|
||||||
@@ -137,7 +135,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
this.runeLiteConfig = runeLiteConfig;
|
this.runeLiteConfig = runeLiteConfig;
|
||||||
this.chatColorConfig = chatColorConfig;
|
this.chatColorConfig = chatColorConfig;
|
||||||
|
|
||||||
searchBar.setIcon(SEARCH);
|
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||||
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
|
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
|
||||||
searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
|
searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
@@ -50,7 +49,6 @@ import net.runelite.client.game.ItemManager;
|
|||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.components.IconTextField;
|
import net.runelite.client.ui.components.IconTextField;
|
||||||
import net.runelite.client.ui.components.PluginErrorPanel;
|
import net.runelite.client.ui.components.PluginErrorPanel;
|
||||||
import net.runelite.client.util.ImageUtil;
|
|
||||||
import net.runelite.client.util.RunnableExceptionLogger;
|
import net.runelite.client.util.RunnableExceptionLogger;
|
||||||
import net.runelite.http.api.item.Item;
|
import net.runelite.http.api.item.Item;
|
||||||
import net.runelite.http.api.item.SearchResult;
|
import net.runelite.http.api.item.SearchResult;
|
||||||
@@ -65,10 +63,6 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
private static final String ERROR_PANEL = "ERROR_PANEL";
|
private static final String ERROR_PANEL = "ERROR_PANEL";
|
||||||
private static final String RESULTS_PANEL = "RESULTS_PANEL";
|
private static final String RESULTS_PANEL = "RESULTS_PANEL";
|
||||||
|
|
||||||
private static final ImageIcon SEARCH_ICON;
|
|
||||||
private static final ImageIcon LOADING_ICON;
|
|
||||||
private static final ImageIcon ERROR_ICON;
|
|
||||||
|
|
||||||
private final GridBagConstraints constraints = new GridBagConstraints();
|
private final GridBagConstraints constraints = new GridBagConstraints();
|
||||||
private final CardLayout cardLayout = new CardLayout();
|
private final CardLayout cardLayout = new CardLayout();
|
||||||
|
|
||||||
@@ -76,7 +70,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
private final ItemManager itemManager;
|
private final ItemManager itemManager;
|
||||||
private final ScheduledExecutorService executor;
|
private final ScheduledExecutorService executor;
|
||||||
|
|
||||||
private final IconTextField searchBox = new IconTextField();
|
private final IconTextField searchBar = new IconTextField();
|
||||||
|
|
||||||
/* The main container, this holds the search bar and the center panel */
|
/* The main container, this holds the search bar and the center panel */
|
||||||
private final JPanel container = new JPanel();
|
private final JPanel container = new JPanel();
|
||||||
@@ -98,13 +92,6 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
@Setter
|
@Setter
|
||||||
private Map<Integer, Integer> itemGELimits = Collections.emptyMap();
|
private Map<Integer, Integer> itemGELimits = Collections.emptyMap();
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
SEARCH_ICON = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.grayscaleOffset(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"), 0f), 1.75f));
|
|
||||||
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner.gif"));
|
|
||||||
ERROR_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "error.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
GrandExchangeSearchPanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor)
|
GrandExchangeSearchPanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor)
|
||||||
{
|
{
|
||||||
this.clientThread = clientThread;
|
this.clientThread = clientThread;
|
||||||
@@ -113,7 +100,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
private void init()
|
||||||
{
|
{
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||||
@@ -122,11 +109,11 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
container.setBorder(new EmptyBorder(10, 10, 10, 10));
|
container.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
container.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
container.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||||
|
|
||||||
searchBox.setPreferredSize(new Dimension(100, 30));
|
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||||
searchBox.setBackground(ColorScheme.MEDIUM_GRAY_COLOR);
|
searchBar.setPreferredSize(new Dimension(100, 30));
|
||||||
searchBox.setHoverBackgroundColor(ColorScheme.MEDIUM_GRAY_COLOR.brighter());
|
searchBar.setBackground(ColorScheme.MEDIUM_GRAY_COLOR);
|
||||||
searchBox.setIcon(SEARCH_ICON);
|
searchBar.setHoverBackgroundColor(ColorScheme.MEDIUM_GRAY_COLOR.brighter());
|
||||||
searchBox.addActionListener(e -> executor.execute(RunnableExceptionLogger.wrap(() -> priceLookup(false))));
|
searchBar.addActionListener(e -> executor.execute(RunnableExceptionLogger.wrap(() -> priceLookup(false))));
|
||||||
|
|
||||||
searchItemsPanel.setLayout(new GridBagLayout());
|
searchItemsPanel.setLayout(new GridBagLayout());
|
||||||
searchItemsPanel.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
searchItemsPanel.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||||
@@ -160,7 +147,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
|
|
||||||
cardLayout.show(centerPanel, ERROR_PANEL);
|
cardLayout.show(centerPanel, ERROR_PANEL);
|
||||||
|
|
||||||
container.add(searchBox, BorderLayout.NORTH);
|
container.add(searchBar, BorderLayout.NORTH);
|
||||||
container.add(centerPanel, BorderLayout.CENTER);
|
container.add(centerPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
add(container, BorderLayout.CENTER);
|
add(container, BorderLayout.CENTER);
|
||||||
@@ -168,13 +155,13 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
|
|
||||||
void priceLookup(String item)
|
void priceLookup(String item)
|
||||||
{
|
{
|
||||||
searchBox.setText(item);
|
searchBar.setText(item);
|
||||||
executor.execute(RunnableExceptionLogger.wrap(() -> priceLookup(true)));
|
executor.execute(RunnableExceptionLogger.wrap(() -> priceLookup(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void priceLookup(boolean exactMatch)
|
private void priceLookup(boolean exactMatch)
|
||||||
{
|
{
|
||||||
String lookup = searchBox.getText();
|
String lookup = searchBar.getText();
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(lookup))
|
if (Strings.isNullOrEmpty(lookup))
|
||||||
{
|
{
|
||||||
@@ -185,9 +172,9 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
|
|
||||||
// Input is not empty, add searching label
|
// Input is not empty, add searching label
|
||||||
searchItemsPanel.removeAll();
|
searchItemsPanel.removeAll();
|
||||||
searchBox.setBackground(ColorScheme.MEDIUM_GRAY_COLOR);
|
searchBar.setBackground(ColorScheme.MEDIUM_GRAY_COLOR);
|
||||||
searchBox.setEditable(false);
|
searchBar.setEditable(false);
|
||||||
searchBox.setIcon(LOADING_ICON);
|
searchBar.setIcon(IconTextField.Icon.LOADING);
|
||||||
|
|
||||||
SearchResult result;
|
SearchResult result;
|
||||||
|
|
||||||
@@ -198,8 +185,8 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
catch (Exception ex) // handle com.google.common.cache.CacheLoader$InvalidCacheLoadException
|
catch (Exception ex) // handle com.google.common.cache.CacheLoader$InvalidCacheLoadException
|
||||||
{
|
{
|
||||||
log.warn("Unable to search for item {}", lookup, ex);
|
log.warn("Unable to search for item {}", lookup, ex);
|
||||||
searchBox.setIcon(ERROR_ICON);
|
searchBar.setIcon(IconTextField.Icon.ERROR);
|
||||||
searchBox.setEditable(true);
|
searchBar.setEditable(true);
|
||||||
errorPanel.setContent("Error fetching results", "An error occurred while trying to fetch item data, please try again later.");
|
errorPanel.setContent("Error fetching results", "An error occurred while trying to fetch item data, please try again later.");
|
||||||
cardLayout.show(centerPanel, ERROR_PANEL);
|
cardLayout.show(centerPanel, ERROR_PANEL);
|
||||||
return;
|
return;
|
||||||
@@ -242,7 +229,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
searchBox.setIcon(ERROR_ICON);
|
searchBar.setIcon(IconTextField.Icon.ERROR);
|
||||||
errorPanel.setContent("No results found.", "No items were found with that name, please try again.");
|
errorPanel.setContent("No results found.", "No items were found with that name, please try again.");
|
||||||
cardLayout.show(centerPanel, ERROR_PANEL);
|
cardLayout.show(centerPanel, ERROR_PANEL);
|
||||||
}
|
}
|
||||||
@@ -280,12 +267,12 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
{
|
{
|
||||||
searchItemsPanel.requestFocusInWindow();
|
searchItemsPanel.requestFocusInWindow();
|
||||||
}
|
}
|
||||||
searchBox.setEditable(true);
|
searchBar.setEditable(true);
|
||||||
|
|
||||||
// Remove searching label after search is complete
|
// Remove searching label after search is complete
|
||||||
if (!itemsList.isEmpty())
|
if (!itemsList.isEmpty())
|
||||||
{
|
{
|
||||||
searchBox.setIcon(SEARCH_ICON);
|
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,10 +99,6 @@ public class HiscorePanel extends PluginPanel
|
|||||||
/* The maximum allowed username length in runescape accounts */
|
/* The maximum allowed username length in runescape accounts */
|
||||||
private static final int MAX_USERNAME_LENGTH = 12;
|
private static final int MAX_USERNAME_LENGTH = 12;
|
||||||
|
|
||||||
private static final ImageIcon SEARCH_ICON;
|
|
||||||
private static final ImageIcon LOADING_ICON;
|
|
||||||
private static final ImageIcon ERROR_ICON;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Real skills, ordered in the way they should be displayed in the panel.
|
* Real skills, ordered in the way they should be displayed in the panel.
|
||||||
*/
|
*/
|
||||||
@@ -125,7 +121,8 @@ public class HiscorePanel extends PluginPanel
|
|||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
private final HiscoreConfig config;
|
private final HiscoreConfig config;
|
||||||
private final IconTextField input;
|
|
||||||
|
private final IconTextField searchBar;
|
||||||
|
|
||||||
private final List<JLabel> skillLabels = new ArrayList<>();
|
private final List<JLabel> skillLabels = new ArrayList<>();
|
||||||
|
|
||||||
@@ -144,13 +141,6 @@ public class HiscorePanel extends PluginPanel
|
|||||||
/* Used to prevent users from switching endpoint tabs while the results are loading */
|
/* Used to prevent users from switching endpoint tabs while the results are loading */
|
||||||
private boolean loading = false;
|
private boolean loading = false;
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
SEARCH_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"));
|
|
||||||
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner_darker.gif"));
|
|
||||||
ERROR_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "error.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public HiscorePanel(HiscoreConfig config)
|
public HiscorePanel(HiscoreConfig config)
|
||||||
{
|
{
|
||||||
@@ -173,13 +163,14 @@ public class HiscorePanel extends PluginPanel
|
|||||||
c.weighty = 0;
|
c.weighty = 0;
|
||||||
c.insets = new Insets(0, 0, 10, 0);
|
c.insets = new Insets(0, 0, 10, 0);
|
||||||
|
|
||||||
input = new IconTextField();
|
searchBar = new IconTextField();
|
||||||
input.setMinimumSize(new Dimension(0, 30));
|
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||||
input.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
|
||||||
input.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
|
searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
input.setIcon(SEARCH_ICON);
|
searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
|
||||||
input.addActionListener(e -> executor.execute(RunnableExceptionLogger.wrap(this::lookup)));
|
searchBar.setMinimumSize(new Dimension(0, 30));
|
||||||
input.addMouseListener(new MouseAdapter()
|
searchBar.addActionListener(e -> executor.execute(RunnableExceptionLogger.wrap(this::lookup)));
|
||||||
|
searchBar.addMouseListener(new MouseAdapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e)
|
public void mouseClicked(MouseEvent e)
|
||||||
@@ -202,7 +193,7 @@ public class HiscorePanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
add(input, c);
|
add(searchBar, c);
|
||||||
c.gridy++;
|
c.gridy++;
|
||||||
|
|
||||||
tabGroup = new MaterialTabGroup();
|
tabGroup = new MaterialTabGroup();
|
||||||
@@ -296,7 +287,7 @@ public class HiscorePanel extends PluginPanel
|
|||||||
public void onActivate()
|
public void onActivate()
|
||||||
{
|
{
|
||||||
super.onActivate();
|
super.onActivate();
|
||||||
input.requestFocusInWindow();
|
searchBar.requestFocusInWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Builds a JPanel displaying an icon and level/number associated with it */
|
/* Builds a JPanel displaying an icon and level/number associated with it */
|
||||||
@@ -337,14 +328,14 @@ public class HiscorePanel extends PluginPanel
|
|||||||
|
|
||||||
public void lookup(String username)
|
public void lookup(String username)
|
||||||
{
|
{
|
||||||
input.setText(username);
|
searchBar.setText(username);
|
||||||
resetEndpoints();
|
resetEndpoints();
|
||||||
lookup();
|
lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookup()
|
private void lookup()
|
||||||
{
|
{
|
||||||
String lookup = input.getText();
|
String lookup = searchBar.getText();
|
||||||
|
|
||||||
lookup = sanitize(lookup);
|
lookup = sanitize(lookup);
|
||||||
|
|
||||||
@@ -356,13 +347,13 @@ public class HiscorePanel extends PluginPanel
|
|||||||
/* Runescape usernames can't be longer than 12 characters long */
|
/* Runescape usernames can't be longer than 12 characters long */
|
||||||
if (lookup.length() > MAX_USERNAME_LENGTH)
|
if (lookup.length() > MAX_USERNAME_LENGTH)
|
||||||
{
|
{
|
||||||
input.setIcon(ERROR_ICON);
|
searchBar.setIcon(IconTextField.Icon.ERROR);
|
||||||
loading = false;
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.setEditable(false);
|
searchBar.setEditable(false);
|
||||||
input.setIcon(LOADING_ICON);
|
searchBar.setIcon(IconTextField.Icon.LOADING_DARKER);
|
||||||
loading = true;
|
loading = true;
|
||||||
|
|
||||||
for (JLabel label : skillLabels)
|
for (JLabel label : skillLabels)
|
||||||
@@ -385,23 +376,23 @@ public class HiscorePanel extends PluginPanel
|
|||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
log.warn("Error fetching Hiscore data " + ex.getMessage());
|
log.warn("Error fetching Hiscore data " + ex.getMessage());
|
||||||
input.setIcon(ERROR_ICON);
|
searchBar.setIcon(IconTextField.Icon.ERROR);
|
||||||
input.setEditable(true);
|
searchBar.setEditable(true);
|
||||||
loading = false;
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
input.setIcon(ERROR_ICON);
|
searchBar.setIcon(IconTextField.Icon.ERROR);
|
||||||
input.setEditable(true);
|
searchBar.setEditable(true);
|
||||||
loading = false;
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//successful player search
|
//successful player search
|
||||||
input.setIcon(SEARCH_ICON);
|
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||||
input.setEditable(true);
|
searchBar.setEditable(true);
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -448,12 +439,12 @@ public class HiscorePanel extends PluginPanel
|
|||||||
|
|
||||||
void addInputKeyListener(KeyListener l)
|
void addInputKeyListener(KeyListener l)
|
||||||
{
|
{
|
||||||
this.input.addKeyListener(l);
|
this.searchBar.addKeyListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeInputKeyListener(KeyListener l)
|
void removeInputKeyListener(KeyListener l)
|
||||||
{
|
{
|
||||||
this.input.removeKeyListener(l);
|
this.searchBar.removeKeyListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -30,10 +30,12 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.KeyListener;
|
import java.awt.event.KeyListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -43,6 +45,8 @@ import javax.swing.SwingUtilities;
|
|||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
|
|
||||||
@@ -113,7 +117,7 @@ public class IconTextField extends JPanel
|
|||||||
clearButton.setVisible(false);
|
clearButton.setVisible(false);
|
||||||
|
|
||||||
// ActionListener for keyboard use (via Tab -> Space)
|
// ActionListener for keyboard use (via Tab -> Space)
|
||||||
clearButton.addActionListener((l) -> setText(null));
|
clearButton.addActionListener(evt -> setText(null));
|
||||||
|
|
||||||
// MouseListener for hover and click events
|
// MouseListener for hover and click events
|
||||||
clearButton.addMouseListener(new MouseAdapter()
|
clearButton.addMouseListener(new MouseAdapter()
|
||||||
@@ -170,9 +174,10 @@ public class IconTextField extends JPanel
|
|||||||
textField.addActionListener(actionListener);
|
textField.addActionListener(actionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(ImageIcon icon)
|
public void setIcon(Icon icon)
|
||||||
{
|
{
|
||||||
iconWrapperLabel.setIcon(icon);
|
final ImageIcon imageIcon = new ImageIcon(this.getClass().getResource(icon.getFile()));
|
||||||
|
iconWrapperLabel.setIcon(imageIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText()
|
public String getText()
|
||||||
@@ -217,6 +222,30 @@ public class IconTextField extends JPanel
|
|||||||
textField.addKeyListener(keyListener);
|
textField.addKeyListener(keyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addKeyListener(Consumer<KeyEvent> keyEventConsumer)
|
||||||
|
{
|
||||||
|
addKeyListener(new net.runelite.client.input.KeyListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
keyEventConsumer.accept(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e)
|
||||||
|
{
|
||||||
|
keyEventConsumer.accept(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e)
|
||||||
|
{
|
||||||
|
keyEventConsumer.accept(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeKeyListener(KeyListener keyListener)
|
public void removeKeyListener(KeyListener keyListener)
|
||||||
{
|
{
|
||||||
@@ -244,4 +273,16 @@ public class IconTextField extends JPanel
|
|||||||
return textField.getDocument();
|
return textField.getDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum Icon
|
||||||
|
{
|
||||||
|
SEARCH("search.png"),
|
||||||
|
LOADING("loading_spinner.gif"),
|
||||||
|
LOADING_DARKER("loading_spinner_darker.gif"),
|
||||||
|
ERROR("error.png");
|
||||||
|
|
||||||
|
private final String file;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user