Sort the PluginToolbar
This commit is contained in:
@@ -45,6 +45,7 @@ public class NavigationButton extends JButton
|
|||||||
public NavigationButton(String name, Image icon, Supplier<PluginPanel> panelSupplier)
|
public NavigationButton(String name, Image icon, Supplier<PluginPanel> panelSupplier)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
setName(name);
|
||||||
setToolTipText(name);
|
setToolTipText(name);
|
||||||
setIcon(new ImageIcon(icon));
|
setIcon(new ImageIcon(icon));
|
||||||
this.panelSupplier = panelSupplier;
|
this.panelSupplier = panelSupplier;
|
||||||
|
|||||||
@@ -24,18 +24,21 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.ui;
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.util.ArrayList;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.TreeSet;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.swing.JToolBar;
|
import javax.swing.JToolBar;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class PluginToolbar extends JToolBar
|
public class PluginToolbar extends JToolBar
|
||||||
{
|
{
|
||||||
public static final int TOOLBAR_WIDTH = 36, TOOLBAR_HEIGHT = 503;
|
public static final int TOOLBAR_WIDTH = 36, TOOLBAR_HEIGHT = 503;
|
||||||
|
|
||||||
private final ClientUI ui;
|
private final ClientUI ui;
|
||||||
private final List<NavigationButton> buttons = new ArrayList<>();
|
private final TreeSet<NavigationButton> buttons = new TreeSet<>(Comparator.comparing(Component::getName));
|
||||||
|
|
||||||
private NavigationButton current;
|
private NavigationButton current;
|
||||||
|
|
||||||
@@ -56,8 +59,15 @@ public class PluginToolbar extends JToolBar
|
|||||||
button.addActionListener((ae) -> onClick(button));
|
button.addActionListener((ae) -> onClick(button));
|
||||||
button.setToolTipText(button.getName());
|
button.setToolTipText(button.getName());
|
||||||
|
|
||||||
|
if (buttons.contains(button))
|
||||||
|
{
|
||||||
|
log.warn("Button already in container '{}'", button.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buttons.add(button);
|
buttons.add(button);
|
||||||
add(button);
|
int index = buttons.headSet(button).size();
|
||||||
|
add(button, index);
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user