Use consistent API and order for title and sides
Use same API for ordering title and sidebar and order them in the swing components and not in events as that is unreliable. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -31,5 +31,4 @@ import net.runelite.client.ui.NavigationButton;
|
||||
public class PluginToolbarButtonAdded
|
||||
{
|
||||
private NavigationButton button;
|
||||
private int index;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,4 @@ import net.runelite.client.ui.NavigationButton;
|
||||
public class PluginToolbarButtonRemoved
|
||||
{
|
||||
private NavigationButton button;
|
||||
private int index;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,4 @@ import net.runelite.client.ui.NavigationButton;
|
||||
public class TitleToolbarButtonAdded
|
||||
{
|
||||
private NavigationButton button;
|
||||
private int index;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,4 @@ import net.runelite.client.ui.NavigationButton;
|
||||
public class TitleToolbarButtonRemoved
|
||||
{
|
||||
private NavigationButton button;
|
||||
private int index;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import javax.swing.JToolBar;
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,12 @@ import javax.swing.JToolBar;
|
||||
public class ClientPluginToolbar extends JToolBar
|
||||
{
|
||||
private static final int TOOLBAR_WIDTH = 36, TOOLBAR_HEIGHT = 503;
|
||||
private final Map<NavigationButton, Component> componentMap = new HashMap<>();
|
||||
private final Map<NavigationButton, Component> componentMap = new TreeMap<>((a, b) ->
|
||||
ComparisonChain
|
||||
.start()
|
||||
.compare(a.getPriority(), b.getPriority())
|
||||
.compare(a.getTooltip(), b.getTooltip())
|
||||
.result());
|
||||
|
||||
/**
|
||||
* Instantiates a new Client plugin toolbar.
|
||||
@@ -53,33 +59,26 @@ public class ClientPluginToolbar extends JToolBar
|
||||
addSeparator();
|
||||
}
|
||||
|
||||
public void addComponent(final int index, final NavigationButton button, final Component component)
|
||||
void addComponent(final NavigationButton button, final Component c)
|
||||
{
|
||||
if (componentMap.put(button, component) == null)
|
||||
if (componentMap.put(button, c) == null)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
add(component);
|
||||
}
|
||||
else
|
||||
{
|
||||
add(component, index);
|
||||
}
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeComponent(final NavigationButton button)
|
||||
void removeComponent(final NavigationButton button)
|
||||
{
|
||||
final Component component = componentMap.remove(button);
|
||||
|
||||
if (component != null)
|
||||
if (componentMap.remove(button) != null)
|
||||
{
|
||||
remove(component);
|
||||
revalidate();
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private void update()
|
||||
{
|
||||
removeAll();
|
||||
componentMap.forEach((key, value) -> add(value));
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.LayoutManager2;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
@@ -39,8 +40,12 @@ class ClientTitleToolbar extends JPanel
|
||||
{
|
||||
static final int TITLEBAR_SIZE = 23;
|
||||
private static final int ITEM_PADDING = 4;
|
||||
|
||||
private final Map<NavigationButton, Component> componentMap = new HashMap<>();
|
||||
private final Map<NavigationButton, Component> componentMap = new TreeMap<>((a, b) ->
|
||||
ComparisonChain
|
||||
.start()
|
||||
.compare(a.getPriority(), b.getPriority())
|
||||
.compare(a.getTooltip(), b.getTooltip())
|
||||
.result());
|
||||
|
||||
/**
|
||||
* Instantiates a new Client title toolbar.
|
||||
@@ -122,24 +127,26 @@ class ClientTitleToolbar extends JPanel
|
||||
});
|
||||
}
|
||||
|
||||
public void addComponent(NavigationButton button, Component c)
|
||||
void addComponent(final NavigationButton button, final Component c)
|
||||
{
|
||||
if (componentMap.put(button, c) == null)
|
||||
{
|
||||
add(c);
|
||||
revalidate();
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeComponent(NavigationButton button)
|
||||
void removeComponent(final NavigationButton button)
|
||||
{
|
||||
final Component component = componentMap.remove(button);
|
||||
if (component != null)
|
||||
if (componentMap.remove(button) != null)
|
||||
{
|
||||
remove(component);
|
||||
revalidate();
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private void update()
|
||||
{
|
||||
removeAll();
|
||||
componentMap.forEach((key, value) -> add(value));
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class ClientUI
|
||||
}
|
||||
});
|
||||
|
||||
pluginToolbar.addComponent(event.getIndex(), event.getButton(), button);
|
||||
pluginToolbar.addComponent(event.getButton(), button);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ public class ClientUI
|
||||
return;
|
||||
}
|
||||
|
||||
pluginToolbar.addComponent(-1, event.getButton(), button);
|
||||
pluginToolbar.addComponent(event.getButton(), button);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -449,6 +449,7 @@ public class ClientUI
|
||||
// Create hide sidebar button
|
||||
sidebarNavigationButton = NavigationButton
|
||||
.builder()
|
||||
.priority(100)
|
||||
.icon(SIDEBAR_CLOSE)
|
||||
.onClick(this::toggleSidebar)
|
||||
.build();
|
||||
|
||||
@@ -47,7 +47,8 @@ public class NavigationButton
|
||||
/**
|
||||
* Tooltip to show when hovered.
|
||||
*/
|
||||
private final String tooltip;
|
||||
@Builder.Default
|
||||
private final String tooltip = "";
|
||||
|
||||
/**
|
||||
* Button selection state
|
||||
@@ -69,7 +70,6 @@ public class NavigationButton
|
||||
*/
|
||||
private PluginPanel panel;
|
||||
|
||||
|
||||
/**
|
||||
* The order in which the button should be displayed in the side bar. (from lower to higher)
|
||||
*/
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.client.events.PluginToolbarButtonAdded;
|
||||
@@ -39,11 +39,7 @@ import net.runelite.client.events.PluginToolbarButtonRemoved;
|
||||
public class PluginToolbar
|
||||
{
|
||||
private final EventBus eventBus;
|
||||
private final TreeSet<NavigationButton> buttons = new TreeSet<>((a, b) ->
|
||||
ComparisonChain.start()
|
||||
.compare(a.getPriority(), b.getPriority())
|
||||
.compare(a.getTooltip(), b.getTooltip())
|
||||
.result());
|
||||
private final Set<NavigationButton> buttons = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
private PluginToolbar(final EventBus eventBus)
|
||||
@@ -65,8 +61,7 @@ public class PluginToolbar
|
||||
|
||||
if (buttons.add(button))
|
||||
{
|
||||
int index = buttons.headSet(button).size();
|
||||
eventBus.post(new PluginToolbarButtonAdded(button, index));
|
||||
eventBus.post(new PluginToolbarButtonAdded(button));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +72,9 @@ public class PluginToolbar
|
||||
*/
|
||||
public void removeNavigation(final NavigationButton button)
|
||||
{
|
||||
int index = buttons.headSet(button).size();
|
||||
|
||||
if (buttons.remove(button))
|
||||
{
|
||||
eventBus.post(new PluginToolbarButtonRemoved(button, index));
|
||||
eventBus.post(new PluginToolbarButtonRemoved(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.client.events.TitleToolbarButtonAdded;
|
||||
@@ -40,7 +40,7 @@ import net.runelite.client.events.TitleToolbarButtonRemoved;
|
||||
public class TitleToolbar
|
||||
{
|
||||
private final EventBus eventBus;
|
||||
private final TreeSet<NavigationButton> buttons = new TreeSet<>(Comparator.comparing(NavigationButton::getTooltip));
|
||||
private final Set<NavigationButton> buttons = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
private TitleToolbar(final EventBus eventBus)
|
||||
@@ -62,8 +62,7 @@ public class TitleToolbar
|
||||
|
||||
if (buttons.add(button))
|
||||
{
|
||||
int index = buttons.headSet(button).size();
|
||||
eventBus.post(new TitleToolbarButtonAdded(button, index));
|
||||
eventBus.post(new TitleToolbarButtonAdded(button));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,11 +73,9 @@ public class TitleToolbar
|
||||
*/
|
||||
public void removeNavigation(final NavigationButton button)
|
||||
{
|
||||
int index = buttons.headSet(button).size();
|
||||
|
||||
if (buttons.remove(button))
|
||||
{
|
||||
eventBus.post(new TitleToolbarButtonRemoved(button, index));
|
||||
eventBus.post(new TitleToolbarButtonRemoved(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user