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