Add isTab property to title buttons

In order to differentiate between title and sidebar buttons in sidebar
add isTab property that will place them after separator.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-07-27 08:00:52 +02:00
parent 746d948a84
commit 7864522210
5 changed files with 25 additions and 1 deletions

View File

@@ -85,12 +85,14 @@ public class AccountPlugin extends Plugin
protected void startUp() throws Exception
{
loginButton = NavigationButton.builder()
.tab(false)
.icon(LOGIN_IMAGE)
.tooltip("Login to RuneLite")
.onClick(this::loginClick)
.build();
logoutButton = NavigationButton.builder()
.tab(false)
.icon(LOGOUT_IMAGE)
.tooltip("Logout of RuneLite")
.onClick(this::logoutClick)

View File

@@ -95,6 +95,7 @@ public class DiscordPlugin extends Plugin
}
discordButton = NavigationButton.builder()
.tab(false)
.tooltip("Join Discord")
.icon(icon)
.onClick(() -> LinkBrowser.browse(properties.getDiscordInvite()))

View File

@@ -203,6 +203,7 @@ public class ScreenshotPlugin extends Plugin
}
titleBarButton = NavigationButton.builder()
.tab(false)
.tooltip("Take screenshot")
.icon(iconImage)
.onClick(() -> takeScreenshot(format(new Date())))

View File

@@ -30,6 +30,7 @@ import java.awt.Component;
import java.awt.Dimension;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JToolBar;
/**
@@ -41,6 +42,7 @@ public class ClientPluginToolbar extends JToolBar
private final Map<NavigationButton, Component> componentMap = new TreeMap<>((a, b) ->
ComparisonChain
.start()
.compare(a.isTab(), b.isTab())
.compare(a.getPriority(), b.getPriority())
.compare(a.getTooltip(), b.getTooltip())
.result());
@@ -78,7 +80,19 @@ public class ClientPluginToolbar extends JToolBar
private void update()
{
removeAll();
componentMap.forEach((key, value) -> add(value));
final AtomicBoolean isDelimited = new AtomicBoolean(false);
componentMap.forEach((key, value) ->
{
if (!key.isTab() && !isDelimited.get())
{
isDelimited.set(true);
addSeparator();
}
add(value);
});
repaint();
}
}

View File

@@ -44,6 +44,12 @@ public class NavigationButton
*/
private final BufferedImage icon;
/**
* If the button is tab or not
*/
@Builder.Default
private boolean tab = true;
/**
* Tooltip to show when hovered.
*/